wolfSSL SSL/TLS library, support up to TLS1.3

Dependents:   CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more

Committer:
wolfSSL
Date:
Tue Aug 22 10:48:22 2017 +0000
Revision:
13:f67a6c6013ca
wolfSSL3.12.0 with TLS1.3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 13:f67a6c6013ca 1 /* internal.h
wolfSSL 13:f67a6c6013ca 2 *
wolfSSL 13:f67a6c6013ca 3 * Copyright (C) 2006-2016 wolfSSL Inc.
wolfSSL 13:f67a6c6013ca 4 *
wolfSSL 13:f67a6c6013ca 5 * This file is part of wolfSSL.
wolfSSL 13:f67a6c6013ca 6 *
wolfSSL 13:f67a6c6013ca 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 13:f67a6c6013ca 8 * it under the terms of the GNU General Public License as published by
wolfSSL 13:f67a6c6013ca 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 13:f67a6c6013ca 10 * (at your option) any later version.
wolfSSL 13:f67a6c6013ca 11 *
wolfSSL 13:f67a6c6013ca 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 13:f67a6c6013ca 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 13:f67a6c6013ca 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 13:f67a6c6013ca 15 * GNU General Public License for more details.
wolfSSL 13:f67a6c6013ca 16 *
wolfSSL 13:f67a6c6013ca 17 * You should have received a copy of the GNU General Public License
wolfSSL 13:f67a6c6013ca 18 * along with this program; if not, write to the Free Software
wolfSSL 13:f67a6c6013ca 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
wolfSSL 13:f67a6c6013ca 20 */
wolfSSL 13:f67a6c6013ca 21
wolfSSL 13:f67a6c6013ca 22
wolfSSL 13:f67a6c6013ca 23
wolfSSL 13:f67a6c6013ca 24 #ifndef WOLFSSL_INT_H
wolfSSL 13:f67a6c6013ca 25 #define WOLFSSL_INT_H
wolfSSL 13:f67a6c6013ca 26
wolfSSL 13:f67a6c6013ca 27
wolfSSL 13:f67a6c6013ca 28 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 13:f67a6c6013ca 29 #include <wolfssl/ssl.h>
wolfSSL 13:f67a6c6013ca 30 #ifdef HAVE_CRL
wolfSSL 13:f67a6c6013ca 31 #include <wolfssl/crl.h>
wolfSSL 13:f67a6c6013ca 32 #endif
wolfSSL 13:f67a6c6013ca 33 #include <wolfssl/wolfcrypt/random.h>
wolfSSL 13:f67a6c6013ca 34 #ifndef NO_DES3
wolfSSL 13:f67a6c6013ca 35 #include <wolfssl/wolfcrypt/des3.h>
wolfSSL 13:f67a6c6013ca 36 #endif
wolfSSL 13:f67a6c6013ca 37 #ifndef NO_HC128
wolfSSL 13:f67a6c6013ca 38 #include <wolfssl/wolfcrypt/hc128.h>
wolfSSL 13:f67a6c6013ca 39 #endif
wolfSSL 13:f67a6c6013ca 40 #ifndef NO_RABBIT
wolfSSL 13:f67a6c6013ca 41 #include <wolfssl/wolfcrypt/rabbit.h>
wolfSSL 13:f67a6c6013ca 42 #endif
wolfSSL 13:f67a6c6013ca 43 #ifdef HAVE_CHACHA
wolfSSL 13:f67a6c6013ca 44 #include <wolfssl/wolfcrypt/chacha.h>
wolfSSL 13:f67a6c6013ca 45 #endif
wolfSSL 13:f67a6c6013ca 46 #ifndef NO_ASN
wolfSSL 13:f67a6c6013ca 47 #include <wolfssl/wolfcrypt/asn.h>
wolfSSL 13:f67a6c6013ca 48 #include <wolfssl/wolfcrypt/pkcs12.h>
wolfSSL 13:f67a6c6013ca 49 #endif
wolfSSL 13:f67a6c6013ca 50 #ifndef NO_MD5
wolfSSL 13:f67a6c6013ca 51 #include <wolfssl/wolfcrypt/md5.h>
wolfSSL 13:f67a6c6013ca 52 #endif
wolfSSL 13:f67a6c6013ca 53 #ifndef NO_SHA
wolfSSL 13:f67a6c6013ca 54 #include <wolfssl/wolfcrypt/sha.h>
wolfSSL 13:f67a6c6013ca 55 #endif
wolfSSL 13:f67a6c6013ca 56 #ifndef NO_AES
wolfSSL 13:f67a6c6013ca 57 #include <wolfssl/wolfcrypt/aes.h>
wolfSSL 13:f67a6c6013ca 58 #endif
wolfSSL 13:f67a6c6013ca 59 #ifdef HAVE_POLY1305
wolfSSL 13:f67a6c6013ca 60 #include <wolfssl/wolfcrypt/poly1305.h>
wolfSSL 13:f67a6c6013ca 61 #endif
wolfSSL 13:f67a6c6013ca 62 #ifdef HAVE_CAMELLIA
wolfSSL 13:f67a6c6013ca 63 #include <wolfssl/wolfcrypt/camellia.h>
wolfSSL 13:f67a6c6013ca 64 #endif
wolfSSL 13:f67a6c6013ca 65 #include <wolfssl/wolfcrypt/logging.h>
wolfSSL 13:f67a6c6013ca 66 #ifndef NO_HMAC
wolfSSL 13:f67a6c6013ca 67 #include <wolfssl/wolfcrypt/hmac.h>
wolfSSL 13:f67a6c6013ca 68 #endif
wolfSSL 13:f67a6c6013ca 69 #ifndef NO_RC4
wolfSSL 13:f67a6c6013ca 70 #include <wolfssl/wolfcrypt/arc4.h>
wolfSSL 13:f67a6c6013ca 71 #endif
wolfSSL 13:f67a6c6013ca 72 #ifdef HAVE_ECC
wolfSSL 13:f67a6c6013ca 73 #include <wolfssl/wolfcrypt/ecc.h>
wolfSSL 13:f67a6c6013ca 74 #endif
wolfSSL 13:f67a6c6013ca 75 #ifdef HAVE_ED25519
wolfSSL 13:f67a6c6013ca 76 #include <wolfssl/wolfcrypt/ed25519.h>
wolfSSL 13:f67a6c6013ca 77 #endif
wolfSSL 13:f67a6c6013ca 78 #ifdef HAVE_CURVE25519
wolfSSL 13:f67a6c6013ca 79 #include <wolfssl/wolfcrypt/curve25519.h>
wolfSSL 13:f67a6c6013ca 80 #endif
wolfSSL 13:f67a6c6013ca 81 #ifndef NO_SHA256
wolfSSL 13:f67a6c6013ca 82 #include <wolfssl/wolfcrypt/sha256.h>
wolfSSL 13:f67a6c6013ca 83 #endif
wolfSSL 13:f67a6c6013ca 84 #ifdef HAVE_OCSP
wolfSSL 13:f67a6c6013ca 85 #include <wolfssl/ocsp.h>
wolfSSL 13:f67a6c6013ca 86 #endif
wolfSSL 13:f67a6c6013ca 87 #ifdef WOLFSSL_SHA512
wolfSSL 13:f67a6c6013ca 88 #include <wolfssl/wolfcrypt/sha512.h>
wolfSSL 13:f67a6c6013ca 89 #endif
wolfSSL 13:f67a6c6013ca 90 #ifdef HAVE_AESGCM
wolfSSL 13:f67a6c6013ca 91 #include <wolfssl/wolfcrypt/sha512.h>
wolfSSL 13:f67a6c6013ca 92 #endif
wolfSSL 13:f67a6c6013ca 93 #ifdef WOLFSSL_RIPEMD
wolfSSL 13:f67a6c6013ca 94 #include <wolfssl/wolfcrypt/ripemd.h>
wolfSSL 13:f67a6c6013ca 95 #endif
wolfSSL 13:f67a6c6013ca 96 #ifdef HAVE_IDEA
wolfSSL 13:f67a6c6013ca 97 #include <wolfssl/wolfcrypt/idea.h>
wolfSSL 13:f67a6c6013ca 98 #endif
wolfSSL 13:f67a6c6013ca 99 #ifndef NO_RSA
wolfSSL 13:f67a6c6013ca 100 #include <wolfssl/wolfcrypt/rsa.h>
wolfSSL 13:f67a6c6013ca 101 #endif
wolfSSL 13:f67a6c6013ca 102 #ifdef HAVE_ECC
wolfSSL 13:f67a6c6013ca 103 #include <wolfssl/wolfcrypt/ecc.h>
wolfSSL 13:f67a6c6013ca 104 #endif
wolfSSL 13:f67a6c6013ca 105 #ifndef NO_DH
wolfSSL 13:f67a6c6013ca 106 #include <wolfssl/wolfcrypt/dh.h>
wolfSSL 13:f67a6c6013ca 107 #endif
wolfSSL 13:f67a6c6013ca 108
wolfSSL 13:f67a6c6013ca 109 #include <wolfssl/wolfcrypt/hash.h>
wolfSSL 13:f67a6c6013ca 110
wolfSSL 13:f67a6c6013ca 111 #ifdef WOLFSSL_CALLBACKS
wolfSSL 13:f67a6c6013ca 112 #include <wolfssl/callbacks.h>
wolfSSL 13:f67a6c6013ca 113 #include <signal.h>
wolfSSL 13:f67a6c6013ca 114 #endif
wolfSSL 13:f67a6c6013ca 115
wolfSSL 13:f67a6c6013ca 116 #ifdef USE_WINDOWS_API
wolfSSL 13:f67a6c6013ca 117 #ifdef WOLFSSL_GAME_BUILD
wolfSSL 13:f67a6c6013ca 118 #include "system/xtl.h"
wolfSSL 13:f67a6c6013ca 119 #else
wolfSSL 13:f67a6c6013ca 120 #if defined(_WIN32_WCE) || defined(WIN32_LEAN_AND_MEAN)
wolfSSL 13:f67a6c6013ca 121 /* On WinCE winsock2.h must be included before windows.h */
wolfSSL 13:f67a6c6013ca 122 #include <winsock2.h>
wolfSSL 13:f67a6c6013ca 123 #endif
wolfSSL 13:f67a6c6013ca 124 #include <windows.h>
wolfSSL 13:f67a6c6013ca 125 #endif
wolfSSL 13:f67a6c6013ca 126 #elif defined(THREADX)
wolfSSL 13:f67a6c6013ca 127 #ifndef SINGLE_THREADED
wolfSSL 13:f67a6c6013ca 128 #include "tx_api.h"
wolfSSL 13:f67a6c6013ca 129 #endif
wolfSSL 13:f67a6c6013ca 130 #elif defined(MICRIUM)
wolfSSL 13:f67a6c6013ca 131 /* do nothing, just don't pick Unix */
wolfSSL 13:f67a6c6013ca 132 #elif defined(FREERTOS) || defined(FREERTOS_TCP) || defined(WOLFSSL_SAFERTOS)
wolfSSL 13:f67a6c6013ca 133 /* do nothing */
wolfSSL 13:f67a6c6013ca 134 #elif defined(EBSNET)
wolfSSL 13:f67a6c6013ca 135 /* do nothing */
wolfSSL 13:f67a6c6013ca 136 #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
wolfSSL 13:f67a6c6013ca 137 /* do nothing */
wolfSSL 13:f67a6c6013ca 138 #elif defined(FREESCALE_FREE_RTOS)
wolfSSL 13:f67a6c6013ca 139 #include "fsl_os_abstraction.h"
wolfSSL 13:f67a6c6013ca 140 #elif defined(WOLFSSL_uITRON4)
wolfSSL 13:f67a6c6013ca 141 /* do nothing */
wolfSSL 13:f67a6c6013ca 142 #elif defined(WOLFSSL_uTKERNEL2)
wolfSSL 13:f67a6c6013ca 143 /* do nothing */
wolfSSL 13:f67a6c6013ca 144 #elif defined(WOLFSSL_MDK_ARM)
wolfSSL 13:f67a6c6013ca 145 #if defined(WOLFSSL_MDK5)
wolfSSL 13:f67a6c6013ca 146 #include "cmsis_os.h"
wolfSSL 13:f67a6c6013ca 147 #else
wolfSSL 13:f67a6c6013ca 148 #include <rtl.h>
wolfSSL 13:f67a6c6013ca 149 #endif
wolfSSL 13:f67a6c6013ca 150 #elif defined(WOLFSSL_CMSIS_RTOS)
wolfSSL 13:f67a6c6013ca 151 #include "cmsis_os.h"
wolfSSL 13:f67a6c6013ca 152 #elif defined(MBED)
wolfSSL 13:f67a6c6013ca 153 #elif defined(WOLFSSL_TIRTOS)
wolfSSL 13:f67a6c6013ca 154 /* do nothing */
wolfSSL 13:f67a6c6013ca 155 #elif defined(INTIME_RTOS)
wolfSSL 13:f67a6c6013ca 156 #include <rt.h>
wolfSSL 13:f67a6c6013ca 157 #else
wolfSSL 13:f67a6c6013ca 158 #ifndef SINGLE_THREADED
wolfSSL 13:f67a6c6013ca 159 #define WOLFSSL_PTHREADS
wolfSSL 13:f67a6c6013ca 160 #include <pthread.h>
wolfSSL 13:f67a6c6013ca 161 #endif
wolfSSL 13:f67a6c6013ca 162 #if defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS)
wolfSSL 13:f67a6c6013ca 163 #include <unistd.h> /* for close of BIO */
wolfSSL 13:f67a6c6013ca 164 #endif
wolfSSL 13:f67a6c6013ca 165 #endif
wolfSSL 13:f67a6c6013ca 166
wolfSSL 13:f67a6c6013ca 167 #ifndef CHAR_BIT
wolfSSL 13:f67a6c6013ca 168 /* Needed for DTLS without big math */
wolfSSL 13:f67a6c6013ca 169 #include <limits.h>
wolfSSL 13:f67a6c6013ca 170 #endif
wolfSSL 13:f67a6c6013ca 171
wolfSSL 13:f67a6c6013ca 172
wolfSSL 13:f67a6c6013ca 173 #ifdef HAVE_LIBZ
wolfSSL 13:f67a6c6013ca 174 #include "zlib.h"
wolfSSL 13:f67a6c6013ca 175 #endif
wolfSSL 13:f67a6c6013ca 176
wolfSSL 13:f67a6c6013ca 177 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 13:f67a6c6013ca 178 #include <wolfssl/wolfcrypt/async.h>
wolfSSL 13:f67a6c6013ca 179 #endif
wolfSSL 13:f67a6c6013ca 180
wolfSSL 13:f67a6c6013ca 181 #ifdef _MSC_VER
wolfSSL 13:f67a6c6013ca 182 /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
wolfSSL 13:f67a6c6013ca 183 #pragma warning(disable: 4996)
wolfSSL 13:f67a6c6013ca 184 #endif
wolfSSL 13:f67a6c6013ca 185
wolfSSL 13:f67a6c6013ca 186 #ifdef NO_SHA
wolfSSL 13:f67a6c6013ca 187 #define SHA_DIGEST_SIZE 20
wolfSSL 13:f67a6c6013ca 188 #endif
wolfSSL 13:f67a6c6013ca 189
wolfSSL 13:f67a6c6013ca 190 #ifdef NO_SHA256
wolfSSL 13:f67a6c6013ca 191 #define SHA256_DIGEST_SIZE 32
wolfSSL 13:f67a6c6013ca 192 #endif
wolfSSL 13:f67a6c6013ca 193
wolfSSL 13:f67a6c6013ca 194 #ifdef NO_MD5
wolfSSL 13:f67a6c6013ca 195 #define MD5_DIGEST_SIZE 16
wolfSSL 13:f67a6c6013ca 196 #endif
wolfSSL 13:f67a6c6013ca 197
wolfSSL 13:f67a6c6013ca 198
wolfSSL 13:f67a6c6013ca 199 #ifdef __cplusplus
wolfSSL 13:f67a6c6013ca 200 extern "C" {
wolfSSL 13:f67a6c6013ca 201 #endif
wolfSSL 13:f67a6c6013ca 202
wolfSSL 13:f67a6c6013ca 203
wolfSSL 13:f67a6c6013ca 204 typedef byte word24[3];
wolfSSL 13:f67a6c6013ca 205
wolfSSL 13:f67a6c6013ca 206 /* Define or comment out the cipher suites you'd like to be compiled in
wolfSSL 13:f67a6c6013ca 207 make sure to use at least one BUILD_SSL_xxx or BUILD_TLS_xxx is defined
wolfSSL 13:f67a6c6013ca 208
wolfSSL 13:f67a6c6013ca 209 When adding cipher suites, add name to cipher_names, idx to cipher_name_idx
wolfSSL 13:f67a6c6013ca 210
wolfSSL 13:f67a6c6013ca 211 Now that there is a maximum strength crypto build, the following BUILD_XXX
wolfSSL 13:f67a6c6013ca 212 flags need to be divided into two groups selected by WOLFSSL_MAX_STRENGTH.
wolfSSL 13:f67a6c6013ca 213 Those that do not use Perfect Forward Security and do not use AEAD ciphers
wolfSSL 13:f67a6c6013ca 214 need to be switched off. Allowed suites use (EC)DHE, AES-GCM|CCM, or
wolfSSL 13:f67a6c6013ca 215 CHACHA-POLY.
wolfSSL 13:f67a6c6013ca 216 */
wolfSSL 13:f67a6c6013ca 217
wolfSSL 13:f67a6c6013ca 218 /* Check that if WOLFSSL_MAX_STRENGTH is set that all the required options are
wolfSSL 13:f67a6c6013ca 219 * not turned off. */
wolfSSL 13:f67a6c6013ca 220 #if defined(WOLFSSL_MAX_STRENGTH) && \
wolfSSL 13:f67a6c6013ca 221 ((!defined(HAVE_ECC) && (defined(NO_DH) || defined(NO_RSA))) || \
wolfSSL 13:f67a6c6013ca 222 (!defined(HAVE_AESGCM) && !defined(HAVE_AESCCM) && \
wolfSSL 13:f67a6c6013ca 223 (!defined(HAVE_POLY1305) || !defined(HAVE_CHACHA))) || \
wolfSSL 13:f67a6c6013ca 224 (defined(NO_SHA256) && !defined(WOLFSSL_SHA384)) || \
wolfSSL 13:f67a6c6013ca 225 !defined(NO_OLD_TLS))
wolfSSL 13:f67a6c6013ca 226
wolfSSL 13:f67a6c6013ca 227 #error "You are trying to build max strength with requirements disabled."
wolfSSL 13:f67a6c6013ca 228 #endif
wolfSSL 13:f67a6c6013ca 229
wolfSSL 13:f67a6c6013ca 230 /* Have QSH : Quantum-safe Handshake */
wolfSSL 13:f67a6c6013ca 231 #if defined(HAVE_QSH)
wolfSSL 13:f67a6c6013ca 232 #define BUILD_TLS_QSH
wolfSSL 13:f67a6c6013ca 233 #endif
wolfSSL 13:f67a6c6013ca 234
wolfSSL 13:f67a6c6013ca 235 #ifndef WOLFSSL_MAX_STRENGTH
wolfSSL 13:f67a6c6013ca 236
wolfSSL 13:f67a6c6013ca 237 #if !defined(NO_RSA) && !defined(NO_RC4)
wolfSSL 13:f67a6c6013ca 238 #if defined(WOLFSSL_STATIC_RSA)
wolfSSL 13:f67a6c6013ca 239 #if !defined(NO_SHA)
wolfSSL 13:f67a6c6013ca 240 #define BUILD_SSL_RSA_WITH_RC4_128_SHA
wolfSSL 13:f67a6c6013ca 241 #endif
wolfSSL 13:f67a6c6013ca 242 #if !defined(NO_MD5)
wolfSSL 13:f67a6c6013ca 243 #define BUILD_SSL_RSA_WITH_RC4_128_MD5
wolfSSL 13:f67a6c6013ca 244 #endif
wolfSSL 13:f67a6c6013ca 245 #endif
wolfSSL 13:f67a6c6013ca 246 #if !defined(NO_TLS) && defined(HAVE_NTRU) && !defined(NO_SHA) \
wolfSSL 13:f67a6c6013ca 247 && defined(WOLFSSL_STATIC_RSA)
wolfSSL 13:f67a6c6013ca 248 #define BUILD_TLS_NTRU_RSA_WITH_RC4_128_SHA
wolfSSL 13:f67a6c6013ca 249 #endif
wolfSSL 13:f67a6c6013ca 250 #endif
wolfSSL 13:f67a6c6013ca 251
wolfSSL 13:f67a6c6013ca 252 #if !defined(NO_RSA) && !defined(NO_DES3)
wolfSSL 13:f67a6c6013ca 253 #if !defined(NO_SHA)
wolfSSL 13:f67a6c6013ca 254 #if defined(WOLFSSL_STATIC_RSA)
wolfSSL 13:f67a6c6013ca 255 #define BUILD_SSL_RSA_WITH_3DES_EDE_CBC_SHA
wolfSSL 13:f67a6c6013ca 256 #endif
wolfSSL 13:f67a6c6013ca 257 #if !defined(NO_TLS) && defined(HAVE_NTRU) \
wolfSSL 13:f67a6c6013ca 258 && defined(WOLFSSL_STATIC_RSA)
wolfSSL 13:f67a6c6013ca 259 #define BUILD_TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA
wolfSSL 13:f67a6c6013ca 260 #endif
wolfSSL 13:f67a6c6013ca 261 #endif
wolfSSL 13:f67a6c6013ca 262 #endif
wolfSSL 13:f67a6c6013ca 263
wolfSSL 13:f67a6c6013ca 264 #if !defined(NO_RSA) && defined(HAVE_IDEA)
wolfSSL 13:f67a6c6013ca 265 #if !defined(NO_SHA) && defined(WOLFSSL_STATIC_RSA)
wolfSSL 13:f67a6c6013ca 266 #define BUILD_SSL_RSA_WITH_IDEA_CBC_SHA
wolfSSL 13:f67a6c6013ca 267 #endif
wolfSSL 13:f67a6c6013ca 268 #endif
wolfSSL 13:f67a6c6013ca 269
wolfSSL 13:f67a6c6013ca 270 #if !defined(NO_RSA) && !defined(NO_AES) && !defined(NO_TLS)
wolfSSL 13:f67a6c6013ca 271 #if !defined(NO_SHA)
wolfSSL 13:f67a6c6013ca 272 #if defined(WOLFSSL_STATIC_RSA)
wolfSSL 13:f67a6c6013ca 273 #define BUILD_TLS_RSA_WITH_AES_128_CBC_SHA
wolfSSL 13:f67a6c6013ca 274 #define BUILD_TLS_RSA_WITH_AES_256_CBC_SHA
wolfSSL 13:f67a6c6013ca 275 #endif
wolfSSL 13:f67a6c6013ca 276 #if defined(HAVE_NTRU) && defined(WOLFSSL_STATIC_RSA)
wolfSSL 13:f67a6c6013ca 277 #define BUILD_TLS_NTRU_RSA_WITH_AES_128_CBC_SHA
wolfSSL 13:f67a6c6013ca 278 #define BUILD_TLS_NTRU_RSA_WITH_AES_256_CBC_SHA
wolfSSL 13:f67a6c6013ca 279 #endif
wolfSSL 13:f67a6c6013ca 280 #endif
wolfSSL 13:f67a6c6013ca 281 #if defined(WOLFSSL_STATIC_RSA)
wolfSSL 13:f67a6c6013ca 282 #if !defined (NO_SHA256)
wolfSSL 13:f67a6c6013ca 283 #define BUILD_TLS_RSA_WITH_AES_128_CBC_SHA256
wolfSSL 13:f67a6c6013ca 284 #define BUILD_TLS_RSA_WITH_AES_256_CBC_SHA256
wolfSSL 13:f67a6c6013ca 285 #endif
wolfSSL 13:f67a6c6013ca 286 #if defined (HAVE_AESGCM)
wolfSSL 13:f67a6c6013ca 287 #define BUILD_TLS_RSA_WITH_AES_128_GCM_SHA256
wolfSSL 13:f67a6c6013ca 288 #if defined (WOLFSSL_SHA384)
wolfSSL 13:f67a6c6013ca 289 #define BUILD_TLS_RSA_WITH_AES_256_GCM_SHA384
wolfSSL 13:f67a6c6013ca 290 #endif
wolfSSL 13:f67a6c6013ca 291 #endif
wolfSSL 13:f67a6c6013ca 292 #if defined (HAVE_AESCCM)
wolfSSL 13:f67a6c6013ca 293 #define BUILD_TLS_RSA_WITH_AES_128_CCM_8
wolfSSL 13:f67a6c6013ca 294 #define BUILD_TLS_RSA_WITH_AES_256_CCM_8
wolfSSL 13:f67a6c6013ca 295 #endif
wolfSSL 13:f67a6c6013ca 296 #if defined(HAVE_BLAKE2)
wolfSSL 13:f67a6c6013ca 297 #define BUILD_TLS_RSA_WITH_AES_128_CBC_B2B256
wolfSSL 13:f67a6c6013ca 298 #define BUILD_TLS_RSA_WITH_AES_256_CBC_B2B256
wolfSSL 13:f67a6c6013ca 299 #endif
wolfSSL 13:f67a6c6013ca 300 #endif
wolfSSL 13:f67a6c6013ca 301 #endif
wolfSSL 13:f67a6c6013ca 302
wolfSSL 13:f67a6c6013ca 303 #if defined(HAVE_CAMELLIA) && !defined(NO_TLS)
wolfSSL 13:f67a6c6013ca 304 #ifndef NO_RSA
wolfSSL 13:f67a6c6013ca 305 #if defined(WOLFSSL_STATIC_RSA)
wolfSSL 13:f67a6c6013ca 306 #if !defined(NO_SHA)
wolfSSL 13:f67a6c6013ca 307 #define BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA
wolfSSL 13:f67a6c6013ca 308 #define BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA
wolfSSL 13:f67a6c6013ca 309 #endif
wolfSSL 13:f67a6c6013ca 310 #ifndef NO_SHA256
wolfSSL 13:f67a6c6013ca 311 #define BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256
wolfSSL 13:f67a6c6013ca 312 #define BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256
wolfSSL 13:f67a6c6013ca 313 #endif
wolfSSL 13:f67a6c6013ca 314 #endif
wolfSSL 13:f67a6c6013ca 315 #if !defined(NO_DH)
wolfSSL 13:f67a6c6013ca 316 #if !defined(NO_SHA)
wolfSSL 13:f67a6c6013ca 317 #define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA
wolfSSL 13:f67a6c6013ca 318 #define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA
wolfSSL 13:f67a6c6013ca 319 #endif
wolfSSL 13:f67a6c6013ca 320 #ifndef NO_SHA256
wolfSSL 13:f67a6c6013ca 321 #define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
wolfSSL 13:f67a6c6013ca 322 #define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256
wolfSSL 13:f67a6c6013ca 323 #endif
wolfSSL 13:f67a6c6013ca 324 #endif
wolfSSL 13:f67a6c6013ca 325 #endif
wolfSSL 13:f67a6c6013ca 326 #endif
wolfSSL 13:f67a6c6013ca 327
wolfSSL 13:f67a6c6013ca 328 #if defined(WOLFSSL_STATIC_PSK)
wolfSSL 13:f67a6c6013ca 329 #if !defined(NO_PSK) && !defined(NO_AES) && !defined(NO_TLS)
wolfSSL 13:f67a6c6013ca 330 #if !defined(NO_SHA)
wolfSSL 13:f67a6c6013ca 331 #define BUILD_TLS_PSK_WITH_AES_128_CBC_SHA
wolfSSL 13:f67a6c6013ca 332 #define BUILD_TLS_PSK_WITH_AES_256_CBC_SHA
wolfSSL 13:f67a6c6013ca 333 #endif
wolfSSL 13:f67a6c6013ca 334 #ifndef NO_SHA256
wolfSSL 13:f67a6c6013ca 335 #define BUILD_TLS_PSK_WITH_AES_128_CBC_SHA256
wolfSSL 13:f67a6c6013ca 336 #ifdef HAVE_AESGCM
wolfSSL 13:f67a6c6013ca 337 #define BUILD_TLS_PSK_WITH_AES_128_GCM_SHA256
wolfSSL 13:f67a6c6013ca 338 #endif
wolfSSL 13:f67a6c6013ca 339 #ifdef HAVE_AESCCM
wolfSSL 13:f67a6c6013ca 340 #define BUILD_TLS_PSK_WITH_AES_128_CCM_8
wolfSSL 13:f67a6c6013ca 341 #define BUILD_TLS_PSK_WITH_AES_256_CCM_8
wolfSSL 13:f67a6c6013ca 342 #define BUILD_TLS_PSK_WITH_AES_128_CCM
wolfSSL 13:f67a6c6013ca 343 #define BUILD_TLS_PSK_WITH_AES_256_CCM
wolfSSL 13:f67a6c6013ca 344 #endif
wolfSSL 13:f67a6c6013ca 345 #endif
wolfSSL 13:f67a6c6013ca 346 #ifdef WOLFSSL_SHA384
wolfSSL 13:f67a6c6013ca 347 #define BUILD_TLS_PSK_WITH_AES_256_CBC_SHA384
wolfSSL 13:f67a6c6013ca 348 #ifdef HAVE_AESGCM
wolfSSL 13:f67a6c6013ca 349 #define BUILD_TLS_PSK_WITH_AES_256_GCM_SHA384
wolfSSL 13:f67a6c6013ca 350 #endif
wolfSSL 13:f67a6c6013ca 351 #endif
wolfSSL 13:f67a6c6013ca 352 #endif
wolfSSL 13:f67a6c6013ca 353 #endif
wolfSSL 13:f67a6c6013ca 354
wolfSSL 13:f67a6c6013ca 355 #if !defined(NO_TLS) && defined(HAVE_NULL_CIPHER)
wolfSSL 13:f67a6c6013ca 356 #if !defined(NO_RSA)
wolfSSL 13:f67a6c6013ca 357 #if defined(WOLFSSL_STATIC_RSA)
wolfSSL 13:f67a6c6013ca 358 #if !defined(NO_SHA)
wolfSSL 13:f67a6c6013ca 359 #define BUILD_TLS_RSA_WITH_NULL_SHA
wolfSSL 13:f67a6c6013ca 360 #endif
wolfSSL 13:f67a6c6013ca 361 #ifndef NO_SHA256
wolfSSL 13:f67a6c6013ca 362 #define BUILD_TLS_RSA_WITH_NULL_SHA256
wolfSSL 13:f67a6c6013ca 363 #endif
wolfSSL 13:f67a6c6013ca 364 #endif
wolfSSL 13:f67a6c6013ca 365 #endif
wolfSSL 13:f67a6c6013ca 366 #if !defined(NO_PSK) && defined(WOLFSSL_STATIC_PSK)
wolfSSL 13:f67a6c6013ca 367 #if !defined(NO_SHA)
wolfSSL 13:f67a6c6013ca 368 #define BUILD_TLS_PSK_WITH_NULL_SHA
wolfSSL 13:f67a6c6013ca 369 #endif
wolfSSL 13:f67a6c6013ca 370 #ifndef NO_SHA256
wolfSSL 13:f67a6c6013ca 371 #define BUILD_TLS_PSK_WITH_NULL_SHA256
wolfSSL 13:f67a6c6013ca 372 #endif
wolfSSL 13:f67a6c6013ca 373 #ifdef WOLFSSL_SHA384
wolfSSL 13:f67a6c6013ca 374 #define BUILD_TLS_PSK_WITH_NULL_SHA384
wolfSSL 13:f67a6c6013ca 375 #endif
wolfSSL 13:f67a6c6013ca 376 #endif
wolfSSL 13:f67a6c6013ca 377 #endif
wolfSSL 13:f67a6c6013ca 378
wolfSSL 13:f67a6c6013ca 379 #if defined(WOLFSSL_STATIC_RSA)
wolfSSL 13:f67a6c6013ca 380 #if !defined(NO_HC128) && !defined(NO_RSA) && !defined(NO_TLS)
wolfSSL 13:f67a6c6013ca 381 #ifndef NO_MD5
wolfSSL 13:f67a6c6013ca 382 #define BUILD_TLS_RSA_WITH_HC_128_MD5
wolfSSL 13:f67a6c6013ca 383 #endif
wolfSSL 13:f67a6c6013ca 384 #if !defined(NO_SHA)
wolfSSL 13:f67a6c6013ca 385 #define BUILD_TLS_RSA_WITH_HC_128_SHA
wolfSSL 13:f67a6c6013ca 386 #endif
wolfSSL 13:f67a6c6013ca 387 #if defined(HAVE_BLAKE2)
wolfSSL 13:f67a6c6013ca 388 #define BUILD_TLS_RSA_WITH_HC_128_B2B256
wolfSSL 13:f67a6c6013ca 389 #endif
wolfSSL 13:f67a6c6013ca 390 #endif
wolfSSL 13:f67a6c6013ca 391
wolfSSL 13:f67a6c6013ca 392 #if !defined(NO_RABBIT) && !defined(NO_TLS) && !defined(NO_RSA)
wolfSSL 13:f67a6c6013ca 393 #if !defined(NO_SHA)
wolfSSL 13:f67a6c6013ca 394 #define BUILD_TLS_RSA_WITH_RABBIT_SHA
wolfSSL 13:f67a6c6013ca 395 #endif
wolfSSL 13:f67a6c6013ca 396 #endif
wolfSSL 13:f67a6c6013ca 397 #endif
wolfSSL 13:f67a6c6013ca 398
wolfSSL 13:f67a6c6013ca 399 #if !defined(NO_DH) && !defined(NO_AES) && !defined(NO_TLS) && \
wolfSSL 13:f67a6c6013ca 400 !defined(NO_RSA)
wolfSSL 13:f67a6c6013ca 401
wolfSSL 13:f67a6c6013ca 402 #if !defined(NO_SHA)
wolfSSL 13:f67a6c6013ca 403 #define BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA
wolfSSL 13:f67a6c6013ca 404 #define BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA
wolfSSL 13:f67a6c6013ca 405 #if !defined(NO_DES3)
wolfSSL 13:f67a6c6013ca 406 #define BUILD_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
wolfSSL 13:f67a6c6013ca 407 #endif
wolfSSL 13:f67a6c6013ca 408 #endif
wolfSSL 13:f67a6c6013ca 409 #if !defined(NO_SHA256)
wolfSSL 13:f67a6c6013ca 410 #define BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
wolfSSL 13:f67a6c6013ca 411 #define BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
wolfSSL 13:f67a6c6013ca 412 #endif
wolfSSL 13:f67a6c6013ca 413 #endif
wolfSSL 13:f67a6c6013ca 414
wolfSSL 13:f67a6c6013ca 415 #if defined(HAVE_ANON) && !defined(NO_TLS) && !defined(NO_DH) && \
wolfSSL 13:f67a6c6013ca 416 !defined(NO_AES) && !defined(NO_SHA)
wolfSSL 13:f67a6c6013ca 417 #define BUILD_TLS_DH_anon_WITH_AES_128_CBC_SHA
wolfSSL 13:f67a6c6013ca 418 #endif
wolfSSL 13:f67a6c6013ca 419
wolfSSL 13:f67a6c6013ca 420 #if !defined(NO_DH) && !defined(NO_PSK) && !defined(NO_TLS)
wolfSSL 13:f67a6c6013ca 421 #ifndef NO_SHA256
wolfSSL 13:f67a6c6013ca 422 #ifndef NO_AES
wolfSSL 13:f67a6c6013ca 423 #define BUILD_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256
wolfSSL 13:f67a6c6013ca 424 #endif
wolfSSL 13:f67a6c6013ca 425 #ifdef HAVE_NULL_CIPHER
wolfSSL 13:f67a6c6013ca 426 #define BUILD_TLS_DHE_PSK_WITH_NULL_SHA256
wolfSSL 13:f67a6c6013ca 427 #endif
wolfSSL 13:f67a6c6013ca 428 #endif
wolfSSL 13:f67a6c6013ca 429 #ifdef WOLFSSL_SHA384
wolfSSL 13:f67a6c6013ca 430 #ifndef NO_AES
wolfSSL 13:f67a6c6013ca 431 #define BUILD_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384
wolfSSL 13:f67a6c6013ca 432 #endif
wolfSSL 13:f67a6c6013ca 433 #ifdef HAVE_NULL_CIPHER
wolfSSL 13:f67a6c6013ca 434 #define BUILD_TLS_DHE_PSK_WITH_NULL_SHA384
wolfSSL 13:f67a6c6013ca 435 #endif
wolfSSL 13:f67a6c6013ca 436 #endif
wolfSSL 13:f67a6c6013ca 437 #endif
wolfSSL 13:f67a6c6013ca 438
wolfSSL 13:f67a6c6013ca 439 #if defined(HAVE_ECC) && !defined(NO_TLS)
wolfSSL 13:f67a6c6013ca 440 #if !defined(NO_AES)
wolfSSL 13:f67a6c6013ca 441 #if !defined(NO_SHA)
wolfSSL 13:f67a6c6013ca 442 #if !defined(NO_RSA)
wolfSSL 13:f67a6c6013ca 443 #define BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
wolfSSL 13:f67a6c6013ca 444 #define BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
wolfSSL 13:f67a6c6013ca 445 #if defined(WOLFSSL_STATIC_DH)
wolfSSL 13:f67a6c6013ca 446 #define BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
wolfSSL 13:f67a6c6013ca 447 #define BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
wolfSSL 13:f67a6c6013ca 448 #endif
wolfSSL 13:f67a6c6013ca 449 #endif
wolfSSL 13:f67a6c6013ca 450
wolfSSL 13:f67a6c6013ca 451 #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
wolfSSL 13:f67a6c6013ca 452 #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
wolfSSL 13:f67a6c6013ca 453
wolfSSL 13:f67a6c6013ca 454 #if defined(WOLFSSL_STATIC_DH)
wolfSSL 13:f67a6c6013ca 455 #define BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
wolfSSL 13:f67a6c6013ca 456 #define BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
wolfSSL 13:f67a6c6013ca 457 #endif
wolfSSL 13:f67a6c6013ca 458 #endif /* NO_SHA */
wolfSSL 13:f67a6c6013ca 459 #ifndef NO_SHA256
wolfSSL 13:f67a6c6013ca 460 #if !defined(NO_RSA)
wolfSSL 13:f67a6c6013ca 461 #define BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
wolfSSL 13:f67a6c6013ca 462 #if defined(WOLFSSL_STATIC_DH)
wolfSSL 13:f67a6c6013ca 463 #define BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
wolfSSL 13:f67a6c6013ca 464 #endif
wolfSSL 13:f67a6c6013ca 465 #endif
wolfSSL 13:f67a6c6013ca 466 #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
wolfSSL 13:f67a6c6013ca 467 #if defined(WOLFSSL_STATIC_DH)
wolfSSL 13:f67a6c6013ca 468 #define BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
wolfSSL 13:f67a6c6013ca 469 #endif
wolfSSL 13:f67a6c6013ca 470 #endif
wolfSSL 13:f67a6c6013ca 471
wolfSSL 13:f67a6c6013ca 472 #ifdef WOLFSSL_SHA384
wolfSSL 13:f67a6c6013ca 473 #if !defined(NO_RSA)
wolfSSL 13:f67a6c6013ca 474 #define BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
wolfSSL 13:f67a6c6013ca 475 #if defined(WOLFSSL_STATIC_DH)
wolfSSL 13:f67a6c6013ca 476 #define BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
wolfSSL 13:f67a6c6013ca 477 #endif
wolfSSL 13:f67a6c6013ca 478 #endif
wolfSSL 13:f67a6c6013ca 479 #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
wolfSSL 13:f67a6c6013ca 480 #if defined(WOLFSSL_STATIC_DH)
wolfSSL 13:f67a6c6013ca 481 #define BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
wolfSSL 13:f67a6c6013ca 482 #endif
wolfSSL 13:f67a6c6013ca 483 #endif
wolfSSL 13:f67a6c6013ca 484
wolfSSL 13:f67a6c6013ca 485 #if defined (HAVE_AESGCM)
wolfSSL 13:f67a6c6013ca 486 #if !defined(NO_RSA)
wolfSSL 13:f67a6c6013ca 487 #if defined(WOLFSSL_STATIC_DH)
wolfSSL 13:f67a6c6013ca 488 #define BUILD_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
wolfSSL 13:f67a6c6013ca 489 #endif
wolfSSL 13:f67a6c6013ca 490 #if defined(WOLFSSL_SHA384)
wolfSSL 13:f67a6c6013ca 491 #if defined(WOLFSSL_STATIC_DH)
wolfSSL 13:f67a6c6013ca 492 #define BUILD_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
wolfSSL 13:f67a6c6013ca 493 #endif
wolfSSL 13:f67a6c6013ca 494 #endif
wolfSSL 13:f67a6c6013ca 495 #endif
wolfSSL 13:f67a6c6013ca 496
wolfSSL 13:f67a6c6013ca 497 #if defined(WOLFSSL_STATIC_DH)
wolfSSL 13:f67a6c6013ca 498 #define BUILD_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256
wolfSSL 13:f67a6c6013ca 499 #endif
wolfSSL 13:f67a6c6013ca 500
wolfSSL 13:f67a6c6013ca 501 #if defined(WOLFSSL_SHA384)
wolfSSL 13:f67a6c6013ca 502 #if defined(WOLFSSL_STATIC_DH)
wolfSSL 13:f67a6c6013ca 503 #define BUILD_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
wolfSSL 13:f67a6c6013ca 504 #endif
wolfSSL 13:f67a6c6013ca 505 #endif
wolfSSL 13:f67a6c6013ca 506 #endif
wolfSSL 13:f67a6c6013ca 507 #endif /* NO_AES */
wolfSSL 13:f67a6c6013ca 508 #if !defined(NO_RC4)
wolfSSL 13:f67a6c6013ca 509 #if !defined(NO_SHA)
wolfSSL 13:f67a6c6013ca 510 #if !defined(NO_RSA)
wolfSSL 13:f67a6c6013ca 511 #define BUILD_TLS_ECDHE_RSA_WITH_RC4_128_SHA
wolfSSL 13:f67a6c6013ca 512 #if defined(WOLFSSL_STATIC_DH)
wolfSSL 13:f67a6c6013ca 513 #define BUILD_TLS_ECDH_RSA_WITH_RC4_128_SHA
wolfSSL 13:f67a6c6013ca 514 #endif
wolfSSL 13:f67a6c6013ca 515 #endif
wolfSSL 13:f67a6c6013ca 516
wolfSSL 13:f67a6c6013ca 517 #define BUILD_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
wolfSSL 13:f67a6c6013ca 518 #if defined(WOLFSSL_STATIC_DH)
wolfSSL 13:f67a6c6013ca 519 #define BUILD_TLS_ECDH_ECDSA_WITH_RC4_128_SHA
wolfSSL 13:f67a6c6013ca 520 #endif
wolfSSL 13:f67a6c6013ca 521 #endif
wolfSSL 13:f67a6c6013ca 522 #endif
wolfSSL 13:f67a6c6013ca 523 #if !defined(NO_DES3)
wolfSSL 13:f67a6c6013ca 524 #ifndef NO_SHA
wolfSSL 13:f67a6c6013ca 525 #if !defined(NO_RSA)
wolfSSL 13:f67a6c6013ca 526 #define BUILD_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
wolfSSL 13:f67a6c6013ca 527 #if defined(WOLFSSL_STATIC_DH)
wolfSSL 13:f67a6c6013ca 528 #define BUILD_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
wolfSSL 13:f67a6c6013ca 529 #endif
wolfSSL 13:f67a6c6013ca 530 #endif
wolfSSL 13:f67a6c6013ca 531
wolfSSL 13:f67a6c6013ca 532 #define BUILD_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
wolfSSL 13:f67a6c6013ca 533 #if defined(WOLFSSL_STATIC_DH)
wolfSSL 13:f67a6c6013ca 534 #define BUILD_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
wolfSSL 13:f67a6c6013ca 535 #endif
wolfSSL 13:f67a6c6013ca 536 #endif /* NO_SHA */
wolfSSL 13:f67a6c6013ca 537 #endif
wolfSSL 13:f67a6c6013ca 538 #if defined(HAVE_NULL_CIPHER)
wolfSSL 13:f67a6c6013ca 539 #if !defined(NO_SHA)
wolfSSL 13:f67a6c6013ca 540 #define BUILD_TLS_ECDHE_ECDSA_WITH_NULL_SHA
wolfSSL 13:f67a6c6013ca 541 #endif
wolfSSL 13:f67a6c6013ca 542 #if !defined(NO_PSK) && !defined(NO_SHA256)
wolfSSL 13:f67a6c6013ca 543 #define BUILD_TLS_ECDHE_PSK_WITH_NULL_SHA256
wolfSSL 13:f67a6c6013ca 544 #endif
wolfSSL 13:f67a6c6013ca 545 #endif
wolfSSL 13:f67a6c6013ca 546 #if !defined(NO_PSK) && !defined(NO_SHA256) && !defined(NO_AES)
wolfSSL 13:f67a6c6013ca 547 #define BUILD_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
wolfSSL 13:f67a6c6013ca 548 #endif
wolfSSL 13:f67a6c6013ca 549 #endif
wolfSSL 13:f67a6c6013ca 550 #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(NO_SHA256)
wolfSSL 13:f67a6c6013ca 551 #if !defined(NO_OLD_POLY1305)
wolfSSL 13:f67a6c6013ca 552 #ifdef HAVE_ECC
wolfSSL 13:f67a6c6013ca 553 #define BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_OLD_POLY1305_SHA256
wolfSSL 13:f67a6c6013ca 554 #ifndef NO_RSA
wolfSSL 13:f67a6c6013ca 555 #define BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256
wolfSSL 13:f67a6c6013ca 556 #endif
wolfSSL 13:f67a6c6013ca 557 #endif
wolfSSL 13:f67a6c6013ca 558 #if !defined(NO_DH) && !defined(NO_RSA)
wolfSSL 13:f67a6c6013ca 559 #define BUILD_TLS_DHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256
wolfSSL 13:f67a6c6013ca 560 #endif
wolfSSL 13:f67a6c6013ca 561 #endif /* NO_OLD_POLY1305 */
wolfSSL 13:f67a6c6013ca 562 #if !defined(NO_PSK)
wolfSSL 13:f67a6c6013ca 563 #define BUILD_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256
wolfSSL 13:f67a6c6013ca 564 #ifdef HAVE_ECC
wolfSSL 13:f67a6c6013ca 565 #define BUILD_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256
wolfSSL 13:f67a6c6013ca 566 #endif
wolfSSL 13:f67a6c6013ca 567 #ifndef NO_DH
wolfSSL 13:f67a6c6013ca 568 #define BUILD_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256
wolfSSL 13:f67a6c6013ca 569 #endif
wolfSSL 13:f67a6c6013ca 570 #endif /* !NO_PSK */
wolfSSL 13:f67a6c6013ca 571 #endif
wolfSSL 13:f67a6c6013ca 572
wolfSSL 13:f67a6c6013ca 573 #endif /* !WOLFSSL_MAX_STRENGTH */
wolfSSL 13:f67a6c6013ca 574
wolfSSL 13:f67a6c6013ca 575 #if !defined(NO_DH) && !defined(NO_AES) && !defined(NO_TLS) && \
wolfSSL 13:f67a6c6013ca 576 !defined(NO_RSA) && defined(HAVE_AESGCM)
wolfSSL 13:f67a6c6013ca 577
wolfSSL 13:f67a6c6013ca 578 #ifndef NO_SHA256
wolfSSL 13:f67a6c6013ca 579 #define BUILD_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
wolfSSL 13:f67a6c6013ca 580 #endif
wolfSSL 13:f67a6c6013ca 581
wolfSSL 13:f67a6c6013ca 582 #ifdef WOLFSSL_SHA384
wolfSSL 13:f67a6c6013ca 583 #define BUILD_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
wolfSSL 13:f67a6c6013ca 584 #endif
wolfSSL 13:f67a6c6013ca 585 #endif
wolfSSL 13:f67a6c6013ca 586
wolfSSL 13:f67a6c6013ca 587 #if !defined(NO_DH) && !defined(NO_PSK) && !defined(NO_TLS)
wolfSSL 13:f67a6c6013ca 588 #ifndef NO_SHA256
wolfSSL 13:f67a6c6013ca 589 #ifdef HAVE_AESGCM
wolfSSL 13:f67a6c6013ca 590 #define BUILD_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256
wolfSSL 13:f67a6c6013ca 591 #endif
wolfSSL 13:f67a6c6013ca 592 #ifdef HAVE_AESCCM
wolfSSL 13:f67a6c6013ca 593 #define BUILD_TLS_DHE_PSK_WITH_AES_128_CCM
wolfSSL 13:f67a6c6013ca 594 #define BUILD_TLS_DHE_PSK_WITH_AES_256_CCM
wolfSSL 13:f67a6c6013ca 595 #endif
wolfSSL 13:f67a6c6013ca 596 #endif
wolfSSL 13:f67a6c6013ca 597 #if defined(WOLFSSL_SHA384) && defined(HAVE_AESGCM)
wolfSSL 13:f67a6c6013ca 598 #define BUILD_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384
wolfSSL 13:f67a6c6013ca 599 #endif
wolfSSL 13:f67a6c6013ca 600 #endif
wolfSSL 13:f67a6c6013ca 601
wolfSSL 13:f67a6c6013ca 602 #if defined(HAVE_ECC) && !defined(NO_TLS) && !defined(NO_AES)
wolfSSL 13:f67a6c6013ca 603 #ifdef HAVE_AESGCM
wolfSSL 13:f67a6c6013ca 604 #ifndef NO_SHA256
wolfSSL 13:f67a6c6013ca 605 #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
wolfSSL 13:f67a6c6013ca 606 #ifndef NO_RSA
wolfSSL 13:f67a6c6013ca 607 #define BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
wolfSSL 13:f67a6c6013ca 608 #endif
wolfSSL 13:f67a6c6013ca 609 #endif
wolfSSL 13:f67a6c6013ca 610 #ifdef WOLFSSL_SHA384
wolfSSL 13:f67a6c6013ca 611 #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
wolfSSL 13:f67a6c6013ca 612 #ifndef NO_RSA
wolfSSL 13:f67a6c6013ca 613 #define BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
wolfSSL 13:f67a6c6013ca 614 #endif
wolfSSL 13:f67a6c6013ca 615 #endif
wolfSSL 13:f67a6c6013ca 616 #endif
wolfSSL 13:f67a6c6013ca 617 #if defined(HAVE_AESCCM) && !defined(NO_SHA256)
wolfSSL 13:f67a6c6013ca 618 #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CCM
wolfSSL 13:f67a6c6013ca 619 #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
wolfSSL 13:f67a6c6013ca 620 #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8
wolfSSL 13:f67a6c6013ca 621 #endif
wolfSSL 13:f67a6c6013ca 622 #endif
wolfSSL 13:f67a6c6013ca 623
wolfSSL 13:f67a6c6013ca 624 #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(NO_SHA256)
wolfSSL 13:f67a6c6013ca 625 #ifdef HAVE_ECC
wolfSSL 13:f67a6c6013ca 626 #define BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
wolfSSL 13:f67a6c6013ca 627 #ifndef NO_RSA
wolfSSL 13:f67a6c6013ca 628 #define BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256
wolfSSL 13:f67a6c6013ca 629 #endif
wolfSSL 13:f67a6c6013ca 630 #endif
wolfSSL 13:f67a6c6013ca 631 #if !defined(NO_DH) && !defined(NO_RSA)
wolfSSL 13:f67a6c6013ca 632 #define BUILD_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256
wolfSSL 13:f67a6c6013ca 633 #endif
wolfSSL 13:f67a6c6013ca 634 #endif
wolfSSL 13:f67a6c6013ca 635
wolfSSL 13:f67a6c6013ca 636 #if defined(WOLFSSL_TLS13)
wolfSSL 13:f67a6c6013ca 637 #ifdef HAVE_AESGCM
wolfSSL 13:f67a6c6013ca 638 #ifndef NO_SHA256
wolfSSL 13:f67a6c6013ca 639 #define BUILD_TLS_AES_128_GCM_SHA256
wolfSSL 13:f67a6c6013ca 640 #endif
wolfSSL 13:f67a6c6013ca 641 #ifdef WOLFSSL_SHA384
wolfSSL 13:f67a6c6013ca 642 #define BUILD_TLS_AES_256_GCM_SHA384
wolfSSL 13:f67a6c6013ca 643 #endif
wolfSSL 13:f67a6c6013ca 644 #endif
wolfSSL 13:f67a6c6013ca 645
wolfSSL 13:f67a6c6013ca 646 #ifdef HAVE_CHACHA
wolfSSL 13:f67a6c6013ca 647 #ifndef NO_SHA256
wolfSSL 13:f67a6c6013ca 648 #define BUILD_TLS_CHACHA20_POLY1305_SHA256
wolfSSL 13:f67a6c6013ca 649 #endif
wolfSSL 13:f67a6c6013ca 650 #endif
wolfSSL 13:f67a6c6013ca 651
wolfSSL 13:f67a6c6013ca 652 #ifdef HAVE_AESCCM
wolfSSL 13:f67a6c6013ca 653 #ifndef NO_SHA256
wolfSSL 13:f67a6c6013ca 654 #define BUILD_TLS_AES_128_CCM_SHA256
wolfSSL 13:f67a6c6013ca 655 #define BUILD_TLS_AES_128_CCM_8_SHA256
wolfSSL 13:f67a6c6013ca 656 #endif
wolfSSL 13:f67a6c6013ca 657 #endif
wolfSSL 13:f67a6c6013ca 658 #endif
wolfSSL 13:f67a6c6013ca 659
wolfSSL 13:f67a6c6013ca 660 #ifdef WOLFSSL_MULTICAST
wolfSSL 13:f67a6c6013ca 661 #if defined(HAVE_NULL_CIPHER) && !defined(NO_SHA256)
wolfSSL 13:f67a6c6013ca 662 #define BUILD_WDM_WITH_NULL_SHA256
wolfSSL 13:f67a6c6013ca 663 #endif
wolfSSL 13:f67a6c6013ca 664 #endif
wolfSSL 13:f67a6c6013ca 665
wolfSSL 13:f67a6c6013ca 666 #if defined(BUILD_SSL_RSA_WITH_RC4_128_SHA) || \
wolfSSL 13:f67a6c6013ca 667 defined(BUILD_SSL_RSA_WITH_RC4_128_MD5)
wolfSSL 13:f67a6c6013ca 668 #define BUILD_ARC4
wolfSSL 13:f67a6c6013ca 669 #endif
wolfSSL 13:f67a6c6013ca 670
wolfSSL 13:f67a6c6013ca 671 #if defined(BUILD_SSL_RSA_WITH_3DES_EDE_CBC_SHA)
wolfSSL 13:f67a6c6013ca 672 #define BUILD_DES3
wolfSSL 13:f67a6c6013ca 673 #endif
wolfSSL 13:f67a6c6013ca 674
wolfSSL 13:f67a6c6013ca 675 #if defined(BUILD_TLS_RSA_WITH_AES_128_CBC_SHA) || \
wolfSSL 13:f67a6c6013ca 676 defined(BUILD_TLS_RSA_WITH_AES_256_CBC_SHA) || \
wolfSSL 13:f67a6c6013ca 677 defined(BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256) || \
wolfSSL 13:f67a6c6013ca 678 defined(BUILD_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256)
wolfSSL 13:f67a6c6013ca 679 #undef BUILD_AES
wolfSSL 13:f67a6c6013ca 680 #define BUILD_AES
wolfSSL 13:f67a6c6013ca 681 #endif
wolfSSL 13:f67a6c6013ca 682
wolfSSL 13:f67a6c6013ca 683 #if defined(BUILD_TLS_RSA_WITH_AES_128_GCM_SHA256) || \
wolfSSL 13:f67a6c6013ca 684 defined(BUILD_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256) || \
wolfSSL 13:f67a6c6013ca 685 defined(BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256) || \
wolfSSL 13:f67a6c6013ca 686 defined(BUILD_TLS_PSK_WITH_AES_128_GCM_SHA256) || \
wolfSSL 13:f67a6c6013ca 687 defined(BUILD_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256) || \
wolfSSL 13:f67a6c6013ca 688 defined(BUILD_TLS_RSA_WITH_AES_256_GCM_SHA384) || \
wolfSSL 13:f67a6c6013ca 689 defined(BUILD_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384) || \
wolfSSL 13:f67a6c6013ca 690 defined(BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384) || \
wolfSSL 13:f67a6c6013ca 691 defined(BUILD_TLS_PSK_WITH_AES_256_GCM_SHA384) || \
wolfSSL 13:f67a6c6013ca 692 defined(BUILD_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384)
wolfSSL 13:f67a6c6013ca 693 #define BUILD_AESGCM
wolfSSL 13:f67a6c6013ca 694 #endif
wolfSSL 13:f67a6c6013ca 695
wolfSSL 13:f67a6c6013ca 696 #if defined(BUILD_TLS_RSA_WITH_HC_128_SHA) || \
wolfSSL 13:f67a6c6013ca 697 defined(BUILD_TLS_RSA_WITH_HC_128_MD5) || \
wolfSSL 13:f67a6c6013ca 698 defined(BUILD_TLS_RSA_WITH_HC_128_B2B256)
wolfSSL 13:f67a6c6013ca 699 #define BUILD_HC128
wolfSSL 13:f67a6c6013ca 700 #endif
wolfSSL 13:f67a6c6013ca 701
wolfSSL 13:f67a6c6013ca 702 #if defined(BUILD_TLS_RSA_WITH_RABBIT_SHA)
wolfSSL 13:f67a6c6013ca 703 #define BUILD_RABBIT
wolfSSL 13:f67a6c6013ca 704 #endif
wolfSSL 13:f67a6c6013ca 705
wolfSSL 13:f67a6c6013ca 706 #ifdef NO_DES3
wolfSSL 13:f67a6c6013ca 707 #define DES_BLOCK_SIZE 8
wolfSSL 13:f67a6c6013ca 708 #else
wolfSSL 13:f67a6c6013ca 709 #undef BUILD_DES3
wolfSSL 13:f67a6c6013ca 710 #define BUILD_DES3
wolfSSL 13:f67a6c6013ca 711 #endif
wolfSSL 13:f67a6c6013ca 712
wolfSSL 13:f67a6c6013ca 713 #if defined(NO_AES) || defined(NO_AES_DECRYPT)
wolfSSL 13:f67a6c6013ca 714 #define AES_BLOCK_SIZE 16
wolfSSL 13:f67a6c6013ca 715 #undef BUILD_AES
wolfSSL 13:f67a6c6013ca 716 #else
wolfSSL 13:f67a6c6013ca 717 #undef BUILD_AES
wolfSSL 13:f67a6c6013ca 718 #define BUILD_AES
wolfSSL 13:f67a6c6013ca 719 #endif
wolfSSL 13:f67a6c6013ca 720
wolfSSL 13:f67a6c6013ca 721 #ifndef NO_RC4
wolfSSL 13:f67a6c6013ca 722 #undef BUILD_ARC4
wolfSSL 13:f67a6c6013ca 723 #define BUILD_ARC4
wolfSSL 13:f67a6c6013ca 724 #endif
wolfSSL 13:f67a6c6013ca 725
wolfSSL 13:f67a6c6013ca 726 #ifdef HAVE_CHACHA
wolfSSL 13:f67a6c6013ca 727 #define CHACHA20_BLOCK_SIZE 16
wolfSSL 13:f67a6c6013ca 728 #endif
wolfSSL 13:f67a6c6013ca 729
wolfSSL 13:f67a6c6013ca 730 #if defined(WOLFSSL_MAX_STRENGTH) || \
wolfSSL 13:f67a6c6013ca 731 defined(HAVE_AESGCM) || defined(HAVE_AESCCM) || \
wolfSSL 13:f67a6c6013ca 732 (defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
wolfSSL 13:f67a6c6013ca 733
wolfSSL 13:f67a6c6013ca 734 #define HAVE_AEAD
wolfSSL 13:f67a6c6013ca 735 #endif
wolfSSL 13:f67a6c6013ca 736
wolfSSL 13:f67a6c6013ca 737 #if defined(WOLFSSL_MAX_STRENGTH) || \
wolfSSL 13:f67a6c6013ca 738 defined(HAVE_ECC) || !defined(NO_DH)
wolfSSL 13:f67a6c6013ca 739
wolfSSL 13:f67a6c6013ca 740 #define HAVE_PFS
wolfSSL 13:f67a6c6013ca 741 #endif
wolfSSL 13:f67a6c6013ca 742
wolfSSL 13:f67a6c6013ca 743 #if defined(BUILD_SSL_RSA_WITH_IDEA_CBC_SHA)
wolfSSL 13:f67a6c6013ca 744 #define BUILD_IDEA
wolfSSL 13:f67a6c6013ca 745 #endif
wolfSSL 13:f67a6c6013ca 746
wolfSSL 13:f67a6c6013ca 747 /* actual cipher values, 2nd byte */
wolfSSL 13:f67a6c6013ca 748 enum {
wolfSSL 13:f67a6c6013ca 749 TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA = 0x16,
wolfSSL 13:f67a6c6013ca 750 TLS_DHE_RSA_WITH_AES_256_CBC_SHA = 0x39,
wolfSSL 13:f67a6c6013ca 751 TLS_DHE_RSA_WITH_AES_128_CBC_SHA = 0x33,
wolfSSL 13:f67a6c6013ca 752 TLS_DH_anon_WITH_AES_128_CBC_SHA = 0x34,
wolfSSL 13:f67a6c6013ca 753 TLS_RSA_WITH_AES_256_CBC_SHA = 0x35,
wolfSSL 13:f67a6c6013ca 754 TLS_RSA_WITH_AES_128_CBC_SHA = 0x2F,
wolfSSL 13:f67a6c6013ca 755 TLS_RSA_WITH_NULL_SHA = 0x02,
wolfSSL 13:f67a6c6013ca 756 TLS_PSK_WITH_AES_256_CBC_SHA = 0x8d,
wolfSSL 13:f67a6c6013ca 757 TLS_PSK_WITH_AES_128_CBC_SHA256 = 0xae,
wolfSSL 13:f67a6c6013ca 758 TLS_PSK_WITH_AES_256_CBC_SHA384 = 0xaf,
wolfSSL 13:f67a6c6013ca 759 TLS_PSK_WITH_AES_128_CBC_SHA = 0x8c,
wolfSSL 13:f67a6c6013ca 760 TLS_PSK_WITH_NULL_SHA256 = 0xb0,
wolfSSL 13:f67a6c6013ca 761 TLS_PSK_WITH_NULL_SHA384 = 0xb1,
wolfSSL 13:f67a6c6013ca 762 TLS_PSK_WITH_NULL_SHA = 0x2c,
wolfSSL 13:f67a6c6013ca 763 SSL_RSA_WITH_RC4_128_SHA = 0x05,
wolfSSL 13:f67a6c6013ca 764 SSL_RSA_WITH_RC4_128_MD5 = 0x04,
wolfSSL 13:f67a6c6013ca 765 SSL_RSA_WITH_3DES_EDE_CBC_SHA = 0x0A,
wolfSSL 13:f67a6c6013ca 766 SSL_RSA_WITH_IDEA_CBC_SHA = 0x07,
wolfSSL 13:f67a6c6013ca 767
wolfSSL 13:f67a6c6013ca 768 /* ECC suites, first byte is 0xC0 (ECC_BYTE) */
wolfSSL 13:f67a6c6013ca 769 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = 0x14,
wolfSSL 13:f67a6c6013ca 770 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA = 0x13,
wolfSSL 13:f67a6c6013ca 771 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA = 0x0A,
wolfSSL 13:f67a6c6013ca 772 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA = 0x09,
wolfSSL 13:f67a6c6013ca 773 TLS_ECDHE_RSA_WITH_RC4_128_SHA = 0x11,
wolfSSL 13:f67a6c6013ca 774 TLS_ECDHE_ECDSA_WITH_RC4_128_SHA = 0x07,
wolfSSL 13:f67a6c6013ca 775 TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA = 0x12,
wolfSSL 13:f67a6c6013ca 776 TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA = 0x08,
wolfSSL 13:f67a6c6013ca 777 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 = 0x27,
wolfSSL 13:f67a6c6013ca 778 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 = 0x23,
wolfSSL 13:f67a6c6013ca 779 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 = 0x28,
wolfSSL 13:f67a6c6013ca 780 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 = 0x24,
wolfSSL 13:f67a6c6013ca 781 TLS_ECDHE_ECDSA_WITH_NULL_SHA = 0x06,
wolfSSL 13:f67a6c6013ca 782 TLS_ECDHE_PSK_WITH_NULL_SHA256 = 0x3a,
wolfSSL 13:f67a6c6013ca 783 TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 = 0x37,
wolfSSL 13:f67a6c6013ca 784
wolfSSL 13:f67a6c6013ca 785 /* static ECDH, first byte is 0xC0 (ECC_BYTE) */
wolfSSL 13:f67a6c6013ca 786 TLS_ECDH_RSA_WITH_AES_256_CBC_SHA = 0x0F,
wolfSSL 13:f67a6c6013ca 787 TLS_ECDH_RSA_WITH_AES_128_CBC_SHA = 0x0E,
wolfSSL 13:f67a6c6013ca 788 TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA = 0x05,
wolfSSL 13:f67a6c6013ca 789 TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA = 0x04,
wolfSSL 13:f67a6c6013ca 790 TLS_ECDH_RSA_WITH_RC4_128_SHA = 0x0C,
wolfSSL 13:f67a6c6013ca 791 TLS_ECDH_ECDSA_WITH_RC4_128_SHA = 0x02,
wolfSSL 13:f67a6c6013ca 792 TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA = 0x0D,
wolfSSL 13:f67a6c6013ca 793 TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA = 0x03,
wolfSSL 13:f67a6c6013ca 794 TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 = 0x29,
wolfSSL 13:f67a6c6013ca 795 TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 = 0x25,
wolfSSL 13:f67a6c6013ca 796 TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 = 0x2A,
wolfSSL 13:f67a6c6013ca 797 TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 = 0x26,
wolfSSL 13:f67a6c6013ca 798
wolfSSL 13:f67a6c6013ca 799 /* wolfSSL extension - eSTREAM */
wolfSSL 13:f67a6c6013ca 800 TLS_RSA_WITH_HC_128_MD5 = 0xFB,
wolfSSL 13:f67a6c6013ca 801 TLS_RSA_WITH_HC_128_SHA = 0xFC,
wolfSSL 13:f67a6c6013ca 802 TLS_RSA_WITH_RABBIT_SHA = 0xFD,
wolfSSL 13:f67a6c6013ca 803 WDM_WITH_NULL_SHA256 = 0xFE, /* wolfSSL DTLS Multicast */
wolfSSL 13:f67a6c6013ca 804
wolfSSL 13:f67a6c6013ca 805 /* wolfSSL extension - Blake2b 256 */
wolfSSL 13:f67a6c6013ca 806 TLS_RSA_WITH_AES_128_CBC_B2B256 = 0xF8,
wolfSSL 13:f67a6c6013ca 807 TLS_RSA_WITH_AES_256_CBC_B2B256 = 0xF9,
wolfSSL 13:f67a6c6013ca 808 TLS_RSA_WITH_HC_128_B2B256 = 0xFA, /* eSTREAM too */
wolfSSL 13:f67a6c6013ca 809
wolfSSL 13:f67a6c6013ca 810 /* wolfSSL extension - NTRU */
wolfSSL 13:f67a6c6013ca 811 TLS_NTRU_RSA_WITH_RC4_128_SHA = 0xe5,
wolfSSL 13:f67a6c6013ca 812 TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA = 0xe6,
wolfSSL 13:f67a6c6013ca 813 TLS_NTRU_RSA_WITH_AES_128_CBC_SHA = 0xe7, /* clashes w/official SHA-256 */
wolfSSL 13:f67a6c6013ca 814 TLS_NTRU_RSA_WITH_AES_256_CBC_SHA = 0xe8,
wolfSSL 13:f67a6c6013ca 815
wolfSSL 13:f67a6c6013ca 816 /* wolfSSL extension - NTRU , Quantum-safe Handshake
wolfSSL 13:f67a6c6013ca 817 first byte is 0xD0 (QSH_BYTE) */
wolfSSL 13:f67a6c6013ca 818 TLS_QSH = 0x01,
wolfSSL 13:f67a6c6013ca 819
wolfSSL 13:f67a6c6013ca 820 /* SHA256 */
wolfSSL 13:f67a6c6013ca 821 TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 = 0x6b,
wolfSSL 13:f67a6c6013ca 822 TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 = 0x67,
wolfSSL 13:f67a6c6013ca 823 TLS_RSA_WITH_AES_256_CBC_SHA256 = 0x3d,
wolfSSL 13:f67a6c6013ca 824 TLS_RSA_WITH_AES_128_CBC_SHA256 = 0x3c,
wolfSSL 13:f67a6c6013ca 825 TLS_RSA_WITH_NULL_SHA256 = 0x3b,
wolfSSL 13:f67a6c6013ca 826 TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 = 0xb2,
wolfSSL 13:f67a6c6013ca 827 TLS_DHE_PSK_WITH_NULL_SHA256 = 0xb4,
wolfSSL 13:f67a6c6013ca 828
wolfSSL 13:f67a6c6013ca 829 /* SHA384 */
wolfSSL 13:f67a6c6013ca 830 TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 = 0xb3,
wolfSSL 13:f67a6c6013ca 831 TLS_DHE_PSK_WITH_NULL_SHA384 = 0xb5,
wolfSSL 13:f67a6c6013ca 832
wolfSSL 13:f67a6c6013ca 833 /* AES-GCM */
wolfSSL 13:f67a6c6013ca 834 TLS_RSA_WITH_AES_128_GCM_SHA256 = 0x9c,
wolfSSL 13:f67a6c6013ca 835 TLS_RSA_WITH_AES_256_GCM_SHA384 = 0x9d,
wolfSSL 13:f67a6c6013ca 836 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 = 0x9e,
wolfSSL 13:f67a6c6013ca 837 TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 = 0x9f,
wolfSSL 13:f67a6c6013ca 838 TLS_PSK_WITH_AES_128_GCM_SHA256 = 0xa8,
wolfSSL 13:f67a6c6013ca 839 TLS_PSK_WITH_AES_256_GCM_SHA384 = 0xa9,
wolfSSL 13:f67a6c6013ca 840 TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 = 0xaa,
wolfSSL 13:f67a6c6013ca 841 TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 = 0xab,
wolfSSL 13:f67a6c6013ca 842
wolfSSL 13:f67a6c6013ca 843 /* ECC AES-GCM, first byte is 0xC0 (ECC_BYTE) */
wolfSSL 13:f67a6c6013ca 844 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 = 0x2b,
wolfSSL 13:f67a6c6013ca 845 TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 = 0x2c,
wolfSSL 13:f67a6c6013ca 846 TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 = 0x2d,
wolfSSL 13:f67a6c6013ca 847 TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 = 0x2e,
wolfSSL 13:f67a6c6013ca 848 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 = 0x2f,
wolfSSL 13:f67a6c6013ca 849 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 = 0x30,
wolfSSL 13:f67a6c6013ca 850 TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 = 0x31,
wolfSSL 13:f67a6c6013ca 851 TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 = 0x32,
wolfSSL 13:f67a6c6013ca 852
wolfSSL 13:f67a6c6013ca 853 /* AES-CCM, first byte is 0xC0 but isn't ECC,
wolfSSL 13:f67a6c6013ca 854 * also, in some of the other AES-CCM suites
wolfSSL 13:f67a6c6013ca 855 * there will be second byte number conflicts
wolfSSL 13:f67a6c6013ca 856 * with non-ECC AES-GCM */
wolfSSL 13:f67a6c6013ca 857 TLS_RSA_WITH_AES_128_CCM_8 = 0xa0,
wolfSSL 13:f67a6c6013ca 858 TLS_RSA_WITH_AES_256_CCM_8 = 0xa1,
wolfSSL 13:f67a6c6013ca 859 TLS_ECDHE_ECDSA_WITH_AES_128_CCM = 0xac,
wolfSSL 13:f67a6c6013ca 860 TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 = 0xae,
wolfSSL 13:f67a6c6013ca 861 TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 = 0xaf,
wolfSSL 13:f67a6c6013ca 862 TLS_PSK_WITH_AES_128_CCM = 0xa4,
wolfSSL 13:f67a6c6013ca 863 TLS_PSK_WITH_AES_256_CCM = 0xa5,
wolfSSL 13:f67a6c6013ca 864 TLS_PSK_WITH_AES_128_CCM_8 = 0xa8,
wolfSSL 13:f67a6c6013ca 865 TLS_PSK_WITH_AES_256_CCM_8 = 0xa9,
wolfSSL 13:f67a6c6013ca 866 TLS_DHE_PSK_WITH_AES_128_CCM = 0xa6,
wolfSSL 13:f67a6c6013ca 867 TLS_DHE_PSK_WITH_AES_256_CCM = 0xa7,
wolfSSL 13:f67a6c6013ca 868
wolfSSL 13:f67a6c6013ca 869 /* Camellia */
wolfSSL 13:f67a6c6013ca 870 TLS_RSA_WITH_CAMELLIA_128_CBC_SHA = 0x41,
wolfSSL 13:f67a6c6013ca 871 TLS_RSA_WITH_CAMELLIA_256_CBC_SHA = 0x84,
wolfSSL 13:f67a6c6013ca 872 TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0xba,
wolfSSL 13:f67a6c6013ca 873 TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 = 0xc0,
wolfSSL 13:f67a6c6013ca 874 TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA = 0x45,
wolfSSL 13:f67a6c6013ca 875 TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA = 0x88,
wolfSSL 13:f67a6c6013ca 876 TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0xbe,
wolfSSL 13:f67a6c6013ca 877 TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 = 0xc4,
wolfSSL 13:f67a6c6013ca 878
wolfSSL 13:f67a6c6013ca 879 /* chacha20-poly1305 suites first byte is 0xCC (CHACHA_BYTE) */
wolfSSL 13:f67a6c6013ca 880 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = 0xa8,
wolfSSL 13:f67a6c6013ca 881 TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 = 0xa9,
wolfSSL 13:f67a6c6013ca 882 TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = 0xaa,
wolfSSL 13:f67a6c6013ca 883 TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 = 0xac,
wolfSSL 13:f67a6c6013ca 884 TLS_PSK_WITH_CHACHA20_POLY1305_SHA256 = 0xab,
wolfSSL 13:f67a6c6013ca 885 TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256 = 0xad,
wolfSSL 13:f67a6c6013ca 886
wolfSSL 13:f67a6c6013ca 887 /* chacha20-poly1305 earlier version of nonce and padding (CHACHA_BYTE) */
wolfSSL 13:f67a6c6013ca 888 TLS_ECDHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 = 0x13,
wolfSSL 13:f67a6c6013ca 889 TLS_ECDHE_ECDSA_WITH_CHACHA20_OLD_POLY1305_SHA256 = 0x14,
wolfSSL 13:f67a6c6013ca 890 TLS_DHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 = 0x15,
wolfSSL 13:f67a6c6013ca 891
wolfSSL 13:f67a6c6013ca 892 /* TLS v1.3 cipher suites */
wolfSSL 13:f67a6c6013ca 893 TLS_AES_128_GCM_SHA256 = 0x01,
wolfSSL 13:f67a6c6013ca 894 TLS_AES_256_GCM_SHA384 = 0x02,
wolfSSL 13:f67a6c6013ca 895 TLS_CHACHA20_POLY1305_SHA256 = 0x03,
wolfSSL 13:f67a6c6013ca 896 TLS_AES_128_CCM_SHA256 = 0x04,
wolfSSL 13:f67a6c6013ca 897 TLS_AES_128_CCM_8_SHA256 = 0x05,
wolfSSL 13:f67a6c6013ca 898
wolfSSL 13:f67a6c6013ca 899 /* Renegotiation Indication Extension Special Suite */
wolfSSL 13:f67a6c6013ca 900 TLS_EMPTY_RENEGOTIATION_INFO_SCSV = 0xff
wolfSSL 13:f67a6c6013ca 901 };
wolfSSL 13:f67a6c6013ca 902
wolfSSL 13:f67a6c6013ca 903
wolfSSL 13:f67a6c6013ca 904 #ifndef WOLFSSL_SESSION_TIMEOUT
wolfSSL 13:f67a6c6013ca 905 #define WOLFSSL_SESSION_TIMEOUT 500
wolfSSL 13:f67a6c6013ca 906 /* default session resumption cache timeout in seconds */
wolfSSL 13:f67a6c6013ca 907 #endif
wolfSSL 13:f67a6c6013ca 908
wolfSSL 13:f67a6c6013ca 909
wolfSSL 13:f67a6c6013ca 910 #ifndef WOLFSSL_DTLS_WINDOW_WORDS
wolfSSL 13:f67a6c6013ca 911 #define WOLFSSL_DTLS_WINDOW_WORDS 2
wolfSSL 13:f67a6c6013ca 912 #endif /* WOLFSSL_DTLS_WINDOW_WORDS */
wolfSSL 13:f67a6c6013ca 913 #define DTLS_WORD_BITS (sizeof(word32) * CHAR_BIT)
wolfSSL 13:f67a6c6013ca 914 #define DTLS_SEQ_BITS (WOLFSSL_DTLS_WINDOW_WORDS * DTLS_WORD_BITS)
wolfSSL 13:f67a6c6013ca 915 #define DTLS_SEQ_SZ (sizeof(word32) * WOLFSSL_DTLS_WINDOW_WORDS)
wolfSSL 13:f67a6c6013ca 916
wolfSSL 13:f67a6c6013ca 917 #ifndef WOLFSSL_MULTICAST
wolfSSL 13:f67a6c6013ca 918 #define WOLFSSL_DTLS_PEERSEQ_SZ 1
wolfSSL 13:f67a6c6013ca 919 #else
wolfSSL 13:f67a6c6013ca 920 #ifndef WOLFSSL_MULTICAST_PEERS
wolfSSL 13:f67a6c6013ca 921 /* max allowed multicast group peers */
wolfSSL 13:f67a6c6013ca 922 #define WOLFSSL_MULTICAST_PEERS 100
wolfSSL 13:f67a6c6013ca 923 #endif
wolfSSL 13:f67a6c6013ca 924 #define WOLFSSL_DTLS_PEERSEQ_SZ WOLFSSL_MULTICAST_PEERS
wolfSSL 13:f67a6c6013ca 925 #endif /* WOLFSSL_MULTICAST */
wolfSSL 13:f67a6c6013ca 926
wolfSSL 13:f67a6c6013ca 927 #ifndef WOLFSSL_MAX_MTU
wolfSSL 13:f67a6c6013ca 928 #define WOLFSSL_MAX_MTU 1500
wolfSSL 13:f67a6c6013ca 929 #endif /* WOLFSSL_MAX_MTU */
wolfSSL 13:f67a6c6013ca 930
wolfSSL 13:f67a6c6013ca 931
wolfSSL 13:f67a6c6013ca 932
wolfSSL 13:f67a6c6013ca 933 enum Misc {
wolfSSL 13:f67a6c6013ca 934 ECC_BYTE = 0xC0, /* ECC first cipher suite byte */
wolfSSL 13:f67a6c6013ca 935 QSH_BYTE = 0xD0, /* Quantum-safe Handshake cipher suite */
wolfSSL 13:f67a6c6013ca 936 CHACHA_BYTE = 0xCC, /* ChaCha first cipher suite */
wolfSSL 13:f67a6c6013ca 937 TLS13_BYTE = 0x13, /* TLS v1.3 first byte of cipher suite */
wolfSSL 13:f67a6c6013ca 938
wolfSSL 13:f67a6c6013ca 939 SEND_CERT = 1,
wolfSSL 13:f67a6c6013ca 940 SEND_BLANK_CERT = 2,
wolfSSL 13:f67a6c6013ca 941
wolfSSL 13:f67a6c6013ca 942 DTLS_MAJOR = 0xfe, /* DTLS major version number */
wolfSSL 13:f67a6c6013ca 943 DTLS_MINOR = 0xff, /* DTLS minor version number */
wolfSSL 13:f67a6c6013ca 944 DTLSv1_2_MINOR = 0xfd, /* DTLS minor version number */
wolfSSL 13:f67a6c6013ca 945 SSLv3_MAJOR = 3, /* SSLv3 and TLSv1+ major version number */
wolfSSL 13:f67a6c6013ca 946 SSLv3_MINOR = 0, /* TLSv1 minor version number */
wolfSSL 13:f67a6c6013ca 947 TLSv1_MINOR = 1, /* TLSv1 minor version number */
wolfSSL 13:f67a6c6013ca 948 TLSv1_1_MINOR = 2, /* TLSv1_1 minor version number */
wolfSSL 13:f67a6c6013ca 949 TLSv1_2_MINOR = 3, /* TLSv1_2 minor version number */
wolfSSL 13:f67a6c6013ca 950 TLSv1_3_MINOR = 4, /* TLSv1_3 minor version number */
wolfSSL 13:f67a6c6013ca 951 TLS_DRAFT_MAJOR = 0x7f, /* Draft TLS major version number */
wolfSSL 13:f67a6c6013ca 952 #ifdef WOLFSSL_TLS13_DRAFT_18
wolfSSL 13:f67a6c6013ca 953 TLS_DRAFT_MINOR = 0x12, /* Minor version number of TLS draft */
wolfSSL 13:f67a6c6013ca 954 #else
wolfSSL 13:f67a6c6013ca 955 TLS_DRAFT_MINOR = 0x14, /* Minor version number of TLS draft */
wolfSSL 13:f67a6c6013ca 956 #endif
wolfSSL 13:f67a6c6013ca 957 OLD_HELLO_ID = 0x01, /* SSLv2 Client Hello Indicator */
wolfSSL 13:f67a6c6013ca 958 INVALID_BYTE = 0xff, /* Used to initialize cipher specs values */
wolfSSL 13:f67a6c6013ca 959 NO_COMPRESSION = 0,
wolfSSL 13:f67a6c6013ca 960 ZLIB_COMPRESSION = 221, /* wolfSSL zlib compression */
wolfSSL 13:f67a6c6013ca 961 HELLO_EXT_SIG_ALGO = 13, /* ID for the sig_algo hello extension */
wolfSSL 13:f67a6c6013ca 962 HELLO_EXT_EXTMS = 0x0017, /* ID for the extended master secret ext */
wolfSSL 13:f67a6c6013ca 963 SECRET_LEN = 48, /* pre RSA and all master */
wolfSSL 13:f67a6c6013ca 964 #if defined(WOLFSSL_MYSQL_COMPATIBLE)
wolfSSL 13:f67a6c6013ca 965 ENCRYPT_LEN = 1024, /* allow larger static buffer with mysql */
wolfSSL 13:f67a6c6013ca 966 #else
wolfSSL 13:f67a6c6013ca 967 ENCRYPT_LEN = 512, /* allow 4096 bit static buffer */
wolfSSL 13:f67a6c6013ca 968 #endif
wolfSSL 13:f67a6c6013ca 969 SIZEOF_SENDER = 4, /* clnt or srvr */
wolfSSL 13:f67a6c6013ca 970 FINISHED_SZ = 36, /* MD5_DIGEST_SIZE + SHA_DIGEST_SIZE */
wolfSSL 13:f67a6c6013ca 971 MAX_RECORD_SIZE = 16384, /* 2^14, max size by standard */
wolfSSL 13:f67a6c6013ca 972 MAX_MSG_EXTRA = 38 + MAX_DIGEST_SIZE,
wolfSSL 13:f67a6c6013ca 973 /* max added to msg, mac + pad from */
wolfSSL 13:f67a6c6013ca 974 /* RECORD_HEADER_SZ + BLOCK_SZ (pad) + Max
wolfSSL 13:f67a6c6013ca 975 digest sz + BLOC_SZ (iv) + pad byte (1) */
wolfSSL 13:f67a6c6013ca 976 MAX_COMP_EXTRA = 1024, /* max compression extra */
wolfSSL 13:f67a6c6013ca 977 MAX_MTU = WOLFSSL_MAX_MTU, /* max expected MTU */
wolfSSL 13:f67a6c6013ca 978 MAX_UDP_SIZE = 8192 - 100, /* was MAX_MTU - 100 */
wolfSSL 13:f67a6c6013ca 979 MAX_DH_SZ = 1036, /* 4096 p, pub, g + 2 byte size for each */
wolfSSL 13:f67a6c6013ca 980 MAX_STR_VERSION = 8, /* string rep of protocol version */
wolfSSL 13:f67a6c6013ca 981
wolfSSL 13:f67a6c6013ca 982 PAD_MD5 = 48, /* pad length for finished */
wolfSSL 13:f67a6c6013ca 983 PAD_SHA = 40, /* pad length for finished */
wolfSSL 13:f67a6c6013ca 984 MAX_PAD_SIZE = 256, /* maximum length of padding */
wolfSSL 13:f67a6c6013ca 985 COMPRESS_DUMMY_SIZE = 64, /* compression dummy round size */
wolfSSL 13:f67a6c6013ca 986 COMPRESS_CONSTANT = 13, /* compression calc constant */
wolfSSL 13:f67a6c6013ca 987 COMPRESS_UPPER = 55, /* compression calc numerator */
wolfSSL 13:f67a6c6013ca 988 COMPRESS_LOWER = 64, /* compression calc denominator */
wolfSSL 13:f67a6c6013ca 989
wolfSSL 13:f67a6c6013ca 990 PEM_LINE_LEN = 80, /* PEM line max + fudge */
wolfSSL 13:f67a6c6013ca 991 LENGTH_SZ = 2, /* length field for HMAC, data only */
wolfSSL 13:f67a6c6013ca 992 VERSION_SZ = 2, /* length of proctocol version */
wolfSSL 13:f67a6c6013ca 993 SEQ_SZ = 8, /* 64 bit sequence number */
wolfSSL 13:f67a6c6013ca 994 ALERT_SIZE = 2, /* level + description */
wolfSSL 13:f67a6c6013ca 995 VERIFY_HEADER = 2, /* always use 2 bytes */
wolfSSL 13:f67a6c6013ca 996 EXTS_SZ = 2, /* always use 2 bytes */
wolfSSL 13:f67a6c6013ca 997 EXT_ID_SZ = 2, /* always use 2 bytes */
wolfSSL 13:f67a6c6013ca 998 MAX_DH_SIZE = 513, /* 4096 bit plus possible leading 0 */
wolfSSL 13:f67a6c6013ca 999 NAMED_DH_MASK = 0x100, /* Named group mask for DH parameters */
wolfSSL 13:f67a6c6013ca 1000 SESSION_HINT_SZ = 4, /* session timeout hint */
wolfSSL 13:f67a6c6013ca 1001 SESSION_ADD_SZ = 4, /* session age add */
wolfSSL 13:f67a6c6013ca 1002 MAX_LIFETIME = 604800, /* maximum ticket lifetime */
wolfSSL 13:f67a6c6013ca 1003 MAX_EARLY_DATA_SZ = 4096, /* maximum early data size */
wolfSSL 13:f67a6c6013ca 1004
wolfSSL 13:f67a6c6013ca 1005 RAN_LEN = 32, /* random length */
wolfSSL 13:f67a6c6013ca 1006 SEED_LEN = RAN_LEN * 2, /* tls prf seed length */
wolfSSL 13:f67a6c6013ca 1007 ID_LEN = 32, /* session id length */
wolfSSL 13:f67a6c6013ca 1008 COOKIE_SECRET_SZ = 14, /* dtls cookie secret size */
wolfSSL 13:f67a6c6013ca 1009 MAX_COOKIE_LEN = 32, /* max dtls cookie size */
wolfSSL 13:f67a6c6013ca 1010 COOKIE_SZ = 20, /* use a 20 byte cookie */
wolfSSL 13:f67a6c6013ca 1011 SUITE_LEN = 2, /* cipher suite sz length */
wolfSSL 13:f67a6c6013ca 1012 ENUM_LEN = 1, /* always a byte */
wolfSSL 13:f67a6c6013ca 1013 OPAQUE8_LEN = 1, /* 1 byte */
wolfSSL 13:f67a6c6013ca 1014 OPAQUE16_LEN = 2, /* 2 bytes */
wolfSSL 13:f67a6c6013ca 1015 OPAQUE24_LEN = 3, /* 3 bytes */
wolfSSL 13:f67a6c6013ca 1016 OPAQUE32_LEN = 4, /* 4 bytes */
wolfSSL 13:f67a6c6013ca 1017 OPAQUE64_LEN = 8, /* 8 bytes */
wolfSSL 13:f67a6c6013ca 1018 COMP_LEN = 1, /* compression length */
wolfSSL 13:f67a6c6013ca 1019 CURVE_LEN = 2, /* ecc named curve length */
wolfSSL 13:f67a6c6013ca 1020 KE_GROUP_LEN = 2, /* key exchange group length */
wolfSSL 13:f67a6c6013ca 1021 SERVER_ID_LEN = 20, /* server session id length */
wolfSSL 13:f67a6c6013ca 1022
wolfSSL 13:f67a6c6013ca 1023 HANDSHAKE_HEADER_SZ = 4, /* type + length(3) */
wolfSSL 13:f67a6c6013ca 1024 RECORD_HEADER_SZ = 5, /* type + version + len(2) */
wolfSSL 13:f67a6c6013ca 1025 CERT_HEADER_SZ = 3, /* always 3 bytes */
wolfSSL 13:f67a6c6013ca 1026 REQ_HEADER_SZ = 2, /* cert request header sz */
wolfSSL 13:f67a6c6013ca 1027 HINT_LEN_SZ = 2, /* length of hint size field */
wolfSSL 13:f67a6c6013ca 1028 TRUNCATED_HMAC_SZ = 10, /* length of hmac w/ truncated hmac extension */
wolfSSL 13:f67a6c6013ca 1029 HELLO_EXT_SZ = 4, /* base length of a hello extension */
wolfSSL 13:f67a6c6013ca 1030 HELLO_EXT_TYPE_SZ = 2, /* length of a hello extension type */
wolfSSL 13:f67a6c6013ca 1031 HELLO_EXT_SZ_SZ = 2, /* length of a hello extension size */
wolfSSL 13:f67a6c6013ca 1032 HELLO_EXT_SIGALGO_SZ = 2, /* length of number of items in sigalgo list */
wolfSSL 13:f67a6c6013ca 1033 HELLO_EXT_SIGALGO_MAX = 32, /* number of items in the signature algo list */
wolfSSL 13:f67a6c6013ca 1034
wolfSSL 13:f67a6c6013ca 1035 DTLS_HANDSHAKE_HEADER_SZ = 12, /* normal + seq(2) + offset(3) + length(3) */
wolfSSL 13:f67a6c6013ca 1036 DTLS_RECORD_HEADER_SZ = 13, /* normal + epoch(2) + seq_num(6) */
wolfSSL 13:f67a6c6013ca 1037 DTLS_HANDSHAKE_EXTRA = 8, /* diff from normal */
wolfSSL 13:f67a6c6013ca 1038 DTLS_RECORD_EXTRA = 8, /* diff from normal */
wolfSSL 13:f67a6c6013ca 1039 DTLS_HANDSHAKE_SEQ_SZ = 2, /* handshake header sequence number */
wolfSSL 13:f67a6c6013ca 1040 DTLS_HANDSHAKE_FRAG_SZ = 3, /* fragment offset and length are 24 bit */
wolfSSL 13:f67a6c6013ca 1041 DTLS_POOL_SZ = 255,/* allowed number of list items in TX pool */
wolfSSL 13:f67a6c6013ca 1042 DTLS_EXPORT_PRO = 165,/* wolfSSL protocol for serialized session */
wolfSSL 13:f67a6c6013ca 1043 DTLS_EXPORT_VERSION = 4, /* wolfSSL version for serialized session */
wolfSSL 13:f67a6c6013ca 1044 DTLS_EXPORT_OPT_SZ = 58, /* amount of bytes used from Options */
wolfSSL 13:f67a6c6013ca 1045 DTLS_EXPORT_VERSION_3 = 3, /* wolfSSL version before TLS 1.3 addition */
wolfSSL 13:f67a6c6013ca 1046 DTLS_EXPORT_OPT_SZ_3 = 57, /* amount of bytes used from Options */
wolfSSL 13:f67a6c6013ca 1047 DTLS_EXPORT_KEY_SZ = 325 + (DTLS_SEQ_SZ * 2),
wolfSSL 13:f67a6c6013ca 1048 /* max amount of bytes used from Keys */
wolfSSL 13:f67a6c6013ca 1049 DTLS_EXPORT_MIN_KEY_SZ = 78 + (DTLS_SEQ_SZ * 2),
wolfSSL 13:f67a6c6013ca 1050 /* min amount of bytes used from Keys */
wolfSSL 13:f67a6c6013ca 1051 DTLS_EXPORT_SPC_SZ = 16, /* amount of bytes used from CipherSpecs */
wolfSSL 13:f67a6c6013ca 1052 DTLS_EXPORT_LEN = 2, /* 2 bytes for length and protocol */
wolfSSL 13:f67a6c6013ca 1053 DTLS_EXPORT_IP = 46, /* max ip size IPv4 mapped IPv6 */
wolfSSL 13:f67a6c6013ca 1054 MAX_EXPORT_BUFFER = 514, /* max size of buffer for exporting */
wolfSSL 13:f67a6c6013ca 1055 FINISHED_LABEL_SZ = 15, /* TLS finished label size */
wolfSSL 13:f67a6c6013ca 1056 TLS_FINISHED_SZ = 12, /* TLS has a shorter size */
wolfSSL 13:f67a6c6013ca 1057 EXT_MASTER_LABEL_SZ = 22, /* TLS extended master secret label sz */
wolfSSL 13:f67a6c6013ca 1058 MASTER_LABEL_SZ = 13, /* TLS master secret label sz */
wolfSSL 13:f67a6c6013ca 1059 KEY_LABEL_SZ = 13, /* TLS key block expansion sz */
wolfSSL 13:f67a6c6013ca 1060 MAX_PRF_HALF = 256, /* Maximum half secret len */
wolfSSL 13:f67a6c6013ca 1061 MAX_PRF_LABSEED = 128, /* Maximum label + seed len */
wolfSSL 13:f67a6c6013ca 1062 MAX_PRF_DIG = 224, /* Maximum digest len */
wolfSSL 13:f67a6c6013ca 1063 PROTOCOL_LABEL_SZ = 9, /* Length of the protocol label */
wolfSSL 13:f67a6c6013ca 1064 MAX_LABEL_SZ = 34, /* Maximum length of a label */
wolfSSL 13:f67a6c6013ca 1065 MAX_HKDF_LABEL_SZ = OPAQUE16_LEN +
wolfSSL 13:f67a6c6013ca 1066 OPAQUE8_LEN + PROTOCOL_LABEL_SZ + MAX_LABEL_SZ +
wolfSSL 13:f67a6c6013ca 1067 OPAQUE8_LEN + MAX_DIGEST_SIZE,
wolfSSL 13:f67a6c6013ca 1068 MAX_REQUEST_SZ = 256, /* Maximum cert req len (no auth yet */
wolfSSL 13:f67a6c6013ca 1069 SESSION_FLUSH_COUNT = 256, /* Flush session cache unless user turns off */
wolfSSL 13:f67a6c6013ca 1070
wolfSSL 13:f67a6c6013ca 1071 RC4_KEY_SIZE = 16, /* always 128bit */
wolfSSL 13:f67a6c6013ca 1072 DES_KEY_SIZE = 8, /* des */
wolfSSL 13:f67a6c6013ca 1073 DES3_KEY_SIZE = 24, /* 3 des ede */
wolfSSL 13:f67a6c6013ca 1074 DES_IV_SIZE = DES_BLOCK_SIZE,
wolfSSL 13:f67a6c6013ca 1075 AES_256_KEY_SIZE = 32, /* for 256 bit */
wolfSSL 13:f67a6c6013ca 1076 AES_192_KEY_SIZE = 24, /* for 192 bit */
wolfSSL 13:f67a6c6013ca 1077 AES_IV_SIZE = 16, /* always block size */
wolfSSL 13:f67a6c6013ca 1078 AES_128_KEY_SIZE = 16, /* for 128 bit */
wolfSSL 13:f67a6c6013ca 1079
wolfSSL 13:f67a6c6013ca 1080 AEAD_SEQ_OFFSET = 4, /* Auth Data: Sequence number */
wolfSSL 13:f67a6c6013ca 1081 AEAD_TYPE_OFFSET = 8, /* Auth Data: Type */
wolfSSL 13:f67a6c6013ca 1082 AEAD_VMAJ_OFFSET = 9, /* Auth Data: Major Version */
wolfSSL 13:f67a6c6013ca 1083 AEAD_VMIN_OFFSET = 10, /* Auth Data: Minor Version */
wolfSSL 13:f67a6c6013ca 1084 AEAD_LEN_OFFSET = 11, /* Auth Data: Length */
wolfSSL 13:f67a6c6013ca 1085 AEAD_AUTH_DATA_SZ = 13, /* Size of the data to authenticate */
wolfSSL 13:f67a6c6013ca 1086 AEAD_NONCE_SZ = 12,
wolfSSL 13:f67a6c6013ca 1087 AESGCM_IMP_IV_SZ = 4, /* Size of GCM/CCM AEAD implicit IV */
wolfSSL 13:f67a6c6013ca 1088 AESGCM_EXP_IV_SZ = 8, /* Size of GCM/CCM AEAD explicit IV */
wolfSSL 13:f67a6c6013ca 1089 AESGCM_NONCE_SZ = AESGCM_EXP_IV_SZ + AESGCM_IMP_IV_SZ,
wolfSSL 13:f67a6c6013ca 1090
wolfSSL 13:f67a6c6013ca 1091 CHACHA20_IMP_IV_SZ = 12, /* Size of ChaCha20 AEAD implicit IV */
wolfSSL 13:f67a6c6013ca 1092 CHACHA20_NONCE_SZ = 12, /* Size of ChacCha20 nonce */
wolfSSL 13:f67a6c6013ca 1093 CHACHA20_OLD_OFFSET = 4, /* Offset for seq # in old poly1305 */
wolfSSL 13:f67a6c6013ca 1094
wolfSSL 13:f67a6c6013ca 1095 /* For any new implicit/explicit IV size adjust AEAD_MAX_***_SZ */
wolfSSL 13:f67a6c6013ca 1096
wolfSSL 13:f67a6c6013ca 1097 AES_GCM_AUTH_SZ = 16, /* AES-GCM Auth Tag length */
wolfSSL 13:f67a6c6013ca 1098 AES_CCM_16_AUTH_SZ = 16, /* AES-CCM-16 Auth Tag length */
wolfSSL 13:f67a6c6013ca 1099 AES_CCM_8_AUTH_SZ = 8, /* AES-CCM-8 Auth Tag Length */
wolfSSL 13:f67a6c6013ca 1100 AESCCM_NONCE_SZ = 12,
wolfSSL 13:f67a6c6013ca 1101
wolfSSL 13:f67a6c6013ca 1102 CAMELLIA_128_KEY_SIZE = 16, /* for 128 bit */
wolfSSL 13:f67a6c6013ca 1103 CAMELLIA_192_KEY_SIZE = 24, /* for 192 bit */
wolfSSL 13:f67a6c6013ca 1104 CAMELLIA_256_KEY_SIZE = 32, /* for 256 bit */
wolfSSL 13:f67a6c6013ca 1105 CAMELLIA_IV_SIZE = 16, /* always block size */
wolfSSL 13:f67a6c6013ca 1106
wolfSSL 13:f67a6c6013ca 1107 CHACHA20_256_KEY_SIZE = 32, /* for 256 bit */
wolfSSL 13:f67a6c6013ca 1108 CHACHA20_128_KEY_SIZE = 16, /* for 128 bit */
wolfSSL 13:f67a6c6013ca 1109 CHACHA20_IV_SIZE = 12, /* 96 bits for iv */
wolfSSL 13:f67a6c6013ca 1110
wolfSSL 13:f67a6c6013ca 1111 POLY1305_AUTH_SZ = 16, /* 128 bits */
wolfSSL 13:f67a6c6013ca 1112
wolfSSL 13:f67a6c6013ca 1113 HC_128_KEY_SIZE = 16, /* 128 bits */
wolfSSL 13:f67a6c6013ca 1114 HC_128_IV_SIZE = 16, /* also 128 bits */
wolfSSL 13:f67a6c6013ca 1115
wolfSSL 13:f67a6c6013ca 1116 RABBIT_KEY_SIZE = 16, /* 128 bits */
wolfSSL 13:f67a6c6013ca 1117 RABBIT_IV_SIZE = 8, /* 64 bits for iv */
wolfSSL 13:f67a6c6013ca 1118
wolfSSL 13:f67a6c6013ca 1119 EVP_SALT_SIZE = 8, /* evp salt size 64 bits */
wolfSSL 13:f67a6c6013ca 1120
wolfSSL 13:f67a6c6013ca 1121 ECDHE_SIZE = 32, /* ECHDE server size defaults to 256 bit */
wolfSSL 13:f67a6c6013ca 1122 MAX_EXPORT_ECC_SZ = 256, /* Export ANS X9.62 max future size */
wolfSSL 13:f67a6c6013ca 1123 MAX_CURVE_NAME_SZ = 16, /* Maximum size of curve name string */
wolfSSL 13:f67a6c6013ca 1124
wolfSSL 13:f67a6c6013ca 1125 NEW_SA_MAJOR = 8, /* Most signicant byte used with new sig algos */
wolfSSL 13:f67a6c6013ca 1126 ED25519_SA_MAJOR = 8, /* Most significant byte for ED25519 */
wolfSSL 13:f67a6c6013ca 1127 ED25519_SA_MINOR = 7, /* Least significant byte for ED25519 */
wolfSSL 13:f67a6c6013ca 1128 ED448_SA_MAJOR = 8, /* Most significant byte for ED448 */
wolfSSL 13:f67a6c6013ca 1129 ED448_SA_MINOR = 8, /* Least significant byte for ED448 */
wolfSSL 13:f67a6c6013ca 1130
wolfSSL 13:f67a6c6013ca 1131 MIN_RSA_SHA512_PSS_BITS = 512 * 2 + 8 * 8, /* Min key size */
wolfSSL 13:f67a6c6013ca 1132 MIN_RSA_SHA384_PSS_BITS = 384 * 2 + 8 * 8, /* Min key size */
wolfSSL 13:f67a6c6013ca 1133
wolfSSL 13:f67a6c6013ca 1134 #ifdef HAVE_QSH
wolfSSL 13:f67a6c6013ca 1135 /* qsh handshake sends 600+ size keys over hello extensions */
wolfSSL 13:f67a6c6013ca 1136 MAX_HELLO_SZ = 2048, /* max client or server hello */
wolfSSL 13:f67a6c6013ca 1137 #else
wolfSSL 13:f67a6c6013ca 1138 MAX_HELLO_SZ = 128, /* max client or server hello */
wolfSSL 13:f67a6c6013ca 1139 #endif
wolfSSL 13:f67a6c6013ca 1140 MAX_CERT_VERIFY_SZ = 1024, /* max */
wolfSSL 13:f67a6c6013ca 1141 CLIENT_HELLO_FIRST = 35, /* Protocol + RAN_LEN + sizeof(id_len) */
wolfSSL 13:f67a6c6013ca 1142 MAX_SUITE_NAME = 48, /* maximum length of cipher suite string */
wolfSSL 13:f67a6c6013ca 1143
wolfSSL 13:f67a6c6013ca 1144 DTLS_TIMEOUT_INIT = 1, /* default timeout init for DTLS receive */
wolfSSL 13:f67a6c6013ca 1145 DTLS_TIMEOUT_MAX = 64, /* default max timeout for DTLS receive */
wolfSSL 13:f67a6c6013ca 1146 DTLS_TIMEOUT_MULTIPLIER = 2, /* default timeout multiplier for DTLS recv */
wolfSSL 13:f67a6c6013ca 1147
wolfSSL 13:f67a6c6013ca 1148 MAX_PSK_ID_LEN = 128, /* max psk identity/hint supported */
wolfSSL 13:f67a6c6013ca 1149 NULL_TERM_LEN = 1, /* length of null '\0' termination character */
wolfSSL 13:f67a6c6013ca 1150 MAX_PSK_KEY_LEN = 64, /* max psk key supported */
wolfSSL 13:f67a6c6013ca 1151 MIN_PSK_ID_LEN = 6, /* min length of identities */
wolfSSL 13:f67a6c6013ca 1152 MIN_PSK_BINDERS_LEN= 33, /* min length of binders */
wolfSSL 13:f67a6c6013ca 1153 MAX_TICKET_AGE_SECS= 10, /* maximum ticket age in seconds */
wolfSSL 13:f67a6c6013ca 1154
wolfSSL 13:f67a6c6013ca 1155 MAX_WOLFSSL_FILE_SIZE = 1024 * 1024 * 4, /* 4 mb file size alloc limit */
wolfSSL 13:f67a6c6013ca 1156
wolfSSL 13:f67a6c6013ca 1157 #if defined(HAVE_EX_DATA) || defined(FORTRESS)
wolfSSL 13:f67a6c6013ca 1158 MAX_EX_DATA = 5, /* allow for five items of ex_data */
wolfSSL 13:f67a6c6013ca 1159 #endif
wolfSSL 13:f67a6c6013ca 1160
wolfSSL 13:f67a6c6013ca 1161 MAX_X509_SIZE = 2048, /* max static x509 buffer size */
wolfSSL 13:f67a6c6013ca 1162 CERT_MIN_SIZE = 256, /* min PEM cert size with header/footer */
wolfSSL 13:f67a6c6013ca 1163 FILE_BUFFER_SIZE = 1024, /* default static file buffer size for input,
wolfSSL 13:f67a6c6013ca 1164 will use dynamic buffer if not big enough */
wolfSSL 13:f67a6c6013ca 1165
wolfSSL 13:f67a6c6013ca 1166 MAX_NTRU_PUB_KEY_SZ = 1027, /* NTRU max for now */
wolfSSL 13:f67a6c6013ca 1167 MAX_NTRU_ENCRYPT_SZ = 1027, /* NTRU max for now */
wolfSSL 13:f67a6c6013ca 1168 MAX_NTRU_BITS = 256, /* max symmetric bit strength */
wolfSSL 13:f67a6c6013ca 1169 NO_SNIFF = 0, /* not sniffing */
wolfSSL 13:f67a6c6013ca 1170 SNIFF = 1, /* currently sniffing */
wolfSSL 13:f67a6c6013ca 1171
wolfSSL 13:f67a6c6013ca 1172 HASH_SIG_SIZE = 2, /* default SHA1 RSA */
wolfSSL 13:f67a6c6013ca 1173
wolfSSL 13:f67a6c6013ca 1174 NO_COPY = 0, /* should we copy static buffer for write */
wolfSSL 13:f67a6c6013ca 1175 COPY = 1, /* should we copy static buffer for write */
wolfSSL 13:f67a6c6013ca 1176
wolfSSL 13:f67a6c6013ca 1177 INVALID_PEER_ID = 0xFFFF, /* Initialize value for peer ID. */
wolfSSL 13:f67a6c6013ca 1178
wolfSSL 13:f67a6c6013ca 1179 PREV_ORDER = -1, /* Sequence number is in previous epoch. */
wolfSSL 13:f67a6c6013ca 1180 PEER_ORDER = 1, /* Peer sequence number for verify. */
wolfSSL 13:f67a6c6013ca 1181 CUR_ORDER = 0 /* Current sequence number. */
wolfSSL 13:f67a6c6013ca 1182 };
wolfSSL 13:f67a6c6013ca 1183
wolfSSL 13:f67a6c6013ca 1184
wolfSSL 13:f67a6c6013ca 1185 /* Set max implicit IV size for AEAD cipher suites */
wolfSSL 13:f67a6c6013ca 1186 #define AEAD_MAX_IMP_SZ 12
wolfSSL 13:f67a6c6013ca 1187
wolfSSL 13:f67a6c6013ca 1188 /* Set max explicit IV size for AEAD cipher suites */
wolfSSL 13:f67a6c6013ca 1189 #define AEAD_MAX_EXP_SZ 8
wolfSSL 13:f67a6c6013ca 1190
wolfSSL 13:f67a6c6013ca 1191
wolfSSL 13:f67a6c6013ca 1192 #ifndef WOLFSSL_MAX_SUITE_SZ
wolfSSL 13:f67a6c6013ca 1193 #define WOLFSSL_MAX_SUITE_SZ 300
wolfSSL 13:f67a6c6013ca 1194 /* 150 suites for now! */
wolfSSL 13:f67a6c6013ca 1195 #endif
wolfSSL 13:f67a6c6013ca 1196
wolfSSL 13:f67a6c6013ca 1197 /* set minimum ECC key size allowed */
wolfSSL 13:f67a6c6013ca 1198 #ifndef WOLFSSL_MIN_ECC_BITS
wolfSSL 13:f67a6c6013ca 1199 #ifdef WOLFSSL_MAX_STRENGTH
wolfSSL 13:f67a6c6013ca 1200 #define WOLFSSL_MIN_ECC_BITS 256
wolfSSL 13:f67a6c6013ca 1201 #else
wolfSSL 13:f67a6c6013ca 1202 #define WOLFSSL_MIN_ECC_BITS 224
wolfSSL 13:f67a6c6013ca 1203 #endif
wolfSSL 13:f67a6c6013ca 1204 #endif /* WOLFSSL_MIN_ECC_BITS */
wolfSSL 13:f67a6c6013ca 1205 #if (WOLFSSL_MIN_ECC_BITS % 8)
wolfSSL 13:f67a6c6013ca 1206 /* Some ECC keys are not divisable by 8 such as prime239v1 or sect131r1.
wolfSSL 13:f67a6c6013ca 1207 In these cases round down to the nearest value divisable by 8. The
wolfSSL 13:f67a6c6013ca 1208 restriction of being divisable by 8 is in place to match wc_ecc_size
wolfSSL 13:f67a6c6013ca 1209 function from wolfSSL.
wolfSSL 13:f67a6c6013ca 1210 */
wolfSSL 13:f67a6c6013ca 1211 #error ECC minimum bit size must be a multiple of 8
wolfSSL 13:f67a6c6013ca 1212 #endif
wolfSSL 13:f67a6c6013ca 1213 #define MIN_ECCKEY_SZ (WOLFSSL_MIN_ECC_BITS / 8)
wolfSSL 13:f67a6c6013ca 1214
wolfSSL 13:f67a6c6013ca 1215 /* set minimum RSA key size allowed */
wolfSSL 13:f67a6c6013ca 1216 #ifndef WOLFSSL_MIN_RSA_BITS
wolfSSL 13:f67a6c6013ca 1217 #ifdef WOLFSSL_MAX_STRENGTH
wolfSSL 13:f67a6c6013ca 1218 #define WOLFSSL_MIN_RSA_BITS 2048
wolfSSL 13:f67a6c6013ca 1219 #else
wolfSSL 13:f67a6c6013ca 1220 #define WOLFSSL_MIN_RSA_BITS 1024
wolfSSL 13:f67a6c6013ca 1221 #endif
wolfSSL 13:f67a6c6013ca 1222 #endif /* WOLFSSL_MIN_RSA_BITS */
wolfSSL 13:f67a6c6013ca 1223 #if (WOLFSSL_MIN_RSA_BITS % 8)
wolfSSL 13:f67a6c6013ca 1224 /* This is to account for the example case of a min size of 2050 bits but
wolfSSL 13:f67a6c6013ca 1225 still allows 2049 bit key. So we need the measurment to be in bytes. */
wolfSSL 13:f67a6c6013ca 1226 #error RSA minimum bit size must be a multiple of 8
wolfSSL 13:f67a6c6013ca 1227 #endif
wolfSSL 13:f67a6c6013ca 1228 #define MIN_RSAKEY_SZ (WOLFSSL_MIN_RSA_BITS / 8)
wolfSSL 13:f67a6c6013ca 1229
wolfSSL 13:f67a6c6013ca 1230 /* set minimum DH key size allowed */
wolfSSL 13:f67a6c6013ca 1231 #ifndef WOLFSSL_MIN_DHKEY_BITS
wolfSSL 13:f67a6c6013ca 1232 #ifdef WOLFSSL_MAX_STRENGTH
wolfSSL 13:f67a6c6013ca 1233 #define WOLFSSL_MIN_DHKEY_BITS 2048
wolfSSL 13:f67a6c6013ca 1234 #else
wolfSSL 13:f67a6c6013ca 1235 #define WOLFSSL_MIN_DHKEY_BITS 1024
wolfSSL 13:f67a6c6013ca 1236 #endif
wolfSSL 13:f67a6c6013ca 1237 #endif
wolfSSL 13:f67a6c6013ca 1238 #if (WOLFSSL_MIN_DHKEY_BITS % 8)
wolfSSL 13:f67a6c6013ca 1239 #error DH minimum bit size must be multiple of 8
wolfSSL 13:f67a6c6013ca 1240 #endif
wolfSSL 13:f67a6c6013ca 1241 #if (WOLFSSL_MIN_DHKEY_BITS > 16000)
wolfSSL 13:f67a6c6013ca 1242 #error DH minimum bit size must not be greater than 16000
wolfSSL 13:f67a6c6013ca 1243 #endif
wolfSSL 13:f67a6c6013ca 1244 #define MIN_DHKEY_SZ (WOLFSSL_MIN_DHKEY_BITS / 8)
wolfSSL 13:f67a6c6013ca 1245
wolfSSL 13:f67a6c6013ca 1246
wolfSSL 13:f67a6c6013ca 1247 #ifdef SESSION_INDEX
wolfSSL 13:f67a6c6013ca 1248 /* Shift values for making a session index */
wolfSSL 13:f67a6c6013ca 1249 #define SESSIDX_ROW_SHIFT 4
wolfSSL 13:f67a6c6013ca 1250 #define SESSIDX_IDX_MASK 0x0F
wolfSSL 13:f67a6c6013ca 1251 #endif
wolfSSL 13:f67a6c6013ca 1252
wolfSSL 13:f67a6c6013ca 1253
wolfSSL 13:f67a6c6013ca 1254 /* max cert chain peer depth */
wolfSSL 13:f67a6c6013ca 1255 #ifndef MAX_CHAIN_DEPTH
wolfSSL 13:f67a6c6013ca 1256 #define MAX_CHAIN_DEPTH 9
wolfSSL 13:f67a6c6013ca 1257 #endif
wolfSSL 13:f67a6c6013ca 1258
wolfSSL 13:f67a6c6013ca 1259 /* max size of a certificate message payload */
wolfSSL 13:f67a6c6013ca 1260 /* assumes MAX_CHAIN_DEPTH number of certificates at 2kb per certificate */
wolfSSL 13:f67a6c6013ca 1261 #ifndef MAX_CERTIFICATE_SZ
wolfSSL 13:f67a6c6013ca 1262 #define MAX_CERTIFICATE_SZ \
wolfSSL 13:f67a6c6013ca 1263 CERT_HEADER_SZ + \
wolfSSL 13:f67a6c6013ca 1264 (MAX_X509_SIZE + CERT_HEADER_SZ) * MAX_CHAIN_DEPTH
wolfSSL 13:f67a6c6013ca 1265 #endif
wolfSSL 13:f67a6c6013ca 1266
wolfSSL 13:f67a6c6013ca 1267 /* max size of a handshake message, currently set to the certificate */
wolfSSL 13:f67a6c6013ca 1268 #ifndef MAX_HANDSHAKE_SZ
wolfSSL 13:f67a6c6013ca 1269 #define MAX_HANDSHAKE_SZ MAX_CERTIFICATE_SZ
wolfSSL 13:f67a6c6013ca 1270 #endif
wolfSSL 13:f67a6c6013ca 1271
wolfSSL 13:f67a6c6013ca 1272 #ifndef SESSION_TICKET_LEN
wolfSSL 13:f67a6c6013ca 1273 #define SESSION_TICKET_LEN 256
wolfSSL 13:f67a6c6013ca 1274 #endif
wolfSSL 13:f67a6c6013ca 1275
wolfSSL 13:f67a6c6013ca 1276 #ifndef SESSION_TICKET_HINT_DEFAULT
wolfSSL 13:f67a6c6013ca 1277 #define SESSION_TICKET_HINT_DEFAULT 300
wolfSSL 13:f67a6c6013ca 1278 #endif
wolfSSL 13:f67a6c6013ca 1279
wolfSSL 13:f67a6c6013ca 1280
wolfSSL 13:f67a6c6013ca 1281 /* don't use extra 3/4k stack space unless need to */
wolfSSL 13:f67a6c6013ca 1282 #ifdef HAVE_NTRU
wolfSSL 13:f67a6c6013ca 1283 #define MAX_ENCRYPT_SZ MAX_NTRU_ENCRYPT_SZ
wolfSSL 13:f67a6c6013ca 1284 #else
wolfSSL 13:f67a6c6013ca 1285 #define MAX_ENCRYPT_SZ ENCRYPT_LEN
wolfSSL 13:f67a6c6013ca 1286 #endif
wolfSSL 13:f67a6c6013ca 1287
wolfSSL 13:f67a6c6013ca 1288
wolfSSL 13:f67a6c6013ca 1289 /* states */
wolfSSL 13:f67a6c6013ca 1290 enum states {
wolfSSL 13:f67a6c6013ca 1291 NULL_STATE = 0,
wolfSSL 13:f67a6c6013ca 1292
wolfSSL 13:f67a6c6013ca 1293 SERVER_HELLOVERIFYREQUEST_COMPLETE,
wolfSSL 13:f67a6c6013ca 1294 SERVER_HELLO_COMPLETE,
wolfSSL 13:f67a6c6013ca 1295 SERVER_ENCRYPTED_EXTENSIONS_COMPLETE,
wolfSSL 13:f67a6c6013ca 1296 SERVER_CERT_COMPLETE,
wolfSSL 13:f67a6c6013ca 1297 SERVER_KEYEXCHANGE_COMPLETE,
wolfSSL 13:f67a6c6013ca 1298 SERVER_HELLODONE_COMPLETE,
wolfSSL 13:f67a6c6013ca 1299 SERVER_FINISHED_COMPLETE,
wolfSSL 13:f67a6c6013ca 1300 SERVER_HELLO_RETRY_REQUEST,
wolfSSL 13:f67a6c6013ca 1301
wolfSSL 13:f67a6c6013ca 1302 CLIENT_HELLO_COMPLETE,
wolfSSL 13:f67a6c6013ca 1303 CLIENT_KEYEXCHANGE_COMPLETE,
wolfSSL 13:f67a6c6013ca 1304 CLIENT_FINISHED_COMPLETE,
wolfSSL 13:f67a6c6013ca 1305
wolfSSL 13:f67a6c6013ca 1306 HANDSHAKE_DONE
wolfSSL 13:f67a6c6013ca 1307 };
wolfSSL 13:f67a6c6013ca 1308
wolfSSL 13:f67a6c6013ca 1309
wolfSSL 13:f67a6c6013ca 1310 #if defined(__GNUC__)
wolfSSL 13:f67a6c6013ca 1311 #define WOLFSSL_PACK __attribute__ ((packed))
wolfSSL 13:f67a6c6013ca 1312 #else
wolfSSL 13:f67a6c6013ca 1313 #define WOLFSSL_PACK
wolfSSL 13:f67a6c6013ca 1314 #endif
wolfSSL 13:f67a6c6013ca 1315
wolfSSL 13:f67a6c6013ca 1316 /* SSL Version */
wolfSSL 13:f67a6c6013ca 1317 typedef struct ProtocolVersion {
wolfSSL 13:f67a6c6013ca 1318 byte major;
wolfSSL 13:f67a6c6013ca 1319 byte minor;
wolfSSL 13:f67a6c6013ca 1320 } WOLFSSL_PACK ProtocolVersion;
wolfSSL 13:f67a6c6013ca 1321
wolfSSL 13:f67a6c6013ca 1322
wolfSSL 13:f67a6c6013ca 1323 WOLFSSL_LOCAL ProtocolVersion MakeSSLv3(void);
wolfSSL 13:f67a6c6013ca 1324 WOLFSSL_LOCAL ProtocolVersion MakeTLSv1(void);
wolfSSL 13:f67a6c6013ca 1325 WOLFSSL_LOCAL ProtocolVersion MakeTLSv1_1(void);
wolfSSL 13:f67a6c6013ca 1326 WOLFSSL_LOCAL ProtocolVersion MakeTLSv1_2(void);
wolfSSL 13:f67a6c6013ca 1327 WOLFSSL_LOCAL ProtocolVersion MakeTLSv1_3(void);
wolfSSL 13:f67a6c6013ca 1328
wolfSSL 13:f67a6c6013ca 1329 #ifdef WOLFSSL_DTLS
wolfSSL 13:f67a6c6013ca 1330 WOLFSSL_LOCAL ProtocolVersion MakeDTLSv1(void);
wolfSSL 13:f67a6c6013ca 1331 WOLFSSL_LOCAL ProtocolVersion MakeDTLSv1_2(void);
wolfSSL 13:f67a6c6013ca 1332
wolfSSL 13:f67a6c6013ca 1333 #ifdef WOLFSSL_SESSION_EXPORT
wolfSSL 13:f67a6c6013ca 1334 WOLFSSL_LOCAL int wolfSSL_dtls_import_internal(WOLFSSL* ssl, byte* buf,
wolfSSL 13:f67a6c6013ca 1335 word32 sz);
wolfSSL 13:f67a6c6013ca 1336 WOLFSSL_LOCAL int wolfSSL_dtls_export_internal(WOLFSSL* ssl, byte* buf,
wolfSSL 13:f67a6c6013ca 1337 word32 sz);
wolfSSL 13:f67a6c6013ca 1338 WOLFSSL_LOCAL int wolfSSL_send_session(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 1339 #endif
wolfSSL 13:f67a6c6013ca 1340 #endif
wolfSSL 13:f67a6c6013ca 1341
wolfSSL 13:f67a6c6013ca 1342
wolfSSL 13:f67a6c6013ca 1343 enum BIO_TYPE {
wolfSSL 13:f67a6c6013ca 1344 BIO_BUFFER = 1,
wolfSSL 13:f67a6c6013ca 1345 BIO_SOCKET = 2,
wolfSSL 13:f67a6c6013ca 1346 BIO_SSL = 3,
wolfSSL 13:f67a6c6013ca 1347 BIO_MEMORY = 4,
wolfSSL 13:f67a6c6013ca 1348 BIO_BIO = 5,
wolfSSL 13:f67a6c6013ca 1349 BIO_FILE = 6
wolfSSL 13:f67a6c6013ca 1350 };
wolfSSL 13:f67a6c6013ca 1351
wolfSSL 13:f67a6c6013ca 1352
wolfSSL 13:f67a6c6013ca 1353 /* wolfSSL BIO_METHOD type */
wolfSSL 13:f67a6c6013ca 1354 struct WOLFSSL_BIO_METHOD {
wolfSSL 13:f67a6c6013ca 1355 byte type; /* method type */
wolfSSL 13:f67a6c6013ca 1356 };
wolfSSL 13:f67a6c6013ca 1357
wolfSSL 13:f67a6c6013ca 1358
wolfSSL 13:f67a6c6013ca 1359 /* wolfSSL BIO type */
wolfSSL 13:f67a6c6013ca 1360 struct WOLFSSL_BIO {
wolfSSL 13:f67a6c6013ca 1361 WOLFSSL* ssl; /* possible associated ssl */
wolfSSL 13:f67a6c6013ca 1362 #ifndef NO_FILESYSTEM
wolfSSL 13:f67a6c6013ca 1363 XFILE file;
wolfSSL 13:f67a6c6013ca 1364 #endif
wolfSSL 13:f67a6c6013ca 1365 WOLFSSL_BIO* prev; /* previous in chain */
wolfSSL 13:f67a6c6013ca 1366 WOLFSSL_BIO* next; /* next in chain */
wolfSSL 13:f67a6c6013ca 1367 WOLFSSL_BIO* pair; /* BIO paired with */
wolfSSL 13:f67a6c6013ca 1368 void* heap; /* user heap hint */
wolfSSL 13:f67a6c6013ca 1369 byte* mem; /* memory buffer */
wolfSSL 13:f67a6c6013ca 1370 int wrSz; /* write buffer size (mem) */
wolfSSL 13:f67a6c6013ca 1371 int wrIdx; /* current index for write buffer */
wolfSSL 13:f67a6c6013ca 1372 int rdIdx; /* current read index */
wolfSSL 13:f67a6c6013ca 1373 int readRq; /* read request */
wolfSSL 13:f67a6c6013ca 1374 int memLen; /* memory buffer length */
wolfSSL 13:f67a6c6013ca 1375 int fd; /* possible file descriptor */
wolfSSL 13:f67a6c6013ca 1376 int eof; /* eof flag */
wolfSSL 13:f67a6c6013ca 1377 byte type; /* method type */
wolfSSL 13:f67a6c6013ca 1378 byte close; /* close flag */
wolfSSL 13:f67a6c6013ca 1379 };
wolfSSL 13:f67a6c6013ca 1380
wolfSSL 13:f67a6c6013ca 1381
wolfSSL 13:f67a6c6013ca 1382 /* wolfSSL method type */
wolfSSL 13:f67a6c6013ca 1383 struct WOLFSSL_METHOD {
wolfSSL 13:f67a6c6013ca 1384 ProtocolVersion version;
wolfSSL 13:f67a6c6013ca 1385 byte side; /* connection side, server or client */
wolfSSL 13:f67a6c6013ca 1386 byte downgrade; /* whether to downgrade version, default no */
wolfSSL 13:f67a6c6013ca 1387 };
wolfSSL 13:f67a6c6013ca 1388
wolfSSL 13:f67a6c6013ca 1389 /* wolfSSL buffer type - internal uses "buffer" type */
wolfSSL 13:f67a6c6013ca 1390 typedef WOLFSSL_BUFFER_INFO buffer;
wolfSSL 13:f67a6c6013ca 1391
wolfSSL 13:f67a6c6013ca 1392
wolfSSL 13:f67a6c6013ca 1393 /* defaults to client */
wolfSSL 13:f67a6c6013ca 1394 WOLFSSL_LOCAL void InitSSL_Method(WOLFSSL_METHOD*, ProtocolVersion);
wolfSSL 13:f67a6c6013ca 1395
wolfSSL 13:f67a6c6013ca 1396 /* for sniffer */
wolfSSL 13:f67a6c6013ca 1397 WOLFSSL_LOCAL int DoFinished(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
wolfSSL 13:f67a6c6013ca 1398 word32 size, word32 totalSz, int sniff);
wolfSSL 13:f67a6c6013ca 1399 WOLFSSL_LOCAL int DoApplicationData(WOLFSSL* ssl, byte* input, word32* inOutIdx);
wolfSSL 13:f67a6c6013ca 1400 /* TLS v1.3 needs these */
wolfSSL 13:f67a6c6013ca 1401 WOLFSSL_LOCAL int DoClientHello(WOLFSSL* ssl, const byte* input, word32*,
wolfSSL 13:f67a6c6013ca 1402 word32);
wolfSSL 13:f67a6c6013ca 1403 #ifdef WOLFSSL_TLS13
wolfSSL 13:f67a6c6013ca 1404 WOLFSSL_LOCAL int DoTls13ClientHello(WOLFSSL* ssl, const byte* input,
wolfSSL 13:f67a6c6013ca 1405 word32* inOutIdx, word32 helloSz);
wolfSSL 13:f67a6c6013ca 1406 #endif
wolfSSL 13:f67a6c6013ca 1407 WOLFSSL_LOCAL int DoServerHello(WOLFSSL* ssl, const byte* input, word32*,
wolfSSL 13:f67a6c6013ca 1408 word32);
wolfSSL 13:f67a6c6013ca 1409 WOLFSSL_LOCAL int CheckVersion(WOLFSSL *ssl, ProtocolVersion pv);
wolfSSL 13:f67a6c6013ca 1410 WOLFSSL_LOCAL void PickHashSigAlgo(WOLFSSL* ssl, const byte* hashSigAlgo,
wolfSSL 13:f67a6c6013ca 1411 word32 hashSigAlgoSz);
wolfSSL 13:f67a6c6013ca 1412 WOLFSSL_LOCAL int DecodePrivateKey(WOLFSSL *ssl, word16* length);
wolfSSL 13:f67a6c6013ca 1413 WOLFSSL_LOCAL void FreeKeyExchange(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 1414 WOLFSSL_LOCAL int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx, word32 size);
wolfSSL 13:f67a6c6013ca 1415 WOLFSSL_LOCAL int MatchDomainName(const char* pattern, int len, const char* str);
wolfSSL 13:f67a6c6013ca 1416 #ifndef NO_CERTS
wolfSSL 13:f67a6c6013ca 1417 WOLFSSL_LOCAL int CheckAltNames(DecodedCert* dCert, char* domain);
wolfSSL 13:f67a6c6013ca 1418 #endif
wolfSSL 13:f67a6c6013ca 1419 WOLFSSL_LOCAL int CreateTicket(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 1420 WOLFSSL_LOCAL int HashOutputRaw(WOLFSSL* ssl, const byte* output, int sz);
wolfSSL 13:f67a6c6013ca 1421 WOLFSSL_LOCAL int HashOutput(WOLFSSL* ssl, const byte* output, int sz,
wolfSSL 13:f67a6c6013ca 1422 int ivSz);
wolfSSL 13:f67a6c6013ca 1423 WOLFSSL_LOCAL int HashInput(WOLFSSL* ssl, const byte* input, int sz);
wolfSSL 13:f67a6c6013ca 1424 #if defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || defined (WOLFSSL_HAPROXY)
wolfSSL 13:f67a6c6013ca 1425 WOLFSSL_LOCAL int SNI_Callback(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 1426 #endif
wolfSSL 13:f67a6c6013ca 1427 #ifdef WOLFSSL_TLS13
wolfSSL 13:f67a6c6013ca 1428 WOLFSSL_LOCAL int DecryptTls13(WOLFSSL* ssl, byte* output, const byte* input,
wolfSSL 13:f67a6c6013ca 1429 word16 sz);
wolfSSL 13:f67a6c6013ca 1430 WOLFSSL_LOCAL int DoTls13HandShakeMsgType(WOLFSSL* ssl, byte* input,
wolfSSL 13:f67a6c6013ca 1431 word32* inOutIdx, byte type,
wolfSSL 13:f67a6c6013ca 1432 word32 size, word32 totalSz);
wolfSSL 13:f67a6c6013ca 1433 WOLFSSL_LOCAL int DoTls13HandShakeMsg(WOLFSSL* ssl, byte* input,
wolfSSL 13:f67a6c6013ca 1434 word32* inOutIdx, word32 totalSz);
wolfSSL 13:f67a6c6013ca 1435 WOLFSSL_LOCAL int DoTls13ServerHello(WOLFSSL* ssl, const byte* input,
wolfSSL 13:f67a6c6013ca 1436 word32* inOutIdx, word32 helloSz);
wolfSSL 13:f67a6c6013ca 1437 #endif
wolfSSL 13:f67a6c6013ca 1438
wolfSSL 13:f67a6c6013ca 1439 #ifndef NO_CERTS
wolfSSL 13:f67a6c6013ca 1440 /* wolfSSL DER buffer */
wolfSSL 13:f67a6c6013ca 1441 typedef struct DerBuffer {
wolfSSL 13:f67a6c6013ca 1442 byte* buffer;
wolfSSL 13:f67a6c6013ca 1443 void* heap;
wolfSSL 13:f67a6c6013ca 1444 word32 length;
wolfSSL 13:f67a6c6013ca 1445 int type; /* enum CertType */
wolfSSL 13:f67a6c6013ca 1446 int dynType; /* DYNAMIC_TYPE_* */
wolfSSL 13:f67a6c6013ca 1447 } DerBuffer;
wolfSSL 13:f67a6c6013ca 1448 #endif /* !NO_CERTS */
wolfSSL 13:f67a6c6013ca 1449
wolfSSL 13:f67a6c6013ca 1450
wolfSSL 13:f67a6c6013ca 1451 enum {
wolfSSL 13:f67a6c6013ca 1452 FORCED_FREE = 1,
wolfSSL 13:f67a6c6013ca 1453 NO_FORCED_FREE = 0
wolfSSL 13:f67a6c6013ca 1454 };
wolfSSL 13:f67a6c6013ca 1455
wolfSSL 13:f67a6c6013ca 1456
wolfSSL 13:f67a6c6013ca 1457 /* only use compression extra if using compression */
wolfSSL 13:f67a6c6013ca 1458 #ifdef HAVE_LIBZ
wolfSSL 13:f67a6c6013ca 1459 #define COMP_EXTRA MAX_COMP_EXTRA
wolfSSL 13:f67a6c6013ca 1460 #else
wolfSSL 13:f67a6c6013ca 1461 #define COMP_EXTRA 0
wolfSSL 13:f67a6c6013ca 1462 #endif
wolfSSL 13:f67a6c6013ca 1463
wolfSSL 13:f67a6c6013ca 1464 /* only the sniffer needs space in the buffer for extra MTU record(s) */
wolfSSL 13:f67a6c6013ca 1465 #ifdef WOLFSSL_SNIFFER
wolfSSL 13:f67a6c6013ca 1466 #define MTU_EXTRA MAX_MTU * 3
wolfSSL 13:f67a6c6013ca 1467 #else
wolfSSL 13:f67a6c6013ca 1468 #define MTU_EXTRA 0
wolfSSL 13:f67a6c6013ca 1469 #endif
wolfSSL 13:f67a6c6013ca 1470
wolfSSL 13:f67a6c6013ca 1471
wolfSSL 13:f67a6c6013ca 1472 /* embedded callbacks require large static buffers, make sure on */
wolfSSL 13:f67a6c6013ca 1473 #ifdef WOLFSSL_CALLBACKS
wolfSSL 13:f67a6c6013ca 1474 #undef LARGE_STATIC_BUFFERS
wolfSSL 13:f67a6c6013ca 1475 #define LARGE_STATIC_BUFFERS
wolfSSL 13:f67a6c6013ca 1476 #endif
wolfSSL 13:f67a6c6013ca 1477
wolfSSL 13:f67a6c6013ca 1478
wolfSSL 13:f67a6c6013ca 1479 /* give user option to use 16K static buffers */
wolfSSL 13:f67a6c6013ca 1480 #if defined(LARGE_STATIC_BUFFERS)
wolfSSL 13:f67a6c6013ca 1481 #define RECORD_SIZE MAX_RECORD_SIZE
wolfSSL 13:f67a6c6013ca 1482 #else
wolfSSL 13:f67a6c6013ca 1483 #ifdef WOLFSSL_DTLS
wolfSSL 13:f67a6c6013ca 1484 #define RECORD_SIZE MAX_MTU
wolfSSL 13:f67a6c6013ca 1485 #else
wolfSSL 13:f67a6c6013ca 1486 #define RECORD_SIZE 128
wolfSSL 13:f67a6c6013ca 1487 #endif
wolfSSL 13:f67a6c6013ca 1488 #endif
wolfSSL 13:f67a6c6013ca 1489
wolfSSL 13:f67a6c6013ca 1490
wolfSSL 13:f67a6c6013ca 1491 /* user option to turn off 16K output option */
wolfSSL 13:f67a6c6013ca 1492 /* if using small static buffers (default) and SSL_write tries to write data
wolfSSL 13:f67a6c6013ca 1493 larger than the record we have, dynamically get it, unless user says only
wolfSSL 13:f67a6c6013ca 1494 write in static buffer chunks */
wolfSSL 13:f67a6c6013ca 1495 #ifndef STATIC_CHUNKS_ONLY
wolfSSL 13:f67a6c6013ca 1496 #define OUTPUT_RECORD_SIZE MAX_RECORD_SIZE
wolfSSL 13:f67a6c6013ca 1497 #else
wolfSSL 13:f67a6c6013ca 1498 #define OUTPUT_RECORD_SIZE RECORD_SIZE
wolfSSL 13:f67a6c6013ca 1499 #endif
wolfSSL 13:f67a6c6013ca 1500
wolfSSL 13:f67a6c6013ca 1501 /* wolfSSL input buffer
wolfSSL 13:f67a6c6013ca 1502
wolfSSL 13:f67a6c6013ca 1503 RFC 2246:
wolfSSL 13:f67a6c6013ca 1504
wolfSSL 13:f67a6c6013ca 1505 length
wolfSSL 13:f67a6c6013ca 1506 The length (in bytes) of the following TLSPlaintext.fragment.
wolfSSL 13:f67a6c6013ca 1507 The length should not exceed 2^14.
wolfSSL 13:f67a6c6013ca 1508 */
wolfSSL 13:f67a6c6013ca 1509 #if defined(LARGE_STATIC_BUFFERS)
wolfSSL 13:f67a6c6013ca 1510 #define STATIC_BUFFER_LEN RECORD_HEADER_SZ + RECORD_SIZE + COMP_EXTRA + \
wolfSSL 13:f67a6c6013ca 1511 MTU_EXTRA + MAX_MSG_EXTRA
wolfSSL 13:f67a6c6013ca 1512 #else
wolfSSL 13:f67a6c6013ca 1513 /* don't fragment memory from the record header */
wolfSSL 13:f67a6c6013ca 1514 #define STATIC_BUFFER_LEN RECORD_HEADER_SZ
wolfSSL 13:f67a6c6013ca 1515 #endif
wolfSSL 13:f67a6c6013ca 1516
wolfSSL 13:f67a6c6013ca 1517 typedef struct {
wolfSSL 13:f67a6c6013ca 1518 ALIGN16 byte staticBuffer[STATIC_BUFFER_LEN];
wolfSSL 13:f67a6c6013ca 1519 byte* buffer; /* place holder for static or dynamic buffer */
wolfSSL 13:f67a6c6013ca 1520 word32 length; /* total buffer length used */
wolfSSL 13:f67a6c6013ca 1521 word32 idx; /* idx to part of length already consumed */
wolfSSL 13:f67a6c6013ca 1522 word32 bufferSize; /* current buffer size */
wolfSSL 13:f67a6c6013ca 1523 byte dynamicFlag; /* dynamic memory currently in use */
wolfSSL 13:f67a6c6013ca 1524 byte offset; /* alignment offset attempt */
wolfSSL 13:f67a6c6013ca 1525 } bufferStatic;
wolfSSL 13:f67a6c6013ca 1526
wolfSSL 13:f67a6c6013ca 1527 /* Cipher Suites holder */
wolfSSL 13:f67a6c6013ca 1528 typedef struct Suites {
wolfSSL 13:f67a6c6013ca 1529 word16 suiteSz; /* suite length in bytes */
wolfSSL 13:f67a6c6013ca 1530 word16 hashSigAlgoSz; /* SigAlgo extension length in bytes */
wolfSSL 13:f67a6c6013ca 1531 byte suites[WOLFSSL_MAX_SUITE_SZ];
wolfSSL 13:f67a6c6013ca 1532 byte hashSigAlgo[HELLO_EXT_SIGALGO_MAX]; /* sig/algo to offer */
wolfSSL 13:f67a6c6013ca 1533 byte setSuites; /* user set suites from default */
wolfSSL 13:f67a6c6013ca 1534 byte hashAlgo; /* selected hash algorithm */
wolfSSL 13:f67a6c6013ca 1535 byte sigAlgo; /* selected sig algorithm */
wolfSSL 13:f67a6c6013ca 1536 } Suites;
wolfSSL 13:f67a6c6013ca 1537
wolfSSL 13:f67a6c6013ca 1538
wolfSSL 13:f67a6c6013ca 1539 WOLFSSL_LOCAL void InitSuitesHashSigAlgo(Suites* suites, int haveECDSAsig,
wolfSSL 13:f67a6c6013ca 1540 int haveRSAsig, int haveAnon,
wolfSSL 13:f67a6c6013ca 1541 int tls1_2, int keySz);
wolfSSL 13:f67a6c6013ca 1542 WOLFSSL_LOCAL void InitSuites(Suites*, ProtocolVersion, int, word16, word16,
wolfSSL 13:f67a6c6013ca 1543 word16, word16, word16, word16, word16, int);
wolfSSL 13:f67a6c6013ca 1544 WOLFSSL_LOCAL int MatchSuite(WOLFSSL* ssl, Suites* peerSuites);
wolfSSL 13:f67a6c6013ca 1545 WOLFSSL_LOCAL int SetCipherList(WOLFSSL_CTX*, Suites*, const char* list);
wolfSSL 13:f67a6c6013ca 1546
wolfSSL 13:f67a6c6013ca 1547 #ifndef PSK_TYPES_DEFINED
wolfSSL 13:f67a6c6013ca 1548 typedef unsigned int (*wc_psk_client_callback)(WOLFSSL*, const char*, char*,
wolfSSL 13:f67a6c6013ca 1549 unsigned int, unsigned char*, unsigned int);
wolfSSL 13:f67a6c6013ca 1550 typedef unsigned int (*wc_psk_server_callback)(WOLFSSL*, const char*,
wolfSSL 13:f67a6c6013ca 1551 unsigned char*, unsigned int);
wolfSSL 13:f67a6c6013ca 1552 #endif /* PSK_TYPES_DEFINED */
wolfSSL 13:f67a6c6013ca 1553 #ifdef WOLFSSL_DTLS
wolfSSL 13:f67a6c6013ca 1554 typedef int (*wc_dtls_export)(WOLFSSL* ssl,
wolfSSL 13:f67a6c6013ca 1555 unsigned char* exportBuffer, unsigned int sz, void* userCtx);
wolfSSL 13:f67a6c6013ca 1556 #endif
wolfSSL 13:f67a6c6013ca 1557
wolfSSL 13:f67a6c6013ca 1558
wolfSSL 13:f67a6c6013ca 1559 /* wolfSSL Cipher type just points back to SSL */
wolfSSL 13:f67a6c6013ca 1560 struct WOLFSSL_CIPHER {
wolfSSL 13:f67a6c6013ca 1561 WOLFSSL* ssl;
wolfSSL 13:f67a6c6013ca 1562 };
wolfSSL 13:f67a6c6013ca 1563
wolfSSL 13:f67a6c6013ca 1564
wolfSSL 13:f67a6c6013ca 1565 typedef struct OcspEntry OcspEntry;
wolfSSL 13:f67a6c6013ca 1566
wolfSSL 13:f67a6c6013ca 1567 #ifdef NO_SHA
wolfSSL 13:f67a6c6013ca 1568 #define OCSP_DIGEST_SIZE SHA256_DIGEST_SIZE
wolfSSL 13:f67a6c6013ca 1569 #else
wolfSSL 13:f67a6c6013ca 1570 #define OCSP_DIGEST_SIZE SHA_DIGEST_SIZE
wolfSSL 13:f67a6c6013ca 1571 #endif
wolfSSL 13:f67a6c6013ca 1572
wolfSSL 13:f67a6c6013ca 1573 #ifdef NO_ASN
wolfSSL 13:f67a6c6013ca 1574 /* no_asn won't have */
wolfSSL 13:f67a6c6013ca 1575 typedef struct CertStatus CertStatus;
wolfSSL 13:f67a6c6013ca 1576 #endif
wolfSSL 13:f67a6c6013ca 1577
wolfSSL 13:f67a6c6013ca 1578 struct OcspEntry {
wolfSSL 13:f67a6c6013ca 1579 OcspEntry* next; /* next entry */
wolfSSL 13:f67a6c6013ca 1580 byte issuerHash[OCSP_DIGEST_SIZE]; /* issuer hash */
wolfSSL 13:f67a6c6013ca 1581 byte issuerKeyHash[OCSP_DIGEST_SIZE]; /* issuer public key hash */
wolfSSL 13:f67a6c6013ca 1582 CertStatus* status; /* OCSP response list */
wolfSSL 13:f67a6c6013ca 1583 int totalStatus; /* number on list */
wolfSSL 13:f67a6c6013ca 1584 };
wolfSSL 13:f67a6c6013ca 1585
wolfSSL 13:f67a6c6013ca 1586
wolfSSL 13:f67a6c6013ca 1587 #ifndef HAVE_OCSP
wolfSSL 13:f67a6c6013ca 1588 typedef struct WOLFSSL_OCSP WOLFSSL_OCSP;
wolfSSL 13:f67a6c6013ca 1589 #endif
wolfSSL 13:f67a6c6013ca 1590
wolfSSL 13:f67a6c6013ca 1591 /* wolfSSL OCSP controller */
wolfSSL 13:f67a6c6013ca 1592 struct WOLFSSL_OCSP {
wolfSSL 13:f67a6c6013ca 1593 WOLFSSL_CERT_MANAGER* cm; /* pointer back to cert manager */
wolfSSL 13:f67a6c6013ca 1594 OcspEntry* ocspList; /* OCSP response list */
wolfSSL 13:f67a6c6013ca 1595 wolfSSL_Mutex ocspLock; /* OCSP list lock */
wolfSSL 13:f67a6c6013ca 1596 #if defined(WOLFSSL_NGINX) || defined (WOLFSSL_HAPROXY)
wolfSSL 13:f67a6c6013ca 1597 int(*statusCb)(WOLFSSL*, void*);
wolfSSL 13:f67a6c6013ca 1598 #endif
wolfSSL 13:f67a6c6013ca 1599 };
wolfSSL 13:f67a6c6013ca 1600
wolfSSL 13:f67a6c6013ca 1601 #ifndef MAX_DATE_SIZE
wolfSSL 13:f67a6c6013ca 1602 #define MAX_DATE_SIZE 32
wolfSSL 13:f67a6c6013ca 1603 #endif
wolfSSL 13:f67a6c6013ca 1604
wolfSSL 13:f67a6c6013ca 1605 typedef struct CRL_Entry CRL_Entry;
wolfSSL 13:f67a6c6013ca 1606
wolfSSL 13:f67a6c6013ca 1607 #ifdef NO_SHA
wolfSSL 13:f67a6c6013ca 1608 #define CRL_DIGEST_SIZE SHA256_DIGEST_SIZE
wolfSSL 13:f67a6c6013ca 1609 #else
wolfSSL 13:f67a6c6013ca 1610 #define CRL_DIGEST_SIZE SHA_DIGEST_SIZE
wolfSSL 13:f67a6c6013ca 1611 #endif
wolfSSL 13:f67a6c6013ca 1612
wolfSSL 13:f67a6c6013ca 1613 #ifdef NO_ASN
wolfSSL 13:f67a6c6013ca 1614 typedef struct RevokedCert RevokedCert;
wolfSSL 13:f67a6c6013ca 1615 #endif
wolfSSL 13:f67a6c6013ca 1616
wolfSSL 13:f67a6c6013ca 1617 /* Complete CRL */
wolfSSL 13:f67a6c6013ca 1618 struct CRL_Entry {
wolfSSL 13:f67a6c6013ca 1619 CRL_Entry* next; /* next entry */
wolfSSL 13:f67a6c6013ca 1620 byte issuerHash[CRL_DIGEST_SIZE]; /* issuer hash */
wolfSSL 13:f67a6c6013ca 1621 /* byte crlHash[CRL_DIGEST_SIZE]; raw crl data hash */
wolfSSL 13:f67a6c6013ca 1622 /* restore the hash here if needed for optimized comparisons */
wolfSSL 13:f67a6c6013ca 1623 byte lastDate[MAX_DATE_SIZE]; /* last date updated */
wolfSSL 13:f67a6c6013ca 1624 byte nextDate[MAX_DATE_SIZE]; /* next update date */
wolfSSL 13:f67a6c6013ca 1625 byte lastDateFormat; /* last date format */
wolfSSL 13:f67a6c6013ca 1626 byte nextDateFormat; /* next date format */
wolfSSL 13:f67a6c6013ca 1627 RevokedCert* certs; /* revoked cert list */
wolfSSL 13:f67a6c6013ca 1628 int totalCerts; /* number on list */
wolfSSL 13:f67a6c6013ca 1629 int verified;
wolfSSL 13:f67a6c6013ca 1630 byte* toBeSigned;
wolfSSL 13:f67a6c6013ca 1631 word32 tbsSz;
wolfSSL 13:f67a6c6013ca 1632 byte* signature;
wolfSSL 13:f67a6c6013ca 1633 word32 signatureSz;
wolfSSL 13:f67a6c6013ca 1634 word32 signatureOID;
wolfSSL 13:f67a6c6013ca 1635 #if !defined(NO_SKID) && defined(CRL_SKID_READY)
wolfSSL 13:f67a6c6013ca 1636 byte extAuthKeyIdSet;
wolfSSL 13:f67a6c6013ca 1637 byte extAuthKeyId[KEYID_SIZE];
wolfSSL 13:f67a6c6013ca 1638 #endif
wolfSSL 13:f67a6c6013ca 1639 };
wolfSSL 13:f67a6c6013ca 1640
wolfSSL 13:f67a6c6013ca 1641
wolfSSL 13:f67a6c6013ca 1642 typedef struct CRL_Monitor CRL_Monitor;
wolfSSL 13:f67a6c6013ca 1643
wolfSSL 13:f67a6c6013ca 1644 /* CRL directory monitor */
wolfSSL 13:f67a6c6013ca 1645 struct CRL_Monitor {
wolfSSL 13:f67a6c6013ca 1646 char* path; /* full dir path, if valid pointer we're using */
wolfSSL 13:f67a6c6013ca 1647 int type; /* PEM or ASN1 type */
wolfSSL 13:f67a6c6013ca 1648 };
wolfSSL 13:f67a6c6013ca 1649
wolfSSL 13:f67a6c6013ca 1650
wolfSSL 13:f67a6c6013ca 1651 #if defined(HAVE_CRL) && defined(NO_FILESYSTEM)
wolfSSL 13:f67a6c6013ca 1652 #undef HAVE_CRL_MONITOR
wolfSSL 13:f67a6c6013ca 1653 #endif
wolfSSL 13:f67a6c6013ca 1654
wolfSSL 13:f67a6c6013ca 1655 /* wolfSSL CRL controller */
wolfSSL 13:f67a6c6013ca 1656 struct WOLFSSL_CRL {
wolfSSL 13:f67a6c6013ca 1657 WOLFSSL_CERT_MANAGER* cm; /* pointer back to cert manager */
wolfSSL 13:f67a6c6013ca 1658 CRL_Entry* crlList; /* our CRL list */
wolfSSL 13:f67a6c6013ca 1659 #ifdef HAVE_CRL_IO
wolfSSL 13:f67a6c6013ca 1660 CbCrlIO crlIOCb;
wolfSSL 13:f67a6c6013ca 1661 #endif
wolfSSL 13:f67a6c6013ca 1662 wolfSSL_Mutex crlLock; /* CRL list lock */
wolfSSL 13:f67a6c6013ca 1663 CRL_Monitor monitors[2]; /* PEM and DER possible */
wolfSSL 13:f67a6c6013ca 1664 #ifdef HAVE_CRL_MONITOR
wolfSSL 13:f67a6c6013ca 1665 pthread_cond_t cond; /* condition to signal setup */
wolfSSL 13:f67a6c6013ca 1666 pthread_t tid; /* monitoring thread */
wolfSSL 13:f67a6c6013ca 1667 int mfd; /* monitor fd, -1 if no init yet */
wolfSSL 13:f67a6c6013ca 1668 int setup; /* thread is setup predicate */
wolfSSL 13:f67a6c6013ca 1669 #endif
wolfSSL 13:f67a6c6013ca 1670 void* heap; /* heap hint for dynamic memory */
wolfSSL 13:f67a6c6013ca 1671 };
wolfSSL 13:f67a6c6013ca 1672
wolfSSL 13:f67a6c6013ca 1673
wolfSSL 13:f67a6c6013ca 1674 #ifdef NO_ASN
wolfSSL 13:f67a6c6013ca 1675 typedef struct Signer Signer;
wolfSSL 13:f67a6c6013ca 1676 #ifdef WOLFSSL_TRUST_PEER_CERT
wolfSSL 13:f67a6c6013ca 1677 typedef struct TrustedPeerCert TrustedPeerCert;
wolfSSL 13:f67a6c6013ca 1678 #endif
wolfSSL 13:f67a6c6013ca 1679 #endif
wolfSSL 13:f67a6c6013ca 1680
wolfSSL 13:f67a6c6013ca 1681
wolfSSL 13:f67a6c6013ca 1682 #ifndef CA_TABLE_SIZE
wolfSSL 13:f67a6c6013ca 1683 #define CA_TABLE_SIZE 11
wolfSSL 13:f67a6c6013ca 1684 #endif
wolfSSL 13:f67a6c6013ca 1685 #ifdef WOLFSSL_TRUST_PEER_CERT
wolfSSL 13:f67a6c6013ca 1686 #define TP_TABLE_SIZE 11
wolfSSL 13:f67a6c6013ca 1687 #endif
wolfSSL 13:f67a6c6013ca 1688
wolfSSL 13:f67a6c6013ca 1689 /* wolfSSL Certificate Manager */
wolfSSL 13:f67a6c6013ca 1690 struct WOLFSSL_CERT_MANAGER {
wolfSSL 13:f67a6c6013ca 1691 Signer* caTable[CA_TABLE_SIZE]; /* the CA signer table */
wolfSSL 13:f67a6c6013ca 1692 void* heap; /* heap helper */
wolfSSL 13:f67a6c6013ca 1693 #ifdef WOLFSSL_TRUST_PEER_CERT
wolfSSL 13:f67a6c6013ca 1694 TrustedPeerCert* tpTable[TP_TABLE_SIZE]; /* table of trusted peer certs */
wolfSSL 13:f67a6c6013ca 1695 wolfSSL_Mutex tpLock; /* trusted peer list lock */
wolfSSL 13:f67a6c6013ca 1696 #endif
wolfSSL 13:f67a6c6013ca 1697 WOLFSSL_CRL* crl; /* CRL checker */
wolfSSL 13:f67a6c6013ca 1698 WOLFSSL_OCSP* ocsp; /* OCSP checker */
wolfSSL 13:f67a6c6013ca 1699 #if !defined(NO_WOLFSSL_SERVER) && (defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
wolfSSL 13:f67a6c6013ca 1700 || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2))
wolfSSL 13:f67a6c6013ca 1701 WOLFSSL_OCSP* ocsp_stapling; /* OCSP checker for OCSP stapling */
wolfSSL 13:f67a6c6013ca 1702 #endif
wolfSSL 13:f67a6c6013ca 1703 char* ocspOverrideURL; /* use this responder */
wolfSSL 13:f67a6c6013ca 1704 void* ocspIOCtx; /* I/O callback CTX */
wolfSSL 13:f67a6c6013ca 1705 CallbackCACache caCacheCallback; /* CA cache addition callback */
wolfSSL 13:f67a6c6013ca 1706 CbMissingCRL cbMissingCRL; /* notify through cb of missing crl */
wolfSSL 13:f67a6c6013ca 1707 CbOCSPIO ocspIOCb; /* I/O callback for OCSP lookup */
wolfSSL 13:f67a6c6013ca 1708 CbOCSPRespFree ocspRespFreeCb; /* Frees OCSP Response from IO Cb */
wolfSSL 13:f67a6c6013ca 1709 wolfSSL_Mutex caLock; /* CA list lock */
wolfSSL 13:f67a6c6013ca 1710 byte crlEnabled; /* is CRL on ? */
wolfSSL 13:f67a6c6013ca 1711 byte crlCheckAll; /* always leaf, but all ? */
wolfSSL 13:f67a6c6013ca 1712 byte ocspEnabled; /* is OCSP on ? */
wolfSSL 13:f67a6c6013ca 1713 byte ocspCheckAll; /* always leaf, but all ? */
wolfSSL 13:f67a6c6013ca 1714 byte ocspSendNonce; /* send the OCSP nonce ? */
wolfSSL 13:f67a6c6013ca 1715 byte ocspUseOverrideURL; /* ignore cert's responder, override */
wolfSSL 13:f67a6c6013ca 1716 byte ocspStaplingEnabled; /* is OCSP Stapling on ? */
wolfSSL 13:f67a6c6013ca 1717
wolfSSL 13:f67a6c6013ca 1718 #ifndef NO_RSA
wolfSSL 13:f67a6c6013ca 1719 short minRsaKeySz; /* minimum allowed RSA key size */
wolfSSL 13:f67a6c6013ca 1720 #endif
wolfSSL 13:f67a6c6013ca 1721 #if defined(HAVE_ECC) || defined(HAVE_ED25519)
wolfSSL 13:f67a6c6013ca 1722 short minEccKeySz; /* minimum allowed ECC key size */
wolfSSL 13:f67a6c6013ca 1723 #endif
wolfSSL 13:f67a6c6013ca 1724 };
wolfSSL 13:f67a6c6013ca 1725
wolfSSL 13:f67a6c6013ca 1726 WOLFSSL_LOCAL int CM_SaveCertCache(WOLFSSL_CERT_MANAGER*, const char*);
wolfSSL 13:f67a6c6013ca 1727 WOLFSSL_LOCAL int CM_RestoreCertCache(WOLFSSL_CERT_MANAGER*, const char*);
wolfSSL 13:f67a6c6013ca 1728 WOLFSSL_LOCAL int CM_MemSaveCertCache(WOLFSSL_CERT_MANAGER*, void*, int, int*);
wolfSSL 13:f67a6c6013ca 1729 WOLFSSL_LOCAL int CM_MemRestoreCertCache(WOLFSSL_CERT_MANAGER*, const void*, int);
wolfSSL 13:f67a6c6013ca 1730 WOLFSSL_LOCAL int CM_GetCertCacheMemSize(WOLFSSL_CERT_MANAGER*);
wolfSSL 13:f67a6c6013ca 1731
wolfSSL 13:f67a6c6013ca 1732 /* wolfSSL Sock Addr */
wolfSSL 13:f67a6c6013ca 1733 struct WOLFSSL_SOCKADDR {
wolfSSL 13:f67a6c6013ca 1734 unsigned int sz; /* sockaddr size */
wolfSSL 13:f67a6c6013ca 1735 void* sa; /* pointer to the sockaddr_in or sockaddr_in6 */
wolfSSL 13:f67a6c6013ca 1736 };
wolfSSL 13:f67a6c6013ca 1737
wolfSSL 13:f67a6c6013ca 1738 typedef struct WOLFSSL_DTLS_CTX {
wolfSSL 13:f67a6c6013ca 1739 WOLFSSL_SOCKADDR peer;
wolfSSL 13:f67a6c6013ca 1740 int rfd;
wolfSSL 13:f67a6c6013ca 1741 int wfd;
wolfSSL 13:f67a6c6013ca 1742 } WOLFSSL_DTLS_CTX;
wolfSSL 13:f67a6c6013ca 1743
wolfSSL 13:f67a6c6013ca 1744
wolfSSL 13:f67a6c6013ca 1745 typedef struct WOLFSSL_DTLS_PEERSEQ {
wolfSSL 13:f67a6c6013ca 1746 word32 window[WOLFSSL_DTLS_WINDOW_WORDS];
wolfSSL 13:f67a6c6013ca 1747 /* Sliding window for current epoch */
wolfSSL 13:f67a6c6013ca 1748 word16 nextEpoch; /* Expected epoch in next record */
wolfSSL 13:f67a6c6013ca 1749 word16 nextSeq_hi; /* Expected sequence in next record */
wolfSSL 13:f67a6c6013ca 1750 word32 nextSeq_lo;
wolfSSL 13:f67a6c6013ca 1751
wolfSSL 13:f67a6c6013ca 1752 word32 prevWindow[WOLFSSL_DTLS_WINDOW_WORDS];
wolfSSL 13:f67a6c6013ca 1753 /* Sliding window for old epoch */
wolfSSL 13:f67a6c6013ca 1754 word32 prevSeq_lo;
wolfSSL 13:f67a6c6013ca 1755 word16 prevSeq_hi; /* Next sequence in allowed old epoch */
wolfSSL 13:f67a6c6013ca 1756
wolfSSL 13:f67a6c6013ca 1757 #ifdef WOLFSSL_MULTICAST
wolfSSL 13:f67a6c6013ca 1758 word16 peerId;
wolfSSL 13:f67a6c6013ca 1759 word32 highwaterMark;
wolfSSL 13:f67a6c6013ca 1760 #endif
wolfSSL 13:f67a6c6013ca 1761 } WOLFSSL_DTLS_PEERSEQ;
wolfSSL 13:f67a6c6013ca 1762
wolfSSL 13:f67a6c6013ca 1763
wolfSSL 13:f67a6c6013ca 1764 #define MAX_WRITE_IV_SZ 16 /* max size of client/server write_IV */
wolfSSL 13:f67a6c6013ca 1765
wolfSSL 13:f67a6c6013ca 1766 /* keys and secrets
wolfSSL 13:f67a6c6013ca 1767 * keep as a constant size (no additional ifdefs) for session export */
wolfSSL 13:f67a6c6013ca 1768 typedef struct Keys {
wolfSSL 13:f67a6c6013ca 1769 byte client_write_MAC_secret[MAX_DIGEST_SIZE]; /* max sizes */
wolfSSL 13:f67a6c6013ca 1770 byte server_write_MAC_secret[MAX_DIGEST_SIZE];
wolfSSL 13:f67a6c6013ca 1771 byte client_write_key[AES_256_KEY_SIZE]; /* max sizes */
wolfSSL 13:f67a6c6013ca 1772 byte server_write_key[AES_256_KEY_SIZE];
wolfSSL 13:f67a6c6013ca 1773 byte client_write_IV[MAX_WRITE_IV_SZ]; /* max sizes */
wolfSSL 13:f67a6c6013ca 1774 byte server_write_IV[MAX_WRITE_IV_SZ];
wolfSSL 13:f67a6c6013ca 1775 #if defined(HAVE_AEAD) || defined(WOLFSSL_SESSION_EXPORT)
wolfSSL 13:f67a6c6013ca 1776 byte aead_exp_IV[AEAD_MAX_EXP_SZ];
wolfSSL 13:f67a6c6013ca 1777 byte aead_enc_imp_IV[AEAD_MAX_IMP_SZ];
wolfSSL 13:f67a6c6013ca 1778 byte aead_dec_imp_IV[AEAD_MAX_IMP_SZ];
wolfSSL 13:f67a6c6013ca 1779 #endif
wolfSSL 13:f67a6c6013ca 1780
wolfSSL 13:f67a6c6013ca 1781 word32 peer_sequence_number_hi;
wolfSSL 13:f67a6c6013ca 1782 word32 peer_sequence_number_lo;
wolfSSL 13:f67a6c6013ca 1783 word32 sequence_number_hi;
wolfSSL 13:f67a6c6013ca 1784 word32 sequence_number_lo;
wolfSSL 13:f67a6c6013ca 1785
wolfSSL 13:f67a6c6013ca 1786 #ifdef WOLFSSL_DTLS
wolfSSL 13:f67a6c6013ca 1787 word16 curEpoch; /* Received epoch in current record */
wolfSSL 13:f67a6c6013ca 1788 word16 curSeq_hi; /* Received sequence in current record */
wolfSSL 13:f67a6c6013ca 1789 word32 curSeq_lo;
wolfSSL 13:f67a6c6013ca 1790 #ifdef WOLFSSL_MULTICAST
wolfSSL 13:f67a6c6013ca 1791 byte curPeerId; /* Received peer group ID in current record */
wolfSSL 13:f67a6c6013ca 1792 #endif
wolfSSL 13:f67a6c6013ca 1793 WOLFSSL_DTLS_PEERSEQ peerSeq[WOLFSSL_DTLS_PEERSEQ_SZ];
wolfSSL 13:f67a6c6013ca 1794
wolfSSL 13:f67a6c6013ca 1795 word16 dtls_peer_handshake_number;
wolfSSL 13:f67a6c6013ca 1796 word16 dtls_expected_peer_handshake_number;
wolfSSL 13:f67a6c6013ca 1797
wolfSSL 13:f67a6c6013ca 1798 word16 dtls_epoch; /* Current epoch */
wolfSSL 13:f67a6c6013ca 1799 word16 dtls_sequence_number_hi; /* Current epoch */
wolfSSL 13:f67a6c6013ca 1800 word32 dtls_sequence_number_lo;
wolfSSL 13:f67a6c6013ca 1801 word16 dtls_prev_sequence_number_hi; /* Previous epoch */
wolfSSL 13:f67a6c6013ca 1802 word32 dtls_prev_sequence_number_lo;
wolfSSL 13:f67a6c6013ca 1803 word16 dtls_handshake_number; /* Current tx handshake seq */
wolfSSL 13:f67a6c6013ca 1804 #endif
wolfSSL 13:f67a6c6013ca 1805
wolfSSL 13:f67a6c6013ca 1806 word32 encryptSz; /* last size of encrypted data */
wolfSSL 13:f67a6c6013ca 1807 word32 padSz; /* how much to advance after decrypt part */
wolfSSL 13:f67a6c6013ca 1808 byte encryptionOn; /* true after change cipher spec */
wolfSSL 13:f67a6c6013ca 1809 byte decryptedCur; /* only decrypt current record once */
wolfSSL 13:f67a6c6013ca 1810 #ifdef WOLFSSL_TLS13
wolfSSL 13:f67a6c6013ca 1811 byte updateResponseReq:1; /* KeyUpdate response from peer required. */
wolfSSL 13:f67a6c6013ca 1812 byte keyUpdateRespond:1; /* KeyUpdate is to be responded to. */
wolfSSL 13:f67a6c6013ca 1813 #endif
wolfSSL 13:f67a6c6013ca 1814 } Keys;
wolfSSL 13:f67a6c6013ca 1815
wolfSSL 13:f67a6c6013ca 1816
wolfSSL 13:f67a6c6013ca 1817
wolfSSL 13:f67a6c6013ca 1818 /** TLS Extensions - RFC 6066 */
wolfSSL 13:f67a6c6013ca 1819 #ifdef HAVE_TLS_EXTENSIONS
wolfSSL 13:f67a6c6013ca 1820
wolfSSL 13:f67a6c6013ca 1821 typedef enum {
wolfSSL 13:f67a6c6013ca 1822 TLSX_SERVER_NAME = 0x0000, /* a.k.a. SNI */
wolfSSL 13:f67a6c6013ca 1823 TLSX_MAX_FRAGMENT_LENGTH = 0x0001,
wolfSSL 13:f67a6c6013ca 1824 TLSX_TRUNCATED_HMAC = 0x0004,
wolfSSL 13:f67a6c6013ca 1825 TLSX_STATUS_REQUEST = 0x0005, /* a.k.a. OCSP stapling */
wolfSSL 13:f67a6c6013ca 1826 TLSX_SUPPORTED_GROUPS = 0x000a, /* a.k.a. Supported Curves */
wolfSSL 13:f67a6c6013ca 1827 TLSX_SIGNATURE_ALGORITHMS = 0x000d,
wolfSSL 13:f67a6c6013ca 1828 TLSX_APPLICATION_LAYER_PROTOCOL = 0x0010, /* a.k.a. ALPN */
wolfSSL 13:f67a6c6013ca 1829 TLSX_STATUS_REQUEST_V2 = 0x0011, /* a.k.a. OCSP stapling v2 */
wolfSSL 13:f67a6c6013ca 1830 TLSX_QUANTUM_SAFE_HYBRID = 0x0018, /* a.k.a. QSH */
wolfSSL 13:f67a6c6013ca 1831 TLSX_SESSION_TICKET = 0x0023,
wolfSSL 13:f67a6c6013ca 1832 #ifdef WOLFSSL_TLS13
wolfSSL 13:f67a6c6013ca 1833 TLSX_KEY_SHARE = 0x0028,
wolfSSL 13:f67a6c6013ca 1834 #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
wolfSSL 13:f67a6c6013ca 1835 TLSX_PRE_SHARED_KEY = 0x0029,
wolfSSL 13:f67a6c6013ca 1836 #endif
wolfSSL 13:f67a6c6013ca 1837 #ifdef WOLFSSL_EARLY_DATA
wolfSSL 13:f67a6c6013ca 1838 TLSX_EARLY_DATA = 0x002a,
wolfSSL 13:f67a6c6013ca 1839 #endif
wolfSSL 13:f67a6c6013ca 1840 TLSX_SUPPORTED_VERSIONS = 0x002b,
wolfSSL 13:f67a6c6013ca 1841 TLSX_COOKIE = 0x002c,
wolfSSL 13:f67a6c6013ca 1842 #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
wolfSSL 13:f67a6c6013ca 1843 TLSX_PSK_KEY_EXCHANGE_MODES = 0x002d,
wolfSSL 13:f67a6c6013ca 1844 #endif
wolfSSL 13:f67a6c6013ca 1845 #ifdef WOLFSSL_POST_HANDSHAKE_AUTH
wolfSSL 13:f67a6c6013ca 1846 TLSX_POST_HANDSHAKE_AUTH = 0x0031,
wolfSSL 13:f67a6c6013ca 1847 #endif
wolfSSL 13:f67a6c6013ca 1848 #endif
wolfSSL 13:f67a6c6013ca 1849 TLSX_RENEGOTIATION_INFO = 0xff01
wolfSSL 13:f67a6c6013ca 1850 } TLSX_Type;
wolfSSL 13:f67a6c6013ca 1851
wolfSSL 13:f67a6c6013ca 1852 typedef struct TLSX {
wolfSSL 13:f67a6c6013ca 1853 TLSX_Type type; /* Extension Type */
wolfSSL 13:f67a6c6013ca 1854 void* data; /* Extension Data */
wolfSSL 13:f67a6c6013ca 1855 word32 val; /* Extension Value */
wolfSSL 13:f67a6c6013ca 1856 byte resp; /* IsResponse Flag */
wolfSSL 13:f67a6c6013ca 1857 struct TLSX* next; /* List Behavior */
wolfSSL 13:f67a6c6013ca 1858 } TLSX;
wolfSSL 13:f67a6c6013ca 1859
wolfSSL 13:f67a6c6013ca 1860 WOLFSSL_LOCAL TLSX* TLSX_Find(TLSX* list, TLSX_Type type);
wolfSSL 13:f67a6c6013ca 1861 WOLFSSL_LOCAL void TLSX_FreeAll(TLSX* list, void* heap);
wolfSSL 13:f67a6c6013ca 1862 WOLFSSL_LOCAL int TLSX_SupportExtensions(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 1863 WOLFSSL_LOCAL int TLSX_PopulateExtensions(WOLFSSL* ssl, byte isRequest);
wolfSSL 13:f67a6c6013ca 1864
wolfSSL 13:f67a6c6013ca 1865 #ifndef NO_WOLFSSL_CLIENT
wolfSSL 13:f67a6c6013ca 1866 WOLFSSL_LOCAL word16 TLSX_GetRequestSize(WOLFSSL* ssl, byte msgType);
wolfSSL 13:f67a6c6013ca 1867 WOLFSSL_LOCAL word16 TLSX_WriteRequest(WOLFSSL* ssl, byte* output,
wolfSSL 13:f67a6c6013ca 1868 byte msgType);
wolfSSL 13:f67a6c6013ca 1869 #endif
wolfSSL 13:f67a6c6013ca 1870
wolfSSL 13:f67a6c6013ca 1871 #ifndef NO_WOLFSSL_SERVER
wolfSSL 13:f67a6c6013ca 1872 WOLFSSL_LOCAL word16 TLSX_GetResponseSize(WOLFSSL* ssl, byte msgType);
wolfSSL 13:f67a6c6013ca 1873 WOLFSSL_LOCAL word16 TLSX_WriteResponse(WOLFSSL* ssl, byte* output,
wolfSSL 13:f67a6c6013ca 1874 byte msgType);
wolfSSL 13:f67a6c6013ca 1875 #endif
wolfSSL 13:f67a6c6013ca 1876
wolfSSL 13:f67a6c6013ca 1877 WOLFSSL_LOCAL int TLSX_Parse(WOLFSSL* ssl, byte* input, word16 length,
wolfSSL 13:f67a6c6013ca 1878 byte msgType, Suites *suites);
wolfSSL 13:f67a6c6013ca 1879
wolfSSL 13:f67a6c6013ca 1880 #elif defined(HAVE_SNI) \
wolfSSL 13:f67a6c6013ca 1881 || defined(HAVE_MAX_FRAGMENT) \
wolfSSL 13:f67a6c6013ca 1882 || defined(HAVE_TRUNCATED_HMAC) \
wolfSSL 13:f67a6c6013ca 1883 || defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
wolfSSL 13:f67a6c6013ca 1884 || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) \
wolfSSL 13:f67a6c6013ca 1885 || defined(HAVE_SUPPORTED_CURVES) \
wolfSSL 13:f67a6c6013ca 1886 || defined(HAVE_ALPN) \
wolfSSL 13:f67a6c6013ca 1887 || defined(HAVE_QSH) \
wolfSSL 13:f67a6c6013ca 1888 || defined(HAVE_SESSION_TICKET) \
wolfSSL 13:f67a6c6013ca 1889 || defined(HAVE_SECURE_RENEGOTIATION) \
wolfSSL 13:f67a6c6013ca 1890 || defined(HAVE_SERVER_RENEGOTIATION_INFO)
wolfSSL 13:f67a6c6013ca 1891
wolfSSL 13:f67a6c6013ca 1892 #error Using TLS extensions requires HAVE_TLS_EXTENSIONS to be defined.
wolfSSL 13:f67a6c6013ca 1893
wolfSSL 13:f67a6c6013ca 1894 #endif /* HAVE_TLS_EXTENSIONS */
wolfSSL 13:f67a6c6013ca 1895
wolfSSL 13:f67a6c6013ca 1896 /** Server Name Indication - RFC 6066 (session 3) */
wolfSSL 13:f67a6c6013ca 1897 #ifdef HAVE_SNI
wolfSSL 13:f67a6c6013ca 1898
wolfSSL 13:f67a6c6013ca 1899 typedef struct SNI {
wolfSSL 13:f67a6c6013ca 1900 byte type; /* SNI Type */
wolfSSL 13:f67a6c6013ca 1901 union { char* host_name; } data; /* SNI Data */
wolfSSL 13:f67a6c6013ca 1902 struct SNI* next; /* List Behavior */
wolfSSL 13:f67a6c6013ca 1903 #ifndef NO_WOLFSSL_SERVER
wolfSSL 13:f67a6c6013ca 1904 byte options; /* Behavior options */
wolfSSL 13:f67a6c6013ca 1905 byte status; /* Matching result */
wolfSSL 13:f67a6c6013ca 1906 #endif
wolfSSL 13:f67a6c6013ca 1907 } SNI;
wolfSSL 13:f67a6c6013ca 1908
wolfSSL 13:f67a6c6013ca 1909 WOLFSSL_LOCAL int TLSX_UseSNI(TLSX** extensions, byte type, const void* data,
wolfSSL 13:f67a6c6013ca 1910 word16 size, void* heap);
wolfSSL 13:f67a6c6013ca 1911
wolfSSL 13:f67a6c6013ca 1912 #ifndef NO_WOLFSSL_SERVER
wolfSSL 13:f67a6c6013ca 1913 WOLFSSL_LOCAL void TLSX_SNI_SetOptions(TLSX* extensions, byte type,
wolfSSL 13:f67a6c6013ca 1914 byte options);
wolfSSL 13:f67a6c6013ca 1915 WOLFSSL_LOCAL byte TLSX_SNI_Status(TLSX* extensions, byte type);
wolfSSL 13:f67a6c6013ca 1916 WOLFSSL_LOCAL word16 TLSX_SNI_GetRequest(TLSX* extensions, byte type,
wolfSSL 13:f67a6c6013ca 1917 void** data);
wolfSSL 13:f67a6c6013ca 1918 WOLFSSL_LOCAL int TLSX_SNI_GetFromBuffer(const byte* buffer, word32 bufferSz,
wolfSSL 13:f67a6c6013ca 1919 byte type, byte* sni, word32* inOutSz);
wolfSSL 13:f67a6c6013ca 1920 #endif
wolfSSL 13:f67a6c6013ca 1921
wolfSSL 13:f67a6c6013ca 1922 #endif /* HAVE_SNI */
wolfSSL 13:f67a6c6013ca 1923
wolfSSL 13:f67a6c6013ca 1924 /* Application-Layer Protocol Negotiation - RFC 7301 */
wolfSSL 13:f67a6c6013ca 1925 #ifdef HAVE_ALPN
wolfSSL 13:f67a6c6013ca 1926 typedef struct ALPN {
wolfSSL 13:f67a6c6013ca 1927 char* protocol_name; /* ALPN protocol name */
wolfSSL 13:f67a6c6013ca 1928 struct ALPN* next; /* List Behavior */
wolfSSL 13:f67a6c6013ca 1929 byte options; /* Behavior options */
wolfSSL 13:f67a6c6013ca 1930 byte negotiated; /* ALPN protocol negotiated or not */
wolfSSL 13:f67a6c6013ca 1931 } ALPN;
wolfSSL 13:f67a6c6013ca 1932
wolfSSL 13:f67a6c6013ca 1933 WOLFSSL_LOCAL int TLSX_ALPN_GetRequest(TLSX* extensions,
wolfSSL 13:f67a6c6013ca 1934 void** data, word16 *dataSz);
wolfSSL 13:f67a6c6013ca 1935
wolfSSL 13:f67a6c6013ca 1936 WOLFSSL_LOCAL int TLSX_UseALPN(TLSX** extensions, const void* data,
wolfSSL 13:f67a6c6013ca 1937 word16 size, byte options, void* heap);
wolfSSL 13:f67a6c6013ca 1938
wolfSSL 13:f67a6c6013ca 1939 WOLFSSL_LOCAL int TLSX_ALPN_SetOptions(TLSX** extensions, const byte option);
wolfSSL 13:f67a6c6013ca 1940
wolfSSL 13:f67a6c6013ca 1941 #endif /* HAVE_ALPN */
wolfSSL 13:f67a6c6013ca 1942
wolfSSL 13:f67a6c6013ca 1943 /** Maximum Fragment Length Negotiation - RFC 6066 (session 4) */
wolfSSL 13:f67a6c6013ca 1944 #ifdef HAVE_MAX_FRAGMENT
wolfSSL 13:f67a6c6013ca 1945
wolfSSL 13:f67a6c6013ca 1946 WOLFSSL_LOCAL int TLSX_UseMaxFragment(TLSX** extensions, byte mfl, void* heap);
wolfSSL 13:f67a6c6013ca 1947
wolfSSL 13:f67a6c6013ca 1948 #endif /* HAVE_MAX_FRAGMENT */
wolfSSL 13:f67a6c6013ca 1949
wolfSSL 13:f67a6c6013ca 1950 /** Truncated HMAC - RFC 6066 (session 7) */
wolfSSL 13:f67a6c6013ca 1951 #ifdef HAVE_TRUNCATED_HMAC
wolfSSL 13:f67a6c6013ca 1952
wolfSSL 13:f67a6c6013ca 1953 WOLFSSL_LOCAL int TLSX_UseTruncatedHMAC(TLSX** extensions, void* heap);
wolfSSL 13:f67a6c6013ca 1954
wolfSSL 13:f67a6c6013ca 1955 #endif /* HAVE_TRUNCATED_HMAC */
wolfSSL 13:f67a6c6013ca 1956
wolfSSL 13:f67a6c6013ca 1957 /** Certificate Status Request - RFC 6066 (session 8) */
wolfSSL 13:f67a6c6013ca 1958 #ifdef HAVE_CERTIFICATE_STATUS_REQUEST
wolfSSL 13:f67a6c6013ca 1959
wolfSSL 13:f67a6c6013ca 1960 typedef struct {
wolfSSL 13:f67a6c6013ca 1961 byte status_type;
wolfSSL 13:f67a6c6013ca 1962 byte options;
wolfSSL 13:f67a6c6013ca 1963 union {
wolfSSL 13:f67a6c6013ca 1964 OcspRequest ocsp;
wolfSSL 13:f67a6c6013ca 1965 } request;
wolfSSL 13:f67a6c6013ca 1966 } CertificateStatusRequest;
wolfSSL 13:f67a6c6013ca 1967
wolfSSL 13:f67a6c6013ca 1968 WOLFSSL_LOCAL int TLSX_UseCertificateStatusRequest(TLSX** extensions,
wolfSSL 13:f67a6c6013ca 1969 byte status_type, byte options, void* heap, int devId);
wolfSSL 13:f67a6c6013ca 1970 #ifndef NO_CERTS
wolfSSL 13:f67a6c6013ca 1971 WOLFSSL_LOCAL int TLSX_CSR_InitRequest(TLSX* extensions, DecodedCert* cert,
wolfSSL 13:f67a6c6013ca 1972 void* heap);
wolfSSL 13:f67a6c6013ca 1973 #endif
wolfSSL 13:f67a6c6013ca 1974 WOLFSSL_LOCAL void* TLSX_CSR_GetRequest(TLSX* extensions);
wolfSSL 13:f67a6c6013ca 1975 WOLFSSL_LOCAL int TLSX_CSR_ForceRequest(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 1976
wolfSSL 13:f67a6c6013ca 1977 #endif
wolfSSL 13:f67a6c6013ca 1978
wolfSSL 13:f67a6c6013ca 1979 /** Certificate Status Request v2 - RFC 6961 */
wolfSSL 13:f67a6c6013ca 1980 #ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
wolfSSL 13:f67a6c6013ca 1981
wolfSSL 13:f67a6c6013ca 1982 typedef struct CSRIv2 {
wolfSSL 13:f67a6c6013ca 1983 byte status_type;
wolfSSL 13:f67a6c6013ca 1984 byte options;
wolfSSL 13:f67a6c6013ca 1985 word16 requests;
wolfSSL 13:f67a6c6013ca 1986 union {
wolfSSL 13:f67a6c6013ca 1987 OcspRequest ocsp[1 + MAX_CHAIN_DEPTH];
wolfSSL 13:f67a6c6013ca 1988 } request;
wolfSSL 13:f67a6c6013ca 1989 struct CSRIv2* next;
wolfSSL 13:f67a6c6013ca 1990 } CertificateStatusRequestItemV2;
wolfSSL 13:f67a6c6013ca 1991
wolfSSL 13:f67a6c6013ca 1992 WOLFSSL_LOCAL int TLSX_UseCertificateStatusRequestV2(TLSX** extensions,
wolfSSL 13:f67a6c6013ca 1993 byte status_type, byte options, void* heap, int devId);
wolfSSL 13:f67a6c6013ca 1994 #ifndef NO_CERTS
wolfSSL 13:f67a6c6013ca 1995 WOLFSSL_LOCAL int TLSX_CSR2_InitRequests(TLSX* extensions, DecodedCert* cert,
wolfSSL 13:f67a6c6013ca 1996 byte isPeer, void* heap);
wolfSSL 13:f67a6c6013ca 1997 #endif
wolfSSL 13:f67a6c6013ca 1998 WOLFSSL_LOCAL void* TLSX_CSR2_GetRequest(TLSX* extensions, byte status_type,
wolfSSL 13:f67a6c6013ca 1999 byte index);
wolfSSL 13:f67a6c6013ca 2000 WOLFSSL_LOCAL int TLSX_CSR2_ForceRequest(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 2001
wolfSSL 13:f67a6c6013ca 2002 #endif
wolfSSL 13:f67a6c6013ca 2003
wolfSSL 13:f67a6c6013ca 2004 /** Supported Elliptic Curves - RFC 4492 (session 4) */
wolfSSL 13:f67a6c6013ca 2005 #ifdef HAVE_SUPPORTED_CURVES
wolfSSL 13:f67a6c6013ca 2006
wolfSSL 13:f67a6c6013ca 2007 typedef struct EllipticCurve {
wolfSSL 13:f67a6c6013ca 2008 word16 name; /* CurveNames */
wolfSSL 13:f67a6c6013ca 2009 struct EllipticCurve* next; /* List Behavior */
wolfSSL 13:f67a6c6013ca 2010 } EllipticCurve;
wolfSSL 13:f67a6c6013ca 2011
wolfSSL 13:f67a6c6013ca 2012 WOLFSSL_LOCAL int TLSX_UseSupportedCurve(TLSX** extensions, word16 name,
wolfSSL 13:f67a6c6013ca 2013 void* heap);
wolfSSL 13:f67a6c6013ca 2014
wolfSSL 13:f67a6c6013ca 2015 #ifndef NO_WOLFSSL_SERVER
wolfSSL 13:f67a6c6013ca 2016 WOLFSSL_LOCAL int TLSX_ValidateEllipticCurves(WOLFSSL* ssl, byte first,
wolfSSL 13:f67a6c6013ca 2017 byte second);
wolfSSL 13:f67a6c6013ca 2018 #endif
wolfSSL 13:f67a6c6013ca 2019
wolfSSL 13:f67a6c6013ca 2020 #endif /* HAVE_SUPPORTED_CURVES */
wolfSSL 13:f67a6c6013ca 2021
wolfSSL 13:f67a6c6013ca 2022 /** Renegotiation Indication - RFC 5746 */
wolfSSL 13:f67a6c6013ca 2023 #if defined(HAVE_SECURE_RENEGOTIATION) \
wolfSSL 13:f67a6c6013ca 2024 || defined(HAVE_SERVER_RENEGOTIATION_INFO)
wolfSSL 13:f67a6c6013ca 2025
wolfSSL 13:f67a6c6013ca 2026 enum key_cache_state {
wolfSSL 13:f67a6c6013ca 2027 SCR_CACHE_NULL = 0, /* empty / begin state */
wolfSSL 13:f67a6c6013ca 2028 SCR_CACHE_NEEDED, /* need to cache keys */
wolfSSL 13:f67a6c6013ca 2029 SCR_CACHE_COPY, /* we have a cached copy */
wolfSSL 13:f67a6c6013ca 2030 SCR_CACHE_PARTIAL, /* partial restore to real keys */
wolfSSL 13:f67a6c6013ca 2031 SCR_CACHE_COMPLETE /* complete restore to real keys */
wolfSSL 13:f67a6c6013ca 2032 };
wolfSSL 13:f67a6c6013ca 2033
wolfSSL 13:f67a6c6013ca 2034 /* Additional Connection State according to rfc5746 section 3.1 */
wolfSSL 13:f67a6c6013ca 2035 typedef struct SecureRenegotiation {
wolfSSL 13:f67a6c6013ca 2036 byte enabled; /* secure_renegotiation flag in rfc */
wolfSSL 13:f67a6c6013ca 2037 byte startScr; /* server requested client to start scr */
wolfSSL 13:f67a6c6013ca 2038 enum key_cache_state cache_status; /* track key cache state */
wolfSSL 13:f67a6c6013ca 2039 byte client_verify_data[TLS_FINISHED_SZ]; /* cached */
wolfSSL 13:f67a6c6013ca 2040 byte server_verify_data[TLS_FINISHED_SZ]; /* cached */
wolfSSL 13:f67a6c6013ca 2041 byte subject_hash[SHA_DIGEST_SIZE]; /* peer cert hash */
wolfSSL 13:f67a6c6013ca 2042 Keys tmp_keys; /* can't overwrite real keys yet */
wolfSSL 13:f67a6c6013ca 2043 } SecureRenegotiation;
wolfSSL 13:f67a6c6013ca 2044
wolfSSL 13:f67a6c6013ca 2045 WOLFSSL_LOCAL int TLSX_UseSecureRenegotiation(TLSX** extensions, void* heap);
wolfSSL 13:f67a6c6013ca 2046
wolfSSL 13:f67a6c6013ca 2047 #ifdef HAVE_SERVER_RENEGOTIATION_INFO
wolfSSL 13:f67a6c6013ca 2048 WOLFSSL_LOCAL int TLSX_AddEmptyRenegotiationInfo(TLSX** extensions, void* heap);
wolfSSL 13:f67a6c6013ca 2049 #endif
wolfSSL 13:f67a6c6013ca 2050
wolfSSL 13:f67a6c6013ca 2051 #endif /* HAVE_SECURE_RENEGOTIATION */
wolfSSL 13:f67a6c6013ca 2052
wolfSSL 13:f67a6c6013ca 2053 /** Session Ticket - RFC 5077 (session 3.2) */
wolfSSL 13:f67a6c6013ca 2054 #ifdef HAVE_SESSION_TICKET
wolfSSL 13:f67a6c6013ca 2055
wolfSSL 13:f67a6c6013ca 2056 typedef struct SessionTicket {
wolfSSL 13:f67a6c6013ca 2057 word32 lifetime;
wolfSSL 13:f67a6c6013ca 2058 #ifdef WOLFSSL_TLS13
wolfSSL 13:f67a6c6013ca 2059 word64 seen;
wolfSSL 13:f67a6c6013ca 2060 word32 ageAdd;
wolfSSL 13:f67a6c6013ca 2061 #endif
wolfSSL 13:f67a6c6013ca 2062 byte* data;
wolfSSL 13:f67a6c6013ca 2063 word16 size;
wolfSSL 13:f67a6c6013ca 2064 } SessionTicket;
wolfSSL 13:f67a6c6013ca 2065
wolfSSL 13:f67a6c6013ca 2066 WOLFSSL_LOCAL int TLSX_UseSessionTicket(TLSX** extensions,
wolfSSL 13:f67a6c6013ca 2067 SessionTicket* ticket, void* heap);
wolfSSL 13:f67a6c6013ca 2068 WOLFSSL_LOCAL SessionTicket* TLSX_SessionTicket_Create(word32 lifetime,
wolfSSL 13:f67a6c6013ca 2069 byte* data, word16 size, void* heap);
wolfSSL 13:f67a6c6013ca 2070 WOLFSSL_LOCAL void TLSX_SessionTicket_Free(SessionTicket* ticket, void* heap);
wolfSSL 13:f67a6c6013ca 2071
wolfSSL 13:f67a6c6013ca 2072 #endif /* HAVE_SESSION_TICKET */
wolfSSL 13:f67a6c6013ca 2073
wolfSSL 13:f67a6c6013ca 2074 /** Quantum-Safe-Hybrid - draft-whyte-qsh-tls12-00 */
wolfSSL 13:f67a6c6013ca 2075 #ifdef HAVE_QSH
wolfSSL 13:f67a6c6013ca 2076
wolfSSL 13:f67a6c6013ca 2077 typedef struct QSHScheme {
wolfSSL 13:f67a6c6013ca 2078 struct QSHScheme* next; /* List Behavior */
wolfSSL 13:f67a6c6013ca 2079 byte* PK;
wolfSSL 13:f67a6c6013ca 2080 word16 name; /* QSHScheme Names */
wolfSSL 13:f67a6c6013ca 2081 word16 PKLen;
wolfSSL 13:f67a6c6013ca 2082 } QSHScheme;
wolfSSL 13:f67a6c6013ca 2083
wolfSSL 13:f67a6c6013ca 2084 typedef struct QSHkey {
wolfSSL 13:f67a6c6013ca 2085 struct QSHKey* next;
wolfSSL 13:f67a6c6013ca 2086 word16 name;
wolfSSL 13:f67a6c6013ca 2087 buffer pub;
wolfSSL 13:f67a6c6013ca 2088 buffer pri;
wolfSSL 13:f67a6c6013ca 2089 } QSHKey;
wolfSSL 13:f67a6c6013ca 2090
wolfSSL 13:f67a6c6013ca 2091 typedef struct QSHSecret {
wolfSSL 13:f67a6c6013ca 2092 QSHScheme* list;
wolfSSL 13:f67a6c6013ca 2093 buffer* SerSi;
wolfSSL 13:f67a6c6013ca 2094 buffer* CliSi;
wolfSSL 13:f67a6c6013ca 2095 } QSHSecret;
wolfSSL 13:f67a6c6013ca 2096
wolfSSL 13:f67a6c6013ca 2097 /* used in key exchange during handshake */
wolfSSL 13:f67a6c6013ca 2098 WOLFSSL_LOCAL int TLSX_QSHCipher_Parse(WOLFSSL* ssl, const byte* input,
wolfSSL 13:f67a6c6013ca 2099 word16 length, byte isServer);
wolfSSL 13:f67a6c6013ca 2100 WOLFSSL_LOCAL word16 TLSX_QSHPK_Write(QSHScheme* list, byte* output);
wolfSSL 13:f67a6c6013ca 2101 WOLFSSL_LOCAL word16 TLSX_QSH_GetSize(QSHScheme* list, byte isRequest);
wolfSSL 13:f67a6c6013ca 2102
wolfSSL 13:f67a6c6013ca 2103 /* used by api for setting a specific QSH scheme */
wolfSSL 13:f67a6c6013ca 2104 WOLFSSL_LOCAL int TLSX_UseQSHScheme(TLSX** extensions, word16 name,
wolfSSL 13:f67a6c6013ca 2105 byte* pKey, word16 pKeySz, void* heap);
wolfSSL 13:f67a6c6013ca 2106
wolfSSL 13:f67a6c6013ca 2107 /* used when parsing in QSHCipher structs */
wolfSSL 13:f67a6c6013ca 2108 WOLFSSL_LOCAL int QSH_Decrypt(QSHKey* key, byte* in, word32 szIn,
wolfSSL 13:f67a6c6013ca 2109 byte* out, word16* szOut);
wolfSSL 13:f67a6c6013ca 2110 #ifndef NO_WOLFSSL_SERVER
wolfSSL 13:f67a6c6013ca 2111 WOLFSSL_LOCAL int TLSX_ValidateQSHScheme(TLSX** extensions, word16 name);
wolfSSL 13:f67a6c6013ca 2112 #endif
wolfSSL 13:f67a6c6013ca 2113
wolfSSL 13:f67a6c6013ca 2114 #endif /* HAVE_QSH */
wolfSSL 13:f67a6c6013ca 2115
wolfSSL 13:f67a6c6013ca 2116 #ifdef WOLFSSL_TLS13
wolfSSL 13:f67a6c6013ca 2117 /* Cookie extension information - cookie data. */
wolfSSL 13:f67a6c6013ca 2118 typedef struct Cookie {
wolfSSL 13:f67a6c6013ca 2119 word16 len;
wolfSSL 13:f67a6c6013ca 2120 byte data;
wolfSSL 13:f67a6c6013ca 2121 } Cookie;
wolfSSL 13:f67a6c6013ca 2122
wolfSSL 13:f67a6c6013ca 2123 WOLFSSL_LOCAL int TLSX_Cookie_Use(WOLFSSL* ssl, byte* data, word16 len,
wolfSSL 13:f67a6c6013ca 2124 byte* mac, byte macSz, int resp);
wolfSSL 13:f67a6c6013ca 2125
wolfSSL 13:f67a6c6013ca 2126
wolfSSL 13:f67a6c6013ca 2127 /* Key Share - TLS v1.3 Specification */
wolfSSL 13:f67a6c6013ca 2128
wolfSSL 13:f67a6c6013ca 2129 /* The KeyShare extension information - entry in a linked list. */
wolfSSL 13:f67a6c6013ca 2130 typedef struct KeyShareEntry {
wolfSSL 13:f67a6c6013ca 2131 word16 group; /* NamedGroup */
wolfSSL 13:f67a6c6013ca 2132 byte* ke; /* Key exchange data */
wolfSSL 13:f67a6c6013ca 2133 word32 keLen; /* Key exchange data length */
wolfSSL 13:f67a6c6013ca 2134 void* key; /* Private key */
wolfSSL 13:f67a6c6013ca 2135 word32 keyLen; /* Private key length */
wolfSSL 13:f67a6c6013ca 2136 struct KeyShareEntry* next; /* List pointer */
wolfSSL 13:f67a6c6013ca 2137 } KeyShareEntry;
wolfSSL 13:f67a6c6013ca 2138
wolfSSL 13:f67a6c6013ca 2139 WOLFSSL_LOCAL int TLSX_KeyShare_Use(WOLFSSL* ssl, word16 group, word16 len,
wolfSSL 13:f67a6c6013ca 2140 byte* data, KeyShareEntry **kse);
wolfSSL 13:f67a6c6013ca 2141 WOLFSSL_LOCAL int TLSX_KeyShare_Empty(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 2142 WOLFSSL_LOCAL int TLSX_KeyShare_Establish(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 2143
wolfSSL 13:f67a6c6013ca 2144
wolfSSL 13:f67a6c6013ca 2145 #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
wolfSSL 13:f67a6c6013ca 2146 /* The PreSharedKey extension information - entry in a linked list. */
wolfSSL 13:f67a6c6013ca 2147 typedef struct PreSharedKey {
wolfSSL 13:f67a6c6013ca 2148 word16 identityLen; /* Length of identity */
wolfSSL 13:f67a6c6013ca 2149 byte* identity; /* PSK identity */
wolfSSL 13:f67a6c6013ca 2150 word32 ticketAge; /* Age of the ticket */
wolfSSL 13:f67a6c6013ca 2151 byte cipherSuite0; /* Cipher Suite */
wolfSSL 13:f67a6c6013ca 2152 byte cipherSuite; /* Cipher Suite */
wolfSSL 13:f67a6c6013ca 2153 word32 binderLen; /* Length of HMAC */
wolfSSL 13:f67a6c6013ca 2154 byte binder[MAX_DIGEST_SIZE]; /* HMAC of hanshake */
wolfSSL 13:f67a6c6013ca 2155 byte hmac; /* HMAC algorithm */
wolfSSL 13:f67a6c6013ca 2156 byte resumption:1; /* Resumption PSK */
wolfSSL 13:f67a6c6013ca 2157 byte chosen:1; /* Server's choice */
wolfSSL 13:f67a6c6013ca 2158 struct PreSharedKey* next; /* List pointer */
wolfSSL 13:f67a6c6013ca 2159 } PreSharedKey;
wolfSSL 13:f67a6c6013ca 2160
wolfSSL 13:f67a6c6013ca 2161 WOLFSSL_LOCAL word16 TLSX_PreSharedKey_WriteBinders(PreSharedKey* list,
wolfSSL 13:f67a6c6013ca 2162 byte* output, byte msgType);
wolfSSL 13:f67a6c6013ca 2163 WOLFSSL_LOCAL word16 TLSX_PreSharedKey_GetSizeBinders(PreSharedKey* list,
wolfSSL 13:f67a6c6013ca 2164 byte msgType);
wolfSSL 13:f67a6c6013ca 2165 WOLFSSL_LOCAL int TLSX_PreSharedKey_Use(WOLFSSL* ssl, byte* identity,
wolfSSL 13:f67a6c6013ca 2166 word16 len, word32 age, byte hmac,
wolfSSL 13:f67a6c6013ca 2167 byte cipherSuite0, byte cipherSuite,
wolfSSL 13:f67a6c6013ca 2168 byte resumption,
wolfSSL 13:f67a6c6013ca 2169 PreSharedKey **preSharedKey);
wolfSSL 13:f67a6c6013ca 2170
wolfSSL 13:f67a6c6013ca 2171 /* The possible Pre-Shared Key key exchange modes. */
wolfSSL 13:f67a6c6013ca 2172 enum PskKeyExchangeMode {
wolfSSL 13:f67a6c6013ca 2173 PSK_KE,
wolfSSL 13:f67a6c6013ca 2174 PSK_DHE_KE
wolfSSL 13:f67a6c6013ca 2175 };
wolfSSL 13:f67a6c6013ca 2176
wolfSSL 13:f67a6c6013ca 2177 /* User can define this. */
wolfSSL 13:f67a6c6013ca 2178 #ifndef WOLFSSL_DEF_PSK_CIPHER
wolfSSL 13:f67a6c6013ca 2179 #define WOLFSSL_DEF_PSK_CIPHER TLS_AES_128_GCM_SHA256
wolfSSL 13:f67a6c6013ca 2180 #endif
wolfSSL 13:f67a6c6013ca 2181
wolfSSL 13:f67a6c6013ca 2182 WOLFSSL_LOCAL int TLSX_PskKeModes_Use(WOLFSSL* ssl, byte modes);
wolfSSL 13:f67a6c6013ca 2183
wolfSSL 13:f67a6c6013ca 2184 #ifdef WOLFSSL_EARLY_DATA
wolfSSL 13:f67a6c6013ca 2185 WOLFSSL_LOCAL int TLSX_EarlyData_Use(WOLFSSL* ssl, word32 max);
wolfSSL 13:f67a6c6013ca 2186 #endif
wolfSSL 13:f67a6c6013ca 2187 #endif /* HAVE_SESSION_TICKET || !NO_PSK */
wolfSSL 13:f67a6c6013ca 2188
wolfSSL 13:f67a6c6013ca 2189
wolfSSL 13:f67a6c6013ca 2190 /* The types of keys to derive for. */
wolfSSL 13:f67a6c6013ca 2191 enum DeriveKeyType {
wolfSSL 13:f67a6c6013ca 2192 no_key,
wolfSSL 13:f67a6c6013ca 2193 early_data_key,
wolfSSL 13:f67a6c6013ca 2194 handshake_key,
wolfSSL 13:f67a6c6013ca 2195 traffic_key,
wolfSSL 13:f67a6c6013ca 2196 update_traffic_key
wolfSSL 13:f67a6c6013ca 2197 };
wolfSSL 13:f67a6c6013ca 2198
wolfSSL 13:f67a6c6013ca 2199 /* The key update request values for KeyUpdate message. */
wolfSSL 13:f67a6c6013ca 2200 enum KeyUpdateRequest {
wolfSSL 13:f67a6c6013ca 2201 update_not_requested,
wolfSSL 13:f67a6c6013ca 2202 update_requested
wolfSSL 13:f67a6c6013ca 2203 };
wolfSSL 13:f67a6c6013ca 2204 #endif /* WOLFSSL_TLS13 */
wolfSSL 13:f67a6c6013ca 2205
wolfSSL 13:f67a6c6013ca 2206
wolfSSL 13:f67a6c6013ca 2207 /* wolfSSL context type */
wolfSSL 13:f67a6c6013ca 2208 struct WOLFSSL_CTX {
wolfSSL 13:f67a6c6013ca 2209 WOLFSSL_METHOD* method;
wolfSSL 13:f67a6c6013ca 2210 #ifdef SINGLE_THREADED
wolfSSL 13:f67a6c6013ca 2211 WC_RNG* rng; /* to be shared with WOLFSSL w/o locking */
wolfSSL 13:f67a6c6013ca 2212 #endif
wolfSSL 13:f67a6c6013ca 2213 wolfSSL_Mutex countMutex; /* reference count mutex */
wolfSSL 13:f67a6c6013ca 2214 int refCount; /* reference count */
wolfSSL 13:f67a6c6013ca 2215 int err; /* error code in case of mutex not created */
wolfSSL 13:f67a6c6013ca 2216 #ifndef NO_DH
wolfSSL 13:f67a6c6013ca 2217 buffer serverDH_P;
wolfSSL 13:f67a6c6013ca 2218 buffer serverDH_G;
wolfSSL 13:f67a6c6013ca 2219 #endif
wolfSSL 13:f67a6c6013ca 2220 #ifndef NO_CERTS
wolfSSL 13:f67a6c6013ca 2221 DerBuffer* certificate;
wolfSSL 13:f67a6c6013ca 2222 DerBuffer* certChain;
wolfSSL 13:f67a6c6013ca 2223 /* chain after self, in DER, with leading size for each cert */
wolfSSL 13:f67a6c6013ca 2224 #ifdef OPENSSL_EXTRA
wolfSSL 13:f67a6c6013ca 2225 STACK_OF(WOLFSSL_X509_NAME)* ca_names;
wolfSSL 13:f67a6c6013ca 2226 #endif
wolfSSL 13:f67a6c6013ca 2227 #if defined(WOLFSSL_NGINX) || defined (WOLFSSL_HAPROXY)
wolfSSL 13:f67a6c6013ca 2228 STACK_OF(WOLFSSL_X509)* x509Chain;
wolfSSL 13:f67a6c6013ca 2229 #endif
wolfSSL 13:f67a6c6013ca 2230 #ifdef WOLFSSL_TLS13
wolfSSL 13:f67a6c6013ca 2231 int certChainCnt;
wolfSSL 13:f67a6c6013ca 2232 #endif
wolfSSL 13:f67a6c6013ca 2233 DerBuffer* privateKey;
wolfSSL 13:f67a6c6013ca 2234 byte privateKeyType;
wolfSSL 13:f67a6c6013ca 2235 int privateKeySz;
wolfSSL 13:f67a6c6013ca 2236 WOLFSSL_CERT_MANAGER* cm; /* our cert manager, ctx owns SSL will use */
wolfSSL 13:f67a6c6013ca 2237 #endif
wolfSSL 13:f67a6c6013ca 2238 #ifdef KEEP_OUR_CERT
wolfSSL 13:f67a6c6013ca 2239 WOLFSSL_X509* ourCert; /* keep alive a X509 struct of cert */
wolfSSL 13:f67a6c6013ca 2240 int ownOurCert; /* Dispose of certificate if we own */
wolfSSL 13:f67a6c6013ca 2241 #endif
wolfSSL 13:f67a6c6013ca 2242 Suites* suites; /* make dynamic, user may not need/set */
wolfSSL 13:f67a6c6013ca 2243 void* heap; /* for user memory overrides */
wolfSSL 13:f67a6c6013ca 2244 byte verifyPeer;
wolfSSL 13:f67a6c6013ca 2245 byte verifyNone;
wolfSSL 13:f67a6c6013ca 2246 byte failNoCert;
wolfSSL 13:f67a6c6013ca 2247 byte failNoCertxPSK; /* fail if no cert with the exception of PSK*/
wolfSSL 13:f67a6c6013ca 2248 byte sessionCacheOff;
wolfSSL 13:f67a6c6013ca 2249 byte sessionCacheFlushOff;
wolfSSL 13:f67a6c6013ca 2250 #ifdef HAVE_EXT_CACHE
wolfSSL 13:f67a6c6013ca 2251 byte internalCacheOff;
wolfSSL 13:f67a6c6013ca 2252 #endif
wolfSSL 13:f67a6c6013ca 2253 byte sendVerify; /* for client side */
wolfSSL 13:f67a6c6013ca 2254 byte haveRSA; /* RSA available */
wolfSSL 13:f67a6c6013ca 2255 byte haveECC; /* ECC available */
wolfSSL 13:f67a6c6013ca 2256 byte haveDH; /* server DH parms set by user */
wolfSSL 13:f67a6c6013ca 2257 byte haveNTRU; /* server private NTRU key loaded */
wolfSSL 13:f67a6c6013ca 2258 byte haveECDSAsig; /* server cert signed w/ ECDSA */
wolfSSL 13:f67a6c6013ca 2259 byte haveStaticECC; /* static server ECC private key */
wolfSSL 13:f67a6c6013ca 2260 byte partialWrite; /* only one msg per write call */
wolfSSL 13:f67a6c6013ca 2261 byte quietShutdown; /* don't send close notify */
wolfSSL 13:f67a6c6013ca 2262 byte groupMessages; /* group handshake messages before sending */
wolfSSL 13:f67a6c6013ca 2263 byte minDowngrade; /* minimum downgrade version */
wolfSSL 13:f67a6c6013ca 2264 byte haveEMS; /* have extended master secret extension */
wolfSSL 13:f67a6c6013ca 2265 byte useClientOrder:1; /* Use client's cipher preference order */
wolfSSL 13:f67a6c6013ca 2266 #ifdef WOLFSSL_TLS13
wolfSSL 13:f67a6c6013ca 2267 byte noTicketTls13:1; /* Server won't create new Ticket */
wolfSSL 13:f67a6c6013ca 2268 byte noPskDheKe:1; /* Don't use (EC)DHE with PSK */
wolfSSL 13:f67a6c6013ca 2269 #endif
wolfSSL 13:f67a6c6013ca 2270 #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
wolfSSL 13:f67a6c6013ca 2271 byte postHandshakeAuth:1; /* Post-handshake auth supported. */
wolfSSL 13:f67a6c6013ca 2272 #endif
wolfSSL 13:f67a6c6013ca 2273 #ifdef WOLFSSL_MULTICAST
wolfSSL 13:f67a6c6013ca 2274 byte haveMcast; /* multicast requested */
wolfSSL 13:f67a6c6013ca 2275 byte mcastID; /* multicast group ID */
wolfSSL 13:f67a6c6013ca 2276 #endif
wolfSSL 13:f67a6c6013ca 2277 #if defined(WOLFSSL_SCTP) && defined(WOLFSSL_DTLS)
wolfSSL 13:f67a6c6013ca 2278 byte dtlsSctp; /* DTLS-over-SCTP mode */
wolfSSL 13:f67a6c6013ca 2279 word16 dtlsMtuSz; /* DTLS MTU size */
wolfSSL 13:f67a6c6013ca 2280 #endif
wolfSSL 13:f67a6c6013ca 2281 #ifndef NO_DH
wolfSSL 13:f67a6c6013ca 2282 word16 minDhKeySz; /* minimum DH key size */
wolfSSL 13:f67a6c6013ca 2283 #endif
wolfSSL 13:f67a6c6013ca 2284 #ifndef NO_RSA
wolfSSL 13:f67a6c6013ca 2285 short minRsaKeySz; /* minimum RSA key size */
wolfSSL 13:f67a6c6013ca 2286 #endif
wolfSSL 13:f67a6c6013ca 2287 #if defined(HAVE_ECC) || defined(HAVE_ED25519)
wolfSSL 13:f67a6c6013ca 2288 short minEccKeySz; /* minimum ECC key size */
wolfSSL 13:f67a6c6013ca 2289 #endif
wolfSSL 13:f67a6c6013ca 2290 #ifdef OPENSSL_EXTRA
wolfSSL 13:f67a6c6013ca 2291 word32 disabledCurves; /* curves disabled by user */
wolfSSL 13:f67a6c6013ca 2292 byte verifyDepth; /* maximum verification depth */
wolfSSL 13:f67a6c6013ca 2293 unsigned long mask; /* store SSL_OP_ flags */
wolfSSL 13:f67a6c6013ca 2294 #endif
wolfSSL 13:f67a6c6013ca 2295 CallbackIORecv CBIORecv;
wolfSSL 13:f67a6c6013ca 2296 CallbackIOSend CBIOSend;
wolfSSL 13:f67a6c6013ca 2297 #ifdef WOLFSSL_DTLS
wolfSSL 13:f67a6c6013ca 2298 CallbackGenCookie CBIOCookie; /* gen cookie callback */
wolfSSL 13:f67a6c6013ca 2299 wc_dtls_export dtls_export; /* export function for DTLS session */
wolfSSL 13:f67a6c6013ca 2300 #ifdef WOLFSSL_SESSION_EXPORT
wolfSSL 13:f67a6c6013ca 2301 CallbackGetPeer CBGetPeer;
wolfSSL 13:f67a6c6013ca 2302 CallbackSetPeer CBSetPeer;
wolfSSL 13:f67a6c6013ca 2303 #endif
wolfSSL 13:f67a6c6013ca 2304 #endif /* WOLFSSL_DTLS */
wolfSSL 13:f67a6c6013ca 2305 VerifyCallback verifyCallback; /* cert verification callback */
wolfSSL 13:f67a6c6013ca 2306 word32 timeout; /* session timeout */
wolfSSL 13:f67a6c6013ca 2307 #if defined(HAVE_ECC) || defined(HAVE_CURVE25519)
wolfSSL 13:f67a6c6013ca 2308 word32 ecdhCurveOID; /* curve Ecc_Sum */
wolfSSL 13:f67a6c6013ca 2309 #endif
wolfSSL 13:f67a6c6013ca 2310 #ifdef HAVE_ECC
wolfSSL 13:f67a6c6013ca 2311 word16 eccTempKeySz; /* in octets 20 - 66 */
wolfSSL 13:f67a6c6013ca 2312 word32 pkCurveOID; /* curve Ecc_Sum */
wolfSSL 13:f67a6c6013ca 2313 #endif
wolfSSL 13:f67a6c6013ca 2314 #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
wolfSSL 13:f67a6c6013ca 2315 byte havePSK; /* psk key set by user */
wolfSSL 13:f67a6c6013ca 2316 wc_psk_client_callback client_psk_cb; /* client callback */
wolfSSL 13:f67a6c6013ca 2317 wc_psk_server_callback server_psk_cb; /* server callback */
wolfSSL 13:f67a6c6013ca 2318 char server_hint[MAX_PSK_ID_LEN + NULL_TERM_LEN];
wolfSSL 13:f67a6c6013ca 2319 #endif /* HAVE_SESSION_TICKET || !NO_PSK */
wolfSSL 13:f67a6c6013ca 2320 #ifdef WOLFSSL_EARLY_DATA
wolfSSL 13:f67a6c6013ca 2321 word32 maxEarlyDataSz;
wolfSSL 13:f67a6c6013ca 2322 #endif
wolfSSL 13:f67a6c6013ca 2323 #ifdef HAVE_ANON
wolfSSL 13:f67a6c6013ca 2324 byte haveAnon; /* User wants to allow Anon suites */
wolfSSL 13:f67a6c6013ca 2325 #endif /* HAVE_ANON */
wolfSSL 13:f67a6c6013ca 2326 #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
wolfSSL 13:f67a6c6013ca 2327 pem_password_cb* passwd_cb;
wolfSSL 13:f67a6c6013ca 2328 void* userdata;
wolfSSL 13:f67a6c6013ca 2329 WOLFSSL_X509_STORE x509_store; /* points to ctx->cm */
wolfSSL 13:f67a6c6013ca 2330 byte readAhead;
wolfSSL 13:f67a6c6013ca 2331 void* userPRFArg; /* passed to prf callback */
wolfSSL 13:f67a6c6013ca 2332 #endif /* OPENSSL_EXTRA */
wolfSSL 13:f67a6c6013ca 2333 #ifdef HAVE_EX_DATA
wolfSSL 13:f67a6c6013ca 2334 void* ex_data[MAX_EX_DATA];
wolfSSL 13:f67a6c6013ca 2335 #endif
wolfSSL 13:f67a6c6013ca 2336 #if defined(HAVE_ALPN) && (defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY))
wolfSSL 13:f67a6c6013ca 2337 CallbackALPNSelect alpnSelect;
wolfSSL 13:f67a6c6013ca 2338 void* alpnSelectArg;
wolfSSL 13:f67a6c6013ca 2339 #endif
wolfSSL 13:f67a6c6013ca 2340 #if defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
wolfSSL 13:f67a6c6013ca 2341 CallbackSniRecv sniRecvCb;
wolfSSL 13:f67a6c6013ca 2342 void* sniRecvCbArg;
wolfSSL 13:f67a6c6013ca 2343 #endif
wolfSSL 13:f67a6c6013ca 2344 #if defined(WOLFSSL_MULTICAST) && defined(WOLFSSL_DTLS)
wolfSSL 13:f67a6c6013ca 2345 CallbackMcastHighwater mcastHwCb; /* Sequence number highwater callback */
wolfSSL 13:f67a6c6013ca 2346 word32 mcastFirstSeq; /* first trigger level */
wolfSSL 13:f67a6c6013ca 2347 word32 mcastSecondSeq; /* second tigger level */
wolfSSL 13:f67a6c6013ca 2348 word32 mcastMaxSeq; /* max level */
wolfSSL 13:f67a6c6013ca 2349 #endif
wolfSSL 13:f67a6c6013ca 2350 #ifdef HAVE_OCSP
wolfSSL 13:f67a6c6013ca 2351 WOLFSSL_OCSP ocsp;
wolfSSL 13:f67a6c6013ca 2352 #endif
wolfSSL 13:f67a6c6013ca 2353 int devId; /* async device id to use */
wolfSSL 13:f67a6c6013ca 2354 #ifdef HAVE_TLS_EXTENSIONS
wolfSSL 13:f67a6c6013ca 2355 TLSX* extensions; /* RFC 6066 TLS Extensions data */
wolfSSL 13:f67a6c6013ca 2356 #ifndef NO_WOLFSSL_SERVER
wolfSSL 13:f67a6c6013ca 2357 #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
wolfSSL 13:f67a6c6013ca 2358 || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
wolfSSL 13:f67a6c6013ca 2359 OcspRequest* certOcspRequest;
wolfSSL 13:f67a6c6013ca 2360 #endif
wolfSSL 13:f67a6c6013ca 2361 #if defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
wolfSSL 13:f67a6c6013ca 2362 OcspRequest* chainOcspRequest[MAX_CHAIN_DEPTH];
wolfSSL 13:f67a6c6013ca 2363 #endif
wolfSSL 13:f67a6c6013ca 2364 #endif
wolfSSL 13:f67a6c6013ca 2365 #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER)
wolfSSL 13:f67a6c6013ca 2366 SessionTicketEncCb ticketEncCb; /* enc/dec session ticket Cb */
wolfSSL 13:f67a6c6013ca 2367 void* ticketEncCtx; /* session encrypt context */
wolfSSL 13:f67a6c6013ca 2368 int ticketHint; /* ticket hint in seconds */
wolfSSL 13:f67a6c6013ca 2369 #endif
wolfSSL 13:f67a6c6013ca 2370 #ifdef HAVE_SUPPORTED_CURVES
wolfSSL 13:f67a6c6013ca 2371 byte userCurves; /* indicates user called wolfSSL_CTX_UseSupportedCurve */
wolfSSL 13:f67a6c6013ca 2372 #endif
wolfSSL 13:f67a6c6013ca 2373 #endif
wolfSSL 13:f67a6c6013ca 2374 #ifdef ATOMIC_USER
wolfSSL 13:f67a6c6013ca 2375 CallbackMacEncrypt MacEncryptCb; /* Atomic User Mac/Encrypt Cb */
wolfSSL 13:f67a6c6013ca 2376 CallbackDecryptVerify DecryptVerifyCb; /* Atomic User Decrypt/Verify Cb */
wolfSSL 13:f67a6c6013ca 2377 #endif
wolfSSL 13:f67a6c6013ca 2378 #ifdef HAVE_PK_CALLBACKS
wolfSSL 13:f67a6c6013ca 2379 #ifdef HAVE_ECC
wolfSSL 13:f67a6c6013ca 2380 CallbackEccSign EccSignCb; /* User EccSign Callback handler */
wolfSSL 13:f67a6c6013ca 2381 CallbackEccVerify EccVerifyCb; /* User EccVerify Callback handler */
wolfSSL 13:f67a6c6013ca 2382 CallbackEccSharedSecret EccSharedSecretCb; /* User EccVerify Callback handler */
wolfSSL 13:f67a6c6013ca 2383 #ifdef HAVE_ED25519
wolfSSL 13:f67a6c6013ca 2384 /* User Ed25519Sign Callback handler */
wolfSSL 13:f67a6c6013ca 2385 CallbackEd25519Sign Ed25519SignCb;
wolfSSL 13:f67a6c6013ca 2386 /* User Ed25519Verify Callback handler */
wolfSSL 13:f67a6c6013ca 2387 CallbackEd25519Verify Ed25519VerifyCb;
wolfSSL 13:f67a6c6013ca 2388 #endif
wolfSSL 13:f67a6c6013ca 2389 #ifdef HAVE_CURVE25519
wolfSSL 13:f67a6c6013ca 2390 /* User EccSharedSecret Callback handler */
wolfSSL 13:f67a6c6013ca 2391 CallbackX25519SharedSecret X25519SharedSecretCb;
wolfSSL 13:f67a6c6013ca 2392 #endif
wolfSSL 13:f67a6c6013ca 2393 #endif /* HAVE_ECC */
wolfSSL 13:f67a6c6013ca 2394 #ifndef NO_RSA
wolfSSL 13:f67a6c6013ca 2395 CallbackRsaSign RsaSignCb; /* User RsaSign Callback handler */
wolfSSL 13:f67a6c6013ca 2396 CallbackRsaVerify RsaVerifyCb; /* User RsaVerify Callback handler */
wolfSSL 13:f67a6c6013ca 2397 #ifdef WC_RSA_PSS
wolfSSL 13:f67a6c6013ca 2398 CallbackRsaPssSign RsaPssSignCb; /* User RsaPssSign */
wolfSSL 13:f67a6c6013ca 2399 CallbackRsaPssVerify RsaPssVerifyCb; /* User RsaPssVerify */
wolfSSL 13:f67a6c6013ca 2400 #endif
wolfSSL 13:f67a6c6013ca 2401 CallbackRsaEnc RsaEncCb; /* User Rsa Public Encrypt handler */
wolfSSL 13:f67a6c6013ca 2402 CallbackRsaDec RsaDecCb; /* User Rsa Private Decrypt handler */
wolfSSL 13:f67a6c6013ca 2403 #endif /* NO_RSA */
wolfSSL 13:f67a6c6013ca 2404 #endif /* HAVE_PK_CALLBACKS */
wolfSSL 13:f67a6c6013ca 2405 #ifdef HAVE_WOLF_EVENT
wolfSSL 13:f67a6c6013ca 2406 WOLF_EVENT_QUEUE event_queue;
wolfSSL 13:f67a6c6013ca 2407 #endif /* HAVE_WOLF_EVENT */
wolfSSL 13:f67a6c6013ca 2408 #ifdef HAVE_EXT_CACHE
wolfSSL 13:f67a6c6013ca 2409 WOLFSSL_SESSION*(*get_sess_cb)(WOLFSSL*, unsigned char*, int, int*);
wolfSSL 13:f67a6c6013ca 2410 int (*new_sess_cb)(WOLFSSL*, WOLFSSL_SESSION*);
wolfSSL 13:f67a6c6013ca 2411 void (*rem_sess_cb)(WOLFSSL_CTX*, WOLFSSL_SESSION*);
wolfSSL 13:f67a6c6013ca 2412 #endif
wolfSSL 13:f67a6c6013ca 2413 };
wolfSSL 13:f67a6c6013ca 2414
wolfSSL 13:f67a6c6013ca 2415
wolfSSL 13:f67a6c6013ca 2416 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 2417 WOLFSSL_CTX* wolfSSL_CTX_new_ex(WOLFSSL_METHOD* method, void* heap);
wolfSSL 13:f67a6c6013ca 2418 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 2419 int InitSSL_Ctx(WOLFSSL_CTX*, WOLFSSL_METHOD*, void* heap);
wolfSSL 13:f67a6c6013ca 2420 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 2421 void FreeSSL_Ctx(WOLFSSL_CTX*);
wolfSSL 13:f67a6c6013ca 2422 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 2423 void SSL_CtxResourceFree(WOLFSSL_CTX*);
wolfSSL 13:f67a6c6013ca 2424
wolfSSL 13:f67a6c6013ca 2425 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 2426 int DeriveTlsKeys(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 2427 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 2428 int ProcessOldClientHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
wolfSSL 13:f67a6c6013ca 2429 word32 inSz, word16 sz);
wolfSSL 13:f67a6c6013ca 2430
wolfSSL 13:f67a6c6013ca 2431 #ifndef NO_CERTS
wolfSSL 13:f67a6c6013ca 2432 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 2433 int AddCA(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int type, int verify);
wolfSSL 13:f67a6c6013ca 2434 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 2435 int AlreadySigner(WOLFSSL_CERT_MANAGER* cm, byte* hash);
wolfSSL 13:f67a6c6013ca 2436 #ifdef WOLFSSL_TRUST_PEER_CERT
wolfSSL 13:f67a6c6013ca 2437 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 2438 int AddTrustedPeer(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int verify);
wolfSSL 13:f67a6c6013ca 2439 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 2440 int AlreadyTrustedPeer(WOLFSSL_CERT_MANAGER* cm, byte* hash);
wolfSSL 13:f67a6c6013ca 2441 #endif
wolfSSL 13:f67a6c6013ca 2442 #endif
wolfSSL 13:f67a6c6013ca 2443
wolfSSL 13:f67a6c6013ca 2444 /* All cipher suite related info
wolfSSL 13:f67a6c6013ca 2445 * Keep as a constant size (no ifdefs) for session export */
wolfSSL 13:f67a6c6013ca 2446 typedef struct CipherSpecs {
wolfSSL 13:f67a6c6013ca 2447 word16 key_size;
wolfSSL 13:f67a6c6013ca 2448 word16 iv_size;
wolfSSL 13:f67a6c6013ca 2449 word16 block_size;
wolfSSL 13:f67a6c6013ca 2450 word16 aead_mac_size;
wolfSSL 13:f67a6c6013ca 2451 byte bulk_cipher_algorithm;
wolfSSL 13:f67a6c6013ca 2452 byte cipher_type; /* block, stream, or aead */
wolfSSL 13:f67a6c6013ca 2453 byte mac_algorithm;
wolfSSL 13:f67a6c6013ca 2454 byte kea; /* key exchange algo */
wolfSSL 13:f67a6c6013ca 2455 byte sig_algo;
wolfSSL 13:f67a6c6013ca 2456 byte hash_size;
wolfSSL 13:f67a6c6013ca 2457 byte pad_size;
wolfSSL 13:f67a6c6013ca 2458 byte static_ecdh;
wolfSSL 13:f67a6c6013ca 2459 } CipherSpecs;
wolfSSL 13:f67a6c6013ca 2460
wolfSSL 13:f67a6c6013ca 2461
wolfSSL 13:f67a6c6013ca 2462 void InitCipherSpecs(CipherSpecs* cs);
wolfSSL 13:f67a6c6013ca 2463
wolfSSL 13:f67a6c6013ca 2464
wolfSSL 13:f67a6c6013ca 2465 /* Supported Message Authentication Codes from page 43 */
wolfSSL 13:f67a6c6013ca 2466 enum MACAlgorithm {
wolfSSL 13:f67a6c6013ca 2467 no_mac,
wolfSSL 13:f67a6c6013ca 2468 md5_mac,
wolfSSL 13:f67a6c6013ca 2469 sha_mac,
wolfSSL 13:f67a6c6013ca 2470 sha224_mac,
wolfSSL 13:f67a6c6013ca 2471 sha256_mac, /* needs to match external KDF_MacAlgorithm */
wolfSSL 13:f67a6c6013ca 2472 sha384_mac,
wolfSSL 13:f67a6c6013ca 2473 sha512_mac,
wolfSSL 13:f67a6c6013ca 2474 rmd_mac,
wolfSSL 13:f67a6c6013ca 2475 blake2b_mac
wolfSSL 13:f67a6c6013ca 2476 };
wolfSSL 13:f67a6c6013ca 2477
wolfSSL 13:f67a6c6013ca 2478
wolfSSL 13:f67a6c6013ca 2479 /* Supported Key Exchange Protocols */
wolfSSL 13:f67a6c6013ca 2480 enum KeyExchangeAlgorithm {
wolfSSL 13:f67a6c6013ca 2481 no_kea,
wolfSSL 13:f67a6c6013ca 2482 rsa_kea,
wolfSSL 13:f67a6c6013ca 2483 diffie_hellman_kea,
wolfSSL 13:f67a6c6013ca 2484 fortezza_kea,
wolfSSL 13:f67a6c6013ca 2485 psk_kea,
wolfSSL 13:f67a6c6013ca 2486 dhe_psk_kea,
wolfSSL 13:f67a6c6013ca 2487 ecdhe_psk_kea,
wolfSSL 13:f67a6c6013ca 2488 ntru_kea,
wolfSSL 13:f67a6c6013ca 2489 ecc_diffie_hellman_kea,
wolfSSL 13:f67a6c6013ca 2490 ecc_static_diffie_hellman_kea /* for verify suite only */
wolfSSL 13:f67a6c6013ca 2491 };
wolfSSL 13:f67a6c6013ca 2492
wolfSSL 13:f67a6c6013ca 2493
wolfSSL 13:f67a6c6013ca 2494 /* Supported Authentication Schemes */
wolfSSL 13:f67a6c6013ca 2495 enum SignatureAlgorithm {
wolfSSL 13:f67a6c6013ca 2496 anonymous_sa_algo = 0,
wolfSSL 13:f67a6c6013ca 2497 rsa_sa_algo = 1,
wolfSSL 13:f67a6c6013ca 2498 dsa_sa_algo = 2,
wolfSSL 13:f67a6c6013ca 2499 ecc_dsa_sa_algo = 3,
wolfSSL 13:f67a6c6013ca 2500 rsa_pss_sa_algo = 8,
wolfSSL 13:f67a6c6013ca 2501 ed25519_sa_algo = 9
wolfSSL 13:f67a6c6013ca 2502 };
wolfSSL 13:f67a6c6013ca 2503
wolfSSL 13:f67a6c6013ca 2504
wolfSSL 13:f67a6c6013ca 2505 /* Supprted ECC Curve Types */
wolfSSL 13:f67a6c6013ca 2506 enum EccCurves {
wolfSSL 13:f67a6c6013ca 2507 named_curve = 3
wolfSSL 13:f67a6c6013ca 2508 };
wolfSSL 13:f67a6c6013ca 2509
wolfSSL 13:f67a6c6013ca 2510
wolfSSL 13:f67a6c6013ca 2511 /* Valid client certificate request types from page 27 */
wolfSSL 13:f67a6c6013ca 2512 enum ClientCertificateType {
wolfSSL 13:f67a6c6013ca 2513 rsa_sign = 1,
wolfSSL 13:f67a6c6013ca 2514 dss_sign = 2,
wolfSSL 13:f67a6c6013ca 2515 rsa_fixed_dh = 3,
wolfSSL 13:f67a6c6013ca 2516 dss_fixed_dh = 4,
wolfSSL 13:f67a6c6013ca 2517 rsa_ephemeral_dh = 5,
wolfSSL 13:f67a6c6013ca 2518 dss_ephemeral_dh = 6,
wolfSSL 13:f67a6c6013ca 2519 fortezza_kea_cert = 20,
wolfSSL 13:f67a6c6013ca 2520 ecdsa_sign = 64,
wolfSSL 13:f67a6c6013ca 2521 rsa_fixed_ecdh = 65,
wolfSSL 13:f67a6c6013ca 2522 ecdsa_fixed_ecdh = 66
wolfSSL 13:f67a6c6013ca 2523 };
wolfSSL 13:f67a6c6013ca 2524
wolfSSL 13:f67a6c6013ca 2525
wolfSSL 13:f67a6c6013ca 2526 enum CipherType { stream, block, aead };
wolfSSL 13:f67a6c6013ca 2527
wolfSSL 13:f67a6c6013ca 2528
wolfSSL 13:f67a6c6013ca 2529
wolfSSL 13:f67a6c6013ca 2530
wolfSSL 13:f67a6c6013ca 2531
wolfSSL 13:f67a6c6013ca 2532
wolfSSL 13:f67a6c6013ca 2533 /* cipher for now */
wolfSSL 13:f67a6c6013ca 2534 typedef struct Ciphers {
wolfSSL 13:f67a6c6013ca 2535 #ifdef BUILD_ARC4
wolfSSL 13:f67a6c6013ca 2536 Arc4* arc4;
wolfSSL 13:f67a6c6013ca 2537 #endif
wolfSSL 13:f67a6c6013ca 2538 #ifdef BUILD_DES3
wolfSSL 13:f67a6c6013ca 2539 Des3* des3;
wolfSSL 13:f67a6c6013ca 2540 #endif
wolfSSL 13:f67a6c6013ca 2541 #if defined(BUILD_AES) || defined(BUILD_AESGCM)
wolfSSL 13:f67a6c6013ca 2542 Aes* aes;
wolfSSL 13:f67a6c6013ca 2543 #if defined(BUILD_AESGCM) || defined(HAVE_AESCCM)
wolfSSL 13:f67a6c6013ca 2544 byte* additional;
wolfSSL 13:f67a6c6013ca 2545 byte* nonce;
wolfSSL 13:f67a6c6013ca 2546 #endif
wolfSSL 13:f67a6c6013ca 2547 #endif
wolfSSL 13:f67a6c6013ca 2548 #ifdef HAVE_CAMELLIA
wolfSSL 13:f67a6c6013ca 2549 Camellia* cam;
wolfSSL 13:f67a6c6013ca 2550 #endif
wolfSSL 13:f67a6c6013ca 2551 #ifdef HAVE_CHACHA
wolfSSL 13:f67a6c6013ca 2552 ChaCha* chacha;
wolfSSL 13:f67a6c6013ca 2553 #endif
wolfSSL 13:f67a6c6013ca 2554 #ifdef HAVE_HC128
wolfSSL 13:f67a6c6013ca 2555 HC128* hc128;
wolfSSL 13:f67a6c6013ca 2556 #endif
wolfSSL 13:f67a6c6013ca 2557 #ifdef BUILD_RABBIT
wolfSSL 13:f67a6c6013ca 2558 Rabbit* rabbit;
wolfSSL 13:f67a6c6013ca 2559 #endif
wolfSSL 13:f67a6c6013ca 2560 #ifdef HAVE_IDEA
wolfSSL 13:f67a6c6013ca 2561 Idea* idea;
wolfSSL 13:f67a6c6013ca 2562 #endif
wolfSSL 13:f67a6c6013ca 2563 byte state;
wolfSSL 13:f67a6c6013ca 2564 byte setup; /* have we set it up flag for detection */
wolfSSL 13:f67a6c6013ca 2565 } Ciphers;
wolfSSL 13:f67a6c6013ca 2566
wolfSSL 13:f67a6c6013ca 2567
wolfSSL 13:f67a6c6013ca 2568 #ifdef HAVE_ONE_TIME_AUTH
wolfSSL 13:f67a6c6013ca 2569 /* Ciphers for one time authentication such as poly1305 */
wolfSSL 13:f67a6c6013ca 2570 typedef struct OneTimeAuth {
wolfSSL 13:f67a6c6013ca 2571 #ifdef HAVE_POLY1305
wolfSSL 13:f67a6c6013ca 2572 Poly1305* poly1305;
wolfSSL 13:f67a6c6013ca 2573 #endif
wolfSSL 13:f67a6c6013ca 2574 byte setup; /* flag for if a cipher has been set */
wolfSSL 13:f67a6c6013ca 2575
wolfSSL 13:f67a6c6013ca 2576 } OneTimeAuth;
wolfSSL 13:f67a6c6013ca 2577 #endif
wolfSSL 13:f67a6c6013ca 2578
wolfSSL 13:f67a6c6013ca 2579
wolfSSL 13:f67a6c6013ca 2580 WOLFSSL_LOCAL void InitCiphers(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 2581 WOLFSSL_LOCAL void FreeCiphers(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 2582
wolfSSL 13:f67a6c6013ca 2583
wolfSSL 13:f67a6c6013ca 2584 /* hashes type */
wolfSSL 13:f67a6c6013ca 2585 typedef struct Hashes {
wolfSSL 13:f67a6c6013ca 2586 #if !defined(NO_MD5) && !defined(NO_OLD_TLS)
wolfSSL 13:f67a6c6013ca 2587 byte md5[MD5_DIGEST_SIZE];
wolfSSL 13:f67a6c6013ca 2588 #endif
wolfSSL 13:f67a6c6013ca 2589 #if !defined(NO_SHA)
wolfSSL 13:f67a6c6013ca 2590 byte sha[SHA_DIGEST_SIZE];
wolfSSL 13:f67a6c6013ca 2591 #endif
wolfSSL 13:f67a6c6013ca 2592 #ifndef NO_SHA256
wolfSSL 13:f67a6c6013ca 2593 byte sha256[SHA256_DIGEST_SIZE];
wolfSSL 13:f67a6c6013ca 2594 #endif
wolfSSL 13:f67a6c6013ca 2595 #ifdef WOLFSSL_SHA384
wolfSSL 13:f67a6c6013ca 2596 byte sha384[SHA384_DIGEST_SIZE];
wolfSSL 13:f67a6c6013ca 2597 #endif
wolfSSL 13:f67a6c6013ca 2598 #ifdef WOLFSSL_SHA512
wolfSSL 13:f67a6c6013ca 2599 byte sha512[SHA512_DIGEST_SIZE];
wolfSSL 13:f67a6c6013ca 2600 #endif
wolfSSL 13:f67a6c6013ca 2601 } Hashes;
wolfSSL 13:f67a6c6013ca 2602
wolfSSL 13:f67a6c6013ca 2603 WOLFSSL_LOCAL int BuildCertHashes(WOLFSSL* ssl, Hashes* hashes);
wolfSSL 13:f67a6c6013ca 2604
wolfSSL 13:f67a6c6013ca 2605 #ifdef WOLFSSL_TLS13
wolfSSL 13:f67a6c6013ca 2606 typedef union Digest {
wolfSSL 13:f67a6c6013ca 2607 #ifndef NO_WOLFSSL_SHA256
wolfSSL 13:f67a6c6013ca 2608 Sha256 sha256;
wolfSSL 13:f67a6c6013ca 2609 #endif
wolfSSL 13:f67a6c6013ca 2610 #ifdef WOLFSSL_SHA384
wolfSSL 13:f67a6c6013ca 2611 Sha384 sha384;
wolfSSL 13:f67a6c6013ca 2612 #endif
wolfSSL 13:f67a6c6013ca 2613 #ifdef WOLFSSL_SHA512
wolfSSL 13:f67a6c6013ca 2614 Sha512 sha512;
wolfSSL 13:f67a6c6013ca 2615 #endif
wolfSSL 13:f67a6c6013ca 2616 } Digest;
wolfSSL 13:f67a6c6013ca 2617 #endif
wolfSSL 13:f67a6c6013ca 2618
wolfSSL 13:f67a6c6013ca 2619 /* Static x509 buffer */
wolfSSL 13:f67a6c6013ca 2620 typedef struct x509_buffer {
wolfSSL 13:f67a6c6013ca 2621 int length; /* actual size */
wolfSSL 13:f67a6c6013ca 2622 byte buffer[MAX_X509_SIZE]; /* max static cert size */
wolfSSL 13:f67a6c6013ca 2623 } x509_buffer;
wolfSSL 13:f67a6c6013ca 2624
wolfSSL 13:f67a6c6013ca 2625
wolfSSL 13:f67a6c6013ca 2626 /* wolfSSL X509_CHAIN, for no dynamic memory SESSION_CACHE */
wolfSSL 13:f67a6c6013ca 2627 struct WOLFSSL_X509_CHAIN {
wolfSSL 13:f67a6c6013ca 2628 int count; /* total number in chain */
wolfSSL 13:f67a6c6013ca 2629 x509_buffer certs[MAX_CHAIN_DEPTH]; /* only allow max depth 4 for now */
wolfSSL 13:f67a6c6013ca 2630 };
wolfSSL 13:f67a6c6013ca 2631
wolfSSL 13:f67a6c6013ca 2632
wolfSSL 13:f67a6c6013ca 2633 /* wolfSSL session type */
wolfSSL 13:f67a6c6013ca 2634 struct WOLFSSL_SESSION {
wolfSSL 13:f67a6c6013ca 2635 word32 bornOn; /* create time in seconds */
wolfSSL 13:f67a6c6013ca 2636 word32 timeout; /* timeout in seconds */
wolfSSL 13:f67a6c6013ca 2637 byte sessionID[ID_LEN]; /* id for protocol */
wolfSSL 13:f67a6c6013ca 2638 byte sessionIDSz;
wolfSSL 13:f67a6c6013ca 2639 byte masterSecret[SECRET_LEN]; /* stored secret */
wolfSSL 13:f67a6c6013ca 2640 word16 haveEMS; /* ext master secret flag */
wolfSSL 13:f67a6c6013ca 2641 #ifdef SESSION_CERTS
wolfSSL 13:f67a6c6013ca 2642 WOLFSSL_X509_CHAIN chain; /* peer cert chain, static */
wolfSSL 13:f67a6c6013ca 2643 #endif
wolfSSL 13:f67a6c6013ca 2644 #if defined(SESSION_CERTS) || (defined(WOLFSSL_TLS13) && \
wolfSSL 13:f67a6c6013ca 2645 defined(HAVE_SESSION_TICKET))
wolfSSL 13:f67a6c6013ca 2646 ProtocolVersion version; /* which version was used */
wolfSSL 13:f67a6c6013ca 2647 byte cipherSuite0; /* first byte, normally 0 */
wolfSSL 13:f67a6c6013ca 2648 byte cipherSuite; /* 2nd byte, actual suite */
wolfSSL 13:f67a6c6013ca 2649 #endif
wolfSSL 13:f67a6c6013ca 2650 #ifndef NO_CLIENT_CACHE
wolfSSL 13:f67a6c6013ca 2651 word16 idLen; /* serverID length */
wolfSSL 13:f67a6c6013ca 2652 byte serverID[SERVER_ID_LEN]; /* for easier client lookup */
wolfSSL 13:f67a6c6013ca 2653 #endif
wolfSSL 13:f67a6c6013ca 2654 #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
wolfSSL 13:f67a6c6013ca 2655 #ifdef WOLFSSL_TLS13
wolfSSL 13:f67a6c6013ca 2656 byte namedGroup;
wolfSSL 13:f67a6c6013ca 2657 word32 ticketSeen; /* Time ticket seen (ms) */
wolfSSL 13:f67a6c6013ca 2658 word32 ticketAdd; /* Added by client */
wolfSSL 13:f67a6c6013ca 2659 #endif
wolfSSL 13:f67a6c6013ca 2660 #ifdef WOLFSSL_EARLY_DATA
wolfSSL 13:f67a6c6013ca 2661 word32 maxEarlyDataSz;
wolfSSL 13:f67a6c6013ca 2662 #endif
wolfSSL 13:f67a6c6013ca 2663 byte* ticket;
wolfSSL 13:f67a6c6013ca 2664 word16 ticketLen;
wolfSSL 13:f67a6c6013ca 2665 byte staticTicket[SESSION_TICKET_LEN];
wolfSSL 13:f67a6c6013ca 2666 byte isDynamic;
wolfSSL 13:f67a6c6013ca 2667 #endif
wolfSSL 13:f67a6c6013ca 2668 #ifdef HAVE_EXT_CACHE
wolfSSL 13:f67a6c6013ca 2669 byte isAlloced;
wolfSSL 13:f67a6c6013ca 2670 #endif
wolfSSL 13:f67a6c6013ca 2671 #ifdef HAVE_EX_DATA
wolfSSL 13:f67a6c6013ca 2672 void* ex_data[MAX_EX_DATA];
wolfSSL 13:f67a6c6013ca 2673 #endif
wolfSSL 13:f67a6c6013ca 2674 };
wolfSSL 13:f67a6c6013ca 2675
wolfSSL 13:f67a6c6013ca 2676
wolfSSL 13:f67a6c6013ca 2677 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 2678 WOLFSSL_SESSION* GetSession(WOLFSSL*, byte*, byte);
wolfSSL 13:f67a6c6013ca 2679 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 2680 int SetSession(WOLFSSL*, WOLFSSL_SESSION*);
wolfSSL 13:f67a6c6013ca 2681
wolfSSL 13:f67a6c6013ca 2682 typedef int (*hmacfp) (WOLFSSL*, byte*, const byte*, word32, int, int);
wolfSSL 13:f67a6c6013ca 2683
wolfSSL 13:f67a6c6013ca 2684 #ifndef NO_CLIENT_CACHE
wolfSSL 13:f67a6c6013ca 2685 WOLFSSL_SESSION* GetSessionClient(WOLFSSL*, const byte*, int);
wolfSSL 13:f67a6c6013ca 2686 #endif
wolfSSL 13:f67a6c6013ca 2687
wolfSSL 13:f67a6c6013ca 2688 /* client connect state for nonblocking restart */
wolfSSL 13:f67a6c6013ca 2689 enum ConnectState {
wolfSSL 13:f67a6c6013ca 2690 CONNECT_BEGIN = 0,
wolfSSL 13:f67a6c6013ca 2691 CLIENT_HELLO_SENT,
wolfSSL 13:f67a6c6013ca 2692 HELLO_AGAIN, /* HELLO_AGAIN s for DTLS case */
wolfSSL 13:f67a6c6013ca 2693 HELLO_AGAIN_REPLY,
wolfSSL 13:f67a6c6013ca 2694 FIRST_REPLY_DONE,
wolfSSL 13:f67a6c6013ca 2695 FIRST_REPLY_FIRST,
wolfSSL 13:f67a6c6013ca 2696 FIRST_REPLY_SECOND,
wolfSSL 13:f67a6c6013ca 2697 FIRST_REPLY_THIRD,
wolfSSL 13:f67a6c6013ca 2698 FIRST_REPLY_FOURTH,
wolfSSL 13:f67a6c6013ca 2699 FINISHED_DONE,
wolfSSL 13:f67a6c6013ca 2700 SECOND_REPLY_DONE
wolfSSL 13:f67a6c6013ca 2701 };
wolfSSL 13:f67a6c6013ca 2702
wolfSSL 13:f67a6c6013ca 2703
wolfSSL 13:f67a6c6013ca 2704 /* server accept state for nonblocking restart */
wolfSSL 13:f67a6c6013ca 2705 enum AcceptState {
wolfSSL 13:f67a6c6013ca 2706 ACCEPT_BEGIN = 0,
wolfSSL 13:f67a6c6013ca 2707 ACCEPT_CLIENT_HELLO_DONE,
wolfSSL 13:f67a6c6013ca 2708 ACCEPT_HELLO_RETRY_REQUEST_DONE,
wolfSSL 13:f67a6c6013ca 2709 ACCEPT_FIRST_REPLY_DONE,
wolfSSL 13:f67a6c6013ca 2710 SERVER_HELLO_SENT,
wolfSSL 13:f67a6c6013ca 2711 SERVER_EXTENSIONS_SENT,
wolfSSL 13:f67a6c6013ca 2712 CERT_SENT,
wolfSSL 13:f67a6c6013ca 2713 CERT_VERIFY_SENT,
wolfSSL 13:f67a6c6013ca 2714 CERT_STATUS_SENT,
wolfSSL 13:f67a6c6013ca 2715 KEY_EXCHANGE_SENT,
wolfSSL 13:f67a6c6013ca 2716 CERT_REQ_SENT,
wolfSSL 13:f67a6c6013ca 2717 SERVER_HELLO_DONE,
wolfSSL 13:f67a6c6013ca 2718 ACCEPT_SECOND_REPLY_DONE,
wolfSSL 13:f67a6c6013ca 2719 TICKET_SENT,
wolfSSL 13:f67a6c6013ca 2720 CHANGE_CIPHER_SENT,
wolfSSL 13:f67a6c6013ca 2721 ACCEPT_FINISHED_DONE,
wolfSSL 13:f67a6c6013ca 2722 ACCEPT_THIRD_REPLY_DONE
wolfSSL 13:f67a6c6013ca 2723 };
wolfSSL 13:f67a6c6013ca 2724
wolfSSL 13:f67a6c6013ca 2725 /* buffers for struct WOLFSSL */
wolfSSL 13:f67a6c6013ca 2726 typedef struct Buffers {
wolfSSL 13:f67a6c6013ca 2727 bufferStatic inputBuffer;
wolfSSL 13:f67a6c6013ca 2728 bufferStatic outputBuffer;
wolfSSL 13:f67a6c6013ca 2729 buffer domainName; /* for client check */
wolfSSL 13:f67a6c6013ca 2730 buffer clearOutputBuffer;
wolfSSL 13:f67a6c6013ca 2731 buffer sig; /* signature data */
wolfSSL 13:f67a6c6013ca 2732 buffer digest; /* digest data */
wolfSSL 13:f67a6c6013ca 2733 int prevSent; /* previous plain text bytes sent
wolfSSL 13:f67a6c6013ca 2734 when got WANT_WRITE */
wolfSSL 13:f67a6c6013ca 2735 int plainSz; /* plain text bytes in buffer to send
wolfSSL 13:f67a6c6013ca 2736 when got WANT_WRITE */
wolfSSL 13:f67a6c6013ca 2737 byte weOwnCert; /* SSL own cert flag */
wolfSSL 13:f67a6c6013ca 2738 byte weOwnCertChain; /* SSL own cert chain flag */
wolfSSL 13:f67a6c6013ca 2739 byte weOwnKey; /* SSL own key flag */
wolfSSL 13:f67a6c6013ca 2740 byte weOwnDH; /* SSL own dh (p,g) flag */
wolfSSL 13:f67a6c6013ca 2741 #ifndef NO_DH
wolfSSL 13:f67a6c6013ca 2742 buffer serverDH_P; /* WOLFSSL_CTX owns, unless we own */
wolfSSL 13:f67a6c6013ca 2743 buffer serverDH_G; /* WOLFSSL_CTX owns, unless we own */
wolfSSL 13:f67a6c6013ca 2744 buffer serverDH_Pub;
wolfSSL 13:f67a6c6013ca 2745 buffer serverDH_Priv;
wolfSSL 13:f67a6c6013ca 2746 DhKey* serverDH_Key;
wolfSSL 13:f67a6c6013ca 2747 #endif
wolfSSL 13:f67a6c6013ca 2748 #ifndef NO_CERTS
wolfSSL 13:f67a6c6013ca 2749 DerBuffer* certificate; /* WOLFSSL_CTX owns, unless we own */
wolfSSL 13:f67a6c6013ca 2750 DerBuffer* key; /* WOLFSSL_CTX owns, unless we own */
wolfSSL 13:f67a6c6013ca 2751 byte keyType; /* Type of key: RSA, ECC, Ed25519 */
wolfSSL 13:f67a6c6013ca 2752 int keySz; /* Size of RSA key */
wolfSSL 13:f67a6c6013ca 2753 DerBuffer* certChain; /* WOLFSSL_CTX owns, unless we own */
wolfSSL 13:f67a6c6013ca 2754 /* chain after self, in DER, with leading size for each cert */
wolfSSL 13:f67a6c6013ca 2755 #ifdef WOLFSSL_TLS13
wolfSSL 13:f67a6c6013ca 2756 int certChainCnt;
wolfSSL 13:f67a6c6013ca 2757 #endif
wolfSSL 13:f67a6c6013ca 2758 #endif
wolfSSL 13:f67a6c6013ca 2759 #ifdef WOLFSSL_SEND_HRR_COOKIE
wolfSSL 13:f67a6c6013ca 2760 buffer tls13CookieSecret; /* HRR cookie secret */
wolfSSL 13:f67a6c6013ca 2761 #endif
wolfSSL 13:f67a6c6013ca 2762 #ifdef WOLFSSL_DTLS
wolfSSL 13:f67a6c6013ca 2763 WOLFSSL_DTLS_CTX dtlsCtx; /* DTLS connection context */
wolfSSL 13:f67a6c6013ca 2764 #ifndef NO_WOLFSSL_SERVER
wolfSSL 13:f67a6c6013ca 2765 buffer dtlsCookieSecret; /* DTLS cookie secret */
wolfSSL 13:f67a6c6013ca 2766 #endif /* NO_WOLFSSL_SERVER */
wolfSSL 13:f67a6c6013ca 2767 #endif
wolfSSL 13:f67a6c6013ca 2768 #ifdef HAVE_PK_CALLBACKS
wolfSSL 13:f67a6c6013ca 2769 #ifdef HAVE_ECC
wolfSSL 13:f67a6c6013ca 2770 buffer peerEccDsaKey; /* we own for Ecc Verify Callbacks */
wolfSSL 13:f67a6c6013ca 2771 #endif /* HAVE_ECC */
wolfSSL 13:f67a6c6013ca 2772 #ifdef HAVE_ED25519
wolfSSL 13:f67a6c6013ca 2773 buffer peerEd25519Key; /* for Ed25519 Verify Callbacks */
wolfSSL 13:f67a6c6013ca 2774 #endif /* HAVE_ED25519 */
wolfSSL 13:f67a6c6013ca 2775 #ifndef NO_RSA
wolfSSL 13:f67a6c6013ca 2776 buffer peerRsaKey; /* we own for Rsa Verify Callbacks */
wolfSSL 13:f67a6c6013ca 2777 #endif /* NO_RSA */
wolfSSL 13:f67a6c6013ca 2778 #endif /* HAVE_PK_CALLBACKS */
wolfSSL 13:f67a6c6013ca 2779 } Buffers;
wolfSSL 13:f67a6c6013ca 2780
wolfSSL 13:f67a6c6013ca 2781 /* sub-states for send/do key share (key exchange) */
wolfSSL 13:f67a6c6013ca 2782 enum asyncState {
wolfSSL 13:f67a6c6013ca 2783 TLS_ASYNC_BEGIN = 0,
wolfSSL 13:f67a6c6013ca 2784 TLS_ASYNC_BUILD,
wolfSSL 13:f67a6c6013ca 2785 TLS_ASYNC_DO,
wolfSSL 13:f67a6c6013ca 2786 TLS_ASYNC_VERIFY,
wolfSSL 13:f67a6c6013ca 2787 TLS_ASYNC_FINALIZE,
wolfSSL 13:f67a6c6013ca 2788 TLS_ASYNC_END
wolfSSL 13:f67a6c6013ca 2789 };
wolfSSL 13:f67a6c6013ca 2790
wolfSSL 13:f67a6c6013ca 2791 /* sub-states for build message */
wolfSSL 13:f67a6c6013ca 2792 enum buildMsgState {
wolfSSL 13:f67a6c6013ca 2793 BUILD_MSG_BEGIN = 0,
wolfSSL 13:f67a6c6013ca 2794 BUILD_MSG_SIZE,
wolfSSL 13:f67a6c6013ca 2795 BUILD_MSG_HASH,
wolfSSL 13:f67a6c6013ca 2796 BUILD_MSG_VERIFY_MAC,
wolfSSL 13:f67a6c6013ca 2797 BUILD_MSG_ENCRYPT,
wolfSSL 13:f67a6c6013ca 2798 };
wolfSSL 13:f67a6c6013ca 2799
wolfSSL 13:f67a6c6013ca 2800 /* sub-states for cipher operations */
wolfSSL 13:f67a6c6013ca 2801 enum cipherState {
wolfSSL 13:f67a6c6013ca 2802 CIPHER_STATE_BEGIN = 0,
wolfSSL 13:f67a6c6013ca 2803 CIPHER_STATE_DO,
wolfSSL 13:f67a6c6013ca 2804 CIPHER_STATE_END,
wolfSSL 13:f67a6c6013ca 2805 };
wolfSSL 13:f67a6c6013ca 2806
wolfSSL 13:f67a6c6013ca 2807 typedef struct Options {
wolfSSL 13:f67a6c6013ca 2808 #ifndef NO_PSK
wolfSSL 13:f67a6c6013ca 2809 wc_psk_client_callback client_psk_cb;
wolfSSL 13:f67a6c6013ca 2810 wc_psk_server_callback server_psk_cb;
wolfSSL 13:f67a6c6013ca 2811 #endif /* NO_PSK */
wolfSSL 13:f67a6c6013ca 2812 #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
wolfSSL 13:f67a6c6013ca 2813 word16 havePSK:1; /* psk key set by user */
wolfSSL 13:f67a6c6013ca 2814 #endif /* HAVE_SESSION_TICKET || !NO_PSK */
wolfSSL 13:f67a6c6013ca 2815 #ifdef OPENSSL_EXTRA
wolfSSL 13:f67a6c6013ca 2816 unsigned long mask; /* store SSL_OP_ flags */
wolfSSL 13:f67a6c6013ca 2817 #endif
wolfSSL 13:f67a6c6013ca 2818
wolfSSL 13:f67a6c6013ca 2819 /* on/off or small bit flags, optimize layout */
wolfSSL 13:f67a6c6013ca 2820 word16 sendVerify:2; /* false = 0, true = 1, sendBlank = 2 */
wolfSSL 13:f67a6c6013ca 2821 word16 sessionCacheOff:1;
wolfSSL 13:f67a6c6013ca 2822 word16 sessionCacheFlushOff:1;
wolfSSL 13:f67a6c6013ca 2823 #ifdef HAVE_EXT_CACHE
wolfSSL 13:f67a6c6013ca 2824 word16 internalCacheOff:1;
wolfSSL 13:f67a6c6013ca 2825 #endif
wolfSSL 13:f67a6c6013ca 2826 word16 side:1; /* client or server end */
wolfSSL 13:f67a6c6013ca 2827 word16 verifyPeer:1;
wolfSSL 13:f67a6c6013ca 2828 word16 verifyNone:1;
wolfSSL 13:f67a6c6013ca 2829 word16 failNoCert:1;
wolfSSL 13:f67a6c6013ca 2830 word16 failNoCertxPSK:1; /* fail for no cert except with PSK */
wolfSSL 13:f67a6c6013ca 2831 word16 downgrade:1; /* allow downgrade of versions */
wolfSSL 13:f67a6c6013ca 2832 word16 resuming:1;
wolfSSL 13:f67a6c6013ca 2833 word16 haveSessionId:1; /* server may not send */
wolfSSL 13:f67a6c6013ca 2834 word16 tls:1; /* using TLS ? */
wolfSSL 13:f67a6c6013ca 2835 word16 tls1_1:1; /* using TLSv1.1+ ? */
wolfSSL 13:f67a6c6013ca 2836 word16 tls1_3:1; /* using TLSv1.3+ ? */
wolfSSL 13:f67a6c6013ca 2837 word16 dtls:1; /* using datagrams ? */
wolfSSL 13:f67a6c6013ca 2838 word16 connReset:1; /* has the peer reset */
wolfSSL 13:f67a6c6013ca 2839 word16 isClosed:1; /* if we consider conn closed */
wolfSSL 13:f67a6c6013ca 2840 word16 closeNotify:1; /* we've received a close notify */
wolfSSL 13:f67a6c6013ca 2841 word16 sentNotify:1; /* we've sent a close notify */
wolfSSL 13:f67a6c6013ca 2842 word16 usingCompression:1; /* are we using compression */
wolfSSL 13:f67a6c6013ca 2843 word16 haveRSA:1; /* RSA available */
wolfSSL 13:f67a6c6013ca 2844 word16 haveECC:1; /* ECC available */
wolfSSL 13:f67a6c6013ca 2845 word16 haveDH:1; /* server DH parms set by user */
wolfSSL 13:f67a6c6013ca 2846 word16 haveNTRU:1; /* server NTRU private key loaded */
wolfSSL 13:f67a6c6013ca 2847 word16 haveQSH:1; /* have QSH ability */
wolfSSL 13:f67a6c6013ca 2848 word16 haveECDSAsig:1; /* server ECDSA signed cert */
wolfSSL 13:f67a6c6013ca 2849 word16 haveStaticECC:1; /* static server ECC private key */
wolfSSL 13:f67a6c6013ca 2850 word16 havePeerCert:1; /* do we have peer's cert */
wolfSSL 13:f67a6c6013ca 2851 word16 havePeerVerify:1; /* and peer's cert verify */
wolfSSL 13:f67a6c6013ca 2852 word16 usingPSK_cipher:1; /* are using psk as cipher */
wolfSSL 13:f67a6c6013ca 2853 word16 usingAnon_cipher:1; /* are we using an anon cipher */
wolfSSL 13:f67a6c6013ca 2854 word16 noPskDheKe:1; /* Don't use (EC)DHE with PSK */
wolfSSL 13:f67a6c6013ca 2855 word16 sendAlertState:1; /* nonblocking resume */
wolfSSL 13:f67a6c6013ca 2856 word16 partialWrite:1; /* only one msg per write call */
wolfSSL 13:f67a6c6013ca 2857 word16 quietShutdown:1; /* don't send close notify */
wolfSSL 13:f67a6c6013ca 2858 word16 certOnly:1; /* stop once we get cert */
wolfSSL 13:f67a6c6013ca 2859 word16 groupMessages:1; /* group handshake messages */
wolfSSL 13:f67a6c6013ca 2860 word16 usingNonblock:1; /* are we using nonblocking socket */
wolfSSL 13:f67a6c6013ca 2861 word16 saveArrays:1; /* save array Memory for user get keys
wolfSSL 13:f67a6c6013ca 2862 or psk */
wolfSSL 13:f67a6c6013ca 2863 word16 weOwnRng:1; /* will be true unless CTX owns */
wolfSSL 13:f67a6c6013ca 2864 word16 haveEMS:1; /* using extended master secret */
wolfSSL 13:f67a6c6013ca 2865 #ifdef HAVE_POLY1305
wolfSSL 13:f67a6c6013ca 2866 word16 oldPoly:1; /* set when to use old rfc way of poly*/
wolfSSL 13:f67a6c6013ca 2867 #endif
wolfSSL 13:f67a6c6013ca 2868 #ifdef HAVE_ANON
wolfSSL 13:f67a6c6013ca 2869 word16 haveAnon:1; /* User wants to allow Anon suites */
wolfSSL 13:f67a6c6013ca 2870 #endif
wolfSSL 13:f67a6c6013ca 2871 #ifdef HAVE_SESSION_TICKET
wolfSSL 13:f67a6c6013ca 2872 word16 createTicket:1; /* Server to create new Ticket */
wolfSSL 13:f67a6c6013ca 2873 word16 useTicket:1; /* Use Ticket not session cache */
wolfSSL 13:f67a6c6013ca 2874 word16 rejectTicket:1; /* Callback rejected ticket */
wolfSSL 13:f67a6c6013ca 2875 #ifdef WOLFSSL_TLS13
wolfSSL 13:f67a6c6013ca 2876 word16 noTicketTls13:1; /* Server won't create new Ticket */
wolfSSL 13:f67a6c6013ca 2877 #endif
wolfSSL 13:f67a6c6013ca 2878 #endif
wolfSSL 13:f67a6c6013ca 2879 #ifdef WOLFSSL_DTLS
wolfSSL 13:f67a6c6013ca 2880 word16 dtlsHsRetain:1; /* DTLS retaining HS data */
wolfSSL 13:f67a6c6013ca 2881 word16 haveMcast:1; /* using multicast ? */
wolfSSL 13:f67a6c6013ca 2882 #ifdef WOLFSSL_SCTP
wolfSSL 13:f67a6c6013ca 2883 word16 dtlsSctp:1; /* DTLS-over-SCTP mode */
wolfSSL 13:f67a6c6013ca 2884 #endif
wolfSSL 13:f67a6c6013ca 2885 #endif
wolfSSL 13:f67a6c6013ca 2886 #if defined(HAVE_TLS_EXTENSIONS) && defined(HAVE_SUPPORTED_CURVES)
wolfSSL 13:f67a6c6013ca 2887 word16 userCurves:1; /* indicates user called wolfSSL_UseSupportedCurve */
wolfSSL 13:f67a6c6013ca 2888 #endif
wolfSSL 13:f67a6c6013ca 2889 word16 keepResources:1; /* Keep resources after handshake */
wolfSSL 13:f67a6c6013ca 2890 word16 useClientOrder:1; /* Use client's cipher order */
wolfSSL 13:f67a6c6013ca 2891 #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
wolfSSL 13:f67a6c6013ca 2892 word16 postHandshakeAuth:1;/* Client send post_handshake_auth
wolfSSL 13:f67a6c6013ca 2893 * extendion. */
wolfSSL 13:f67a6c6013ca 2894 #endif
wolfSSL 13:f67a6c6013ca 2895 #if defined(WOLFSSL_TLS13) && !defined(NO_WOLFSSL_SERVER)
wolfSSL 13:f67a6c6013ca 2896 word16 sendCookie:1; /* Server creates a Cookie in HRR */
wolfSSL 13:f67a6c6013ca 2897 #endif
wolfSSL 13:f67a6c6013ca 2898
wolfSSL 13:f67a6c6013ca 2899 /* need full byte values for this section */
wolfSSL 13:f67a6c6013ca 2900 byte processReply; /* nonblocking resume */
wolfSSL 13:f67a6c6013ca 2901 byte cipherSuite0; /* first byte, normally 0 */
wolfSSL 13:f67a6c6013ca 2902 byte cipherSuite; /* second byte, actual suite */
wolfSSL 13:f67a6c6013ca 2903 byte serverState;
wolfSSL 13:f67a6c6013ca 2904 byte clientState;
wolfSSL 13:f67a6c6013ca 2905 byte handShakeState;
wolfSSL 13:f67a6c6013ca 2906 byte handShakeDone; /* at least one handshake complete */
wolfSSL 13:f67a6c6013ca 2907 byte minDowngrade; /* minimum downgrade version */
wolfSSL 13:f67a6c6013ca 2908 byte connectState; /* nonblocking resume */
wolfSSL 13:f67a6c6013ca 2909 byte acceptState; /* nonblocking resume */
wolfSSL 13:f67a6c6013ca 2910 byte asyncState; /* sub-state for enum asyncState */
wolfSSL 13:f67a6c6013ca 2911 byte buildMsgState; /* sub-state for enum buildMsgState */
wolfSSL 13:f67a6c6013ca 2912 byte alertCount; /* detect warning dos attempt */
wolfSSL 13:f67a6c6013ca 2913 #ifdef WOLFSSL_MULTICAST
wolfSSL 13:f67a6c6013ca 2914 word16 mcastID; /* Multicast group ID */
wolfSSL 13:f67a6c6013ca 2915 #endif
wolfSSL 13:f67a6c6013ca 2916 #ifndef NO_DH
wolfSSL 13:f67a6c6013ca 2917 word16 minDhKeySz; /* minimum DH key size */
wolfSSL 13:f67a6c6013ca 2918 word16 dhKeySz; /* actual DH key size */
wolfSSL 13:f67a6c6013ca 2919 #endif
wolfSSL 13:f67a6c6013ca 2920 #ifndef NO_RSA
wolfSSL 13:f67a6c6013ca 2921 short minRsaKeySz; /* minimum RSA key size */
wolfSSL 13:f67a6c6013ca 2922 #endif
wolfSSL 13:f67a6c6013ca 2923 #if defined(HAVE_ECC) || defined(HAVE_ED25519)
wolfSSL 13:f67a6c6013ca 2924 short minEccKeySz; /* minimum ECC key size */
wolfSSL 13:f67a6c6013ca 2925 #endif
wolfSSL 13:f67a6c6013ca 2926 #ifdef OPENSSL_EXTRA
wolfSSL 13:f67a6c6013ca 2927 byte verifyDepth; /* maximum verification depth */
wolfSSL 13:f67a6c6013ca 2928 #endif
wolfSSL 13:f67a6c6013ca 2929 #ifdef WOLFSSL_EARLY_DATA
wolfSSL 13:f67a6c6013ca 2930 word32 maxEarlyDataSz;
wolfSSL 13:f67a6c6013ca 2931 #endif
wolfSSL 13:f67a6c6013ca 2932
wolfSSL 13:f67a6c6013ca 2933 } Options;
wolfSSL 13:f67a6c6013ca 2934
wolfSSL 13:f67a6c6013ca 2935 typedef struct Arrays {
wolfSSL 13:f67a6c6013ca 2936 byte* pendingMsg; /* defrag buffer */
wolfSSL 13:f67a6c6013ca 2937 byte* preMasterSecret;
wolfSSL 13:f67a6c6013ca 2938 word32 preMasterSz; /* differs for DH, actual size */
wolfSSL 13:f67a6c6013ca 2939 word32 pendingMsgSz; /* defrag buffer size */
wolfSSL 13:f67a6c6013ca 2940 word32 pendingMsgOffset; /* current offset into defrag buffer */
wolfSSL 13:f67a6c6013ca 2941 #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
wolfSSL 13:f67a6c6013ca 2942 word32 psk_keySz; /* actual size */
wolfSSL 13:f67a6c6013ca 2943 char client_identity[MAX_PSK_ID_LEN + NULL_TERM_LEN];
wolfSSL 13:f67a6c6013ca 2944 char server_hint[MAX_PSK_ID_LEN + NULL_TERM_LEN];
wolfSSL 13:f67a6c6013ca 2945 byte psk_key[MAX_PSK_KEY_LEN];
wolfSSL 13:f67a6c6013ca 2946 #endif
wolfSSL 13:f67a6c6013ca 2947 byte clientRandom[RAN_LEN];
wolfSSL 13:f67a6c6013ca 2948 byte serverRandom[RAN_LEN];
wolfSSL 13:f67a6c6013ca 2949 byte sessionID[ID_LEN];
wolfSSL 13:f67a6c6013ca 2950 byte sessionIDSz;
wolfSSL 13:f67a6c6013ca 2951 #ifdef WOLFSSL_TLS13
wolfSSL 13:f67a6c6013ca 2952 byte clientSecret[SECRET_LEN];
wolfSSL 13:f67a6c6013ca 2953 byte serverSecret[SECRET_LEN];
wolfSSL 13:f67a6c6013ca 2954 byte secret[SECRET_LEN];
wolfSSL 13:f67a6c6013ca 2955 #endif
wolfSSL 13:f67a6c6013ca 2956 byte masterSecret[SECRET_LEN];
wolfSSL 13:f67a6c6013ca 2957 #ifdef WOLFSSL_DTLS
wolfSSL 13:f67a6c6013ca 2958 byte cookie[MAX_COOKIE_LEN];
wolfSSL 13:f67a6c6013ca 2959 byte cookieSz;
wolfSSL 13:f67a6c6013ca 2960 #endif
wolfSSL 13:f67a6c6013ca 2961 byte pendingMsgType; /* defrag buffer message type */
wolfSSL 13:f67a6c6013ca 2962 } Arrays;
wolfSSL 13:f67a6c6013ca 2963
wolfSSL 13:f67a6c6013ca 2964 #ifndef ASN_NAME_MAX
wolfSSL 13:f67a6c6013ca 2965 #define ASN_NAME_MAX 256
wolfSSL 13:f67a6c6013ca 2966 #endif
wolfSSL 13:f67a6c6013ca 2967
wolfSSL 13:f67a6c6013ca 2968 #ifndef MAX_DATE_SZ
wolfSSL 13:f67a6c6013ca 2969 #define MAX_DATE_SZ 32
wolfSSL 13:f67a6c6013ca 2970 #endif
wolfSSL 13:f67a6c6013ca 2971
wolfSSL 13:f67a6c6013ca 2972 struct WOLFSSL_STACK {
wolfSSL 13:f67a6c6013ca 2973 unsigned long num; /* number of nodes in stack
wolfSSL 13:f67a6c6013ca 2974 * (saftey measure for freeing and shortcut for count) */
wolfSSL 13:f67a6c6013ca 2975 union {
wolfSSL 13:f67a6c6013ca 2976 WOLFSSL_X509* x509;
wolfSSL 13:f67a6c6013ca 2977 WOLFSSL_X509_NAME* name;
wolfSSL 13:f67a6c6013ca 2978 WOLFSSL_BIO* bio;
wolfSSL 13:f67a6c6013ca 2979 WOLFSSL_ASN1_OBJECT* obj;
wolfSSL 13:f67a6c6013ca 2980 char* string;
wolfSSL 13:f67a6c6013ca 2981 } data;
wolfSSL 13:f67a6c6013ca 2982 WOLFSSL_STACK* next;
wolfSSL 13:f67a6c6013ca 2983 };
wolfSSL 13:f67a6c6013ca 2984
wolfSSL 13:f67a6c6013ca 2985
wolfSSL 13:f67a6c6013ca 2986 struct WOLFSSL_X509_NAME {
wolfSSL 13:f67a6c6013ca 2987 char *name;
wolfSSL 13:f67a6c6013ca 2988 char staticName[ASN_NAME_MAX];
wolfSSL 13:f67a6c6013ca 2989 int dynamicName;
wolfSSL 13:f67a6c6013ca 2990 int sz;
wolfSSL 13:f67a6c6013ca 2991 #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
wolfSSL 13:f67a6c6013ca 2992 DecodedName fullName;
wolfSSL 13:f67a6c6013ca 2993 WOLFSSL_X509_NAME_ENTRY cnEntry;
wolfSSL 13:f67a6c6013ca 2994 WOLFSSL_X509* x509; /* x509 that struct belongs to */
wolfSSL 13:f67a6c6013ca 2995 #endif /* OPENSSL_EXTRA */
wolfSSL 13:f67a6c6013ca 2996 #ifdef WOLFSSL_NGINX
wolfSSL 13:f67a6c6013ca 2997 byte raw[ASN_NAME_MAX];
wolfSSL 13:f67a6c6013ca 2998 int rawLen;
wolfSSL 13:f67a6c6013ca 2999 #endif
wolfSSL 13:f67a6c6013ca 3000 };
wolfSSL 13:f67a6c6013ca 3001
wolfSSL 13:f67a6c6013ca 3002 #ifndef EXTERNAL_SERIAL_SIZE
wolfSSL 13:f67a6c6013ca 3003 #define EXTERNAL_SERIAL_SIZE 32
wolfSSL 13:f67a6c6013ca 3004 #endif
wolfSSL 13:f67a6c6013ca 3005
wolfSSL 13:f67a6c6013ca 3006 #ifdef NO_ASN
wolfSSL 13:f67a6c6013ca 3007 typedef struct DNS_entry DNS_entry;
wolfSSL 13:f67a6c6013ca 3008 #endif
wolfSSL 13:f67a6c6013ca 3009
wolfSSL 13:f67a6c6013ca 3010 struct WOLFSSL_X509 {
wolfSSL 13:f67a6c6013ca 3011 int version;
wolfSSL 13:f67a6c6013ca 3012 WOLFSSL_X509_NAME issuer;
wolfSSL 13:f67a6c6013ca 3013 WOLFSSL_X509_NAME subject;
wolfSSL 13:f67a6c6013ca 3014 int serialSz;
wolfSSL 13:f67a6c6013ca 3015 byte serial[EXTERNAL_SERIAL_SIZE];
wolfSSL 13:f67a6c6013ca 3016 char subjectCN[ASN_NAME_MAX]; /* common name short cut */
wolfSSL 13:f67a6c6013ca 3017 #ifdef WOLFSSL_SEP
wolfSSL 13:f67a6c6013ca 3018 int deviceTypeSz;
wolfSSL 13:f67a6c6013ca 3019 byte deviceType[EXTERNAL_SERIAL_SIZE];
wolfSSL 13:f67a6c6013ca 3020 int hwTypeSz;
wolfSSL 13:f67a6c6013ca 3021 byte hwType[EXTERNAL_SERIAL_SIZE];
wolfSSL 13:f67a6c6013ca 3022 int hwSerialNumSz;
wolfSSL 13:f67a6c6013ca 3023 byte hwSerialNum[EXTERNAL_SERIAL_SIZE];
wolfSSL 13:f67a6c6013ca 3024 #ifdef OPENSSL_EXTRA
wolfSSL 13:f67a6c6013ca 3025 byte certPolicySet;
wolfSSL 13:f67a6c6013ca 3026 byte certPolicyCrit;
wolfSSL 13:f67a6c6013ca 3027 #endif /* OPENSSL_EXTRA */
wolfSSL 13:f67a6c6013ca 3028 #endif
wolfSSL 13:f67a6c6013ca 3029 int notBeforeSz;
wolfSSL 13:f67a6c6013ca 3030 byte notBefore[MAX_DATE_SZ];
wolfSSL 13:f67a6c6013ca 3031 int notAfterSz;
wolfSSL 13:f67a6c6013ca 3032 byte notAfter[MAX_DATE_SZ];
wolfSSL 13:f67a6c6013ca 3033 int sigOID;
wolfSSL 13:f67a6c6013ca 3034 buffer sig;
wolfSSL 13:f67a6c6013ca 3035 int pubKeyOID;
wolfSSL 13:f67a6c6013ca 3036 buffer pubKey;
wolfSSL 13:f67a6c6013ca 3037 #ifdef HAVE_ECC
wolfSSL 13:f67a6c6013ca 3038 word32 pkCurveOID;
wolfSSL 13:f67a6c6013ca 3039 #endif /* HAVE_ECC */
wolfSSL 13:f67a6c6013ca 3040 #ifndef NO_CERTS
wolfSSL 13:f67a6c6013ca 3041 DerBuffer* derCert; /* may need */
wolfSSL 13:f67a6c6013ca 3042 #endif
wolfSSL 13:f67a6c6013ca 3043 DNS_entry* altNames; /* alt names list */
wolfSSL 13:f67a6c6013ca 3044 DNS_entry* altNamesNext; /* hint for retrieval */
wolfSSL 13:f67a6c6013ca 3045 void* heap; /* heap hint */
wolfSSL 13:f67a6c6013ca 3046 byte dynamicMemory; /* dynamic memory flag */
wolfSSL 13:f67a6c6013ca 3047 byte isCa;
wolfSSL 13:f67a6c6013ca 3048 #ifdef WOLFSSL_CERT_EXT
wolfSSL 13:f67a6c6013ca 3049 char certPolicies[MAX_CERTPOL_NB][MAX_CERTPOL_SZ];
wolfSSL 13:f67a6c6013ca 3050 int certPoliciesNb;
wolfSSL 13:f67a6c6013ca 3051 #endif /* WOLFSSL_CERT_EXT */
wolfSSL 13:f67a6c6013ca 3052 #ifdef OPENSSL_EXTRA
wolfSSL 13:f67a6c6013ca 3053 #ifdef HAVE_EX_DATA
wolfSSL 13:f67a6c6013ca 3054 void* ex_data[MAX_EX_DATA];
wolfSSL 13:f67a6c6013ca 3055 #endif
wolfSSL 13:f67a6c6013ca 3056 word32 pathLength;
wolfSSL 13:f67a6c6013ca 3057 word16 keyUsage;
wolfSSL 13:f67a6c6013ca 3058 byte CRLdistSet;
wolfSSL 13:f67a6c6013ca 3059 byte CRLdistCrit;
wolfSSL 13:f67a6c6013ca 3060 byte* CRLInfo;
wolfSSL 13:f67a6c6013ca 3061 int CRLInfoSz;
wolfSSL 13:f67a6c6013ca 3062 byte authInfoSet;
wolfSSL 13:f67a6c6013ca 3063 byte authInfoCrit;
wolfSSL 13:f67a6c6013ca 3064 byte* authInfo;
wolfSSL 13:f67a6c6013ca 3065 int authInfoSz;
wolfSSL 13:f67a6c6013ca 3066 byte basicConstSet;
wolfSSL 13:f67a6c6013ca 3067 byte basicConstCrit;
wolfSSL 13:f67a6c6013ca 3068 byte basicConstPlSet;
wolfSSL 13:f67a6c6013ca 3069 byte subjAltNameSet;
wolfSSL 13:f67a6c6013ca 3070 byte subjAltNameCrit;
wolfSSL 13:f67a6c6013ca 3071 byte authKeyIdSet;
wolfSSL 13:f67a6c6013ca 3072 byte authKeyIdCrit;
wolfSSL 13:f67a6c6013ca 3073 byte* authKeyId;
wolfSSL 13:f67a6c6013ca 3074 word32 authKeyIdSz;
wolfSSL 13:f67a6c6013ca 3075 byte subjKeyIdSet;
wolfSSL 13:f67a6c6013ca 3076 byte subjKeyIdCrit;
wolfSSL 13:f67a6c6013ca 3077 byte* subjKeyId;
wolfSSL 13:f67a6c6013ca 3078 word32 subjKeyIdSz;
wolfSSL 13:f67a6c6013ca 3079 byte keyUsageSet;
wolfSSL 13:f67a6c6013ca 3080 byte keyUsageCrit;
wolfSSL 13:f67a6c6013ca 3081 byte extKeyUsageCrit;
wolfSSL 13:f67a6c6013ca 3082 byte* extKeyUsageSrc;
wolfSSL 13:f67a6c6013ca 3083 word32 extKeyUsageSz;
wolfSSL 13:f67a6c6013ca 3084 word32 extKeyUsageCount;
wolfSSL 13:f67a6c6013ca 3085 #endif /* OPENSSL_EXTRA */
wolfSSL 13:f67a6c6013ca 3086 };
wolfSSL 13:f67a6c6013ca 3087
wolfSSL 13:f67a6c6013ca 3088
wolfSSL 13:f67a6c6013ca 3089 /* record layer header for PlainText, Compressed, and CipherText */
wolfSSL 13:f67a6c6013ca 3090 typedef struct RecordLayerHeader {
wolfSSL 13:f67a6c6013ca 3091 byte type;
wolfSSL 13:f67a6c6013ca 3092 byte pvMajor;
wolfSSL 13:f67a6c6013ca 3093 byte pvMinor;
wolfSSL 13:f67a6c6013ca 3094 byte length[2];
wolfSSL 13:f67a6c6013ca 3095 } RecordLayerHeader;
wolfSSL 13:f67a6c6013ca 3096
wolfSSL 13:f67a6c6013ca 3097
wolfSSL 13:f67a6c6013ca 3098 /* record layer header for DTLS PlainText, Compressed, and CipherText */
wolfSSL 13:f67a6c6013ca 3099 typedef struct DtlsRecordLayerHeader {
wolfSSL 13:f67a6c6013ca 3100 byte type;
wolfSSL 13:f67a6c6013ca 3101 byte pvMajor;
wolfSSL 13:f67a6c6013ca 3102 byte pvMinor;
wolfSSL 13:f67a6c6013ca 3103 byte sequence_number[8]; /* per record */
wolfSSL 13:f67a6c6013ca 3104 byte length[2];
wolfSSL 13:f67a6c6013ca 3105 } DtlsRecordLayerHeader;
wolfSSL 13:f67a6c6013ca 3106
wolfSSL 13:f67a6c6013ca 3107
wolfSSL 13:f67a6c6013ca 3108 typedef struct DtlsFrag {
wolfSSL 13:f67a6c6013ca 3109 word32 begin;
wolfSSL 13:f67a6c6013ca 3110 word32 end;
wolfSSL 13:f67a6c6013ca 3111 struct DtlsFrag* next;
wolfSSL 13:f67a6c6013ca 3112 } DtlsFrag;
wolfSSL 13:f67a6c6013ca 3113
wolfSSL 13:f67a6c6013ca 3114
wolfSSL 13:f67a6c6013ca 3115 typedef struct DtlsMsg {
wolfSSL 13:f67a6c6013ca 3116 struct DtlsMsg* next;
wolfSSL 13:f67a6c6013ca 3117 byte* buf;
wolfSSL 13:f67a6c6013ca 3118 byte* msg;
wolfSSL 13:f67a6c6013ca 3119 DtlsFrag* fragList;
wolfSSL 13:f67a6c6013ca 3120 word32 fragSz; /* Length of fragments received */
wolfSSL 13:f67a6c6013ca 3121 word32 seq; /* Handshake sequence number */
wolfSSL 13:f67a6c6013ca 3122 word32 sz; /* Length of whole mesage */
wolfSSL 13:f67a6c6013ca 3123 byte type;
wolfSSL 13:f67a6c6013ca 3124 } DtlsMsg;
wolfSSL 13:f67a6c6013ca 3125
wolfSSL 13:f67a6c6013ca 3126
wolfSSL 13:f67a6c6013ca 3127 #ifdef HAVE_NETX
wolfSSL 13:f67a6c6013ca 3128
wolfSSL 13:f67a6c6013ca 3129 /* NETX I/O Callback default */
wolfSSL 13:f67a6c6013ca 3130 typedef struct NetX_Ctx {
wolfSSL 13:f67a6c6013ca 3131 NX_TCP_SOCKET* nxSocket; /* send/recv socket handle */
wolfSSL 13:f67a6c6013ca 3132 NX_PACKET* nxPacket; /* incoming packet handle for short reads */
wolfSSL 13:f67a6c6013ca 3133 ULONG nxOffset; /* offset already read from nxPacket */
wolfSSL 13:f67a6c6013ca 3134 ULONG nxWait; /* wait option flag */
wolfSSL 13:f67a6c6013ca 3135 } NetX_Ctx;
wolfSSL 13:f67a6c6013ca 3136
wolfSSL 13:f67a6c6013ca 3137 #endif
wolfSSL 13:f67a6c6013ca 3138
wolfSSL 13:f67a6c6013ca 3139
wolfSSL 13:f67a6c6013ca 3140 /* Handshake messages received from peer (plus change cipher */
wolfSSL 13:f67a6c6013ca 3141 typedef struct MsgsReceived {
wolfSSL 13:f67a6c6013ca 3142 word16 got_hello_request:1;
wolfSSL 13:f67a6c6013ca 3143 word16 got_client_hello:2;
wolfSSL 13:f67a6c6013ca 3144 word16 got_server_hello:1;
wolfSSL 13:f67a6c6013ca 3145 word16 got_hello_verify_request:1;
wolfSSL 13:f67a6c6013ca 3146 word16 got_session_ticket:1;
wolfSSL 13:f67a6c6013ca 3147 word16 got_end_of_early_data:1;
wolfSSL 13:f67a6c6013ca 3148 word16 got_hello_retry_request:1;
wolfSSL 13:f67a6c6013ca 3149 word16 got_encrypted_extensions:1;
wolfSSL 13:f67a6c6013ca 3150 word16 got_certificate:1;
wolfSSL 13:f67a6c6013ca 3151 word16 got_certificate_status:1;
wolfSSL 13:f67a6c6013ca 3152 word16 got_server_key_exchange:1;
wolfSSL 13:f67a6c6013ca 3153 word16 got_certificate_request:1;
wolfSSL 13:f67a6c6013ca 3154 word16 got_server_hello_done:1;
wolfSSL 13:f67a6c6013ca 3155 word16 got_certificate_verify:1;
wolfSSL 13:f67a6c6013ca 3156 word16 got_client_key_exchange:1;
wolfSSL 13:f67a6c6013ca 3157 word16 got_finished:1;
wolfSSL 13:f67a6c6013ca 3158 word16 got_key_update:1;
wolfSSL 13:f67a6c6013ca 3159 word16 got_change_cipher:1;
wolfSSL 13:f67a6c6013ca 3160 } MsgsReceived;
wolfSSL 13:f67a6c6013ca 3161
wolfSSL 13:f67a6c6013ca 3162
wolfSSL 13:f67a6c6013ca 3163 /* Handshake hashes */
wolfSSL 13:f67a6c6013ca 3164 typedef struct HS_Hashes {
wolfSSL 13:f67a6c6013ca 3165 Hashes verifyHashes;
wolfSSL 13:f67a6c6013ca 3166 Hashes certHashes; /* for cert verify */
wolfSSL 13:f67a6c6013ca 3167 #ifndef NO_SHA
wolfSSL 13:f67a6c6013ca 3168 Sha hashSha; /* sha hash of handshake msgs */
wolfSSL 13:f67a6c6013ca 3169 #endif
wolfSSL 13:f67a6c6013ca 3170 #if !defined(NO_MD5) && !defined(NO_OLD_TLS)
wolfSSL 13:f67a6c6013ca 3171 Md5 hashMd5; /* md5 hash of handshake msgs */
wolfSSL 13:f67a6c6013ca 3172 #endif
wolfSSL 13:f67a6c6013ca 3173 #ifndef NO_SHA256
wolfSSL 13:f67a6c6013ca 3174 Sha256 hashSha256; /* sha256 hash of handshake msgs */
wolfSSL 13:f67a6c6013ca 3175 #endif
wolfSSL 13:f67a6c6013ca 3176 #ifdef WOLFSSL_SHA384
wolfSSL 13:f67a6c6013ca 3177 Sha384 hashSha384; /* sha384 hash of handshake msgs */
wolfSSL 13:f67a6c6013ca 3178 #endif
wolfSSL 13:f67a6c6013ca 3179 #ifdef WOLFSSL_SHA512
wolfSSL 13:f67a6c6013ca 3180 Sha512 hashSha512; /* sha512 hash of handshake msgs */
wolfSSL 13:f67a6c6013ca 3181 #endif
wolfSSL 13:f67a6c6013ca 3182 } HS_Hashes;
wolfSSL 13:f67a6c6013ca 3183
wolfSSL 13:f67a6c6013ca 3184
wolfSSL 13:f67a6c6013ca 3185 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 13:f67a6c6013ca 3186 #define MAX_ASYNC_ARGS 18
wolfSSL 13:f67a6c6013ca 3187 typedef void (*FreeArgsCb)(struct WOLFSSL* ssl, void* pArgs);
wolfSSL 13:f67a6c6013ca 3188
wolfSSL 13:f67a6c6013ca 3189 struct WOLFSSL_ASYNC {
wolfSSL 13:f67a6c6013ca 3190 WC_ASYNC_DEV* dev;
wolfSSL 13:f67a6c6013ca 3191 FreeArgsCb freeArgs; /* function pointer to cleanup args */
wolfSSL 13:f67a6c6013ca 3192 word32 args[MAX_ASYNC_ARGS]; /* holder for current args */
wolfSSL 13:f67a6c6013ca 3193 };
wolfSSL 13:f67a6c6013ca 3194 #endif
wolfSSL 13:f67a6c6013ca 3195
wolfSSL 13:f67a6c6013ca 3196 #ifdef HAVE_WRITE_DUP
wolfSSL 13:f67a6c6013ca 3197
wolfSSL 13:f67a6c6013ca 3198 #define WRITE_DUP_SIDE 1
wolfSSL 13:f67a6c6013ca 3199 #define READ_DUP_SIDE 2
wolfSSL 13:f67a6c6013ca 3200
wolfSSL 13:f67a6c6013ca 3201 typedef struct WriteDup {
wolfSSL 13:f67a6c6013ca 3202 wolfSSL_Mutex dupMutex; /* reference count mutex */
wolfSSL 13:f67a6c6013ca 3203 int dupCount; /* reference count */
wolfSSL 13:f67a6c6013ca 3204 int dupErr; /* under dupMutex, pass to other side */
wolfSSL 13:f67a6c6013ca 3205 } WriteDup;
wolfSSL 13:f67a6c6013ca 3206
wolfSSL 13:f67a6c6013ca 3207 WOLFSSL_LOCAL void FreeWriteDup(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 3208 WOLFSSL_LOCAL int NotifyWriteSide(WOLFSSL* ssl, int err);
wolfSSL 13:f67a6c6013ca 3209 #endif /* HAVE_WRITE_DUP */
wolfSSL 13:f67a6c6013ca 3210
wolfSSL 13:f67a6c6013ca 3211 #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
wolfSSL 13:f67a6c6013ca 3212 typedef struct CertReqCtx CertReqCtx;
wolfSSL 13:f67a6c6013ca 3213
wolfSSL 13:f67a6c6013ca 3214 struct CertReqCtx {
wolfSSL 13:f67a6c6013ca 3215 CertReqCtx* next;
wolfSSL 13:f67a6c6013ca 3216 byte len;
wolfSSL 13:f67a6c6013ca 3217 byte ctx;
wolfSSL 13:f67a6c6013ca 3218 };
wolfSSL 13:f67a6c6013ca 3219 #endif
wolfSSL 13:f67a6c6013ca 3220
wolfSSL 13:f67a6c6013ca 3221 /* wolfSSL ssl type */
wolfSSL 13:f67a6c6013ca 3222 struct WOLFSSL {
wolfSSL 13:f67a6c6013ca 3223 WOLFSSL_CTX* ctx;
wolfSSL 13:f67a6c6013ca 3224 Suites* suites; /* only need during handshake */
wolfSSL 13:f67a6c6013ca 3225 Arrays* arrays;
wolfSSL 13:f67a6c6013ca 3226 HS_Hashes* hsHashes;
wolfSSL 13:f67a6c6013ca 3227 void* IOCB_ReadCtx;
wolfSSL 13:f67a6c6013ca 3228 void* IOCB_WriteCtx;
wolfSSL 13:f67a6c6013ca 3229 WC_RNG* rng;
wolfSSL 13:f67a6c6013ca 3230 void* verifyCbCtx; /* cert verify callback user ctx*/
wolfSSL 13:f67a6c6013ca 3231 VerifyCallback verifyCallback; /* cert verification callback */
wolfSSL 13:f67a6c6013ca 3232 void* heap; /* for user overrides */
wolfSSL 13:f67a6c6013ca 3233 #ifdef HAVE_WRITE_DUP
wolfSSL 13:f67a6c6013ca 3234 WriteDup* dupWrite; /* valid pointer indicates ON */
wolfSSL 13:f67a6c6013ca 3235 /* side that decrements dupCount to zero frees overall structure */
wolfSSL 13:f67a6c6013ca 3236 byte dupSide; /* write side or read side */
wolfSSL 13:f67a6c6013ca 3237 #endif
wolfSSL 13:f67a6c6013ca 3238 #ifdef WOLFSSL_STATIC_MEMORY
wolfSSL 13:f67a6c6013ca 3239 WOLFSSL_HEAP_HINT heap_hint;
wolfSSL 13:f67a6c6013ca 3240 #endif
wolfSSL 13:f67a6c6013ca 3241 #ifndef NO_HANDSHAKE_DONE_CB
wolfSSL 13:f67a6c6013ca 3242 HandShakeDoneCb hsDoneCb; /* notify user handshake done */
wolfSSL 13:f67a6c6013ca 3243 void* hsDoneCtx; /* user handshake cb context */
wolfSSL 13:f67a6c6013ca 3244 #endif
wolfSSL 13:f67a6c6013ca 3245 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 13:f67a6c6013ca 3246 struct WOLFSSL_ASYNC async;
wolfSSL 13:f67a6c6013ca 3247 #endif
wolfSSL 13:f67a6c6013ca 3248 void* hsKey; /* Handshake key (RsaKey or ecc_key) allocated from heap */
wolfSSL 13:f67a6c6013ca 3249 word32 hsType; /* Type of Handshake key (hsKey) */
wolfSSL 13:f67a6c6013ca 3250 WOLFSSL_CIPHER cipher;
wolfSSL 13:f67a6c6013ca 3251 hmacfp hmac;
wolfSSL 13:f67a6c6013ca 3252 Ciphers encrypt;
wolfSSL 13:f67a6c6013ca 3253 Ciphers decrypt;
wolfSSL 13:f67a6c6013ca 3254 Buffers buffers;
wolfSSL 13:f67a6c6013ca 3255 WOLFSSL_SESSION session;
wolfSSL 13:f67a6c6013ca 3256 #ifdef HAVE_EXT_CACHE
wolfSSL 13:f67a6c6013ca 3257 WOLFSSL_SESSION* extSession;
wolfSSL 13:f67a6c6013ca 3258 #endif
wolfSSL 13:f67a6c6013ca 3259 WOLFSSL_ALERT_HISTORY alert_history;
wolfSSL 13:f67a6c6013ca 3260 int error;
wolfSSL 13:f67a6c6013ca 3261 int rfd; /* read file descriptor */
wolfSSL 13:f67a6c6013ca 3262 int wfd; /* write file descriptor */
wolfSSL 13:f67a6c6013ca 3263 int rflags; /* user read flags */
wolfSSL 13:f67a6c6013ca 3264 int wflags; /* user write flags */
wolfSSL 13:f67a6c6013ca 3265 word32 timeout; /* session timeout */
wolfSSL 13:f67a6c6013ca 3266 word32 fragOffset; /* fragment offset */
wolfSSL 13:f67a6c6013ca 3267 word16 curSize;
wolfSSL 13:f67a6c6013ca 3268 RecordLayerHeader curRL;
wolfSSL 13:f67a6c6013ca 3269 MsgsReceived msgsReceived; /* peer messages received */
wolfSSL 13:f67a6c6013ca 3270 ProtocolVersion version; /* negotiated version */
wolfSSL 13:f67a6c6013ca 3271 ProtocolVersion chVersion; /* client hello version */
wolfSSL 13:f67a6c6013ca 3272 CipherSpecs specs;
wolfSSL 13:f67a6c6013ca 3273 Keys keys;
wolfSSL 13:f67a6c6013ca 3274 Options options;
wolfSSL 13:f67a6c6013ca 3275 #ifdef OPENSSL_EXTRA
wolfSSL 13:f67a6c6013ca 3276 WOLFSSL_BIO* biord; /* socket bio read to free/close */
wolfSSL 13:f67a6c6013ca 3277 WOLFSSL_BIO* biowr; /* socket bio write to free/close */
wolfSSL 13:f67a6c6013ca 3278 unsigned long peerVerifyRet;
wolfSSL 13:f67a6c6013ca 3279 byte readAhead;
wolfSSL 13:f67a6c6013ca 3280 #ifdef HAVE_PK_CALLBACKS
wolfSSL 13:f67a6c6013ca 3281 void* loggingCtx; /* logging callback argument */
wolfSSL 13:f67a6c6013ca 3282 #endif
wolfSSL 13:f67a6c6013ca 3283 #endif
wolfSSL 13:f67a6c6013ca 3284 #ifndef NO_RSA
wolfSSL 13:f67a6c6013ca 3285 RsaKey* peerRsaKey;
wolfSSL 13:f67a6c6013ca 3286 byte peerRsaKeyPresent;
wolfSSL 13:f67a6c6013ca 3287 #endif
wolfSSL 13:f67a6c6013ca 3288 #ifdef HAVE_QSH
wolfSSL 13:f67a6c6013ca 3289 QSHKey* QSH_Key;
wolfSSL 13:f67a6c6013ca 3290 QSHKey* peerQSHKey;
wolfSSL 13:f67a6c6013ca 3291 QSHSecret* QSH_secret;
wolfSSL 13:f67a6c6013ca 3292 byte isQSH; /* is the handshake a QSH? */
wolfSSL 13:f67a6c6013ca 3293 byte sendQSHKeys; /* flag for if the client should sen
wolfSSL 13:f67a6c6013ca 3294 public keys */
wolfSSL 13:f67a6c6013ca 3295 byte peerQSHKeyPresent;
wolfSSL 13:f67a6c6013ca 3296 byte minRequest;
wolfSSL 13:f67a6c6013ca 3297 byte maxRequest;
wolfSSL 13:f67a6c6013ca 3298 byte user_set_QSHSchemes;
wolfSSL 13:f67a6c6013ca 3299 #endif
wolfSSL 13:f67a6c6013ca 3300 #ifdef WOLFSSL_TLS13
wolfSSL 13:f67a6c6013ca 3301 word16 namedGroup;
wolfSSL 13:f67a6c6013ca 3302 #endif
wolfSSL 13:f67a6c6013ca 3303 byte pssAlgo;
wolfSSL 13:f67a6c6013ca 3304 #ifdef HAVE_NTRU
wolfSSL 13:f67a6c6013ca 3305 word16 peerNtruKeyLen;
wolfSSL 13:f67a6c6013ca 3306 byte peerNtruKey[MAX_NTRU_PUB_KEY_SZ];
wolfSSL 13:f67a6c6013ca 3307 byte peerNtruKeyPresent;
wolfSSL 13:f67a6c6013ca 3308 #endif
wolfSSL 13:f67a6c6013ca 3309 #if defined(HAVE_ECC) || defined(HAVE_ED25519)
wolfSSL 13:f67a6c6013ca 3310 int eccVerifyRes;
wolfSSL 13:f67a6c6013ca 3311 #endif
wolfSSL 13:f67a6c6013ca 3312 #if defined(HAVE_ECC) || defined(HAVE_CURVE25519)
wolfSSL 13:f67a6c6013ca 3313 word32 ecdhCurveOID; /* curve Ecc_Sum */
wolfSSL 13:f67a6c6013ca 3314 ecc_key* eccTempKey; /* private ECDHE key */
wolfSSL 13:f67a6c6013ca 3315 byte eccTempKeyPresent;
wolfSSL 13:f67a6c6013ca 3316 byte peerEccKeyPresent;
wolfSSL 13:f67a6c6013ca 3317 #endif
wolfSSL 13:f67a6c6013ca 3318 #ifdef HAVE_ECC
wolfSSL 13:f67a6c6013ca 3319 ecc_key* peerEccKey; /* peer's ECDHE key */
wolfSSL 13:f67a6c6013ca 3320 ecc_key* peerEccDsaKey; /* peer's ECDSA key */
wolfSSL 13:f67a6c6013ca 3321 word32 pkCurveOID; /* curve Ecc_Sum */
wolfSSL 13:f67a6c6013ca 3322 word16 eccTempKeySz; /* in octets 20 - 66 */
wolfSSL 13:f67a6c6013ca 3323 byte peerEccDsaKeyPresent;
wolfSSL 13:f67a6c6013ca 3324 #endif
wolfSSL 13:f67a6c6013ca 3325 #ifdef HAVE_ED25519
wolfSSL 13:f67a6c6013ca 3326 ed25519_key* peerEd25519Key;
wolfSSL 13:f67a6c6013ca 3327 byte peerEd25519KeyPresent;
wolfSSL 13:f67a6c6013ca 3328 #endif
wolfSSL 13:f67a6c6013ca 3329 #ifdef HAVE_CURVE25519
wolfSSL 13:f67a6c6013ca 3330 curve25519_key* peerX25519Key;
wolfSSL 13:f67a6c6013ca 3331 byte peerX25519KeyPresent;
wolfSSL 13:f67a6c6013ca 3332 #endif
wolfSSL 13:f67a6c6013ca 3333 #ifdef HAVE_LIBZ
wolfSSL 13:f67a6c6013ca 3334 z_stream c_stream; /* compression stream */
wolfSSL 13:f67a6c6013ca 3335 z_stream d_stream; /* decompression stream */
wolfSSL 13:f67a6c6013ca 3336 byte didStreamInit; /* for stream init and end */
wolfSSL 13:f67a6c6013ca 3337 #endif
wolfSSL 13:f67a6c6013ca 3338 #ifdef WOLFSSL_DTLS
wolfSSL 13:f67a6c6013ca 3339 int dtls_timeout_init; /* starting timeout value */
wolfSSL 13:f67a6c6013ca 3340 int dtls_timeout_max; /* maximum timeout value */
wolfSSL 13:f67a6c6013ca 3341 int dtls_timeout; /* current timeout value, changes */
wolfSSL 13:f67a6c6013ca 3342 word32 dtls_tx_msg_list_sz;
wolfSSL 13:f67a6c6013ca 3343 word32 dtls_rx_msg_list_sz;
wolfSSL 13:f67a6c6013ca 3344 DtlsMsg* dtls_tx_msg_list;
wolfSSL 13:f67a6c6013ca 3345 DtlsMsg* dtls_rx_msg_list;
wolfSSL 13:f67a6c6013ca 3346 void* IOCB_CookieCtx; /* gen cookie ctx */
wolfSSL 13:f67a6c6013ca 3347 word32 dtls_expected_rx;
wolfSSL 13:f67a6c6013ca 3348 wc_dtls_export dtls_export; /* export function for session */
wolfSSL 13:f67a6c6013ca 3349 #ifdef WOLFSSL_SCTP
wolfSSL 13:f67a6c6013ca 3350 word16 dtlsMtuSz;
wolfSSL 13:f67a6c6013ca 3351 #endif /* WOLFSSL_SCTP */
wolfSSL 13:f67a6c6013ca 3352 #ifdef WOLFSSL_MULTICAST
wolfSSL 13:f67a6c6013ca 3353 void* mcastHwCbCtx; /* Multicast highwater callback ctx */
wolfSSL 13:f67a6c6013ca 3354 #endif /* WOLFSSL_MULTICAST */
wolfSSL 13:f67a6c6013ca 3355 #ifdef WOLFSSL_DTLS_DROP_STATS
wolfSSL 13:f67a6c6013ca 3356 word32 macDropCount;
wolfSSL 13:f67a6c6013ca 3357 word32 replayDropCount;
wolfSSL 13:f67a6c6013ca 3358 #endif /* WOLFSSL_DTLS_DROP_STATS */
wolfSSL 13:f67a6c6013ca 3359 #endif /* WOLFSSL_DTLS */
wolfSSL 13:f67a6c6013ca 3360 #ifdef WOLFSSL_CALLBACKS
wolfSSL 13:f67a6c6013ca 3361 HandShakeInfo handShakeInfo; /* info saved during handshake */
wolfSSL 13:f67a6c6013ca 3362 TimeoutInfo timeoutInfo; /* info saved during handshake */
wolfSSL 13:f67a6c6013ca 3363 byte hsInfoOn; /* track handshake info */
wolfSSL 13:f67a6c6013ca 3364 byte toInfoOn; /* track timeout info */
wolfSSL 13:f67a6c6013ca 3365 #endif
wolfSSL 13:f67a6c6013ca 3366 #ifdef HAVE_FUZZER
wolfSSL 13:f67a6c6013ca 3367 CallbackFuzzer fuzzerCb; /* for testing with using fuzzer */
wolfSSL 13:f67a6c6013ca 3368 void* fuzzerCtx; /* user defined pointer */
wolfSSL 13:f67a6c6013ca 3369 #endif
wolfSSL 13:f67a6c6013ca 3370 #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
wolfSSL 13:f67a6c6013ca 3371 CertReqCtx* certReqCtx;
wolfSSL 13:f67a6c6013ca 3372 #endif
wolfSSL 13:f67a6c6013ca 3373 #ifdef KEEP_PEER_CERT
wolfSSL 13:f67a6c6013ca 3374 WOLFSSL_X509 peerCert; /* X509 peer cert */
wolfSSL 13:f67a6c6013ca 3375 #endif
wolfSSL 13:f67a6c6013ca 3376 #ifdef KEEP_OUR_CERT
wolfSSL 13:f67a6c6013ca 3377 WOLFSSL_X509* ourCert; /* keep alive a X509 struct of cert.
wolfSSL 13:f67a6c6013ca 3378 points to ctx if not owned (owned
wolfSSL 13:f67a6c6013ca 3379 flag found in buffers.weOwnCert) */
wolfSSL 13:f67a6c6013ca 3380 #endif
wolfSSL 13:f67a6c6013ca 3381 byte keepCert; /* keep certificate after handshake */
wolfSSL 13:f67a6c6013ca 3382 #if defined(HAVE_EX_DATA) || defined(FORTRESS)
wolfSSL 13:f67a6c6013ca 3383 void* ex_data[MAX_EX_DATA]; /* external data, for Fortress */
wolfSSL 13:f67a6c6013ca 3384 #endif
wolfSSL 13:f67a6c6013ca 3385 int devId; /* async device id to use */
wolfSSL 13:f67a6c6013ca 3386 #ifdef HAVE_ONE_TIME_AUTH
wolfSSL 13:f67a6c6013ca 3387 OneTimeAuth auth;
wolfSSL 13:f67a6c6013ca 3388 #endif
wolfSSL 13:f67a6c6013ca 3389 #ifdef HAVE_TLS_EXTENSIONS
wolfSSL 13:f67a6c6013ca 3390 TLSX* extensions; /* RFC 6066 TLS Extensions data */
wolfSSL 13:f67a6c6013ca 3391 #ifdef HAVE_MAX_FRAGMENT
wolfSSL 13:f67a6c6013ca 3392 word16 max_fragment;
wolfSSL 13:f67a6c6013ca 3393 #endif
wolfSSL 13:f67a6c6013ca 3394 #ifdef HAVE_TRUNCATED_HMAC
wolfSSL 13:f67a6c6013ca 3395 byte truncated_hmac;
wolfSSL 13:f67a6c6013ca 3396 #endif
wolfSSL 13:f67a6c6013ca 3397 #ifdef HAVE_CERTIFICATE_STATUS_REQUEST
wolfSSL 13:f67a6c6013ca 3398 byte status_request;
wolfSSL 13:f67a6c6013ca 3399 #endif
wolfSSL 13:f67a6c6013ca 3400 #ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
wolfSSL 13:f67a6c6013ca 3401 byte status_request_v2;
wolfSSL 13:f67a6c6013ca 3402 #endif
wolfSSL 13:f67a6c6013ca 3403 #if defined(HAVE_SECURE_RENEGOTIATION) \
wolfSSL 13:f67a6c6013ca 3404 || defined(HAVE_SERVER_RENEGOTIATION_INFO)
wolfSSL 13:f67a6c6013ca 3405 SecureRenegotiation* secure_renegotiation; /* valid pointer indicates */
wolfSSL 13:f67a6c6013ca 3406 #endif /* user turned on */
wolfSSL 13:f67a6c6013ca 3407 #ifdef HAVE_ALPN
wolfSSL 13:f67a6c6013ca 3408 char* alpn_client_list; /* keep the client's list */
wolfSSL 13:f67a6c6013ca 3409 #if defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
wolfSSL 13:f67a6c6013ca 3410 CallbackALPNSelect alpnSelect;
wolfSSL 13:f67a6c6013ca 3411 void* alpnSelectArg;
wolfSSL 13:f67a6c6013ca 3412 #endif
wolfSSL 13:f67a6c6013ca 3413 #endif /* of accepted protocols */
wolfSSL 13:f67a6c6013ca 3414 #if !defined(NO_WOLFSSL_CLIENT) && defined(HAVE_SESSION_TICKET)
wolfSSL 13:f67a6c6013ca 3415 CallbackSessionTicket session_ticket_cb;
wolfSSL 13:f67a6c6013ca 3416 void* session_ticket_ctx;
wolfSSL 13:f67a6c6013ca 3417 byte expect_session_ticket;
wolfSSL 13:f67a6c6013ca 3418 #endif
wolfSSL 13:f67a6c6013ca 3419 #endif /* HAVE_TLS_EXTENSIONS */
wolfSSL 13:f67a6c6013ca 3420 #ifdef OPENSSL_EXTRA
wolfSSL 13:f67a6c6013ca 3421 byte* ocspResp;
wolfSSL 13:f67a6c6013ca 3422 int ocspRespSz;
wolfSSL 13:f67a6c6013ca 3423 #if defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
wolfSSL 13:f67a6c6013ca 3424 char* url;
wolfSSL 13:f67a6c6013ca 3425 #endif
wolfSSL 13:f67a6c6013ca 3426 #endif
wolfSSL 13:f67a6c6013ca 3427 #ifdef HAVE_NETX
wolfSSL 13:f67a6c6013ca 3428 NetX_Ctx nxCtx; /* NetX IO Context */
wolfSSL 13:f67a6c6013ca 3429 #endif
wolfSSL 13:f67a6c6013ca 3430 #ifdef SESSION_INDEX
wolfSSL 13:f67a6c6013ca 3431 int sessionIndex; /* Session's location in the cache. */
wolfSSL 13:f67a6c6013ca 3432 #endif
wolfSSL 13:f67a6c6013ca 3433 #ifdef ATOMIC_USER
wolfSSL 13:f67a6c6013ca 3434 void* MacEncryptCtx; /* Atomic User Mac/Encrypt Callback Context */
wolfSSL 13:f67a6c6013ca 3435 void* DecryptVerifyCtx; /* Atomic User Decrypt/Verify Callback Context */
wolfSSL 13:f67a6c6013ca 3436 #endif
wolfSSL 13:f67a6c6013ca 3437 #ifdef HAVE_PK_CALLBACKS
wolfSSL 13:f67a6c6013ca 3438 #ifdef HAVE_ECC
wolfSSL 13:f67a6c6013ca 3439 void* EccSignCtx; /* Ecc Sign Callback Context */
wolfSSL 13:f67a6c6013ca 3440 void* EccVerifyCtx; /* Ecc Verify Callback Context */
wolfSSL 13:f67a6c6013ca 3441 void* EccSharedSecretCtx; /* Ecc Pms Callback Context */
wolfSSL 13:f67a6c6013ca 3442 #ifdef HAVE_ED25519
wolfSSL 13:f67a6c6013ca 3443 void* Ed25519SignCtx; /* ED25519 Sign Callback Context */
wolfSSL 13:f67a6c6013ca 3444 void* Ed25519VerifyCtx; /* ED25519 Verify Callback Context */
wolfSSL 13:f67a6c6013ca 3445 #endif
wolfSSL 13:f67a6c6013ca 3446 #ifdef HAVE_CURVE25519
wolfSSL 13:f67a6c6013ca 3447 void* X25519SharedSecretCtx; /* X25519 Pms Callback Context */
wolfSSL 13:f67a6c6013ca 3448 #endif
wolfSSL 13:f67a6c6013ca 3449 #endif /* HAVE_ECC */
wolfSSL 13:f67a6c6013ca 3450 #ifndef NO_RSA
wolfSSL 13:f67a6c6013ca 3451 void* RsaSignCtx; /* Rsa Sign Callback Context */
wolfSSL 13:f67a6c6013ca 3452 void* RsaVerifyCtx; /* Rsa Verify Callback Context */
wolfSSL 13:f67a6c6013ca 3453 #ifdef WC_RSA_PSS
wolfSSL 13:f67a6c6013ca 3454 void* RsaPssSignCtx; /* Rsa PSS Sign Callback Context */
wolfSSL 13:f67a6c6013ca 3455 void* RsaPssVerifyCtx; /* Rsa PSS Verify Callback Context */
wolfSSL 13:f67a6c6013ca 3456 #endif
wolfSSL 13:f67a6c6013ca 3457 void* RsaEncCtx; /* Rsa Public Encrypt Callback Context */
wolfSSL 13:f67a6c6013ca 3458 void* RsaDecCtx; /* Rsa Private Decrypt Callback Context */
wolfSSL 13:f67a6c6013ca 3459 #endif /* NO_RSA */
wolfSSL 13:f67a6c6013ca 3460 #endif /* HAVE_PK_CALLBACKS */
wolfSSL 13:f67a6c6013ca 3461 #ifdef HAVE_SECRET_CALLBACK
wolfSSL 13:f67a6c6013ca 3462 SessionSecretCb sessionSecretCb;
wolfSSL 13:f67a6c6013ca 3463 void* sessionSecretCtx;
wolfSSL 13:f67a6c6013ca 3464 #endif /* HAVE_SECRET_CALLBACK */
wolfSSL 13:f67a6c6013ca 3465 #ifdef WOLFSSL_JNI
wolfSSL 13:f67a6c6013ca 3466 void* jObjectRef; /* reference to WolfSSLSession in JNI wrapper */
wolfSSL 13:f67a6c6013ca 3467 #endif /* WOLFSSL_JNI */
wolfSSL 13:f67a6c6013ca 3468 #ifdef WOLFSSL_EARLY_DATA
wolfSSL 13:f67a6c6013ca 3469 int earlyData;
wolfSSL 13:f67a6c6013ca 3470 word32 earlyDataSz;
wolfSSL 13:f67a6c6013ca 3471 #endif
wolfSSL 13:f67a6c6013ca 3472 };
wolfSSL 13:f67a6c6013ca 3473
wolfSSL 13:f67a6c6013ca 3474
wolfSSL 13:f67a6c6013ca 3475 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 3476 int SetSSL_CTX(WOLFSSL*, WOLFSSL_CTX*, int);
wolfSSL 13:f67a6c6013ca 3477 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 3478 int InitSSL(WOLFSSL*, WOLFSSL_CTX*, int);
wolfSSL 13:f67a6c6013ca 3479 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 3480 void FreeSSL(WOLFSSL*, void* heap);
wolfSSL 13:f67a6c6013ca 3481 WOLFSSL_API void SSL_ResourceFree(WOLFSSL*); /* Micrium uses */
wolfSSL 13:f67a6c6013ca 3482
wolfSSL 13:f67a6c6013ca 3483
wolfSSL 13:f67a6c6013ca 3484 enum {
wolfSSL 13:f67a6c6013ca 3485 IV_SZ = 32, /* max iv sz */
wolfSSL 13:f67a6c6013ca 3486 NAME_SZ = 80 /* max one line */
wolfSSL 13:f67a6c6013ca 3487 };
wolfSSL 13:f67a6c6013ca 3488
wolfSSL 13:f67a6c6013ca 3489
wolfSSL 13:f67a6c6013ca 3490 typedef struct EncryptedInfo {
wolfSSL 13:f67a6c6013ca 3491 char name[NAME_SZ]; /* encryption name */
wolfSSL 13:f67a6c6013ca 3492 byte iv[IV_SZ]; /* encrypted IV */
wolfSSL 13:f67a6c6013ca 3493 word32 ivSz; /* encrypted IV size */
wolfSSL 13:f67a6c6013ca 3494 long consumed; /* tracks PEM bytes consumed */
wolfSSL 13:f67a6c6013ca 3495 byte set; /* if encryption set */
wolfSSL 13:f67a6c6013ca 3496 WOLFSSL_CTX* ctx; /* CTX owner */
wolfSSL 13:f67a6c6013ca 3497 } EncryptedInfo;
wolfSSL 13:f67a6c6013ca 3498
wolfSSL 13:f67a6c6013ca 3499
wolfSSL 13:f67a6c6013ca 3500 #ifndef NO_CERTS
wolfSSL 13:f67a6c6013ca 3501
wolfSSL 13:f67a6c6013ca 3502 WOLFSSL_LOCAL int AllocDer(DerBuffer** der, word32 length, int type, void* heap);
wolfSSL 13:f67a6c6013ca 3503 WOLFSSL_LOCAL void FreeDer(DerBuffer** der);
wolfSSL 13:f67a6c6013ca 3504
wolfSSL 13:f67a6c6013ca 3505 WOLFSSL_LOCAL int PemToDer(const unsigned char* buff, long sz, int type,
wolfSSL 13:f67a6c6013ca 3506 DerBuffer** pDer, void* heap, EncryptedInfo* info,
wolfSSL 13:f67a6c6013ca 3507 int* eccKey);
wolfSSL 13:f67a6c6013ca 3508
wolfSSL 13:f67a6c6013ca 3509 WOLFSSL_LOCAL int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff,
wolfSSL 13:f67a6c6013ca 3510 long sz, int format, int type, WOLFSSL* ssl,
wolfSSL 13:f67a6c6013ca 3511 long* used, int userChain);
wolfSSL 13:f67a6c6013ca 3512 WOLFSSL_LOCAL int ProcessFile(WOLFSSL_CTX* ctx, const char* fname, int format,
wolfSSL 13:f67a6c6013ca 3513 int type, WOLFSSL* ssl, int userChain,
wolfSSL 13:f67a6c6013ca 3514 WOLFSSL_CRL* crl);
wolfSSL 13:f67a6c6013ca 3515
wolfSSL 13:f67a6c6013ca 3516 #ifdef OPENSSL_EXTRA
wolfSSL 13:f67a6c6013ca 3517 WOLFSSL_LOCAL int CheckHostName(DecodedCert* dCert, char *domainName,
wolfSSL 13:f67a6c6013ca 3518 size_t domainNameLen);
wolfSSL 13:f67a6c6013ca 3519 #endif
wolfSSL 13:f67a6c6013ca 3520 #endif
wolfSSL 13:f67a6c6013ca 3521
wolfSSL 13:f67a6c6013ca 3522
wolfSSL 13:f67a6c6013ca 3523 #ifdef WOLFSSL_CALLBACKS
wolfSSL 13:f67a6c6013ca 3524 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 3525 void InitHandShakeInfo(HandShakeInfo*, WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3526 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 3527 void FinishHandShakeInfo(HandShakeInfo*);
wolfSSL 13:f67a6c6013ca 3528 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 3529 void AddPacketName(const char*, HandShakeInfo*);
wolfSSL 13:f67a6c6013ca 3530
wolfSSL 13:f67a6c6013ca 3531 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 3532 void InitTimeoutInfo(TimeoutInfo*);
wolfSSL 13:f67a6c6013ca 3533 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 3534 void FreeTimeoutInfo(TimeoutInfo*, void*);
wolfSSL 13:f67a6c6013ca 3535 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 3536 void AddPacketInfo(const char*, TimeoutInfo*, const byte*, int, void*);
wolfSSL 13:f67a6c6013ca 3537 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 3538 void AddLateName(const char*, TimeoutInfo*);
wolfSSL 13:f67a6c6013ca 3539 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 3540 void AddLateRecordHeader(const RecordLayerHeader* rl, TimeoutInfo* info);
wolfSSL 13:f67a6c6013ca 3541 #endif
wolfSSL 13:f67a6c6013ca 3542
wolfSSL 13:f67a6c6013ca 3543
wolfSSL 13:f67a6c6013ca 3544 /* Record Layer Header identifier from page 12 */
wolfSSL 13:f67a6c6013ca 3545 enum ContentType {
wolfSSL 13:f67a6c6013ca 3546 no_type = 0,
wolfSSL 13:f67a6c6013ca 3547 change_cipher_spec = 20,
wolfSSL 13:f67a6c6013ca 3548 alert = 21,
wolfSSL 13:f67a6c6013ca 3549 handshake = 22,
wolfSSL 13:f67a6c6013ca 3550 application_data = 23
wolfSSL 13:f67a6c6013ca 3551 };
wolfSSL 13:f67a6c6013ca 3552
wolfSSL 13:f67a6c6013ca 3553
wolfSSL 13:f67a6c6013ca 3554 /* handshake header, same for each message type, pgs 20/21 */
wolfSSL 13:f67a6c6013ca 3555 typedef struct HandShakeHeader {
wolfSSL 13:f67a6c6013ca 3556 byte type;
wolfSSL 13:f67a6c6013ca 3557 word24 length;
wolfSSL 13:f67a6c6013ca 3558 } HandShakeHeader;
wolfSSL 13:f67a6c6013ca 3559
wolfSSL 13:f67a6c6013ca 3560
wolfSSL 13:f67a6c6013ca 3561 /* DTLS handshake header, same for each message type */
wolfSSL 13:f67a6c6013ca 3562 typedef struct DtlsHandShakeHeader {
wolfSSL 13:f67a6c6013ca 3563 byte type;
wolfSSL 13:f67a6c6013ca 3564 word24 length;
wolfSSL 13:f67a6c6013ca 3565 byte message_seq[2]; /* start at 0, retransmit gets same # */
wolfSSL 13:f67a6c6013ca 3566 word24 fragment_offset; /* bytes in previous fragments */
wolfSSL 13:f67a6c6013ca 3567 word24 fragment_length; /* length of this fragment */
wolfSSL 13:f67a6c6013ca 3568 } DtlsHandShakeHeader;
wolfSSL 13:f67a6c6013ca 3569
wolfSSL 13:f67a6c6013ca 3570
wolfSSL 13:f67a6c6013ca 3571 enum HandShakeType {
wolfSSL 13:f67a6c6013ca 3572 hello_request = 0,
wolfSSL 13:f67a6c6013ca 3573 client_hello = 1,
wolfSSL 13:f67a6c6013ca 3574 server_hello = 2,
wolfSSL 13:f67a6c6013ca 3575 hello_verify_request = 3, /* DTLS addition */
wolfSSL 13:f67a6c6013ca 3576 session_ticket = 4,
wolfSSL 13:f67a6c6013ca 3577 end_of_early_data = 5,
wolfSSL 13:f67a6c6013ca 3578 hello_retry_request = 6,
wolfSSL 13:f67a6c6013ca 3579 encrypted_extensions = 8,
wolfSSL 13:f67a6c6013ca 3580 certificate = 11,
wolfSSL 13:f67a6c6013ca 3581 server_key_exchange = 12,
wolfSSL 13:f67a6c6013ca 3582 certificate_request = 13,
wolfSSL 13:f67a6c6013ca 3583 server_hello_done = 14,
wolfSSL 13:f67a6c6013ca 3584 certificate_verify = 15,
wolfSSL 13:f67a6c6013ca 3585 client_key_exchange = 16,
wolfSSL 13:f67a6c6013ca 3586 finished = 20,
wolfSSL 13:f67a6c6013ca 3587 certificate_status = 22,
wolfSSL 13:f67a6c6013ca 3588 key_update = 24,
wolfSSL 13:f67a6c6013ca 3589 change_cipher_hs = 55, /* simulate unique handshake type for sanity
wolfSSL 13:f67a6c6013ca 3590 checks. record layer change_cipher
wolfSSL 13:f67a6c6013ca 3591 conflicts with handshake finished */
wolfSSL 13:f67a6c6013ca 3592 message_hash = 254, /* synthetic message type for TLS v1.3 */
wolfSSL 13:f67a6c6013ca 3593 no_shake = 255 /* used to initialize the DtlsMsg record */
wolfSSL 13:f67a6c6013ca 3594 };
wolfSSL 13:f67a6c6013ca 3595
wolfSSL 13:f67a6c6013ca 3596 enum ProvisionSide {
wolfSSL 13:f67a6c6013ca 3597 PROVISION_CLIENT = 1,
wolfSSL 13:f67a6c6013ca 3598 PROVISION_SERVER = 2,
wolfSSL 13:f67a6c6013ca 3599 PROVISION_CLIENT_SERVER = 3
wolfSSL 13:f67a6c6013ca 3600 };
wolfSSL 13:f67a6c6013ca 3601
wolfSSL 13:f67a6c6013ca 3602
wolfSSL 13:f67a6c6013ca 3603 static const byte client[SIZEOF_SENDER] = { 0x43, 0x4C, 0x4E, 0x54 };
wolfSSL 13:f67a6c6013ca 3604 static const byte server[SIZEOF_SENDER] = { 0x53, 0x52, 0x56, 0x52 };
wolfSSL 13:f67a6c6013ca 3605
wolfSSL 13:f67a6c6013ca 3606 static const byte tls_client[FINISHED_LABEL_SZ + 1] = "client finished";
wolfSSL 13:f67a6c6013ca 3607 static const byte tls_server[FINISHED_LABEL_SZ + 1] = "server finished";
wolfSSL 13:f67a6c6013ca 3608
wolfSSL 13:f67a6c6013ca 3609
wolfSSL 13:f67a6c6013ca 3610 /* internal functions */
wolfSSL 13:f67a6c6013ca 3611 WOLFSSL_LOCAL int SendChangeCipher(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3612 WOLFSSL_LOCAL int SendTicket(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3613 WOLFSSL_LOCAL int DoClientTicket(WOLFSSL*, const byte*, word32);
wolfSSL 13:f67a6c6013ca 3614 WOLFSSL_LOCAL int SendData(WOLFSSL*, const void*, int);
wolfSSL 13:f67a6c6013ca 3615 #ifdef WOLFSSL_TLS13
wolfSSL 13:f67a6c6013ca 3616 WOLFSSL_LOCAL int SendTls13HelloRetryRequest(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3617 #endif
wolfSSL 13:f67a6c6013ca 3618 WOLFSSL_LOCAL int SendCertificate(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3619 WOLFSSL_LOCAL int SendCertificateRequest(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3620 WOLFSSL_LOCAL int SendCertificateStatus(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3621 WOLFSSL_LOCAL int SendServerKeyExchange(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3622 WOLFSSL_LOCAL int SendBuffered(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3623 WOLFSSL_LOCAL int ReceiveData(WOLFSSL*, byte*, int, int);
wolfSSL 13:f67a6c6013ca 3624 WOLFSSL_LOCAL int SendFinished(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3625 WOLFSSL_LOCAL int SendAlert(WOLFSSL*, int, int);
wolfSSL 13:f67a6c6013ca 3626 WOLFSSL_LOCAL int ProcessReply(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3627
wolfSSL 13:f67a6c6013ca 3628 WOLFSSL_LOCAL int SetCipherSpecs(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3629 WOLFSSL_LOCAL int MakeMasterSecret(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3630
wolfSSL 13:f67a6c6013ca 3631 WOLFSSL_LOCAL int AddSession(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3632 WOLFSSL_LOCAL int DeriveKeys(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 3633 WOLFSSL_LOCAL int StoreKeys(WOLFSSL* ssl, const byte* keyData, int side);
wolfSSL 13:f67a6c6013ca 3634
wolfSSL 13:f67a6c6013ca 3635 WOLFSSL_LOCAL int IsTLS(const WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 3636 WOLFSSL_LOCAL int IsAtLeastTLSv1_2(const WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 3637 WOLFSSL_LOCAL int IsAtLeastTLSv1_3(const ProtocolVersion pv);
wolfSSL 13:f67a6c6013ca 3638
wolfSSL 13:f67a6c6013ca 3639 WOLFSSL_LOCAL void FreeHandshakeResources(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 3640 WOLFSSL_LOCAL void ShrinkInputBuffer(WOLFSSL* ssl, int forcedFree);
wolfSSL 13:f67a6c6013ca 3641 WOLFSSL_LOCAL void ShrinkOutputBuffer(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 3642
wolfSSL 13:f67a6c6013ca 3643 WOLFSSL_LOCAL int VerifyClientSuite(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 3644
wolfSSL 13:f67a6c6013ca 3645 WOLFSSL_LOCAL int SetTicket(WOLFSSL*, const byte*, word32);
wolfSSL 13:f67a6c6013ca 3646
wolfSSL 13:f67a6c6013ca 3647 #ifndef NO_CERTS
wolfSSL 13:f67a6c6013ca 3648 #ifndef NO_RSA
wolfSSL 13:f67a6c6013ca 3649 #ifdef WC_RSA_PSS
wolfSSL 13:f67a6c6013ca 3650 WOLFSSL_LOCAL int CheckRsaPssPadding(const byte* plain, word32 plainSz,
wolfSSL 13:f67a6c6013ca 3651 byte* out, word32 sigSz,
wolfSSL 13:f67a6c6013ca 3652 enum wc_HashType hashType);
wolfSSL 13:f67a6c6013ca 3653 WOLFSSL_LOCAL int ConvertHashPss(int hashAlgo, enum wc_HashType* hashType, int* mgf);
wolfSSL 13:f67a6c6013ca 3654 #endif
wolfSSL 13:f67a6c6013ca 3655 WOLFSSL_LOCAL int VerifyRsaSign(WOLFSSL* ssl,
wolfSSL 13:f67a6c6013ca 3656 byte* verifySig, word32 sigSz,
wolfSSL 13:f67a6c6013ca 3657 const byte* plain, word32 plainSz,
wolfSSL 13:f67a6c6013ca 3658 int sigAlgo, int hashAlgo,
wolfSSL 13:f67a6c6013ca 3659 RsaKey* key);
wolfSSL 13:f67a6c6013ca 3660 WOLFSSL_LOCAL int RsaSign(WOLFSSL* ssl, const byte* in, word32 inSz,
wolfSSL 13:f67a6c6013ca 3661 byte* out, word32* outSz, int sigAlgo, int hashAlgo, RsaKey* key,
wolfSSL 13:f67a6c6013ca 3662 const byte* keyBuf, word32 keySz, void* ctx);
wolfSSL 13:f67a6c6013ca 3663 WOLFSSL_LOCAL int RsaVerify(WOLFSSL* ssl, byte* in, word32 inSz,
wolfSSL 13:f67a6c6013ca 3664 byte** out, int sigAlgo, int hashAlgo, RsaKey* key,
wolfSSL 13:f67a6c6013ca 3665 const byte* keyBuf, word32 keySz, void* ctx);
wolfSSL 13:f67a6c6013ca 3666 WOLFSSL_LOCAL int RsaDec(WOLFSSL* ssl, byte* in, word32 inSz, byte** out,
wolfSSL 13:f67a6c6013ca 3667 word32* outSz, RsaKey* key, const byte* keyBuf, word32 keySz, void* ctx);
wolfSSL 13:f67a6c6013ca 3668 WOLFSSL_LOCAL int RsaEnc(WOLFSSL* ssl, const byte* in, word32 inSz, byte* out,
wolfSSL 13:f67a6c6013ca 3669 word32* outSz, RsaKey* key, const byte* keyBuf, word32 keySz, void* ctx);
wolfSSL 13:f67a6c6013ca 3670 #endif /* !NO_RSA */
wolfSSL 13:f67a6c6013ca 3671
wolfSSL 13:f67a6c6013ca 3672 #ifdef HAVE_ECC
wolfSSL 13:f67a6c6013ca 3673 WOLFSSL_LOCAL int EccSign(WOLFSSL* ssl, const byte* in, word32 inSz,
wolfSSL 13:f67a6c6013ca 3674 byte* out, word32* outSz, ecc_key* key, byte* keyBuf, word32 keySz,
wolfSSL 13:f67a6c6013ca 3675 void* ctx);
wolfSSL 13:f67a6c6013ca 3676 WOLFSSL_LOCAL int EccVerify(WOLFSSL* ssl, const byte* in, word32 inSz,
wolfSSL 13:f67a6c6013ca 3677 const byte* out, word32 outSz, ecc_key* key, byte* keyBuf, word32 keySz,
wolfSSL 13:f67a6c6013ca 3678 void* ctx);
wolfSSL 13:f67a6c6013ca 3679 WOLFSSL_LOCAL int EccSharedSecret(WOLFSSL* ssl, ecc_key* priv_key,
wolfSSL 13:f67a6c6013ca 3680 ecc_key* pub_key, byte* pubKeyDer, word32* pubKeySz, byte* out,
wolfSSL 13:f67a6c6013ca 3681 word32* outlen, int side, void* ctx);
wolfSSL 13:f67a6c6013ca 3682 #endif /* HAVE_ECC */
wolfSSL 13:f67a6c6013ca 3683 #ifdef HAVE_ED25519
wolfSSL 13:f67a6c6013ca 3684 WOLFSSL_LOCAL int Ed25519Sign(WOLFSSL* ssl, const byte* in, word32 inSz,
wolfSSL 13:f67a6c6013ca 3685 byte* out, word32* outSz, ed25519_key* key, byte* keyBuf,
wolfSSL 13:f67a6c6013ca 3686 word32 keySz, void* ctx);
wolfSSL 13:f67a6c6013ca 3687 WOLFSSL_LOCAL int Ed25519Verify(WOLFSSL* ssl, const byte* in,
wolfSSL 13:f67a6c6013ca 3688 word32 inSz, const byte* msg, word32 msgSz, ed25519_key* key,
wolfSSL 13:f67a6c6013ca 3689 byte* keyBuf, word32 keySz, void* ctx);
wolfSSL 13:f67a6c6013ca 3690 #endif /* HAVE_ED25519 */
wolfSSL 13:f67a6c6013ca 3691
wolfSSL 13:f67a6c6013ca 3692
wolfSSL 13:f67a6c6013ca 3693 #ifdef WOLFSSL_TRUST_PEER_CERT
wolfSSL 13:f67a6c6013ca 3694
wolfSSL 13:f67a6c6013ca 3695 /* options for searching hash table for a matching trusted peer cert */
wolfSSL 13:f67a6c6013ca 3696 #define WC_MATCH_SKID 0
wolfSSL 13:f67a6c6013ca 3697 #define WC_MATCH_NAME 1
wolfSSL 13:f67a6c6013ca 3698
wolfSSL 13:f67a6c6013ca 3699 WOLFSSL_LOCAL TrustedPeerCert* GetTrustedPeer(void* vp, byte* hash,
wolfSSL 13:f67a6c6013ca 3700 int type);
wolfSSL 13:f67a6c6013ca 3701 WOLFSSL_LOCAL int MatchTrustedPeer(TrustedPeerCert* tp,
wolfSSL 13:f67a6c6013ca 3702 DecodedCert* cert);
wolfSSL 13:f67a6c6013ca 3703 #endif
wolfSSL 13:f67a6c6013ca 3704
wolfSSL 13:f67a6c6013ca 3705 WOLFSSL_LOCAL Signer* GetCA(void* cm, byte* hash);
wolfSSL 13:f67a6c6013ca 3706 #ifndef NO_SKID
wolfSSL 13:f67a6c6013ca 3707 WOLFSSL_LOCAL Signer* GetCAByName(void* cm, byte* hash);
wolfSSL 13:f67a6c6013ca 3708 #endif
wolfSSL 13:f67a6c6013ca 3709 #endif /* !NO_CERTS */
wolfSSL 13:f67a6c6013ca 3710 WOLFSSL_LOCAL int BuildTlsHandshakeHash(WOLFSSL* ssl, byte* hash,
wolfSSL 13:f67a6c6013ca 3711 word32* hashLen);
wolfSSL 13:f67a6c6013ca 3712 WOLFSSL_LOCAL int BuildTlsFinished(WOLFSSL* ssl, Hashes* hashes,
wolfSSL 13:f67a6c6013ca 3713 const byte* sender);
wolfSSL 13:f67a6c6013ca 3714 WOLFSSL_LOCAL void FreeArrays(WOLFSSL* ssl, int keep);
wolfSSL 13:f67a6c6013ca 3715 WOLFSSL_LOCAL int CheckAvailableSize(WOLFSSL *ssl, int size);
wolfSSL 13:f67a6c6013ca 3716 WOLFSSL_LOCAL int GrowInputBuffer(WOLFSSL* ssl, int size, int usedLength);
wolfSSL 13:f67a6c6013ca 3717
wolfSSL 13:f67a6c6013ca 3718 #ifndef NO_TLS
wolfSSL 13:f67a6c6013ca 3719 WOLFSSL_LOCAL int MakeTlsMasterSecret(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3720 WOLFSSL_LOCAL int TLS_hmac(WOLFSSL* ssl, byte* digest, const byte* in,
wolfSSL 13:f67a6c6013ca 3721 word32 sz, int content, int verify);
wolfSSL 13:f67a6c6013ca 3722 #endif
wolfSSL 13:f67a6c6013ca 3723
wolfSSL 13:f67a6c6013ca 3724 #ifndef NO_WOLFSSL_CLIENT
wolfSSL 13:f67a6c6013ca 3725 WOLFSSL_LOCAL int SendClientHello(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3726 #ifdef WOLFSSL_TLS13
wolfSSL 13:f67a6c6013ca 3727 WOLFSSL_LOCAL int SendTls13ClientHello(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3728 #endif
wolfSSL 13:f67a6c6013ca 3729 WOLFSSL_LOCAL int SendClientKeyExchange(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3730 WOLFSSL_LOCAL int SendCertificateVerify(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3731 #endif /* NO_WOLFSSL_CLIENT */
wolfSSL 13:f67a6c6013ca 3732
wolfSSL 13:f67a6c6013ca 3733 #ifndef NO_WOLFSSL_SERVER
wolfSSL 13:f67a6c6013ca 3734 WOLFSSL_LOCAL int SendServerHello(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3735 WOLFSSL_LOCAL int SendServerHelloDone(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3736 #endif /* NO_WOLFSSL_SERVER */
wolfSSL 13:f67a6c6013ca 3737
wolfSSL 13:f67a6c6013ca 3738 #ifdef WOLFSSL_DTLS
wolfSSL 13:f67a6c6013ca 3739 WOLFSSL_LOCAL DtlsMsg* DtlsMsgNew(word32, void*);
wolfSSL 13:f67a6c6013ca 3740 WOLFSSL_LOCAL void DtlsMsgDelete(DtlsMsg*, void*);
wolfSSL 13:f67a6c6013ca 3741 WOLFSSL_LOCAL void DtlsMsgListDelete(DtlsMsg*, void*);
wolfSSL 13:f67a6c6013ca 3742 WOLFSSL_LOCAL int DtlsMsgSet(DtlsMsg*, word32, const byte*, byte,
wolfSSL 13:f67a6c6013ca 3743 word32, word32, void*);
wolfSSL 13:f67a6c6013ca 3744 WOLFSSL_LOCAL DtlsMsg* DtlsMsgFind(DtlsMsg*, word32);
wolfSSL 13:f67a6c6013ca 3745 WOLFSSL_LOCAL void DtlsMsgStore(WOLFSSL*, word32, const byte*, word32,
wolfSSL 13:f67a6c6013ca 3746 byte, word32, word32, void*);
wolfSSL 13:f67a6c6013ca 3747 WOLFSSL_LOCAL DtlsMsg* DtlsMsgInsert(DtlsMsg*, DtlsMsg*);
wolfSSL 13:f67a6c6013ca 3748
wolfSSL 13:f67a6c6013ca 3749 WOLFSSL_LOCAL int DtlsMsgPoolSave(WOLFSSL*, const byte*, word32);
wolfSSL 13:f67a6c6013ca 3750 WOLFSSL_LOCAL int DtlsMsgPoolTimeout(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3751 WOLFSSL_LOCAL int VerifyForDtlsMsgPoolSend(WOLFSSL*, byte, word32);
wolfSSL 13:f67a6c6013ca 3752 WOLFSSL_LOCAL void DtlsMsgPoolReset(WOLFSSL*);
wolfSSL 13:f67a6c6013ca 3753 WOLFSSL_LOCAL int DtlsMsgPoolSend(WOLFSSL*, int);
wolfSSL 13:f67a6c6013ca 3754 #endif /* WOLFSSL_DTLS */
wolfSSL 13:f67a6c6013ca 3755
wolfSSL 13:f67a6c6013ca 3756 #ifndef NO_TLS
wolfSSL 13:f67a6c6013ca 3757
wolfSSL 13:f67a6c6013ca 3758
wolfSSL 13:f67a6c6013ca 3759 #endif /* NO_TLS */
wolfSSL 13:f67a6c6013ca 3760
wolfSSL 13:f67a6c6013ca 3761 #if defined(WOLFSSL_TLS13) && (defined(HAVE_SESSION_TICKET) || !defined(NO_PSK))
wolfSSL 13:f67a6c6013ca 3762 WOLFSSL_LOCAL word32 TimeNowInMilliseconds(void);
wolfSSL 13:f67a6c6013ca 3763 #endif
wolfSSL 13:f67a6c6013ca 3764 WOLFSSL_LOCAL word32 LowResTimer(void);
wolfSSL 13:f67a6c6013ca 3765
wolfSSL 13:f67a6c6013ca 3766 #ifndef NO_CERTS
wolfSSL 13:f67a6c6013ca 3767 WOLFSSL_LOCAL void InitX509Name(WOLFSSL_X509_NAME*, int);
wolfSSL 13:f67a6c6013ca 3768 WOLFSSL_LOCAL void FreeX509Name(WOLFSSL_X509_NAME* name, void* heap);
wolfSSL 13:f67a6c6013ca 3769 WOLFSSL_LOCAL void InitX509(WOLFSSL_X509*, int, void* heap);
wolfSSL 13:f67a6c6013ca 3770 WOLFSSL_LOCAL void FreeX509(WOLFSSL_X509*);
wolfSSL 13:f67a6c6013ca 3771 WOLFSSL_LOCAL int CopyDecodedToX509(WOLFSSL_X509*, DecodedCert*);
wolfSSL 13:f67a6c6013ca 3772 #endif
wolfSSL 13:f67a6c6013ca 3773
wolfSSL 13:f67a6c6013ca 3774 /* used by ssl.c and internal.c */
wolfSSL 13:f67a6c6013ca 3775 WOLFSSL_LOCAL void c32to24(word32 in, word24 out);
wolfSSL 13:f67a6c6013ca 3776
wolfSSL 13:f67a6c6013ca 3777 WOLFSSL_LOCAL const char* const* GetCipherNames(void);
wolfSSL 13:f67a6c6013ca 3778 WOLFSSL_LOCAL int GetCipherNamesSize(void);
wolfSSL 13:f67a6c6013ca 3779 WOLFSSL_LOCAL const char* GetCipherNameInternal(const char* cipherName, int cipherSuite);
wolfSSL 13:f67a6c6013ca 3780 WOLFSSL_LOCAL const char* wolfSSL_get_cipher_name_internal(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 3781 WOLFSSL_LOCAL const char* wolfSSL_get_cipher_name_from_suite(
wolfSSL 13:f67a6c6013ca 3782 const unsigned char cipherSuite, const unsigned char cipherSuite0);
wolfSSL 13:f67a6c6013ca 3783
wolfSSL 13:f67a6c6013ca 3784 enum encrypt_side {
wolfSSL 13:f67a6c6013ca 3785 ENCRYPT_SIDE_ONLY = 1,
wolfSSL 13:f67a6c6013ca 3786 DECRYPT_SIDE_ONLY,
wolfSSL 13:f67a6c6013ca 3787 ENCRYPT_AND_DECRYPT_SIDE
wolfSSL 13:f67a6c6013ca 3788 };
wolfSSL 13:f67a6c6013ca 3789
wolfSSL 13:f67a6c6013ca 3790 WOLFSSL_LOCAL int SetKeysSide(WOLFSSL*, enum encrypt_side);
wolfSSL 13:f67a6c6013ca 3791
wolfSSL 13:f67a6c6013ca 3792
wolfSSL 13:f67a6c6013ca 3793 #ifndef NO_DH
wolfSSL 13:f67a6c6013ca 3794 WOLFSSL_LOCAL int DhGenKeyPair(WOLFSSL* ssl, DhKey* dhKey,
wolfSSL 13:f67a6c6013ca 3795 byte* priv, word32* privSz,
wolfSSL 13:f67a6c6013ca 3796 byte* pub, word32* pubSz);
wolfSSL 13:f67a6c6013ca 3797 WOLFSSL_LOCAL int DhAgree(WOLFSSL* ssl, DhKey* dhKey,
wolfSSL 13:f67a6c6013ca 3798 const byte* priv, word32 privSz,
wolfSSL 13:f67a6c6013ca 3799 const byte* otherPub, word32 otherPubSz,
wolfSSL 13:f67a6c6013ca 3800 byte* agree, word32* agreeSz);
wolfSSL 13:f67a6c6013ca 3801 #endif /* !NO_DH */
wolfSSL 13:f67a6c6013ca 3802
wolfSSL 13:f67a6c6013ca 3803 #ifdef HAVE_ECC
wolfSSL 13:f67a6c6013ca 3804 WOLFSSL_LOCAL int EccMakeKey(WOLFSSL* ssl, ecc_key* key, ecc_key* peer);
wolfSSL 13:f67a6c6013ca 3805 #endif
wolfSSL 13:f67a6c6013ca 3806
wolfSSL 13:f67a6c6013ca 3807 WOLFSSL_LOCAL int InitHandshakeHashes(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 3808 WOLFSSL_LOCAL void FreeHandshakeHashes(WOLFSSL* ssl);
wolfSSL 13:f67a6c6013ca 3809
wolfSSL 13:f67a6c6013ca 3810 WOLFSSL_LOCAL int BuildMessage(WOLFSSL* ssl, byte* output, int outSz,
wolfSSL 13:f67a6c6013ca 3811 const byte* input, int inSz, int type, int hashOutput,
wolfSSL 13:f67a6c6013ca 3812 int sizeOnly, int asyncOkay);
wolfSSL 13:f67a6c6013ca 3813
wolfSSL 13:f67a6c6013ca 3814 #ifdef WOLFSSL_TLS13
wolfSSL 13:f67a6c6013ca 3815 int BuildTls13Message(WOLFSSL* ssl, byte* output, int outSz, const byte* input,
wolfSSL 13:f67a6c6013ca 3816 int inSz, int type, int hashOutput, int sizeOnly, int asyncOkay);
wolfSSL 13:f67a6c6013ca 3817 #endif
wolfSSL 13:f67a6c6013ca 3818
wolfSSL 13:f67a6c6013ca 3819 WOLFSSL_LOCAL int AllocKey(WOLFSSL* ssl, int type, void** pKey);
wolfSSL 13:f67a6c6013ca 3820 WOLFSSL_LOCAL void FreeKey(WOLFSSL* ssl, int type, void** pKey);
wolfSSL 13:f67a6c6013ca 3821
wolfSSL 13:f67a6c6013ca 3822 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 13:f67a6c6013ca 3823 WOLFSSL_LOCAL int wolfSSL_AsyncPop(WOLFSSL* ssl, byte* state);
wolfSSL 13:f67a6c6013ca 3824 WOLFSSL_LOCAL int wolfSSL_AsyncPush(WOLFSSL* ssl, WC_ASYNC_DEV* asyncDev,
wolfSSL 13:f67a6c6013ca 3825 word32 flags);
wolfSSL 13:f67a6c6013ca 3826 #endif
wolfSSL 13:f67a6c6013ca 3827
wolfSSL 13:f67a6c6013ca 3828
wolfSSL 13:f67a6c6013ca 3829 #ifdef __cplusplus
wolfSSL 13:f67a6c6013ca 3830 } /* extern "C" */
wolfSSL 13:f67a6c6013ca 3831 #endif
wolfSSL 13:f67a6c6013ca 3832
wolfSSL 13:f67a6c6013ca 3833 #endif /* wolfSSL_INT_H */
wolfSSL 13:f67a6c6013ca 3834