10Sstevel@tonic-gate /* ssl/ssl_locl.h */ 20Sstevel@tonic-gate /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 30Sstevel@tonic-gate * All rights reserved. 40Sstevel@tonic-gate * 50Sstevel@tonic-gate * This package is an SSL implementation written 60Sstevel@tonic-gate * by Eric Young (eay@cryptsoft.com). 70Sstevel@tonic-gate * The implementation was written so as to conform with Netscapes SSL. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * This library is free for commercial and non-commercial use as long as 100Sstevel@tonic-gate * the following conditions are aheared to. The following conditions 110Sstevel@tonic-gate * apply to all code found in this distribution, be it the RC4, RSA, 120Sstevel@tonic-gate * lhash, DES, etc., code; not just the SSL code. The SSL documentation 130Sstevel@tonic-gate * included with this distribution is covered by the same copyright terms 140Sstevel@tonic-gate * except that the holder is Tim Hudson (tjh@cryptsoft.com). 150Sstevel@tonic-gate * 160Sstevel@tonic-gate * Copyright remains Eric Young's, and as such any Copyright notices in 170Sstevel@tonic-gate * the code are not to be removed. 180Sstevel@tonic-gate * If this package is used in a product, Eric Young should be given attribution 190Sstevel@tonic-gate * as the author of the parts of the library used. 200Sstevel@tonic-gate * This can be in the form of a textual message at program startup or 210Sstevel@tonic-gate * in documentation (online or textual) provided with the package. 220Sstevel@tonic-gate * 230Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 240Sstevel@tonic-gate * modification, are permitted provided that the following conditions 250Sstevel@tonic-gate * are met: 260Sstevel@tonic-gate * 1. Redistributions of source code must retain the copyright 270Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 280Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 290Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 300Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 310Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software 320Sstevel@tonic-gate * must display the following acknowledgement: 330Sstevel@tonic-gate * "This product includes cryptographic software written by 340Sstevel@tonic-gate * Eric Young (eay@cryptsoft.com)" 350Sstevel@tonic-gate * The word 'cryptographic' can be left out if the rouines from the library 360Sstevel@tonic-gate * being used are not cryptographic related :-). 370Sstevel@tonic-gate * 4. If you include any Windows specific code (or a derivative thereof) from 380Sstevel@tonic-gate * the apps directory (application code) you must include an acknowledgement: 390Sstevel@tonic-gate * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 400Sstevel@tonic-gate * 410Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 420Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 430Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 440Sstevel@tonic-gate * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 450Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 460Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 470Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 480Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 490Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 500Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 510Sstevel@tonic-gate * SUCH DAMAGE. 520Sstevel@tonic-gate * 530Sstevel@tonic-gate * The licence and distribution terms for any publically available version or 540Sstevel@tonic-gate * derivative of this code cannot be changed. i.e. this code cannot simply be 550Sstevel@tonic-gate * copied and put under another distribution licence 560Sstevel@tonic-gate * [including the GNU Public Licence.] 570Sstevel@tonic-gate */ 580Sstevel@tonic-gate /* ==================================================================== 590Sstevel@tonic-gate * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. 600Sstevel@tonic-gate * 610Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 620Sstevel@tonic-gate * modification, are permitted provided that the following conditions 630Sstevel@tonic-gate * are met: 640Sstevel@tonic-gate * 650Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 660Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 670Sstevel@tonic-gate * 680Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 690Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in 700Sstevel@tonic-gate * the documentation and/or other materials provided with the 710Sstevel@tonic-gate * distribution. 720Sstevel@tonic-gate * 730Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this 740Sstevel@tonic-gate * software must display the following acknowledgment: 750Sstevel@tonic-gate * "This product includes software developed by the OpenSSL Project 760Sstevel@tonic-gate * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 770Sstevel@tonic-gate * 780Sstevel@tonic-gate * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 790Sstevel@tonic-gate * endorse or promote products derived from this software without 800Sstevel@tonic-gate * prior written permission. For written permission, please contact 810Sstevel@tonic-gate * openssl-core@openssl.org. 820Sstevel@tonic-gate * 830Sstevel@tonic-gate * 5. Products derived from this software may not be called "OpenSSL" 840Sstevel@tonic-gate * nor may "OpenSSL" appear in their names without prior written 850Sstevel@tonic-gate * permission of the OpenSSL Project. 860Sstevel@tonic-gate * 870Sstevel@tonic-gate * 6. Redistributions of any form whatsoever must retain the following 880Sstevel@tonic-gate * acknowledgment: 890Sstevel@tonic-gate * "This product includes software developed by the OpenSSL Project 900Sstevel@tonic-gate * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 910Sstevel@tonic-gate * 920Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 930Sstevel@tonic-gate * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 940Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 950Sstevel@tonic-gate * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 960Sstevel@tonic-gate * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 970Sstevel@tonic-gate * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 980Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 990Sstevel@tonic-gate * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1000Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 1010Sstevel@tonic-gate * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1020Sstevel@tonic-gate * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 1030Sstevel@tonic-gate * OF THE POSSIBILITY OF SUCH DAMAGE. 1040Sstevel@tonic-gate * ==================================================================== 1050Sstevel@tonic-gate * 1060Sstevel@tonic-gate * This product includes cryptographic software written by Eric Young 1070Sstevel@tonic-gate * (eay@cryptsoft.com). This product includes software written by Tim 1080Sstevel@tonic-gate * Hudson (tjh@cryptsoft.com). 1090Sstevel@tonic-gate * 1100Sstevel@tonic-gate */ 1112139Sjp161948 /* ==================================================================== 1122139Sjp161948 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 1132139Sjp161948 * ECC cipher suite support in OpenSSL originally developed by 1142139Sjp161948 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. 1152139Sjp161948 */ 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate #ifndef HEADER_SSL_LOCL_H 1180Sstevel@tonic-gate #define HEADER_SSL_LOCL_H 1190Sstevel@tonic-gate #include <stdlib.h> 1200Sstevel@tonic-gate #include <time.h> 1210Sstevel@tonic-gate #include <string.h> 1220Sstevel@tonic-gate #include <errno.h> 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate #include "e_os.h" 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate #include <openssl/buffer.h> 1270Sstevel@tonic-gate #include <openssl/comp.h> 1280Sstevel@tonic-gate #include <openssl/bio.h> 1290Sstevel@tonic-gate #include <openssl/stack.h> 1302139Sjp161948 #ifndef OPENSSL_NO_RSA 1312139Sjp161948 #include <openssl/rsa.h> 1322139Sjp161948 #endif 1332139Sjp161948 #ifndef OPENSSL_NO_DSA 1342139Sjp161948 #include <openssl/dsa.h> 1352139Sjp161948 #endif 1360Sstevel@tonic-gate #include <openssl/err.h> 1370Sstevel@tonic-gate #include <openssl/ssl.h> 1380Sstevel@tonic-gate #include <openssl/symhacks.h> 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate #ifdef OPENSSL_BUILD_SHLIBSSL 1410Sstevel@tonic-gate # undef OPENSSL_EXTERN 1420Sstevel@tonic-gate # define OPENSSL_EXTERN OPENSSL_EXPORT 1430Sstevel@tonic-gate #endif 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate #define PKCS1_CHECK 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate #define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \ 1480Sstevel@tonic-gate l|=(((unsigned long)(*((c)++)))<< 8), \ 1490Sstevel@tonic-gate l|=(((unsigned long)(*((c)++)))<<16), \ 1500Sstevel@tonic-gate l|=(((unsigned long)(*((c)++)))<<24)) 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate /* NOTE - c is not incremented as per c2l */ 1530Sstevel@tonic-gate #define c2ln(c,l1,l2,n) { \ 1540Sstevel@tonic-gate c+=n; \ 1550Sstevel@tonic-gate l1=l2=0; \ 1560Sstevel@tonic-gate switch (n) { \ 1570Sstevel@tonic-gate case 8: l2 =((unsigned long)(*(--(c))))<<24; \ 1580Sstevel@tonic-gate case 7: l2|=((unsigned long)(*(--(c))))<<16; \ 1590Sstevel@tonic-gate case 6: l2|=((unsigned long)(*(--(c))))<< 8; \ 1600Sstevel@tonic-gate case 5: l2|=((unsigned long)(*(--(c)))); \ 1610Sstevel@tonic-gate case 4: l1 =((unsigned long)(*(--(c))))<<24; \ 1620Sstevel@tonic-gate case 3: l1|=((unsigned long)(*(--(c))))<<16; \ 1630Sstevel@tonic-gate case 2: l1|=((unsigned long)(*(--(c))))<< 8; \ 1640Sstevel@tonic-gate case 1: l1|=((unsigned long)(*(--(c)))); \ 1650Sstevel@tonic-gate } \ 1660Sstevel@tonic-gate } 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ 1690Sstevel@tonic-gate *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ 1700Sstevel@tonic-gate *((c)++)=(unsigned char)(((l)>>16)&0xff), \ 1710Sstevel@tonic-gate *((c)++)=(unsigned char)(((l)>>24)&0xff)) 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate #define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24, \ 1740Sstevel@tonic-gate l|=((unsigned long)(*((c)++)))<<16, \ 1750Sstevel@tonic-gate l|=((unsigned long)(*((c)++)))<< 8, \ 1760Sstevel@tonic-gate l|=((unsigned long)(*((c)++)))) 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate #define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \ 1790Sstevel@tonic-gate *((c)++)=(unsigned char)(((l)>>16)&0xff), \ 1800Sstevel@tonic-gate *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ 1810Sstevel@tonic-gate *((c)++)=(unsigned char)(((l) )&0xff)) 1820Sstevel@tonic-gate 1832139Sjp161948 #define l2n6(l,c) (*((c)++)=(unsigned char)(((l)>>40)&0xff), \ 1842139Sjp161948 *((c)++)=(unsigned char)(((l)>>32)&0xff), \ 1852139Sjp161948 *((c)++)=(unsigned char)(((l)>>24)&0xff), \ 1862139Sjp161948 *((c)++)=(unsigned char)(((l)>>16)&0xff), \ 1872139Sjp161948 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ 1882139Sjp161948 *((c)++)=(unsigned char)(((l) )&0xff)) 1892139Sjp161948 1902139Sjp161948 #define n2l6(c,l) (l =((BN_ULLONG)(*((c)++)))<<40, \ 1912139Sjp161948 l|=((BN_ULLONG)(*((c)++)))<<32, \ 1922139Sjp161948 l|=((BN_ULLONG)(*((c)++)))<<24, \ 1932139Sjp161948 l|=((BN_ULLONG)(*((c)++)))<<16, \ 1942139Sjp161948 l|=((BN_ULLONG)(*((c)++)))<< 8, \ 1952139Sjp161948 l|=((BN_ULLONG)(*((c)++)))) 1962139Sjp161948 1970Sstevel@tonic-gate /* NOTE - c is not incremented as per l2c */ 1980Sstevel@tonic-gate #define l2cn(l1,l2,c,n) { \ 1990Sstevel@tonic-gate c+=n; \ 2000Sstevel@tonic-gate switch (n) { \ 2010Sstevel@tonic-gate case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ 2020Sstevel@tonic-gate case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ 2030Sstevel@tonic-gate case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ 2040Sstevel@tonic-gate case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ 2050Sstevel@tonic-gate case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ 2060Sstevel@tonic-gate case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ 2070Sstevel@tonic-gate case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ 2080Sstevel@tonic-gate case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ 2090Sstevel@tonic-gate } \ 2100Sstevel@tonic-gate } 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate #define n2s(c,s) ((s=(((unsigned int)(c[0]))<< 8)| \ 2130Sstevel@tonic-gate (((unsigned int)(c[1])) )),c+=2) 2140Sstevel@tonic-gate #define s2n(s,c) ((c[0]=(unsigned char)(((s)>> 8)&0xff), \ 2150Sstevel@tonic-gate c[1]=(unsigned char)(((s) )&0xff)),c+=2) 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate #define n2l3(c,l) ((l =(((unsigned long)(c[0]))<<16)| \ 2180Sstevel@tonic-gate (((unsigned long)(c[1]))<< 8)| \ 2190Sstevel@tonic-gate (((unsigned long)(c[2])) )),c+=3) 2200Sstevel@tonic-gate 2210Sstevel@tonic-gate #define l2n3(l,c) ((c[0]=(unsigned char)(((l)>>16)&0xff), \ 2220Sstevel@tonic-gate c[1]=(unsigned char)(((l)>> 8)&0xff), \ 2230Sstevel@tonic-gate c[2]=(unsigned char)(((l) )&0xff)),c+=3) 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate /* LOCAL STUFF */ 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate #define SSL_DECRYPT 0 2280Sstevel@tonic-gate #define SSL_ENCRYPT 1 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate #define TWO_BYTE_BIT 0x80 2310Sstevel@tonic-gate #define SEC_ESC_BIT 0x40 2320Sstevel@tonic-gate #define TWO_BYTE_MASK 0x7fff 2330Sstevel@tonic-gate #define THREE_BYTE_MASK 0x3fff 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate #define INC32(a) ((a)=((a)+1)&0xffffffffL) 2360Sstevel@tonic-gate #define DEC32(a) ((a)=((a)-1)&0xffffffffL) 2370Sstevel@tonic-gate #define MAX_MAC_SIZE 20 /* up from 16 for SSLv3 */ 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate /* 2400Sstevel@tonic-gate * Define the Bitmasks for SSL_CIPHER.algorithms. 2410Sstevel@tonic-gate * This bits are used packed as dense as possible. If new methods/ciphers 2420Sstevel@tonic-gate * etc will be added, the bits a likely to change, so this information 2430Sstevel@tonic-gate * is for internal library use only, even though SSL_CIPHER.algorithms 2440Sstevel@tonic-gate * can be publicly accessed. 2450Sstevel@tonic-gate * Use the according functions for cipher management instead. 2460Sstevel@tonic-gate * 2470Sstevel@tonic-gate * The bit mask handling in the selection and sorting scheme in 2480Sstevel@tonic-gate * ssl_create_cipher_list() has only limited capabilities, reflecting 2490Sstevel@tonic-gate * that the different entities within are mutually exclusive: 2500Sstevel@tonic-gate * ONLY ONE BIT PER MASK CAN BE SET AT A TIME. 2510Sstevel@tonic-gate */ 2522139Sjp161948 #define SSL_MKEY_MASK 0x000000FFL 2530Sstevel@tonic-gate #define SSL_kRSA 0x00000001L /* RSA key exchange */ 2540Sstevel@tonic-gate #define SSL_kDHr 0x00000002L /* DH cert RSA CA cert */ 2550Sstevel@tonic-gate #define SSL_kDHd 0x00000004L /* DH cert DSA CA cert */ 2560Sstevel@tonic-gate #define SSL_kFZA 0x00000008L 2570Sstevel@tonic-gate #define SSL_kEDH 0x00000010L /* tmp DH key no DH cert */ 2580Sstevel@tonic-gate #define SSL_kKRB5 0x00000020L /* Kerberos5 key exchange */ 2592139Sjp161948 #define SSL_kECDH 0x00000040L /* ECDH w/ long-term keys */ 2602139Sjp161948 #define SSL_kECDHE 0x00000080L /* ephemeral ECDH */ 2610Sstevel@tonic-gate #define SSL_EDH (SSL_kEDH|(SSL_AUTH_MASK^SSL_aNULL)) 2620Sstevel@tonic-gate 2632139Sjp161948 #define SSL_AUTH_MASK 0x00007F00L 2642139Sjp161948 #define SSL_aRSA 0x00000100L /* Authenticate with RSA */ 2652139Sjp161948 #define SSL_aDSS 0x00000200L /* Authenticate with DSS */ 2660Sstevel@tonic-gate #define SSL_DSS SSL_aDSS 2672139Sjp161948 #define SSL_aFZA 0x00000400L 2682139Sjp161948 #define SSL_aNULL 0x00000800L /* no Authenticate, ADH */ 2692139Sjp161948 #define SSL_aDH 0x00001000L /* no Authenticate, ADH */ 2702139Sjp161948 #define SSL_aKRB5 0x00002000L /* Authenticate with KRB5 */ 2712139Sjp161948 #define SSL_aECDSA 0x00004000L /* Authenticate with ECDSA */ 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate #define SSL_NULL (SSL_eNULL) 2740Sstevel@tonic-gate #define SSL_ADH (SSL_kEDH|SSL_aNULL) 2750Sstevel@tonic-gate #define SSL_RSA (SSL_kRSA|SSL_aRSA) 2760Sstevel@tonic-gate #define SSL_DH (SSL_kDHr|SSL_kDHd|SSL_kEDH) 2772139Sjp161948 #define SSL_ECDH (SSL_kECDH|SSL_kECDHE) 2780Sstevel@tonic-gate #define SSL_FZA (SSL_aFZA|SSL_kFZA|SSL_eFZA) 2790Sstevel@tonic-gate #define SSL_KRB5 (SSL_kKRB5|SSL_aKRB5) 2800Sstevel@tonic-gate 2812139Sjp161948 #define SSL_ENC_MASK 0x043F8000L 2822139Sjp161948 #define SSL_DES 0x00008000L 2832139Sjp161948 #define SSL_3DES 0x00010000L 2842139Sjp161948 #define SSL_RC4 0x00020000L 2852139Sjp161948 #define SSL_RC2 0x00040000L 2862139Sjp161948 #define SSL_IDEA 0x00080000L 2872139Sjp161948 #define SSL_eFZA 0x00100000L 2882139Sjp161948 #define SSL_eNULL 0x00200000L 2892139Sjp161948 #define SSL_AES 0x04000000L 2900Sstevel@tonic-gate 2912139Sjp161948 #define SSL_MAC_MASK 0x00c00000L 2922139Sjp161948 #define SSL_MD5 0x00400000L 2932139Sjp161948 #define SSL_SHA1 0x00800000L 2940Sstevel@tonic-gate #define SSL_SHA (SSL_SHA1) 2950Sstevel@tonic-gate 2962139Sjp161948 #define SSL_SSL_MASK 0x03000000L 2972139Sjp161948 #define SSL_SSLV2 0x01000000L 2982139Sjp161948 #define SSL_SSLV3 0x02000000L 2990Sstevel@tonic-gate #define SSL_TLSV1 SSL_SSLV3 /* for now */ 3000Sstevel@tonic-gate 3012139Sjp161948 /* we have used 07ffffff - 5 bits left to go. */ 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate /* 3040Sstevel@tonic-gate * Export and cipher strength information. For each cipher we have to decide 3050Sstevel@tonic-gate * whether it is exportable or not. This information is likely to change 3060Sstevel@tonic-gate * over time, since the export control rules are no static technical issue. 3070Sstevel@tonic-gate * 3080Sstevel@tonic-gate * Independent of the export flag the cipher strength is sorted into classes. 3090Sstevel@tonic-gate * SSL_EXP40 was denoting the 40bit US export limit of past times, which now 3100Sstevel@tonic-gate * is at 56bit (SSL_EXP56). If the exportable cipher class is going to change 3110Sstevel@tonic-gate * again (eg. to 64bit) the use of "SSL_EXP*" becomes blurred even more, 3120Sstevel@tonic-gate * since SSL_EXP64 could be similar to SSL_LOW. 3130Sstevel@tonic-gate * For this reason SSL_MICRO and SSL_MINI macros are included to widen the 3140Sstevel@tonic-gate * namespace of SSL_LOW-SSL_HIGH to lower values. As development of speed 3150Sstevel@tonic-gate * and ciphers goes, another extension to SSL_SUPER and/or SSL_ULTRA would 3160Sstevel@tonic-gate * be possible. 3170Sstevel@tonic-gate */ 3180Sstevel@tonic-gate #define SSL_EXP_MASK 0x00000003L 3190Sstevel@tonic-gate #define SSL_NOT_EXP 0x00000001L 3200Sstevel@tonic-gate #define SSL_EXPORT 0x00000002L 3210Sstevel@tonic-gate 3220Sstevel@tonic-gate #define SSL_STRONG_MASK 0x000000fcL 3230Sstevel@tonic-gate #define SSL_STRONG_NONE 0x00000004L 3240Sstevel@tonic-gate #define SSL_EXP40 0x00000008L 3250Sstevel@tonic-gate #define SSL_MICRO (SSL_EXP40) 3260Sstevel@tonic-gate #define SSL_EXP56 0x00000010L 3270Sstevel@tonic-gate #define SSL_MINI (SSL_EXP56) 3280Sstevel@tonic-gate #define SSL_LOW 0x00000020L 3290Sstevel@tonic-gate #define SSL_MEDIUM 0x00000040L 3300Sstevel@tonic-gate #define SSL_HIGH 0x00000080L 3310Sstevel@tonic-gate 3320Sstevel@tonic-gate /* we have used 000000ff - 24 bits left to go */ 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate /* 3350Sstevel@tonic-gate * Macros to check the export status and cipher strength for export ciphers. 3360Sstevel@tonic-gate * Even though the macros for EXPORT and EXPORT40/56 have similar names, 3370Sstevel@tonic-gate * their meaning is different: 3380Sstevel@tonic-gate * *_EXPORT macros check the 'exportable' status. 3390Sstevel@tonic-gate * *_EXPORT40/56 macros are used to check whether a certain cipher strength 3400Sstevel@tonic-gate * is given. 3410Sstevel@tonic-gate * Since the SSL_IS_EXPORT* and SSL_EXPORT* macros depend on the correct 3420Sstevel@tonic-gate * algorithm structure element to be passed (algorithms, algo_strength) and no 3430Sstevel@tonic-gate * typechecking can be done as they are all of type unsigned long, their 3440Sstevel@tonic-gate * direct usage is discouraged. 3450Sstevel@tonic-gate * Use the SSL_C_* macros instead. 3460Sstevel@tonic-gate */ 3470Sstevel@tonic-gate #define SSL_IS_EXPORT(a) ((a)&SSL_EXPORT) 3480Sstevel@tonic-gate #define SSL_IS_EXPORT56(a) ((a)&SSL_EXP56) 3490Sstevel@tonic-gate #define SSL_IS_EXPORT40(a) ((a)&SSL_EXP40) 3500Sstevel@tonic-gate #define SSL_C_IS_EXPORT(c) SSL_IS_EXPORT((c)->algo_strength) 3510Sstevel@tonic-gate #define SSL_C_IS_EXPORT56(c) SSL_IS_EXPORT56((c)->algo_strength) 3520Sstevel@tonic-gate #define SSL_C_IS_EXPORT40(c) SSL_IS_EXPORT40((c)->algo_strength) 3530Sstevel@tonic-gate 3540Sstevel@tonic-gate #define SSL_EXPORT_KEYLENGTH(a,s) (SSL_IS_EXPORT40(s) ? 5 : \ 3550Sstevel@tonic-gate ((a)&SSL_ENC_MASK) == SSL_DES ? 8 : 7) 3560Sstevel@tonic-gate #define SSL_EXPORT_PKEYLENGTH(a) (SSL_IS_EXPORT40(a) ? 512 : 1024) 3570Sstevel@tonic-gate #define SSL_C_EXPORT_KEYLENGTH(c) SSL_EXPORT_KEYLENGTH((c)->algorithms, \ 3580Sstevel@tonic-gate (c)->algo_strength) 3590Sstevel@tonic-gate #define SSL_C_EXPORT_PKEYLENGTH(c) SSL_EXPORT_PKEYLENGTH((c)->algo_strength) 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate 3620Sstevel@tonic-gate #define SSL_ALL 0xffffffffL 3630Sstevel@tonic-gate #define SSL_ALL_CIPHERS (SSL_MKEY_MASK|SSL_AUTH_MASK|SSL_ENC_MASK|\ 3640Sstevel@tonic-gate SSL_MAC_MASK) 3650Sstevel@tonic-gate #define SSL_ALL_STRENGTHS (SSL_EXP_MASK|SSL_STRONG_MASK) 3660Sstevel@tonic-gate 3670Sstevel@tonic-gate /* Mostly for SSLv3 */ 3680Sstevel@tonic-gate #define SSL_PKEY_RSA_ENC 0 3690Sstevel@tonic-gate #define SSL_PKEY_RSA_SIGN 1 3700Sstevel@tonic-gate #define SSL_PKEY_DSA_SIGN 2 3710Sstevel@tonic-gate #define SSL_PKEY_DH_RSA 3 3720Sstevel@tonic-gate #define SSL_PKEY_DH_DSA 4 3732139Sjp161948 #define SSL_PKEY_ECC 5 3742139Sjp161948 #define SSL_PKEY_NUM 6 3750Sstevel@tonic-gate 3760Sstevel@tonic-gate /* SSL_kRSA <- RSA_ENC | (RSA_TMP & RSA_SIGN) | 3770Sstevel@tonic-gate * <- (EXPORT & (RSA_ENC | RSA_TMP) & RSA_SIGN) 3780Sstevel@tonic-gate * SSL_kDH <- DH_ENC & (RSA_ENC | RSA_SIGN | DSA_SIGN) 3790Sstevel@tonic-gate * SSL_kEDH <- RSA_ENC | RSA_SIGN | DSA_SIGN 3800Sstevel@tonic-gate * SSL_aRSA <- RSA_ENC | RSA_SIGN 3810Sstevel@tonic-gate * SSL_aDSS <- DSA_SIGN 3820Sstevel@tonic-gate */ 3830Sstevel@tonic-gate 3840Sstevel@tonic-gate /* 3850Sstevel@tonic-gate #define CERT_INVALID 0 3860Sstevel@tonic-gate #define CERT_PUBLIC_KEY 1 3870Sstevel@tonic-gate #define CERT_PRIVATE_KEY 2 3880Sstevel@tonic-gate */ 3890Sstevel@tonic-gate 3902139Sjp161948 #ifndef OPENSSL_NO_EC 3912139Sjp161948 /* From ECC-TLS draft, used in encoding the curve type in 3922139Sjp161948 * ECParameters 3932139Sjp161948 */ 3942139Sjp161948 #define EXPLICIT_PRIME_CURVE_TYPE 1 3952139Sjp161948 #define EXPLICIT_CHAR2_CURVE_TYPE 2 3962139Sjp161948 #define NAMED_CURVE_TYPE 3 3972139Sjp161948 #endif /* OPENSSL_NO_EC */ 3982139Sjp161948 3990Sstevel@tonic-gate typedef struct cert_pkey_st 4000Sstevel@tonic-gate { 4010Sstevel@tonic-gate X509 *x509; 4020Sstevel@tonic-gate EVP_PKEY *privatekey; 4030Sstevel@tonic-gate } CERT_PKEY; 4040Sstevel@tonic-gate 4050Sstevel@tonic-gate typedef struct cert_st 4060Sstevel@tonic-gate { 4070Sstevel@tonic-gate /* Current active set */ 4080Sstevel@tonic-gate CERT_PKEY *key; /* ALWAYS points to an element of the pkeys array 4090Sstevel@tonic-gate * Probably it would make more sense to store 4100Sstevel@tonic-gate * an index, not a pointer. */ 4110Sstevel@tonic-gate 4120Sstevel@tonic-gate /* The following masks are for the key and auth 4130Sstevel@tonic-gate * algorithms that are supported by the certs below */ 4140Sstevel@tonic-gate int valid; 4150Sstevel@tonic-gate unsigned long mask; 4160Sstevel@tonic-gate unsigned long export_mask; 4170Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA 4180Sstevel@tonic-gate RSA *rsa_tmp; 4190Sstevel@tonic-gate RSA *(*rsa_tmp_cb)(SSL *ssl,int is_export,int keysize); 4200Sstevel@tonic-gate #endif 4210Sstevel@tonic-gate #ifndef OPENSSL_NO_DH 4220Sstevel@tonic-gate DH *dh_tmp; 4230Sstevel@tonic-gate DH *(*dh_tmp_cb)(SSL *ssl,int is_export,int keysize); 4240Sstevel@tonic-gate #endif 4252139Sjp161948 #ifndef OPENSSL_NO_ECDH 4262139Sjp161948 EC_KEY *ecdh_tmp; 4272139Sjp161948 /* Callback for generating ephemeral ECDH keys */ 4282139Sjp161948 EC_KEY *(*ecdh_tmp_cb)(SSL *ssl,int is_export,int keysize); 4292139Sjp161948 #endif 4300Sstevel@tonic-gate 4310Sstevel@tonic-gate CERT_PKEY pkeys[SSL_PKEY_NUM]; 4320Sstevel@tonic-gate 4330Sstevel@tonic-gate int references; /* >1 only if SSL_copy_session_id is used */ 4340Sstevel@tonic-gate } CERT; 4350Sstevel@tonic-gate 4360Sstevel@tonic-gate 4370Sstevel@tonic-gate typedef struct sess_cert_st 4380Sstevel@tonic-gate { 4390Sstevel@tonic-gate STACK_OF(X509) *cert_chain; /* as received from peer (not for SSL2) */ 4400Sstevel@tonic-gate 4410Sstevel@tonic-gate /* The 'peer_...' members are used only by clients. */ 4420Sstevel@tonic-gate int peer_cert_type; 4430Sstevel@tonic-gate 4440Sstevel@tonic-gate CERT_PKEY *peer_key; /* points to an element of peer_pkeys (never NULL!) */ 4450Sstevel@tonic-gate CERT_PKEY peer_pkeys[SSL_PKEY_NUM]; 4460Sstevel@tonic-gate /* Obviously we don't have the private keys of these, 4470Sstevel@tonic-gate * so maybe we shouldn't even use the CERT_PKEY type here. */ 4480Sstevel@tonic-gate 4490Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA 4500Sstevel@tonic-gate RSA *peer_rsa_tmp; /* not used for SSL 2 */ 4510Sstevel@tonic-gate #endif 4520Sstevel@tonic-gate #ifndef OPENSSL_NO_DH 4530Sstevel@tonic-gate DH *peer_dh_tmp; /* not used for SSL 2 */ 4540Sstevel@tonic-gate #endif 4552139Sjp161948 #ifndef OPENSSL_NO_ECDH 4562139Sjp161948 EC_KEY *peer_ecdh_tmp; 4572139Sjp161948 #endif 4580Sstevel@tonic-gate 4590Sstevel@tonic-gate int references; /* actually always 1 at the moment */ 4600Sstevel@tonic-gate } SESS_CERT; 4610Sstevel@tonic-gate 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate /*#define MAC_DEBUG */ 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate /*#define ERR_DEBUG */ 4660Sstevel@tonic-gate /*#define ABORT_DEBUG */ 4670Sstevel@tonic-gate /*#define PKT_DEBUG 1 */ 4680Sstevel@tonic-gate /*#define DES_DEBUG */ 4690Sstevel@tonic-gate /*#define DES_OFB_DEBUG */ 4700Sstevel@tonic-gate /*#define SSL_DEBUG */ 4710Sstevel@tonic-gate /*#define RSA_DEBUG */ 4720Sstevel@tonic-gate /*#define IDEA_DEBUG */ 4730Sstevel@tonic-gate 4740Sstevel@tonic-gate #define FP_ICC (int (*)(const void *,const void *)) 4750Sstevel@tonic-gate #define ssl_put_cipher_by_char(ssl,ciph,ptr) \ 4760Sstevel@tonic-gate ((ssl)->method->put_cipher_by_char((ciph),(ptr))) 4770Sstevel@tonic-gate #define ssl_get_cipher_by_char(ssl,ptr) \ 4780Sstevel@tonic-gate ((ssl)->method->get_cipher_by_char(ptr)) 4790Sstevel@tonic-gate 4800Sstevel@tonic-gate /* This is for the SSLv3/TLSv1.0 differences in crypto/hash stuff 4810Sstevel@tonic-gate * It is a bit of a mess of functions, but hell, think of it as 4820Sstevel@tonic-gate * an opaque structure :-) */ 4830Sstevel@tonic-gate typedef struct ssl3_enc_method 4840Sstevel@tonic-gate { 4850Sstevel@tonic-gate int (*enc)(SSL *, int); 4860Sstevel@tonic-gate int (*mac)(SSL *, unsigned char *, int); 4870Sstevel@tonic-gate int (*setup_key_block)(SSL *); 4880Sstevel@tonic-gate int (*generate_master_secret)(SSL *, unsigned char *, unsigned char *, int); 4890Sstevel@tonic-gate int (*change_cipher_state)(SSL *, int); 4900Sstevel@tonic-gate int (*final_finish_mac)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char *, int, unsigned char *); 4910Sstevel@tonic-gate int finish_mac_length; 4920Sstevel@tonic-gate int (*cert_verify_mac)(SSL *, EVP_MD_CTX *, unsigned char *); 4930Sstevel@tonic-gate const char *client_finished_label; 4940Sstevel@tonic-gate int client_finished_label_len; 4950Sstevel@tonic-gate const char *server_finished_label; 4960Sstevel@tonic-gate int server_finished_label_len; 4970Sstevel@tonic-gate int (*alert_value)(int); 4980Sstevel@tonic-gate } SSL3_ENC_METHOD; 4990Sstevel@tonic-gate 5000Sstevel@tonic-gate /* Used for holding the relevant compression methods loaded into SSL_CTX */ 5010Sstevel@tonic-gate typedef struct ssl3_comp_st 5020Sstevel@tonic-gate { 5030Sstevel@tonic-gate int comp_id; /* The identifier byte for this compression type */ 5040Sstevel@tonic-gate char *name; /* Text name used for the compression type */ 5050Sstevel@tonic-gate COMP_METHOD *method; /* The method :-) */ 5060Sstevel@tonic-gate } SSL3_COMP; 5070Sstevel@tonic-gate 5082139Sjp161948 extern SSL3_ENC_METHOD ssl3_undef_enc_method; 5090Sstevel@tonic-gate OPENSSL_EXTERN SSL_CIPHER ssl2_ciphers[]; 5100Sstevel@tonic-gate OPENSSL_EXTERN SSL_CIPHER ssl3_ciphers[]; 5110Sstevel@tonic-gate 5120Sstevel@tonic-gate 5130Sstevel@tonic-gate SSL_METHOD *ssl_bad_method(int ver); 5140Sstevel@tonic-gate SSL_METHOD *sslv2_base_method(void); 5150Sstevel@tonic-gate SSL_METHOD *sslv23_base_method(void); 5160Sstevel@tonic-gate SSL_METHOD *sslv3_base_method(void); 5170Sstevel@tonic-gate 5182139Sjp161948 extern SSL3_ENC_METHOD TLSv1_enc_data; 5192139Sjp161948 extern SSL3_ENC_METHOD SSLv3_enc_data; 5202139Sjp161948 extern SSL3_ENC_METHOD DTLSv1_enc_data; 5212139Sjp161948 5222139Sjp161948 #define IMPLEMENT_tls1_meth_func(func_name, s_accept, s_connect, s_get_meth) \ 5232139Sjp161948 SSL_METHOD *func_name(void) \ 5242139Sjp161948 { \ 5252139Sjp161948 static SSL_METHOD func_name##_data= { \ 5262139Sjp161948 TLS1_VERSION, \ 5272139Sjp161948 tls1_new, \ 5282139Sjp161948 tls1_clear, \ 5292139Sjp161948 tls1_free, \ 5302139Sjp161948 s_accept, \ 5312139Sjp161948 s_connect, \ 5322139Sjp161948 ssl3_read, \ 5332139Sjp161948 ssl3_peek, \ 5342139Sjp161948 ssl3_write, \ 5352139Sjp161948 ssl3_shutdown, \ 5362139Sjp161948 ssl3_renegotiate, \ 5372139Sjp161948 ssl3_renegotiate_check, \ 5382139Sjp161948 ssl3_get_message, \ 5392139Sjp161948 ssl3_read_bytes, \ 5402139Sjp161948 ssl3_write_bytes, \ 5412139Sjp161948 ssl3_dispatch_alert, \ 5422139Sjp161948 ssl3_ctrl, \ 5432139Sjp161948 ssl3_ctx_ctrl, \ 5442139Sjp161948 ssl3_get_cipher_by_char, \ 5452139Sjp161948 ssl3_put_cipher_by_char, \ 5462139Sjp161948 ssl3_pending, \ 5472139Sjp161948 ssl3_num_ciphers, \ 5482139Sjp161948 ssl3_get_cipher, \ 5492139Sjp161948 s_get_meth, \ 5502139Sjp161948 tls1_default_timeout, \ 5512139Sjp161948 &TLSv1_enc_data, \ 5522139Sjp161948 ssl_undefined_void_function, \ 5532139Sjp161948 ssl3_callback_ctrl, \ 5542139Sjp161948 ssl3_ctx_callback_ctrl, \ 5552139Sjp161948 }; \ 5562139Sjp161948 return &func_name##_data; \ 5572139Sjp161948 } 5582139Sjp161948 5592139Sjp161948 #define IMPLEMENT_ssl3_meth_func(func_name, s_accept, s_connect, s_get_meth) \ 5602139Sjp161948 SSL_METHOD *func_name(void) \ 5612139Sjp161948 { \ 5622139Sjp161948 static SSL_METHOD func_name##_data= { \ 5632139Sjp161948 SSL3_VERSION, \ 5642139Sjp161948 ssl3_new, \ 5652139Sjp161948 ssl3_clear, \ 5662139Sjp161948 ssl3_free, \ 5672139Sjp161948 s_accept, \ 5682139Sjp161948 s_connect, \ 5692139Sjp161948 ssl3_read, \ 5702139Sjp161948 ssl3_peek, \ 5712139Sjp161948 ssl3_write, \ 5722139Sjp161948 ssl3_shutdown, \ 5732139Sjp161948 ssl3_renegotiate, \ 5742139Sjp161948 ssl3_renegotiate_check, \ 5752139Sjp161948 ssl3_get_message, \ 5762139Sjp161948 ssl3_read_bytes, \ 5772139Sjp161948 ssl3_write_bytes, \ 5782139Sjp161948 ssl3_dispatch_alert, \ 5792139Sjp161948 ssl3_ctrl, \ 5802139Sjp161948 ssl3_ctx_ctrl, \ 5812139Sjp161948 ssl3_get_cipher_by_char, \ 5822139Sjp161948 ssl3_put_cipher_by_char, \ 5832139Sjp161948 ssl3_pending, \ 5842139Sjp161948 ssl3_num_ciphers, \ 5852139Sjp161948 ssl3_get_cipher, \ 5862139Sjp161948 s_get_meth, \ 5872139Sjp161948 ssl3_default_timeout, \ 5882139Sjp161948 &SSLv3_enc_data, \ 5892139Sjp161948 ssl_undefined_void_function, \ 5902139Sjp161948 ssl3_callback_ctrl, \ 5912139Sjp161948 ssl3_ctx_callback_ctrl, \ 5922139Sjp161948 }; \ 5932139Sjp161948 return &func_name##_data; \ 5942139Sjp161948 } 5952139Sjp161948 5962139Sjp161948 #define IMPLEMENT_ssl23_meth_func(func_name, s_accept, s_connect, s_get_meth) \ 5972139Sjp161948 SSL_METHOD *func_name(void) \ 5982139Sjp161948 { \ 5992139Sjp161948 static SSL_METHOD func_name##_data= { \ 6002139Sjp161948 TLS1_VERSION, \ 6012139Sjp161948 tls1_new, \ 6022139Sjp161948 tls1_clear, \ 6032139Sjp161948 tls1_free, \ 6042139Sjp161948 s_accept, \ 6052139Sjp161948 s_connect, \ 6062139Sjp161948 ssl23_read, \ 6072139Sjp161948 ssl23_peek, \ 6082139Sjp161948 ssl23_write, \ 6092139Sjp161948 ssl_undefined_function, \ 6102139Sjp161948 ssl_undefined_function, \ 6112139Sjp161948 ssl_ok, \ 6122139Sjp161948 ssl3_get_message, \ 6132139Sjp161948 ssl3_read_bytes, \ 6142139Sjp161948 ssl3_write_bytes, \ 6152139Sjp161948 ssl3_dispatch_alert, \ 6162139Sjp161948 ssl3_ctrl, \ 6172139Sjp161948 ssl3_ctx_ctrl, \ 6182139Sjp161948 ssl23_get_cipher_by_char, \ 6192139Sjp161948 ssl23_put_cipher_by_char, \ 6202139Sjp161948 ssl_undefined_const_function, \ 6212139Sjp161948 ssl23_num_ciphers, \ 6222139Sjp161948 ssl23_get_cipher, \ 6232139Sjp161948 s_get_meth, \ 6242139Sjp161948 ssl23_default_timeout, \ 6252139Sjp161948 &ssl3_undef_enc_method, \ 6262139Sjp161948 ssl_undefined_void_function, \ 6272139Sjp161948 ssl3_callback_ctrl, \ 6282139Sjp161948 ssl3_ctx_callback_ctrl, \ 6292139Sjp161948 }; \ 6302139Sjp161948 return &func_name##_data; \ 6312139Sjp161948 } 6322139Sjp161948 6332139Sjp161948 #define IMPLEMENT_ssl2_meth_func(func_name, s_accept, s_connect, s_get_meth) \ 6342139Sjp161948 SSL_METHOD *func_name(void) \ 6352139Sjp161948 { \ 6362139Sjp161948 static SSL_METHOD func_name##_data= { \ 6372139Sjp161948 SSL2_VERSION, \ 6382139Sjp161948 ssl2_new, /* local */ \ 6392139Sjp161948 ssl2_clear, /* local */ \ 6402139Sjp161948 ssl2_free, /* local */ \ 6412139Sjp161948 s_accept, \ 6422139Sjp161948 s_connect, \ 6432139Sjp161948 ssl2_read, \ 6442139Sjp161948 ssl2_peek, \ 6452139Sjp161948 ssl2_write, \ 6462139Sjp161948 ssl2_shutdown, \ 6472139Sjp161948 ssl_ok, /* NULL - renegotiate */ \ 6482139Sjp161948 ssl_ok, /* NULL - check renegotiate */ \ 6492139Sjp161948 NULL, /* NULL - ssl_get_message */ \ 6502139Sjp161948 NULL, /* NULL - ssl_get_record */ \ 6512139Sjp161948 NULL, /* NULL - ssl_write_bytes */ \ 6522139Sjp161948 NULL, /* NULL - dispatch_alert */ \ 6532139Sjp161948 ssl2_ctrl, /* local */ \ 6542139Sjp161948 ssl2_ctx_ctrl, /* local */ \ 6552139Sjp161948 ssl2_get_cipher_by_char, \ 6562139Sjp161948 ssl2_put_cipher_by_char, \ 6572139Sjp161948 ssl2_pending, \ 6582139Sjp161948 ssl2_num_ciphers, \ 6592139Sjp161948 ssl2_get_cipher, \ 6602139Sjp161948 s_get_meth, \ 6612139Sjp161948 ssl2_default_timeout, \ 6622139Sjp161948 &ssl3_undef_enc_method, \ 6632139Sjp161948 ssl_undefined_void_function, \ 6642139Sjp161948 ssl2_callback_ctrl, /* local */ \ 6652139Sjp161948 ssl2_ctx_callback_ctrl, /* local */ \ 6662139Sjp161948 }; \ 6672139Sjp161948 return &func_name##_data; \ 6682139Sjp161948 } 6692139Sjp161948 6702139Sjp161948 #define IMPLEMENT_dtls1_meth_func(func_name, s_accept, s_connect, s_get_meth) \ 6712139Sjp161948 SSL_METHOD *func_name(void) \ 6722139Sjp161948 { \ 6732139Sjp161948 static SSL_METHOD func_name##_data= { \ 6742139Sjp161948 DTLS1_VERSION, \ 6752139Sjp161948 dtls1_new, \ 6762139Sjp161948 dtls1_clear, \ 6772139Sjp161948 dtls1_free, \ 6782139Sjp161948 s_accept, \ 6792139Sjp161948 s_connect, \ 6802139Sjp161948 ssl3_read, \ 6812139Sjp161948 ssl3_peek, \ 6822139Sjp161948 ssl3_write, \ 6832139Sjp161948 ssl3_shutdown, \ 6842139Sjp161948 ssl3_renegotiate, \ 6852139Sjp161948 ssl3_renegotiate_check, \ 6862139Sjp161948 dtls1_get_message, \ 6872139Sjp161948 dtls1_read_bytes, \ 6882139Sjp161948 dtls1_write_app_data_bytes, \ 6892139Sjp161948 dtls1_dispatch_alert, \ 6902139Sjp161948 ssl3_ctrl, \ 6912139Sjp161948 ssl3_ctx_ctrl, \ 6922139Sjp161948 ssl3_get_cipher_by_char, \ 6932139Sjp161948 ssl3_put_cipher_by_char, \ 6942139Sjp161948 ssl3_pending, \ 6952139Sjp161948 ssl3_num_ciphers, \ 696*5434Sjp161948 dtls1_get_cipher, \ 6972139Sjp161948 s_get_meth, \ 6982139Sjp161948 dtls1_default_timeout, \ 6992139Sjp161948 &DTLSv1_enc_data, \ 7002139Sjp161948 ssl_undefined_void_function, \ 7012139Sjp161948 ssl3_callback_ctrl, \ 7022139Sjp161948 ssl3_ctx_callback_ctrl, \ 7032139Sjp161948 }; \ 7042139Sjp161948 return &func_name##_data; \ 7052139Sjp161948 } 7062139Sjp161948 7070Sstevel@tonic-gate void ssl_clear_cipher_ctx(SSL *s); 7080Sstevel@tonic-gate int ssl_clear_bad_session(SSL *s); 7090Sstevel@tonic-gate CERT *ssl_cert_new(void); 7100Sstevel@tonic-gate CERT *ssl_cert_dup(CERT *cert); 7110Sstevel@tonic-gate int ssl_cert_inst(CERT **o); 7120Sstevel@tonic-gate void ssl_cert_free(CERT *c); 7130Sstevel@tonic-gate SESS_CERT *ssl_sess_cert_new(void); 7140Sstevel@tonic-gate void ssl_sess_cert_free(SESS_CERT *sc); 7150Sstevel@tonic-gate int ssl_set_peer_cert_type(SESS_CERT *c, int type); 7160Sstevel@tonic-gate int ssl_get_new_session(SSL *s, int session); 7170Sstevel@tonic-gate int ssl_get_prev_session(SSL *s, unsigned char *session,int len); 7180Sstevel@tonic-gate int ssl_cipher_id_cmp(const SSL_CIPHER *a,const SSL_CIPHER *b); 7190Sstevel@tonic-gate int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap, 7200Sstevel@tonic-gate const SSL_CIPHER * const *bp); 7210Sstevel@tonic-gate STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num, 7220Sstevel@tonic-gate STACK_OF(SSL_CIPHER) **skp); 7232139Sjp161948 int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p, 7242139Sjp161948 int (*put_cb)(const SSL_CIPHER *, unsigned char *)); 7250Sstevel@tonic-gate STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth, 7260Sstevel@tonic-gate STACK_OF(SSL_CIPHER) **pref, 7270Sstevel@tonic-gate STACK_OF(SSL_CIPHER) **sorted, 7280Sstevel@tonic-gate const char *rule_str); 7290Sstevel@tonic-gate void ssl_update_cache(SSL *s, int mode); 7302139Sjp161948 int ssl_cipher_get_evp(const SSL_SESSION *s,const EVP_CIPHER **enc, 7312139Sjp161948 const EVP_MD **md,SSL_COMP **comp); 7320Sstevel@tonic-gate int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk); 7330Sstevel@tonic-gate int ssl_undefined_function(SSL *s); 7342139Sjp161948 int ssl_undefined_void_function(void); 7352139Sjp161948 int ssl_undefined_const_function(const SSL *s); 7360Sstevel@tonic-gate X509 *ssl_get_server_send_cert(SSL *); 7370Sstevel@tonic-gate EVP_PKEY *ssl_get_sign_pkey(SSL *,SSL_CIPHER *); 7380Sstevel@tonic-gate int ssl_cert_type(X509 *x,EVP_PKEY *pkey); 7390Sstevel@tonic-gate void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher); 7400Sstevel@tonic-gate STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s); 7410Sstevel@tonic-gate int ssl_verify_alarm_type(long type); 7422139Sjp161948 void ssl_load_ciphers(void); 7430Sstevel@tonic-gate 7440Sstevel@tonic-gate int ssl2_enc_init(SSL *s, int client); 7450Sstevel@tonic-gate int ssl2_generate_key_material(SSL *s); 7460Sstevel@tonic-gate void ssl2_enc(SSL *s,int send_data); 7470Sstevel@tonic-gate void ssl2_mac(SSL *s,unsigned char *mac,int send_data); 7480Sstevel@tonic-gate SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p); 7490Sstevel@tonic-gate int ssl2_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p); 7500Sstevel@tonic-gate int ssl2_part_read(SSL *s, unsigned long f, int i); 7510Sstevel@tonic-gate int ssl2_do_write(SSL *s); 7522139Sjp161948 int ssl2_set_certificate(SSL *s, int type, int len, const unsigned char *data); 7530Sstevel@tonic-gate void ssl2_return_error(SSL *s,int reason); 7540Sstevel@tonic-gate void ssl2_write_error(SSL *s); 7550Sstevel@tonic-gate int ssl2_num_ciphers(void); 7560Sstevel@tonic-gate SSL_CIPHER *ssl2_get_cipher(unsigned int u); 7570Sstevel@tonic-gate int ssl2_new(SSL *s); 7580Sstevel@tonic-gate void ssl2_free(SSL *s); 7590Sstevel@tonic-gate int ssl2_accept(SSL *s); 7600Sstevel@tonic-gate int ssl2_connect(SSL *s); 7610Sstevel@tonic-gate int ssl2_read(SSL *s, void *buf, int len); 7620Sstevel@tonic-gate int ssl2_peek(SSL *s, void *buf, int len); 7630Sstevel@tonic-gate int ssl2_write(SSL *s, const void *buf, int len); 7640Sstevel@tonic-gate int ssl2_shutdown(SSL *s); 7650Sstevel@tonic-gate void ssl2_clear(SSL *s); 7660Sstevel@tonic-gate long ssl2_ctrl(SSL *s,int cmd, long larg, void *parg); 7670Sstevel@tonic-gate long ssl2_ctx_ctrl(SSL_CTX *s,int cmd, long larg, void *parg); 7682139Sjp161948 long ssl2_callback_ctrl(SSL *s,int cmd, void (*fp)(void)); 7692139Sjp161948 long ssl2_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)(void)); 7702139Sjp161948 int ssl2_pending(const SSL *s); 7712139Sjp161948 long ssl2_default_timeout(void ); 7720Sstevel@tonic-gate 7730Sstevel@tonic-gate SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p); 7740Sstevel@tonic-gate int ssl3_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p); 7750Sstevel@tonic-gate void ssl3_init_finished_mac(SSL *s); 7760Sstevel@tonic-gate int ssl3_send_server_certificate(SSL *s); 7770Sstevel@tonic-gate int ssl3_get_finished(SSL *s,int state_a,int state_b); 7780Sstevel@tonic-gate int ssl3_setup_key_block(SSL *s); 7790Sstevel@tonic-gate int ssl3_send_change_cipher_spec(SSL *s,int state_a,int state_b); 7800Sstevel@tonic-gate int ssl3_change_cipher_state(SSL *s,int which); 7810Sstevel@tonic-gate void ssl3_cleanup_key_block(SSL *s); 7820Sstevel@tonic-gate int ssl3_do_write(SSL *s,int type); 7830Sstevel@tonic-gate void ssl3_send_alert(SSL *s,int level, int desc); 7840Sstevel@tonic-gate int ssl3_generate_master_secret(SSL *s, unsigned char *out, 7850Sstevel@tonic-gate unsigned char *p, int len); 7860Sstevel@tonic-gate int ssl3_get_req_cert_type(SSL *s,unsigned char *p); 7870Sstevel@tonic-gate long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok); 7880Sstevel@tonic-gate int ssl3_send_finished(SSL *s, int a, int b, const char *sender,int slen); 7890Sstevel@tonic-gate int ssl3_num_ciphers(void); 7900Sstevel@tonic-gate SSL_CIPHER *ssl3_get_cipher(unsigned int u); 7910Sstevel@tonic-gate int ssl3_renegotiate(SSL *ssl); 7920Sstevel@tonic-gate int ssl3_renegotiate_check(SSL *ssl); 7930Sstevel@tonic-gate int ssl3_dispatch_alert(SSL *s); 7940Sstevel@tonic-gate int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek); 7950Sstevel@tonic-gate int ssl3_write_bytes(SSL *s, int type, const void *buf, int len); 7960Sstevel@tonic-gate int ssl3_final_finish_mac(SSL *s, EVP_MD_CTX *ctx1, EVP_MD_CTX *ctx2, 7970Sstevel@tonic-gate const char *sender, int slen,unsigned char *p); 7980Sstevel@tonic-gate int ssl3_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p); 7990Sstevel@tonic-gate void ssl3_finish_mac(SSL *s, const unsigned char *buf, int len); 8000Sstevel@tonic-gate int ssl3_enc(SSL *s, int send_data); 8010Sstevel@tonic-gate int ssl3_mac(SSL *ssl, unsigned char *md, int send_data); 8020Sstevel@tonic-gate unsigned long ssl3_output_cert_chain(SSL *s, X509 *x); 8030Sstevel@tonic-gate SSL_CIPHER *ssl3_choose_cipher(SSL *ssl,STACK_OF(SSL_CIPHER) *clnt, 8040Sstevel@tonic-gate STACK_OF(SSL_CIPHER) *srvr); 8050Sstevel@tonic-gate int ssl3_setup_buffers(SSL *s); 8060Sstevel@tonic-gate int ssl3_new(SSL *s); 8070Sstevel@tonic-gate void ssl3_free(SSL *s); 8080Sstevel@tonic-gate int ssl3_accept(SSL *s); 8090Sstevel@tonic-gate int ssl3_connect(SSL *s); 8100Sstevel@tonic-gate int ssl3_read(SSL *s, void *buf, int len); 8110Sstevel@tonic-gate int ssl3_peek(SSL *s, void *buf, int len); 8120Sstevel@tonic-gate int ssl3_write(SSL *s, const void *buf, int len); 8130Sstevel@tonic-gate int ssl3_shutdown(SSL *s); 8140Sstevel@tonic-gate void ssl3_clear(SSL *s); 8150Sstevel@tonic-gate long ssl3_ctrl(SSL *s,int cmd, long larg, void *parg); 8160Sstevel@tonic-gate long ssl3_ctx_ctrl(SSL_CTX *s,int cmd, long larg, void *parg); 8172139Sjp161948 long ssl3_callback_ctrl(SSL *s,int cmd, void (*fp)(void)); 8182139Sjp161948 long ssl3_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)(void)); 8192139Sjp161948 int ssl3_pending(const SSL *s); 8202139Sjp161948 8212139Sjp161948 void ssl3_record_sequence_update(unsigned char *seq); 8222139Sjp161948 int ssl3_do_change_cipher_spec(SSL *ssl); 8232139Sjp161948 long ssl3_default_timeout(void ); 8242139Sjp161948 8252139Sjp161948 int ssl23_num_ciphers(void ); 8262139Sjp161948 SSL_CIPHER *ssl23_get_cipher(unsigned int u); 8272139Sjp161948 int ssl23_read(SSL *s, void *buf, int len); 8282139Sjp161948 int ssl23_peek(SSL *s, void *buf, int len); 8292139Sjp161948 int ssl23_write(SSL *s, const void *buf, int len); 8302139Sjp161948 int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p); 8312139Sjp161948 SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p); 8322139Sjp161948 long ssl23_default_timeout(void ); 8332139Sjp161948 8342139Sjp161948 long tls1_default_timeout(void); 8352139Sjp161948 int dtls1_do_write(SSL *s,int type); 8362139Sjp161948 int ssl3_read_n(SSL *s, int n, int max, int extend); 8372139Sjp161948 int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek); 8382139Sjp161948 int ssl3_do_compress(SSL *ssl); 8392139Sjp161948 int ssl3_do_uncompress(SSL *ssl); 8402139Sjp161948 int ssl3_write_pending(SSL *s, int type, const unsigned char *buf, 8412139Sjp161948 unsigned int len); 8422139Sjp161948 unsigned char *dtls1_set_message_header(SSL *s, 8432139Sjp161948 unsigned char *p, unsigned char mt, unsigned long len, 8442139Sjp161948 unsigned long frag_off, unsigned long frag_len); 8452139Sjp161948 8462139Sjp161948 int dtls1_write_app_data_bytes(SSL *s, int type, const void *buf, int len); 8472139Sjp161948 int dtls1_write_bytes(SSL *s, int type, const void *buf, int len); 8482139Sjp161948 8492139Sjp161948 int dtls1_send_change_cipher_spec(SSL *s, int a, int b); 8502139Sjp161948 int dtls1_send_finished(SSL *s, int a, int b, const char *sender, int slen); 8512139Sjp161948 unsigned long dtls1_output_cert_chain(SSL *s, X509 *x); 8522139Sjp161948 int dtls1_read_failed(SSL *s, int code); 8532139Sjp161948 int dtls1_buffer_message(SSL *s, int ccs); 8542139Sjp161948 int dtls1_retransmit_message(SSL *s, unsigned short seq, 8552139Sjp161948 unsigned long frag_off, int *found); 8562139Sjp161948 void dtls1_clear_record_buffer(SSL *s); 8572139Sjp161948 void dtls1_get_message_header(unsigned char *data, struct hm_header_st *msg_hdr); 8582139Sjp161948 void dtls1_get_ccs_header(unsigned char *data, struct ccs_header_st *ccs_hdr); 8592139Sjp161948 void dtls1_reset_seq_numbers(SSL *s, int rw); 8602139Sjp161948 long dtls1_default_timeout(void); 861*5434Sjp161948 SSL_CIPHER *dtls1_get_cipher(unsigned int u); 8622139Sjp161948 8632139Sjp161948 8642139Sjp161948 /* some client-only functions */ 8652139Sjp161948 int ssl3_client_hello(SSL *s); 8662139Sjp161948 int ssl3_get_server_hello(SSL *s); 8672139Sjp161948 int ssl3_get_certificate_request(SSL *s); 8682139Sjp161948 int ssl3_get_server_done(SSL *s); 8692139Sjp161948 int ssl3_send_client_verify(SSL *s); 8702139Sjp161948 int ssl3_send_client_certificate(SSL *s); 8712139Sjp161948 int ssl3_send_client_key_exchange(SSL *s); 8722139Sjp161948 int ssl3_get_key_exchange(SSL *s); 8732139Sjp161948 int ssl3_get_server_certificate(SSL *s); 8742139Sjp161948 int ssl3_check_cert_and_algorithm(SSL *s); 8752139Sjp161948 8762139Sjp161948 int dtls1_client_hello(SSL *s); 8772139Sjp161948 int dtls1_send_client_certificate(SSL *s); 8782139Sjp161948 int dtls1_send_client_key_exchange(SSL *s); 8792139Sjp161948 int dtls1_send_client_verify(SSL *s); 8802139Sjp161948 8812139Sjp161948 /* some server-only functions */ 8822139Sjp161948 int ssl3_get_client_hello(SSL *s); 8832139Sjp161948 int ssl3_send_server_hello(SSL *s); 8842139Sjp161948 int ssl3_send_hello_request(SSL *s); 8852139Sjp161948 int ssl3_send_server_key_exchange(SSL *s); 8862139Sjp161948 int ssl3_send_certificate_request(SSL *s); 8872139Sjp161948 int ssl3_send_server_done(SSL *s); 8882139Sjp161948 int ssl3_check_client_hello(SSL *s); 8892139Sjp161948 int ssl3_get_client_certificate(SSL *s); 8902139Sjp161948 int ssl3_get_client_key_exchange(SSL *s); 8912139Sjp161948 int ssl3_get_cert_verify(SSL *s); 8922139Sjp161948 8932139Sjp161948 int dtls1_send_hello_request(SSL *s); 8942139Sjp161948 int dtls1_send_server_hello(SSL *s); 8952139Sjp161948 int dtls1_send_server_certificate(SSL *s); 8962139Sjp161948 int dtls1_send_server_key_exchange(SSL *s); 8972139Sjp161948 int dtls1_send_certificate_request(SSL *s); 8982139Sjp161948 int dtls1_send_server_done(SSL *s); 8992139Sjp161948 9002139Sjp161948 9010Sstevel@tonic-gate 9020Sstevel@tonic-gate int ssl23_accept(SSL *s); 9030Sstevel@tonic-gate int ssl23_connect(SSL *s); 9040Sstevel@tonic-gate int ssl23_read_bytes(SSL *s, int n); 9050Sstevel@tonic-gate int ssl23_write_bytes(SSL *s); 9060Sstevel@tonic-gate 9070Sstevel@tonic-gate int tls1_new(SSL *s); 9080Sstevel@tonic-gate void tls1_free(SSL *s); 9090Sstevel@tonic-gate void tls1_clear(SSL *s); 9100Sstevel@tonic-gate long tls1_ctrl(SSL *s,int cmd, long larg, void *parg); 9112139Sjp161948 long tls1_callback_ctrl(SSL *s,int cmd, void (*fp)(void)); 9120Sstevel@tonic-gate SSL_METHOD *tlsv1_base_method(void ); 9130Sstevel@tonic-gate 9142139Sjp161948 int dtls1_new(SSL *s); 9152139Sjp161948 int dtls1_accept(SSL *s); 9162139Sjp161948 int dtls1_connect(SSL *s); 9172139Sjp161948 void dtls1_free(SSL *s); 9182139Sjp161948 void dtls1_clear(SSL *s); 9192139Sjp161948 long dtls1_ctrl(SSL *s,int cmd, long larg, void *parg); 9202139Sjp161948 SSL_METHOD *dtlsv1_base_method(void ); 9212139Sjp161948 9222139Sjp161948 long dtls1_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok); 9232139Sjp161948 int dtls1_get_record(SSL *s); 9242139Sjp161948 int do_dtls1_write(SSL *s, int type, const unsigned char *buf, 9252139Sjp161948 unsigned int len, int create_empty_fragement); 9262139Sjp161948 int dtls1_dispatch_alert(SSL *s); 9272139Sjp161948 int dtls1_enc(SSL *s, int snd); 9282139Sjp161948 9290Sstevel@tonic-gate int ssl_init_wbio_buffer(SSL *s, int push); 9300Sstevel@tonic-gate void ssl_free_wbio_buffer(SSL *s); 9310Sstevel@tonic-gate 9320Sstevel@tonic-gate int tls1_change_cipher_state(SSL *s, int which); 9330Sstevel@tonic-gate int tls1_setup_key_block(SSL *s); 9340Sstevel@tonic-gate int tls1_enc(SSL *s, int snd); 9350Sstevel@tonic-gate int tls1_final_finish_mac(SSL *s, EVP_MD_CTX *in1_ctx, EVP_MD_CTX *in2_ctx, 9360Sstevel@tonic-gate const char *str, int slen, unsigned char *p); 9370Sstevel@tonic-gate int tls1_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p); 9380Sstevel@tonic-gate int tls1_mac(SSL *ssl, unsigned char *md, int snd); 9390Sstevel@tonic-gate int tls1_generate_master_secret(SSL *s, unsigned char *out, 9400Sstevel@tonic-gate unsigned char *p, int len); 9410Sstevel@tonic-gate int tls1_alert_code(int code); 9420Sstevel@tonic-gate int ssl3_alert_code(int code); 9430Sstevel@tonic-gate int ssl_ok(SSL *s); 9440Sstevel@tonic-gate 9452139Sjp161948 int check_srvr_ecc_cert_and_alg(X509 *x, SSL_CIPHER *cs); 9462139Sjp161948 9470Sstevel@tonic-gate SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n); 9480Sstevel@tonic-gate 9490Sstevel@tonic-gate 9500Sstevel@tonic-gate #endif 951