xref: /freebsd/crypto/openssl/ssl/ssl_local.h (revision eee55a22b20214ca41cd6b1bbea79b863c8c11ac)
117f01e99SJung-uk Kim /*
283eaf7aeSJung-uk Kim  * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
317f01e99SJung-uk Kim  * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
417f01e99SJung-uk Kim  * Copyright 2005 Nokia. All rights reserved.
517f01e99SJung-uk Kim  *
6b077aed3SPierre Pronchery  * Licensed under the Apache License 2.0 (the "License").  You may not use
717f01e99SJung-uk Kim  * this file except in compliance with the License.  You can obtain a copy
817f01e99SJung-uk Kim  * in the file LICENSE in the source distribution or at
917f01e99SJung-uk Kim  * https://www.openssl.org/source/license.html
1017f01e99SJung-uk Kim  */
1117f01e99SJung-uk Kim 
1217f01e99SJung-uk Kim #ifndef OSSL_SSL_LOCAL_H
1317f01e99SJung-uk Kim # define OSSL_SSL_LOCAL_H
1417f01e99SJung-uk Kim 
1517f01e99SJung-uk Kim # include "e_os.h"              /* struct timeval for DTLS */
1617f01e99SJung-uk Kim # include <stdlib.h>
1717f01e99SJung-uk Kim # include <time.h>
1817f01e99SJung-uk Kim # include <string.h>
1917f01e99SJung-uk Kim # include <errno.h>
2017f01e99SJung-uk Kim 
2117f01e99SJung-uk Kim # include <openssl/buffer.h>
2217f01e99SJung-uk Kim # include <openssl/comp.h>
2317f01e99SJung-uk Kim # include <openssl/bio.h>
2417f01e99SJung-uk Kim # include <openssl/dsa.h>
2517f01e99SJung-uk Kim # include <openssl/err.h>
2617f01e99SJung-uk Kim # include <openssl/ssl.h>
2717f01e99SJung-uk Kim # include <openssl/async.h>
2817f01e99SJung-uk Kim # include <openssl/symhacks.h>
2917f01e99SJung-uk Kim # include <openssl/ct.h>
3017f01e99SJung-uk Kim # include "record/record.h"
3117f01e99SJung-uk Kim # include "statem/statem.h"
32b077aed3SPierre Pronchery # include "internal/packet.h"
3317f01e99SJung-uk Kim # include "internal/dane.h"
3417f01e99SJung-uk Kim # include "internal/refcount.h"
3517f01e99SJung-uk Kim # include "internal/tsan_assist.h"
36aa906e2aSJohn Baldwin # include "internal/bio.h"
37aa906e2aSJohn Baldwin # include "internal/ktls.h"
3817f01e99SJung-uk Kim 
3917f01e99SJung-uk Kim # ifdef OPENSSL_BUILD_SHLIBSSL
4017f01e99SJung-uk Kim #  undef OPENSSL_EXTERN
4117f01e99SJung-uk Kim #  define OPENSSL_EXTERN OPENSSL_EXPORT
4217f01e99SJung-uk Kim # endif
4317f01e99SJung-uk Kim 
4417f01e99SJung-uk Kim # define c2l(c,l)        (l = ((unsigned long)(*((c)++)))     , \
4517f01e99SJung-uk Kim                          l|=(((unsigned long)(*((c)++)))<< 8), \
4617f01e99SJung-uk Kim                          l|=(((unsigned long)(*((c)++)))<<16), \
4717f01e99SJung-uk Kim                          l|=(((unsigned long)(*((c)++)))<<24))
4817f01e99SJung-uk Kim 
4917f01e99SJung-uk Kim /* NOTE - c is not incremented as per c2l */
5017f01e99SJung-uk Kim # define c2ln(c,l1,l2,n) { \
5117f01e99SJung-uk Kim                         c+=n; \
5217f01e99SJung-uk Kim                         l1=l2=0; \
5317f01e99SJung-uk Kim                         switch (n) { \
5417f01e99SJung-uk Kim                         case 8: l2 =((unsigned long)(*(--(c))))<<24; \
5517f01e99SJung-uk Kim                         case 7: l2|=((unsigned long)(*(--(c))))<<16; \
5617f01e99SJung-uk Kim                         case 6: l2|=((unsigned long)(*(--(c))))<< 8; \
5717f01e99SJung-uk Kim                         case 5: l2|=((unsigned long)(*(--(c))));     \
5817f01e99SJung-uk Kim                         case 4: l1 =((unsigned long)(*(--(c))))<<24; \
5917f01e99SJung-uk Kim                         case 3: l1|=((unsigned long)(*(--(c))))<<16; \
6017f01e99SJung-uk Kim                         case 2: l1|=((unsigned long)(*(--(c))))<< 8; \
6117f01e99SJung-uk Kim                         case 1: l1|=((unsigned long)(*(--(c))));     \
6217f01e99SJung-uk Kim                                 } \
6317f01e99SJung-uk Kim                         }
6417f01e99SJung-uk Kim 
6517f01e99SJung-uk Kim # define l2c(l,c)        (*((c)++)=(unsigned char)(((l)    )&0xff), \
6617f01e99SJung-uk Kim                          *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
6717f01e99SJung-uk Kim                          *((c)++)=(unsigned char)(((l)>>16)&0xff), \
6817f01e99SJung-uk Kim                          *((c)++)=(unsigned char)(((l)>>24)&0xff))
6917f01e99SJung-uk Kim 
7017f01e99SJung-uk Kim # define n2l(c,l)        (l =((unsigned long)(*((c)++)))<<24, \
7117f01e99SJung-uk Kim                          l|=((unsigned long)(*((c)++)))<<16, \
7217f01e99SJung-uk Kim                          l|=((unsigned long)(*((c)++)))<< 8, \
7317f01e99SJung-uk Kim                          l|=((unsigned long)(*((c)++))))
7417f01e99SJung-uk Kim 
7517f01e99SJung-uk Kim # define n2l8(c,l)       (l =((uint64_t)(*((c)++)))<<56, \
7617f01e99SJung-uk Kim                          l|=((uint64_t)(*((c)++)))<<48, \
7717f01e99SJung-uk Kim                          l|=((uint64_t)(*((c)++)))<<40, \
7817f01e99SJung-uk Kim                          l|=((uint64_t)(*((c)++)))<<32, \
7917f01e99SJung-uk Kim                          l|=((uint64_t)(*((c)++)))<<24, \
8017f01e99SJung-uk Kim                          l|=((uint64_t)(*((c)++)))<<16, \
8117f01e99SJung-uk Kim                          l|=((uint64_t)(*((c)++)))<< 8, \
8217f01e99SJung-uk Kim                          l|=((uint64_t)(*((c)++))))
8317f01e99SJung-uk Kim 
8417f01e99SJung-uk Kim 
8517f01e99SJung-uk Kim # define l2n(l,c)        (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
8617f01e99SJung-uk Kim                          *((c)++)=(unsigned char)(((l)>>16)&0xff), \
8717f01e99SJung-uk Kim                          *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
8817f01e99SJung-uk Kim                          *((c)++)=(unsigned char)(((l)    )&0xff))
8917f01e99SJung-uk Kim 
9017f01e99SJung-uk Kim # define l2n6(l,c)       (*((c)++)=(unsigned char)(((l)>>40)&0xff), \
9117f01e99SJung-uk Kim                          *((c)++)=(unsigned char)(((l)>>32)&0xff), \
9217f01e99SJung-uk Kim                          *((c)++)=(unsigned char)(((l)>>24)&0xff), \
9317f01e99SJung-uk Kim                          *((c)++)=(unsigned char)(((l)>>16)&0xff), \
9417f01e99SJung-uk Kim                          *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
9517f01e99SJung-uk Kim                          *((c)++)=(unsigned char)(((l)    )&0xff))
9617f01e99SJung-uk Kim 
9717f01e99SJung-uk Kim # define l2n8(l,c)       (*((c)++)=(unsigned char)(((l)>>56)&0xff), \
9817f01e99SJung-uk Kim                          *((c)++)=(unsigned char)(((l)>>48)&0xff), \
9917f01e99SJung-uk Kim                          *((c)++)=(unsigned char)(((l)>>40)&0xff), \
10017f01e99SJung-uk Kim                          *((c)++)=(unsigned char)(((l)>>32)&0xff), \
10117f01e99SJung-uk Kim                          *((c)++)=(unsigned char)(((l)>>24)&0xff), \
10217f01e99SJung-uk Kim                          *((c)++)=(unsigned char)(((l)>>16)&0xff), \
10317f01e99SJung-uk Kim                          *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
10417f01e99SJung-uk Kim                          *((c)++)=(unsigned char)(((l)    )&0xff))
10517f01e99SJung-uk Kim 
10617f01e99SJung-uk Kim /* NOTE - c is not incremented as per l2c */
10717f01e99SJung-uk Kim # define l2cn(l1,l2,c,n) { \
10817f01e99SJung-uk Kim                         c+=n; \
10917f01e99SJung-uk Kim                         switch (n) { \
11017f01e99SJung-uk Kim                         case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
11117f01e99SJung-uk Kim                         case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
11217f01e99SJung-uk Kim                         case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
11317f01e99SJung-uk Kim                         case 5: *(--(c))=(unsigned char)(((l2)    )&0xff); \
11417f01e99SJung-uk Kim                         case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
11517f01e99SJung-uk Kim                         case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
11617f01e99SJung-uk Kim                         case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
11717f01e99SJung-uk Kim                         case 1: *(--(c))=(unsigned char)(((l1)    )&0xff); \
11817f01e99SJung-uk Kim                                 } \
11917f01e99SJung-uk Kim                         }
12017f01e99SJung-uk Kim 
12117f01e99SJung-uk Kim # define n2s(c,s)        ((s=(((unsigned int)((c)[0]))<< 8)| \
12217f01e99SJung-uk Kim                              (((unsigned int)((c)[1]))    )),(c)+=2)
12317f01e99SJung-uk Kim # define s2n(s,c)        (((c)[0]=(unsigned char)(((s)>> 8)&0xff), \
12417f01e99SJung-uk Kim                            (c)[1]=(unsigned char)(((s)    )&0xff)),(c)+=2)
12517f01e99SJung-uk Kim 
12617f01e99SJung-uk Kim # define n2l3(c,l)       ((l =(((unsigned long)((c)[0]))<<16)| \
12717f01e99SJung-uk Kim                               (((unsigned long)((c)[1]))<< 8)| \
12817f01e99SJung-uk Kim                               (((unsigned long)((c)[2]))    )),(c)+=3)
12917f01e99SJung-uk Kim 
13017f01e99SJung-uk Kim # define l2n3(l,c)       (((c)[0]=(unsigned char)(((l)>>16)&0xff), \
13117f01e99SJung-uk Kim                            (c)[1]=(unsigned char)(((l)>> 8)&0xff), \
13217f01e99SJung-uk Kim                            (c)[2]=(unsigned char)(((l)    )&0xff)),(c)+=3)
13317f01e99SJung-uk Kim 
134b077aed3SPierre Pronchery # define TLS_MAX_VERSION_INTERNAL TLS1_3_VERSION
135b077aed3SPierre Pronchery # define DTLS_MAX_VERSION_INTERNAL DTLS1_2_VERSION
136b077aed3SPierre Pronchery 
13717f01e99SJung-uk Kim /*
13817f01e99SJung-uk Kim  * DTLS version numbers are strange because they're inverted. Except for
13917f01e99SJung-uk Kim  * DTLS1_BAD_VER, which should be considered "lower" than the rest.
14017f01e99SJung-uk Kim  */
14117f01e99SJung-uk Kim # define dtls_ver_ordinal(v1) (((v1) == DTLS1_BAD_VER) ? 0xff00 : (v1))
14217f01e99SJung-uk Kim # define DTLS_VERSION_GT(v1, v2) (dtls_ver_ordinal(v1) < dtls_ver_ordinal(v2))
14317f01e99SJung-uk Kim # define DTLS_VERSION_GE(v1, v2) (dtls_ver_ordinal(v1) <= dtls_ver_ordinal(v2))
14417f01e99SJung-uk Kim # define DTLS_VERSION_LT(v1, v2) (dtls_ver_ordinal(v1) > dtls_ver_ordinal(v2))
14517f01e99SJung-uk Kim # define DTLS_VERSION_LE(v1, v2) (dtls_ver_ordinal(v1) >= dtls_ver_ordinal(v2))
14617f01e99SJung-uk Kim 
14717f01e99SJung-uk Kim 
14817f01e99SJung-uk Kim /*
14917f01e99SJung-uk Kim  * Define the Bitmasks for SSL_CIPHER.algorithms.
15017f01e99SJung-uk Kim  * This bits are used packed as dense as possible. If new methods/ciphers
15117f01e99SJung-uk Kim  * etc will be added, the bits a likely to change, so this information
15217f01e99SJung-uk Kim  * is for internal library use only, even though SSL_CIPHER.algorithms
15317f01e99SJung-uk Kim  * can be publicly accessed.
15417f01e99SJung-uk Kim  * Use the according functions for cipher management instead.
15517f01e99SJung-uk Kim  *
15617f01e99SJung-uk Kim  * The bit mask handling in the selection and sorting scheme in
15717f01e99SJung-uk Kim  * ssl_create_cipher_list() has only limited capabilities, reflecting
15817f01e99SJung-uk Kim  * that the different entities within are mutually exclusive:
15917f01e99SJung-uk Kim  * ONLY ONE BIT PER MASK CAN BE SET AT A TIME.
16017f01e99SJung-uk Kim  */
16117f01e99SJung-uk Kim 
16217f01e99SJung-uk Kim /* Bits for algorithm_mkey (key exchange algorithm) */
16317f01e99SJung-uk Kim /* RSA key exchange */
16417f01e99SJung-uk Kim # define SSL_kRSA                0x00000001U
16517f01e99SJung-uk Kim /* tmp DH key no DH cert */
16617f01e99SJung-uk Kim # define SSL_kDHE                0x00000002U
16717f01e99SJung-uk Kim /* synonym */
16817f01e99SJung-uk Kim # define SSL_kEDH                SSL_kDHE
16917f01e99SJung-uk Kim /* ephemeral ECDH */
17017f01e99SJung-uk Kim # define SSL_kECDHE              0x00000004U
17117f01e99SJung-uk Kim /* synonym */
17217f01e99SJung-uk Kim # define SSL_kEECDH              SSL_kECDHE
17317f01e99SJung-uk Kim /* PSK */
17417f01e99SJung-uk Kim # define SSL_kPSK                0x00000008U
17517f01e99SJung-uk Kim /* GOST key exchange */
17617f01e99SJung-uk Kim # define SSL_kGOST               0x00000010U
17717f01e99SJung-uk Kim /* SRP */
17817f01e99SJung-uk Kim # define SSL_kSRP                0x00000020U
17917f01e99SJung-uk Kim 
18017f01e99SJung-uk Kim # define SSL_kRSAPSK             0x00000040U
18117f01e99SJung-uk Kim # define SSL_kECDHEPSK           0x00000080U
18217f01e99SJung-uk Kim # define SSL_kDHEPSK             0x00000100U
183b077aed3SPierre Pronchery /* GOST KDF key exchange, draft-smyshlyaev-tls12-gost-suites */
184b077aed3SPierre Pronchery # define SSL_kGOST18             0x00000200U
18517f01e99SJung-uk Kim 
18617f01e99SJung-uk Kim /* all PSK */
18717f01e99SJung-uk Kim 
18817f01e99SJung-uk Kim # define SSL_PSK     (SSL_kPSK | SSL_kRSAPSK | SSL_kECDHEPSK | SSL_kDHEPSK)
18917f01e99SJung-uk Kim 
19017f01e99SJung-uk Kim /* Any appropriate key exchange algorithm (for TLS 1.3 ciphersuites) */
19117f01e99SJung-uk Kim # define SSL_kANY                0x00000000U
19217f01e99SJung-uk Kim 
19317f01e99SJung-uk Kim /* Bits for algorithm_auth (server authentication) */
19417f01e99SJung-uk Kim /* RSA auth */
19517f01e99SJung-uk Kim # define SSL_aRSA                0x00000001U
19617f01e99SJung-uk Kim /* DSS auth */
19717f01e99SJung-uk Kim # define SSL_aDSS                0x00000002U
19817f01e99SJung-uk Kim /* no auth (i.e. use ADH or AECDH) */
19917f01e99SJung-uk Kim # define SSL_aNULL               0x00000004U
20017f01e99SJung-uk Kim /* ECDSA auth*/
20117f01e99SJung-uk Kim # define SSL_aECDSA              0x00000008U
20217f01e99SJung-uk Kim /* PSK auth */
20317f01e99SJung-uk Kim # define SSL_aPSK                0x00000010U
20417f01e99SJung-uk Kim /* GOST R 34.10-2001 signature auth */
20517f01e99SJung-uk Kim # define SSL_aGOST01             0x00000020U
20617f01e99SJung-uk Kim /* SRP auth */
20717f01e99SJung-uk Kim # define SSL_aSRP                0x00000040U
20817f01e99SJung-uk Kim /* GOST R 34.10-2012 signature auth */
20917f01e99SJung-uk Kim # define SSL_aGOST12             0x00000080U
21017f01e99SJung-uk Kim /* Any appropriate signature auth (for TLS 1.3 ciphersuites) */
21117f01e99SJung-uk Kim # define SSL_aANY                0x00000000U
21217f01e99SJung-uk Kim /* All bits requiring a certificate */
21317f01e99SJung-uk Kim #define SSL_aCERT \
21417f01e99SJung-uk Kim     (SSL_aRSA | SSL_aDSS | SSL_aECDSA | SSL_aGOST01 | SSL_aGOST12)
21517f01e99SJung-uk Kim 
21617f01e99SJung-uk Kim /* Bits for algorithm_enc (symmetric encryption) */
21717f01e99SJung-uk Kim # define SSL_DES                 0x00000001U
21817f01e99SJung-uk Kim # define SSL_3DES                0x00000002U
21917f01e99SJung-uk Kim # define SSL_RC4                 0x00000004U
22017f01e99SJung-uk Kim # define SSL_RC2                 0x00000008U
22117f01e99SJung-uk Kim # define SSL_IDEA                0x00000010U
22217f01e99SJung-uk Kim # define SSL_eNULL               0x00000020U
22317f01e99SJung-uk Kim # define SSL_AES128              0x00000040U
22417f01e99SJung-uk Kim # define SSL_AES256              0x00000080U
22517f01e99SJung-uk Kim # define SSL_CAMELLIA128         0x00000100U
22617f01e99SJung-uk Kim # define SSL_CAMELLIA256         0x00000200U
22717f01e99SJung-uk Kim # define SSL_eGOST2814789CNT     0x00000400U
22817f01e99SJung-uk Kim # define SSL_SEED                0x00000800U
22917f01e99SJung-uk Kim # define SSL_AES128GCM           0x00001000U
23017f01e99SJung-uk Kim # define SSL_AES256GCM           0x00002000U
23117f01e99SJung-uk Kim # define SSL_AES128CCM           0x00004000U
23217f01e99SJung-uk Kim # define SSL_AES256CCM           0x00008000U
23317f01e99SJung-uk Kim # define SSL_AES128CCM8          0x00010000U
23417f01e99SJung-uk Kim # define SSL_AES256CCM8          0x00020000U
23517f01e99SJung-uk Kim # define SSL_eGOST2814789CNT12   0x00040000U
23617f01e99SJung-uk Kim # define SSL_CHACHA20POLY1305    0x00080000U
23717f01e99SJung-uk Kim # define SSL_ARIA128GCM          0x00100000U
23817f01e99SJung-uk Kim # define SSL_ARIA256GCM          0x00200000U
239b077aed3SPierre Pronchery # define SSL_MAGMA               0x00400000U
240b077aed3SPierre Pronchery # define SSL_KUZNYECHIK          0x00800000U
24117f01e99SJung-uk Kim 
24217f01e99SJung-uk Kim # define SSL_AESGCM              (SSL_AES128GCM | SSL_AES256GCM)
24317f01e99SJung-uk Kim # define SSL_AESCCM              (SSL_AES128CCM | SSL_AES256CCM | SSL_AES128CCM8 | SSL_AES256CCM8)
24417f01e99SJung-uk Kim # define SSL_AES                 (SSL_AES128|SSL_AES256|SSL_AESGCM|SSL_AESCCM)
24517f01e99SJung-uk Kim # define SSL_CAMELLIA            (SSL_CAMELLIA128|SSL_CAMELLIA256)
24617f01e99SJung-uk Kim # define SSL_CHACHA20            (SSL_CHACHA20POLY1305)
24717f01e99SJung-uk Kim # define SSL_ARIAGCM             (SSL_ARIA128GCM | SSL_ARIA256GCM)
24817f01e99SJung-uk Kim # define SSL_ARIA                (SSL_ARIAGCM)
249b077aed3SPierre Pronchery # define SSL_CBC                 (SSL_DES | SSL_3DES | SSL_RC2 | SSL_IDEA \
250b077aed3SPierre Pronchery                                   | SSL_AES128 | SSL_AES256 | SSL_CAMELLIA128 \
251b077aed3SPierre Pronchery                                   | SSL_CAMELLIA256 | SSL_SEED)
25217f01e99SJung-uk Kim 
25317f01e99SJung-uk Kim /* Bits for algorithm_mac (symmetric authentication) */
25417f01e99SJung-uk Kim 
25517f01e99SJung-uk Kim # define SSL_MD5                 0x00000001U
25617f01e99SJung-uk Kim # define SSL_SHA1                0x00000002U
25717f01e99SJung-uk Kim # define SSL_GOST94      0x00000004U
25817f01e99SJung-uk Kim # define SSL_GOST89MAC   0x00000008U
25917f01e99SJung-uk Kim # define SSL_SHA256              0x00000010U
26017f01e99SJung-uk Kim # define SSL_SHA384              0x00000020U
26117f01e99SJung-uk Kim /* Not a real MAC, just an indication it is part of cipher */
26217f01e99SJung-uk Kim # define SSL_AEAD                0x00000040U
26317f01e99SJung-uk Kim # define SSL_GOST12_256          0x00000080U
26417f01e99SJung-uk Kim # define SSL_GOST89MAC12         0x00000100U
26517f01e99SJung-uk Kim # define SSL_GOST12_512          0x00000200U
266b077aed3SPierre Pronchery # define SSL_MAGMAOMAC           0x00000400U
267b077aed3SPierre Pronchery # define SSL_KUZNYECHIKOMAC      0x00000800U
26817f01e99SJung-uk Kim 
26917f01e99SJung-uk Kim /*
27017f01e99SJung-uk Kim  * When adding new digest in the ssl_ciph.c and increment SSL_MD_NUM_IDX make
27117f01e99SJung-uk Kim  * sure to update this constant too
27217f01e99SJung-uk Kim  */
27317f01e99SJung-uk Kim 
27417f01e99SJung-uk Kim # define SSL_MD_MD5_IDX  0
27517f01e99SJung-uk Kim # define SSL_MD_SHA1_IDX 1
27617f01e99SJung-uk Kim # define SSL_MD_GOST94_IDX 2
27717f01e99SJung-uk Kim # define SSL_MD_GOST89MAC_IDX 3
27817f01e99SJung-uk Kim # define SSL_MD_SHA256_IDX 4
27917f01e99SJung-uk Kim # define SSL_MD_SHA384_IDX 5
28017f01e99SJung-uk Kim # define SSL_MD_GOST12_256_IDX  6
28117f01e99SJung-uk Kim # define SSL_MD_GOST89MAC12_IDX 7
28217f01e99SJung-uk Kim # define SSL_MD_GOST12_512_IDX  8
28317f01e99SJung-uk Kim # define SSL_MD_MD5_SHA1_IDX 9
28417f01e99SJung-uk Kim # define SSL_MD_SHA224_IDX 10
28517f01e99SJung-uk Kim # define SSL_MD_SHA512_IDX 11
286b077aed3SPierre Pronchery # define SSL_MD_MAGMAOMAC_IDX 12
287b077aed3SPierre Pronchery # define SSL_MD_KUZNYECHIKOMAC_IDX 13
288b077aed3SPierre Pronchery # define SSL_MAX_DIGEST 14
289b077aed3SPierre Pronchery 
290b077aed3SPierre Pronchery #define SSL_MD_NUM_IDX  SSL_MAX_DIGEST
29117f01e99SJung-uk Kim 
29217f01e99SJung-uk Kim /* Bits for algorithm2 (handshake digests and other extra flags) */
29317f01e99SJung-uk Kim 
29417f01e99SJung-uk Kim /* Bits 0-7 are handshake MAC */
29517f01e99SJung-uk Kim # define SSL_HANDSHAKE_MAC_MASK  0xFF
29617f01e99SJung-uk Kim # define SSL_HANDSHAKE_MAC_MD5_SHA1 SSL_MD_MD5_SHA1_IDX
29717f01e99SJung-uk Kim # define SSL_HANDSHAKE_MAC_SHA256   SSL_MD_SHA256_IDX
29817f01e99SJung-uk Kim # define SSL_HANDSHAKE_MAC_SHA384   SSL_MD_SHA384_IDX
29917f01e99SJung-uk Kim # define SSL_HANDSHAKE_MAC_GOST94 SSL_MD_GOST94_IDX
30017f01e99SJung-uk Kim # define SSL_HANDSHAKE_MAC_GOST12_256 SSL_MD_GOST12_256_IDX
30117f01e99SJung-uk Kim # define SSL_HANDSHAKE_MAC_GOST12_512 SSL_MD_GOST12_512_IDX
30217f01e99SJung-uk Kim # define SSL_HANDSHAKE_MAC_DEFAULT  SSL_HANDSHAKE_MAC_MD5_SHA1
30317f01e99SJung-uk Kim 
30417f01e99SJung-uk Kim /* Bits 8-15 bits are PRF */
30517f01e99SJung-uk Kim # define TLS1_PRF_DGST_SHIFT 8
30617f01e99SJung-uk Kim # define TLS1_PRF_SHA1_MD5 (SSL_MD_MD5_SHA1_IDX << TLS1_PRF_DGST_SHIFT)
30717f01e99SJung-uk Kim # define TLS1_PRF_SHA256 (SSL_MD_SHA256_IDX << TLS1_PRF_DGST_SHIFT)
30817f01e99SJung-uk Kim # define TLS1_PRF_SHA384 (SSL_MD_SHA384_IDX << TLS1_PRF_DGST_SHIFT)
30917f01e99SJung-uk Kim # define TLS1_PRF_GOST94 (SSL_MD_GOST94_IDX << TLS1_PRF_DGST_SHIFT)
31017f01e99SJung-uk Kim # define TLS1_PRF_GOST12_256 (SSL_MD_GOST12_256_IDX << TLS1_PRF_DGST_SHIFT)
31117f01e99SJung-uk Kim # define TLS1_PRF_GOST12_512 (SSL_MD_GOST12_512_IDX << TLS1_PRF_DGST_SHIFT)
31217f01e99SJung-uk Kim # define TLS1_PRF            (SSL_MD_MD5_SHA1_IDX << TLS1_PRF_DGST_SHIFT)
31317f01e99SJung-uk Kim 
31417f01e99SJung-uk Kim /*
31517f01e99SJung-uk Kim  * Stream MAC for GOST ciphersuites from cryptopro draft (currently this also
31617f01e99SJung-uk Kim  * goes into algorithm2)
31717f01e99SJung-uk Kim  */
31817f01e99SJung-uk Kim # define TLS1_STREAM_MAC 0x10000
319b077aed3SPierre Pronchery /*
320b077aed3SPierre Pronchery  * TLSTREE cipher/mac key derivation from draft-smyshlyaev-tls12-gost-suites
321b077aed3SPierre Pronchery  * (currently this also  goes into algorithm2)
322b077aed3SPierre Pronchery  */
323b077aed3SPierre Pronchery # define TLS1_TLSTREE 0x20000
32417f01e99SJung-uk Kim 
32517f01e99SJung-uk Kim # define SSL_STRONG_MASK         0x0000001FU
32617f01e99SJung-uk Kim # define SSL_DEFAULT_MASK        0X00000020U
32717f01e99SJung-uk Kim 
32817f01e99SJung-uk Kim # define SSL_STRONG_NONE         0x00000001U
32917f01e99SJung-uk Kim # define SSL_LOW                 0x00000002U
33017f01e99SJung-uk Kim # define SSL_MEDIUM              0x00000004U
33117f01e99SJung-uk Kim # define SSL_HIGH                0x00000008U
33217f01e99SJung-uk Kim # define SSL_FIPS                0x00000010U
33317f01e99SJung-uk Kim # define SSL_NOT_DEFAULT         0x00000020U
33417f01e99SJung-uk Kim 
33517f01e99SJung-uk Kim /* we have used 0000003f - 26 bits left to go */
33617f01e99SJung-uk Kim 
33717f01e99SJung-uk Kim /* Flag used on OpenSSL ciphersuite ids to indicate they are for SSLv3+ */
33817f01e99SJung-uk Kim # define SSL3_CK_CIPHERSUITE_FLAG                0x03000000
33917f01e99SJung-uk Kim 
34017f01e99SJung-uk Kim /* Check if an SSL structure is using DTLS */
34117f01e99SJung-uk Kim # define SSL_IS_DTLS(s)  (s->method->ssl3_enc->enc_flags & SSL_ENC_FLAG_DTLS)
34217f01e99SJung-uk Kim 
34317f01e99SJung-uk Kim /* Check if we are using TLSv1.3 */
34417f01e99SJung-uk Kim # define SSL_IS_TLS13(s) (!SSL_IS_DTLS(s) \
34517f01e99SJung-uk Kim                           && (s)->method->version >= TLS1_3_VERSION \
34617f01e99SJung-uk Kim                           && (s)->method->version != TLS_ANY_VERSION)
34717f01e99SJung-uk Kim 
34817f01e99SJung-uk Kim # define SSL_TREAT_AS_TLS13(s) \
34917f01e99SJung-uk Kim     (SSL_IS_TLS13(s) || (s)->early_data_state == SSL_EARLY_DATA_CONNECTING \
35017f01e99SJung-uk Kim      || (s)->early_data_state == SSL_EARLY_DATA_CONNECT_RETRY \
35117f01e99SJung-uk Kim      || (s)->early_data_state == SSL_EARLY_DATA_WRITING \
35217f01e99SJung-uk Kim      || (s)->early_data_state == SSL_EARLY_DATA_WRITE_RETRY \
35317f01e99SJung-uk Kim      || (s)->hello_retry_request == SSL_HRR_PENDING)
35417f01e99SJung-uk Kim 
355b077aed3SPierre Pronchery # define SSL_IS_FIRST_HANDSHAKE(S) ((s)->s3.tmp.finish_md_len == 0 \
356b077aed3SPierre Pronchery                                     || (s)->s3.tmp.peer_finish_md_len == 0)
35717f01e99SJung-uk Kim 
35817f01e99SJung-uk Kim /* See if we need explicit IV */
35917f01e99SJung-uk Kim # define SSL_USE_EXPLICIT_IV(s)  \
36017f01e99SJung-uk Kim                 (s->method->ssl3_enc->enc_flags & SSL_ENC_FLAG_EXPLICIT_IV)
36117f01e99SJung-uk Kim /*
36217f01e99SJung-uk Kim  * See if we use signature algorithms extension and signature algorithm
36317f01e99SJung-uk Kim  * before signatures.
36417f01e99SJung-uk Kim  */
36517f01e99SJung-uk Kim # define SSL_USE_SIGALGS(s)      \
36617f01e99SJung-uk Kim                         (s->method->ssl3_enc->enc_flags & SSL_ENC_FLAG_SIGALGS)
36717f01e99SJung-uk Kim /*
36817f01e99SJung-uk Kim  * Allow TLS 1.2 ciphersuites: applies to DTLS 1.2 as well as TLS 1.2: may
36917f01e99SJung-uk Kim  * apply to others in future.
37017f01e99SJung-uk Kim  */
37117f01e99SJung-uk Kim # define SSL_USE_TLS1_2_CIPHERS(s)       \
37217f01e99SJung-uk Kim                 (s->method->ssl3_enc->enc_flags & SSL_ENC_FLAG_TLS1_2_CIPHERS)
37317f01e99SJung-uk Kim /*
37417f01e99SJung-uk Kim  * Determine if a client can use TLS 1.2 ciphersuites: can't rely on method
37517f01e99SJung-uk Kim  * flags because it may not be set to correct version yet.
37617f01e99SJung-uk Kim  */
37717f01e99SJung-uk Kim # define SSL_CLIENT_USE_TLS1_2_CIPHERS(s)        \
37817f01e99SJung-uk Kim     ((!SSL_IS_DTLS(s) && s->client_version >= TLS1_2_VERSION) || \
37917f01e99SJung-uk Kim      (SSL_IS_DTLS(s) && DTLS_VERSION_GE(s->client_version, DTLS1_2_VERSION)))
38017f01e99SJung-uk Kim /*
38117f01e99SJung-uk Kim  * Determine if a client should send signature algorithms extension:
38217f01e99SJung-uk Kim  * as with TLS1.2 cipher we can't rely on method flags.
38317f01e99SJung-uk Kim  */
38417f01e99SJung-uk Kim # define SSL_CLIENT_USE_SIGALGS(s)        \
38517f01e99SJung-uk Kim     SSL_CLIENT_USE_TLS1_2_CIPHERS(s)
38617f01e99SJung-uk Kim 
38717f01e99SJung-uk Kim # define IS_MAX_FRAGMENT_LENGTH_EXT_VALID(value) \
38817f01e99SJung-uk Kim     (((value) >= TLSEXT_max_fragment_length_512) && \
38917f01e99SJung-uk Kim      ((value) <= TLSEXT_max_fragment_length_4096))
39017f01e99SJung-uk Kim # define USE_MAX_FRAGMENT_LENGTH_EXT(session) \
39117f01e99SJung-uk Kim     IS_MAX_FRAGMENT_LENGTH_EXT_VALID(session->ext.max_fragment_len_mode)
39217f01e99SJung-uk Kim # define GET_MAX_FRAGMENT_LENGTH(session) \
39317f01e99SJung-uk Kim     (512U << (session->ext.max_fragment_len_mode - 1))
39417f01e99SJung-uk Kim 
395b077aed3SPierre Pronchery # define SSL_READ_ETM(s) (s->s3.flags & TLS1_FLAGS_ENCRYPT_THEN_MAC_READ)
396b077aed3SPierre Pronchery # define SSL_WRITE_ETM(s) (s->s3.flags & TLS1_FLAGS_ENCRYPT_THEN_MAC_WRITE)
39717f01e99SJung-uk Kim 
39817f01e99SJung-uk Kim /* Mostly for SSLv3 */
39917f01e99SJung-uk Kim # define SSL_PKEY_RSA            0
40017f01e99SJung-uk Kim # define SSL_PKEY_RSA_PSS_SIGN   1
40117f01e99SJung-uk Kim # define SSL_PKEY_DSA_SIGN       2
40217f01e99SJung-uk Kim # define SSL_PKEY_ECC            3
40317f01e99SJung-uk Kim # define SSL_PKEY_GOST01         4
40417f01e99SJung-uk Kim # define SSL_PKEY_GOST12_256     5
40517f01e99SJung-uk Kim # define SSL_PKEY_GOST12_512     6
40617f01e99SJung-uk Kim # define SSL_PKEY_ED25519        7
40717f01e99SJung-uk Kim # define SSL_PKEY_ED448          8
40817f01e99SJung-uk Kim # define SSL_PKEY_NUM            9
40917f01e99SJung-uk Kim 
410b077aed3SPierre Pronchery # define SSL_ENC_DES_IDX         0
411b077aed3SPierre Pronchery # define SSL_ENC_3DES_IDX        1
412b077aed3SPierre Pronchery # define SSL_ENC_RC4_IDX         2
413b077aed3SPierre Pronchery # define SSL_ENC_RC2_IDX         3
414b077aed3SPierre Pronchery # define SSL_ENC_IDEA_IDX        4
415b077aed3SPierre Pronchery # define SSL_ENC_NULL_IDX        5
416b077aed3SPierre Pronchery # define SSL_ENC_AES128_IDX      6
417b077aed3SPierre Pronchery # define SSL_ENC_AES256_IDX      7
418b077aed3SPierre Pronchery # define SSL_ENC_CAMELLIA128_IDX 8
419b077aed3SPierre Pronchery # define SSL_ENC_CAMELLIA256_IDX 9
420b077aed3SPierre Pronchery # define SSL_ENC_GOST89_IDX      10
421b077aed3SPierre Pronchery # define SSL_ENC_SEED_IDX        11
422b077aed3SPierre Pronchery # define SSL_ENC_AES128GCM_IDX   12
423b077aed3SPierre Pronchery # define SSL_ENC_AES256GCM_IDX   13
424b077aed3SPierre Pronchery # define SSL_ENC_AES128CCM_IDX   14
425b077aed3SPierre Pronchery # define SSL_ENC_AES256CCM_IDX   15
426b077aed3SPierre Pronchery # define SSL_ENC_AES128CCM8_IDX  16
427b077aed3SPierre Pronchery # define SSL_ENC_AES256CCM8_IDX  17
428b077aed3SPierre Pronchery # define SSL_ENC_GOST8912_IDX    18
429b077aed3SPierre Pronchery # define SSL_ENC_CHACHA_IDX      19
430b077aed3SPierre Pronchery # define SSL_ENC_ARIA128GCM_IDX  20
431b077aed3SPierre Pronchery # define SSL_ENC_ARIA256GCM_IDX  21
432b077aed3SPierre Pronchery # define SSL_ENC_MAGMA_IDX       22
433b077aed3SPierre Pronchery # define SSL_ENC_KUZNYECHIK_IDX  23
434b077aed3SPierre Pronchery # define SSL_ENC_NUM_IDX         24
435b077aed3SPierre Pronchery 
43617f01e99SJung-uk Kim /*-
43717f01e99SJung-uk Kim  * SSL_kRSA <- RSA_ENC
43817f01e99SJung-uk Kim  * SSL_kDH  <- DH_ENC & (RSA_ENC | RSA_SIGN | DSA_SIGN)
43917f01e99SJung-uk Kim  * SSL_kDHE <- RSA_ENC | RSA_SIGN | DSA_SIGN
44017f01e99SJung-uk Kim  * SSL_aRSA <- RSA_ENC | RSA_SIGN
44117f01e99SJung-uk Kim  * SSL_aDSS <- DSA_SIGN
44217f01e99SJung-uk Kim  */
44317f01e99SJung-uk Kim 
44417f01e99SJung-uk Kim /*-
44517f01e99SJung-uk Kim #define CERT_INVALID            0
44617f01e99SJung-uk Kim #define CERT_PUBLIC_KEY         1
44717f01e99SJung-uk Kim #define CERT_PRIVATE_KEY        2
44817f01e99SJung-uk Kim */
44917f01e99SJung-uk Kim 
45017f01e99SJung-uk Kim /* Post-Handshake Authentication state */
45117f01e99SJung-uk Kim typedef enum {
45217f01e99SJung-uk Kim     SSL_PHA_NONE = 0,
45317f01e99SJung-uk Kim     SSL_PHA_EXT_SENT,        /* client-side only: extension sent */
45417f01e99SJung-uk Kim     SSL_PHA_EXT_RECEIVED,    /* server-side only: extension received */
45517f01e99SJung-uk Kim     SSL_PHA_REQUEST_PENDING, /* server-side only: request pending */
45617f01e99SJung-uk Kim     SSL_PHA_REQUESTED        /* request received by client, or sent by server */
45717f01e99SJung-uk Kim } SSL_PHA_STATE;
45817f01e99SJung-uk Kim 
45917f01e99SJung-uk Kim /* CipherSuite length. SSLv3 and all TLS versions. */
46017f01e99SJung-uk Kim # define TLS_CIPHER_LEN 2
46117f01e99SJung-uk Kim /* used to hold info on the particular ciphers used */
46217f01e99SJung-uk Kim struct ssl_cipher_st {
46317f01e99SJung-uk Kim     uint32_t valid;
46417f01e99SJung-uk Kim     const char *name;           /* text name */
46517f01e99SJung-uk Kim     const char *stdname;        /* RFC name */
46617f01e99SJung-uk Kim     uint32_t id;                /* id, 4 bytes, first is version */
46717f01e99SJung-uk Kim     /*
46817f01e99SJung-uk Kim      * changed in 1.0.0: these four used to be portions of a single value
46917f01e99SJung-uk Kim      * 'algorithms'
47017f01e99SJung-uk Kim      */
47117f01e99SJung-uk Kim     uint32_t algorithm_mkey;    /* key exchange algorithm */
47217f01e99SJung-uk Kim     uint32_t algorithm_auth;    /* server authentication */
47317f01e99SJung-uk Kim     uint32_t algorithm_enc;     /* symmetric encryption */
47417f01e99SJung-uk Kim     uint32_t algorithm_mac;     /* symmetric authentication */
47517f01e99SJung-uk Kim     int min_tls;                /* minimum SSL/TLS protocol version */
47617f01e99SJung-uk Kim     int max_tls;                /* maximum SSL/TLS protocol version */
47717f01e99SJung-uk Kim     int min_dtls;               /* minimum DTLS protocol version */
47817f01e99SJung-uk Kim     int max_dtls;               /* maximum DTLS protocol version */
47917f01e99SJung-uk Kim     uint32_t algo_strength;     /* strength and export flags */
48017f01e99SJung-uk Kim     uint32_t algorithm2;        /* Extra flags */
48117f01e99SJung-uk Kim     int32_t strength_bits;      /* Number of bits really used */
48217f01e99SJung-uk Kim     uint32_t alg_bits;          /* Number of bits for algorithm */
48317f01e99SJung-uk Kim };
48417f01e99SJung-uk Kim 
48517f01e99SJung-uk Kim /* Used to hold SSL/TLS functions */
48617f01e99SJung-uk Kim struct ssl_method_st {
48717f01e99SJung-uk Kim     int version;
48817f01e99SJung-uk Kim     unsigned flags;
48917f01e99SJung-uk Kim     unsigned long mask;
49017f01e99SJung-uk Kim     int (*ssl_new) (SSL *s);
49117f01e99SJung-uk Kim     int (*ssl_clear) (SSL *s);
49217f01e99SJung-uk Kim     void (*ssl_free) (SSL *s);
49317f01e99SJung-uk Kim     int (*ssl_accept) (SSL *s);
49417f01e99SJung-uk Kim     int (*ssl_connect) (SSL *s);
49517f01e99SJung-uk Kim     int (*ssl_read) (SSL *s, void *buf, size_t len, size_t *readbytes);
49617f01e99SJung-uk Kim     int (*ssl_peek) (SSL *s, void *buf, size_t len, size_t *readbytes);
49717f01e99SJung-uk Kim     int (*ssl_write) (SSL *s, const void *buf, size_t len, size_t *written);
49817f01e99SJung-uk Kim     int (*ssl_shutdown) (SSL *s);
49917f01e99SJung-uk Kim     int (*ssl_renegotiate) (SSL *s);
50017f01e99SJung-uk Kim     int (*ssl_renegotiate_check) (SSL *s, int);
50117f01e99SJung-uk Kim     int (*ssl_read_bytes) (SSL *s, int type, int *recvd_type,
50217f01e99SJung-uk Kim                            unsigned char *buf, size_t len, int peek,
50317f01e99SJung-uk Kim                            size_t *readbytes);
50417f01e99SJung-uk Kim     int (*ssl_write_bytes) (SSL *s, int type, const void *buf_, size_t len,
50517f01e99SJung-uk Kim                             size_t *written);
50617f01e99SJung-uk Kim     int (*ssl_dispatch_alert) (SSL *s);
50717f01e99SJung-uk Kim     long (*ssl_ctrl) (SSL *s, int cmd, long larg, void *parg);
50817f01e99SJung-uk Kim     long (*ssl_ctx_ctrl) (SSL_CTX *ctx, int cmd, long larg, void *parg);
50917f01e99SJung-uk Kim     const SSL_CIPHER *(*get_cipher_by_char) (const unsigned char *ptr);
51017f01e99SJung-uk Kim     int (*put_cipher_by_char) (const SSL_CIPHER *cipher, WPACKET *pkt,
51117f01e99SJung-uk Kim                                size_t *len);
51217f01e99SJung-uk Kim     size_t (*ssl_pending) (const SSL *s);
51317f01e99SJung-uk Kim     int (*num_ciphers) (void);
51417f01e99SJung-uk Kim     const SSL_CIPHER *(*get_cipher) (unsigned ncipher);
51517f01e99SJung-uk Kim     long (*get_timeout) (void);
51617f01e99SJung-uk Kim     const struct ssl3_enc_method *ssl3_enc; /* Extra SSLv3/TLS stuff */
51717f01e99SJung-uk Kim     int (*ssl_version) (void);
51817f01e99SJung-uk Kim     long (*ssl_callback_ctrl) (SSL *s, int cb_id, void (*fp) (void));
51917f01e99SJung-uk Kim     long (*ssl_ctx_callback_ctrl) (SSL_CTX *s, int cb_id, void (*fp) (void));
52017f01e99SJung-uk Kim };
52117f01e99SJung-uk Kim 
52217f01e99SJung-uk Kim /*
52317f01e99SJung-uk Kim  * Matches the length of PSK_MAX_PSK_LEN. We keep it the same value for
52417f01e99SJung-uk Kim  * consistency, even in the event of OPENSSL_NO_PSK being defined.
52517f01e99SJung-uk Kim  */
526b077aed3SPierre Pronchery # define TLS13_MAX_RESUMPTION_PSK_LENGTH      512
52717f01e99SJung-uk Kim 
52817f01e99SJung-uk Kim /*-
52917f01e99SJung-uk Kim  * Lets make this into an ASN.1 type structure as follows
53017f01e99SJung-uk Kim  * SSL_SESSION_ID ::= SEQUENCE {
53117f01e99SJung-uk Kim  *      version                 INTEGER,        -- structure version number
53217f01e99SJung-uk Kim  *      SSLversion              INTEGER,        -- SSL version number
53317f01e99SJung-uk Kim  *      Cipher                  OCTET STRING,   -- the 3 byte cipher ID
53417f01e99SJung-uk Kim  *      Session_ID              OCTET STRING,   -- the Session ID
53517f01e99SJung-uk Kim  *      Master_key              OCTET STRING,   -- the master key
53617f01e99SJung-uk Kim  *      Key_Arg [ 0 ] IMPLICIT  OCTET STRING,   -- the optional Key argument
53717f01e99SJung-uk Kim  *      Time [ 1 ] EXPLICIT     INTEGER,        -- optional Start Time
53817f01e99SJung-uk Kim  *      Timeout [ 2 ] EXPLICIT  INTEGER,        -- optional Timeout ins seconds
53917f01e99SJung-uk Kim  *      Peer [ 3 ] EXPLICIT     X509,           -- optional Peer Certificate
54017f01e99SJung-uk Kim  *      Session_ID_context [ 4 ] EXPLICIT OCTET STRING,   -- the Session ID context
54117f01e99SJung-uk Kim  *      Verify_result [ 5 ] EXPLICIT INTEGER,   -- X509_V_... code for `Peer'
54217f01e99SJung-uk Kim  *      HostName [ 6 ] EXPLICIT OCTET STRING,   -- optional HostName from servername TLS extension
54317f01e99SJung-uk Kim  *      PSK_identity_hint [ 7 ] EXPLICIT OCTET STRING, -- optional PSK identity hint
54417f01e99SJung-uk Kim  *      PSK_identity [ 8 ] EXPLICIT OCTET STRING,  -- optional PSK identity
54517f01e99SJung-uk Kim  *      Ticket_lifetime_hint [9] EXPLICIT INTEGER, -- server's lifetime hint for session ticket
54617f01e99SJung-uk Kim  *      Ticket [10]             EXPLICIT OCTET STRING, -- session ticket (clients only)
54717f01e99SJung-uk Kim  *      Compression_meth [11]   EXPLICIT OCTET STRING, -- optional compression method
54817f01e99SJung-uk Kim  *      SRP_username [ 12 ] EXPLICIT OCTET STRING -- optional SRP username
54917f01e99SJung-uk Kim  *      flags [ 13 ] EXPLICIT INTEGER -- optional flags
55017f01e99SJung-uk Kim  *      }
55117f01e99SJung-uk Kim  * Look in ssl/ssl_asn1.c for more details
55217f01e99SJung-uk Kim  * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-).
55317f01e99SJung-uk Kim  */
55417f01e99SJung-uk Kim struct ssl_session_st {
55517f01e99SJung-uk Kim     int ssl_version;            /* what ssl version session info is being kept
55617f01e99SJung-uk Kim                                  * in here? */
55717f01e99SJung-uk Kim     size_t master_key_length;
55817f01e99SJung-uk Kim 
55917f01e99SJung-uk Kim     /* TLSv1.3 early_secret used for external PSKs */
56017f01e99SJung-uk Kim     unsigned char early_secret[EVP_MAX_MD_SIZE];
56117f01e99SJung-uk Kim     /*
56217f01e99SJung-uk Kim      * For <=TLS1.2 this is the master_key. For TLS1.3 this is the resumption
56317f01e99SJung-uk Kim      * PSK
56417f01e99SJung-uk Kim      */
56517f01e99SJung-uk Kim     unsigned char master_key[TLS13_MAX_RESUMPTION_PSK_LENGTH];
56617f01e99SJung-uk Kim     /* session_id - valid? */
56717f01e99SJung-uk Kim     size_t session_id_length;
56817f01e99SJung-uk Kim     unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
56917f01e99SJung-uk Kim     /*
57017f01e99SJung-uk Kim      * this is used to determine whether the session is being reused in the
57117f01e99SJung-uk Kim      * appropriate context. It is up to the application to set this, via
57217f01e99SJung-uk Kim      * SSL_new
57317f01e99SJung-uk Kim      */
57417f01e99SJung-uk Kim     size_t sid_ctx_length;
57517f01e99SJung-uk Kim     unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
57617f01e99SJung-uk Kim # ifndef OPENSSL_NO_PSK
57717f01e99SJung-uk Kim     char *psk_identity_hint;
57817f01e99SJung-uk Kim     char *psk_identity;
57917f01e99SJung-uk Kim # endif
58017f01e99SJung-uk Kim     /*
58117f01e99SJung-uk Kim      * Used to indicate that session resumption is not allowed. Applications
58217f01e99SJung-uk Kim      * can also set this bit for a new session via not_resumable_session_cb
58317f01e99SJung-uk Kim      * to disable session caching and tickets.
58417f01e99SJung-uk Kim      */
58517f01e99SJung-uk Kim     int not_resumable;
58617f01e99SJung-uk Kim     /* This is the cert and type for the other end. */
58717f01e99SJung-uk Kim     X509 *peer;
58817f01e99SJung-uk Kim     /* Certificate chain peer sent. */
58917f01e99SJung-uk Kim     STACK_OF(X509) *peer_chain;
59017f01e99SJung-uk Kim     /*
59117f01e99SJung-uk Kim      * when app_verify_callback accepts a session where the peer's
59217f01e99SJung-uk Kim      * certificate is not ok, we must remember the error for session reuse:
59317f01e99SJung-uk Kim      */
59417f01e99SJung-uk Kim     long verify_result;         /* only for servers */
59517f01e99SJung-uk Kim     CRYPTO_REF_COUNT references;
596b077aed3SPierre Pronchery     time_t timeout;
597b077aed3SPierre Pronchery     time_t time;
598b077aed3SPierre Pronchery     time_t calc_timeout;
599b077aed3SPierre Pronchery     int timeout_ovf;
60017f01e99SJung-uk Kim     unsigned int compress_meth; /* Need to lookup the method */
60117f01e99SJung-uk Kim     const SSL_CIPHER *cipher;
60217f01e99SJung-uk Kim     unsigned long cipher_id;    /* when ASN.1 loaded, this needs to be used to
60317f01e99SJung-uk Kim                                  * load the 'cipher' structure */
604b077aed3SPierre Pronchery     unsigned int kex_group;      /* TLS group from key exchange */
60517f01e99SJung-uk Kim     CRYPTO_EX_DATA ex_data;     /* application specific data */
60617f01e99SJung-uk Kim     /*
60717f01e99SJung-uk Kim      * These are used to make removal of session-ids more efficient and to
60817f01e99SJung-uk Kim      * implement a maximum cache size.
60917f01e99SJung-uk Kim      */
61017f01e99SJung-uk Kim     struct ssl_session_st *prev, *next;
61117f01e99SJung-uk Kim 
61217f01e99SJung-uk Kim     struct {
61317f01e99SJung-uk Kim         char *hostname;
61417f01e99SJung-uk Kim         /* RFC4507 info */
61517f01e99SJung-uk Kim         unsigned char *tick; /* Session ticket */
61617f01e99SJung-uk Kim         size_t ticklen;      /* Session ticket length */
61717f01e99SJung-uk Kim         /* Session lifetime hint in seconds */
61817f01e99SJung-uk Kim         unsigned long tick_lifetime_hint;
61917f01e99SJung-uk Kim         uint32_t tick_age_add;
62017f01e99SJung-uk Kim         /* Max number of bytes that can be sent as early data */
62117f01e99SJung-uk Kim         uint32_t max_early_data;
62217f01e99SJung-uk Kim         /* The ALPN protocol selected for this session */
62317f01e99SJung-uk Kim         unsigned char *alpn_selected;
62417f01e99SJung-uk Kim         size_t alpn_selected_len;
62517f01e99SJung-uk Kim         /*
62617f01e99SJung-uk Kim          * Maximum Fragment Length as per RFC 4366.
62717f01e99SJung-uk Kim          * If this value does not contain RFC 4366 allowed values (1-4) then
62817f01e99SJung-uk Kim          * either the Maximum Fragment Length Negotiation failed or was not
62917f01e99SJung-uk Kim          * performed at all.
63017f01e99SJung-uk Kim          */
63117f01e99SJung-uk Kim         uint8_t max_fragment_len_mode;
63217f01e99SJung-uk Kim     } ext;
63317f01e99SJung-uk Kim # ifndef OPENSSL_NO_SRP
63417f01e99SJung-uk Kim     char *srp_username;
63517f01e99SJung-uk Kim # endif
63617f01e99SJung-uk Kim     unsigned char *ticket_appdata;
63717f01e99SJung-uk Kim     size_t ticket_appdata_len;
63817f01e99SJung-uk Kim     uint32_t flags;
639b077aed3SPierre Pronchery     SSL_CTX *owner;
64017f01e99SJung-uk Kim     CRYPTO_RWLOCK *lock;
64117f01e99SJung-uk Kim };
64217f01e99SJung-uk Kim 
64317f01e99SJung-uk Kim /* Extended master secret support */
64417f01e99SJung-uk Kim # define SSL_SESS_FLAG_EXTMS             0x1
64517f01e99SJung-uk Kim 
64617f01e99SJung-uk Kim # ifndef OPENSSL_NO_SRP
64717f01e99SJung-uk Kim 
64817f01e99SJung-uk Kim typedef struct srp_ctx_st {
64917f01e99SJung-uk Kim     /* param for all the callbacks */
65017f01e99SJung-uk Kim     void *SRP_cb_arg;
65117f01e99SJung-uk Kim     /* set client Hello login callback */
65217f01e99SJung-uk Kim     int (*TLS_ext_srp_username_callback) (SSL *, int *, void *);
65317f01e99SJung-uk Kim     /* set SRP N/g param callback for verification */
65417f01e99SJung-uk Kim     int (*SRP_verify_param_callback) (SSL *, void *);
65517f01e99SJung-uk Kim     /* set SRP client passwd callback */
65617f01e99SJung-uk Kim     char *(*SRP_give_srp_client_pwd_callback) (SSL *, void *);
65717f01e99SJung-uk Kim     char *login;
65817f01e99SJung-uk Kim     BIGNUM *N, *g, *s, *B, *A;
65917f01e99SJung-uk Kim     BIGNUM *a, *b, *v;
66017f01e99SJung-uk Kim     char *info;
66117f01e99SJung-uk Kim     int strength;
66217f01e99SJung-uk Kim     unsigned long srp_Mask;
66317f01e99SJung-uk Kim } SRP_CTX;
66417f01e99SJung-uk Kim 
66517f01e99SJung-uk Kim # endif
66617f01e99SJung-uk Kim 
66717f01e99SJung-uk Kim typedef enum {
66817f01e99SJung-uk Kim     SSL_EARLY_DATA_NONE = 0,
66917f01e99SJung-uk Kim     SSL_EARLY_DATA_CONNECT_RETRY,
67017f01e99SJung-uk Kim     SSL_EARLY_DATA_CONNECTING,
67117f01e99SJung-uk Kim     SSL_EARLY_DATA_WRITE_RETRY,
67217f01e99SJung-uk Kim     SSL_EARLY_DATA_WRITING,
67317f01e99SJung-uk Kim     SSL_EARLY_DATA_WRITE_FLUSH,
67417f01e99SJung-uk Kim     SSL_EARLY_DATA_UNAUTH_WRITING,
67517f01e99SJung-uk Kim     SSL_EARLY_DATA_FINISHED_WRITING,
67617f01e99SJung-uk Kim     SSL_EARLY_DATA_ACCEPT_RETRY,
67717f01e99SJung-uk Kim     SSL_EARLY_DATA_ACCEPTING,
67817f01e99SJung-uk Kim     SSL_EARLY_DATA_READ_RETRY,
67917f01e99SJung-uk Kim     SSL_EARLY_DATA_READING,
68017f01e99SJung-uk Kim     SSL_EARLY_DATA_FINISHED_READING
68117f01e99SJung-uk Kim } SSL_EARLY_DATA_STATE;
68217f01e99SJung-uk Kim 
68317f01e99SJung-uk Kim /*
68417f01e99SJung-uk Kim  * We check that the amount of unreadable early data doesn't exceed
68517f01e99SJung-uk Kim  * max_early_data. max_early_data is given in plaintext bytes. However if it is
68617f01e99SJung-uk Kim  * unreadable then we only know the number of ciphertext bytes. We also don't
68717f01e99SJung-uk Kim  * know how much the overhead should be because it depends on the ciphersuite.
68817f01e99SJung-uk Kim  * We make a small allowance. We assume 5 records of actual data plus the end
68917f01e99SJung-uk Kim  * of early data alert record. Each record has a tag and a content type byte.
69017f01e99SJung-uk Kim  * The longest tag length we know of is EVP_GCM_TLS_TAG_LEN. We don't count the
69117f01e99SJung-uk Kim  * content of the alert record either which is 2 bytes.
69217f01e99SJung-uk Kim  */
69317f01e99SJung-uk Kim # define EARLY_DATA_CIPHERTEXT_OVERHEAD ((6 * (EVP_GCM_TLS_TAG_LEN + 1)) + 2)
69417f01e99SJung-uk Kim 
69517f01e99SJung-uk Kim /*
69617f01e99SJung-uk Kim  * The allowance we have between the client's calculated ticket age and our own.
69717f01e99SJung-uk Kim  * We allow for 10 seconds (units are in ms). If a ticket is presented and the
69817f01e99SJung-uk Kim  * client's age calculation is different by more than this than our own then we
69917f01e99SJung-uk Kim  * do not allow that ticket for early_data.
70017f01e99SJung-uk Kim  */
70117f01e99SJung-uk Kim # define TICKET_AGE_ALLOWANCE   (10 * 1000)
70217f01e99SJung-uk Kim 
70317f01e99SJung-uk Kim #define MAX_COMPRESSIONS_SIZE   255
70417f01e99SJung-uk Kim 
70517f01e99SJung-uk Kim struct ssl_comp_st {
70617f01e99SJung-uk Kim     int id;
70717f01e99SJung-uk Kim     const char *name;
70817f01e99SJung-uk Kim     COMP_METHOD *method;
70917f01e99SJung-uk Kim };
71017f01e99SJung-uk Kim 
71117f01e99SJung-uk Kim typedef struct raw_extension_st {
71217f01e99SJung-uk Kim     /* Raw packet data for the extension */
71317f01e99SJung-uk Kim     PACKET data;
71417f01e99SJung-uk Kim     /* Set to 1 if the extension is present or 0 otherwise */
71517f01e99SJung-uk Kim     int present;
71617f01e99SJung-uk Kim     /* Set to 1 if we have already parsed the extension or 0 otherwise */
71717f01e99SJung-uk Kim     int parsed;
71817f01e99SJung-uk Kim     /* The type of this extension, i.e. a TLSEXT_TYPE_* value */
71917f01e99SJung-uk Kim     unsigned int type;
72017f01e99SJung-uk Kim     /* Track what order extensions are received in (0-based). */
72117f01e99SJung-uk Kim     size_t received_order;
72217f01e99SJung-uk Kim } RAW_EXTENSION;
72317f01e99SJung-uk Kim 
72417f01e99SJung-uk Kim typedef struct {
72517f01e99SJung-uk Kim     unsigned int isv2;
72617f01e99SJung-uk Kim     unsigned int legacy_version;
72717f01e99SJung-uk Kim     unsigned char random[SSL3_RANDOM_SIZE];
72817f01e99SJung-uk Kim     size_t session_id_len;
72917f01e99SJung-uk Kim     unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
73017f01e99SJung-uk Kim     size_t dtls_cookie_len;
73117f01e99SJung-uk Kim     unsigned char dtls_cookie[DTLS1_COOKIE_LENGTH];
73217f01e99SJung-uk Kim     PACKET ciphersuites;
73317f01e99SJung-uk Kim     size_t compressions_len;
73417f01e99SJung-uk Kim     unsigned char compressions[MAX_COMPRESSIONS_SIZE];
73517f01e99SJung-uk Kim     PACKET extensions;
73617f01e99SJung-uk Kim     size_t pre_proc_exts_len;
73717f01e99SJung-uk Kim     RAW_EXTENSION *pre_proc_exts;
73817f01e99SJung-uk Kim } CLIENTHELLO_MSG;
73917f01e99SJung-uk Kim 
74017f01e99SJung-uk Kim /*
74117f01e99SJung-uk Kim  * Extension index values NOTE: Any updates to these defines should be mirrored
74217f01e99SJung-uk Kim  * with equivalent updates to ext_defs in extensions.c
74317f01e99SJung-uk Kim  */
74417f01e99SJung-uk Kim typedef enum tlsext_index_en {
74517f01e99SJung-uk Kim     TLSEXT_IDX_renegotiate,
74617f01e99SJung-uk Kim     TLSEXT_IDX_server_name,
74717f01e99SJung-uk Kim     TLSEXT_IDX_max_fragment_length,
74817f01e99SJung-uk Kim     TLSEXT_IDX_srp,
74917f01e99SJung-uk Kim     TLSEXT_IDX_ec_point_formats,
75017f01e99SJung-uk Kim     TLSEXT_IDX_supported_groups,
75117f01e99SJung-uk Kim     TLSEXT_IDX_session_ticket,
75217f01e99SJung-uk Kim     TLSEXT_IDX_status_request,
75317f01e99SJung-uk Kim     TLSEXT_IDX_next_proto_neg,
75417f01e99SJung-uk Kim     TLSEXT_IDX_application_layer_protocol_negotiation,
75517f01e99SJung-uk Kim     TLSEXT_IDX_use_srtp,
75617f01e99SJung-uk Kim     TLSEXT_IDX_encrypt_then_mac,
75717f01e99SJung-uk Kim     TLSEXT_IDX_signed_certificate_timestamp,
75817f01e99SJung-uk Kim     TLSEXT_IDX_extended_master_secret,
75917f01e99SJung-uk Kim     TLSEXT_IDX_signature_algorithms_cert,
76017f01e99SJung-uk Kim     TLSEXT_IDX_post_handshake_auth,
76117f01e99SJung-uk Kim     TLSEXT_IDX_signature_algorithms,
76217f01e99SJung-uk Kim     TLSEXT_IDX_supported_versions,
76317f01e99SJung-uk Kim     TLSEXT_IDX_psk_kex_modes,
76417f01e99SJung-uk Kim     TLSEXT_IDX_key_share,
76517f01e99SJung-uk Kim     TLSEXT_IDX_cookie,
76617f01e99SJung-uk Kim     TLSEXT_IDX_cryptopro_bug,
76717f01e99SJung-uk Kim     TLSEXT_IDX_early_data,
76817f01e99SJung-uk Kim     TLSEXT_IDX_certificate_authorities,
76917f01e99SJung-uk Kim     TLSEXT_IDX_padding,
77017f01e99SJung-uk Kim     TLSEXT_IDX_psk,
77117f01e99SJung-uk Kim     /* Dummy index - must always be the last entry */
77217f01e99SJung-uk Kim     TLSEXT_IDX_num_builtins
77317f01e99SJung-uk Kim } TLSEXT_INDEX;
77417f01e99SJung-uk Kim 
77517f01e99SJung-uk Kim DEFINE_LHASH_OF(SSL_SESSION);
77617f01e99SJung-uk Kim /* Needed in ssl_cert.c */
77717f01e99SJung-uk Kim DEFINE_LHASH_OF(X509_NAME);
77817f01e99SJung-uk Kim 
77917f01e99SJung-uk Kim # define TLSEXT_KEYNAME_LENGTH  16
78017f01e99SJung-uk Kim # define TLSEXT_TICK_KEY_LENGTH 32
78117f01e99SJung-uk Kim 
78217f01e99SJung-uk Kim typedef struct ssl_ctx_ext_secure_st {
78317f01e99SJung-uk Kim     unsigned char tick_hmac_key[TLSEXT_TICK_KEY_LENGTH];
78417f01e99SJung-uk Kim     unsigned char tick_aes_key[TLSEXT_TICK_KEY_LENGTH];
78517f01e99SJung-uk Kim } SSL_CTX_EXT_SECURE;
78617f01e99SJung-uk Kim 
787b077aed3SPierre Pronchery /*
788b077aed3SPierre Pronchery  * Helper function for HMAC
789b077aed3SPierre Pronchery  * The structure should be considered opaque, it will change once the low
790b077aed3SPierre Pronchery  * level deprecated calls are removed.  At that point it can be replaced
791b077aed3SPierre Pronchery  * by EVP_MAC_CTX and most of the functions converted to macros or inlined
792b077aed3SPierre Pronchery  * directly.
793b077aed3SPierre Pronchery  */
794b077aed3SPierre Pronchery typedef struct ssl_hmac_st {
795b077aed3SPierre Pronchery     EVP_MAC_CTX *ctx;
796b077aed3SPierre Pronchery # ifndef OPENSSL_NO_DEPRECATED_3_0
797b077aed3SPierre Pronchery     HMAC_CTX *old_ctx;
798b077aed3SPierre Pronchery # endif
799b077aed3SPierre Pronchery } SSL_HMAC;
800b077aed3SPierre Pronchery 
801b077aed3SPierre Pronchery SSL_HMAC *ssl_hmac_new(const SSL_CTX *ctx);
802b077aed3SPierre Pronchery void ssl_hmac_free(SSL_HMAC *ctx);
803b077aed3SPierre Pronchery # ifndef OPENSSL_NO_DEPRECATED_3_0
804b077aed3SPierre Pronchery HMAC_CTX *ssl_hmac_get0_HMAC_CTX(SSL_HMAC *ctx);
805b077aed3SPierre Pronchery # endif
806b077aed3SPierre Pronchery EVP_MAC_CTX *ssl_hmac_get0_EVP_MAC_CTX(SSL_HMAC *ctx);
807b077aed3SPierre Pronchery int ssl_hmac_init(SSL_HMAC *ctx, void *key, size_t len, char *md);
808b077aed3SPierre Pronchery int ssl_hmac_update(SSL_HMAC *ctx, const unsigned char *data, size_t len);
809b077aed3SPierre Pronchery int ssl_hmac_final(SSL_HMAC *ctx, unsigned char *md, size_t *len,
810b077aed3SPierre Pronchery                    size_t max_size);
811b077aed3SPierre Pronchery size_t ssl_hmac_size(const SSL_HMAC *ctx);
812b077aed3SPierre Pronchery 
813b077aed3SPierre Pronchery int ssl_get_EC_curve_nid(const EVP_PKEY *pkey);
814b077aed3SPierre Pronchery __owur int tls13_set_encoded_pub_key(EVP_PKEY *pkey,
815b077aed3SPierre Pronchery                                      const unsigned char *enckey,
816b077aed3SPierre Pronchery                                      size_t enckeylen);
817b077aed3SPierre Pronchery 
818b077aed3SPierre Pronchery typedef struct tls_group_info_st {
819b077aed3SPierre Pronchery     char *tlsname;           /* Curve Name as in TLS specs */
820b077aed3SPierre Pronchery     char *realname;          /* Curve Name according to provider */
821b077aed3SPierre Pronchery     char *algorithm;         /* Algorithm name to fetch */
822b077aed3SPierre Pronchery     unsigned int secbits;    /* Bits of security (from SP800-57) */
823b077aed3SPierre Pronchery     uint16_t group_id;       /* Group ID */
824b077aed3SPierre Pronchery     int mintls;              /* Minimum TLS version, -1 unsupported */
825b077aed3SPierre Pronchery     int maxtls;              /* Maximum TLS version (or 0 for undefined) */
826b077aed3SPierre Pronchery     int mindtls;             /* Minimum DTLS version, -1 unsupported */
827b077aed3SPierre Pronchery     int maxdtls;             /* Maximum DTLS version (or 0 for undefined) */
828b077aed3SPierre Pronchery     char is_kem;             /* Mode for this Group: 0 is KEX, 1 is KEM */
829b077aed3SPierre Pronchery } TLS_GROUP_INFO;
830b077aed3SPierre Pronchery 
831b077aed3SPierre Pronchery /* flags values */
832b077aed3SPierre Pronchery # define TLS_GROUP_TYPE             0x0000000FU /* Mask for group type */
833b077aed3SPierre Pronchery # define TLS_GROUP_CURVE_PRIME      0x00000001U
834b077aed3SPierre Pronchery # define TLS_GROUP_CURVE_CHAR2      0x00000002U
835b077aed3SPierre Pronchery # define TLS_GROUP_CURVE_CUSTOM     0x00000004U
836b077aed3SPierre Pronchery # define TLS_GROUP_FFDHE            0x00000008U
837b077aed3SPierre Pronchery # define TLS_GROUP_ONLY_FOR_TLS1_3  0x00000010U
838b077aed3SPierre Pronchery 
839b077aed3SPierre Pronchery # define TLS_GROUP_FFDHE_FOR_TLS1_3 (TLS_GROUP_FFDHE|TLS_GROUP_ONLY_FOR_TLS1_3)
840b077aed3SPierre Pronchery 
84117f01e99SJung-uk Kim struct ssl_ctx_st {
842b077aed3SPierre Pronchery     OSSL_LIB_CTX *libctx;
843b077aed3SPierre Pronchery 
84417f01e99SJung-uk Kim     const SSL_METHOD *method;
84517f01e99SJung-uk Kim     STACK_OF(SSL_CIPHER) *cipher_list;
84617f01e99SJung-uk Kim     /* same as above but sorted for lookup */
84717f01e99SJung-uk Kim     STACK_OF(SSL_CIPHER) *cipher_list_by_id;
84817f01e99SJung-uk Kim     /* TLSv1.3 specific ciphersuites */
84917f01e99SJung-uk Kim     STACK_OF(SSL_CIPHER) *tls13_ciphersuites;
85017f01e99SJung-uk Kim     struct x509_store_st /* X509_STORE */ *cert_store;
85117f01e99SJung-uk Kim     LHASH_OF(SSL_SESSION) *sessions;
85217f01e99SJung-uk Kim     /*
85317f01e99SJung-uk Kim      * Most session-ids that will be cached, default is
85417f01e99SJung-uk Kim      * SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited.
85517f01e99SJung-uk Kim      */
85617f01e99SJung-uk Kim     size_t session_cache_size;
85717f01e99SJung-uk Kim     struct ssl_session_st *session_cache_head;
85817f01e99SJung-uk Kim     struct ssl_session_st *session_cache_tail;
85917f01e99SJung-uk Kim     /*
86017f01e99SJung-uk Kim      * This can have one of 2 values, ored together, SSL_SESS_CACHE_CLIENT,
86117f01e99SJung-uk Kim      * SSL_SESS_CACHE_SERVER, Default is SSL_SESSION_CACHE_SERVER, which
86217f01e99SJung-uk Kim      * means only SSL_accept will cache SSL_SESSIONS.
86317f01e99SJung-uk Kim      */
86417f01e99SJung-uk Kim     uint32_t session_cache_mode;
86517f01e99SJung-uk Kim     /*
86617f01e99SJung-uk Kim      * If timeout is not 0, it is the default timeout value set when
86717f01e99SJung-uk Kim      * SSL_new() is called.  This has been put in to make life easier to set
86817f01e99SJung-uk Kim      * things up
86917f01e99SJung-uk Kim      */
87017f01e99SJung-uk Kim     long session_timeout;
87117f01e99SJung-uk Kim     /*
87217f01e99SJung-uk Kim      * If this callback is not null, it will be called each time a session id
87317f01e99SJung-uk Kim      * is added to the cache.  If this function returns 1, it means that the
87417f01e99SJung-uk Kim      * callback will do a SSL_SESSION_free() when it has finished using it.
87517f01e99SJung-uk Kim      * Otherwise, on 0, it means the callback has finished with it. If
87617f01e99SJung-uk Kim      * remove_session_cb is not null, it will be called when a session-id is
87717f01e99SJung-uk Kim      * removed from the cache.  After the call, OpenSSL will
87817f01e99SJung-uk Kim      * SSL_SESSION_free() it.
87917f01e99SJung-uk Kim      */
88017f01e99SJung-uk Kim     int (*new_session_cb) (struct ssl_st *ssl, SSL_SESSION *sess);
88117f01e99SJung-uk Kim     void (*remove_session_cb) (struct ssl_ctx_st *ctx, SSL_SESSION *sess);
88217f01e99SJung-uk Kim     SSL_SESSION *(*get_session_cb) (struct ssl_st *ssl,
88317f01e99SJung-uk Kim                                     const unsigned char *data, int len,
88417f01e99SJung-uk Kim                                     int *copy);
88517f01e99SJung-uk Kim     struct {
88617f01e99SJung-uk Kim         TSAN_QUALIFIER int sess_connect;       /* SSL new conn - started */
88717f01e99SJung-uk Kim         TSAN_QUALIFIER int sess_connect_renegotiate; /* SSL reneg - requested */
88817f01e99SJung-uk Kim         TSAN_QUALIFIER int sess_connect_good;  /* SSL new conne/reneg - finished */
88917f01e99SJung-uk Kim         TSAN_QUALIFIER int sess_accept;        /* SSL new accept - started */
89017f01e99SJung-uk Kim         TSAN_QUALIFIER int sess_accept_renegotiate; /* SSL reneg - requested */
89117f01e99SJung-uk Kim         TSAN_QUALIFIER int sess_accept_good;   /* SSL accept/reneg - finished */
89217f01e99SJung-uk Kim         TSAN_QUALIFIER int sess_miss;          /* session lookup misses */
89317f01e99SJung-uk Kim         TSAN_QUALIFIER int sess_timeout;       /* reuse attempt on timeouted session */
89417f01e99SJung-uk Kim         TSAN_QUALIFIER int sess_cache_full;    /* session removed due to full cache */
89517f01e99SJung-uk Kim         TSAN_QUALIFIER int sess_hit;           /* session reuse actually done */
89617f01e99SJung-uk Kim         TSAN_QUALIFIER int sess_cb_hit;        /* session-id that was not in
89717f01e99SJung-uk Kim                                                 * the cache was passed back via
89817f01e99SJung-uk Kim                                                 * the callback. This indicates
89917f01e99SJung-uk Kim                                                 * that the application is
90017f01e99SJung-uk Kim                                                 * supplying session-id's from
90117f01e99SJung-uk Kim                                                 * other processes - spooky
90217f01e99SJung-uk Kim                                                 * :-) */
90317f01e99SJung-uk Kim     } stats;
904b077aed3SPierre Pronchery #ifdef TSAN_REQUIRES_LOCKING
905b077aed3SPierre Pronchery     CRYPTO_RWLOCK *tsan_lock;
906b077aed3SPierre Pronchery #endif
90717f01e99SJung-uk Kim 
90817f01e99SJung-uk Kim     CRYPTO_REF_COUNT references;
90917f01e99SJung-uk Kim 
91017f01e99SJung-uk Kim     /* if defined, these override the X509_verify_cert() calls */
91117f01e99SJung-uk Kim     int (*app_verify_callback) (X509_STORE_CTX *, void *);
91217f01e99SJung-uk Kim     void *app_verify_arg;
91317f01e99SJung-uk Kim     /*
91417f01e99SJung-uk Kim      * before OpenSSL 0.9.7, 'app_verify_arg' was ignored
91517f01e99SJung-uk Kim      * ('app_verify_callback' was called with just one argument)
91617f01e99SJung-uk Kim      */
91717f01e99SJung-uk Kim 
91817f01e99SJung-uk Kim     /* Default password callback. */
91917f01e99SJung-uk Kim     pem_password_cb *default_passwd_callback;
92017f01e99SJung-uk Kim 
92117f01e99SJung-uk Kim     /* Default password callback user data. */
92217f01e99SJung-uk Kim     void *default_passwd_callback_userdata;
92317f01e99SJung-uk Kim 
92417f01e99SJung-uk Kim     /* get client cert callback */
92517f01e99SJung-uk Kim     int (*client_cert_cb) (SSL *ssl, X509 **x509, EVP_PKEY **pkey);
92617f01e99SJung-uk Kim 
92717f01e99SJung-uk Kim     /* cookie generate callback */
92817f01e99SJung-uk Kim     int (*app_gen_cookie_cb) (SSL *ssl, unsigned char *cookie,
92917f01e99SJung-uk Kim                               unsigned int *cookie_len);
93017f01e99SJung-uk Kim 
93117f01e99SJung-uk Kim     /* verify cookie callback */
93217f01e99SJung-uk Kim     int (*app_verify_cookie_cb) (SSL *ssl, const unsigned char *cookie,
93317f01e99SJung-uk Kim                                  unsigned int cookie_len);
93417f01e99SJung-uk Kim 
93517f01e99SJung-uk Kim     /* TLS1.3 app-controlled cookie generate callback */
93617f01e99SJung-uk Kim     int (*gen_stateless_cookie_cb) (SSL *ssl, unsigned char *cookie,
93717f01e99SJung-uk Kim                                     size_t *cookie_len);
93817f01e99SJung-uk Kim 
93917f01e99SJung-uk Kim     /* TLS1.3 verify app-controlled cookie callback */
94017f01e99SJung-uk Kim     int (*verify_stateless_cookie_cb) (SSL *ssl, const unsigned char *cookie,
94117f01e99SJung-uk Kim                                        size_t cookie_len);
94217f01e99SJung-uk Kim 
94317f01e99SJung-uk Kim     CRYPTO_EX_DATA ex_data;
94417f01e99SJung-uk Kim 
94517f01e99SJung-uk Kim     const EVP_MD *md5;          /* For SSLv3/TLSv1 'ssl3-md5' */
946b077aed3SPierre Pronchery     const EVP_MD *sha1;         /* For SSLv3/TLSv1 'ssl3-sha1' */
94717f01e99SJung-uk Kim 
94817f01e99SJung-uk Kim     STACK_OF(X509) *extra_certs;
94917f01e99SJung-uk Kim     STACK_OF(SSL_COMP) *comp_methods; /* stack of SSL_COMP, SSLv3/TLSv1 */
95017f01e99SJung-uk Kim 
95117f01e99SJung-uk Kim     /* Default values used when no per-SSL value is defined follow */
95217f01e99SJung-uk Kim 
95317f01e99SJung-uk Kim     /* used if SSL's info_callback is NULL */
95417f01e99SJung-uk Kim     void (*info_callback) (const SSL *ssl, int type, int val);
95517f01e99SJung-uk Kim 
95617f01e99SJung-uk Kim     /*
95717f01e99SJung-uk Kim      * What we put in certificate_authorities extension for TLS 1.3
95817f01e99SJung-uk Kim      * (ClientHello and CertificateRequest) or just client cert requests for
95917f01e99SJung-uk Kim      * earlier versions. If client_ca_names is populated then it is only used
96017f01e99SJung-uk Kim      * for client cert requests, and in preference to ca_names.
96117f01e99SJung-uk Kim      */
96217f01e99SJung-uk Kim     STACK_OF(X509_NAME) *ca_names;
96317f01e99SJung-uk Kim     STACK_OF(X509_NAME) *client_ca_names;
96417f01e99SJung-uk Kim 
96517f01e99SJung-uk Kim     /*
96617f01e99SJung-uk Kim      * Default values to use in SSL structures follow (these are copied by
96717f01e99SJung-uk Kim      * SSL_new)
96817f01e99SJung-uk Kim      */
96917f01e99SJung-uk Kim 
970b077aed3SPierre Pronchery     uint64_t options;
97117f01e99SJung-uk Kim     uint32_t mode;
97217f01e99SJung-uk Kim     int min_proto_version;
97317f01e99SJung-uk Kim     int max_proto_version;
97417f01e99SJung-uk Kim     size_t max_cert_list;
97517f01e99SJung-uk Kim 
97617f01e99SJung-uk Kim     struct cert_st /* CERT */ *cert;
97717f01e99SJung-uk Kim     int read_ahead;
97817f01e99SJung-uk Kim 
97917f01e99SJung-uk Kim     /* callback that allows applications to peek at protocol messages */
98017f01e99SJung-uk Kim     void (*msg_callback) (int write_p, int version, int content_type,
98117f01e99SJung-uk Kim                           const void *buf, size_t len, SSL *ssl, void *arg);
98217f01e99SJung-uk Kim     void *msg_callback_arg;
98317f01e99SJung-uk Kim 
98417f01e99SJung-uk Kim     uint32_t verify_mode;
98517f01e99SJung-uk Kim     size_t sid_ctx_length;
98617f01e99SJung-uk Kim     unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
98717f01e99SJung-uk Kim     /* called 'verify_callback' in the SSL */
98817f01e99SJung-uk Kim     int (*default_verify_callback) (int ok, X509_STORE_CTX *ctx);
98917f01e99SJung-uk Kim 
99017f01e99SJung-uk Kim     /* Default generate session ID callback. */
99117f01e99SJung-uk Kim     GEN_SESSION_CB generate_session_id;
99217f01e99SJung-uk Kim 
99317f01e99SJung-uk Kim     X509_VERIFY_PARAM *param;
99417f01e99SJung-uk Kim 
99517f01e99SJung-uk Kim     int quiet_shutdown;
99617f01e99SJung-uk Kim 
99717f01e99SJung-uk Kim # ifndef OPENSSL_NO_CT
99817f01e99SJung-uk Kim     CTLOG_STORE *ctlog_store;   /* CT Log Store */
99917f01e99SJung-uk Kim     /*
100017f01e99SJung-uk Kim      * Validates that the SCTs (Signed Certificate Timestamps) are sufficient.
100117f01e99SJung-uk Kim      * If they are not, the connection should be aborted.
100217f01e99SJung-uk Kim      */
100317f01e99SJung-uk Kim     ssl_ct_validation_cb ct_validation_callback;
100417f01e99SJung-uk Kim     void *ct_validation_callback_arg;
100517f01e99SJung-uk Kim # endif
100617f01e99SJung-uk Kim 
100717f01e99SJung-uk Kim     /*
100817f01e99SJung-uk Kim      * If we're using more than one pipeline how should we divide the data
100917f01e99SJung-uk Kim      * up between the pipes?
101017f01e99SJung-uk Kim      */
101117f01e99SJung-uk Kim     size_t split_send_fragment;
101217f01e99SJung-uk Kim     /*
101317f01e99SJung-uk Kim      * Maximum amount of data to send in one fragment. actual record size can
101417f01e99SJung-uk Kim      * be more than this due to padding and MAC overheads.
101517f01e99SJung-uk Kim      */
101617f01e99SJung-uk Kim     size_t max_send_fragment;
101717f01e99SJung-uk Kim 
101817f01e99SJung-uk Kim     /* Up to how many pipelines should we use? If 0 then 1 is assumed */
101917f01e99SJung-uk Kim     size_t max_pipelines;
102017f01e99SJung-uk Kim 
102117f01e99SJung-uk Kim     /* The default read buffer length to use (0 means not set) */
102217f01e99SJung-uk Kim     size_t default_read_buf_len;
102317f01e99SJung-uk Kim 
102417f01e99SJung-uk Kim # ifndef OPENSSL_NO_ENGINE
102517f01e99SJung-uk Kim     /*
102617f01e99SJung-uk Kim      * Engine to pass requests for client certs to
102717f01e99SJung-uk Kim      */
102817f01e99SJung-uk Kim     ENGINE *client_cert_engine;
102917f01e99SJung-uk Kim # endif
103017f01e99SJung-uk Kim 
103117f01e99SJung-uk Kim     /* ClientHello callback.  Mostly for extensions, but not entirely. */
103217f01e99SJung-uk Kim     SSL_client_hello_cb_fn client_hello_cb;
103317f01e99SJung-uk Kim     void *client_hello_cb_arg;
103417f01e99SJung-uk Kim 
103517f01e99SJung-uk Kim     /* TLS extensions. */
103617f01e99SJung-uk Kim     struct {
103717f01e99SJung-uk Kim         /* TLS extensions servername callback */
103817f01e99SJung-uk Kim         int (*servername_cb) (SSL *, int *, void *);
103917f01e99SJung-uk Kim         void *servername_arg;
104017f01e99SJung-uk Kim         /* RFC 4507 session ticket keys */
104117f01e99SJung-uk Kim         unsigned char tick_key_name[TLSEXT_KEYNAME_LENGTH];
104217f01e99SJung-uk Kim         SSL_CTX_EXT_SECURE *secure;
1043b077aed3SPierre Pronchery # ifndef OPENSSL_NO_DEPRECATED_3_0
104417f01e99SJung-uk Kim         /* Callback to support customisation of ticket key setting */
104517f01e99SJung-uk Kim         int (*ticket_key_cb) (SSL *ssl,
104617f01e99SJung-uk Kim                               unsigned char *name, unsigned char *iv,
104717f01e99SJung-uk Kim                               EVP_CIPHER_CTX *ectx, HMAC_CTX *hctx, int enc);
1048b077aed3SPierre Pronchery #endif
1049b077aed3SPierre Pronchery         int (*ticket_key_evp_cb) (SSL *ssl,
1050b077aed3SPierre Pronchery                                   unsigned char *name, unsigned char *iv,
1051b077aed3SPierre Pronchery                                   EVP_CIPHER_CTX *ectx, EVP_MAC_CTX *hctx,
1052b077aed3SPierre Pronchery                                   int enc);
105317f01e99SJung-uk Kim 
105417f01e99SJung-uk Kim         /* certificate status request info */
105517f01e99SJung-uk Kim         /* Callback for status request */
105617f01e99SJung-uk Kim         int (*status_cb) (SSL *ssl, void *arg);
105717f01e99SJung-uk Kim         void *status_arg;
105817f01e99SJung-uk Kim         /* ext status type used for CSR extension (OCSP Stapling) */
105917f01e99SJung-uk Kim         int status_type;
106017f01e99SJung-uk Kim         /* RFC 4366 Maximum Fragment Length Negotiation */
106117f01e99SJung-uk Kim         uint8_t max_fragment_len_mode;
106217f01e99SJung-uk Kim 
106317f01e99SJung-uk Kim         /* EC extension values inherited by SSL structure */
106417f01e99SJung-uk Kim         size_t ecpointformats_len;
106517f01e99SJung-uk Kim         unsigned char *ecpointformats;
1066b077aed3SPierre Pronchery 
106717f01e99SJung-uk Kim         size_t supportedgroups_len;
106817f01e99SJung-uk Kim         uint16_t *supportedgroups;
106917f01e99SJung-uk Kim 
1070b077aed3SPierre Pronchery         uint16_t *supported_groups_default;
1071b077aed3SPierre Pronchery         size_t supported_groups_default_len;
107217f01e99SJung-uk Kim         /*
107317f01e99SJung-uk Kim          * ALPN information (we are in the process of transitioning from NPN to
107417f01e99SJung-uk Kim          * ALPN.)
107517f01e99SJung-uk Kim          */
107617f01e99SJung-uk Kim 
107717f01e99SJung-uk Kim         /*-
107817f01e99SJung-uk Kim          * For a server, this contains a callback function that allows the
107917f01e99SJung-uk Kim          * server to select the protocol for the connection.
108017f01e99SJung-uk Kim          *   out: on successful return, this must point to the raw protocol
108117f01e99SJung-uk Kim          *        name (without the length prefix).
108217f01e99SJung-uk Kim          *   outlen: on successful return, this contains the length of |*out|.
108317f01e99SJung-uk Kim          *   in: points to the client's list of supported protocols in
108417f01e99SJung-uk Kim          *       wire-format.
108517f01e99SJung-uk Kim          *   inlen: the length of |in|.
108617f01e99SJung-uk Kim          */
108717f01e99SJung-uk Kim         int (*alpn_select_cb) (SSL *s,
108817f01e99SJung-uk Kim                                const unsigned char **out,
108917f01e99SJung-uk Kim                                unsigned char *outlen,
109017f01e99SJung-uk Kim                                const unsigned char *in,
109117f01e99SJung-uk Kim                                unsigned int inlen, void *arg);
109217f01e99SJung-uk Kim         void *alpn_select_cb_arg;
109317f01e99SJung-uk Kim 
109417f01e99SJung-uk Kim         /*
109517f01e99SJung-uk Kim          * For a client, this contains the list of supported protocols in wire
109617f01e99SJung-uk Kim          * format.
109717f01e99SJung-uk Kim          */
109817f01e99SJung-uk Kim         unsigned char *alpn;
109917f01e99SJung-uk Kim         size_t alpn_len;
110017f01e99SJung-uk Kim 
110117f01e99SJung-uk Kim # ifndef OPENSSL_NO_NEXTPROTONEG
110217f01e99SJung-uk Kim         /* Next protocol negotiation information */
110317f01e99SJung-uk Kim 
110417f01e99SJung-uk Kim         /*
110517f01e99SJung-uk Kim          * For a server, this contains a callback function by which the set of
110617f01e99SJung-uk Kim          * advertised protocols can be provided.
110717f01e99SJung-uk Kim          */
110817f01e99SJung-uk Kim         SSL_CTX_npn_advertised_cb_func npn_advertised_cb;
110917f01e99SJung-uk Kim         void *npn_advertised_cb_arg;
111017f01e99SJung-uk Kim         /*
111117f01e99SJung-uk Kim          * For a client, this contains a callback function that selects the next
111217f01e99SJung-uk Kim          * protocol from the list provided by the server.
111317f01e99SJung-uk Kim          */
111417f01e99SJung-uk Kim         SSL_CTX_npn_select_cb_func npn_select_cb;
111517f01e99SJung-uk Kim         void *npn_select_cb_arg;
111617f01e99SJung-uk Kim # endif
111717f01e99SJung-uk Kim 
111817f01e99SJung-uk Kim         unsigned char cookie_hmac_key[SHA256_DIGEST_LENGTH];
111917f01e99SJung-uk Kim     } ext;
112017f01e99SJung-uk Kim 
112117f01e99SJung-uk Kim # ifndef OPENSSL_NO_PSK
112217f01e99SJung-uk Kim     SSL_psk_client_cb_func psk_client_callback;
112317f01e99SJung-uk Kim     SSL_psk_server_cb_func psk_server_callback;
112417f01e99SJung-uk Kim # endif
112517f01e99SJung-uk Kim     SSL_psk_find_session_cb_func psk_find_session_cb;
112617f01e99SJung-uk Kim     SSL_psk_use_session_cb_func psk_use_session_cb;
112717f01e99SJung-uk Kim 
112817f01e99SJung-uk Kim # ifndef OPENSSL_NO_SRP
112917f01e99SJung-uk Kim     SRP_CTX srp_ctx;            /* ctx for SRP authentication */
113017f01e99SJung-uk Kim # endif
113117f01e99SJung-uk Kim 
113217f01e99SJung-uk Kim     /* Shared DANE context */
113317f01e99SJung-uk Kim     struct dane_ctx_st dane;
113417f01e99SJung-uk Kim 
113517f01e99SJung-uk Kim # ifndef OPENSSL_NO_SRTP
113617f01e99SJung-uk Kim     /* SRTP profiles we are willing to do from RFC 5764 */
113717f01e99SJung-uk Kim     STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles;
113817f01e99SJung-uk Kim # endif
113917f01e99SJung-uk Kim     /*
114017f01e99SJung-uk Kim      * Callback for disabling session caching and ticket support on a session
114117f01e99SJung-uk Kim      * basis, depending on the chosen cipher.
114217f01e99SJung-uk Kim      */
114317f01e99SJung-uk Kim     int (*not_resumable_session_cb) (SSL *ssl, int is_forward_secure);
114417f01e99SJung-uk Kim 
114517f01e99SJung-uk Kim     CRYPTO_RWLOCK *lock;
114617f01e99SJung-uk Kim 
114717f01e99SJung-uk Kim     /*
114817f01e99SJung-uk Kim      * Callback for logging key material for use with debugging tools like
114917f01e99SJung-uk Kim      * Wireshark. The callback should log `line` followed by a newline.
115017f01e99SJung-uk Kim      */
115117f01e99SJung-uk Kim     SSL_CTX_keylog_cb_func keylog_callback;
115217f01e99SJung-uk Kim 
115317f01e99SJung-uk Kim     /*
115417f01e99SJung-uk Kim      * The maximum number of bytes advertised in session tickets that can be
115517f01e99SJung-uk Kim      * sent as early data.
115617f01e99SJung-uk Kim      */
115717f01e99SJung-uk Kim     uint32_t max_early_data;
115817f01e99SJung-uk Kim 
115917f01e99SJung-uk Kim     /*
116017f01e99SJung-uk Kim      * The maximum number of bytes of early data that a server will tolerate
116117f01e99SJung-uk Kim      * (which should be at least as much as max_early_data).
116217f01e99SJung-uk Kim      */
116317f01e99SJung-uk Kim     uint32_t recv_max_early_data;
116417f01e99SJung-uk Kim 
116517f01e99SJung-uk Kim     /* TLS1.3 padding callback */
116617f01e99SJung-uk Kim     size_t (*record_padding_cb)(SSL *s, int type, size_t len, void *arg);
116717f01e99SJung-uk Kim     void *record_padding_arg;
116817f01e99SJung-uk Kim     size_t block_padding;
116917f01e99SJung-uk Kim 
117017f01e99SJung-uk Kim     /* Session ticket appdata */
117117f01e99SJung-uk Kim     SSL_CTX_generate_session_ticket_fn generate_ticket_cb;
117217f01e99SJung-uk Kim     SSL_CTX_decrypt_session_ticket_fn decrypt_ticket_cb;
117317f01e99SJung-uk Kim     void *ticket_cb_data;
117417f01e99SJung-uk Kim 
117517f01e99SJung-uk Kim     /* The number of TLS1.3 tickets to automatically send */
117617f01e99SJung-uk Kim     size_t num_tickets;
117717f01e99SJung-uk Kim 
117817f01e99SJung-uk Kim     /* Callback to determine if early_data is acceptable or not */
117917f01e99SJung-uk Kim     SSL_allow_early_data_cb_fn allow_early_data_cb;
118017f01e99SJung-uk Kim     void *allow_early_data_cb_data;
118117f01e99SJung-uk Kim 
118217f01e99SJung-uk Kim     /* Do we advertise Post-handshake auth support? */
118317f01e99SJung-uk Kim     int pha_enabled;
1184b077aed3SPierre Pronchery 
1185b077aed3SPierre Pronchery     /* Callback for SSL async handling */
1186b077aed3SPierre Pronchery     SSL_async_callback_fn async_cb;
1187b077aed3SPierre Pronchery     void *async_cb_arg;
1188b077aed3SPierre Pronchery 
1189b077aed3SPierre Pronchery     char *propq;
1190b077aed3SPierre Pronchery 
1191b077aed3SPierre Pronchery     int ssl_mac_pkey_id[SSL_MD_NUM_IDX];
1192b077aed3SPierre Pronchery     const EVP_CIPHER *ssl_cipher_methods[SSL_ENC_NUM_IDX];
1193b077aed3SPierre Pronchery     const EVP_MD *ssl_digest_methods[SSL_MD_NUM_IDX];
1194b077aed3SPierre Pronchery     size_t ssl_mac_secret_size[SSL_MD_NUM_IDX];
1195b077aed3SPierre Pronchery 
1196b077aed3SPierre Pronchery     /* Cache of all sigalgs we know and whether they are available or not */
1197b077aed3SPierre Pronchery     struct sigalg_lookup_st *sigalg_lookup_cache;
1198b077aed3SPierre Pronchery 
1199b077aed3SPierre Pronchery     TLS_GROUP_INFO *group_list;
1200b077aed3SPierre Pronchery     size_t group_list_len;
1201b077aed3SPierre Pronchery     size_t group_list_max_len;
1202b077aed3SPierre Pronchery 
1203b077aed3SPierre Pronchery     /* masks of disabled algorithms */
1204b077aed3SPierre Pronchery     uint32_t disabled_enc_mask;
1205b077aed3SPierre Pronchery     uint32_t disabled_mac_mask;
1206b077aed3SPierre Pronchery     uint32_t disabled_mkey_mask;
1207b077aed3SPierre Pronchery     uint32_t disabled_auth_mask;
120817f01e99SJung-uk Kim };
120917f01e99SJung-uk Kim 
1210b077aed3SPierre Pronchery typedef struct cert_pkey_st CERT_PKEY;
1211b077aed3SPierre Pronchery 
121217f01e99SJung-uk Kim struct ssl_st {
121317f01e99SJung-uk Kim     /*
121417f01e99SJung-uk Kim      * protocol version (one of SSL2_VERSION, SSL3_VERSION, TLS1_VERSION,
121517f01e99SJung-uk Kim      * DTLS1_VERSION)
121617f01e99SJung-uk Kim      */
121717f01e99SJung-uk Kim     int version;
121817f01e99SJung-uk Kim     /* SSLv3 */
121917f01e99SJung-uk Kim     const SSL_METHOD *method;
122017f01e99SJung-uk Kim     /*
122117f01e99SJung-uk Kim      * There are 2 BIO's even though they are normally both the same.  This
122217f01e99SJung-uk Kim      * is so data can be read and written to different handlers
122317f01e99SJung-uk Kim      */
122417f01e99SJung-uk Kim     /* used by SSL_read */
122517f01e99SJung-uk Kim     BIO *rbio;
122617f01e99SJung-uk Kim     /* used by SSL_write */
122717f01e99SJung-uk Kim     BIO *wbio;
122817f01e99SJung-uk Kim     /* used during session-id reuse to concatenate messages */
122917f01e99SJung-uk Kim     BIO *bbio;
123017f01e99SJung-uk Kim     /*
123117f01e99SJung-uk Kim      * This holds a variable that indicates what we were doing when a 0 or -1
123217f01e99SJung-uk Kim      * is returned.  This is needed for non-blocking IO so we know what
123317f01e99SJung-uk Kim      * request needs re-doing when in SSL_accept or SSL_connect
123417f01e99SJung-uk Kim      */
123517f01e99SJung-uk Kim     int rwstate;
123617f01e99SJung-uk Kim     int (*handshake_func) (SSL *);
123717f01e99SJung-uk Kim     /*
123817f01e99SJung-uk Kim      * Imagine that here's a boolean member "init" that is switched as soon
123917f01e99SJung-uk Kim      * as SSL_set_{accept/connect}_state is called for the first time, so
124017f01e99SJung-uk Kim      * that "state" and "handshake_func" are properly initialized.  But as
124117f01e99SJung-uk Kim      * handshake_func is == 0 until then, we use this test instead of an
124217f01e99SJung-uk Kim      * "init" member.
124317f01e99SJung-uk Kim      */
124417f01e99SJung-uk Kim     /* are we the server side? */
124517f01e99SJung-uk Kim     int server;
124617f01e99SJung-uk Kim     /*
124717f01e99SJung-uk Kim      * Generate a new session or reuse an old one.
124817f01e99SJung-uk Kim      * NB: For servers, the 'new' session may actually be a previously
124917f01e99SJung-uk Kim      * cached session or even the previous session unless
125017f01e99SJung-uk Kim      * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION is set
125117f01e99SJung-uk Kim      */
125217f01e99SJung-uk Kim     int new_session;
125317f01e99SJung-uk Kim     /* don't send shutdown packets */
125417f01e99SJung-uk Kim     int quiet_shutdown;
125517f01e99SJung-uk Kim     /* we have shut things down, 0x01 sent, 0x02 for received */
125617f01e99SJung-uk Kim     int shutdown;
125717f01e99SJung-uk Kim     /* where we are */
125817f01e99SJung-uk Kim     OSSL_STATEM statem;
125917f01e99SJung-uk Kim     SSL_EARLY_DATA_STATE early_data_state;
126017f01e99SJung-uk Kim     BUF_MEM *init_buf;          /* buffer used during init */
126117f01e99SJung-uk Kim     void *init_msg;             /* pointer to handshake message body, set by
126217f01e99SJung-uk Kim                                  * ssl3_get_message() */
126317f01e99SJung-uk Kim     size_t init_num;               /* amount read/written */
126417f01e99SJung-uk Kim     size_t init_off;               /* amount read/written */
1265b077aed3SPierre Pronchery 
1266b077aed3SPierre Pronchery     struct {
1267b077aed3SPierre Pronchery         long flags;
1268b077aed3SPierre Pronchery         size_t read_mac_secret_size;
1269b077aed3SPierre Pronchery         unsigned char read_mac_secret[EVP_MAX_MD_SIZE];
1270b077aed3SPierre Pronchery         size_t write_mac_secret_size;
1271b077aed3SPierre Pronchery         unsigned char write_mac_secret[EVP_MAX_MD_SIZE];
1272b077aed3SPierre Pronchery         unsigned char server_random[SSL3_RANDOM_SIZE];
1273b077aed3SPierre Pronchery         unsigned char client_random[SSL3_RANDOM_SIZE];
1274b077aed3SPierre Pronchery         /* flags for countermeasure against known-IV weakness */
1275b077aed3SPierre Pronchery         int need_empty_fragments;
1276b077aed3SPierre Pronchery         int empty_fragment_done;
1277b077aed3SPierre Pronchery         /* used during startup, digest all incoming/outgoing packets */
1278b077aed3SPierre Pronchery         BIO *handshake_buffer;
1279b077aed3SPierre Pronchery         /*
1280b077aed3SPierre Pronchery          * When handshake digest is determined, buffer is hashed and
1281b077aed3SPierre Pronchery          * freed and MD_CTX for the required digest is stored here.
1282b077aed3SPierre Pronchery          */
1283b077aed3SPierre Pronchery         EVP_MD_CTX *handshake_dgst;
1284b077aed3SPierre Pronchery         /*
1285b077aed3SPierre Pronchery          * Set whenever an expected ChangeCipherSpec message is processed.
1286b077aed3SPierre Pronchery          * Unset when the peer's Finished message is received.
1287b077aed3SPierre Pronchery          * Unexpected ChangeCipherSpec messages trigger a fatal alert.
1288b077aed3SPierre Pronchery          */
1289b077aed3SPierre Pronchery         int change_cipher_spec;
1290b077aed3SPierre Pronchery         int warn_alert;
1291b077aed3SPierre Pronchery         int fatal_alert;
1292b077aed3SPierre Pronchery         /*
1293b077aed3SPierre Pronchery          * we allow one fatal and one warning alert to be outstanding, send close
1294b077aed3SPierre Pronchery          * alert via the warning alert
1295b077aed3SPierre Pronchery          */
1296b077aed3SPierre Pronchery         int alert_dispatch;
1297b077aed3SPierre Pronchery         unsigned char send_alert[2];
1298b077aed3SPierre Pronchery         /*
1299b077aed3SPierre Pronchery          * This flag is set when we should renegotiate ASAP, basically when there
1300b077aed3SPierre Pronchery          * is no more data in the read or write buffers
1301b077aed3SPierre Pronchery          */
1302b077aed3SPierre Pronchery         int renegotiate;
1303b077aed3SPierre Pronchery         int total_renegotiations;
1304b077aed3SPierre Pronchery         int num_renegotiations;
1305b077aed3SPierre Pronchery         int in_read_app_data;
1306b077aed3SPierre Pronchery         struct {
1307b077aed3SPierre Pronchery             /* actually only need to be 16+20 for SSLv3 and 12 for TLS */
1308b077aed3SPierre Pronchery             unsigned char finish_md[EVP_MAX_MD_SIZE * 2];
1309b077aed3SPierre Pronchery             size_t finish_md_len;
1310b077aed3SPierre Pronchery             unsigned char peer_finish_md[EVP_MAX_MD_SIZE * 2];
1311b077aed3SPierre Pronchery             size_t peer_finish_md_len;
1312b077aed3SPierre Pronchery             size_t message_size;
1313b077aed3SPierre Pronchery             int message_type;
1314b077aed3SPierre Pronchery             /* used to hold the new cipher we are going to use */
1315b077aed3SPierre Pronchery             const SSL_CIPHER *new_cipher;
1316b077aed3SPierre Pronchery             EVP_PKEY *pkey;         /* holds short lived key exchange key */
1317b077aed3SPierre Pronchery             /* used for certificate requests */
1318b077aed3SPierre Pronchery             int cert_req;
1319b077aed3SPierre Pronchery             /* Certificate types in certificate request message. */
1320b077aed3SPierre Pronchery             uint8_t *ctype;
1321b077aed3SPierre Pronchery             size_t ctype_len;
1322b077aed3SPierre Pronchery             /* Certificate authorities list peer sent */
1323b077aed3SPierre Pronchery             STACK_OF(X509_NAME) *peer_ca_names;
1324b077aed3SPierre Pronchery             size_t key_block_length;
1325b077aed3SPierre Pronchery             unsigned char *key_block;
1326b077aed3SPierre Pronchery             const EVP_CIPHER *new_sym_enc;
1327b077aed3SPierre Pronchery             const EVP_MD *new_hash;
1328b077aed3SPierre Pronchery             int new_mac_pkey_type;
1329b077aed3SPierre Pronchery             size_t new_mac_secret_size;
1330b077aed3SPierre Pronchery # ifndef OPENSSL_NO_COMP
1331b077aed3SPierre Pronchery             const SSL_COMP *new_compression;
1332b077aed3SPierre Pronchery # else
1333b077aed3SPierre Pronchery             char *new_compression;
1334b077aed3SPierre Pronchery # endif
1335b077aed3SPierre Pronchery             int cert_request;
1336b077aed3SPierre Pronchery             /* Raw values of the cipher list from a client */
1337b077aed3SPierre Pronchery             unsigned char *ciphers_raw;
1338b077aed3SPierre Pronchery             size_t ciphers_rawlen;
1339b077aed3SPierre Pronchery             /* Temporary storage for premaster secret */
1340b077aed3SPierre Pronchery             unsigned char *pms;
1341b077aed3SPierre Pronchery             size_t pmslen;
1342b077aed3SPierre Pronchery # ifndef OPENSSL_NO_PSK
1343b077aed3SPierre Pronchery             /* Temporary storage for PSK key */
1344b077aed3SPierre Pronchery             unsigned char *psk;
1345b077aed3SPierre Pronchery             size_t psklen;
1346b077aed3SPierre Pronchery # endif
1347b077aed3SPierre Pronchery             /* Signature algorithm we actually use */
1348b077aed3SPierre Pronchery             const struct sigalg_lookup_st *sigalg;
1349b077aed3SPierre Pronchery             /* Pointer to certificate we use */
1350b077aed3SPierre Pronchery             CERT_PKEY *cert;
1351b077aed3SPierre Pronchery             /*
1352b077aed3SPierre Pronchery              * signature algorithms peer reports: e.g. supported signature
1353b077aed3SPierre Pronchery              * algorithms extension for server or as part of a certificate
1354b077aed3SPierre Pronchery              * request for client.
1355b077aed3SPierre Pronchery              * Keep track of the algorithms for TLS and X.509 usage separately.
1356b077aed3SPierre Pronchery              */
1357b077aed3SPierre Pronchery             uint16_t *peer_sigalgs;
1358b077aed3SPierre Pronchery             uint16_t *peer_cert_sigalgs;
1359b077aed3SPierre Pronchery             /* Size of above arrays */
1360b077aed3SPierre Pronchery             size_t peer_sigalgslen;
1361b077aed3SPierre Pronchery             size_t peer_cert_sigalgslen;
1362b077aed3SPierre Pronchery             /* Sigalg peer actually uses */
1363b077aed3SPierre Pronchery             const struct sigalg_lookup_st *peer_sigalg;
1364b077aed3SPierre Pronchery             /*
1365b077aed3SPierre Pronchery              * Set if corresponding CERT_PKEY can be used with current
1366b077aed3SPierre Pronchery              * SSL session: e.g. appropriate curve, signature algorithms etc.
1367b077aed3SPierre Pronchery              * If zero it can't be used at all.
1368b077aed3SPierre Pronchery              */
1369b077aed3SPierre Pronchery             uint32_t valid_flags[SSL_PKEY_NUM];
1370b077aed3SPierre Pronchery             /*
1371b077aed3SPierre Pronchery              * For servers the following masks are for the key and auth algorithms
1372b077aed3SPierre Pronchery              * that are supported by the certs below. For clients they are masks of
1373b077aed3SPierre Pronchery              * *disabled* algorithms based on the current session.
1374b077aed3SPierre Pronchery              */
1375b077aed3SPierre Pronchery             uint32_t mask_k;
1376b077aed3SPierre Pronchery             uint32_t mask_a;
1377b077aed3SPierre Pronchery             /*
1378b077aed3SPierre Pronchery              * The following are used by the client to see if a cipher is allowed or
1379b077aed3SPierre Pronchery              * not.  It contains the minimum and maximum version the client's using
1380b077aed3SPierre Pronchery              * based on what it knows so far.
1381b077aed3SPierre Pronchery              */
1382b077aed3SPierre Pronchery             int min_ver;
1383b077aed3SPierre Pronchery             int max_ver;
1384b077aed3SPierre Pronchery         } tmp;
1385b077aed3SPierre Pronchery 
1386b077aed3SPierre Pronchery         /* Connection binding to prevent renegotiation attacks */
1387b077aed3SPierre Pronchery         unsigned char previous_client_finished[EVP_MAX_MD_SIZE];
1388b077aed3SPierre Pronchery         size_t previous_client_finished_len;
1389b077aed3SPierre Pronchery         unsigned char previous_server_finished[EVP_MAX_MD_SIZE];
1390b077aed3SPierre Pronchery         size_t previous_server_finished_len;
1391b077aed3SPierre Pronchery         int send_connection_binding;
1392b077aed3SPierre Pronchery 
1393b077aed3SPierre Pronchery # ifndef OPENSSL_NO_NEXTPROTONEG
1394b077aed3SPierre Pronchery         /*
1395b077aed3SPierre Pronchery          * Set if we saw the Next Protocol Negotiation extension from our peer.
1396b077aed3SPierre Pronchery          */
1397b077aed3SPierre Pronchery         int npn_seen;
1398b077aed3SPierre Pronchery # endif
1399b077aed3SPierre Pronchery 
1400b077aed3SPierre Pronchery         /*
1401b077aed3SPierre Pronchery          * ALPN information (we are in the process of transitioning from NPN to
1402b077aed3SPierre Pronchery          * ALPN.)
1403b077aed3SPierre Pronchery          */
1404b077aed3SPierre Pronchery 
1405b077aed3SPierre Pronchery         /*
1406b077aed3SPierre Pronchery          * In a server these point to the selected ALPN protocol after the
1407b077aed3SPierre Pronchery          * ClientHello has been processed. In a client these contain the protocol
1408b077aed3SPierre Pronchery          * that the server selected once the ServerHello has been processed.
1409b077aed3SPierre Pronchery          */
1410b077aed3SPierre Pronchery         unsigned char *alpn_selected;
1411b077aed3SPierre Pronchery         size_t alpn_selected_len;
1412b077aed3SPierre Pronchery         /* used by the server to know what options were proposed */
1413b077aed3SPierre Pronchery         unsigned char *alpn_proposed;
1414b077aed3SPierre Pronchery         size_t alpn_proposed_len;
1415b077aed3SPierre Pronchery         /* used by the client to know if it actually sent alpn */
1416b077aed3SPierre Pronchery         int alpn_sent;
1417b077aed3SPierre Pronchery 
1418b077aed3SPierre Pronchery         /*
1419b077aed3SPierre Pronchery          * This is set to true if we believe that this is a version of Safari
1420b077aed3SPierre Pronchery          * running on OS X 10.6 or newer. We wish to know this because Safari on
1421b077aed3SPierre Pronchery          * 10.8 .. 10.8.3 has broken ECDHE-ECDSA support.
1422b077aed3SPierre Pronchery          */
1423b077aed3SPierre Pronchery         char is_probably_safari;
1424b077aed3SPierre Pronchery 
1425b077aed3SPierre Pronchery         /*
1426b077aed3SPierre Pronchery          * Track whether we did a key exchange this handshake or not, so
1427b077aed3SPierre Pronchery          * SSL_get_negotiated_group() knows whether to fall back to the
1428b077aed3SPierre Pronchery          * value in the SSL_SESSION.
1429b077aed3SPierre Pronchery          */
1430b077aed3SPierre Pronchery         char did_kex;
1431b077aed3SPierre Pronchery         /* For clients: peer temporary key */
1432b077aed3SPierre Pronchery         /* The group_id for the key exchange key */
1433b077aed3SPierre Pronchery         uint16_t group_id;
1434b077aed3SPierre Pronchery         EVP_PKEY *peer_tmp;
1435b077aed3SPierre Pronchery 
1436b077aed3SPierre Pronchery     } s3;
1437b077aed3SPierre Pronchery 
143817f01e99SJung-uk Kim     struct dtls1_state_st *d1;  /* DTLSv1 variables */
143917f01e99SJung-uk Kim     /* callback that allows applications to peek at protocol messages */
144017f01e99SJung-uk Kim     void (*msg_callback) (int write_p, int version, int content_type,
144117f01e99SJung-uk Kim                           const void *buf, size_t len, SSL *ssl, void *arg);
144217f01e99SJung-uk Kim     void *msg_callback_arg;
144317f01e99SJung-uk Kim     int hit;                    /* reusing a previous session */
144417f01e99SJung-uk Kim     X509_VERIFY_PARAM *param;
144517f01e99SJung-uk Kim     /* Per connection DANE state */
144617f01e99SJung-uk Kim     SSL_DANE dane;
144717f01e99SJung-uk Kim     /* crypto */
144817f01e99SJung-uk Kim     STACK_OF(SSL_CIPHER) *peer_ciphers;
144917f01e99SJung-uk Kim     STACK_OF(SSL_CIPHER) *cipher_list;
145017f01e99SJung-uk Kim     STACK_OF(SSL_CIPHER) *cipher_list_by_id;
145117f01e99SJung-uk Kim     /* TLSv1.3 specific ciphersuites */
145217f01e99SJung-uk Kim     STACK_OF(SSL_CIPHER) *tls13_ciphersuites;
145317f01e99SJung-uk Kim     /*
145417f01e99SJung-uk Kim      * These are the ones being used, the ones in SSL_SESSION are the ones to
145517f01e99SJung-uk Kim      * be 'copied' into these ones
145617f01e99SJung-uk Kim      */
145717f01e99SJung-uk Kim     uint32_t mac_flags;
145817f01e99SJung-uk Kim     /*
145917f01e99SJung-uk Kim      * The TLS1.3 secrets.
146017f01e99SJung-uk Kim      */
146117f01e99SJung-uk Kim     unsigned char early_secret[EVP_MAX_MD_SIZE];
146217f01e99SJung-uk Kim     unsigned char handshake_secret[EVP_MAX_MD_SIZE];
146317f01e99SJung-uk Kim     unsigned char master_secret[EVP_MAX_MD_SIZE];
146417f01e99SJung-uk Kim     unsigned char resumption_master_secret[EVP_MAX_MD_SIZE];
146517f01e99SJung-uk Kim     unsigned char client_finished_secret[EVP_MAX_MD_SIZE];
146617f01e99SJung-uk Kim     unsigned char server_finished_secret[EVP_MAX_MD_SIZE];
146717f01e99SJung-uk Kim     unsigned char server_finished_hash[EVP_MAX_MD_SIZE];
146817f01e99SJung-uk Kim     unsigned char handshake_traffic_hash[EVP_MAX_MD_SIZE];
146917f01e99SJung-uk Kim     unsigned char client_app_traffic_secret[EVP_MAX_MD_SIZE];
147017f01e99SJung-uk Kim     unsigned char server_app_traffic_secret[EVP_MAX_MD_SIZE];
147117f01e99SJung-uk Kim     unsigned char exporter_master_secret[EVP_MAX_MD_SIZE];
147217f01e99SJung-uk Kim     unsigned char early_exporter_master_secret[EVP_MAX_MD_SIZE];
147317f01e99SJung-uk Kim     EVP_CIPHER_CTX *enc_read_ctx; /* cryptographic state */
147417f01e99SJung-uk Kim     unsigned char read_iv[EVP_MAX_IV_LENGTH]; /* TLSv1.3 static read IV */
147517f01e99SJung-uk Kim     EVP_MD_CTX *read_hash;      /* used for mac generation */
147617f01e99SJung-uk Kim     COMP_CTX *compress;         /* compression */
147717f01e99SJung-uk Kim     COMP_CTX *expand;           /* uncompress */
147817f01e99SJung-uk Kim     EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */
147917f01e99SJung-uk Kim     unsigned char write_iv[EVP_MAX_IV_LENGTH]; /* TLSv1.3 static write IV */
148017f01e99SJung-uk Kim     EVP_MD_CTX *write_hash;     /* used for mac generation */
148117f01e99SJung-uk Kim     /* session info */
148217f01e99SJung-uk Kim     /* client cert? */
148317f01e99SJung-uk Kim     /* This is used to hold the server certificate used */
148417f01e99SJung-uk Kim     struct cert_st /* CERT */ *cert;
148517f01e99SJung-uk Kim 
148617f01e99SJung-uk Kim     /*
148717f01e99SJung-uk Kim      * The hash of all messages prior to the CertificateVerify, and the length
148817f01e99SJung-uk Kim      * of that hash.
148917f01e99SJung-uk Kim      */
149017f01e99SJung-uk Kim     unsigned char cert_verify_hash[EVP_MAX_MD_SIZE];
149117f01e99SJung-uk Kim     size_t cert_verify_hash_len;
149217f01e99SJung-uk Kim 
149317f01e99SJung-uk Kim     /* Flag to indicate whether we should send a HelloRetryRequest or not */
149417f01e99SJung-uk Kim     enum {SSL_HRR_NONE = 0, SSL_HRR_PENDING, SSL_HRR_COMPLETE}
149517f01e99SJung-uk Kim         hello_retry_request;
149617f01e99SJung-uk Kim 
149717f01e99SJung-uk Kim     /*
149817f01e99SJung-uk Kim      * the session_id_context is used to ensure sessions are only reused in
149917f01e99SJung-uk Kim      * the appropriate context
150017f01e99SJung-uk Kim      */
150117f01e99SJung-uk Kim     size_t sid_ctx_length;
150217f01e99SJung-uk Kim     unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
150317f01e99SJung-uk Kim     /* This can also be in the session once a session is established */
150417f01e99SJung-uk Kim     SSL_SESSION *session;
150517f01e99SJung-uk Kim     /* TLSv1.3 PSK session */
150617f01e99SJung-uk Kim     SSL_SESSION *psksession;
150717f01e99SJung-uk Kim     unsigned char *psksession_id;
150817f01e99SJung-uk Kim     size_t psksession_id_len;
150917f01e99SJung-uk Kim     /* Default generate session ID callback. */
151017f01e99SJung-uk Kim     GEN_SESSION_CB generate_session_id;
151117f01e99SJung-uk Kim     /*
151217f01e99SJung-uk Kim      * The temporary TLSv1.3 session id. This isn't really a session id at all
151317f01e99SJung-uk Kim      * but is a random value sent in the legacy session id field.
151417f01e99SJung-uk Kim      */
151517f01e99SJung-uk Kim     unsigned char tmp_session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
151617f01e99SJung-uk Kim     size_t tmp_session_id_len;
151717f01e99SJung-uk Kim     /* Used in SSL3 */
151817f01e99SJung-uk Kim     /*
151917f01e99SJung-uk Kim      * 0 don't care about verify failure.
152017f01e99SJung-uk Kim      * 1 fail if verify fails
152117f01e99SJung-uk Kim      */
152217f01e99SJung-uk Kim     uint32_t verify_mode;
152317f01e99SJung-uk Kim     /* fail if callback returns 0 */
152417f01e99SJung-uk Kim     int (*verify_callback) (int ok, X509_STORE_CTX *ctx);
152517f01e99SJung-uk Kim     /* optional informational callback */
152617f01e99SJung-uk Kim     void (*info_callback) (const SSL *ssl, int type, int val);
152717f01e99SJung-uk Kim     /* error bytes to be written */
152817f01e99SJung-uk Kim     int error;
152917f01e99SJung-uk Kim     /* actual code */
153017f01e99SJung-uk Kim     int error_code;
153117f01e99SJung-uk Kim # ifndef OPENSSL_NO_PSK
153217f01e99SJung-uk Kim     SSL_psk_client_cb_func psk_client_callback;
153317f01e99SJung-uk Kim     SSL_psk_server_cb_func psk_server_callback;
153417f01e99SJung-uk Kim # endif
153517f01e99SJung-uk Kim     SSL_psk_find_session_cb_func psk_find_session_cb;
153617f01e99SJung-uk Kim     SSL_psk_use_session_cb_func psk_use_session_cb;
153717f01e99SJung-uk Kim 
153817f01e99SJung-uk Kim     SSL_CTX *ctx;
153917f01e99SJung-uk Kim     /* Verified chain of peer */
154017f01e99SJung-uk Kim     STACK_OF(X509) *verified_chain;
154117f01e99SJung-uk Kim     long verify_result;
154217f01e99SJung-uk Kim     /* extra application data */
154317f01e99SJung-uk Kim     CRYPTO_EX_DATA ex_data;
154417f01e99SJung-uk Kim     /*
154517f01e99SJung-uk Kim      * What we put in certificate_authorities extension for TLS 1.3
154617f01e99SJung-uk Kim      * (ClientHello and CertificateRequest) or just client cert requests for
154717f01e99SJung-uk Kim      * earlier versions. If client_ca_names is populated then it is only used
154817f01e99SJung-uk Kim      * for client cert requests, and in preference to ca_names.
154917f01e99SJung-uk Kim      */
155017f01e99SJung-uk Kim     STACK_OF(X509_NAME) *ca_names;
155117f01e99SJung-uk Kim     STACK_OF(X509_NAME) *client_ca_names;
155217f01e99SJung-uk Kim     CRYPTO_REF_COUNT references;
155317f01e99SJung-uk Kim     /* protocol behaviour */
1554b077aed3SPierre Pronchery     uint64_t options;
155517f01e99SJung-uk Kim     /* API behaviour */
155617f01e99SJung-uk Kim     uint32_t mode;
155717f01e99SJung-uk Kim     int min_proto_version;
155817f01e99SJung-uk Kim     int max_proto_version;
155917f01e99SJung-uk Kim     size_t max_cert_list;
156017f01e99SJung-uk Kim     int first_packet;
156117f01e99SJung-uk Kim     /*
156217f01e99SJung-uk Kim      * What was passed in ClientHello.legacy_version. Used for RSA pre-master
156317f01e99SJung-uk Kim      * secret and SSLv3/TLS (<=1.2) rollback check
156417f01e99SJung-uk Kim      */
156517f01e99SJung-uk Kim     int client_version;
156617f01e99SJung-uk Kim     /*
156717f01e99SJung-uk Kim      * If we're using more than one pipeline how should we divide the data
156817f01e99SJung-uk Kim      * up between the pipes?
156917f01e99SJung-uk Kim      */
157017f01e99SJung-uk Kim     size_t split_send_fragment;
157117f01e99SJung-uk Kim     /*
157217f01e99SJung-uk Kim      * Maximum amount of data to send in one fragment. actual record size can
157317f01e99SJung-uk Kim      * be more than this due to padding and MAC overheads.
157417f01e99SJung-uk Kim      */
157517f01e99SJung-uk Kim     size_t max_send_fragment;
157617f01e99SJung-uk Kim     /* Up to how many pipelines should we use? If 0 then 1 is assumed */
157717f01e99SJung-uk Kim     size_t max_pipelines;
157817f01e99SJung-uk Kim 
157917f01e99SJung-uk Kim     struct {
158017f01e99SJung-uk Kim         /* Built-in extension flags */
158117f01e99SJung-uk Kim         uint8_t extflags[TLSEXT_IDX_num_builtins];
158217f01e99SJung-uk Kim         /* TLS extension debug callback */
158317f01e99SJung-uk Kim         void (*debug_cb)(SSL *s, int client_server, int type,
158417f01e99SJung-uk Kim                          const unsigned char *data, int len, void *arg);
158517f01e99SJung-uk Kim         void *debug_arg;
158617f01e99SJung-uk Kim         char *hostname;
158717f01e99SJung-uk Kim         /* certificate status request info */
158817f01e99SJung-uk Kim         /* Status type or -1 if no status type */
158917f01e99SJung-uk Kim         int status_type;
159017f01e99SJung-uk Kim         /* Raw extension data, if seen */
159117f01e99SJung-uk Kim         unsigned char *scts;
159217f01e99SJung-uk Kim         /* Length of raw extension data, if seen */
159317f01e99SJung-uk Kim         uint16_t scts_len;
159417f01e99SJung-uk Kim         /* Expect OCSP CertificateStatus message */
159517f01e99SJung-uk Kim         int status_expected;
159617f01e99SJung-uk Kim 
159717f01e99SJung-uk Kim         struct {
159817f01e99SJung-uk Kim             /* OCSP status request only */
159917f01e99SJung-uk Kim             STACK_OF(OCSP_RESPID) *ids;
160017f01e99SJung-uk Kim             X509_EXTENSIONS *exts;
160117f01e99SJung-uk Kim             /* OCSP response received or to be sent */
160217f01e99SJung-uk Kim             unsigned char *resp;
160317f01e99SJung-uk Kim             size_t resp_len;
160417f01e99SJung-uk Kim         } ocsp;
160517f01e99SJung-uk Kim 
160617f01e99SJung-uk Kim         /* RFC4507 session ticket expected to be received or sent */
160717f01e99SJung-uk Kim         int ticket_expected;
1608b077aed3SPierre Pronchery         /* TLS 1.3 tickets requested by the application. */
1609b077aed3SPierre Pronchery         int extra_tickets_expected;
161017f01e99SJung-uk Kim         size_t ecpointformats_len;
161117f01e99SJung-uk Kim         /* our list */
161217f01e99SJung-uk Kim         unsigned char *ecpointformats;
161317f01e99SJung-uk Kim 
161417f01e99SJung-uk Kim         size_t peer_ecpointformats_len;
161517f01e99SJung-uk Kim         /* peer's list */
161617f01e99SJung-uk Kim         unsigned char *peer_ecpointformats;
161717f01e99SJung-uk Kim         size_t supportedgroups_len;
161817f01e99SJung-uk Kim         /* our list */
161917f01e99SJung-uk Kim         uint16_t *supportedgroups;
162017f01e99SJung-uk Kim 
162117f01e99SJung-uk Kim         size_t peer_supportedgroups_len;
162217f01e99SJung-uk Kim          /* peer's list */
162317f01e99SJung-uk Kim         uint16_t *peer_supportedgroups;
162417f01e99SJung-uk Kim 
162517f01e99SJung-uk Kim         /* TLS Session Ticket extension override */
162617f01e99SJung-uk Kim         TLS_SESSION_TICKET_EXT *session_ticket;
162717f01e99SJung-uk Kim         /* TLS Session Ticket extension callback */
162817f01e99SJung-uk Kim         tls_session_ticket_ext_cb_fn session_ticket_cb;
162917f01e99SJung-uk Kim         void *session_ticket_cb_arg;
163017f01e99SJung-uk Kim         /* TLS pre-shared secret session resumption */
163117f01e99SJung-uk Kim         tls_session_secret_cb_fn session_secret_cb;
163217f01e99SJung-uk Kim         void *session_secret_cb_arg;
163317f01e99SJung-uk Kim         /*
163417f01e99SJung-uk Kim          * For a client, this contains the list of supported protocols in wire
163517f01e99SJung-uk Kim          * format.
163617f01e99SJung-uk Kim          */
163717f01e99SJung-uk Kim         unsigned char *alpn;
163817f01e99SJung-uk Kim         size_t alpn_len;
163917f01e99SJung-uk Kim         /*
164017f01e99SJung-uk Kim          * Next protocol negotiation. For the client, this is the protocol that
164117f01e99SJung-uk Kim          * we sent in NextProtocol and is set when handling ServerHello
164217f01e99SJung-uk Kim          * extensions. For a server, this is the client's selected_protocol from
164317f01e99SJung-uk Kim          * NextProtocol and is set when handling the NextProtocol message, before
164417f01e99SJung-uk Kim          * the Finished message.
164517f01e99SJung-uk Kim          */
164617f01e99SJung-uk Kim         unsigned char *npn;
164717f01e99SJung-uk Kim         size_t npn_len;
164817f01e99SJung-uk Kim 
164917f01e99SJung-uk Kim         /* The available PSK key exchange modes */
165017f01e99SJung-uk Kim         int psk_kex_mode;
165117f01e99SJung-uk Kim 
165217f01e99SJung-uk Kim         /* Set to one if we have negotiated ETM */
165317f01e99SJung-uk Kim         int use_etm;
165417f01e99SJung-uk Kim 
165517f01e99SJung-uk Kim         /* Are we expecting to receive early data? */
165617f01e99SJung-uk Kim         int early_data;
165717f01e99SJung-uk Kim         /* Is the session suitable for early data? */
165817f01e99SJung-uk Kim         int early_data_ok;
165917f01e99SJung-uk Kim 
166017f01e99SJung-uk Kim         /* May be sent by a server in HRR. Must be echoed back in ClientHello */
166117f01e99SJung-uk Kim         unsigned char *tls13_cookie;
166217f01e99SJung-uk Kim         size_t tls13_cookie_len;
166317f01e99SJung-uk Kim         /* Have we received a cookie from the client? */
166417f01e99SJung-uk Kim         int cookieok;
166517f01e99SJung-uk Kim 
166617f01e99SJung-uk Kim         /*
166717f01e99SJung-uk Kim          * Maximum Fragment Length as per RFC 4366.
166817f01e99SJung-uk Kim          * If this member contains one of the allowed values (1-4)
166917f01e99SJung-uk Kim          * then we should include Maximum Fragment Length Negotiation
167017f01e99SJung-uk Kim          * extension in Client Hello.
167117f01e99SJung-uk Kim          * Please note that value of this member does not have direct
167217f01e99SJung-uk Kim          * effect. The actual (binding) value is stored in SSL_SESSION,
167317f01e99SJung-uk Kim          * as this extension is optional on server side.
167417f01e99SJung-uk Kim          */
167517f01e99SJung-uk Kim         uint8_t max_fragment_len_mode;
167617f01e99SJung-uk Kim 
167717f01e99SJung-uk Kim         /*
167817f01e99SJung-uk Kim          * On the client side the number of ticket identities we sent in the
167917f01e99SJung-uk Kim          * ClientHello. On the server side the identity of the ticket we
168017f01e99SJung-uk Kim          * selected.
168117f01e99SJung-uk Kim          */
168217f01e99SJung-uk Kim         int tick_identity;
168317f01e99SJung-uk Kim     } ext;
168417f01e99SJung-uk Kim 
168517f01e99SJung-uk Kim     /*
168617f01e99SJung-uk Kim      * Parsed form of the ClientHello, kept around across client_hello_cb
168717f01e99SJung-uk Kim      * calls.
168817f01e99SJung-uk Kim      */
168917f01e99SJung-uk Kim     CLIENTHELLO_MSG *clienthello;
169017f01e99SJung-uk Kim 
169117f01e99SJung-uk Kim     /*-
169217f01e99SJung-uk Kim      * no further mod of servername
169317f01e99SJung-uk Kim      * 0 : call the servername extension callback.
169417f01e99SJung-uk Kim      * 1 : prepare 2, allow last ack just after in server callback.
169517f01e99SJung-uk Kim      * 2 : don't call servername callback, no ack in server hello
169617f01e99SJung-uk Kim      */
169717f01e99SJung-uk Kim     int servername_done;
169817f01e99SJung-uk Kim # ifndef OPENSSL_NO_CT
169917f01e99SJung-uk Kim     /*
170017f01e99SJung-uk Kim      * Validates that the SCTs (Signed Certificate Timestamps) are sufficient.
170117f01e99SJung-uk Kim      * If they are not, the connection should be aborted.
170217f01e99SJung-uk Kim      */
170317f01e99SJung-uk Kim     ssl_ct_validation_cb ct_validation_callback;
170417f01e99SJung-uk Kim     /* User-supplied argument that is passed to the ct_validation_callback */
170517f01e99SJung-uk Kim     void *ct_validation_callback_arg;
170617f01e99SJung-uk Kim     /*
170717f01e99SJung-uk Kim      * Consolidated stack of SCTs from all sources.
170817f01e99SJung-uk Kim      * Lazily populated by CT_get_peer_scts(SSL*)
170917f01e99SJung-uk Kim      */
171017f01e99SJung-uk Kim     STACK_OF(SCT) *scts;
171117f01e99SJung-uk Kim     /* Have we attempted to find/parse SCTs yet? */
171217f01e99SJung-uk Kim     int scts_parsed;
171317f01e99SJung-uk Kim # endif
171417f01e99SJung-uk Kim     SSL_CTX *session_ctx;       /* initial ctx, used to store sessions */
171517f01e99SJung-uk Kim # ifndef OPENSSL_NO_SRTP
171617f01e99SJung-uk Kim     /* What we'll do */
171717f01e99SJung-uk Kim     STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles;
171817f01e99SJung-uk Kim     /* What's been chosen */
171917f01e99SJung-uk Kim     SRTP_PROTECTION_PROFILE *srtp_profile;
172017f01e99SJung-uk Kim # endif
172117f01e99SJung-uk Kim     /*-
172217f01e99SJung-uk Kim      * 1 if we are renegotiating.
172317f01e99SJung-uk Kim      * 2 if we are a server and are inside a handshake
172417f01e99SJung-uk Kim      * (i.e. not just sending a HelloRequest)
172517f01e99SJung-uk Kim      */
172617f01e99SJung-uk Kim     int renegotiate;
172717f01e99SJung-uk Kim     /* If sending a KeyUpdate is pending */
172817f01e99SJung-uk Kim     int key_update;
172917f01e99SJung-uk Kim     /* Post-handshake authentication state */
173017f01e99SJung-uk Kim     SSL_PHA_STATE post_handshake_auth;
173117f01e99SJung-uk Kim     int pha_enabled;
173217f01e99SJung-uk Kim     uint8_t* pha_context;
173317f01e99SJung-uk Kim     size_t pha_context_len;
173417f01e99SJung-uk Kim     int certreqs_sent;
173517f01e99SJung-uk Kim     EVP_MD_CTX *pha_dgst; /* this is just the digest through ClientFinished */
173617f01e99SJung-uk Kim 
173717f01e99SJung-uk Kim # ifndef OPENSSL_NO_SRP
173817f01e99SJung-uk Kim     /* ctx for SRP authentication */
173917f01e99SJung-uk Kim     SRP_CTX srp_ctx;
174017f01e99SJung-uk Kim # endif
174117f01e99SJung-uk Kim     /*
174217f01e99SJung-uk Kim      * Callback for disabling session caching and ticket support on a session
174317f01e99SJung-uk Kim      * basis, depending on the chosen cipher.
174417f01e99SJung-uk Kim      */
174517f01e99SJung-uk Kim     int (*not_resumable_session_cb) (SSL *ssl, int is_forward_secure);
174617f01e99SJung-uk Kim     RECORD_LAYER rlayer;
174717f01e99SJung-uk Kim     /* Default password callback. */
174817f01e99SJung-uk Kim     pem_password_cb *default_passwd_callback;
174917f01e99SJung-uk Kim     /* Default password callback user data. */
175017f01e99SJung-uk Kim     void *default_passwd_callback_userdata;
175117f01e99SJung-uk Kim     /* Async Job info */
175217f01e99SJung-uk Kim     ASYNC_JOB *job;
175317f01e99SJung-uk Kim     ASYNC_WAIT_CTX *waitctx;
175417f01e99SJung-uk Kim     size_t asyncrw;
175517f01e99SJung-uk Kim 
175617f01e99SJung-uk Kim     /*
175717f01e99SJung-uk Kim      * The maximum number of bytes advertised in session tickets that can be
175817f01e99SJung-uk Kim      * sent as early data.
175917f01e99SJung-uk Kim      */
176017f01e99SJung-uk Kim     uint32_t max_early_data;
176117f01e99SJung-uk Kim     /*
176217f01e99SJung-uk Kim      * The maximum number of bytes of early data that a server will tolerate
176317f01e99SJung-uk Kim      * (which should be at least as much as max_early_data).
176417f01e99SJung-uk Kim      */
176517f01e99SJung-uk Kim     uint32_t recv_max_early_data;
176617f01e99SJung-uk Kim 
176717f01e99SJung-uk Kim     /*
176817f01e99SJung-uk Kim      * The number of bytes of early data received so far. If we accepted early
176917f01e99SJung-uk Kim      * data then this is a count of the plaintext bytes. If we rejected it then
177017f01e99SJung-uk Kim      * this is a count of the ciphertext bytes.
177117f01e99SJung-uk Kim      */
177217f01e99SJung-uk Kim     uint32_t early_data_count;
177317f01e99SJung-uk Kim 
177417f01e99SJung-uk Kim     /* TLS1.3 padding callback */
177517f01e99SJung-uk Kim     size_t (*record_padding_cb)(SSL *s, int type, size_t len, void *arg);
177617f01e99SJung-uk Kim     void *record_padding_arg;
177717f01e99SJung-uk Kim     size_t block_padding;
177817f01e99SJung-uk Kim 
177917f01e99SJung-uk Kim     CRYPTO_RWLOCK *lock;
178017f01e99SJung-uk Kim 
178117f01e99SJung-uk Kim     /* The number of TLS1.3 tickets to automatically send */
178217f01e99SJung-uk Kim     size_t num_tickets;
178317f01e99SJung-uk Kim     /* The number of TLS1.3 tickets actually sent so far */
178417f01e99SJung-uk Kim     size_t sent_tickets;
178517f01e99SJung-uk Kim     /* The next nonce value to use when we send a ticket on this connection */
178617f01e99SJung-uk Kim     uint64_t next_ticket_nonce;
178717f01e99SJung-uk Kim 
178817f01e99SJung-uk Kim     /* Callback to determine if early_data is acceptable or not */
178917f01e99SJung-uk Kim     SSL_allow_early_data_cb_fn allow_early_data_cb;
179017f01e99SJung-uk Kim     void *allow_early_data_cb_data;
179117f01e99SJung-uk Kim 
1792b077aed3SPierre Pronchery     /* Callback for SSL async handling */
1793b077aed3SPierre Pronchery     SSL_async_callback_fn async_cb;
1794b077aed3SPierre Pronchery     void *async_cb_arg;
1795b077aed3SPierre Pronchery 
179617f01e99SJung-uk Kim     /*
179717f01e99SJung-uk Kim      * Signature algorithms shared by client and server: cached because these
179817f01e99SJung-uk Kim      * are used most often.
179917f01e99SJung-uk Kim      */
180017f01e99SJung-uk Kim     const struct sigalg_lookup_st **shared_sigalgs;
180117f01e99SJung-uk Kim     size_t shared_sigalgslen;
180217f01e99SJung-uk Kim };
180317f01e99SJung-uk Kim 
180417f01e99SJung-uk Kim /*
180517f01e99SJung-uk Kim  * Structure containing table entry of values associated with the signature
180617f01e99SJung-uk Kim  * algorithms (signature scheme) extension
180717f01e99SJung-uk Kim */
180817f01e99SJung-uk Kim typedef struct sigalg_lookup_st {
180917f01e99SJung-uk Kim     /* TLS 1.3 signature scheme name */
181017f01e99SJung-uk Kim     const char *name;
181117f01e99SJung-uk Kim     /* Raw value used in extension */
181217f01e99SJung-uk Kim     uint16_t sigalg;
181317f01e99SJung-uk Kim     /* NID of hash algorithm or NID_undef if no hash */
181417f01e99SJung-uk Kim     int hash;
181517f01e99SJung-uk Kim     /* Index of hash algorithm or -1 if no hash algorithm */
181617f01e99SJung-uk Kim     int hash_idx;
181717f01e99SJung-uk Kim     /* NID of signature algorithm */
181817f01e99SJung-uk Kim     int sig;
181917f01e99SJung-uk Kim     /* Index of signature algorithm */
182017f01e99SJung-uk Kim     int sig_idx;
182117f01e99SJung-uk Kim     /* Combined hash and signature NID, if any */
182217f01e99SJung-uk Kim     int sigandhash;
182317f01e99SJung-uk Kim     /* Required public key curve (ECDSA only) */
182417f01e99SJung-uk Kim     int curve;
1825b077aed3SPierre Pronchery     /* Whether this signature algorithm is actually available for use */
1826b077aed3SPierre Pronchery     int enabled;
182717f01e99SJung-uk Kim } SIGALG_LOOKUP;
182817f01e99SJung-uk Kim 
182917f01e99SJung-uk Kim /*
183017f01e99SJung-uk Kim  * Structure containing table entry of certificate info corresponding to
183117f01e99SJung-uk Kim  * CERT_PKEY entries
183217f01e99SJung-uk Kim  */
183317f01e99SJung-uk Kim typedef struct {
183417f01e99SJung-uk Kim     int nid; /* NID of public key algorithm */
183517f01e99SJung-uk Kim     uint32_t amask; /* authmask corresponding to key type */
183617f01e99SJung-uk Kim } SSL_CERT_LOOKUP;
183717f01e99SJung-uk Kim 
183817f01e99SJung-uk Kim /* DTLS structures */
183917f01e99SJung-uk Kim 
184017f01e99SJung-uk Kim # ifndef OPENSSL_NO_SCTP
184117f01e99SJung-uk Kim #  define DTLS1_SCTP_AUTH_LABEL   "EXPORTER_DTLS_OVER_SCTP"
184217f01e99SJung-uk Kim # endif
184317f01e99SJung-uk Kim 
184417f01e99SJung-uk Kim /* Max MTU overhead we know about so far is 40 for IPv6 + 8 for UDP */
184517f01e99SJung-uk Kim # define DTLS1_MAX_MTU_OVERHEAD                   48
184617f01e99SJung-uk Kim 
184717f01e99SJung-uk Kim /*
184817f01e99SJung-uk Kim  * Flag used in message reuse to indicate the buffer contains the record
184917f01e99SJung-uk Kim  * header as well as the handshake message header.
185017f01e99SJung-uk Kim  */
185117f01e99SJung-uk Kim # define DTLS1_SKIP_RECORD_HEADER                 2
185217f01e99SJung-uk Kim 
185317f01e99SJung-uk Kim struct dtls1_retransmit_state {
185417f01e99SJung-uk Kim     EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */
185517f01e99SJung-uk Kim     EVP_MD_CTX *write_hash;     /* used for mac generation */
185617f01e99SJung-uk Kim     COMP_CTX *compress;         /* compression */
185717f01e99SJung-uk Kim     SSL_SESSION *session;
185817f01e99SJung-uk Kim     unsigned short epoch;
185917f01e99SJung-uk Kim };
186017f01e99SJung-uk Kim 
186117f01e99SJung-uk Kim struct hm_header_st {
186217f01e99SJung-uk Kim     unsigned char type;
186317f01e99SJung-uk Kim     size_t msg_len;
186417f01e99SJung-uk Kim     unsigned short seq;
186517f01e99SJung-uk Kim     size_t frag_off;
186617f01e99SJung-uk Kim     size_t frag_len;
186717f01e99SJung-uk Kim     unsigned int is_ccs;
186817f01e99SJung-uk Kim     struct dtls1_retransmit_state saved_retransmit_state;
186917f01e99SJung-uk Kim };
187017f01e99SJung-uk Kim 
187117f01e99SJung-uk Kim typedef struct hm_fragment_st {
187217f01e99SJung-uk Kim     struct hm_header_st msg_header;
187317f01e99SJung-uk Kim     unsigned char *fragment;
187417f01e99SJung-uk Kim     unsigned char *reassembly;
187517f01e99SJung-uk Kim } hm_fragment;
187617f01e99SJung-uk Kim 
187717f01e99SJung-uk Kim typedef struct pqueue_st pqueue;
187817f01e99SJung-uk Kim typedef struct pitem_st pitem;
187917f01e99SJung-uk Kim 
188017f01e99SJung-uk Kim struct pitem_st {
188117f01e99SJung-uk Kim     unsigned char priority[8];  /* 64-bit value in big-endian encoding */
188217f01e99SJung-uk Kim     void *data;
188317f01e99SJung-uk Kim     pitem *next;
188417f01e99SJung-uk Kim };
188517f01e99SJung-uk Kim 
188617f01e99SJung-uk Kim typedef struct pitem_st *piterator;
188717f01e99SJung-uk Kim 
188817f01e99SJung-uk Kim pitem *pitem_new(unsigned char *prio64be, void *data);
188917f01e99SJung-uk Kim void pitem_free(pitem *item);
189017f01e99SJung-uk Kim pqueue *pqueue_new(void);
189117f01e99SJung-uk Kim void pqueue_free(pqueue *pq);
189217f01e99SJung-uk Kim pitem *pqueue_insert(pqueue *pq, pitem *item);
189317f01e99SJung-uk Kim pitem *pqueue_peek(pqueue *pq);
189417f01e99SJung-uk Kim pitem *pqueue_pop(pqueue *pq);
189517f01e99SJung-uk Kim pitem *pqueue_find(pqueue *pq, unsigned char *prio64be);
189617f01e99SJung-uk Kim pitem *pqueue_iterator(pqueue *pq);
189717f01e99SJung-uk Kim pitem *pqueue_next(piterator *iter);
189817f01e99SJung-uk Kim size_t pqueue_size(pqueue *pq);
189917f01e99SJung-uk Kim 
190017f01e99SJung-uk Kim typedef struct dtls1_state_st {
190117f01e99SJung-uk Kim     unsigned char cookie[DTLS1_COOKIE_LENGTH];
190217f01e99SJung-uk Kim     size_t cookie_len;
190317f01e99SJung-uk Kim     unsigned int cookie_verified;
190417f01e99SJung-uk Kim     /* handshake message numbers */
190517f01e99SJung-uk Kim     unsigned short handshake_write_seq;
190617f01e99SJung-uk Kim     unsigned short next_handshake_write_seq;
190717f01e99SJung-uk Kim     unsigned short handshake_read_seq;
190817f01e99SJung-uk Kim     /* Buffered handshake messages */
190917f01e99SJung-uk Kim     pqueue *buffered_messages;
191017f01e99SJung-uk Kim     /* Buffered (sent) handshake records */
191117f01e99SJung-uk Kim     pqueue *sent_messages;
191217f01e99SJung-uk Kim     size_t link_mtu;      /* max on-the-wire DTLS packet size */
191317f01e99SJung-uk Kim     size_t mtu;           /* max DTLS packet size */
191417f01e99SJung-uk Kim     struct hm_header_st w_msg_hdr;
191517f01e99SJung-uk Kim     struct hm_header_st r_msg_hdr;
1916b077aed3SPierre Pronchery     /* Number of alerts received so far */
1917b077aed3SPierre Pronchery     unsigned int timeout_num_alerts;
191817f01e99SJung-uk Kim     /*
191917f01e99SJung-uk Kim      * Indicates when the last handshake msg sent will timeout
192017f01e99SJung-uk Kim      */
192117f01e99SJung-uk Kim     struct timeval next_timeout;
192217f01e99SJung-uk Kim     /* Timeout duration */
192317f01e99SJung-uk Kim     unsigned int timeout_duration_us;
192417f01e99SJung-uk Kim 
192517f01e99SJung-uk Kim     unsigned int retransmitting;
192617f01e99SJung-uk Kim # ifndef OPENSSL_NO_SCTP
192717f01e99SJung-uk Kim     int shutdown_received;
192817f01e99SJung-uk Kim # endif
192917f01e99SJung-uk Kim 
193017f01e99SJung-uk Kim     DTLS_timer_cb timer_cb;
193117f01e99SJung-uk Kim 
193217f01e99SJung-uk Kim } DTLS1_STATE;
193317f01e99SJung-uk Kim 
193417f01e99SJung-uk Kim /*
193517f01e99SJung-uk Kim  * From ECC-TLS draft, used in encoding the curve type in ECParameters
193617f01e99SJung-uk Kim  */
193717f01e99SJung-uk Kim #  define EXPLICIT_PRIME_CURVE_TYPE  1
193817f01e99SJung-uk Kim #  define EXPLICIT_CHAR2_CURVE_TYPE  2
193917f01e99SJung-uk Kim #  define NAMED_CURVE_TYPE           3
194017f01e99SJung-uk Kim 
194117f01e99SJung-uk Kim struct cert_pkey_st {
194217f01e99SJung-uk Kim     X509 *x509;
194317f01e99SJung-uk Kim     EVP_PKEY *privatekey;
194417f01e99SJung-uk Kim     /* Chain for this certificate */
194517f01e99SJung-uk Kim     STACK_OF(X509) *chain;
194617f01e99SJung-uk Kim     /*-
194717f01e99SJung-uk Kim      * serverinfo data for this certificate.  The data is in TLS Extension
194817f01e99SJung-uk Kim      * wire format, specifically it's a series of records like:
194917f01e99SJung-uk Kim      *   uint16_t extension_type; // (RFC 5246, 7.4.1.4, Extension)
195017f01e99SJung-uk Kim      *   uint16_t length;
195117f01e99SJung-uk Kim      *   uint8_t data[length];
195217f01e99SJung-uk Kim      */
195317f01e99SJung-uk Kim     unsigned char *serverinfo;
195417f01e99SJung-uk Kim     size_t serverinfo_length;
195517f01e99SJung-uk Kim };
195617f01e99SJung-uk Kim /* Retrieve Suite B flags */
195717f01e99SJung-uk Kim # define tls1_suiteb(s)  (s->cert->cert_flags & SSL_CERT_FLAG_SUITEB_128_LOS)
195817f01e99SJung-uk Kim /* Uses to check strict mode: suite B modes are always strict */
195917f01e99SJung-uk Kim # define SSL_CERT_FLAGS_CHECK_TLS_STRICT \
196017f01e99SJung-uk Kim         (SSL_CERT_FLAG_SUITEB_128_LOS|SSL_CERT_FLAG_TLS_STRICT)
196117f01e99SJung-uk Kim 
196217f01e99SJung-uk Kim typedef enum {
196317f01e99SJung-uk Kim     ENDPOINT_CLIENT = 0,
196417f01e99SJung-uk Kim     ENDPOINT_SERVER,
196517f01e99SJung-uk Kim     ENDPOINT_BOTH
196617f01e99SJung-uk Kim } ENDPOINT;
196717f01e99SJung-uk Kim 
196817f01e99SJung-uk Kim 
196917f01e99SJung-uk Kim typedef struct {
197017f01e99SJung-uk Kim     unsigned short ext_type;
197117f01e99SJung-uk Kim     ENDPOINT role;
197217f01e99SJung-uk Kim     /* The context which this extension applies to */
197317f01e99SJung-uk Kim     unsigned int context;
197417f01e99SJung-uk Kim     /*
197517f01e99SJung-uk Kim      * Per-connection flags relating to this extension type: not used if
197617f01e99SJung-uk Kim      * part of an SSL_CTX structure.
197717f01e99SJung-uk Kim      */
197817f01e99SJung-uk Kim     uint32_t ext_flags;
197917f01e99SJung-uk Kim     SSL_custom_ext_add_cb_ex add_cb;
198017f01e99SJung-uk Kim     SSL_custom_ext_free_cb_ex free_cb;
198117f01e99SJung-uk Kim     void *add_arg;
198217f01e99SJung-uk Kim     SSL_custom_ext_parse_cb_ex parse_cb;
198317f01e99SJung-uk Kim     void *parse_arg;
198417f01e99SJung-uk Kim } custom_ext_method;
198517f01e99SJung-uk Kim 
198617f01e99SJung-uk Kim /* ext_flags values */
198717f01e99SJung-uk Kim 
198817f01e99SJung-uk Kim /*
198917f01e99SJung-uk Kim  * Indicates an extension has been received. Used to check for unsolicited or
199017f01e99SJung-uk Kim  * duplicate extensions.
199117f01e99SJung-uk Kim  */
199217f01e99SJung-uk Kim # define SSL_EXT_FLAG_RECEIVED   0x1
199317f01e99SJung-uk Kim /*
199417f01e99SJung-uk Kim  * Indicates an extension has been sent: used to enable sending of
199517f01e99SJung-uk Kim  * corresponding ServerHello extension.
199617f01e99SJung-uk Kim  */
199717f01e99SJung-uk Kim # define SSL_EXT_FLAG_SENT       0x2
199817f01e99SJung-uk Kim 
199917f01e99SJung-uk Kim typedef struct {
200017f01e99SJung-uk Kim     custom_ext_method *meths;
200117f01e99SJung-uk Kim     size_t meths_count;
200217f01e99SJung-uk Kim } custom_ext_methods;
200317f01e99SJung-uk Kim 
200417f01e99SJung-uk Kim typedef struct cert_st {
200517f01e99SJung-uk Kim     /* Current active set */
200617f01e99SJung-uk Kim     /*
200717f01e99SJung-uk Kim      * ALWAYS points to an element of the pkeys array
200817f01e99SJung-uk Kim      * Probably it would make more sense to store
200917f01e99SJung-uk Kim      * an index, not a pointer.
201017f01e99SJung-uk Kim      */
201117f01e99SJung-uk Kim     CERT_PKEY *key;
2012b077aed3SPierre Pronchery 
201317f01e99SJung-uk Kim     EVP_PKEY *dh_tmp;
201417f01e99SJung-uk Kim     DH *(*dh_tmp_cb) (SSL *ssl, int is_export, int keysize);
201517f01e99SJung-uk Kim     int dh_tmp_auto;
201617f01e99SJung-uk Kim     /* Flags related to certificates */
201717f01e99SJung-uk Kim     uint32_t cert_flags;
201817f01e99SJung-uk Kim     CERT_PKEY pkeys[SSL_PKEY_NUM];
201917f01e99SJung-uk Kim     /* Custom certificate types sent in certificate request message. */
202017f01e99SJung-uk Kim     uint8_t *ctype;
202117f01e99SJung-uk Kim     size_t ctype_len;
202217f01e99SJung-uk Kim     /*
202317f01e99SJung-uk Kim      * supported signature algorithms. When set on a client this is sent in
202417f01e99SJung-uk Kim      * the client hello as the supported signature algorithms extension. For
202517f01e99SJung-uk Kim      * servers it represents the signature algorithms we are willing to use.
202617f01e99SJung-uk Kim      */
202717f01e99SJung-uk Kim     uint16_t *conf_sigalgs;
202817f01e99SJung-uk Kim     /* Size of above array */
202917f01e99SJung-uk Kim     size_t conf_sigalgslen;
203017f01e99SJung-uk Kim     /*
203117f01e99SJung-uk Kim      * Client authentication signature algorithms, if not set then uses
203217f01e99SJung-uk Kim      * conf_sigalgs. On servers these will be the signature algorithms sent
203317f01e99SJung-uk Kim      * to the client in a certificate request for TLS 1.2. On a client this
203417f01e99SJung-uk Kim      * represents the signature algorithms we are willing to use for client
203517f01e99SJung-uk Kim      * authentication.
203617f01e99SJung-uk Kim      */
203717f01e99SJung-uk Kim     uint16_t *client_sigalgs;
203817f01e99SJung-uk Kim     /* Size of above array */
203917f01e99SJung-uk Kim     size_t client_sigalgslen;
204017f01e99SJung-uk Kim     /*
204117f01e99SJung-uk Kim      * Certificate setup callback: if set is called whenever a certificate
204217f01e99SJung-uk Kim      * may be required (client or server). the callback can then examine any
204317f01e99SJung-uk Kim      * appropriate parameters and setup any certificates required. This
204417f01e99SJung-uk Kim      * allows advanced applications to select certificates on the fly: for
204517f01e99SJung-uk Kim      * example based on supported signature algorithms or curves.
204617f01e99SJung-uk Kim      */
204717f01e99SJung-uk Kim     int (*cert_cb) (SSL *ssl, void *arg);
204817f01e99SJung-uk Kim     void *cert_cb_arg;
204917f01e99SJung-uk Kim     /*
205017f01e99SJung-uk Kim      * Optional X509_STORE for chain building or certificate validation If
205117f01e99SJung-uk Kim      * NULL the parent SSL_CTX store is used instead.
205217f01e99SJung-uk Kim      */
205317f01e99SJung-uk Kim     X509_STORE *chain_store;
205417f01e99SJung-uk Kim     X509_STORE *verify_store;
205517f01e99SJung-uk Kim     /* Custom extensions */
205617f01e99SJung-uk Kim     custom_ext_methods custext;
205717f01e99SJung-uk Kim     /* Security callback */
205817f01e99SJung-uk Kim     int (*sec_cb) (const SSL *s, const SSL_CTX *ctx, int op, int bits, int nid,
205917f01e99SJung-uk Kim                    void *other, void *ex);
206017f01e99SJung-uk Kim     /* Security level */
206117f01e99SJung-uk Kim     int sec_level;
206217f01e99SJung-uk Kim     void *sec_ex;
206317f01e99SJung-uk Kim # ifndef OPENSSL_NO_PSK
206417f01e99SJung-uk Kim     /* If not NULL psk identity hint to use for servers */
206517f01e99SJung-uk Kim     char *psk_identity_hint;
206617f01e99SJung-uk Kim # endif
206717f01e99SJung-uk Kim     CRYPTO_REF_COUNT references;             /* >1 only if SSL_copy_session_id is used */
206817f01e99SJung-uk Kim     CRYPTO_RWLOCK *lock;
206917f01e99SJung-uk Kim } CERT;
207017f01e99SJung-uk Kim 
207117f01e99SJung-uk Kim # define FP_ICC  (int (*)(const void *,const void *))
207217f01e99SJung-uk Kim 
207317f01e99SJung-uk Kim /*
207417f01e99SJung-uk Kim  * This is for the SSLv3/TLSv1.0 differences in crypto/hash stuff It is a bit
207517f01e99SJung-uk Kim  * of a mess of functions, but hell, think of it as an opaque structure :-)
207617f01e99SJung-uk Kim  */
207717f01e99SJung-uk Kim typedef struct ssl3_enc_method {
2078b077aed3SPierre Pronchery     int (*enc) (SSL *, SSL3_RECORD *, size_t, int, SSL_MAC_BUF *, size_t);
207917f01e99SJung-uk Kim     int (*mac) (SSL *, SSL3_RECORD *, unsigned char *, int);
208017f01e99SJung-uk Kim     int (*setup_key_block) (SSL *);
208117f01e99SJung-uk Kim     int (*generate_master_secret) (SSL *, unsigned char *, unsigned char *,
208217f01e99SJung-uk Kim                                    size_t, size_t *);
208317f01e99SJung-uk Kim     int (*change_cipher_state) (SSL *, int);
208417f01e99SJung-uk Kim     size_t (*final_finish_mac) (SSL *, const char *, size_t, unsigned char *);
208517f01e99SJung-uk Kim     const char *client_finished_label;
208617f01e99SJung-uk Kim     size_t client_finished_label_len;
208717f01e99SJung-uk Kim     const char *server_finished_label;
208817f01e99SJung-uk Kim     size_t server_finished_label_len;
208917f01e99SJung-uk Kim     int (*alert_value) (int);
209017f01e99SJung-uk Kim     int (*export_keying_material) (SSL *, unsigned char *, size_t,
209117f01e99SJung-uk Kim                                    const char *, size_t,
209217f01e99SJung-uk Kim                                    const unsigned char *, size_t,
209317f01e99SJung-uk Kim                                    int use_context);
209417f01e99SJung-uk Kim     /* Various flags indicating protocol version requirements */
209517f01e99SJung-uk Kim     uint32_t enc_flags;
209617f01e99SJung-uk Kim     /* Set the handshake header */
209717f01e99SJung-uk Kim     int (*set_handshake_header) (SSL *s, WPACKET *pkt, int type);
209817f01e99SJung-uk Kim     /* Close construction of the handshake message */
209917f01e99SJung-uk Kim     int (*close_construct_packet) (SSL *s, WPACKET *pkt, int htype);
210017f01e99SJung-uk Kim     /* Write out handshake message */
210117f01e99SJung-uk Kim     int (*do_write) (SSL *s);
210217f01e99SJung-uk Kim } SSL3_ENC_METHOD;
210317f01e99SJung-uk Kim 
210417f01e99SJung-uk Kim # define ssl_set_handshake_header(s, pkt, htype) \
210517f01e99SJung-uk Kim         s->method->ssl3_enc->set_handshake_header((s), (pkt), (htype))
210617f01e99SJung-uk Kim # define ssl_close_construct_packet(s, pkt, htype) \
210717f01e99SJung-uk Kim         s->method->ssl3_enc->close_construct_packet((s), (pkt), (htype))
210817f01e99SJung-uk Kim # define ssl_do_write(s)  s->method->ssl3_enc->do_write(s)
210917f01e99SJung-uk Kim 
211017f01e99SJung-uk Kim /* Values for enc_flags */
211117f01e99SJung-uk Kim 
211217f01e99SJung-uk Kim /* Uses explicit IV for CBC mode */
211317f01e99SJung-uk Kim # define SSL_ENC_FLAG_EXPLICIT_IV        0x1
211417f01e99SJung-uk Kim /* Uses signature algorithms extension */
211517f01e99SJung-uk Kim # define SSL_ENC_FLAG_SIGALGS            0x2
211617f01e99SJung-uk Kim /* Uses SHA256 default PRF */
211717f01e99SJung-uk Kim # define SSL_ENC_FLAG_SHA256_PRF         0x4
211817f01e99SJung-uk Kim /* Is DTLS */
211917f01e99SJung-uk Kim # define SSL_ENC_FLAG_DTLS               0x8
212017f01e99SJung-uk Kim /*
212117f01e99SJung-uk Kim  * Allow TLS 1.2 ciphersuites: applies to DTLS 1.2 as well as TLS 1.2: may
212217f01e99SJung-uk Kim  * apply to others in future.
212317f01e99SJung-uk Kim  */
212417f01e99SJung-uk Kim # define SSL_ENC_FLAG_TLS1_2_CIPHERS     0x10
212517f01e99SJung-uk Kim 
212617f01e99SJung-uk Kim # ifndef OPENSSL_NO_COMP
212717f01e99SJung-uk Kim /* Used for holding the relevant compression methods loaded into SSL_CTX */
212817f01e99SJung-uk Kim typedef struct ssl3_comp_st {
212917f01e99SJung-uk Kim     int comp_id;                /* The identifier byte for this compression
213017f01e99SJung-uk Kim                                  * type */
213117f01e99SJung-uk Kim     char *name;                 /* Text name used for the compression type */
213217f01e99SJung-uk Kim     COMP_METHOD *method;        /* The method :-) */
213317f01e99SJung-uk Kim } SSL3_COMP;
213417f01e99SJung-uk Kim # endif
213517f01e99SJung-uk Kim 
213617f01e99SJung-uk Kim typedef enum downgrade_en {
213717f01e99SJung-uk Kim     DOWNGRADE_NONE,
213817f01e99SJung-uk Kim     DOWNGRADE_TO_1_2,
213917f01e99SJung-uk Kim     DOWNGRADE_TO_1_1
214017f01e99SJung-uk Kim } DOWNGRADE;
214117f01e99SJung-uk Kim 
214217f01e99SJung-uk Kim /*
214317f01e99SJung-uk Kim  * Dummy status type for the status_type extension. Indicates no status type
214417f01e99SJung-uk Kim  * set
214517f01e99SJung-uk Kim  */
214617f01e99SJung-uk Kim #define TLSEXT_STATUSTYPE_nothing  -1
214717f01e99SJung-uk Kim 
214817f01e99SJung-uk Kim /* Sigalgs values */
214917f01e99SJung-uk Kim #define TLSEXT_SIGALG_ecdsa_secp256r1_sha256                    0x0403
215017f01e99SJung-uk Kim #define TLSEXT_SIGALG_ecdsa_secp384r1_sha384                    0x0503
215117f01e99SJung-uk Kim #define TLSEXT_SIGALG_ecdsa_secp521r1_sha512                    0x0603
215217f01e99SJung-uk Kim #define TLSEXT_SIGALG_ecdsa_sha224                              0x0303
215317f01e99SJung-uk Kim #define TLSEXT_SIGALG_ecdsa_sha1                                0x0203
215417f01e99SJung-uk Kim #define TLSEXT_SIGALG_rsa_pss_rsae_sha256                       0x0804
215517f01e99SJung-uk Kim #define TLSEXT_SIGALG_rsa_pss_rsae_sha384                       0x0805
215617f01e99SJung-uk Kim #define TLSEXT_SIGALG_rsa_pss_rsae_sha512                       0x0806
215717f01e99SJung-uk Kim #define TLSEXT_SIGALG_rsa_pss_pss_sha256                        0x0809
215817f01e99SJung-uk Kim #define TLSEXT_SIGALG_rsa_pss_pss_sha384                        0x080a
215917f01e99SJung-uk Kim #define TLSEXT_SIGALG_rsa_pss_pss_sha512                        0x080b
216017f01e99SJung-uk Kim #define TLSEXT_SIGALG_rsa_pkcs1_sha256                          0x0401
216117f01e99SJung-uk Kim #define TLSEXT_SIGALG_rsa_pkcs1_sha384                          0x0501
216217f01e99SJung-uk Kim #define TLSEXT_SIGALG_rsa_pkcs1_sha512                          0x0601
216317f01e99SJung-uk Kim #define TLSEXT_SIGALG_rsa_pkcs1_sha224                          0x0301
216417f01e99SJung-uk Kim #define TLSEXT_SIGALG_rsa_pkcs1_sha1                            0x0201
216517f01e99SJung-uk Kim #define TLSEXT_SIGALG_dsa_sha256                                0x0402
216617f01e99SJung-uk Kim #define TLSEXT_SIGALG_dsa_sha384                                0x0502
216717f01e99SJung-uk Kim #define TLSEXT_SIGALG_dsa_sha512                                0x0602
216817f01e99SJung-uk Kim #define TLSEXT_SIGALG_dsa_sha224                                0x0302
216917f01e99SJung-uk Kim #define TLSEXT_SIGALG_dsa_sha1                                  0x0202
2170b077aed3SPierre Pronchery #define TLSEXT_SIGALG_gostr34102012_256_intrinsic               0x0840
2171b077aed3SPierre Pronchery #define TLSEXT_SIGALG_gostr34102012_512_intrinsic               0x0841
217217f01e99SJung-uk Kim #define TLSEXT_SIGALG_gostr34102012_256_gostr34112012_256       0xeeee
217317f01e99SJung-uk Kim #define TLSEXT_SIGALG_gostr34102012_512_gostr34112012_512       0xefef
217417f01e99SJung-uk Kim #define TLSEXT_SIGALG_gostr34102001_gostr3411                   0xeded
217517f01e99SJung-uk Kim 
217617f01e99SJung-uk Kim #define TLSEXT_SIGALG_ed25519                                   0x0807
217717f01e99SJung-uk Kim #define TLSEXT_SIGALG_ed448                                     0x0808
217817f01e99SJung-uk Kim 
217917f01e99SJung-uk Kim /* Known PSK key exchange modes */
218017f01e99SJung-uk Kim #define TLSEXT_KEX_MODE_KE                                      0x00
218117f01e99SJung-uk Kim #define TLSEXT_KEX_MODE_KE_DHE                                  0x01
218217f01e99SJung-uk Kim 
218317f01e99SJung-uk Kim /*
218417f01e99SJung-uk Kim  * Internal representations of key exchange modes
218517f01e99SJung-uk Kim  */
218617f01e99SJung-uk Kim #define TLSEXT_KEX_MODE_FLAG_NONE                               0
218717f01e99SJung-uk Kim #define TLSEXT_KEX_MODE_FLAG_KE                                 1
218817f01e99SJung-uk Kim #define TLSEXT_KEX_MODE_FLAG_KE_DHE                             2
218917f01e99SJung-uk Kim 
2190b077aed3SPierre Pronchery #define SSL_USE_PSS(s) (s->s3.tmp.peer_sigalg != NULL && \
2191b077aed3SPierre Pronchery                         s->s3.tmp.peer_sigalg->sig == EVP_PKEY_RSA_PSS)
219217f01e99SJung-uk Kim 
219317f01e99SJung-uk Kim /* A dummy signature value not valid for TLSv1.2 signature algs */
219417f01e99SJung-uk Kim #define TLSEXT_signature_rsa_pss                                0x0101
219517f01e99SJung-uk Kim 
219617f01e99SJung-uk Kim /* TLSv1.3 downgrade protection sentinel values */
219717f01e99SJung-uk Kim extern const unsigned char tls11downgrade[8];
219817f01e99SJung-uk Kim extern const unsigned char tls12downgrade[8];
219917f01e99SJung-uk Kim 
220017f01e99SJung-uk Kim extern SSL3_ENC_METHOD ssl3_undef_enc_method;
220117f01e99SJung-uk Kim 
220217f01e99SJung-uk Kim __owur const SSL_METHOD *ssl_bad_method(int ver);
220317f01e99SJung-uk Kim __owur const SSL_METHOD *sslv3_method(void);
220417f01e99SJung-uk Kim __owur const SSL_METHOD *sslv3_server_method(void);
220517f01e99SJung-uk Kim __owur const SSL_METHOD *sslv3_client_method(void);
220617f01e99SJung-uk Kim __owur const SSL_METHOD *tlsv1_method(void);
220717f01e99SJung-uk Kim __owur const SSL_METHOD *tlsv1_server_method(void);
220817f01e99SJung-uk Kim __owur const SSL_METHOD *tlsv1_client_method(void);
220917f01e99SJung-uk Kim __owur const SSL_METHOD *tlsv1_1_method(void);
221017f01e99SJung-uk Kim __owur const SSL_METHOD *tlsv1_1_server_method(void);
221117f01e99SJung-uk Kim __owur const SSL_METHOD *tlsv1_1_client_method(void);
221217f01e99SJung-uk Kim __owur const SSL_METHOD *tlsv1_2_method(void);
221317f01e99SJung-uk Kim __owur const SSL_METHOD *tlsv1_2_server_method(void);
221417f01e99SJung-uk Kim __owur const SSL_METHOD *tlsv1_2_client_method(void);
221517f01e99SJung-uk Kim __owur const SSL_METHOD *tlsv1_3_method(void);
221617f01e99SJung-uk Kim __owur const SSL_METHOD *tlsv1_3_server_method(void);
221717f01e99SJung-uk Kim __owur const SSL_METHOD *tlsv1_3_client_method(void);
221817f01e99SJung-uk Kim __owur const SSL_METHOD *dtlsv1_method(void);
221917f01e99SJung-uk Kim __owur const SSL_METHOD *dtlsv1_server_method(void);
222017f01e99SJung-uk Kim __owur const SSL_METHOD *dtlsv1_client_method(void);
222117f01e99SJung-uk Kim __owur const SSL_METHOD *dtls_bad_ver_client_method(void);
222217f01e99SJung-uk Kim __owur const SSL_METHOD *dtlsv1_2_method(void);
222317f01e99SJung-uk Kim __owur const SSL_METHOD *dtlsv1_2_server_method(void);
222417f01e99SJung-uk Kim __owur const SSL_METHOD *dtlsv1_2_client_method(void);
222517f01e99SJung-uk Kim 
222617f01e99SJung-uk Kim extern const SSL3_ENC_METHOD TLSv1_enc_data;
222717f01e99SJung-uk Kim extern const SSL3_ENC_METHOD TLSv1_1_enc_data;
222817f01e99SJung-uk Kim extern const SSL3_ENC_METHOD TLSv1_2_enc_data;
222917f01e99SJung-uk Kim extern const SSL3_ENC_METHOD TLSv1_3_enc_data;
223017f01e99SJung-uk Kim extern const SSL3_ENC_METHOD SSLv3_enc_data;
223117f01e99SJung-uk Kim extern const SSL3_ENC_METHOD DTLSv1_enc_data;
223217f01e99SJung-uk Kim extern const SSL3_ENC_METHOD DTLSv1_2_enc_data;
223317f01e99SJung-uk Kim 
223417f01e99SJung-uk Kim /*
223517f01e99SJung-uk Kim  * Flags for SSL methods
223617f01e99SJung-uk Kim  */
223717f01e99SJung-uk Kim # define SSL_METHOD_NO_FIPS      (1U<<0)
223817f01e99SJung-uk Kim # define SSL_METHOD_NO_SUITEB    (1U<<1)
223917f01e99SJung-uk Kim 
224017f01e99SJung-uk Kim # define IMPLEMENT_tls_meth_func(version, flags, mask, func_name, s_accept, \
224117f01e99SJung-uk Kim                                  s_connect, enc_data) \
224217f01e99SJung-uk Kim const SSL_METHOD *func_name(void)  \
224317f01e99SJung-uk Kim         { \
224417f01e99SJung-uk Kim         static const SSL_METHOD func_name##_data= { \
224517f01e99SJung-uk Kim                 version, \
224617f01e99SJung-uk Kim                 flags, \
224717f01e99SJung-uk Kim                 mask, \
224817f01e99SJung-uk Kim                 tls1_new, \
224917f01e99SJung-uk Kim                 tls1_clear, \
225017f01e99SJung-uk Kim                 tls1_free, \
225117f01e99SJung-uk Kim                 s_accept, \
225217f01e99SJung-uk Kim                 s_connect, \
225317f01e99SJung-uk Kim                 ssl3_read, \
225417f01e99SJung-uk Kim                 ssl3_peek, \
225517f01e99SJung-uk Kim                 ssl3_write, \
225617f01e99SJung-uk Kim                 ssl3_shutdown, \
225717f01e99SJung-uk Kim                 ssl3_renegotiate, \
225817f01e99SJung-uk Kim                 ssl3_renegotiate_check, \
225917f01e99SJung-uk Kim                 ssl3_read_bytes, \
226017f01e99SJung-uk Kim                 ssl3_write_bytes, \
226117f01e99SJung-uk Kim                 ssl3_dispatch_alert, \
226217f01e99SJung-uk Kim                 ssl3_ctrl, \
226317f01e99SJung-uk Kim                 ssl3_ctx_ctrl, \
226417f01e99SJung-uk Kim                 ssl3_get_cipher_by_char, \
226517f01e99SJung-uk Kim                 ssl3_put_cipher_by_char, \
226617f01e99SJung-uk Kim                 ssl3_pending, \
226717f01e99SJung-uk Kim                 ssl3_num_ciphers, \
226817f01e99SJung-uk Kim                 ssl3_get_cipher, \
226917f01e99SJung-uk Kim                 tls1_default_timeout, \
227017f01e99SJung-uk Kim                 &enc_data, \
227117f01e99SJung-uk Kim                 ssl_undefined_void_function, \
227217f01e99SJung-uk Kim                 ssl3_callback_ctrl, \
227317f01e99SJung-uk Kim                 ssl3_ctx_callback_ctrl, \
227417f01e99SJung-uk Kim         }; \
227517f01e99SJung-uk Kim         return &func_name##_data; \
227617f01e99SJung-uk Kim         }
227717f01e99SJung-uk Kim 
227817f01e99SJung-uk Kim # define IMPLEMENT_ssl3_meth_func(func_name, s_accept, s_connect) \
227917f01e99SJung-uk Kim const SSL_METHOD *func_name(void)  \
228017f01e99SJung-uk Kim         { \
228117f01e99SJung-uk Kim         static const SSL_METHOD func_name##_data= { \
228217f01e99SJung-uk Kim                 SSL3_VERSION, \
228317f01e99SJung-uk Kim                 SSL_METHOD_NO_FIPS | SSL_METHOD_NO_SUITEB, \
228417f01e99SJung-uk Kim                 SSL_OP_NO_SSLv3, \
228517f01e99SJung-uk Kim                 ssl3_new, \
228617f01e99SJung-uk Kim                 ssl3_clear, \
228717f01e99SJung-uk Kim                 ssl3_free, \
228817f01e99SJung-uk Kim                 s_accept, \
228917f01e99SJung-uk Kim                 s_connect, \
229017f01e99SJung-uk Kim                 ssl3_read, \
229117f01e99SJung-uk Kim                 ssl3_peek, \
229217f01e99SJung-uk Kim                 ssl3_write, \
229317f01e99SJung-uk Kim                 ssl3_shutdown, \
229417f01e99SJung-uk Kim                 ssl3_renegotiate, \
229517f01e99SJung-uk Kim                 ssl3_renegotiate_check, \
229617f01e99SJung-uk Kim                 ssl3_read_bytes, \
229717f01e99SJung-uk Kim                 ssl3_write_bytes, \
229817f01e99SJung-uk Kim                 ssl3_dispatch_alert, \
229917f01e99SJung-uk Kim                 ssl3_ctrl, \
230017f01e99SJung-uk Kim                 ssl3_ctx_ctrl, \
230117f01e99SJung-uk Kim                 ssl3_get_cipher_by_char, \
230217f01e99SJung-uk Kim                 ssl3_put_cipher_by_char, \
230317f01e99SJung-uk Kim                 ssl3_pending, \
230417f01e99SJung-uk Kim                 ssl3_num_ciphers, \
230517f01e99SJung-uk Kim                 ssl3_get_cipher, \
230617f01e99SJung-uk Kim                 ssl3_default_timeout, \
230717f01e99SJung-uk Kim                 &SSLv3_enc_data, \
230817f01e99SJung-uk Kim                 ssl_undefined_void_function, \
230917f01e99SJung-uk Kim                 ssl3_callback_ctrl, \
231017f01e99SJung-uk Kim                 ssl3_ctx_callback_ctrl, \
231117f01e99SJung-uk Kim         }; \
231217f01e99SJung-uk Kim         return &func_name##_data; \
231317f01e99SJung-uk Kim         }
231417f01e99SJung-uk Kim 
231517f01e99SJung-uk Kim # define IMPLEMENT_dtls1_meth_func(version, flags, mask, func_name, s_accept, \
231617f01e99SJung-uk Kim                                         s_connect, enc_data) \
231717f01e99SJung-uk Kim const SSL_METHOD *func_name(void)  \
231817f01e99SJung-uk Kim         { \
231917f01e99SJung-uk Kim         static const SSL_METHOD func_name##_data= { \
232017f01e99SJung-uk Kim                 version, \
232117f01e99SJung-uk Kim                 flags, \
232217f01e99SJung-uk Kim                 mask, \
232317f01e99SJung-uk Kim                 dtls1_new, \
232417f01e99SJung-uk Kim                 dtls1_clear, \
232517f01e99SJung-uk Kim                 dtls1_free, \
232617f01e99SJung-uk Kim                 s_accept, \
232717f01e99SJung-uk Kim                 s_connect, \
232817f01e99SJung-uk Kim                 ssl3_read, \
232917f01e99SJung-uk Kim                 ssl3_peek, \
233017f01e99SJung-uk Kim                 ssl3_write, \
233117f01e99SJung-uk Kim                 dtls1_shutdown, \
233217f01e99SJung-uk Kim                 ssl3_renegotiate, \
233317f01e99SJung-uk Kim                 ssl3_renegotiate_check, \
233417f01e99SJung-uk Kim                 dtls1_read_bytes, \
233517f01e99SJung-uk Kim                 dtls1_write_app_data_bytes, \
233617f01e99SJung-uk Kim                 dtls1_dispatch_alert, \
233717f01e99SJung-uk Kim                 dtls1_ctrl, \
233817f01e99SJung-uk Kim                 ssl3_ctx_ctrl, \
233917f01e99SJung-uk Kim                 ssl3_get_cipher_by_char, \
234017f01e99SJung-uk Kim                 ssl3_put_cipher_by_char, \
234117f01e99SJung-uk Kim                 ssl3_pending, \
234217f01e99SJung-uk Kim                 ssl3_num_ciphers, \
234317f01e99SJung-uk Kim                 ssl3_get_cipher, \
234417f01e99SJung-uk Kim                 dtls1_default_timeout, \
234517f01e99SJung-uk Kim                 &enc_data, \
234617f01e99SJung-uk Kim                 ssl_undefined_void_function, \
234717f01e99SJung-uk Kim                 ssl3_callback_ctrl, \
234817f01e99SJung-uk Kim                 ssl3_ctx_callback_ctrl, \
234917f01e99SJung-uk Kim         }; \
235017f01e99SJung-uk Kim         return &func_name##_data; \
235117f01e99SJung-uk Kim         }
235217f01e99SJung-uk Kim 
235317f01e99SJung-uk Kim struct openssl_ssl_test_functions {
235417f01e99SJung-uk Kim     int (*p_ssl_init_wbio_buffer) (SSL *s);
235517f01e99SJung-uk Kim     int (*p_ssl3_setup_buffers) (SSL *s);
235617f01e99SJung-uk Kim };
235717f01e99SJung-uk Kim 
235817f01e99SJung-uk Kim const char *ssl_protocol_to_string(int version);
235917f01e99SJung-uk Kim 
236017f01e99SJung-uk Kim /* Returns true if certificate and private key for 'idx' are present */
ssl_has_cert(const SSL * s,int idx)236117f01e99SJung-uk Kim static ossl_inline int ssl_has_cert(const SSL *s, int idx)
236217f01e99SJung-uk Kim {
236317f01e99SJung-uk Kim     if (idx < 0 || idx >= SSL_PKEY_NUM)
236417f01e99SJung-uk Kim         return 0;
236517f01e99SJung-uk Kim     return s->cert->pkeys[idx].x509 != NULL
236617f01e99SJung-uk Kim         && s->cert->pkeys[idx].privatekey != NULL;
236717f01e99SJung-uk Kim }
236817f01e99SJung-uk Kim 
tls1_get_peer_groups(SSL * s,const uint16_t ** pgroups,size_t * pgroupslen)236917f01e99SJung-uk Kim static ossl_inline void tls1_get_peer_groups(SSL *s, const uint16_t **pgroups,
237017f01e99SJung-uk Kim                                              size_t *pgroupslen)
237117f01e99SJung-uk Kim {
237217f01e99SJung-uk Kim     *pgroups = s->ext.peer_supportedgroups;
237317f01e99SJung-uk Kim     *pgroupslen = s->ext.peer_supportedgroups_len;
237417f01e99SJung-uk Kim }
237517f01e99SJung-uk Kim 
237617f01e99SJung-uk Kim # ifndef OPENSSL_UNIT_TEST
237717f01e99SJung-uk Kim 
237817f01e99SJung-uk Kim __owur int ssl_read_internal(SSL *s, void *buf, size_t num, size_t *readbytes);
237917f01e99SJung-uk Kim __owur int ssl_write_internal(SSL *s, const void *buf, size_t num, size_t *written);
238017f01e99SJung-uk Kim void ssl_clear_cipher_ctx(SSL *s);
238117f01e99SJung-uk Kim int ssl_clear_bad_session(SSL *s);
238217f01e99SJung-uk Kim __owur CERT *ssl_cert_new(void);
238317f01e99SJung-uk Kim __owur CERT *ssl_cert_dup(CERT *cert);
238417f01e99SJung-uk Kim void ssl_cert_clear_certs(CERT *c);
238517f01e99SJung-uk Kim void ssl_cert_free(CERT *c);
238617f01e99SJung-uk Kim __owur int ssl_generate_session_id(SSL *s, SSL_SESSION *ss);
238717f01e99SJung-uk Kim __owur int ssl_get_new_session(SSL *s, int session);
238817f01e99SJung-uk Kim __owur SSL_SESSION *lookup_sess_in_cache(SSL *s, const unsigned char *sess_id,
238917f01e99SJung-uk Kim                                          size_t sess_id_len);
239017f01e99SJung-uk Kim __owur int ssl_get_prev_session(SSL *s, CLIENTHELLO_MSG *hello);
2391b077aed3SPierre Pronchery __owur SSL_SESSION *ssl_session_dup(const SSL_SESSION *src, int ticket);
239217f01e99SJung-uk Kim __owur int ssl_cipher_id_cmp(const SSL_CIPHER *a, const SSL_CIPHER *b);
239317f01e99SJung-uk Kim DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER, ssl_cipher_id);
239417f01e99SJung-uk Kim __owur int ssl_cipher_ptr_id_cmp(const SSL_CIPHER *const *ap,
239517f01e99SJung-uk Kim                                  const SSL_CIPHER *const *bp);
2396b077aed3SPierre Pronchery __owur STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx,
239717f01e99SJung-uk Kim                                                     STACK_OF(SSL_CIPHER) *tls13_ciphersuites,
239817f01e99SJung-uk Kim                                                     STACK_OF(SSL_CIPHER) **cipher_list,
239917f01e99SJung-uk Kim                                                     STACK_OF(SSL_CIPHER) **cipher_list_by_id,
240017f01e99SJung-uk Kim                                                     const char *rule_str,
240117f01e99SJung-uk Kim                                                     CERT *c);
240217f01e99SJung-uk Kim __owur int ssl_cache_cipherlist(SSL *s, PACKET *cipher_suites, int sslv2format);
240317f01e99SJung-uk Kim __owur int bytes_to_cipher_list(SSL *s, PACKET *cipher_suites,
240417f01e99SJung-uk Kim                                 STACK_OF(SSL_CIPHER) **skp,
240517f01e99SJung-uk Kim                                 STACK_OF(SSL_CIPHER) **scsvs, int sslv2format,
240617f01e99SJung-uk Kim                                 int fatal);
240717f01e99SJung-uk Kim void ssl_update_cache(SSL *s, int mode);
2408b077aed3SPierre Pronchery __owur int ssl_cipher_get_evp_cipher(SSL_CTX *ctx, const SSL_CIPHER *sslc,
2409b077aed3SPierre Pronchery                                      const EVP_CIPHER **enc);
2410b077aed3SPierre Pronchery __owur int ssl_cipher_get_evp(SSL_CTX *ctxc, const SSL_SESSION *s,
2411b077aed3SPierre Pronchery                               const EVP_CIPHER **enc, const EVP_MD **md,
2412b077aed3SPierre Pronchery                               int *mac_pkey_type, size_t *mac_secret_size,
2413b077aed3SPierre Pronchery                               SSL_COMP **comp, int use_etm);
241417f01e99SJung-uk Kim __owur int ssl_cipher_get_overhead(const SSL_CIPHER *c, size_t *mac_overhead,
241517f01e99SJung-uk Kim                                    size_t *int_overhead, size_t *blocksize,
241617f01e99SJung-uk Kim                                    size_t *ext_overhead);
2417b077aed3SPierre Pronchery __owur int ssl_cert_is_disabled(SSL_CTX *ctx, size_t idx);
241817f01e99SJung-uk Kim __owur const SSL_CIPHER *ssl_get_cipher_by_char(SSL *ssl,
241917f01e99SJung-uk Kim                                                 const unsigned char *ptr,
242017f01e99SJung-uk Kim                                                 int all);
242117f01e99SJung-uk Kim __owur int ssl_cert_set0_chain(SSL *s, SSL_CTX *ctx, STACK_OF(X509) *chain);
242217f01e99SJung-uk Kim __owur int ssl_cert_set1_chain(SSL *s, SSL_CTX *ctx, STACK_OF(X509) *chain);
242317f01e99SJung-uk Kim __owur int ssl_cert_add0_chain_cert(SSL *s, SSL_CTX *ctx, X509 *x);
242417f01e99SJung-uk Kim __owur int ssl_cert_add1_chain_cert(SSL *s, SSL_CTX *ctx, X509 *x);
242517f01e99SJung-uk Kim __owur int ssl_cert_select_current(CERT *c, X509 *x);
242617f01e99SJung-uk Kim __owur int ssl_cert_set_current(CERT *c, long arg);
242717f01e99SJung-uk Kim void ssl_cert_set_cert_cb(CERT *c, int (*cb) (SSL *ssl, void *arg), void *arg);
242817f01e99SJung-uk Kim 
242917f01e99SJung-uk Kim __owur int ssl_verify_cert_chain(SSL *s, STACK_OF(X509) *sk);
243017f01e99SJung-uk Kim __owur int ssl_build_cert_chain(SSL *s, SSL_CTX *ctx, int flags);
243117f01e99SJung-uk Kim __owur int ssl_cert_set_cert_store(CERT *c, X509_STORE *store, int chain,
243217f01e99SJung-uk Kim                                    int ref);
243383eaf7aeSJung-uk Kim __owur int ssl_cert_get_cert_store(CERT *c, X509_STORE **pstore, int chain);
243417f01e99SJung-uk Kim 
243517f01e99SJung-uk Kim __owur int ssl_security(const SSL *s, int op, int bits, int nid, void *other);
243617f01e99SJung-uk Kim __owur int ssl_ctx_security(const SSL_CTX *ctx, int op, int bits, int nid,
243717f01e99SJung-uk Kim                             void *other);
24389a3ae0cdSJung-uk Kim int ssl_get_security_level_bits(const SSL *s, const SSL_CTX *ctx, int *levelp);
243917f01e99SJung-uk Kim 
244017f01e99SJung-uk Kim __owur int ssl_cert_lookup_by_nid(int nid, size_t *pidx);
244117f01e99SJung-uk Kim __owur const SSL_CERT_LOOKUP *ssl_cert_lookup_by_pkey(const EVP_PKEY *pk,
244217f01e99SJung-uk Kim                                                       size_t *pidx);
244317f01e99SJung-uk Kim __owur const SSL_CERT_LOOKUP *ssl_cert_lookup_by_idx(size_t idx);
244417f01e99SJung-uk Kim 
244517f01e99SJung-uk Kim int ssl_undefined_function(SSL *s);
244617f01e99SJung-uk Kim __owur int ssl_undefined_void_function(void);
244717f01e99SJung-uk Kim __owur int ssl_undefined_const_function(const SSL *s);
244817f01e99SJung-uk Kim __owur int ssl_get_server_cert_serverinfo(SSL *s,
244917f01e99SJung-uk Kim                                           const unsigned char **serverinfo,
245017f01e99SJung-uk Kim                                           size_t *serverinfo_length);
245117f01e99SJung-uk Kim void ssl_set_masks(SSL *s);
245217f01e99SJung-uk Kim __owur STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s);
245317f01e99SJung-uk Kim __owur int ssl_x509err2alert(int type);
245417f01e99SJung-uk Kim void ssl_sort_cipher_list(void);
2455b077aed3SPierre Pronchery int ssl_load_ciphers(SSL_CTX *ctx);
2456b077aed3SPierre Pronchery __owur int ssl_setup_sig_algs(SSL_CTX *ctx);
2457b077aed3SPierre Pronchery int ssl_load_groups(SSL_CTX *ctx);
245817f01e99SJung-uk Kim __owur int ssl_fill_hello_random(SSL *s, int server, unsigned char *field,
245917f01e99SJung-uk Kim                                  size_t len, DOWNGRADE dgrd);
246017f01e99SJung-uk Kim __owur int ssl_generate_master_secret(SSL *s, unsigned char *pms, size_t pmslen,
246117f01e99SJung-uk Kim                                       int free_pms);
2462b077aed3SPierre Pronchery __owur EVP_PKEY *ssl_generate_pkey(SSL *s, EVP_PKEY *pm);
2463b077aed3SPierre Pronchery __owur int ssl_gensecret(SSL *s, unsigned char *pms, size_t pmslen);
246417f01e99SJung-uk Kim __owur int ssl_derive(SSL *s, EVP_PKEY *privkey, EVP_PKEY *pubkey,
246517f01e99SJung-uk Kim                       int genmaster);
2466b077aed3SPierre Pronchery __owur int ssl_decapsulate(SSL *s, EVP_PKEY *privkey,
2467b077aed3SPierre Pronchery                            const unsigned char *ct, size_t ctlen,
2468b077aed3SPierre Pronchery                            int gensecret);
2469b077aed3SPierre Pronchery __owur int ssl_encapsulate(SSL *s, EVP_PKEY *pubkey,
2470b077aed3SPierre Pronchery                            unsigned char **ctp, size_t *ctlenp,
2471b077aed3SPierre Pronchery                            int gensecret);
247217f01e99SJung-uk Kim __owur EVP_PKEY *ssl_dh_to_pkey(DH *dh);
2473b077aed3SPierre Pronchery __owur int ssl_set_tmp_ecdh_groups(uint16_t **pext, size_t *pextlen,
2474b077aed3SPierre Pronchery                                    void *key);
247517f01e99SJung-uk Kim __owur unsigned int ssl_get_max_send_fragment(const SSL *ssl);
247617f01e99SJung-uk Kim __owur unsigned int ssl_get_split_send_fragment(const SSL *ssl);
247717f01e99SJung-uk Kim 
247817f01e99SJung-uk Kim __owur const SSL_CIPHER *ssl3_get_cipher_by_id(uint32_t id);
247917f01e99SJung-uk Kim __owur const SSL_CIPHER *ssl3_get_cipher_by_std_name(const char *stdname);
248017f01e99SJung-uk Kim __owur const SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p);
248117f01e99SJung-uk Kim __owur int ssl3_put_cipher_by_char(const SSL_CIPHER *c, WPACKET *pkt,
248217f01e99SJung-uk Kim                                    size_t *len);
248317f01e99SJung-uk Kim int ssl3_init_finished_mac(SSL *s);
248417f01e99SJung-uk Kim __owur int ssl3_setup_key_block(SSL *s);
248517f01e99SJung-uk Kim __owur int ssl3_change_cipher_state(SSL *s, int which);
248617f01e99SJung-uk Kim void ssl3_cleanup_key_block(SSL *s);
248717f01e99SJung-uk Kim __owur int ssl3_do_write(SSL *s, int type);
248817f01e99SJung-uk Kim int ssl3_send_alert(SSL *s, int level, int desc);
248917f01e99SJung-uk Kim __owur int ssl3_generate_master_secret(SSL *s, unsigned char *out,
249017f01e99SJung-uk Kim                                        unsigned char *p, size_t len,
249117f01e99SJung-uk Kim                                        size_t *secret_size);
249217f01e99SJung-uk Kim __owur int ssl3_get_req_cert_type(SSL *s, WPACKET *pkt);
249317f01e99SJung-uk Kim __owur int ssl3_num_ciphers(void);
249417f01e99SJung-uk Kim __owur const SSL_CIPHER *ssl3_get_cipher(unsigned int u);
249517f01e99SJung-uk Kim int ssl3_renegotiate(SSL *ssl);
249617f01e99SJung-uk Kim int ssl3_renegotiate_check(SSL *ssl, int initok);
2497b077aed3SPierre Pronchery void ssl3_digest_master_key_set_params(const SSL_SESSION *session,
2498b077aed3SPierre Pronchery                                        OSSL_PARAM params[]);
249917f01e99SJung-uk Kim __owur int ssl3_dispatch_alert(SSL *s);
250017f01e99SJung-uk Kim __owur size_t ssl3_final_finish_mac(SSL *s, const char *sender, size_t slen,
250117f01e99SJung-uk Kim                                     unsigned char *p);
250217f01e99SJung-uk Kim __owur int ssl3_finish_mac(SSL *s, const unsigned char *buf, size_t len);
250317f01e99SJung-uk Kim void ssl3_free_digest_list(SSL *s);
250417f01e99SJung-uk Kim __owur unsigned long ssl3_output_cert_chain(SSL *s, WPACKET *pkt,
250517f01e99SJung-uk Kim                                             CERT_PKEY *cpk);
250617f01e99SJung-uk Kim __owur const SSL_CIPHER *ssl3_choose_cipher(SSL *ssl,
250717f01e99SJung-uk Kim                                             STACK_OF(SSL_CIPHER) *clnt,
250817f01e99SJung-uk Kim                                             STACK_OF(SSL_CIPHER) *srvr);
250917f01e99SJung-uk Kim __owur int ssl3_digest_cached_records(SSL *s, int keep);
251017f01e99SJung-uk Kim __owur int ssl3_new(SSL *s);
251117f01e99SJung-uk Kim void ssl3_free(SSL *s);
251217f01e99SJung-uk Kim __owur int ssl3_read(SSL *s, void *buf, size_t len, size_t *readbytes);
251317f01e99SJung-uk Kim __owur int ssl3_peek(SSL *s, void *buf, size_t len, size_t *readbytes);
251417f01e99SJung-uk Kim __owur int ssl3_write(SSL *s, const void *buf, size_t len, size_t *written);
251517f01e99SJung-uk Kim __owur int ssl3_shutdown(SSL *s);
251617f01e99SJung-uk Kim int ssl3_clear(SSL *s);
251717f01e99SJung-uk Kim __owur long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg);
251817f01e99SJung-uk Kim __owur long ssl3_ctx_ctrl(SSL_CTX *s, int cmd, long larg, void *parg);
251917f01e99SJung-uk Kim __owur long ssl3_callback_ctrl(SSL *s, int cmd, void (*fp) (void));
252017f01e99SJung-uk Kim __owur long ssl3_ctx_callback_ctrl(SSL_CTX *s, int cmd, void (*fp) (void));
252117f01e99SJung-uk Kim 
252217f01e99SJung-uk Kim __owur int ssl3_do_change_cipher_spec(SSL *ssl);
252317f01e99SJung-uk Kim __owur long ssl3_default_timeout(void);
252417f01e99SJung-uk Kim 
252517f01e99SJung-uk Kim __owur int ssl3_set_handshake_header(SSL *s, WPACKET *pkt, int htype);
252617f01e99SJung-uk Kim __owur int tls_close_construct_packet(SSL *s, WPACKET *pkt, int htype);
252717f01e99SJung-uk Kim __owur int tls_setup_handshake(SSL *s);
252817f01e99SJung-uk Kim __owur int dtls1_set_handshake_header(SSL *s, WPACKET *pkt, int htype);
252917f01e99SJung-uk Kim __owur int dtls1_close_construct_packet(SSL *s, WPACKET *pkt, int htype);
253017f01e99SJung-uk Kim __owur int ssl3_handshake_write(SSL *s);
253117f01e99SJung-uk Kim 
253217f01e99SJung-uk Kim __owur int ssl_allow_compression(SSL *s);
253317f01e99SJung-uk Kim 
253417f01e99SJung-uk Kim __owur int ssl_version_supported(const SSL *s, int version,
253517f01e99SJung-uk Kim                                  const SSL_METHOD **meth);
253617f01e99SJung-uk Kim 
253717f01e99SJung-uk Kim __owur int ssl_set_client_hello_version(SSL *s);
253817f01e99SJung-uk Kim __owur int ssl_check_version_downgrade(SSL *s);
253917f01e99SJung-uk Kim __owur int ssl_set_version_bound(int method_version, int version, int *bound);
254017f01e99SJung-uk Kim __owur int ssl_choose_server_version(SSL *s, CLIENTHELLO_MSG *hello,
254117f01e99SJung-uk Kim                                      DOWNGRADE *dgrd);
254217f01e99SJung-uk Kim __owur int ssl_choose_client_version(SSL *s, int version,
254317f01e99SJung-uk Kim                                      RAW_EXTENSION *extensions);
254417f01e99SJung-uk Kim __owur int ssl_get_min_max_version(const SSL *s, int *min_version,
254517f01e99SJung-uk Kim                                    int *max_version, int *real_max);
254617f01e99SJung-uk Kim 
254717f01e99SJung-uk Kim __owur long tls1_default_timeout(void);
254817f01e99SJung-uk Kim __owur int dtls1_do_write(SSL *s, int type);
254917f01e99SJung-uk Kim void dtls1_set_message_header(SSL *s,
255017f01e99SJung-uk Kim                               unsigned char mt,
255117f01e99SJung-uk Kim                               size_t len,
255217f01e99SJung-uk Kim                               size_t frag_off, size_t frag_len);
255317f01e99SJung-uk Kim 
255417f01e99SJung-uk Kim int dtls1_write_app_data_bytes(SSL *s, int type, const void *buf_, size_t len,
255517f01e99SJung-uk Kim                                size_t *written);
255617f01e99SJung-uk Kim 
255717f01e99SJung-uk Kim __owur int dtls1_read_failed(SSL *s, int code);
255817f01e99SJung-uk Kim __owur int dtls1_buffer_message(SSL *s, int ccs);
255917f01e99SJung-uk Kim __owur int dtls1_retransmit_message(SSL *s, unsigned short seq, int *found);
256017f01e99SJung-uk Kim __owur int dtls1_get_queue_priority(unsigned short seq, int is_ccs);
256117f01e99SJung-uk Kim int dtls1_retransmit_buffered_messages(SSL *s);
256217f01e99SJung-uk Kim void dtls1_clear_received_buffer(SSL *s);
256317f01e99SJung-uk Kim void dtls1_clear_sent_buffer(SSL *s);
256417f01e99SJung-uk Kim void dtls1_get_message_header(unsigned char *data,
256517f01e99SJung-uk Kim                               struct hm_header_st *msg_hdr);
256617f01e99SJung-uk Kim __owur long dtls1_default_timeout(void);
256717f01e99SJung-uk Kim __owur struct timeval *dtls1_get_timeout(SSL *s, struct timeval *timeleft);
256817f01e99SJung-uk Kim __owur int dtls1_check_timeout_num(SSL *s);
256917f01e99SJung-uk Kim __owur int dtls1_handle_timeout(SSL *s);
257017f01e99SJung-uk Kim void dtls1_start_timer(SSL *s);
257117f01e99SJung-uk Kim void dtls1_stop_timer(SSL *s);
257217f01e99SJung-uk Kim __owur int dtls1_is_timer_expired(SSL *s);
257317f01e99SJung-uk Kim __owur int dtls_raw_hello_verify_request(WPACKET *pkt, unsigned char *cookie,
257417f01e99SJung-uk Kim                                          size_t cookie_len);
257517f01e99SJung-uk Kim __owur size_t dtls1_min_mtu(SSL *s);
257617f01e99SJung-uk Kim void dtls1_hm_fragment_free(hm_fragment *frag);
257717f01e99SJung-uk Kim __owur int dtls1_query_mtu(SSL *s);
257817f01e99SJung-uk Kim 
257917f01e99SJung-uk Kim __owur int tls1_new(SSL *s);
258017f01e99SJung-uk Kim void tls1_free(SSL *s);
258117f01e99SJung-uk Kim int tls1_clear(SSL *s);
258217f01e99SJung-uk Kim 
258317f01e99SJung-uk Kim __owur int dtls1_new(SSL *s);
258417f01e99SJung-uk Kim void dtls1_free(SSL *s);
258517f01e99SJung-uk Kim int dtls1_clear(SSL *s);
258617f01e99SJung-uk Kim long dtls1_ctrl(SSL *s, int cmd, long larg, void *parg);
258717f01e99SJung-uk Kim __owur int dtls1_shutdown(SSL *s);
258817f01e99SJung-uk Kim 
258917f01e99SJung-uk Kim __owur int dtls1_dispatch_alert(SSL *s);
259017f01e99SJung-uk Kim 
259117f01e99SJung-uk Kim __owur int ssl_init_wbio_buffer(SSL *s);
259217f01e99SJung-uk Kim int ssl_free_wbio_buffer(SSL *s);
259317f01e99SJung-uk Kim 
259417f01e99SJung-uk Kim __owur int tls1_change_cipher_state(SSL *s, int which);
259517f01e99SJung-uk Kim __owur int tls1_setup_key_block(SSL *s);
259617f01e99SJung-uk Kim __owur size_t tls1_final_finish_mac(SSL *s, const char *str, size_t slen,
259717f01e99SJung-uk Kim                                     unsigned char *p);
259817f01e99SJung-uk Kim __owur int tls1_generate_master_secret(SSL *s, unsigned char *out,
259917f01e99SJung-uk Kim                                        unsigned char *p, size_t len,
260017f01e99SJung-uk Kim                                        size_t *secret_size);
260117f01e99SJung-uk Kim __owur int tls13_setup_key_block(SSL *s);
260217f01e99SJung-uk Kim __owur size_t tls13_final_finish_mac(SSL *s, const char *str, size_t slen,
260317f01e99SJung-uk Kim                                      unsigned char *p);
260417f01e99SJung-uk Kim __owur int tls13_change_cipher_state(SSL *s, int which);
260517f01e99SJung-uk Kim __owur int tls13_update_key(SSL *s, int send);
260617f01e99SJung-uk Kim __owur int tls13_hkdf_expand(SSL *s, const EVP_MD *md,
260717f01e99SJung-uk Kim                              const unsigned char *secret,
260817f01e99SJung-uk Kim                              const unsigned char *label, size_t labellen,
260917f01e99SJung-uk Kim                              const unsigned char *data, size_t datalen,
261017f01e99SJung-uk Kim                              unsigned char *out, size_t outlen, int fatal);
261117f01e99SJung-uk Kim __owur int tls13_derive_key(SSL *s, const EVP_MD *md,
261217f01e99SJung-uk Kim                             const unsigned char *secret, unsigned char *key,
261317f01e99SJung-uk Kim                             size_t keylen);
261417f01e99SJung-uk Kim __owur int tls13_derive_iv(SSL *s, const EVP_MD *md,
261517f01e99SJung-uk Kim                            const unsigned char *secret, unsigned char *iv,
261617f01e99SJung-uk Kim                            size_t ivlen);
261717f01e99SJung-uk Kim __owur int tls13_derive_finishedkey(SSL *s, const EVP_MD *md,
261817f01e99SJung-uk Kim                                     const unsigned char *secret,
261917f01e99SJung-uk Kim                                     unsigned char *fin, size_t finlen);
262017f01e99SJung-uk Kim int tls13_generate_secret(SSL *s, const EVP_MD *md,
262117f01e99SJung-uk Kim                           const unsigned char *prevsecret,
262217f01e99SJung-uk Kim                           const unsigned char *insecret,
262317f01e99SJung-uk Kim                           size_t insecretlen,
262417f01e99SJung-uk Kim                           unsigned char *outsecret);
262517f01e99SJung-uk Kim __owur int tls13_generate_handshake_secret(SSL *s,
262617f01e99SJung-uk Kim                                            const unsigned char *insecret,
262717f01e99SJung-uk Kim                                            size_t insecretlen);
262817f01e99SJung-uk Kim __owur int tls13_generate_master_secret(SSL *s, unsigned char *out,
262917f01e99SJung-uk Kim                                         unsigned char *prev, size_t prevlen,
263017f01e99SJung-uk Kim                                         size_t *secret_size);
263117f01e99SJung-uk Kim __owur int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,
263217f01e99SJung-uk Kim                                        const char *label, size_t llen,
263317f01e99SJung-uk Kim                                        const unsigned char *p, size_t plen,
263417f01e99SJung-uk Kim                                        int use_context);
263517f01e99SJung-uk Kim __owur int tls13_export_keying_material(SSL *s, unsigned char *out, size_t olen,
263617f01e99SJung-uk Kim                                         const char *label, size_t llen,
263717f01e99SJung-uk Kim                                         const unsigned char *context,
263817f01e99SJung-uk Kim                                         size_t contextlen, int use_context);
263917f01e99SJung-uk Kim __owur int tls13_export_keying_material_early(SSL *s, unsigned char *out,
264017f01e99SJung-uk Kim                                               size_t olen, const char *label,
264117f01e99SJung-uk Kim                                               size_t llen,
264217f01e99SJung-uk Kim                                               const unsigned char *context,
264317f01e99SJung-uk Kim                                               size_t contextlen);
264417f01e99SJung-uk Kim __owur int tls1_alert_code(int code);
264517f01e99SJung-uk Kim __owur int tls13_alert_code(int code);
264617f01e99SJung-uk Kim __owur int ssl3_alert_code(int code);
264717f01e99SJung-uk Kim 
264817f01e99SJung-uk Kim __owur int ssl_check_srvr_ecc_cert_and_alg(X509 *x, SSL *s);
264917f01e99SJung-uk Kim 
265017f01e99SJung-uk Kim SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n);
265117f01e99SJung-uk Kim 
2652b077aed3SPierre Pronchery __owur const TLS_GROUP_INFO *tls1_group_id_lookup(SSL_CTX *ctx, uint16_t curve_id);
2653b077aed3SPierre Pronchery __owur int tls1_group_id2nid(uint16_t group_id, int include_unknown);
2654b077aed3SPierre Pronchery __owur uint16_t tls1_nid2group_id(int nid);
265517f01e99SJung-uk Kim __owur int tls1_check_group_id(SSL *s, uint16_t group_id, int check_own_curves);
265617f01e99SJung-uk Kim __owur uint16_t tls1_shared_group(SSL *s, int nmatch);
265717f01e99SJung-uk Kim __owur int tls1_set_groups(uint16_t **pext, size_t *pextlen,
265817f01e99SJung-uk Kim                            int *curves, size_t ncurves);
2659b077aed3SPierre Pronchery __owur int tls1_set_groups_list(SSL_CTX *ctx, uint16_t **pext, size_t *pextlen,
266017f01e99SJung-uk Kim                                 const char *str);
2661b077aed3SPierre Pronchery __owur EVP_PKEY *ssl_generate_pkey_group(SSL *s, uint16_t id);
2662b077aed3SPierre Pronchery __owur int tls_valid_group(SSL *s, uint16_t group_id, int minversion,
2663b077aed3SPierre Pronchery                            int maxversion, int isec, int *okfortls13);
2664b077aed3SPierre Pronchery __owur EVP_PKEY *ssl_generate_param_group(SSL *s, uint16_t id);
266517f01e99SJung-uk Kim void tls1_get_formatlist(SSL *s, const unsigned char **pformats,
266617f01e99SJung-uk Kim                          size_t *num_formats);
266717f01e99SJung-uk Kim __owur int tls1_check_ec_tmp_key(SSL *s, unsigned long id);
266817f01e99SJung-uk Kim 
2669b077aed3SPierre Pronchery __owur int tls_group_allowed(SSL *s, uint16_t curve, int op);
267017f01e99SJung-uk Kim void tls1_get_supported_groups(SSL *s, const uint16_t **pgroups,
267117f01e99SJung-uk Kim                                size_t *pgroupslen);
267217f01e99SJung-uk Kim 
267317f01e99SJung-uk Kim __owur int tls1_set_server_sigalgs(SSL *s);
267417f01e99SJung-uk Kim 
267517f01e99SJung-uk Kim __owur SSL_TICKET_STATUS tls_get_ticket_from_client(SSL *s, CLIENTHELLO_MSG *hello,
267617f01e99SJung-uk Kim                                                     SSL_SESSION **ret);
267717f01e99SJung-uk Kim __owur SSL_TICKET_STATUS tls_decrypt_ticket(SSL *s, const unsigned char *etick,
267817f01e99SJung-uk Kim                                             size_t eticklen,
267917f01e99SJung-uk Kim                                             const unsigned char *sess_id,
268017f01e99SJung-uk Kim                                             size_t sesslen, SSL_SESSION **psess);
268117f01e99SJung-uk Kim 
268217f01e99SJung-uk Kim __owur int tls_use_ticket(SSL *s);
268317f01e99SJung-uk Kim 
268417f01e99SJung-uk Kim void ssl_set_sig_mask(uint32_t *pmask_a, SSL *s, int op);
268517f01e99SJung-uk Kim 
268617f01e99SJung-uk Kim __owur int tls1_set_sigalgs_list(CERT *c, const char *str, int client);
268717f01e99SJung-uk Kim __owur int tls1_set_raw_sigalgs(CERT *c, const uint16_t *psigs, size_t salglen,
268817f01e99SJung-uk Kim                                 int client);
268917f01e99SJung-uk Kim __owur int tls1_set_sigalgs(CERT *c, const int *salg, size_t salglen,
269017f01e99SJung-uk Kim                             int client);
269117f01e99SJung-uk Kim int tls1_check_chain(SSL *s, X509 *x, EVP_PKEY *pk, STACK_OF(X509) *chain,
269217f01e99SJung-uk Kim                      int idx);
269317f01e99SJung-uk Kim void tls1_set_cert_validity(SSL *s);
269417f01e99SJung-uk Kim 
269517f01e99SJung-uk Kim #  ifndef OPENSSL_NO_CT
269617f01e99SJung-uk Kim __owur int ssl_validate_ct(SSL *s);
269717f01e99SJung-uk Kim #  endif
269817f01e99SJung-uk Kim 
2699b077aed3SPierre Pronchery __owur EVP_PKEY *ssl_get_auto_dh(SSL *s);
270017f01e99SJung-uk Kim 
270117f01e99SJung-uk Kim __owur int ssl_security_cert(SSL *s, SSL_CTX *ctx, X509 *x, int vfy, int is_ee);
270217f01e99SJung-uk Kim __owur int ssl_security_cert_chain(SSL *s, STACK_OF(X509) *sk, X509 *ex,
270317f01e99SJung-uk Kim                                    int vfy);
270417f01e99SJung-uk Kim 
270517f01e99SJung-uk Kim int tls_choose_sigalg(SSL *s, int fatalerrs);
270617f01e99SJung-uk Kim 
270717f01e99SJung-uk Kim __owur EVP_MD_CTX *ssl_replace_hash(EVP_MD_CTX **hash, const EVP_MD *md);
270817f01e99SJung-uk Kim void ssl_clear_hash_ctx(EVP_MD_CTX **hash);
270917f01e99SJung-uk Kim __owur long ssl_get_algorithm2(SSL *s);
271017f01e99SJung-uk Kim __owur int tls12_copy_sigalgs(SSL *s, WPACKET *pkt,
271117f01e99SJung-uk Kim                               const uint16_t *psig, size_t psiglen);
271217f01e99SJung-uk Kim __owur int tls1_save_u16(PACKET *pkt, uint16_t **pdest, size_t *pdestlen);
271317f01e99SJung-uk Kim __owur int tls1_save_sigalgs(SSL *s, PACKET *pkt, int cert);
271417f01e99SJung-uk Kim __owur int tls1_process_sigalgs(SSL *s);
271517f01e99SJung-uk Kim __owur int tls1_set_peer_legacy_sigalg(SSL *s, const EVP_PKEY *pkey);
2716b077aed3SPierre Pronchery __owur int tls1_lookup_md(SSL_CTX *ctx, const SIGALG_LOOKUP *lu,
2717b077aed3SPierre Pronchery                           const EVP_MD **pmd);
271817f01e99SJung-uk Kim __owur size_t tls12_get_psigalgs(SSL *s, int sent, const uint16_t **psigs);
271917f01e99SJung-uk Kim __owur int tls_check_sigalg_curve(const SSL *s, int curve);
272017f01e99SJung-uk Kim __owur int tls12_check_peer_sigalg(SSL *s, uint16_t, EVP_PKEY *pkey);
272117f01e99SJung-uk Kim __owur int ssl_set_client_disabled(SSL *s);
272217f01e99SJung-uk Kim __owur int ssl_cipher_disabled(const SSL *s, const SSL_CIPHER *c, int op, int echde);
272317f01e99SJung-uk Kim 
272417f01e99SJung-uk Kim __owur int ssl_handshake_hash(SSL *s, unsigned char *out, size_t outlen,
272517f01e99SJung-uk Kim                                  size_t *hashlen);
2726b077aed3SPierre Pronchery __owur const EVP_MD *ssl_md(SSL_CTX *ctx, int idx);
272717f01e99SJung-uk Kim __owur const EVP_MD *ssl_handshake_md(SSL *s);
272817f01e99SJung-uk Kim __owur const EVP_MD *ssl_prf_md(SSL *s);
272917f01e99SJung-uk Kim 
273017f01e99SJung-uk Kim /*
273117f01e99SJung-uk Kim  * ssl_log_rsa_client_key_exchange logs |premaster| to the SSL_CTX associated
273217f01e99SJung-uk Kim  * with |ssl|, if logging is enabled. It returns one on success and zero on
273317f01e99SJung-uk Kim  * failure. The entry is identified by the first 8 bytes of
273417f01e99SJung-uk Kim  * |encrypted_premaster|.
273517f01e99SJung-uk Kim  */
273617f01e99SJung-uk Kim __owur int ssl_log_rsa_client_key_exchange(SSL *ssl,
273717f01e99SJung-uk Kim                                            const uint8_t *encrypted_premaster,
273817f01e99SJung-uk Kim                                            size_t encrypted_premaster_len,
273917f01e99SJung-uk Kim                                            const uint8_t *premaster,
274017f01e99SJung-uk Kim                                            size_t premaster_len);
274117f01e99SJung-uk Kim 
274217f01e99SJung-uk Kim /*
274317f01e99SJung-uk Kim  * ssl_log_secret logs |secret| to the SSL_CTX associated with |ssl|, if
274417f01e99SJung-uk Kim  * logging is available. It returns one on success and zero on failure. It tags
274517f01e99SJung-uk Kim  * the entry with |label|.
274617f01e99SJung-uk Kim  */
274717f01e99SJung-uk Kim __owur int ssl_log_secret(SSL *ssl, const char *label,
274817f01e99SJung-uk Kim                           const uint8_t *secret, size_t secret_len);
274917f01e99SJung-uk Kim 
275017f01e99SJung-uk Kim #define MASTER_SECRET_LABEL "CLIENT_RANDOM"
275117f01e99SJung-uk Kim #define CLIENT_EARLY_LABEL "CLIENT_EARLY_TRAFFIC_SECRET"
275217f01e99SJung-uk Kim #define CLIENT_HANDSHAKE_LABEL "CLIENT_HANDSHAKE_TRAFFIC_SECRET"
275317f01e99SJung-uk Kim #define SERVER_HANDSHAKE_LABEL "SERVER_HANDSHAKE_TRAFFIC_SECRET"
275417f01e99SJung-uk Kim #define CLIENT_APPLICATION_LABEL "CLIENT_TRAFFIC_SECRET_0"
2755b077aed3SPierre Pronchery #define CLIENT_APPLICATION_N_LABEL "CLIENT_TRAFFIC_SECRET_N"
275617f01e99SJung-uk Kim #define SERVER_APPLICATION_LABEL "SERVER_TRAFFIC_SECRET_0"
2757b077aed3SPierre Pronchery #define SERVER_APPLICATION_N_LABEL "SERVER_TRAFFIC_SECRET_N"
275817f01e99SJung-uk Kim #define EARLY_EXPORTER_SECRET_LABEL "EARLY_EXPORTER_SECRET"
275917f01e99SJung-uk Kim #define EXPORTER_SECRET_LABEL "EXPORTER_SECRET"
276017f01e99SJung-uk Kim 
2761aa906e2aSJohn Baldwin #  ifndef OPENSSL_NO_KTLS
2762aa906e2aSJohn Baldwin /* ktls.c */
2763aa906e2aSJohn Baldwin int ktls_check_supported_cipher(const SSL *s, const EVP_CIPHER *c,
2764aa906e2aSJohn Baldwin                                 const EVP_CIPHER_CTX *dd);
2765*eee55a22SJohn Baldwin int ktls_configure_crypto(SSL *s, const EVP_CIPHER *c, EVP_CIPHER_CTX *dd,
2766aa906e2aSJohn Baldwin                           void *rl_sequence, ktls_crypto_info_t *crypto_info,
2767*eee55a22SJohn Baldwin                           int is_tx, unsigned char *iv,
2768aa906e2aSJohn Baldwin                           unsigned char *key, unsigned char *mac_key,
2769aa906e2aSJohn Baldwin                           size_t mac_secret_size);
2770aa906e2aSJohn Baldwin #  endif
2771aa906e2aSJohn Baldwin 
277217f01e99SJung-uk Kim /* s3_cbc.c */
277317f01e99SJung-uk Kim __owur char ssl3_cbc_record_digest_supported(const EVP_MD_CTX *ctx);
2774b077aed3SPierre Pronchery __owur int ssl3_cbc_digest_record(const EVP_MD *md,
277517f01e99SJung-uk Kim                                   unsigned char *md_out,
277617f01e99SJung-uk Kim                                   size_t *md_out_size,
2777b2bf0c7eSJung-uk Kim                                   const unsigned char *header,
277817f01e99SJung-uk Kim                                   const unsigned char *data,
2779b077aed3SPierre Pronchery                                   size_t data_size,
278017f01e99SJung-uk Kim                                   size_t data_plus_mac_plus_padding_size,
278117f01e99SJung-uk Kim                                   const unsigned char *mac_secret,
278217f01e99SJung-uk Kim                                   size_t mac_secret_length, char is_sslv3);
278317f01e99SJung-uk Kim 
278417f01e99SJung-uk Kim __owur int srp_generate_server_master_secret(SSL *s);
278517f01e99SJung-uk Kim __owur int srp_generate_client_master_secret(SSL *s);
278617f01e99SJung-uk Kim __owur int srp_verify_server_param(SSL *s);
278717f01e99SJung-uk Kim 
278817f01e99SJung-uk Kim /* statem/statem_srvr.c */
278917f01e99SJung-uk Kim 
279017f01e99SJung-uk Kim __owur int send_certificate_request(SSL *s);
279117f01e99SJung-uk Kim 
279217f01e99SJung-uk Kim /* statem/extensions_cust.c */
279317f01e99SJung-uk Kim 
279417f01e99SJung-uk Kim custom_ext_method *custom_ext_find(const custom_ext_methods *exts,
279517f01e99SJung-uk Kim                                    ENDPOINT role, unsigned int ext_type,
279617f01e99SJung-uk Kim                                    size_t *idx);
279717f01e99SJung-uk Kim 
279817f01e99SJung-uk Kim void custom_ext_init(custom_ext_methods *meths);
279917f01e99SJung-uk Kim 
280017f01e99SJung-uk Kim __owur int custom_ext_parse(SSL *s, unsigned int context, unsigned int ext_type,
280117f01e99SJung-uk Kim                             const unsigned char *ext_data, size_t ext_size,
280217f01e99SJung-uk Kim                             X509 *x, size_t chainidx);
280317f01e99SJung-uk Kim __owur int custom_ext_add(SSL *s, int context, WPACKET *pkt, X509 *x,
280417f01e99SJung-uk Kim                           size_t chainidx, int maxversion);
280517f01e99SJung-uk Kim 
280617f01e99SJung-uk Kim __owur int custom_exts_copy(custom_ext_methods *dst,
280717f01e99SJung-uk Kim                             const custom_ext_methods *src);
280817f01e99SJung-uk Kim __owur int custom_exts_copy_flags(custom_ext_methods *dst,
280917f01e99SJung-uk Kim                                   const custom_ext_methods *src);
281017f01e99SJung-uk Kim void custom_exts_free(custom_ext_methods *exts);
281117f01e99SJung-uk Kim 
281217f01e99SJung-uk Kim void ssl_comp_free_compression_methods_int(void);
281317f01e99SJung-uk Kim 
281417f01e99SJung-uk Kim /* ssl_mcnf.c */
281517f01e99SJung-uk Kim void ssl_ctx_system_config(SSL_CTX *ctx);
281617f01e99SJung-uk Kim 
2817b077aed3SPierre Pronchery const EVP_CIPHER *ssl_evp_cipher_fetch(OSSL_LIB_CTX *libctx,
2818b077aed3SPierre Pronchery                                        int nid,
2819b077aed3SPierre Pronchery                                        const char *properties);
2820b077aed3SPierre Pronchery int ssl_evp_cipher_up_ref(const EVP_CIPHER *cipher);
2821b077aed3SPierre Pronchery void ssl_evp_cipher_free(const EVP_CIPHER *cipher);
2822b077aed3SPierre Pronchery const EVP_MD *ssl_evp_md_fetch(OSSL_LIB_CTX *libctx,
2823b077aed3SPierre Pronchery                                int nid,
2824b077aed3SPierre Pronchery                                const char *properties);
2825b077aed3SPierre Pronchery int ssl_evp_md_up_ref(const EVP_MD *md);
2826b077aed3SPierre Pronchery void ssl_evp_md_free(const EVP_MD *md);
2827b077aed3SPierre Pronchery 
2828b077aed3SPierre Pronchery int tls_provider_set_tls_params(SSL *s, EVP_CIPHER_CTX *ctx,
2829b077aed3SPierre Pronchery                                 const EVP_CIPHER *ciph,
2830b077aed3SPierre Pronchery                                 const EVP_MD *md);
2831b077aed3SPierre Pronchery 
2832b077aed3SPierre Pronchery void tls_engine_finish(ENGINE *e);
2833b077aed3SPierre Pronchery const EVP_CIPHER *tls_get_cipher_from_engine(int nid);
2834b077aed3SPierre Pronchery const EVP_MD *tls_get_digest_from_engine(int nid);
2835b077aed3SPierre Pronchery int tls_engine_load_ssl_client_cert(SSL *s, X509 **px509, EVP_PKEY **ppkey);
2836b077aed3SPierre Pronchery int ssl_hmac_old_new(SSL_HMAC *ret);
2837b077aed3SPierre Pronchery void ssl_hmac_old_free(SSL_HMAC *ctx);
2838b077aed3SPierre Pronchery int ssl_hmac_old_init(SSL_HMAC *ctx, void *key, size_t len, char *md);
2839b077aed3SPierre Pronchery int ssl_hmac_old_update(SSL_HMAC *ctx, const unsigned char *data, size_t len);
2840b077aed3SPierre Pronchery int ssl_hmac_old_final(SSL_HMAC *ctx, unsigned char *md, size_t *len);
2841b077aed3SPierre Pronchery size_t ssl_hmac_old_size(const SSL_HMAC *ctx);
2842b077aed3SPierre Pronchery 
2843b077aed3SPierre Pronchery int ssl_ctx_srp_ctx_free_intern(SSL_CTX *ctx);
2844b077aed3SPierre Pronchery int ssl_ctx_srp_ctx_init_intern(SSL_CTX *ctx);
2845b077aed3SPierre Pronchery int ssl_srp_ctx_free_intern(SSL *s);
2846b077aed3SPierre Pronchery int ssl_srp_ctx_init_intern(SSL *s);
2847b077aed3SPierre Pronchery 
2848b077aed3SPierre Pronchery int ssl_srp_calc_a_param_intern(SSL *s);
2849b077aed3SPierre Pronchery int ssl_srp_server_param_with_username_intern(SSL *s, int *ad);
2850b077aed3SPierre Pronchery 
2851b077aed3SPierre Pronchery void ssl_session_calculate_timeout(SSL_SESSION* ss);
2852b077aed3SPierre Pronchery 
285317f01e99SJung-uk Kim # else /* OPENSSL_UNIT_TEST */
285417f01e99SJung-uk Kim 
285517f01e99SJung-uk Kim #  define ssl_init_wbio_buffer SSL_test_functions()->p_ssl_init_wbio_buffer
285617f01e99SJung-uk Kim #  define ssl3_setup_buffers SSL_test_functions()->p_ssl3_setup_buffers
285717f01e99SJung-uk Kim 
285817f01e99SJung-uk Kim # endif
2859b077aed3SPierre Pronchery 
2860b077aed3SPierre Pronchery /* Some helper routines to support TSAN operations safely */
ssl_tsan_lock(const SSL_CTX * ctx)2861b077aed3SPierre Pronchery static ossl_unused ossl_inline int ssl_tsan_lock(const SSL_CTX *ctx)
2862b077aed3SPierre Pronchery {
2863b077aed3SPierre Pronchery #ifdef TSAN_REQUIRES_LOCKING
2864b077aed3SPierre Pronchery     if (!CRYPTO_THREAD_write_lock(ctx->tsan_lock))
2865b077aed3SPierre Pronchery         return 0;
2866b077aed3SPierre Pronchery #endif
2867b077aed3SPierre Pronchery     return 1;
2868b077aed3SPierre Pronchery }
2869b077aed3SPierre Pronchery 
ssl_tsan_unlock(const SSL_CTX * ctx)2870b077aed3SPierre Pronchery static ossl_unused ossl_inline void ssl_tsan_unlock(const SSL_CTX *ctx)
2871b077aed3SPierre Pronchery {
2872b077aed3SPierre Pronchery #ifdef TSAN_REQUIRES_LOCKING
2873b077aed3SPierre Pronchery     CRYPTO_THREAD_unlock(ctx->tsan_lock);
2874b077aed3SPierre Pronchery #endif
2875b077aed3SPierre Pronchery }
2876b077aed3SPierre Pronchery 
ssl_tsan_counter(const SSL_CTX * ctx,TSAN_QUALIFIER int * stat)2877b077aed3SPierre Pronchery static ossl_unused ossl_inline void ssl_tsan_counter(const SSL_CTX *ctx,
2878b077aed3SPierre Pronchery                                                      TSAN_QUALIFIER int *stat)
2879b077aed3SPierre Pronchery {
2880b077aed3SPierre Pronchery     if (ssl_tsan_lock(ctx)) {
2881b077aed3SPierre Pronchery         tsan_counter(stat);
2882b077aed3SPierre Pronchery         ssl_tsan_unlock(ctx);
2883b077aed3SPierre Pronchery     }
2884b077aed3SPierre Pronchery }
2885b077aed3SPierre Pronchery 
288617f01e99SJung-uk Kim #endif
2887