/src/wolfssl-openssl-api/src/keys.c
Line | Count | Source |
1 | | /* keys.c |
2 | | * |
3 | | * Copyright (C) 2006-2026 wolfSSL Inc. |
4 | | * |
5 | | * This file is part of wolfSSL. |
6 | | * |
7 | | * wolfSSL is free software; you can redistribute it and/or modify |
8 | | * it under the terms of the GNU General Public License as published by |
9 | | * the Free Software Foundation; either version 3 of the License, or |
10 | | * (at your option) any later version. |
11 | | * |
12 | | * wolfSSL is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | * GNU General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU General Public License |
18 | | * along with this program; if not, write to the Free Software |
19 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
20 | | */ |
21 | | |
22 | | |
23 | | /* Name change compatibility layer no longer needs to be included here */ |
24 | | |
25 | | #include <wolfssl/wolfcrypt/libwolfssl_sources.h> |
26 | | |
27 | | #if !defined(WOLFCRYPT_ONLY) && !defined(NO_TLS) |
28 | | |
29 | | #include <wolfssl/internal.h> |
30 | | #include <wolfssl/error-ssl.h> |
31 | | #if defined(SHOW_SECRETS) || defined(CHACHA_AEAD_TEST) |
32 | | #ifndef NO_STDIO_FILESYSTEM |
33 | | #include <stdio.h> |
34 | | #endif |
35 | | #endif |
36 | | #ifdef NO_INLINE |
37 | | #include <wolfssl/wolfcrypt/misc.h> |
38 | | #else |
39 | | #define WOLFSSL_MISC_INCLUDED |
40 | | #include <wolfcrypt/src/misc.c> |
41 | | #endif |
42 | | |
43 | | #if defined(WOLFSSL_RENESAS_FSPSM_TLS) || defined(WOLFSSL_RENESAS_TSIP_TLS) |
44 | | #include <wolfssl/wolfcrypt/port/Renesas/renesas_cmn.h> |
45 | | #endif |
46 | | |
47 | | int SetCipherSpecs(WOLFSSL* ssl) |
48 | 0 | { |
49 | 0 | int ret; |
50 | | |
51 | | /* GetCipherSpec only sets these, for the suite being set. */ |
52 | 0 | ssl->options.usingPSK_cipher = 0; |
53 | 0 | ssl->options.usingAnon_cipher = 0; |
54 | 0 | ret = GetCipherSpec(ssl->options.side, ssl->options.cipherSuite0, |
55 | 0 | ssl->options.cipherSuite, &ssl->specs, &ssl->options); |
56 | 0 | if (ret == 0) { |
57 | 0 | #ifdef WOLFSSL_TLS13 |
58 | | /* The client only checks that the ServerHello suite was offered, and |
59 | | * the TLS 1.2 key block of TLS_SHA384_SHA384 exceeds MAX_PRF_DIG. */ |
60 | 0 | if (ssl->specs.kea == any_kea && !IsAtLeastTLSv1_3(ssl->version)) { |
61 | 0 | WOLFSSL_MSG("TLS 1.3 cipher suite not valid for lower version"); |
62 | 0 | WOLFSSL_ERROR_VERBOSE(UNSUPPORTED_SUITE); |
63 | | /* GetCipherSpec already wrote the rejected suite's sizes. */ |
64 | 0 | XMEMSET(&ssl->specs, 0, sizeof(ssl->specs)); |
65 | 0 | return UNSUPPORTED_SUITE; |
66 | 0 | } |
67 | 0 | #endif /* WOLFSSL_TLS13 */ |
68 | | |
69 | | #ifdef WOLFSSL_ALLOW_SSLV3 |
70 | | /* SSLv3 (RFC 6101) defines MAC algorithms as MD5 and SHA-1. SHA-256 |
71 | | * was introduced in TLS 1.2 (RFC 5246). SSL_hmac for old SSLv3 |
72 | | * connections can not handle newer cipher suites that use digest sizes |
73 | | * larger than SHA-1 */ |
74 | | if (ssl->version.major == SSLv3_MAJOR && |
75 | | ssl->version.minor == SSLv3_MINOR && |
76 | | ssl->specs.hash_size > WC_SHA_DIGEST_SIZE) { |
77 | | WOLFSSL_MSG("SSLv3 does not support SHA-256 or higher MAC"); |
78 | | WOLFSSL_ERROR_VERBOSE(UNSUPPORTED_SUITE); |
79 | | return UNSUPPORTED_SUITE; |
80 | | } |
81 | | #endif /* WOLFSSL_ALLOW_SSLV3 */ |
82 | | |
83 | | /* set TLS if it hasn't been turned off */ |
84 | 0 | if (ssl->version.major == SSLv3_MAJOR && |
85 | 0 | ssl->version.minor >= TLSv1_MINOR) { |
86 | 0 | #ifndef NO_TLS |
87 | 0 | ssl->options.tls = 1; |
88 | 0 | #if !defined(WOLFSSL_NO_TLS12) && !defined(WOLFSSL_AEAD_ONLY) |
89 | 0 | #if !defined(WOLFSSL_RENESAS_FSPSM_TLS) && \ |
90 | 0 | !defined(WOLFSSL_RENESAS_TSIP_TLS) |
91 | 0 | ssl->hmac = TLS_hmac; |
92 | | #else |
93 | | ssl->hmac = Renesas_cmn_TLS_hmac; |
94 | | #endif |
95 | 0 | #endif |
96 | 0 | if (ssl->version.minor >= TLSv1_1_MINOR) { |
97 | 0 | ssl->options.tls1_1 = 1; |
98 | 0 | if (ssl->version.minor >= TLSv1_3_MINOR) |
99 | 0 | ssl->options.tls1_3 = 1; |
100 | 0 | } |
101 | 0 | #endif |
102 | 0 | } |
103 | |
|
104 | 0 | #if defined(HAVE_ENCRYPT_THEN_MAC) && !defined(WOLFSSL_AEAD_ONLY) |
105 | 0 | if (IsAtLeastTLSv1_3(ssl->version) || ssl->specs.cipher_type != block) |
106 | 0 | ssl->options.encThenMac = 0; |
107 | 0 | #endif |
108 | |
|
109 | | #ifdef HAVE_LIBZ |
110 | | /* TLS 1.3 removed record layer compression (RFC 8446 5.2). A client |
111 | | * that asked for it may still land on 1.3, so drop the request rather |
112 | | * than compress records the peer will not decompress. */ |
113 | | if (IsAtLeastTLSv1_3(ssl->version)) |
114 | | ssl->options.usingCompression = 0; |
115 | | #endif |
116 | |
|
117 | | #if defined(WOLFSSL_DTLS) |
118 | | if (ssl->options.dtls && ssl->version.major == DTLS_MAJOR) { |
119 | | #ifndef WOLFSSL_AEAD_ONLY |
120 | | #if !defined(WOLFSSL_RENESAS_FSPSM_TLS) && \ |
121 | | !defined(WOLFSSL_RENESAS_TSIP_TLS) |
122 | | ssl->hmac = TLS_hmac; |
123 | | #else |
124 | | ssl->hmac = Renesas_cmn_TLS_hmac; |
125 | | #endif |
126 | | #endif |
127 | | ssl->options.tls = 1; |
128 | | ssl->options.tls1_1 = 1; /* DTLS 1.0 == TLS 1.1 */ |
129 | | #ifdef WOLFSSL_DTLS13 |
130 | | if (ssl->version.minor <= DTLSv1_3_MINOR) |
131 | | ssl->options.tls1_3 = 1; |
132 | | #endif |
133 | | } |
134 | | #endif |
135 | 0 | } |
136 | 0 | return ret; |
137 | 0 | } |
138 | | |
139 | | /** |
140 | | * Populate specs with the specification of the chosen ciphersuite. If opts is |
141 | | * not NULL then the appropriate options will also be set. |
142 | | * |
143 | | * @param side [in] WOLFSSL_SERVER_END or WOLFSSL_CLIENT_END |
144 | | * @param cipherSuite0 [in] |
145 | | * @param cipherSuite [in] |
146 | | * @param specs [out] CipherSpecs |
147 | | * @param opts [in/out] Options can be NULL |
148 | | * @return int (less than 0 on fail, 0 on success) |
149 | | */ |
150 | | int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, |
151 | | CipherSpecs* specs, Options* opts) |
152 | 0 | { |
153 | 0 | word16 havePSK = 0; |
154 | 0 | (void)havePSK; |
155 | 0 | (void)side; |
156 | 0 | #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK) |
157 | 0 | if (opts != NULL) |
158 | 0 | havePSK = opts->havePSK; |
159 | 0 | #endif |
160 | 0 | #ifndef NO_WOLFSSL_CLIENT |
161 | 0 | if (side == WOLFSSL_CLIENT_END) { |
162 | | /* server side verified before SetCipherSpecs call */ |
163 | 0 | if (VerifyClientSuite(havePSK, cipherSuite0, cipherSuite) != 1) { |
164 | 0 | WOLFSSL_MSG("SetCipherSpecs() client has an unusable suite"); |
165 | 0 | WOLFSSL_ERROR_VERBOSE(UNSUPPORTED_SUITE); |
166 | 0 | return UNSUPPORTED_SUITE; |
167 | 0 | } |
168 | 0 | } |
169 | 0 | #endif /* NO_WOLFSSL_CLIENT */ |
170 | | |
171 | | /* Initialize specs */ |
172 | 0 | XMEMSET(specs, 0, sizeof(CipherSpecs)); |
173 | | |
174 | | /* Chacha extensions, 0xcc */ |
175 | 0 | if (cipherSuite0 == CHACHA_BYTE) { |
176 | |
|
177 | 0 | switch (cipherSuite) { |
178 | 0 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 |
179 | 0 | case TLS_ECDHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256: |
180 | 0 | specs->bulk_cipher_algorithm = wolfssl_chacha; |
181 | 0 | specs->cipher_type = aead; |
182 | 0 | specs->mac_algorithm = sha256_mac; |
183 | 0 | specs->kea = ecc_diffie_hellman_kea; |
184 | 0 | specs->sig_algo = rsa_sa_algo; |
185 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
186 | 0 | specs->pad_size = PAD_SHA; |
187 | 0 | specs->static_ecdh = 0; |
188 | 0 | specs->key_size = CHACHA20_256_KEY_SIZE; |
189 | 0 | specs->block_size = CHACHA20_BLOCK_SIZE; |
190 | 0 | specs->iv_size = CHACHA20_IV_SIZE; |
191 | 0 | specs->aead_mac_size = POLY1305_AUTH_SZ; |
192 | 0 | if (opts != NULL) |
193 | 0 | opts->oldPoly = 1; /* use old poly1305 padding */ |
194 | |
|
195 | 0 | break; |
196 | 0 | #endif |
197 | | |
198 | 0 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_OLD_POLY1305_SHA256 |
199 | 0 | case TLS_ECDHE_ECDSA_WITH_CHACHA20_OLD_POLY1305_SHA256: |
200 | 0 | specs->bulk_cipher_algorithm = wolfssl_chacha; |
201 | 0 | specs->cipher_type = aead; |
202 | 0 | specs->mac_algorithm = sha256_mac; |
203 | 0 | specs->kea = ecc_diffie_hellman_kea; |
204 | 0 | specs->sig_algo = ecc_dsa_sa_algo; |
205 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
206 | 0 | specs->pad_size = PAD_SHA; |
207 | 0 | specs->static_ecdh = 0; |
208 | 0 | specs->key_size = CHACHA20_256_KEY_SIZE; |
209 | 0 | specs->block_size = CHACHA20_BLOCK_SIZE; |
210 | 0 | specs->iv_size = CHACHA20_IV_SIZE; |
211 | 0 | specs->aead_mac_size = POLY1305_AUTH_SZ; |
212 | 0 | if (opts != NULL) |
213 | 0 | opts->oldPoly = 1; /* use old poly1305 padding */ |
214 | |
|
215 | 0 | break; |
216 | 0 | #endif |
217 | | |
218 | 0 | #ifdef BUILD_TLS_DHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 |
219 | 0 | case TLS_DHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256: |
220 | 0 | specs->bulk_cipher_algorithm = wolfssl_chacha; |
221 | 0 | specs->cipher_type = aead; |
222 | 0 | specs->mac_algorithm = sha256_mac; |
223 | 0 | specs->kea = diffie_hellman_kea; |
224 | 0 | specs->sig_algo = rsa_sa_algo; |
225 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
226 | 0 | specs->pad_size = PAD_SHA; |
227 | 0 | specs->static_ecdh = 0; |
228 | 0 | specs->key_size = CHACHA20_256_KEY_SIZE; |
229 | 0 | specs->block_size = CHACHA20_BLOCK_SIZE; |
230 | 0 | specs->iv_size = CHACHA20_IV_SIZE; |
231 | 0 | specs->aead_mac_size = POLY1305_AUTH_SZ; |
232 | 0 | if (opts != NULL) |
233 | 0 | opts->oldPoly = 1; /* use old poly1305 padding */ |
234 | |
|
235 | 0 | break; |
236 | 0 | #endif |
237 | 0 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 |
238 | 0 | case TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256: |
239 | 0 | specs->bulk_cipher_algorithm = wolfssl_chacha; |
240 | 0 | specs->cipher_type = aead; |
241 | 0 | specs->mac_algorithm = sha256_mac; |
242 | 0 | specs->kea = ecc_diffie_hellman_kea; |
243 | 0 | specs->sig_algo = rsa_sa_algo; |
244 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
245 | 0 | specs->pad_size = PAD_SHA; |
246 | 0 | specs->static_ecdh = 0; |
247 | 0 | specs->key_size = CHACHA20_256_KEY_SIZE; |
248 | 0 | specs->block_size = CHACHA20_BLOCK_SIZE; |
249 | 0 | specs->iv_size = CHACHA20_IV_SIZE; |
250 | 0 | specs->aead_mac_size = POLY1305_AUTH_SZ; |
251 | 0 | if (opts != NULL) |
252 | 0 | opts->oldPoly = 0; /* use recent padding RFC */ |
253 | |
|
254 | 0 | break; |
255 | 0 | #endif |
256 | | |
257 | 0 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 |
258 | 0 | case TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256: |
259 | 0 | specs->bulk_cipher_algorithm = wolfssl_chacha; |
260 | 0 | specs->cipher_type = aead; |
261 | 0 | specs->mac_algorithm = sha256_mac; |
262 | 0 | specs->kea = ecc_diffie_hellman_kea; |
263 | 0 | specs->sig_algo = ecc_dsa_sa_algo; |
264 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
265 | 0 | specs->pad_size = PAD_SHA; |
266 | 0 | specs->static_ecdh = 0; |
267 | 0 | specs->key_size = CHACHA20_256_KEY_SIZE; |
268 | 0 | specs->block_size = CHACHA20_BLOCK_SIZE; |
269 | 0 | specs->iv_size = CHACHA20_IV_SIZE; |
270 | 0 | specs->aead_mac_size = POLY1305_AUTH_SZ; |
271 | 0 | if (opts != NULL) |
272 | 0 | opts->oldPoly = 0; /* use recent padding RFC */ |
273 | |
|
274 | 0 | break; |
275 | 0 | #endif |
276 | | |
277 | 0 | #ifdef BUILD_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 |
278 | 0 | case TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256: |
279 | 0 | specs->bulk_cipher_algorithm = wolfssl_chacha; |
280 | 0 | specs->cipher_type = aead; |
281 | 0 | specs->mac_algorithm = sha256_mac; |
282 | 0 | specs->kea = diffie_hellman_kea; |
283 | 0 | specs->sig_algo = rsa_sa_algo; |
284 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
285 | 0 | specs->pad_size = PAD_SHA; |
286 | 0 | specs->static_ecdh = 0; |
287 | 0 | specs->key_size = CHACHA20_256_KEY_SIZE; |
288 | 0 | specs->block_size = CHACHA20_BLOCK_SIZE; |
289 | 0 | specs->iv_size = CHACHA20_IV_SIZE; |
290 | 0 | specs->aead_mac_size = POLY1305_AUTH_SZ; |
291 | 0 | if (opts != NULL) |
292 | 0 | opts->oldPoly = 0; /* use recent padding RFC */ |
293 | |
|
294 | 0 | break; |
295 | 0 | #endif |
296 | | |
297 | | #ifdef BUILD_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256 |
298 | | case TLS_PSK_WITH_CHACHA20_POLY1305_SHA256: |
299 | | specs->bulk_cipher_algorithm = wolfssl_chacha; |
300 | | specs->cipher_type = aead; |
301 | | specs->mac_algorithm = sha256_mac; |
302 | | specs->kea = psk_kea; |
303 | | specs->sig_algo = anonymous_sa_algo; |
304 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
305 | | specs->pad_size = PAD_SHA; |
306 | | specs->static_ecdh = 0; |
307 | | specs->key_size = CHACHA20_256_KEY_SIZE; |
308 | | specs->block_size = CHACHA20_BLOCK_SIZE; |
309 | | specs->iv_size = CHACHA20_IV_SIZE; |
310 | | specs->aead_mac_size = POLY1305_AUTH_SZ; |
311 | | |
312 | | if (opts != NULL) { |
313 | | opts->oldPoly = 0; /* use recent padding RFC */ |
314 | | opts->usingPSK_cipher = 1; |
315 | | } |
316 | | break; |
317 | | #endif |
318 | | |
319 | | #ifdef BUILD_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 |
320 | | case TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256: |
321 | | specs->bulk_cipher_algorithm = wolfssl_chacha; |
322 | | specs->cipher_type = aead; |
323 | | specs->mac_algorithm = sha256_mac; |
324 | | specs->kea = ecdhe_psk_kea; |
325 | | specs->sig_algo = anonymous_sa_algo; |
326 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
327 | | specs->pad_size = PAD_SHA; |
328 | | specs->static_ecdh = 0; |
329 | | specs->key_size = CHACHA20_256_KEY_SIZE; |
330 | | specs->block_size = CHACHA20_BLOCK_SIZE; |
331 | | specs->iv_size = CHACHA20_IV_SIZE; |
332 | | specs->aead_mac_size = POLY1305_AUTH_SZ; |
333 | | |
334 | | if (opts != NULL) { |
335 | | opts->oldPoly = 0; /* use recent padding RFC */ |
336 | | opts->usingPSK_cipher = 1; |
337 | | } |
338 | | break; |
339 | | #endif |
340 | | |
341 | | #ifdef BUILD_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256 |
342 | | case TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256: |
343 | | specs->bulk_cipher_algorithm = wolfssl_chacha; |
344 | | specs->cipher_type = aead; |
345 | | specs->mac_algorithm = sha256_mac; |
346 | | specs->kea = dhe_psk_kea; |
347 | | specs->sig_algo = anonymous_sa_algo; |
348 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
349 | | specs->pad_size = PAD_SHA; |
350 | | specs->static_ecdh = 0; |
351 | | specs->key_size = CHACHA20_256_KEY_SIZE; |
352 | | specs->block_size = CHACHA20_BLOCK_SIZE; |
353 | | specs->iv_size = CHACHA20_IV_SIZE; |
354 | | specs->aead_mac_size = POLY1305_AUTH_SZ; |
355 | | |
356 | | if (opts != NULL) { |
357 | | opts->oldPoly = 0; /* use recent padding RFC */ |
358 | | opts->usingPSK_cipher = 1; |
359 | | } |
360 | | break; |
361 | | #endif |
362 | 0 | default: |
363 | 0 | WOLFSSL_MSG("Unsupported cipher suite, SetCipherSpecs ChaCha"); |
364 | 0 | return UNSUPPORTED_SUITE; |
365 | 0 | } |
366 | 0 | } |
367 | | |
368 | | /* ECC extensions, AES-CCM or TLS 1.3 Integrity-only */ |
369 | 0 | if (cipherSuite0 == ECC_BYTE) { |
370 | |
|
371 | 0 | switch (cipherSuite) { |
372 | | |
373 | 0 | #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448) |
374 | | |
375 | 0 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 |
376 | 0 | case TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 : |
377 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes; |
378 | 0 | specs->cipher_type = block; |
379 | 0 | specs->mac_algorithm = sha256_mac; |
380 | 0 | specs->kea = ecc_diffie_hellman_kea; |
381 | 0 | specs->sig_algo = rsa_sa_algo; |
382 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
383 | 0 | specs->pad_size = PAD_SHA; |
384 | 0 | specs->static_ecdh = 0; |
385 | 0 | specs->key_size = AES_128_KEY_SIZE; |
386 | 0 | specs->iv_size = AES_IV_SIZE; |
387 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
388 | |
|
389 | 0 | break; |
390 | 0 | #endif |
391 | | |
392 | 0 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 |
393 | 0 | case TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 : |
394 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes; |
395 | 0 | specs->cipher_type = block; |
396 | 0 | specs->mac_algorithm = sha384_mac; |
397 | 0 | specs->kea = ecc_diffie_hellman_kea; |
398 | 0 | specs->sig_algo = rsa_sa_algo; |
399 | 0 | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
400 | 0 | specs->pad_size = PAD_SHA; |
401 | 0 | specs->static_ecdh = 0; |
402 | 0 | specs->key_size = AES_256_KEY_SIZE; |
403 | 0 | specs->iv_size = AES_IV_SIZE; |
404 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
405 | |
|
406 | 0 | break; |
407 | 0 | #endif |
408 | | |
409 | 0 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA |
410 | 0 | case TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA : |
411 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes; |
412 | 0 | specs->cipher_type = block; |
413 | 0 | specs->mac_algorithm = sha_mac; |
414 | 0 | specs->kea = ecc_diffie_hellman_kea; |
415 | 0 | specs->sig_algo = rsa_sa_algo; |
416 | 0 | specs->hash_size = WC_SHA_DIGEST_SIZE; |
417 | 0 | specs->pad_size = PAD_SHA; |
418 | 0 | specs->static_ecdh = 0; |
419 | 0 | specs->key_size = AES_128_KEY_SIZE; |
420 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
421 | 0 | specs->iv_size = AES_IV_SIZE; |
422 | |
|
423 | 0 | break; |
424 | 0 | #endif |
425 | | |
426 | | #ifdef BUILD_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA |
427 | | case TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA : |
428 | | specs->bulk_cipher_algorithm = wolfssl_triple_des; |
429 | | specs->cipher_type = block; |
430 | | specs->mac_algorithm = sha_mac; |
431 | | specs->kea = ecc_diffie_hellman_kea; |
432 | | specs->sig_algo = rsa_sa_algo; |
433 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
434 | | specs->pad_size = PAD_SHA; |
435 | | specs->static_ecdh = 0; |
436 | | specs->key_size = DES3_KEY_SIZE; |
437 | | specs->block_size = DES_BLOCK_SIZE; |
438 | | /* DES_IV_SIZE is incorrectly 16 in FIPS v2. It should be 8, same as the |
439 | | * block size. */ |
440 | | #if defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) |
441 | | specs->iv_size = DES_BLOCK_SIZE; |
442 | | #else |
443 | | specs->iv_size = DES_IV_SIZE; |
444 | | #endif |
445 | | |
446 | | break; |
447 | | #endif |
448 | | |
449 | 0 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_RC4_128_SHA |
450 | 0 | case TLS_ECDHE_RSA_WITH_RC4_128_SHA : |
451 | 0 | specs->bulk_cipher_algorithm = wolfssl_rc4; |
452 | 0 | specs->cipher_type = stream; |
453 | 0 | specs->mac_algorithm = sha_mac; |
454 | 0 | specs->kea = ecc_diffie_hellman_kea; |
455 | 0 | specs->sig_algo = rsa_sa_algo; |
456 | 0 | specs->hash_size = WC_SHA_DIGEST_SIZE; |
457 | 0 | specs->pad_size = PAD_SHA; |
458 | 0 | specs->static_ecdh = 0; |
459 | 0 | specs->key_size = RC4_KEY_SIZE; |
460 | 0 | specs->iv_size = 0; |
461 | 0 | specs->block_size = 0; |
462 | |
|
463 | 0 | break; |
464 | 0 | #endif |
465 | | |
466 | 0 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA |
467 | 0 | case TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA : |
468 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes; |
469 | 0 | specs->cipher_type = block; |
470 | 0 | specs->mac_algorithm = sha_mac; |
471 | 0 | specs->kea = ecc_diffie_hellman_kea; |
472 | 0 | specs->sig_algo = rsa_sa_algo; |
473 | 0 | specs->hash_size = WC_SHA_DIGEST_SIZE; |
474 | 0 | specs->pad_size = PAD_SHA; |
475 | 0 | specs->static_ecdh = 0; |
476 | 0 | specs->key_size = AES_256_KEY_SIZE; |
477 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
478 | 0 | specs->iv_size = AES_IV_SIZE; |
479 | |
|
480 | 0 | break; |
481 | 0 | #endif |
482 | | |
483 | 0 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 |
484 | 0 | case TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 : |
485 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
486 | 0 | specs->cipher_type = aead; |
487 | 0 | specs->mac_algorithm = sha256_mac; |
488 | 0 | specs->kea = ecc_diffie_hellman_kea; |
489 | 0 | specs->sig_algo = rsa_sa_algo; |
490 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
491 | 0 | specs->pad_size = PAD_SHA; |
492 | 0 | specs->static_ecdh = 0; |
493 | 0 | specs->key_size = AES_128_KEY_SIZE; |
494 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
495 | 0 | specs->iv_size = AESGCM_IMP_IV_SZ; |
496 | 0 | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
497 | |
|
498 | 0 | break; |
499 | 0 | #endif |
500 | | |
501 | 0 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 |
502 | 0 | case TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 : |
503 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
504 | 0 | specs->cipher_type = aead; |
505 | 0 | specs->mac_algorithm = sha384_mac; |
506 | 0 | specs->kea = ecc_diffie_hellman_kea; |
507 | 0 | specs->sig_algo = rsa_sa_algo; |
508 | 0 | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
509 | 0 | specs->pad_size = PAD_SHA; |
510 | 0 | specs->static_ecdh = 0; |
511 | 0 | specs->key_size = AES_256_KEY_SIZE; |
512 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
513 | 0 | specs->iv_size = AESGCM_IMP_IV_SZ; |
514 | 0 | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
515 | |
|
516 | 0 | break; |
517 | 0 | #endif |
518 | | |
519 | | #ifdef BUILD_TLS_ECDHE_PSK_WITH_NULL_SHA256 |
520 | | case TLS_ECDHE_PSK_WITH_NULL_SHA256 : |
521 | | specs->bulk_cipher_algorithm = wolfssl_cipher_null; |
522 | | specs->cipher_type = stream; |
523 | | specs->mac_algorithm = sha256_mac; |
524 | | specs->kea = ecdhe_psk_kea; |
525 | | specs->sig_algo = anonymous_sa_algo; |
526 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
527 | | specs->pad_size = PAD_SHA; |
528 | | specs->static_ecdh = 0; |
529 | | specs->key_size = 0; |
530 | | specs->block_size = 0; |
531 | | specs->iv_size = 0; |
532 | | |
533 | | if (opts != NULL) |
534 | | opts->usingPSK_cipher = 1; |
535 | | break; |
536 | | #endif |
537 | | |
538 | | #ifdef BUILD_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 |
539 | | case TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 : |
540 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
541 | | specs->cipher_type = block; |
542 | | specs->mac_algorithm = sha256_mac; |
543 | | specs->kea = ecdhe_psk_kea; |
544 | | specs->sig_algo = anonymous_sa_algo; |
545 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
546 | | specs->pad_size = PAD_SHA; |
547 | | specs->static_ecdh = 0; |
548 | | specs->key_size = AES_128_KEY_SIZE; |
549 | | specs->block_size = WC_AES_BLOCK_SIZE; |
550 | | specs->iv_size = AES_IV_SIZE; |
551 | | |
552 | | if (opts != NULL) |
553 | | opts->usingPSK_cipher = 1; |
554 | | break; |
555 | | #endif |
556 | | |
557 | 0 | #endif /* HAVE_ECC || HAVE_CURVE25519 || HAVE_CURVE448 */ |
558 | | |
559 | 0 | #if defined(HAVE_ECC) || (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) \ |
560 | 0 | || (defined(HAVE_CURVE448) && defined(HAVE_ED448)) |
561 | | |
562 | 0 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 |
563 | 0 | case TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 : |
564 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes; |
565 | 0 | specs->cipher_type = block; |
566 | 0 | specs->mac_algorithm = sha256_mac; |
567 | 0 | specs->kea = ecc_diffie_hellman_kea; |
568 | 0 | specs->sig_algo = ecc_dsa_sa_algo; |
569 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
570 | 0 | specs->pad_size = PAD_SHA; |
571 | 0 | specs->static_ecdh = 0; |
572 | 0 | specs->key_size = AES_128_KEY_SIZE; |
573 | 0 | specs->iv_size = AES_IV_SIZE; |
574 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
575 | |
|
576 | 0 | break; |
577 | 0 | #endif |
578 | | |
579 | 0 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 |
580 | 0 | case TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 : |
581 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes; |
582 | 0 | specs->cipher_type = block; |
583 | 0 | specs->mac_algorithm = sha384_mac; |
584 | 0 | specs->kea = ecc_diffie_hellman_kea; |
585 | 0 | specs->sig_algo = ecc_dsa_sa_algo; |
586 | 0 | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
587 | 0 | specs->pad_size = PAD_SHA; |
588 | 0 | specs->static_ecdh = 0; |
589 | 0 | specs->key_size = AES_256_KEY_SIZE; |
590 | 0 | specs->iv_size = AES_IV_SIZE; |
591 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
592 | |
|
593 | 0 | break; |
594 | 0 | #endif |
595 | | |
596 | | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA |
597 | | case TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA : |
598 | | specs->bulk_cipher_algorithm = wolfssl_triple_des; |
599 | | specs->cipher_type = block; |
600 | | specs->mac_algorithm = sha_mac; |
601 | | specs->kea = ecc_diffie_hellman_kea; |
602 | | specs->sig_algo = ecc_dsa_sa_algo; |
603 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
604 | | specs->pad_size = PAD_SHA; |
605 | | specs->static_ecdh = 0; |
606 | | specs->key_size = DES3_KEY_SIZE; |
607 | | specs->block_size = DES_BLOCK_SIZE; |
608 | | #if defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) |
609 | | specs->iv_size = DES_BLOCK_SIZE; |
610 | | #else |
611 | | specs->iv_size = DES_IV_SIZE; |
612 | | #endif |
613 | | |
614 | | break; |
615 | | #endif |
616 | | |
617 | 0 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA |
618 | 0 | case TLS_ECDHE_ECDSA_WITH_RC4_128_SHA : |
619 | 0 | specs->bulk_cipher_algorithm = wolfssl_rc4; |
620 | 0 | specs->cipher_type = stream; |
621 | 0 | specs->mac_algorithm = sha_mac; |
622 | 0 | specs->kea = ecc_diffie_hellman_kea; |
623 | 0 | specs->sig_algo = ecc_dsa_sa_algo; |
624 | 0 | specs->hash_size = WC_SHA_DIGEST_SIZE; |
625 | 0 | specs->pad_size = PAD_SHA; |
626 | 0 | specs->static_ecdh = 0; |
627 | 0 | specs->key_size = RC4_KEY_SIZE; |
628 | 0 | specs->iv_size = 0; |
629 | 0 | specs->block_size = 0; |
630 | |
|
631 | 0 | break; |
632 | 0 | #endif |
633 | | |
634 | 0 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA |
635 | 0 | case TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA : |
636 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes; |
637 | 0 | specs->cipher_type = block; |
638 | 0 | specs->mac_algorithm = sha_mac; |
639 | 0 | specs->kea = ecc_diffie_hellman_kea; |
640 | 0 | specs->sig_algo = ecc_dsa_sa_algo; |
641 | 0 | specs->hash_size = WC_SHA_DIGEST_SIZE; |
642 | 0 | specs->pad_size = PAD_SHA; |
643 | 0 | specs->static_ecdh = 0; |
644 | 0 | specs->key_size = AES_128_KEY_SIZE; |
645 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
646 | 0 | specs->iv_size = AES_IV_SIZE; |
647 | |
|
648 | 0 | break; |
649 | 0 | #endif |
650 | | |
651 | 0 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA |
652 | 0 | case TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA : |
653 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes; |
654 | 0 | specs->cipher_type = block; |
655 | 0 | specs->mac_algorithm = sha_mac; |
656 | 0 | specs->kea = ecc_diffie_hellman_kea; |
657 | 0 | specs->sig_algo = ecc_dsa_sa_algo; |
658 | 0 | specs->hash_size = WC_SHA_DIGEST_SIZE; |
659 | 0 | specs->pad_size = PAD_SHA; |
660 | 0 | specs->static_ecdh = 0; |
661 | 0 | specs->key_size = AES_256_KEY_SIZE; |
662 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
663 | 0 | specs->iv_size = AES_IV_SIZE; |
664 | |
|
665 | 0 | break; |
666 | 0 | #endif |
667 | | |
668 | 0 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 |
669 | 0 | case TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 : |
670 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
671 | 0 | specs->cipher_type = aead; |
672 | 0 | specs->mac_algorithm = sha256_mac; |
673 | 0 | specs->kea = ecc_diffie_hellman_kea; |
674 | 0 | specs->sig_algo = ecc_dsa_sa_algo; |
675 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
676 | 0 | specs->pad_size = PAD_SHA; |
677 | 0 | specs->static_ecdh = 0; |
678 | 0 | specs->key_size = AES_128_KEY_SIZE; |
679 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
680 | 0 | specs->iv_size = AESGCM_IMP_IV_SZ; |
681 | 0 | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
682 | |
|
683 | 0 | break; |
684 | 0 | #endif |
685 | | |
686 | 0 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 |
687 | 0 | case TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 : |
688 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
689 | 0 | specs->cipher_type = aead; |
690 | 0 | specs->mac_algorithm = sha384_mac; |
691 | 0 | specs->kea = ecc_diffie_hellman_kea; |
692 | 0 | specs->sig_algo = ecc_dsa_sa_algo; |
693 | 0 | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
694 | 0 | specs->pad_size = PAD_SHA; |
695 | 0 | specs->static_ecdh = 0; |
696 | 0 | specs->key_size = AES_256_KEY_SIZE; |
697 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
698 | 0 | specs->iv_size = AESGCM_IMP_IV_SZ; |
699 | 0 | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
700 | |
|
701 | 0 | break; |
702 | 0 | #endif |
703 | | |
704 | 0 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CCM |
705 | 0 | case TLS_ECDHE_ECDSA_WITH_AES_128_CCM : |
706 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes_ccm; |
707 | 0 | specs->cipher_type = aead; |
708 | 0 | specs->mac_algorithm = sha256_mac; |
709 | 0 | specs->kea = ecc_diffie_hellman_kea; |
710 | 0 | specs->sig_algo = ecc_dsa_sa_algo; |
711 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
712 | 0 | specs->pad_size = PAD_SHA; |
713 | 0 | specs->static_ecdh = 0; |
714 | 0 | specs->key_size = AES_128_KEY_SIZE; |
715 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
716 | 0 | specs->iv_size = AESCCM_IMP_IV_SZ; |
717 | 0 | specs->aead_mac_size = AES_CCM_16_AUTH_SZ; |
718 | |
|
719 | 0 | break; |
720 | 0 | #endif |
721 | | |
722 | 0 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 |
723 | 0 | case TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 : |
724 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes_ccm; |
725 | 0 | specs->cipher_type = aead; |
726 | 0 | specs->mac_algorithm = sha256_mac; |
727 | 0 | specs->kea = ecc_diffie_hellman_kea; |
728 | 0 | specs->sig_algo = ecc_dsa_sa_algo; |
729 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
730 | 0 | specs->pad_size = PAD_SHA; |
731 | 0 | specs->static_ecdh = 0; |
732 | 0 | specs->key_size = AES_128_KEY_SIZE; |
733 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
734 | 0 | specs->iv_size = AESCCM_IMP_IV_SZ; |
735 | 0 | specs->aead_mac_size = AES_CCM_8_AUTH_SZ; |
736 | |
|
737 | 0 | break; |
738 | 0 | #endif |
739 | | |
740 | 0 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 |
741 | 0 | case TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 : |
742 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes_ccm; |
743 | 0 | specs->cipher_type = aead; |
744 | 0 | specs->mac_algorithm = sha256_mac; |
745 | 0 | specs->kea = ecc_diffie_hellman_kea; |
746 | 0 | specs->sig_algo = ecc_dsa_sa_algo; |
747 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
748 | 0 | specs->pad_size = PAD_SHA; |
749 | 0 | specs->static_ecdh = 0; |
750 | 0 | specs->key_size = AES_256_KEY_SIZE; |
751 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
752 | 0 | specs->iv_size = AESCCM_IMP_IV_SZ; |
753 | 0 | specs->aead_mac_size = AES_CCM_8_AUTH_SZ; |
754 | |
|
755 | 0 | break; |
756 | 0 | #endif |
757 | | |
758 | | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_NULL_SHA |
759 | | case TLS_ECDHE_ECDSA_WITH_NULL_SHA : |
760 | | specs->bulk_cipher_algorithm = wolfssl_cipher_null; |
761 | | specs->cipher_type = stream; |
762 | | specs->mac_algorithm = sha_mac; |
763 | | specs->kea = ecc_diffie_hellman_kea; |
764 | | specs->sig_algo = ecc_dsa_sa_algo; |
765 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
766 | | specs->pad_size = PAD_SHA; |
767 | | specs->static_ecdh = 0; |
768 | | specs->key_size = 0; |
769 | | specs->block_size = 0; |
770 | | specs->iv_size = 0; |
771 | | |
772 | | break; |
773 | | #endif |
774 | | |
775 | 0 | #endif /* HAVE_ECC || (CURVE25519 && ED25519) || (CURVE448 && ED448) */ |
776 | | |
777 | 0 | #if defined(HAVE_ECC) |
778 | | |
779 | | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 |
780 | | case TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 : |
781 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
782 | | specs->cipher_type = block; |
783 | | specs->mac_algorithm = sha256_mac; |
784 | | specs->kea = ecc_diffie_hellman_kea; |
785 | | specs->sig_algo = rsa_sa_algo; |
786 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
787 | | specs->pad_size = PAD_SHA; |
788 | | specs->static_ecdh = 1; |
789 | | specs->key_size = AES_128_KEY_SIZE; |
790 | | specs->iv_size = AES_IV_SIZE; |
791 | | specs->block_size = WC_AES_BLOCK_SIZE; |
792 | | |
793 | | break; |
794 | | #endif |
795 | | |
796 | | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 |
797 | | case TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 : |
798 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
799 | | specs->cipher_type = block; |
800 | | specs->mac_algorithm = sha256_mac; |
801 | | specs->kea = ecc_diffie_hellman_kea; |
802 | | specs->sig_algo = ecc_dsa_sa_algo; |
803 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
804 | | specs->pad_size = PAD_SHA; |
805 | | specs->static_ecdh = 1; |
806 | | specs->key_size = AES_128_KEY_SIZE; |
807 | | specs->iv_size = AES_IV_SIZE; |
808 | | specs->block_size = WC_AES_BLOCK_SIZE; |
809 | | |
810 | | break; |
811 | | #endif |
812 | | |
813 | | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 |
814 | | case TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 : |
815 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
816 | | specs->cipher_type = block; |
817 | | specs->mac_algorithm = sha384_mac; |
818 | | specs->kea = ecc_diffie_hellman_kea; |
819 | | specs->sig_algo = rsa_sa_algo; |
820 | | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
821 | | specs->pad_size = PAD_SHA; |
822 | | specs->static_ecdh = 1; |
823 | | specs->key_size = AES_256_KEY_SIZE; |
824 | | specs->iv_size = AES_IV_SIZE; |
825 | | specs->block_size = WC_AES_BLOCK_SIZE; |
826 | | |
827 | | break; |
828 | | #endif |
829 | | |
830 | | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 |
831 | | case TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 : |
832 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
833 | | specs->cipher_type = block; |
834 | | specs->mac_algorithm = sha384_mac; |
835 | | specs->kea = ecc_diffie_hellman_kea; |
836 | | specs->sig_algo = ecc_dsa_sa_algo; |
837 | | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
838 | | specs->pad_size = PAD_SHA; |
839 | | specs->static_ecdh = 1; |
840 | | specs->key_size = AES_256_KEY_SIZE; |
841 | | specs->iv_size = AES_IV_SIZE; |
842 | | specs->block_size = WC_AES_BLOCK_SIZE; |
843 | | |
844 | | break; |
845 | | #endif |
846 | | |
847 | | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA |
848 | | case TLS_ECDH_RSA_WITH_AES_128_CBC_SHA : |
849 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
850 | | specs->cipher_type = block; |
851 | | specs->mac_algorithm = sha_mac; |
852 | | specs->kea = ecc_diffie_hellman_kea; |
853 | | specs->sig_algo = rsa_sa_algo; |
854 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
855 | | specs->pad_size = PAD_SHA; |
856 | | specs->static_ecdh = 1; |
857 | | specs->key_size = AES_128_KEY_SIZE; |
858 | | specs->block_size = WC_AES_BLOCK_SIZE; |
859 | | specs->iv_size = AES_IV_SIZE; |
860 | | |
861 | | break; |
862 | | #endif |
863 | | |
864 | | #ifdef BUILD_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA |
865 | | case TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA : |
866 | | specs->bulk_cipher_algorithm = wolfssl_triple_des; |
867 | | specs->cipher_type = block; |
868 | | specs->mac_algorithm = sha_mac; |
869 | | specs->kea = ecc_diffie_hellman_kea; |
870 | | specs->sig_algo = rsa_sa_algo; |
871 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
872 | | specs->pad_size = PAD_SHA; |
873 | | specs->static_ecdh = 1; |
874 | | specs->key_size = DES3_KEY_SIZE; |
875 | | specs->block_size = DES_BLOCK_SIZE; |
876 | | #if defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) |
877 | | specs->iv_size = DES_BLOCK_SIZE; |
878 | | #else |
879 | | specs->iv_size = DES_IV_SIZE; |
880 | | #endif |
881 | | |
882 | | break; |
883 | | #endif |
884 | | |
885 | | #ifdef BUILD_TLS_ECDH_RSA_WITH_RC4_128_SHA |
886 | | case TLS_ECDH_RSA_WITH_RC4_128_SHA : |
887 | | specs->bulk_cipher_algorithm = wolfssl_rc4; |
888 | | specs->cipher_type = stream; |
889 | | specs->mac_algorithm = sha_mac; |
890 | | specs->kea = ecc_diffie_hellman_kea; |
891 | | specs->sig_algo = rsa_sa_algo; |
892 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
893 | | specs->pad_size = PAD_SHA; |
894 | | specs->static_ecdh = 1; |
895 | | specs->key_size = RC4_KEY_SIZE; |
896 | | specs->iv_size = 0; |
897 | | specs->block_size = 0; |
898 | | |
899 | | break; |
900 | | #endif |
901 | | |
902 | | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA |
903 | | case TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA : |
904 | | specs->bulk_cipher_algorithm = wolfssl_triple_des; |
905 | | specs->cipher_type = block; |
906 | | specs->mac_algorithm = sha_mac; |
907 | | specs->kea = ecc_diffie_hellman_kea; |
908 | | specs->sig_algo = ecc_dsa_sa_algo; |
909 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
910 | | specs->pad_size = PAD_SHA; |
911 | | specs->static_ecdh = 1; |
912 | | specs->key_size = DES3_KEY_SIZE; |
913 | | specs->block_size = DES_BLOCK_SIZE; |
914 | | #if defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) |
915 | | specs->iv_size = DES_BLOCK_SIZE; |
916 | | #else |
917 | | specs->iv_size = DES_IV_SIZE; |
918 | | #endif |
919 | | |
920 | | break; |
921 | | #endif |
922 | | |
923 | | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_RC4_128_SHA |
924 | | case TLS_ECDH_ECDSA_WITH_RC4_128_SHA : |
925 | | specs->bulk_cipher_algorithm = wolfssl_rc4; |
926 | | specs->cipher_type = stream; |
927 | | specs->mac_algorithm = sha_mac; |
928 | | specs->kea = ecc_diffie_hellman_kea; |
929 | | specs->sig_algo = ecc_dsa_sa_algo; |
930 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
931 | | specs->pad_size = PAD_SHA; |
932 | | specs->static_ecdh = 1; |
933 | | specs->key_size = RC4_KEY_SIZE; |
934 | | specs->iv_size = 0; |
935 | | specs->block_size = 0; |
936 | | |
937 | | break; |
938 | | #endif |
939 | | |
940 | | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA |
941 | | case TLS_ECDH_RSA_WITH_AES_256_CBC_SHA : |
942 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
943 | | specs->cipher_type = block; |
944 | | specs->mac_algorithm = sha_mac; |
945 | | specs->kea = ecc_diffie_hellman_kea; |
946 | | specs->sig_algo = rsa_sa_algo; |
947 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
948 | | specs->pad_size = PAD_SHA; |
949 | | specs->static_ecdh = 1; |
950 | | specs->key_size = AES_256_KEY_SIZE; |
951 | | specs->block_size = WC_AES_BLOCK_SIZE; |
952 | | specs->iv_size = AES_IV_SIZE; |
953 | | |
954 | | break; |
955 | | #endif |
956 | | |
957 | | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA |
958 | | case TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA : |
959 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
960 | | specs->cipher_type = block; |
961 | | specs->mac_algorithm = sha_mac; |
962 | | specs->kea = ecc_diffie_hellman_kea; |
963 | | specs->sig_algo = ecc_dsa_sa_algo; |
964 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
965 | | specs->pad_size = PAD_SHA; |
966 | | specs->static_ecdh = 1; |
967 | | specs->key_size = AES_128_KEY_SIZE; |
968 | | specs->block_size = WC_AES_BLOCK_SIZE; |
969 | | specs->iv_size = AES_IV_SIZE; |
970 | | |
971 | | break; |
972 | | #endif |
973 | | |
974 | | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA |
975 | | case TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA : |
976 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
977 | | specs->cipher_type = block; |
978 | | specs->mac_algorithm = sha_mac; |
979 | | specs->kea = ecc_diffie_hellman_kea; |
980 | | specs->sig_algo = ecc_dsa_sa_algo; |
981 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
982 | | specs->pad_size = PAD_SHA; |
983 | | specs->static_ecdh = 1; |
984 | | specs->key_size = AES_256_KEY_SIZE; |
985 | | specs->block_size = WC_AES_BLOCK_SIZE; |
986 | | specs->iv_size = AES_IV_SIZE; |
987 | | |
988 | | break; |
989 | | #endif |
990 | | |
991 | | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 |
992 | | case TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 : |
993 | | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
994 | | specs->cipher_type = aead; |
995 | | specs->mac_algorithm = sha256_mac; |
996 | | specs->kea = ecc_diffie_hellman_kea; |
997 | | specs->sig_algo = rsa_sa_algo; |
998 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
999 | | specs->pad_size = PAD_SHA; |
1000 | | specs->static_ecdh = 1; |
1001 | | specs->key_size = AES_128_KEY_SIZE; |
1002 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1003 | | specs->iv_size = AESGCM_IMP_IV_SZ; |
1004 | | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
1005 | | |
1006 | | break; |
1007 | | #endif |
1008 | | |
1009 | | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 |
1010 | | case TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 : |
1011 | | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
1012 | | specs->cipher_type = aead; |
1013 | | specs->mac_algorithm = sha384_mac; |
1014 | | specs->kea = ecc_diffie_hellman_kea; |
1015 | | specs->sig_algo = rsa_sa_algo; |
1016 | | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
1017 | | specs->pad_size = PAD_SHA; |
1018 | | specs->static_ecdh = 1; |
1019 | | specs->key_size = AES_256_KEY_SIZE; |
1020 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1021 | | specs->iv_size = AESGCM_IMP_IV_SZ; |
1022 | | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
1023 | | |
1024 | | break; |
1025 | | #endif |
1026 | | |
1027 | | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 |
1028 | | case TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 : |
1029 | | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
1030 | | specs->cipher_type = aead; |
1031 | | specs->mac_algorithm = sha256_mac; |
1032 | | specs->kea = ecc_diffie_hellman_kea; |
1033 | | specs->sig_algo = ecc_dsa_sa_algo; |
1034 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1035 | | specs->pad_size = PAD_SHA; |
1036 | | specs->static_ecdh = 1; |
1037 | | specs->key_size = AES_128_KEY_SIZE; |
1038 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1039 | | specs->iv_size = AESGCM_IMP_IV_SZ; |
1040 | | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
1041 | | |
1042 | | break; |
1043 | | #endif |
1044 | | |
1045 | | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 |
1046 | | case TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 : |
1047 | | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
1048 | | specs->cipher_type = aead; |
1049 | | specs->mac_algorithm = sha384_mac; |
1050 | | specs->kea = ecc_diffie_hellman_kea; |
1051 | | specs->sig_algo = ecc_dsa_sa_algo; |
1052 | | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
1053 | | specs->pad_size = PAD_SHA; |
1054 | | specs->static_ecdh = 1; |
1055 | | specs->key_size = AES_256_KEY_SIZE; |
1056 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1057 | | specs->iv_size = AESGCM_IMP_IV_SZ; |
1058 | | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
1059 | | |
1060 | | break; |
1061 | | #endif |
1062 | | |
1063 | | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256 |
1064 | | case TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256 : |
1065 | | specs->bulk_cipher_algorithm = wolfssl_aria_gcm; |
1066 | | specs->cipher_type = aead; |
1067 | | specs->mac_algorithm = sha256_mac; |
1068 | | specs->kea = ecc_diffie_hellman_kea; |
1069 | | specs->sig_algo = ecc_dsa_sa_algo; |
1070 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1071 | | specs->pad_size = PAD_SHA; |
1072 | | specs->static_ecdh = 0; |
1073 | | specs->key_size = ARIA_128_KEY_SIZE; |
1074 | | specs->block_size = ARIA_BLOCK_SIZE; |
1075 | | specs->iv_size = AESGCM_IMP_IV_SZ; |
1076 | | specs->aead_mac_size = ARIA_GCM_AUTH_SZ; |
1077 | | |
1078 | | break; |
1079 | | #endif |
1080 | | |
1081 | | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384 |
1082 | | case TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384 : |
1083 | | specs->bulk_cipher_algorithm = wolfssl_aria_gcm; |
1084 | | specs->cipher_type = aead; |
1085 | | specs->mac_algorithm = sha384_mac; |
1086 | | specs->kea = ecc_diffie_hellman_kea; |
1087 | | specs->sig_algo = ecc_dsa_sa_algo; |
1088 | | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
1089 | | specs->pad_size = PAD_SHA; |
1090 | | specs->static_ecdh = 0; |
1091 | | specs->key_size = ARIA_256_KEY_SIZE; |
1092 | | specs->block_size = ARIA_BLOCK_SIZE; |
1093 | | specs->iv_size = AESGCM_IMP_IV_SZ; |
1094 | | specs->aead_mac_size = ARIA_GCM_AUTH_SZ; |
1095 | | |
1096 | | break; |
1097 | | #endif |
1098 | | |
1099 | 0 | #endif /* HAVE_ECC */ |
1100 | | |
1101 | | #ifdef BUILD_TLS_RSA_WITH_AES_128_CCM_8 |
1102 | | case TLS_RSA_WITH_AES_128_CCM_8 : |
1103 | | specs->bulk_cipher_algorithm = wolfssl_aes_ccm; |
1104 | | specs->cipher_type = aead; |
1105 | | specs->mac_algorithm = sha256_mac; |
1106 | | specs->kea = rsa_kea; |
1107 | | specs->sig_algo = rsa_sa_algo; |
1108 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1109 | | specs->pad_size = PAD_SHA; |
1110 | | specs->static_ecdh = 0; |
1111 | | specs->key_size = AES_128_KEY_SIZE; |
1112 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1113 | | specs->iv_size = AESCCM_IMP_IV_SZ; |
1114 | | specs->aead_mac_size = AES_CCM_8_AUTH_SZ; |
1115 | | |
1116 | | break; |
1117 | | #endif |
1118 | | |
1119 | | #ifdef BUILD_TLS_RSA_WITH_AES_256_CCM_8 |
1120 | | case TLS_RSA_WITH_AES_256_CCM_8 : |
1121 | | specs->bulk_cipher_algorithm = wolfssl_aes_ccm; |
1122 | | specs->cipher_type = aead; |
1123 | | specs->mac_algorithm = sha256_mac; |
1124 | | specs->kea = rsa_kea; |
1125 | | specs->sig_algo = rsa_sa_algo; |
1126 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1127 | | specs->pad_size = PAD_SHA; |
1128 | | specs->static_ecdh = 0; |
1129 | | specs->key_size = AES_256_KEY_SIZE; |
1130 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1131 | | specs->iv_size = AESCCM_IMP_IV_SZ; |
1132 | | specs->aead_mac_size = AES_CCM_8_AUTH_SZ; |
1133 | | |
1134 | | break; |
1135 | | #endif |
1136 | | |
1137 | | #ifdef BUILD_TLS_PSK_WITH_AES_128_CCM_8 |
1138 | | case TLS_PSK_WITH_AES_128_CCM_8 : |
1139 | | specs->bulk_cipher_algorithm = wolfssl_aes_ccm; |
1140 | | specs->cipher_type = aead; |
1141 | | specs->mac_algorithm = sha256_mac; |
1142 | | specs->kea = psk_kea; |
1143 | | specs->sig_algo = anonymous_sa_algo; |
1144 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1145 | | specs->pad_size = PAD_SHA; |
1146 | | specs->static_ecdh = 0; |
1147 | | specs->key_size = AES_128_KEY_SIZE; |
1148 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1149 | | specs->iv_size = AESCCM_IMP_IV_SZ; |
1150 | | specs->aead_mac_size = AES_CCM_8_AUTH_SZ; |
1151 | | |
1152 | | if (opts != NULL) |
1153 | | opts->usingPSK_cipher = 1; |
1154 | | break; |
1155 | | #endif |
1156 | | |
1157 | | #ifdef BUILD_TLS_PSK_WITH_AES_256_CCM_8 |
1158 | | case TLS_PSK_WITH_AES_256_CCM_8 : |
1159 | | specs->bulk_cipher_algorithm = wolfssl_aes_ccm; |
1160 | | specs->cipher_type = aead; |
1161 | | specs->mac_algorithm = sha256_mac; |
1162 | | specs->kea = psk_kea; |
1163 | | specs->sig_algo = anonymous_sa_algo; |
1164 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1165 | | specs->pad_size = PAD_SHA; |
1166 | | specs->static_ecdh = 0; |
1167 | | specs->key_size = AES_256_KEY_SIZE; |
1168 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1169 | | specs->iv_size = AESCCM_IMP_IV_SZ; |
1170 | | specs->aead_mac_size = AES_CCM_8_AUTH_SZ; |
1171 | | |
1172 | | if (opts != NULL) |
1173 | | opts->usingPSK_cipher = 1; |
1174 | | break; |
1175 | | #endif |
1176 | | |
1177 | | #ifdef BUILD_TLS_PSK_WITH_AES_128_CCM |
1178 | | case TLS_PSK_WITH_AES_128_CCM : |
1179 | | specs->bulk_cipher_algorithm = wolfssl_aes_ccm; |
1180 | | specs->cipher_type = aead; |
1181 | | specs->mac_algorithm = sha256_mac; |
1182 | | specs->kea = psk_kea; |
1183 | | specs->sig_algo = anonymous_sa_algo; |
1184 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1185 | | specs->pad_size = PAD_SHA; |
1186 | | specs->static_ecdh = 0; |
1187 | | specs->key_size = AES_128_KEY_SIZE; |
1188 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1189 | | specs->iv_size = AESCCM_IMP_IV_SZ; |
1190 | | specs->aead_mac_size = AES_CCM_16_AUTH_SZ; |
1191 | | |
1192 | | if (opts != NULL) |
1193 | | opts->usingPSK_cipher = 1; |
1194 | | break; |
1195 | | #endif |
1196 | | |
1197 | | #ifdef BUILD_TLS_PSK_WITH_AES_256_CCM |
1198 | | case TLS_PSK_WITH_AES_256_CCM : |
1199 | | specs->bulk_cipher_algorithm = wolfssl_aes_ccm; |
1200 | | specs->cipher_type = aead; |
1201 | | specs->mac_algorithm = sha256_mac; |
1202 | | specs->kea = psk_kea; |
1203 | | specs->sig_algo = anonymous_sa_algo; |
1204 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1205 | | specs->pad_size = PAD_SHA; |
1206 | | specs->static_ecdh = 0; |
1207 | | specs->key_size = AES_256_KEY_SIZE; |
1208 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1209 | | specs->iv_size = AESCCM_IMP_IV_SZ; |
1210 | | specs->aead_mac_size = AES_CCM_16_AUTH_SZ; |
1211 | | |
1212 | | if (opts != NULL) |
1213 | | opts->usingPSK_cipher = 1; |
1214 | | break; |
1215 | | #endif |
1216 | | |
1217 | | #ifdef BUILD_TLS_DHE_PSK_WITH_AES_128_CCM |
1218 | | case TLS_DHE_PSK_WITH_AES_128_CCM : |
1219 | | specs->bulk_cipher_algorithm = wolfssl_aes_ccm; |
1220 | | specs->cipher_type = aead; |
1221 | | specs->mac_algorithm = sha256_mac; |
1222 | | specs->kea = dhe_psk_kea; |
1223 | | specs->sig_algo = anonymous_sa_algo; |
1224 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1225 | | specs->pad_size = PAD_SHA; |
1226 | | specs->static_ecdh = 0; |
1227 | | specs->key_size = AES_128_KEY_SIZE; |
1228 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1229 | | specs->iv_size = AESCCM_IMP_IV_SZ; |
1230 | | specs->aead_mac_size = AES_CCM_16_AUTH_SZ; |
1231 | | |
1232 | | if (opts != NULL) |
1233 | | opts->usingPSK_cipher = 1; |
1234 | | break; |
1235 | | #endif |
1236 | | |
1237 | | #ifdef BUILD_TLS_DHE_PSK_WITH_AES_256_CCM |
1238 | | case TLS_DHE_PSK_WITH_AES_256_CCM : |
1239 | | specs->bulk_cipher_algorithm = wolfssl_aes_ccm; |
1240 | | specs->cipher_type = aead; |
1241 | | specs->mac_algorithm = sha256_mac; |
1242 | | specs->kea = dhe_psk_kea; |
1243 | | specs->sig_algo = anonymous_sa_algo; |
1244 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1245 | | specs->pad_size = PAD_SHA; |
1246 | | specs->static_ecdh = 0; |
1247 | | specs->key_size = AES_256_KEY_SIZE; |
1248 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1249 | | specs->iv_size = AESCCM_IMP_IV_SZ; |
1250 | | specs->aead_mac_size = AES_CCM_16_AUTH_SZ; |
1251 | | |
1252 | | if (opts != NULL) |
1253 | | opts->usingPSK_cipher = 1; |
1254 | | break; |
1255 | | #endif |
1256 | | |
1257 | | #if defined(WOLFSSL_TLS13) && defined(HAVE_NULL_CIPHER) |
1258 | | #ifdef BUILD_TLS_SHA256_SHA256 |
1259 | | case TLS_SHA256_SHA256 : |
1260 | | specs->bulk_cipher_algorithm = wolfssl_cipher_null; |
1261 | | specs->cipher_type = aead; |
1262 | | specs->mac_algorithm = sha256_mac; |
1263 | | specs->kea = any_kea; |
1264 | | specs->sig_algo = any_sa_algo; |
1265 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1266 | | specs->pad_size = PAD_SHA; |
1267 | | specs->static_ecdh = 0; |
1268 | | specs->key_size = WC_SHA256_DIGEST_SIZE; |
1269 | | specs->block_size = 0; |
1270 | | specs->iv_size = WC_SHA256_DIGEST_SIZE; |
1271 | | specs->aead_mac_size = WC_SHA256_DIGEST_SIZE; |
1272 | | |
1273 | | break; |
1274 | | #endif |
1275 | | |
1276 | | #ifdef BUILD_TLS_SHA384_SHA384 |
1277 | | case TLS_SHA384_SHA384 : |
1278 | | specs->bulk_cipher_algorithm = wolfssl_cipher_null; |
1279 | | specs->cipher_type = aead; |
1280 | | specs->mac_algorithm = sha384_mac; |
1281 | | specs->kea = any_kea; |
1282 | | specs->sig_algo = any_sa_algo; |
1283 | | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
1284 | | specs->pad_size = PAD_SHA; |
1285 | | specs->static_ecdh = 0; |
1286 | | specs->key_size = WC_SHA384_DIGEST_SIZE; |
1287 | | specs->block_size = 0; |
1288 | | specs->iv_size = WC_SHA384_DIGEST_SIZE; |
1289 | | specs->aead_mac_size = WC_SHA384_DIGEST_SIZE; |
1290 | | |
1291 | | break; |
1292 | | #endif |
1293 | | #endif |
1294 | | |
1295 | 0 | default: |
1296 | 0 | WOLFSSL_MSG("Unsupported cipher suite, SetCipherSpecs ECC"); |
1297 | 0 | return UNSUPPORTED_SUITE; |
1298 | 0 | } /* switch */ |
1299 | 0 | } /* if */ |
1300 | | |
1301 | | /* TLSi v1.3 cipher suites, 0x13 */ |
1302 | 0 | if (cipherSuite0 == TLS13_BYTE) { |
1303 | 0 | switch (cipherSuite) { |
1304 | | |
1305 | 0 | #ifdef WOLFSSL_TLS13 |
1306 | 0 | #ifdef BUILD_TLS_AES_128_GCM_SHA256 |
1307 | 0 | case TLS_AES_128_GCM_SHA256 : |
1308 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
1309 | 0 | specs->cipher_type = aead; |
1310 | 0 | specs->mac_algorithm = sha256_mac; |
1311 | 0 | specs->kea = any_kea; |
1312 | 0 | specs->sig_algo = any_sa_algo; |
1313 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1314 | 0 | specs->pad_size = PAD_SHA; |
1315 | 0 | specs->static_ecdh = 0; |
1316 | 0 | specs->key_size = AES_128_KEY_SIZE; |
1317 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
1318 | 0 | specs->iv_size = AESGCM_NONCE_SZ; |
1319 | 0 | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
1320 | |
|
1321 | 0 | break; |
1322 | 0 | #endif |
1323 | | |
1324 | 0 | #ifdef BUILD_TLS_AES_256_GCM_SHA384 |
1325 | 0 | case TLS_AES_256_GCM_SHA384 : |
1326 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
1327 | 0 | specs->cipher_type = aead; |
1328 | 0 | specs->mac_algorithm = sha384_mac; |
1329 | 0 | specs->kea = any_kea; |
1330 | 0 | specs->sig_algo = any_sa_algo; |
1331 | 0 | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
1332 | 0 | specs->pad_size = PAD_SHA; |
1333 | 0 | specs->static_ecdh = 0; |
1334 | 0 | specs->key_size = AES_256_KEY_SIZE; |
1335 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
1336 | 0 | specs->iv_size = AESGCM_NONCE_SZ; |
1337 | 0 | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
1338 | |
|
1339 | 0 | break; |
1340 | 0 | #endif |
1341 | | |
1342 | 0 | #ifdef BUILD_TLS_CHACHA20_POLY1305_SHA256 |
1343 | 0 | case TLS_CHACHA20_POLY1305_SHA256 : |
1344 | 0 | specs->bulk_cipher_algorithm = wolfssl_chacha; |
1345 | 0 | specs->cipher_type = aead; |
1346 | 0 | specs->mac_algorithm = sha256_mac; |
1347 | 0 | specs->kea = any_kea; |
1348 | 0 | specs->sig_algo = any_sa_algo; |
1349 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1350 | 0 | specs->pad_size = PAD_SHA; |
1351 | 0 | specs->static_ecdh = 0; |
1352 | 0 | specs->key_size = CHACHA20_256_KEY_SIZE; |
1353 | 0 | specs->block_size = CHACHA20_BLOCK_SIZE; |
1354 | 0 | specs->iv_size = CHACHA20_IV_SIZE; |
1355 | 0 | specs->aead_mac_size = POLY1305_AUTH_SZ; |
1356 | 0 | if (opts != NULL) |
1357 | 0 | opts->oldPoly = 0; /* use recent padding RFC */ |
1358 | |
|
1359 | 0 | break; |
1360 | 0 | #endif |
1361 | | |
1362 | 0 | #ifdef BUILD_TLS_AES_128_CCM_SHA256 |
1363 | 0 | case TLS_AES_128_CCM_SHA256 : |
1364 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes_ccm; |
1365 | 0 | specs->cipher_type = aead; |
1366 | 0 | specs->mac_algorithm = sha256_mac; |
1367 | 0 | specs->kea = any_kea; |
1368 | 0 | specs->sig_algo = any_sa_algo; |
1369 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1370 | 0 | specs->pad_size = PAD_SHA; |
1371 | 0 | specs->static_ecdh = 0; |
1372 | 0 | specs->key_size = AES_128_KEY_SIZE; |
1373 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
1374 | 0 | specs->iv_size = AESCCM_NONCE_SZ; |
1375 | 0 | specs->aead_mac_size = AES_CCM_16_AUTH_SZ; |
1376 | |
|
1377 | 0 | break; |
1378 | 0 | #endif |
1379 | | |
1380 | 0 | #ifdef BUILD_TLS_AES_128_CCM_8_SHA256 |
1381 | 0 | case TLS_AES_128_CCM_8_SHA256 : |
1382 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes_ccm; |
1383 | 0 | specs->cipher_type = aead; |
1384 | 0 | specs->mac_algorithm = sha256_mac; |
1385 | 0 | specs->kea = any_kea; |
1386 | 0 | specs->sig_algo = any_sa_algo; |
1387 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1388 | 0 | specs->pad_size = PAD_SHA; |
1389 | 0 | specs->static_ecdh = 0; |
1390 | 0 | specs->key_size = AES_128_KEY_SIZE; |
1391 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
1392 | 0 | specs->iv_size = AESCCM_NONCE_SZ; |
1393 | 0 | specs->aead_mac_size = AES_CCM_8_AUTH_SZ; |
1394 | |
|
1395 | 0 | break; |
1396 | 0 | #endif |
1397 | 0 | #endif /* WOLFSSL_TLS13 */ |
1398 | 0 | default: |
1399 | 0 | WOLFSSL_MSG("Unsupported cipher suite, SetCipherSpecs TLS 1.3"); |
1400 | 0 | return UNSUPPORTED_SUITE; |
1401 | 0 | } |
1402 | 0 | } |
1403 | | |
1404 | 0 | if (cipherSuite0 == ECDHE_PSK_BYTE) { |
1405 | |
|
1406 | 0 | switch (cipherSuite) { |
1407 | | |
1408 | 0 | #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448) |
1409 | | #ifdef BUILD_TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256 |
1410 | | case TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256 : |
1411 | | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
1412 | | specs->cipher_type = aead; |
1413 | | specs->mac_algorithm = sha256_mac; |
1414 | | specs->kea = ecdhe_psk_kea; |
1415 | | specs->sig_algo = anonymous_sa_algo; |
1416 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1417 | | specs->pad_size = PAD_SHA; |
1418 | | specs->static_ecdh = 0; |
1419 | | specs->key_size = AES_128_KEY_SIZE; |
1420 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1421 | | specs->iv_size = AESGCM_IMP_IV_SZ; |
1422 | | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
1423 | | |
1424 | | if (opts != NULL) |
1425 | | opts->usingPSK_cipher = 1; |
1426 | | break; |
1427 | | #endif |
1428 | 0 | #endif |
1429 | | |
1430 | 0 | default: |
1431 | 0 | WOLFSSL_MSG("Unsupported cipher suite, SetCipherSpecs ECDHE_PSK"); |
1432 | 0 | return UNSUPPORTED_SUITE; |
1433 | 0 | } |
1434 | 0 | } |
1435 | | |
1436 | 0 | if (cipherSuite0 == SM_BYTE) { |
1437 | |
|
1438 | 0 | switch (cipherSuite) { |
1439 | 0 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_SM4_CBC_SM3 |
1440 | 0 | case TLS_ECDHE_ECDSA_WITH_SM4_CBC_SM3 : |
1441 | 0 | specs->bulk_cipher_algorithm = wolfssl_sm4_cbc; |
1442 | 0 | specs->cipher_type = block; |
1443 | 0 | specs->mac_algorithm = sm3_mac; |
1444 | 0 | specs->kea = ecc_diffie_hellman_kea; |
1445 | 0 | specs->sig_algo = sm2_sa_algo; |
1446 | 0 | specs->hash_size = WC_SM3_DIGEST_SIZE; |
1447 | 0 | specs->pad_size = PAD_SHA; |
1448 | 0 | specs->static_ecdh = 0; |
1449 | 0 | specs->key_size = SM4_KEY_SIZE; |
1450 | 0 | specs->iv_size = SM4_IV_SIZE; |
1451 | 0 | specs->block_size = SM4_BLOCK_SIZE; |
1452 | |
|
1453 | 0 | break; |
1454 | 0 | #endif |
1455 | | |
1456 | 0 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_SM4_GCM_SM3 |
1457 | 0 | case TLS_ECDHE_ECDSA_WITH_SM4_GCM_SM3 : |
1458 | 0 | specs->bulk_cipher_algorithm = wolfssl_sm4_gcm; |
1459 | 0 | specs->cipher_type = aead; |
1460 | 0 | specs->mac_algorithm = sm3_mac; |
1461 | 0 | specs->kea = ecc_diffie_hellman_kea; |
1462 | 0 | specs->sig_algo = sm2_sa_algo; |
1463 | 0 | specs->hash_size = WC_SM3_DIGEST_SIZE; |
1464 | 0 | specs->pad_size = PAD_SHA; |
1465 | 0 | specs->static_ecdh = 0; |
1466 | 0 | specs->key_size = SM4_KEY_SIZE; |
1467 | 0 | specs->block_size = SM4_BLOCK_SIZE; |
1468 | 0 | specs->iv_size = GCM_IMP_IV_SZ; |
1469 | 0 | specs->aead_mac_size = SM4_GCM_AUTH_SZ; |
1470 | |
|
1471 | 0 | break; |
1472 | 0 | #endif |
1473 | | |
1474 | 0 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_SM4_CCM_SM3 |
1475 | 0 | case TLS_ECDHE_ECDSA_WITH_SM4_CCM_SM3 : |
1476 | 0 | specs->bulk_cipher_algorithm = wolfssl_sm4_ccm; |
1477 | 0 | specs->cipher_type = aead; |
1478 | 0 | specs->mac_algorithm = sm3_mac; |
1479 | 0 | specs->kea = ecc_diffie_hellman_kea; |
1480 | 0 | specs->sig_algo = sm2_sa_algo; |
1481 | 0 | specs->hash_size = WC_SM3_DIGEST_SIZE; |
1482 | 0 | specs->pad_size = PAD_SHA; |
1483 | 0 | specs->static_ecdh = 0; |
1484 | 0 | specs->key_size = SM4_KEY_SIZE; |
1485 | 0 | specs->block_size = SM4_BLOCK_SIZE; |
1486 | 0 | specs->iv_size = CCM_IMP_IV_SZ; |
1487 | 0 | specs->aead_mac_size = SM4_CCM_AUTH_SZ; |
1488 | |
|
1489 | 0 | break; |
1490 | 0 | #endif |
1491 | | |
1492 | 0 | default: |
1493 | 0 | WOLFSSL_MSG("Unsupported cipher suite, SetCipherSpecs SM"); |
1494 | 0 | return UNSUPPORTED_SUITE; |
1495 | 0 | } |
1496 | 0 | } |
1497 | | |
1498 | 0 | if (cipherSuite0 != ECC_BYTE && |
1499 | 0 | cipherSuite0 != ECDHE_PSK_BYTE && |
1500 | 0 | cipherSuite0 != CHACHA_BYTE && |
1501 | 0 | #if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3) && \ |
1502 | 0 | (defined(WOLFSSL_SM4_CBC) || defined(WOLFSSL_SM4_GCM) || \ |
1503 | 0 | defined(WOLFSSL_SM4_CCM)) |
1504 | 0 | cipherSuite0 != SM_BYTE && |
1505 | 0 | #endif |
1506 | 0 | cipherSuite0 != TLS13_BYTE) { /* normal suites */ |
1507 | 0 | switch (cipherSuite) { |
1508 | | |
1509 | 0 | #ifdef BUILD_TLS_SM4_GCM_SM3 |
1510 | 0 | case TLS_SM4_GCM_SM3 : |
1511 | 0 | specs->bulk_cipher_algorithm = wolfssl_sm4_gcm; |
1512 | 0 | specs->cipher_type = aead; |
1513 | 0 | specs->mac_algorithm = sm3_mac; |
1514 | 0 | specs->kea = any_kea; |
1515 | 0 | specs->sig_algo = any_sa_algo; |
1516 | 0 | specs->hash_size = WC_SM3_DIGEST_SIZE; |
1517 | 0 | specs->pad_size = PAD_SHA; |
1518 | 0 | specs->static_ecdh = 0; |
1519 | 0 | specs->key_size = SM4_KEY_SIZE; |
1520 | 0 | specs->block_size = SM4_BLOCK_SIZE; |
1521 | 0 | specs->iv_size = SM4_GCM_NONCE_SZ; |
1522 | 0 | specs->aead_mac_size = SM4_GCM_AUTH_SZ; |
1523 | |
|
1524 | 0 | break; |
1525 | 0 | #endif |
1526 | | |
1527 | 0 | #ifdef BUILD_TLS_SM4_CCM_SM3 |
1528 | 0 | case TLS_SM4_CCM_SM3 : |
1529 | 0 | specs->bulk_cipher_algorithm = wolfssl_sm4_ccm; |
1530 | 0 | specs->cipher_type = aead; |
1531 | 0 | specs->mac_algorithm = sm3_mac; |
1532 | 0 | specs->kea = any_kea; |
1533 | 0 | specs->sig_algo = any_sa_algo; |
1534 | 0 | specs->hash_size = WC_SM3_DIGEST_SIZE; |
1535 | 0 | specs->pad_size = PAD_SHA; |
1536 | 0 | specs->static_ecdh = 0; |
1537 | 0 | specs->key_size = SM4_KEY_SIZE; |
1538 | 0 | specs->block_size = SM4_BLOCK_SIZE; |
1539 | 0 | specs->iv_size = SM4_CCM_NONCE_SZ; |
1540 | 0 | specs->aead_mac_size = SM4_CCM_AUTH_SZ; |
1541 | |
|
1542 | 0 | break; |
1543 | 0 | #endif |
1544 | | |
1545 | | #ifdef BUILD_SSL_RSA_WITH_RC4_128_SHA |
1546 | | case SSL_RSA_WITH_RC4_128_SHA : |
1547 | | specs->bulk_cipher_algorithm = wolfssl_rc4; |
1548 | | specs->cipher_type = stream; |
1549 | | specs->mac_algorithm = sha_mac; |
1550 | | specs->kea = rsa_kea; |
1551 | | specs->sig_algo = rsa_sa_algo; |
1552 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
1553 | | specs->pad_size = PAD_SHA; |
1554 | | specs->static_ecdh = 0; |
1555 | | specs->key_size = RC4_KEY_SIZE; |
1556 | | specs->iv_size = 0; |
1557 | | specs->block_size = 0; |
1558 | | |
1559 | | break; |
1560 | | #endif |
1561 | | |
1562 | | #ifdef BUILD_SSL_RSA_WITH_RC4_128_MD5 |
1563 | | case SSL_RSA_WITH_RC4_128_MD5 : |
1564 | | specs->bulk_cipher_algorithm = wolfssl_rc4; |
1565 | | specs->cipher_type = stream; |
1566 | | specs->mac_algorithm = md5_mac; |
1567 | | specs->kea = rsa_kea; |
1568 | | specs->sig_algo = rsa_sa_algo; |
1569 | | specs->hash_size = WC_MD5_DIGEST_SIZE; |
1570 | | specs->pad_size = PAD_MD5; |
1571 | | specs->static_ecdh = 0; |
1572 | | specs->key_size = RC4_KEY_SIZE; |
1573 | | specs->iv_size = 0; |
1574 | | specs->block_size = 0; |
1575 | | |
1576 | | break; |
1577 | | #endif |
1578 | | |
1579 | | #ifdef BUILD_SSL_RSA_WITH_3DES_EDE_CBC_SHA |
1580 | | case SSL_RSA_WITH_3DES_EDE_CBC_SHA : |
1581 | | specs->bulk_cipher_algorithm = wolfssl_triple_des; |
1582 | | specs->cipher_type = block; |
1583 | | specs->mac_algorithm = sha_mac; |
1584 | | specs->kea = rsa_kea; |
1585 | | specs->sig_algo = rsa_sa_algo; |
1586 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
1587 | | specs->pad_size = PAD_SHA; |
1588 | | specs->static_ecdh = 0; |
1589 | | specs->key_size = DES3_KEY_SIZE; |
1590 | | specs->block_size = DES_BLOCK_SIZE; |
1591 | | #if defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) |
1592 | | specs->iv_size = DES_BLOCK_SIZE; |
1593 | | #else |
1594 | | specs->iv_size = DES_IV_SIZE; |
1595 | | #endif |
1596 | | |
1597 | | break; |
1598 | | #endif |
1599 | | |
1600 | | #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_SHA |
1601 | | case TLS_RSA_WITH_AES_128_CBC_SHA : |
1602 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
1603 | | specs->cipher_type = block; |
1604 | | specs->mac_algorithm = sha_mac; |
1605 | | specs->kea = rsa_kea; |
1606 | | specs->sig_algo = rsa_sa_algo; |
1607 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
1608 | | specs->pad_size = PAD_SHA; |
1609 | | specs->static_ecdh = 0; |
1610 | | specs->key_size = AES_128_KEY_SIZE; |
1611 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1612 | | specs->iv_size = AES_IV_SIZE; |
1613 | | |
1614 | | break; |
1615 | | #endif |
1616 | | |
1617 | | #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_SHA256 |
1618 | | case TLS_RSA_WITH_AES_128_CBC_SHA256 : |
1619 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
1620 | | specs->cipher_type = block; |
1621 | | specs->mac_algorithm = sha256_mac; |
1622 | | specs->kea = rsa_kea; |
1623 | | specs->sig_algo = rsa_sa_algo; |
1624 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1625 | | specs->pad_size = PAD_SHA; |
1626 | | specs->static_ecdh = 0; |
1627 | | specs->key_size = AES_128_KEY_SIZE; |
1628 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1629 | | specs->iv_size = AES_IV_SIZE; |
1630 | | |
1631 | | break; |
1632 | | #endif |
1633 | | |
1634 | | #ifdef BUILD_TLS_RSA_WITH_NULL_MD5 |
1635 | | case TLS_RSA_WITH_NULL_MD5 : |
1636 | | specs->bulk_cipher_algorithm = wolfssl_cipher_null; |
1637 | | specs->cipher_type = stream; |
1638 | | specs->mac_algorithm = md5_mac; |
1639 | | specs->kea = rsa_kea; |
1640 | | specs->sig_algo = rsa_sa_algo; |
1641 | | specs->hash_size = WC_MD5_DIGEST_SIZE; |
1642 | | specs->pad_size = PAD_MD5; |
1643 | | specs->static_ecdh = 0; |
1644 | | specs->key_size = 0; |
1645 | | specs->block_size = 0; |
1646 | | specs->iv_size = 0; |
1647 | | |
1648 | | break; |
1649 | | #endif |
1650 | | |
1651 | | #ifdef BUILD_TLS_RSA_WITH_NULL_SHA |
1652 | | case TLS_RSA_WITH_NULL_SHA : |
1653 | | specs->bulk_cipher_algorithm = wolfssl_cipher_null; |
1654 | | specs->cipher_type = stream; |
1655 | | specs->mac_algorithm = sha_mac; |
1656 | | specs->kea = rsa_kea; |
1657 | | specs->sig_algo = rsa_sa_algo; |
1658 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
1659 | | specs->pad_size = PAD_SHA; |
1660 | | specs->static_ecdh = 0; |
1661 | | specs->key_size = 0; |
1662 | | specs->block_size = 0; |
1663 | | specs->iv_size = 0; |
1664 | | |
1665 | | break; |
1666 | | #endif |
1667 | | |
1668 | | #ifdef BUILD_TLS_RSA_WITH_NULL_SHA256 |
1669 | | case TLS_RSA_WITH_NULL_SHA256 : |
1670 | | specs->bulk_cipher_algorithm = wolfssl_cipher_null; |
1671 | | specs->cipher_type = stream; |
1672 | | specs->mac_algorithm = sha256_mac; |
1673 | | specs->kea = rsa_kea; |
1674 | | specs->sig_algo = rsa_sa_algo; |
1675 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1676 | | specs->pad_size = PAD_SHA; |
1677 | | specs->static_ecdh = 0; |
1678 | | specs->key_size = 0; |
1679 | | specs->block_size = 0; |
1680 | | specs->iv_size = 0; |
1681 | | |
1682 | | break; |
1683 | | #endif |
1684 | | |
1685 | | #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_SHA |
1686 | | case TLS_RSA_WITH_AES_256_CBC_SHA : |
1687 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
1688 | | specs->cipher_type = block; |
1689 | | specs->mac_algorithm = sha_mac; |
1690 | | specs->kea = rsa_kea; |
1691 | | specs->sig_algo = rsa_sa_algo; |
1692 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
1693 | | specs->pad_size = PAD_SHA; |
1694 | | specs->static_ecdh = 0; |
1695 | | specs->key_size = AES_256_KEY_SIZE; |
1696 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1697 | | specs->iv_size = AES_IV_SIZE; |
1698 | | |
1699 | | break; |
1700 | | #endif |
1701 | | |
1702 | | #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_SHA256 |
1703 | | case TLS_RSA_WITH_AES_256_CBC_SHA256 : |
1704 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
1705 | | specs->cipher_type = block; |
1706 | | specs->mac_algorithm = sha256_mac; |
1707 | | specs->kea = rsa_kea; |
1708 | | specs->sig_algo = rsa_sa_algo; |
1709 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1710 | | specs->pad_size = PAD_SHA; |
1711 | | specs->static_ecdh = 0; |
1712 | | specs->key_size = AES_256_KEY_SIZE; |
1713 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1714 | | specs->iv_size = AES_IV_SIZE; |
1715 | | |
1716 | | break; |
1717 | | #endif |
1718 | | |
1719 | | #ifdef BUILD_TLS_PSK_WITH_AES_128_GCM_SHA256 |
1720 | | case TLS_PSK_WITH_AES_128_GCM_SHA256 : |
1721 | | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
1722 | | specs->cipher_type = aead; |
1723 | | specs->mac_algorithm = sha256_mac; |
1724 | | specs->kea = psk_kea; |
1725 | | specs->sig_algo = anonymous_sa_algo; |
1726 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1727 | | specs->pad_size = PAD_SHA; |
1728 | | specs->static_ecdh = 0; |
1729 | | specs->key_size = AES_128_KEY_SIZE; |
1730 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1731 | | specs->iv_size = AESGCM_IMP_IV_SZ; |
1732 | | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
1733 | | |
1734 | | if (opts != NULL) |
1735 | | opts->usingPSK_cipher = 1; |
1736 | | break; |
1737 | | #endif |
1738 | | |
1739 | | #ifdef BUILD_TLS_PSK_WITH_AES_256_GCM_SHA384 |
1740 | | case TLS_PSK_WITH_AES_256_GCM_SHA384 : |
1741 | | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
1742 | | specs->cipher_type = aead; |
1743 | | specs->mac_algorithm = sha384_mac; |
1744 | | specs->kea = psk_kea; |
1745 | | specs->sig_algo = anonymous_sa_algo; |
1746 | | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
1747 | | specs->pad_size = PAD_SHA; |
1748 | | specs->static_ecdh = 0; |
1749 | | specs->key_size = AES_256_KEY_SIZE; |
1750 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1751 | | specs->iv_size = AESGCM_IMP_IV_SZ; |
1752 | | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
1753 | | |
1754 | | if (opts != NULL) |
1755 | | opts->usingPSK_cipher = 1; |
1756 | | break; |
1757 | | #endif |
1758 | | |
1759 | | #ifdef BUILD_TLS_DH_anon_WITH_AES_256_GCM_SHA384 |
1760 | | case TLS_DH_anon_WITH_AES_256_GCM_SHA384: |
1761 | | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
1762 | | specs->cipher_type = aead; |
1763 | | specs->mac_algorithm = sha384_mac; |
1764 | | specs->kea = diffie_hellman_kea; |
1765 | | specs->sig_algo = anonymous_sa_algo; |
1766 | | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
1767 | | specs->pad_size = PAD_SHA; |
1768 | | specs->static_ecdh = 0; |
1769 | | specs->key_size = AES_256_KEY_SIZE; |
1770 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1771 | | specs->iv_size = AESGCM_IMP_IV_SZ; |
1772 | | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
1773 | | |
1774 | | if (opts != NULL) |
1775 | | opts->usingAnon_cipher = 1; |
1776 | | break; |
1777 | | #endif |
1778 | | |
1779 | | #ifdef BUILD_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 |
1780 | | case TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 : |
1781 | | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
1782 | | specs->cipher_type = aead; |
1783 | | specs->mac_algorithm = sha256_mac; |
1784 | | specs->kea = dhe_psk_kea; |
1785 | | specs->sig_algo = anonymous_sa_algo; |
1786 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1787 | | specs->pad_size = PAD_SHA; |
1788 | | specs->static_ecdh = 0; |
1789 | | specs->key_size = AES_128_KEY_SIZE; |
1790 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1791 | | specs->iv_size = AESGCM_IMP_IV_SZ; |
1792 | | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
1793 | | |
1794 | | if (opts != NULL) |
1795 | | opts->usingPSK_cipher = 1; |
1796 | | break; |
1797 | | #endif |
1798 | | |
1799 | | #ifdef BUILD_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 |
1800 | | case TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 : |
1801 | | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
1802 | | specs->cipher_type = aead; |
1803 | | specs->mac_algorithm = sha384_mac; |
1804 | | specs->kea = dhe_psk_kea; |
1805 | | specs->sig_algo = anonymous_sa_algo; |
1806 | | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
1807 | | specs->pad_size = PAD_SHA; |
1808 | | specs->static_ecdh = 0; |
1809 | | specs->key_size = AES_256_KEY_SIZE; |
1810 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1811 | | specs->iv_size = AESGCM_IMP_IV_SZ; |
1812 | | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
1813 | | |
1814 | | if (opts != NULL) |
1815 | | opts->usingPSK_cipher = 1; |
1816 | | break; |
1817 | | #endif |
1818 | | |
1819 | | #ifdef BUILD_TLS_PSK_WITH_AES_128_CBC_SHA256 |
1820 | | case TLS_PSK_WITH_AES_128_CBC_SHA256 : |
1821 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
1822 | | specs->cipher_type = block; |
1823 | | specs->mac_algorithm = sha256_mac; |
1824 | | specs->kea = psk_kea; |
1825 | | specs->sig_algo = anonymous_sa_algo; |
1826 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1827 | | specs->pad_size = PAD_SHA; |
1828 | | specs->static_ecdh = 0; |
1829 | | specs->key_size = AES_128_KEY_SIZE; |
1830 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1831 | | specs->iv_size = AES_IV_SIZE; |
1832 | | |
1833 | | if (opts != NULL) |
1834 | | opts->usingPSK_cipher = 1; |
1835 | | break; |
1836 | | #endif |
1837 | | |
1838 | | #ifdef BUILD_TLS_PSK_WITH_AES_256_CBC_SHA384 |
1839 | | case TLS_PSK_WITH_AES_256_CBC_SHA384 : |
1840 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
1841 | | specs->cipher_type = block; |
1842 | | specs->mac_algorithm = sha384_mac; |
1843 | | specs->kea = psk_kea; |
1844 | | specs->sig_algo = anonymous_sa_algo; |
1845 | | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
1846 | | specs->pad_size = PAD_SHA; |
1847 | | specs->static_ecdh = 0; |
1848 | | specs->key_size = AES_256_KEY_SIZE; |
1849 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1850 | | specs->iv_size = AES_IV_SIZE; |
1851 | | |
1852 | | if (opts != NULL) |
1853 | | opts->usingPSK_cipher = 1; |
1854 | | break; |
1855 | | #endif |
1856 | | |
1857 | | #ifdef BUILD_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 |
1858 | | case TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 : |
1859 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
1860 | | specs->cipher_type = block; |
1861 | | specs->mac_algorithm = sha256_mac; |
1862 | | specs->kea = dhe_psk_kea; |
1863 | | specs->sig_algo = anonymous_sa_algo; |
1864 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1865 | | specs->pad_size = PAD_SHA; |
1866 | | specs->static_ecdh = 0; |
1867 | | specs->key_size = AES_128_KEY_SIZE; |
1868 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1869 | | specs->iv_size = AES_IV_SIZE; |
1870 | | |
1871 | | if (opts != NULL) |
1872 | | opts->usingPSK_cipher = 1; |
1873 | | break; |
1874 | | #endif |
1875 | | |
1876 | | #ifdef BUILD_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 |
1877 | | case TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 : |
1878 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
1879 | | specs->cipher_type = block; |
1880 | | specs->mac_algorithm = sha384_mac; |
1881 | | specs->kea = dhe_psk_kea; |
1882 | | specs->sig_algo = anonymous_sa_algo; |
1883 | | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
1884 | | specs->pad_size = PAD_SHA; |
1885 | | specs->static_ecdh = 0; |
1886 | | specs->key_size = AES_256_KEY_SIZE; |
1887 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1888 | | specs->iv_size = AES_IV_SIZE; |
1889 | | |
1890 | | if (opts != NULL) |
1891 | | opts->usingPSK_cipher = 1; |
1892 | | break; |
1893 | | #endif |
1894 | | |
1895 | | #ifdef BUILD_TLS_PSK_WITH_AES_128_CBC_SHA |
1896 | | case TLS_PSK_WITH_AES_128_CBC_SHA : |
1897 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
1898 | | specs->cipher_type = block; |
1899 | | specs->mac_algorithm = sha_mac; |
1900 | | specs->kea = psk_kea; |
1901 | | specs->sig_algo = anonymous_sa_algo; |
1902 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
1903 | | specs->pad_size = PAD_SHA; |
1904 | | specs->static_ecdh = 0; |
1905 | | specs->key_size = AES_128_KEY_SIZE; |
1906 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1907 | | specs->iv_size = AES_IV_SIZE; |
1908 | | |
1909 | | if (opts != NULL) |
1910 | | opts->usingPSK_cipher = 1; |
1911 | | break; |
1912 | | #endif |
1913 | | |
1914 | | #ifdef BUILD_TLS_PSK_WITH_AES_256_CBC_SHA |
1915 | | case TLS_PSK_WITH_AES_256_CBC_SHA : |
1916 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
1917 | | specs->cipher_type = block; |
1918 | | specs->mac_algorithm = sha_mac; |
1919 | | specs->kea = psk_kea; |
1920 | | specs->sig_algo = anonymous_sa_algo; |
1921 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
1922 | | specs->pad_size = PAD_SHA; |
1923 | | specs->static_ecdh = 0; |
1924 | | specs->key_size = AES_256_KEY_SIZE; |
1925 | | specs->block_size = WC_AES_BLOCK_SIZE; |
1926 | | specs->iv_size = AES_IV_SIZE; |
1927 | | |
1928 | | if (opts != NULL) |
1929 | | opts->usingPSK_cipher = 1; |
1930 | | break; |
1931 | | #endif |
1932 | | |
1933 | | #ifdef BUILD_TLS_PSK_WITH_NULL_SHA256 |
1934 | | case TLS_PSK_WITH_NULL_SHA256 : |
1935 | | specs->bulk_cipher_algorithm = wolfssl_cipher_null; |
1936 | | specs->cipher_type = stream; |
1937 | | specs->mac_algorithm = sha256_mac; |
1938 | | specs->kea = psk_kea; |
1939 | | specs->sig_algo = anonymous_sa_algo; |
1940 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1941 | | specs->pad_size = PAD_SHA; |
1942 | | specs->static_ecdh = 0; |
1943 | | specs->key_size = 0; |
1944 | | specs->block_size = 0; |
1945 | | specs->iv_size = 0; |
1946 | | |
1947 | | if (opts != NULL) |
1948 | | opts->usingPSK_cipher = 1; |
1949 | | break; |
1950 | | #endif |
1951 | | |
1952 | | #ifdef BUILD_TLS_PSK_WITH_NULL_SHA384 |
1953 | | case TLS_PSK_WITH_NULL_SHA384 : |
1954 | | specs->bulk_cipher_algorithm = wolfssl_cipher_null; |
1955 | | specs->cipher_type = stream; |
1956 | | specs->mac_algorithm = sha384_mac; |
1957 | | specs->kea = psk_kea; |
1958 | | specs->sig_algo = anonymous_sa_algo; |
1959 | | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
1960 | | specs->pad_size = PAD_SHA; |
1961 | | specs->static_ecdh = 0; |
1962 | | specs->key_size = 0; |
1963 | | specs->block_size = 0; |
1964 | | specs->iv_size = 0; |
1965 | | |
1966 | | if (opts != NULL) |
1967 | | opts->usingPSK_cipher = 1; |
1968 | | break; |
1969 | | #endif |
1970 | | |
1971 | | #ifdef BUILD_TLS_PSK_WITH_NULL_SHA |
1972 | | case TLS_PSK_WITH_NULL_SHA : |
1973 | | specs->bulk_cipher_algorithm = wolfssl_cipher_null; |
1974 | | specs->cipher_type = stream; |
1975 | | specs->mac_algorithm = sha_mac; |
1976 | | specs->kea = psk_kea; |
1977 | | specs->sig_algo = anonymous_sa_algo; |
1978 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
1979 | | specs->pad_size = PAD_SHA; |
1980 | | specs->static_ecdh = 0; |
1981 | | specs->key_size = 0; |
1982 | | specs->block_size = 0; |
1983 | | specs->iv_size = 0; |
1984 | | |
1985 | | if (opts != NULL) |
1986 | | opts->usingPSK_cipher = 1; |
1987 | | break; |
1988 | | #endif |
1989 | | |
1990 | | #ifdef BUILD_TLS_DHE_PSK_WITH_NULL_SHA256 |
1991 | | case TLS_DHE_PSK_WITH_NULL_SHA256 : |
1992 | | specs->bulk_cipher_algorithm = wolfssl_cipher_null; |
1993 | | specs->cipher_type = stream; |
1994 | | specs->mac_algorithm = sha256_mac; |
1995 | | specs->kea = dhe_psk_kea; |
1996 | | specs->sig_algo = anonymous_sa_algo; |
1997 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
1998 | | specs->pad_size = PAD_SHA; |
1999 | | specs->static_ecdh = 0; |
2000 | | specs->key_size = 0; |
2001 | | specs->block_size = 0; |
2002 | | specs->iv_size = 0; |
2003 | | |
2004 | | if (opts != NULL) |
2005 | | opts->usingPSK_cipher = 1; |
2006 | | break; |
2007 | | #endif |
2008 | | |
2009 | | #ifdef BUILD_TLS_DHE_PSK_WITH_NULL_SHA384 |
2010 | | case TLS_DHE_PSK_WITH_NULL_SHA384 : |
2011 | | specs->bulk_cipher_algorithm = wolfssl_cipher_null; |
2012 | | specs->cipher_type = stream; |
2013 | | specs->mac_algorithm = sha384_mac; |
2014 | | specs->kea = dhe_psk_kea; |
2015 | | specs->sig_algo = anonymous_sa_algo; |
2016 | | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
2017 | | specs->pad_size = PAD_SHA; |
2018 | | specs->static_ecdh = 0; |
2019 | | specs->key_size = 0; |
2020 | | specs->block_size = 0; |
2021 | | specs->iv_size = 0; |
2022 | | |
2023 | | if (opts != NULL) |
2024 | | opts->usingPSK_cipher = 1; |
2025 | | break; |
2026 | | #endif |
2027 | | |
2028 | 0 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 |
2029 | 0 | case TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 : |
2030 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes; |
2031 | 0 | specs->cipher_type = block; |
2032 | 0 | specs->mac_algorithm = sha256_mac; |
2033 | 0 | specs->kea = diffie_hellman_kea; |
2034 | 0 | specs->sig_algo = rsa_sa_algo; |
2035 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
2036 | 0 | specs->pad_size = PAD_SHA; |
2037 | 0 | specs->static_ecdh = 0; |
2038 | 0 | specs->key_size = AES_128_KEY_SIZE; |
2039 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
2040 | 0 | specs->iv_size = AES_IV_SIZE; |
2041 | |
|
2042 | 0 | break; |
2043 | 0 | #endif |
2044 | | |
2045 | | #ifdef BUILD_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA |
2046 | | case TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA : |
2047 | | specs->bulk_cipher_algorithm = wolfssl_triple_des; |
2048 | | specs->cipher_type = block; |
2049 | | specs->mac_algorithm = sha_mac; |
2050 | | specs->kea = diffie_hellman_kea; |
2051 | | specs->sig_algo = rsa_sa_algo; |
2052 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
2053 | | specs->pad_size = PAD_SHA; |
2054 | | specs->static_ecdh = 0; |
2055 | | specs->key_size = DES3_KEY_SIZE; |
2056 | | specs->block_size = DES_BLOCK_SIZE; |
2057 | | specs->iv_size = DES_IV_SIZE; |
2058 | | |
2059 | | break; |
2060 | | #endif |
2061 | | |
2062 | 0 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 |
2063 | 0 | case TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 : |
2064 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes; |
2065 | 0 | specs->cipher_type = block; |
2066 | 0 | specs->mac_algorithm = sha256_mac; |
2067 | 0 | specs->kea = diffie_hellman_kea; |
2068 | 0 | specs->sig_algo = rsa_sa_algo; |
2069 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
2070 | 0 | specs->pad_size = PAD_SHA; |
2071 | 0 | specs->static_ecdh = 0; |
2072 | 0 | specs->key_size = AES_256_KEY_SIZE; |
2073 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
2074 | 0 | specs->iv_size = AES_IV_SIZE; |
2075 | |
|
2076 | 0 | break; |
2077 | 0 | #endif |
2078 | | |
2079 | 0 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA |
2080 | 0 | case TLS_DHE_RSA_WITH_AES_128_CBC_SHA : |
2081 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes; |
2082 | 0 | specs->cipher_type = block; |
2083 | 0 | specs->mac_algorithm = sha_mac; |
2084 | 0 | specs->kea = diffie_hellman_kea; |
2085 | 0 | specs->sig_algo = rsa_sa_algo; |
2086 | 0 | specs->hash_size = WC_SHA_DIGEST_SIZE; |
2087 | 0 | specs->pad_size = PAD_SHA; |
2088 | 0 | specs->static_ecdh = 0; |
2089 | 0 | specs->key_size = AES_128_KEY_SIZE; |
2090 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
2091 | 0 | specs->iv_size = AES_IV_SIZE; |
2092 | |
|
2093 | 0 | break; |
2094 | 0 | #endif |
2095 | | |
2096 | 0 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA |
2097 | 0 | case TLS_DHE_RSA_WITH_AES_256_CBC_SHA : |
2098 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes; |
2099 | 0 | specs->cipher_type = block; |
2100 | 0 | specs->mac_algorithm = sha_mac; |
2101 | 0 | specs->kea = diffie_hellman_kea; |
2102 | 0 | specs->sig_algo = rsa_sa_algo; |
2103 | 0 | specs->hash_size = WC_SHA_DIGEST_SIZE; |
2104 | 0 | specs->pad_size = PAD_SHA; |
2105 | 0 | specs->static_ecdh = 0; |
2106 | 0 | specs->key_size = AES_256_KEY_SIZE; |
2107 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
2108 | 0 | specs->iv_size = AES_IV_SIZE; |
2109 | |
|
2110 | 0 | break; |
2111 | 0 | #endif |
2112 | | |
2113 | | #ifdef BUILD_TLS_RSA_WITH_AES_128_GCM_SHA256 |
2114 | | case TLS_RSA_WITH_AES_128_GCM_SHA256 : |
2115 | | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
2116 | | specs->cipher_type = aead; |
2117 | | specs->mac_algorithm = sha256_mac; |
2118 | | specs->kea = rsa_kea; |
2119 | | specs->sig_algo = rsa_sa_algo; |
2120 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
2121 | | specs->pad_size = PAD_SHA; |
2122 | | specs->static_ecdh = 0; |
2123 | | specs->key_size = AES_128_KEY_SIZE; |
2124 | | specs->block_size = WC_AES_BLOCK_SIZE; |
2125 | | specs->iv_size = AESGCM_IMP_IV_SZ; |
2126 | | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
2127 | | |
2128 | | break; |
2129 | | #endif |
2130 | | |
2131 | | #ifdef BUILD_TLS_RSA_WITH_AES_256_GCM_SHA384 |
2132 | | case TLS_RSA_WITH_AES_256_GCM_SHA384 : |
2133 | | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
2134 | | specs->cipher_type = aead; |
2135 | | specs->mac_algorithm = sha384_mac; |
2136 | | specs->kea = rsa_kea; |
2137 | | specs->sig_algo = rsa_sa_algo; |
2138 | | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
2139 | | specs->pad_size = PAD_SHA; |
2140 | | specs->static_ecdh = 0; |
2141 | | specs->key_size = AES_256_KEY_SIZE; |
2142 | | specs->block_size = WC_AES_BLOCK_SIZE; |
2143 | | specs->iv_size = AESGCM_IMP_IV_SZ; |
2144 | | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
2145 | | |
2146 | | break; |
2147 | | #endif |
2148 | | |
2149 | 0 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 |
2150 | 0 | case TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 : |
2151 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
2152 | 0 | specs->cipher_type = aead; |
2153 | 0 | specs->mac_algorithm = sha256_mac; |
2154 | 0 | specs->kea = diffie_hellman_kea; |
2155 | 0 | specs->sig_algo = rsa_sa_algo; |
2156 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
2157 | 0 | specs->pad_size = PAD_SHA; |
2158 | 0 | specs->static_ecdh = 0; |
2159 | 0 | specs->key_size = AES_128_KEY_SIZE; |
2160 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
2161 | 0 | specs->iv_size = AESGCM_IMP_IV_SZ; |
2162 | 0 | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
2163 | |
|
2164 | 0 | break; |
2165 | 0 | #endif |
2166 | | |
2167 | 0 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 |
2168 | 0 | case TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 : |
2169 | 0 | specs->bulk_cipher_algorithm = wolfssl_aes_gcm; |
2170 | 0 | specs->cipher_type = aead; |
2171 | 0 | specs->mac_algorithm = sha384_mac; |
2172 | 0 | specs->kea = diffie_hellman_kea; |
2173 | 0 | specs->sig_algo = rsa_sa_algo; |
2174 | 0 | specs->hash_size = WC_SHA384_DIGEST_SIZE; |
2175 | 0 | specs->pad_size = PAD_SHA; |
2176 | 0 | specs->static_ecdh = 0; |
2177 | 0 | specs->key_size = AES_256_KEY_SIZE; |
2178 | 0 | specs->block_size = WC_AES_BLOCK_SIZE; |
2179 | 0 | specs->iv_size = AESGCM_IMP_IV_SZ; |
2180 | 0 | specs->aead_mac_size = AES_GCM_AUTH_SZ; |
2181 | |
|
2182 | 0 | break; |
2183 | 0 | #endif |
2184 | | |
2185 | | #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA |
2186 | | case TLS_RSA_WITH_CAMELLIA_128_CBC_SHA : |
2187 | | specs->bulk_cipher_algorithm = wolfssl_camellia; |
2188 | | specs->cipher_type = block; |
2189 | | specs->mac_algorithm = sha_mac; |
2190 | | specs->kea = rsa_kea; |
2191 | | specs->sig_algo = rsa_sa_algo; |
2192 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
2193 | | specs->pad_size = PAD_SHA; |
2194 | | specs->static_ecdh = 0; |
2195 | | specs->key_size = CAMELLIA_128_KEY_SIZE; |
2196 | | specs->block_size = WC_CAMELLIA_BLOCK_SIZE; |
2197 | | specs->iv_size = CAMELLIA_IV_SIZE; |
2198 | | |
2199 | | break; |
2200 | | #endif |
2201 | | |
2202 | | #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA |
2203 | | case TLS_RSA_WITH_CAMELLIA_256_CBC_SHA : |
2204 | | specs->bulk_cipher_algorithm = wolfssl_camellia; |
2205 | | specs->cipher_type = block; |
2206 | | specs->mac_algorithm = sha_mac; |
2207 | | specs->kea = rsa_kea; |
2208 | | specs->sig_algo = rsa_sa_algo; |
2209 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
2210 | | specs->pad_size = PAD_SHA; |
2211 | | specs->static_ecdh = 0; |
2212 | | specs->key_size = CAMELLIA_256_KEY_SIZE; |
2213 | | specs->block_size = WC_CAMELLIA_BLOCK_SIZE; |
2214 | | specs->iv_size = CAMELLIA_IV_SIZE; |
2215 | | |
2216 | | break; |
2217 | | #endif |
2218 | | |
2219 | | #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 |
2220 | | case TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 : |
2221 | | specs->bulk_cipher_algorithm = wolfssl_camellia; |
2222 | | specs->cipher_type = block; |
2223 | | specs->mac_algorithm = sha256_mac; |
2224 | | specs->kea = rsa_kea; |
2225 | | specs->sig_algo = rsa_sa_algo; |
2226 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
2227 | | specs->pad_size = PAD_SHA; |
2228 | | specs->static_ecdh = 0; |
2229 | | specs->key_size = CAMELLIA_128_KEY_SIZE; |
2230 | | specs->block_size = WC_CAMELLIA_BLOCK_SIZE; |
2231 | | specs->iv_size = CAMELLIA_IV_SIZE; |
2232 | | |
2233 | | break; |
2234 | | #endif |
2235 | | |
2236 | | #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 |
2237 | | case TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 : |
2238 | | specs->bulk_cipher_algorithm = wolfssl_camellia; |
2239 | | specs->cipher_type = block; |
2240 | | specs->mac_algorithm = sha256_mac; |
2241 | | specs->kea = rsa_kea; |
2242 | | specs->sig_algo = rsa_sa_algo; |
2243 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
2244 | | specs->pad_size = PAD_SHA; |
2245 | | specs->static_ecdh = 0; |
2246 | | specs->key_size = CAMELLIA_256_KEY_SIZE; |
2247 | | specs->block_size = WC_CAMELLIA_BLOCK_SIZE; |
2248 | | specs->iv_size = CAMELLIA_IV_SIZE; |
2249 | | |
2250 | | break; |
2251 | | #endif |
2252 | | |
2253 | 0 | #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA |
2254 | 0 | case TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA : |
2255 | 0 | specs->bulk_cipher_algorithm = wolfssl_camellia; |
2256 | 0 | specs->cipher_type = block; |
2257 | 0 | specs->mac_algorithm = sha_mac; |
2258 | 0 | specs->kea = diffie_hellman_kea; |
2259 | 0 | specs->sig_algo = rsa_sa_algo; |
2260 | 0 | specs->hash_size = WC_SHA_DIGEST_SIZE; |
2261 | 0 | specs->pad_size = PAD_SHA; |
2262 | 0 | specs->static_ecdh = 0; |
2263 | 0 | specs->key_size = CAMELLIA_128_KEY_SIZE; |
2264 | 0 | specs->block_size = WC_CAMELLIA_BLOCK_SIZE; |
2265 | 0 | specs->iv_size = CAMELLIA_IV_SIZE; |
2266 | |
|
2267 | 0 | break; |
2268 | 0 | #endif |
2269 | | |
2270 | 0 | #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA |
2271 | 0 | case TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA : |
2272 | 0 | specs->bulk_cipher_algorithm = wolfssl_camellia; |
2273 | 0 | specs->cipher_type = block; |
2274 | 0 | specs->mac_algorithm = sha_mac; |
2275 | 0 | specs->kea = diffie_hellman_kea; |
2276 | 0 | specs->sig_algo = rsa_sa_algo; |
2277 | 0 | specs->hash_size = WC_SHA_DIGEST_SIZE; |
2278 | 0 | specs->pad_size = PAD_SHA; |
2279 | 0 | specs->static_ecdh = 0; |
2280 | 0 | specs->key_size = CAMELLIA_256_KEY_SIZE; |
2281 | 0 | specs->block_size = WC_CAMELLIA_BLOCK_SIZE; |
2282 | 0 | specs->iv_size = CAMELLIA_IV_SIZE; |
2283 | |
|
2284 | 0 | break; |
2285 | 0 | #endif |
2286 | | |
2287 | 0 | #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 |
2288 | 0 | case TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 : |
2289 | 0 | specs->bulk_cipher_algorithm = wolfssl_camellia; |
2290 | 0 | specs->cipher_type = block; |
2291 | 0 | specs->mac_algorithm = sha256_mac; |
2292 | 0 | specs->kea = diffie_hellman_kea; |
2293 | 0 | specs->sig_algo = rsa_sa_algo; |
2294 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
2295 | 0 | specs->pad_size = PAD_SHA; |
2296 | 0 | specs->static_ecdh = 0; |
2297 | 0 | specs->key_size = CAMELLIA_128_KEY_SIZE; |
2298 | 0 | specs->block_size = WC_CAMELLIA_BLOCK_SIZE; |
2299 | 0 | specs->iv_size = CAMELLIA_IV_SIZE; |
2300 | |
|
2301 | 0 | break; |
2302 | 0 | #endif |
2303 | | |
2304 | 0 | #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 |
2305 | 0 | case TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 : |
2306 | 0 | specs->bulk_cipher_algorithm = wolfssl_camellia; |
2307 | 0 | specs->cipher_type = block; |
2308 | 0 | specs->mac_algorithm = sha256_mac; |
2309 | 0 | specs->kea = diffie_hellman_kea; |
2310 | 0 | specs->sig_algo = rsa_sa_algo; |
2311 | 0 | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
2312 | 0 | specs->pad_size = PAD_SHA; |
2313 | 0 | specs->static_ecdh = 0; |
2314 | 0 | specs->key_size = CAMELLIA_256_KEY_SIZE; |
2315 | 0 | specs->block_size = WC_CAMELLIA_BLOCK_SIZE; |
2316 | 0 | specs->iv_size = CAMELLIA_IV_SIZE; |
2317 | |
|
2318 | 0 | break; |
2319 | 0 | #endif |
2320 | | |
2321 | | #ifdef BUILD_TLS_DH_anon_WITH_AES_128_CBC_SHA |
2322 | | case TLS_DH_anon_WITH_AES_128_CBC_SHA : |
2323 | | specs->bulk_cipher_algorithm = wolfssl_aes; |
2324 | | specs->cipher_type = block; |
2325 | | specs->mac_algorithm = sha_mac; |
2326 | | specs->kea = diffie_hellman_kea; |
2327 | | specs->sig_algo = anonymous_sa_algo; |
2328 | | specs->hash_size = WC_SHA_DIGEST_SIZE; |
2329 | | specs->pad_size = PAD_SHA; |
2330 | | specs->static_ecdh = 0; |
2331 | | specs->key_size = AES_128_KEY_SIZE; |
2332 | | specs->block_size = WC_AES_BLOCK_SIZE; |
2333 | | specs->iv_size = AES_IV_SIZE; |
2334 | | |
2335 | | if (opts != NULL) |
2336 | | opts->usingAnon_cipher = 1; |
2337 | | break; |
2338 | | #endif |
2339 | | |
2340 | | #ifdef BUILD_WDM_WITH_NULL_SHA256 |
2341 | | case WDM_WITH_NULL_SHA256 : |
2342 | | specs->bulk_cipher_algorithm = wolfssl_cipher_null; |
2343 | | specs->cipher_type = stream; |
2344 | | specs->mac_algorithm = sha256_mac; |
2345 | | specs->kea = no_kea; |
2346 | | specs->sig_algo = anonymous_sa_algo; |
2347 | | specs->hash_size = WC_SHA256_DIGEST_SIZE; |
2348 | | specs->pad_size = PAD_SHA; |
2349 | | |
2350 | | break; |
2351 | | #endif |
2352 | | |
2353 | 0 | default: |
2354 | 0 | WOLFSSL_MSG("Unsupported cipher suite, SetCipherSpecs"); |
2355 | 0 | WOLFSSL_ERROR_VERBOSE(UNSUPPORTED_SUITE); |
2356 | 0 | return UNSUPPORTED_SUITE; |
2357 | 0 | } /* switch */ |
2358 | 0 | } /* if ECC / Normal suites else */ |
2359 | | |
2360 | 0 | if (specs->sig_algo == anonymous_sa_algo && opts != NULL) { |
2361 | | /* CLIENT/SERVER: No peer authentication to be performed. */ |
2362 | 0 | opts->peerAuthGood = 1; |
2363 | 0 | } |
2364 | |
|
2365 | 0 | return 0; |
2366 | 0 | } |
2367 | | |
2368 | | |
2369 | | enum KeyStuff { |
2370 | | MASTER_ROUNDS = 3, |
2371 | | PREFIX = 3, /* up to three letters for master prefix */ |
2372 | | KEY_PREFIX = 9 /* up to 9 prefix letters for key rounds */ |
2373 | | |
2374 | | |
2375 | | }; |
2376 | | |
2377 | | #ifndef NO_OLD_TLS |
2378 | | /* true or false, zero for error */ |
2379 | | static int SetPrefix(byte* sha_input, int idx) |
2380 | | { |
2381 | | switch (idx) { |
2382 | | case 0: |
2383 | | XMEMCPY(sha_input, "A", 1); |
2384 | | break; |
2385 | | case 1: |
2386 | | XMEMCPY(sha_input, "BB", 2); |
2387 | | break; |
2388 | | case 2: |
2389 | | XMEMCPY(sha_input, "CCC", 3); |
2390 | | break; |
2391 | | case 3: |
2392 | | XMEMCPY(sha_input, "DDDD", 4); |
2393 | | break; |
2394 | | case 4: |
2395 | | XMEMCPY(sha_input, "EEEEE", 5); |
2396 | | break; |
2397 | | case 5: |
2398 | | XMEMCPY(sha_input, "FFFFFF", 6); |
2399 | | break; |
2400 | | case 6: |
2401 | | XMEMCPY(sha_input, "GGGGGGG", 7); |
2402 | | break; |
2403 | | case 7: |
2404 | | XMEMCPY(sha_input, "HHHHHHHH", 8); |
2405 | | break; |
2406 | | case 8: |
2407 | | XMEMCPY(sha_input, "IIIIIIIII", 9); |
2408 | | break; |
2409 | | default: |
2410 | | WOLFSSL_MSG("Set Prefix error, bad input"); |
2411 | | return 0; |
2412 | | } |
2413 | | return 1; |
2414 | | } |
2415 | | #endif |
2416 | | |
2417 | | |
2418 | | int SetKeys(Ciphers* enc, Ciphers* dec, Keys* keys, CipherSpecs* specs, |
2419 | | int side, void* heap, int devId, WC_RNG* rng, int tls13) |
2420 | | { |
2421 | | (void)rng; |
2422 | | (void)tls13; |
2423 | | |
2424 | | #ifdef BUILD_ARC4 |
2425 | | if (specs->bulk_cipher_algorithm == wolfssl_rc4) { |
2426 | | word32 sz = specs->key_size; |
2427 | | if (enc && enc->arc4 == NULL) { |
2428 | | enc->arc4 = (Arc4*)XMALLOC(sizeof(Arc4), heap, DYNAMIC_TYPE_CIPHER); |
2429 | | if (enc->arc4 == NULL) |
2430 | | return MEMORY_E; |
2431 | | } |
2432 | | if (dec && dec->arc4 == NULL) { |
2433 | | dec->arc4 = (Arc4*)XMALLOC(sizeof(Arc4), heap, DYNAMIC_TYPE_CIPHER); |
2434 | | if (dec->arc4 == NULL) |
2435 | | return MEMORY_E; |
2436 | | } |
2437 | | |
2438 | | if (enc) { |
2439 | | if (wc_Arc4Init(enc->arc4, heap, devId) != 0) { |
2440 | | WOLFSSL_MSG("Arc4Init failed in SetKeys"); |
2441 | | return ASYNC_INIT_E; |
2442 | | } |
2443 | | } |
2444 | | if (dec) { |
2445 | | if (wc_Arc4Init(dec->arc4, heap, devId) != 0) { |
2446 | | WOLFSSL_MSG("Arc4Init failed in SetKeys"); |
2447 | | return ASYNC_INIT_E; |
2448 | | } |
2449 | | } |
2450 | | |
2451 | | if (side == WOLFSSL_CLIENT_END) { |
2452 | | if (enc) |
2453 | | wc_Arc4SetKey(enc->arc4, keys->client_write_key, sz); |
2454 | | if (dec) |
2455 | | wc_Arc4SetKey(dec->arc4, keys->server_write_key, sz); |
2456 | | } |
2457 | | else { |
2458 | | if (enc) |
2459 | | wc_Arc4SetKey(enc->arc4, keys->server_write_key, sz); |
2460 | | if (dec) |
2461 | | wc_Arc4SetKey(dec->arc4, keys->client_write_key, sz); |
2462 | | } |
2463 | | if (enc) |
2464 | | enc->setup = 1; |
2465 | | if (dec) |
2466 | | dec->setup = 1; |
2467 | | } |
2468 | | #endif /* BUILD_ARC4 */ |
2469 | | |
2470 | | |
2471 | | #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(NO_CHAPOL_AEAD) |
2472 | | /* Check that the max implicit iv size is sufficient */ |
2473 | | #if (AEAD_MAX_IMP_SZ < 12) /* CHACHA20_IMP_IV_SZ */ |
2474 | | #error AEAD_MAX_IMP_SZ is too small for ChaCha20 |
2475 | | #endif |
2476 | | #if (MAX_WRITE_IV_SZ < 12) /* CHACHA20_IMP_IV_SZ */ |
2477 | | #error MAX_WRITE_IV_SZ is too small for ChaCha20 |
2478 | | #endif |
2479 | | |
2480 | | if (specs->bulk_cipher_algorithm == wolfssl_chacha) { |
2481 | | int chachaRet; |
2482 | | if (enc && enc->chacha == NULL) |
2483 | | enc->chacha = |
2484 | | (ChaCha*)XMALLOC(sizeof(ChaCha), heap, DYNAMIC_TYPE_CIPHER); |
2485 | | if (enc && enc->chacha == NULL) |
2486 | | return MEMORY_E; |
2487 | | #ifdef WOLFSSL_CHECK_MEM_ZERO |
2488 | | if (enc) { |
2489 | | wc_MemZero_Add("SSL keys enc chacha", enc->chacha, sizeof(ChaCha)); |
2490 | | } |
2491 | | #endif |
2492 | | if (dec && dec->chacha == NULL) |
2493 | | dec->chacha = |
2494 | | (ChaCha*)XMALLOC(sizeof(ChaCha), heap, DYNAMIC_TYPE_CIPHER); |
2495 | | if (dec && dec->chacha == NULL) |
2496 | | return MEMORY_E; |
2497 | | #ifdef WOLFSSL_CHECK_MEM_ZERO |
2498 | | if (dec) { |
2499 | | wc_MemZero_Add("SSL keys dec chacha", dec->chacha, sizeof(ChaCha)); |
2500 | | } |
2501 | | #endif |
2502 | | if (side == WOLFSSL_CLIENT_END) { |
2503 | | if (enc) { |
2504 | | chachaRet = wc_Chacha_SetKey_ex(enc->chacha, |
2505 | | keys->client_write_key, |
2506 | | specs->key_size, heap, devId); |
2507 | | XMEMCPY(keys->aead_enc_imp_IV, keys->client_write_IV, |
2508 | | CHACHA20_IMP_IV_SZ); |
2509 | | if (chachaRet != 0) return chachaRet; |
2510 | | } |
2511 | | if (dec) { |
2512 | | chachaRet = wc_Chacha_SetKey_ex(dec->chacha, |
2513 | | keys->server_write_key, |
2514 | | specs->key_size, heap, devId); |
2515 | | XMEMCPY(keys->aead_dec_imp_IV, keys->server_write_IV, |
2516 | | CHACHA20_IMP_IV_SZ); |
2517 | | if (chachaRet != 0) return chachaRet; |
2518 | | } |
2519 | | } |
2520 | | else { |
2521 | | if (enc) { |
2522 | | chachaRet = wc_Chacha_SetKey_ex(enc->chacha, |
2523 | | keys->server_write_key, |
2524 | | specs->key_size, heap, devId); |
2525 | | XMEMCPY(keys->aead_enc_imp_IV, keys->server_write_IV, |
2526 | | CHACHA20_IMP_IV_SZ); |
2527 | | if (chachaRet != 0) return chachaRet; |
2528 | | } |
2529 | | if (dec) { |
2530 | | chachaRet = wc_Chacha_SetKey_ex(dec->chacha, |
2531 | | keys->client_write_key, |
2532 | | specs->key_size, heap, devId); |
2533 | | XMEMCPY(keys->aead_dec_imp_IV, keys->client_write_IV, |
2534 | | CHACHA20_IMP_IV_SZ); |
2535 | | if (chachaRet != 0) return chachaRet; |
2536 | | } |
2537 | | } |
2538 | | |
2539 | | if (enc) |
2540 | | enc->setup = 1; |
2541 | | if (dec) |
2542 | | dec->setup = 1; |
2543 | | } |
2544 | | #endif /* HAVE_CHACHA && HAVE_POLY1305 */ |
2545 | | |
2546 | | #ifdef BUILD_DES3 |
2547 | | /* check that buffer sizes are sufficient */ |
2548 | | #if (MAX_WRITE_IV_SZ < 8) /* DES_IV_SIZE */ |
2549 | | #error MAX_WRITE_IV_SZ too small for 3DES |
2550 | | #endif |
2551 | | |
2552 | | if (specs->bulk_cipher_algorithm == wolfssl_triple_des) { |
2553 | | int desRet = 0; |
2554 | | |
2555 | | if (enc) { |
2556 | | if (enc->des3 == NULL) |
2557 | | enc->des3 = (Des3*)XMALLOC(sizeof(Des3), heap, DYNAMIC_TYPE_CIPHER); |
2558 | | if (enc->des3 == NULL) |
2559 | | return MEMORY_E; |
2560 | | XMEMSET(enc->des3, 0, sizeof(Des3)); |
2561 | | } |
2562 | | if (dec) { |
2563 | | if (dec->des3 == NULL) |
2564 | | dec->des3 = (Des3*)XMALLOC(sizeof(Des3), heap, DYNAMIC_TYPE_CIPHER); |
2565 | | if (dec->des3 == NULL) |
2566 | | return MEMORY_E; |
2567 | | XMEMSET(dec->des3, 0, sizeof(Des3)); |
2568 | | } |
2569 | | |
2570 | | if (enc) { |
2571 | | if (wc_Des3Init(enc->des3, heap, devId) != 0) { |
2572 | | WOLFSSL_MSG("Des3Init failed in SetKeys"); |
2573 | | return ASYNC_INIT_E; |
2574 | | } |
2575 | | } |
2576 | | if (dec) { |
2577 | | if (wc_Des3Init(dec->des3, heap, devId) != 0) { |
2578 | | WOLFSSL_MSG("Des3Init failed in SetKeys"); |
2579 | | return ASYNC_INIT_E; |
2580 | | } |
2581 | | } |
2582 | | |
2583 | | if (side == WOLFSSL_CLIENT_END) { |
2584 | | if (enc) { |
2585 | | desRet = wc_Des3_SetKey(enc->des3, keys->client_write_key, |
2586 | | keys->client_write_IV, DES_ENCRYPTION); |
2587 | | if (desRet != 0) return desRet; |
2588 | | } |
2589 | | if (dec) { |
2590 | | desRet = wc_Des3_SetKey(dec->des3, keys->server_write_key, |
2591 | | keys->server_write_IV, DES_DECRYPTION); |
2592 | | if (desRet != 0) return desRet; |
2593 | | } |
2594 | | } |
2595 | | else { |
2596 | | if (enc) { |
2597 | | desRet = wc_Des3_SetKey(enc->des3, keys->server_write_key, |
2598 | | keys->server_write_IV, DES_ENCRYPTION); |
2599 | | if (desRet != 0) return desRet; |
2600 | | } |
2601 | | if (dec) { |
2602 | | desRet = wc_Des3_SetKey(dec->des3, keys->client_write_key, |
2603 | | keys->client_write_IV, DES_DECRYPTION); |
2604 | | if (desRet != 0) return desRet; |
2605 | | } |
2606 | | } |
2607 | | if (enc) |
2608 | | enc->setup = 1; |
2609 | | if (dec) |
2610 | | dec->setup = 1; |
2611 | | } |
2612 | | #endif /* BUILD_DES3 */ |
2613 | | |
2614 | | #ifdef BUILD_AES |
2615 | | /* check that buffer sizes are sufficient */ |
2616 | | #if (MAX_WRITE_IV_SZ < 16) /* AES_IV_SIZE */ |
2617 | | #error MAX_WRITE_IV_SZ too small for AES |
2618 | | #endif |
2619 | | |
2620 | | if (specs->bulk_cipher_algorithm == wolfssl_aes) { |
2621 | | int aesRet = 0; |
2622 | | |
2623 | | if (enc) { |
2624 | | if (enc->aes == NULL) { |
2625 | | enc->aes = (Aes*)XMALLOC(sizeof(Aes), heap, DYNAMIC_TYPE_CIPHER); |
2626 | | if (enc->aes == NULL) |
2627 | | return MEMORY_E; |
2628 | | } else { |
2629 | | wc_AesFree(enc->aes); |
2630 | | } |
2631 | | |
2632 | | XMEMSET(enc->aes, 0, sizeof(Aes)); |
2633 | | } |
2634 | | if (dec) { |
2635 | | if (dec->aes == NULL) { |
2636 | | dec->aes = (Aes*)XMALLOC(sizeof(Aes), heap, DYNAMIC_TYPE_CIPHER); |
2637 | | if (dec->aes == NULL) |
2638 | | return MEMORY_E; |
2639 | | } else { |
2640 | | wc_AesFree(dec->aes); |
2641 | | } |
2642 | | |
2643 | | XMEMSET(dec->aes, 0, sizeof(Aes)); |
2644 | | } |
2645 | | if (enc) { |
2646 | | if (wc_AesInit(enc->aes, heap, devId) != 0) { |
2647 | | WOLFSSL_MSG("AesInit failed in SetKeys"); |
2648 | | return ASYNC_INIT_E; |
2649 | | } |
2650 | | } |
2651 | | if (dec) { |
2652 | | if (wc_AesInit(dec->aes, heap, devId) != 0) { |
2653 | | WOLFSSL_MSG("AesInit failed in SetKeys"); |
2654 | | return ASYNC_INIT_E; |
2655 | | } |
2656 | | } |
2657 | | |
2658 | | if (side == WOLFSSL_CLIENT_END) { |
2659 | | if (enc) { |
2660 | | aesRet = wc_AesSetKey(enc->aes, keys->client_write_key, |
2661 | | specs->key_size, keys->client_write_IV, |
2662 | | AES_ENCRYPTION); |
2663 | | if (aesRet != 0) return aesRet; |
2664 | | } |
2665 | | if (dec) { |
2666 | | aesRet = wc_AesSetKey(dec->aes, keys->server_write_key, |
2667 | | specs->key_size, keys->server_write_IV, |
2668 | | AES_DECRYPTION); |
2669 | | if (aesRet != 0) return aesRet; |
2670 | | } |
2671 | | } |
2672 | | else { |
2673 | | if (enc) { |
2674 | | aesRet = wc_AesSetKey(enc->aes, keys->server_write_key, |
2675 | | specs->key_size, keys->server_write_IV, |
2676 | | AES_ENCRYPTION); |
2677 | | if (aesRet != 0) return aesRet; |
2678 | | } |
2679 | | if (dec) { |
2680 | | aesRet = wc_AesSetKey(dec->aes, keys->client_write_key, |
2681 | | specs->key_size, keys->client_write_IV, |
2682 | | AES_DECRYPTION); |
2683 | | if (aesRet != 0) return aesRet; |
2684 | | } |
2685 | | } |
2686 | | if (enc) |
2687 | | enc->setup = 1; |
2688 | | if (dec) |
2689 | | dec->setup = 1; |
2690 | | } |
2691 | | #endif /* BUILD_AES */ |
2692 | | |
2693 | | #ifdef BUILD_AESGCM |
2694 | | /* check that buffer sizes are sufficient */ |
2695 | | #if (AEAD_MAX_IMP_SZ < 4) /* AESGCM_IMP_IV_SZ */ |
2696 | | #error AEAD_MAX_IMP_SZ too small for AESGCM |
2697 | | #endif |
2698 | | #if (AEAD_MAX_EXP_SZ < 8) /* AESGCM_EXP_IV_SZ */ |
2699 | | #error AEAD_MAX_EXP_SZ too small for AESGCM |
2700 | | #endif |
2701 | | #if (MAX_WRITE_IV_SZ < 4) /* AESGCM_IMP_IV_SZ */ |
2702 | | #error MAX_WRITE_IV_SZ too small for AESGCM |
2703 | | #endif |
2704 | | |
2705 | | if (specs->bulk_cipher_algorithm == wolfssl_aes_gcm) { |
2706 | | int gcmRet; |
2707 | | |
2708 | | if (enc) { |
2709 | | if (enc->aes == NULL) { |
2710 | | enc->aes = (Aes*)XMALLOC(sizeof(Aes), heap, DYNAMIC_TYPE_CIPHER); |
2711 | | if (enc->aes == NULL) |
2712 | | return MEMORY_E; |
2713 | | } else { |
2714 | | wc_AesFree(enc->aes); |
2715 | | } |
2716 | | |
2717 | | XMEMSET(enc->aes, 0, sizeof(Aes)); |
2718 | | } |
2719 | | if (dec) { |
2720 | | if (dec->aes == NULL) { |
2721 | | dec->aes = (Aes*)XMALLOC(sizeof(Aes), heap, DYNAMIC_TYPE_CIPHER); |
2722 | | if (dec->aes == NULL) |
2723 | | return MEMORY_E; |
2724 | | } else { |
2725 | | wc_AesFree(dec->aes); |
2726 | | } |
2727 | | |
2728 | | XMEMSET(dec->aes, 0, sizeof(Aes)); |
2729 | | } |
2730 | | |
2731 | | if (enc) { |
2732 | | if (wc_AesInit(enc->aes, heap, devId) != 0) { |
2733 | | WOLFSSL_MSG("AesInit failed in SetKeys"); |
2734 | | return ASYNC_INIT_E; |
2735 | | } |
2736 | | } |
2737 | | if (dec) { |
2738 | | if (wc_AesInit(dec->aes, heap, devId) != 0) { |
2739 | | WOLFSSL_MSG("AesInit failed in SetKeys"); |
2740 | | return ASYNC_INIT_E; |
2741 | | } |
2742 | | } |
2743 | | |
2744 | | if (side == WOLFSSL_CLIENT_END) { |
2745 | | if (enc) { |
2746 | | gcmRet = wc_AesGcmSetKey(enc->aes, keys->client_write_key, |
2747 | | specs->key_size); |
2748 | | if (gcmRet != 0) return gcmRet; |
2749 | | XMEMCPY(keys->aead_enc_imp_IV, keys->client_write_IV, |
2750 | | AEAD_MAX_IMP_SZ); |
2751 | | #if !defined(NO_PUBLIC_GCM_SET_IV) && \ |
2752 | | ((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \ |
2753 | | (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) |
2754 | | if (!tls13) { |
2755 | | gcmRet = wc_AesGcmSetIV(enc->aes, AESGCM_NONCE_SZ, |
2756 | | keys->client_write_IV, AESGCM_IMP_IV_SZ, rng); |
2757 | | if (gcmRet != 0) return gcmRet; |
2758 | | } |
2759 | | #endif |
2760 | | } |
2761 | | if (dec) { |
2762 | | gcmRet = wc_AesGcmSetKey(dec->aes, keys->server_write_key, |
2763 | | specs->key_size); |
2764 | | if (gcmRet != 0) return gcmRet; |
2765 | | XMEMCPY(keys->aead_dec_imp_IV, keys->server_write_IV, |
2766 | | AEAD_MAX_IMP_SZ); |
2767 | | } |
2768 | | } |
2769 | | else { |
2770 | | if (enc) { |
2771 | | gcmRet = wc_AesGcmSetKey(enc->aes, keys->server_write_key, |
2772 | | specs->key_size); |
2773 | | if (gcmRet != 0) return gcmRet; |
2774 | | XMEMCPY(keys->aead_enc_imp_IV, keys->server_write_IV, |
2775 | | AEAD_MAX_IMP_SZ); |
2776 | | #if !defined(NO_PUBLIC_GCM_SET_IV) && \ |
2777 | | ((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \ |
2778 | | (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) |
2779 | | if (!tls13) { |
2780 | | gcmRet = wc_AesGcmSetIV(enc->aes, AESGCM_NONCE_SZ, |
2781 | | keys->server_write_IV, AESGCM_IMP_IV_SZ, rng); |
2782 | | if (gcmRet != 0) return gcmRet; |
2783 | | } |
2784 | | #endif |
2785 | | } |
2786 | | if (dec) { |
2787 | | gcmRet = wc_AesGcmSetKey(dec->aes, keys->client_write_key, |
2788 | | specs->key_size); |
2789 | | if (gcmRet != 0) return gcmRet; |
2790 | | XMEMCPY(keys->aead_dec_imp_IV, keys->client_write_IV, |
2791 | | AEAD_MAX_IMP_SZ); |
2792 | | } |
2793 | | } |
2794 | | if (enc) |
2795 | | enc->setup = 1; |
2796 | | if (dec) |
2797 | | dec->setup = 1; |
2798 | | } |
2799 | | #endif /* BUILD_AESGCM */ |
2800 | | |
2801 | | #ifdef HAVE_AESCCM |
2802 | | /* check that buffer sizes are sufficient (CCM is same size as GCM) */ |
2803 | | #if (AEAD_MAX_IMP_SZ < 4) /* AESGCM_IMP_IV_SZ */ |
2804 | | #error AEAD_MAX_IMP_SZ too small for AESCCM |
2805 | | #endif |
2806 | | #if (AEAD_MAX_EXP_SZ < 8) /* AESGCM_EXP_IV_SZ */ |
2807 | | #error AEAD_MAX_EXP_SZ too small for AESCCM |
2808 | | #endif |
2809 | | #if (MAX_WRITE_IV_SZ < 4) /* AESGCM_IMP_IV_SZ */ |
2810 | | #error MAX_WRITE_IV_SZ too small for AESCCM |
2811 | | #endif |
2812 | | |
2813 | | if (specs->bulk_cipher_algorithm == wolfssl_aes_ccm) { |
2814 | | int CcmRet; |
2815 | | |
2816 | | if (enc) { |
2817 | | if (enc->aes == NULL) { |
2818 | | enc->aes = (Aes*)XMALLOC(sizeof(Aes), heap, DYNAMIC_TYPE_CIPHER); |
2819 | | if (enc->aes == NULL) |
2820 | | return MEMORY_E; |
2821 | | } else { |
2822 | | wc_AesFree(enc->aes); |
2823 | | } |
2824 | | |
2825 | | XMEMSET(enc->aes, 0, sizeof(Aes)); |
2826 | | } |
2827 | | if (dec) { |
2828 | | if (dec->aes == NULL) { |
2829 | | dec->aes = (Aes*)XMALLOC(sizeof(Aes), heap, DYNAMIC_TYPE_CIPHER); |
2830 | | if (dec->aes == NULL) |
2831 | | return MEMORY_E; |
2832 | | } else { |
2833 | | wc_AesFree(dec->aes); |
2834 | | } |
2835 | | XMEMSET(dec->aes, 0, sizeof(Aes)); |
2836 | | } |
2837 | | |
2838 | | if (enc) { |
2839 | | if (wc_AesInit(enc->aes, heap, devId) != 0) { |
2840 | | WOLFSSL_MSG("AesInit failed in SetKeys"); |
2841 | | return ASYNC_INIT_E; |
2842 | | } |
2843 | | } |
2844 | | if (dec) { |
2845 | | if (wc_AesInit(dec->aes, heap, devId) != 0) { |
2846 | | WOLFSSL_MSG("AesInit failed in SetKeys"); |
2847 | | return ASYNC_INIT_E; |
2848 | | } |
2849 | | } |
2850 | | |
2851 | | if (side == WOLFSSL_CLIENT_END) { |
2852 | | if (enc) { |
2853 | | CcmRet = wc_AesCcmSetKey(enc->aes, keys->client_write_key, |
2854 | | specs->key_size); |
2855 | | if (CcmRet != 0) { |
2856 | | return CcmRet; |
2857 | | } |
2858 | | XMEMCPY(keys->aead_enc_imp_IV, keys->client_write_IV, |
2859 | | AEAD_MAX_IMP_SZ); |
2860 | | #if !defined(NO_PUBLIC_CCM_SET_NONCE) && \ |
2861 | | ((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \ |
2862 | | (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) |
2863 | | if (!tls13) { |
2864 | | CcmRet = wc_AesCcmSetNonce(enc->aes, keys->client_write_IV, |
2865 | | AEAD_NONCE_SZ); |
2866 | | if (CcmRet != 0) return CcmRet; |
2867 | | } |
2868 | | #endif |
2869 | | } |
2870 | | if (dec) { |
2871 | | CcmRet = wc_AesCcmSetKey(dec->aes, keys->server_write_key, |
2872 | | specs->key_size); |
2873 | | if (CcmRet != 0) { |
2874 | | return CcmRet; |
2875 | | } |
2876 | | XMEMCPY(keys->aead_dec_imp_IV, keys->server_write_IV, |
2877 | | AEAD_MAX_IMP_SZ); |
2878 | | } |
2879 | | } |
2880 | | else { |
2881 | | if (enc) { |
2882 | | CcmRet = wc_AesCcmSetKey(enc->aes, keys->server_write_key, |
2883 | | specs->key_size); |
2884 | | if (CcmRet != 0) { |
2885 | | return CcmRet; |
2886 | | } |
2887 | | XMEMCPY(keys->aead_enc_imp_IV, keys->server_write_IV, |
2888 | | AEAD_MAX_IMP_SZ); |
2889 | | #if !defined(NO_PUBLIC_CCM_SET_NONCE) && \ |
2890 | | ((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \ |
2891 | | (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) |
2892 | | if (!tls13) { |
2893 | | CcmRet = wc_AesCcmSetNonce(enc->aes, keys->server_write_IV, |
2894 | | AEAD_NONCE_SZ); |
2895 | | if (CcmRet != 0) return CcmRet; |
2896 | | } |
2897 | | #endif |
2898 | | } |
2899 | | if (dec) { |
2900 | | CcmRet = wc_AesCcmSetKey(dec->aes, keys->client_write_key, |
2901 | | specs->key_size); |
2902 | | if (CcmRet != 0) { |
2903 | | return CcmRet; |
2904 | | } |
2905 | | XMEMCPY(keys->aead_dec_imp_IV, keys->client_write_IV, |
2906 | | AEAD_MAX_IMP_SZ); |
2907 | | } |
2908 | | } |
2909 | | if (enc) |
2910 | | enc->setup = 1; |
2911 | | if (dec) |
2912 | | dec->setup = 1; |
2913 | | } |
2914 | | #endif /* HAVE_AESCCM */ |
2915 | | |
2916 | | #ifdef HAVE_ARIA |
2917 | | /* check that buffer sizes are sufficient */ |
2918 | | #if (MAX_WRITE_IV_SZ < 16) /* AES_IV_SIZE */ |
2919 | | #error MAX_WRITE_IV_SZ too small for AES |
2920 | | #endif |
2921 | | |
2922 | | if (specs->bulk_cipher_algorithm == wolfssl_aria_gcm) { |
2923 | | int ret = 0; |
2924 | | MC_ALGID algo; |
2925 | | |
2926 | | switch(specs->key_size) { |
2927 | | case ARIA_128_KEY_SIZE: |
2928 | | algo = MC_ALGID_ARIA_128BITKEY; |
2929 | | break; |
2930 | | case ARIA_192_KEY_SIZE: |
2931 | | algo = MC_ALGID_ARIA_192BITKEY; |
2932 | | break; |
2933 | | case ARIA_256_KEY_SIZE: |
2934 | | algo = MC_ALGID_ARIA_256BITKEY; |
2935 | | break; |
2936 | | default: |
2937 | | return WOLFSSL_NOT_IMPLEMENTED; /* This should never happen */ |
2938 | | } |
2939 | | |
2940 | | if (enc) { |
2941 | | if (enc->aria == NULL) { |
2942 | | enc->aria = (wc_Aria*)XMALLOC(sizeof(wc_Aria), heap, DYNAMIC_TYPE_CIPHER); |
2943 | | if (enc->aria == NULL) |
2944 | | return MEMORY_E; |
2945 | | } else { |
2946 | | wc_AriaFreeCrypt(enc->aria); |
2947 | | } |
2948 | | |
2949 | | XMEMSET(enc->aria, 0, sizeof(wc_Aria)); |
2950 | | if (wc_AriaInitCrypt(enc->aria, algo) != 0) { |
2951 | | WOLFSSL_MSG("AriaInit failed in SetKeys"); |
2952 | | return ASYNC_INIT_E; |
2953 | | } |
2954 | | } |
2955 | | if (dec) { |
2956 | | if (dec->aria == NULL) { |
2957 | | dec->aria = (wc_Aria*)XMALLOC(sizeof(wc_Aria), heap, DYNAMIC_TYPE_CIPHER); |
2958 | | if (dec->aria == NULL) |
2959 | | return MEMORY_E; |
2960 | | } else { |
2961 | | wc_AriaFreeCrypt(dec->aria); |
2962 | | } |
2963 | | |
2964 | | XMEMSET(dec->aria, 0, sizeof(wc_Aria)); |
2965 | | if (wc_AriaInitCrypt(dec->aria, algo) != 0) { |
2966 | | WOLFSSL_MSG("AriaInit failed in SetKeys"); |
2967 | | return ASYNC_INIT_E; |
2968 | | } |
2969 | | } |
2970 | | |
2971 | | if (side == WOLFSSL_CLIENT_END) { |
2972 | | if (enc) { |
2973 | | ret = wc_AriaSetKey(enc->aria, keys->client_write_key); |
2974 | | if (ret != 0) return ret; |
2975 | | XMEMCPY(keys->aead_enc_imp_IV, keys->client_write_IV, |
2976 | | AEAD_MAX_IMP_SZ); |
2977 | | if (!tls13) { |
2978 | | ret = wc_AriaGcmSetIV(enc->aria, AESGCM_NONCE_SZ, |
2979 | | keys->client_write_IV, AESGCM_IMP_IV_SZ, rng); |
2980 | | if (ret != 0) return ret; |
2981 | | } |
2982 | | } |
2983 | | if (dec) { |
2984 | | ret = wc_AriaSetKey(dec->aria, keys->server_write_key); |
2985 | | if (ret != 0) return ret; |
2986 | | XMEMCPY(keys->aead_dec_imp_IV, keys->server_write_IV, |
2987 | | AEAD_MAX_IMP_SZ); |
2988 | | } |
2989 | | } |
2990 | | else { |
2991 | | if (enc) { |
2992 | | ret = wc_AriaSetKey(enc->aria, keys->server_write_key); |
2993 | | if (ret != 0) return ret; |
2994 | | XMEMCPY(keys->aead_enc_imp_IV, keys->server_write_IV, |
2995 | | AEAD_MAX_IMP_SZ); |
2996 | | if (!tls13) { |
2997 | | ret = wc_AriaGcmSetIV(enc->aria, AESGCM_NONCE_SZ, |
2998 | | keys->server_write_IV, AESGCM_IMP_IV_SZ, rng); |
2999 | | if (ret != 0) return ret; |
3000 | | } |
3001 | | } |
3002 | | if (dec) { |
3003 | | ret = wc_AriaSetKey(dec->aria, keys->client_write_key); |
3004 | | if (ret != 0) return ret; |
3005 | | XMEMCPY(keys->aead_dec_imp_IV, keys->client_write_IV, |
3006 | | AEAD_MAX_IMP_SZ); |
3007 | | } |
3008 | | } |
3009 | | if (enc) |
3010 | | enc->setup = 1; |
3011 | | if (dec) |
3012 | | dec->setup = 1; |
3013 | | } |
3014 | | #endif /* HAVE_ARIA */ |
3015 | | |
3016 | | #ifdef HAVE_CAMELLIA |
3017 | | /* check that buffer sizes are sufficient */ |
3018 | | #if (MAX_WRITE_IV_SZ < 16) /* CAMELLIA_IV_SIZE */ |
3019 | | #error MAX_WRITE_IV_SZ too small for CAMELLIA |
3020 | | #endif |
3021 | | |
3022 | | if (specs->bulk_cipher_algorithm == wolfssl_camellia) { |
3023 | | int camRet; |
3024 | | |
3025 | | if (enc && enc->cam == NULL) |
3026 | | enc->cam = |
3027 | | (wc_Camellia*)XMALLOC(sizeof(wc_Camellia), heap, DYNAMIC_TYPE_CIPHER); |
3028 | | if (enc && enc->cam == NULL) |
3029 | | return MEMORY_E; |
3030 | | |
3031 | | if (dec && dec->cam == NULL) |
3032 | | dec->cam = |
3033 | | (wc_Camellia*)XMALLOC(sizeof(wc_Camellia), heap, DYNAMIC_TYPE_CIPHER); |
3034 | | if (dec && dec->cam == NULL) |
3035 | | return MEMORY_E; |
3036 | | |
3037 | | if (side == WOLFSSL_CLIENT_END) { |
3038 | | if (enc) { |
3039 | | camRet = wc_CamelliaSetKey(enc->cam, keys->client_write_key, |
3040 | | specs->key_size, keys->client_write_IV); |
3041 | | if (camRet != 0) return camRet; |
3042 | | } |
3043 | | if (dec) { |
3044 | | camRet = wc_CamelliaSetKey(dec->cam, keys->server_write_key, |
3045 | | specs->key_size, keys->server_write_IV); |
3046 | | if (camRet != 0) return camRet; |
3047 | | } |
3048 | | } |
3049 | | else { |
3050 | | if (enc) { |
3051 | | camRet = wc_CamelliaSetKey(enc->cam, keys->server_write_key, |
3052 | | specs->key_size, keys->server_write_IV); |
3053 | | if (camRet != 0) return camRet; |
3054 | | } |
3055 | | if (dec) { |
3056 | | camRet = wc_CamelliaSetKey(dec->cam, keys->client_write_key, |
3057 | | specs->key_size, keys->client_write_IV); |
3058 | | if (camRet != 0) return camRet; |
3059 | | } |
3060 | | } |
3061 | | if (enc) |
3062 | | enc->setup = 1; |
3063 | | if (dec) |
3064 | | dec->setup = 1; |
3065 | | } |
3066 | | #endif /* HAVE_CAMELLIA */ |
3067 | | |
3068 | | #ifdef WOLFSSL_SM4_CBC |
3069 | | /* check that buffer sizes are sufficient */ |
3070 | | #if (MAX_WRITE_IV_SZ < 16) /* AES_IV_SIZE */ |
3071 | | #error MAX_WRITE_IV_SZ too small for SM4_CBC |
3072 | | #endif |
3073 | | |
3074 | | if (specs->bulk_cipher_algorithm == wolfssl_sm4_cbc) { |
3075 | | int sm4Ret = 0; |
3076 | | |
3077 | | if (enc) { |
3078 | | if (enc->sm4 == NULL) { |
3079 | | enc->sm4 = (wc_Sm4*)XMALLOC(sizeof(wc_Sm4), heap, |
3080 | | DYNAMIC_TYPE_CIPHER); |
3081 | | if (enc->sm4 == NULL) |
3082 | | return MEMORY_E; |
3083 | | } |
3084 | | else { |
3085 | | wc_Sm4Free(enc->sm4); |
3086 | | } |
3087 | | |
3088 | | XMEMSET(enc->sm4, 0, sizeof(wc_Sm4)); |
3089 | | } |
3090 | | if (dec) { |
3091 | | if (dec->sm4 == NULL) { |
3092 | | dec->sm4 = (wc_Sm4*)XMALLOC(sizeof(wc_Sm4), heap, |
3093 | | DYNAMIC_TYPE_CIPHER); |
3094 | | if (dec->sm4 == NULL) |
3095 | | return MEMORY_E; |
3096 | | } |
3097 | | else { |
3098 | | wc_Sm4Free(dec->sm4); |
3099 | | } |
3100 | | |
3101 | | XMEMSET(dec->sm4, 0, sizeof(wc_Sm4)); |
3102 | | } |
3103 | | if (enc) { |
3104 | | if (wc_Sm4Init(enc->sm4, heap, devId) != 0) { |
3105 | | WOLFSSL_MSG("Sm4Init failed in SetKeys"); |
3106 | | return ASYNC_INIT_E; |
3107 | | } |
3108 | | } |
3109 | | if (dec) { |
3110 | | if (wc_Sm4Init(dec->sm4, heap, devId) != 0) { |
3111 | | WOLFSSL_MSG("Sm4Init failed in SetKeys"); |
3112 | | return ASYNC_INIT_E; |
3113 | | } |
3114 | | } |
3115 | | |
3116 | | if (side == WOLFSSL_CLIENT_END) { |
3117 | | if (enc) { |
3118 | | sm4Ret = wc_Sm4SetKey(enc->sm4, keys->client_write_key, |
3119 | | specs->key_size); |
3120 | | if (sm4Ret != 0) return sm4Ret; |
3121 | | sm4Ret = wc_Sm4SetIV(enc->sm4, keys->client_write_IV); |
3122 | | if (sm4Ret != 0) return sm4Ret; |
3123 | | } |
3124 | | if (dec) { |
3125 | | sm4Ret = wc_Sm4SetKey(dec->sm4, keys->server_write_key, |
3126 | | specs->key_size); |
3127 | | if (sm4Ret != 0) return sm4Ret; |
3128 | | sm4Ret = wc_Sm4SetIV(dec->sm4, keys->server_write_IV); |
3129 | | if (sm4Ret != 0) return sm4Ret; |
3130 | | } |
3131 | | } |
3132 | | else { |
3133 | | if (enc) { |
3134 | | sm4Ret = wc_Sm4SetKey(enc->sm4, keys->server_write_key, |
3135 | | specs->key_size); |
3136 | | if (sm4Ret != 0) return sm4Ret; |
3137 | | sm4Ret = wc_Sm4SetIV(enc->sm4, keys->server_write_IV); |
3138 | | if (sm4Ret != 0) return sm4Ret; |
3139 | | } |
3140 | | if (dec) { |
3141 | | sm4Ret = wc_Sm4SetKey(dec->sm4, keys->client_write_key, |
3142 | | specs->key_size); |
3143 | | if (sm4Ret != 0) return sm4Ret; |
3144 | | sm4Ret = wc_Sm4SetIV(dec->sm4, keys->client_write_IV); |
3145 | | if (sm4Ret != 0) return sm4Ret; |
3146 | | } |
3147 | | } |
3148 | | if (enc) |
3149 | | enc->setup = 1; |
3150 | | if (dec) |
3151 | | dec->setup = 1; |
3152 | | } |
3153 | | #endif /* WOLFSSL_SM4_CBC */ |
3154 | | |
3155 | | #ifdef WOLFSSL_SM4_GCM |
3156 | | /* check that buffer sizes are sufficient */ |
3157 | | #if (AEAD_MAX_IMP_SZ < 4) /* SM4-GCM_IMP_IV_SZ */ |
3158 | | #error AEAD_MAX_IMP_SZ too small for SM4-GCM |
3159 | | #endif |
3160 | | #if (AEAD_MAX_EXP_SZ < 8) /* SM4-GCM_EXP_IV_SZ */ |
3161 | | #error AEAD_MAX_EXP_SZ too small for SM4-GCM |
3162 | | #endif |
3163 | | #if (MAX_WRITE_IV_SZ < 4) /* SM4-GCM_IMP_IV_SZ */ |
3164 | | #error MAX_WRITE_IV_SZ too small for SM4-GCM |
3165 | | #endif |
3166 | | |
3167 | | if (specs->bulk_cipher_algorithm == wolfssl_sm4_gcm) { |
3168 | | int gcmRet; |
3169 | | |
3170 | | if (enc) { |
3171 | | if (enc->sm4 == NULL) { |
3172 | | enc->sm4 = (wc_Sm4*)XMALLOC(sizeof(wc_Sm4), heap, |
3173 | | DYNAMIC_TYPE_CIPHER); |
3174 | | if (enc->sm4 == NULL) |
3175 | | return MEMORY_E; |
3176 | | } else { |
3177 | | wc_Sm4Free(enc->sm4); |
3178 | | } |
3179 | | |
3180 | | XMEMSET(enc->sm4, 0, sizeof(wc_Sm4)); |
3181 | | } |
3182 | | if (dec) { |
3183 | | if (dec->sm4 == NULL) { |
3184 | | dec->sm4 = (wc_Sm4*)XMALLOC(sizeof(wc_Sm4), heap, |
3185 | | DYNAMIC_TYPE_CIPHER); |
3186 | | if (dec->sm4 == NULL) |
3187 | | return MEMORY_E; |
3188 | | } else { |
3189 | | wc_Sm4Free(dec->sm4); |
3190 | | } |
3191 | | |
3192 | | XMEMSET(dec->sm4, 0, sizeof(wc_Sm4)); |
3193 | | } |
3194 | | |
3195 | | if (enc) { |
3196 | | if (wc_Sm4Init(enc->sm4, heap, devId) != 0) { |
3197 | | WOLFSSL_MSG("Sm4Init failed in SetKeys"); |
3198 | | return ASYNC_INIT_E; |
3199 | | } |
3200 | | } |
3201 | | if (dec) { |
3202 | | if (wc_Sm4Init(dec->sm4, heap, devId) != 0) { |
3203 | | WOLFSSL_MSG("Sm4Init failed in SetKeys"); |
3204 | | return ASYNC_INIT_E; |
3205 | | } |
3206 | | } |
3207 | | |
3208 | | if (side == WOLFSSL_CLIENT_END) { |
3209 | | if (enc) { |
3210 | | gcmRet = wc_Sm4GcmSetKey(enc->sm4, keys->client_write_key, |
3211 | | specs->key_size); |
3212 | | if (gcmRet != 0) return gcmRet; |
3213 | | XMEMCPY(keys->aead_enc_imp_IV, keys->client_write_IV, |
3214 | | AEAD_MAX_IMP_SZ); |
3215 | | } |
3216 | | if (dec) { |
3217 | | gcmRet = wc_Sm4GcmSetKey(dec->sm4, keys->server_write_key, |
3218 | | specs->key_size); |
3219 | | if (gcmRet != 0) return gcmRet; |
3220 | | XMEMCPY(keys->aead_dec_imp_IV, keys->server_write_IV, |
3221 | | AEAD_MAX_IMP_SZ); |
3222 | | } |
3223 | | } |
3224 | | else { |
3225 | | if (enc) { |
3226 | | gcmRet = wc_Sm4GcmSetKey(enc->sm4, keys->server_write_key, |
3227 | | specs->key_size); |
3228 | | if (gcmRet != 0) return gcmRet; |
3229 | | XMEMCPY(keys->aead_enc_imp_IV, keys->server_write_IV, |
3230 | | AEAD_MAX_IMP_SZ); |
3231 | | } |
3232 | | if (dec) { |
3233 | | gcmRet = wc_Sm4GcmSetKey(dec->sm4, keys->client_write_key, |
3234 | | specs->key_size); |
3235 | | if (gcmRet != 0) return gcmRet; |
3236 | | XMEMCPY(keys->aead_dec_imp_IV, keys->client_write_IV, |
3237 | | AEAD_MAX_IMP_SZ); |
3238 | | } |
3239 | | } |
3240 | | if (enc) |
3241 | | enc->setup = 1; |
3242 | | if (dec) |
3243 | | dec->setup = 1; |
3244 | | } |
3245 | | #endif /* WOLFSSL_SM4_GCM */ |
3246 | | |
3247 | | #ifdef WOLFSSL_SM4_CCM |
3248 | | /* check that buffer sizes are sufficient (CCM is same size as GCM) */ |
3249 | | #if (AEAD_MAX_IMP_SZ < 4) /* SM4-CCM_IMP_IV_SZ */ |
3250 | | #error AEAD_MAX_IMP_SZ too small for SM4-CCM |
3251 | | #endif |
3252 | | #if (AEAD_MAX_EXP_SZ < 8) /* SM4-CCM_EXP_IV_SZ */ |
3253 | | #error AEAD_MAX_EXP_SZ too small for SM4-CCM |
3254 | | #endif |
3255 | | #if (MAX_WRITE_IV_SZ < 4) /* SM4-CCM_IMP_IV_SZ */ |
3256 | | #error MAX_WRITE_IV_SZ too small for SM4-CCM |
3257 | | #endif |
3258 | | |
3259 | | if (specs->bulk_cipher_algorithm == wolfssl_sm4_ccm) { |
3260 | | int CcmRet; |
3261 | | |
3262 | | if (enc) { |
3263 | | if (enc->sm4 == NULL) { |
3264 | | enc->sm4 = (wc_Sm4*)XMALLOC(sizeof(wc_Sm4), heap, |
3265 | | DYNAMIC_TYPE_CIPHER); |
3266 | | if (enc->sm4 == NULL) |
3267 | | return MEMORY_E; |
3268 | | } else { |
3269 | | wc_Sm4Free(enc->sm4); |
3270 | | } |
3271 | | |
3272 | | XMEMSET(enc->sm4, 0, sizeof(wc_Sm4)); |
3273 | | } |
3274 | | if (dec) { |
3275 | | if (dec->sm4 == NULL) { |
3276 | | dec->sm4 = (wc_Sm4*)XMALLOC(sizeof(wc_Sm4), heap, |
3277 | | DYNAMIC_TYPE_CIPHER); |
3278 | | if (dec->sm4 == NULL) |
3279 | | return MEMORY_E; |
3280 | | } else { |
3281 | | wc_Sm4Free(dec->sm4); |
3282 | | } |
3283 | | XMEMSET(dec->sm4, 0, sizeof(wc_Sm4)); |
3284 | | } |
3285 | | |
3286 | | if (enc) { |
3287 | | if (wc_Sm4Init(enc->sm4, heap, devId) != 0) { |
3288 | | WOLFSSL_MSG("Sm4Init failed in SetKeys"); |
3289 | | return ASYNC_INIT_E; |
3290 | | } |
3291 | | } |
3292 | | if (dec) { |
3293 | | if (wc_Sm4Init(dec->sm4, heap, devId) != 0) { |
3294 | | WOLFSSL_MSG("Sm4Init failed in SetKeys"); |
3295 | | return ASYNC_INIT_E; |
3296 | | } |
3297 | | } |
3298 | | |
3299 | | if (side == WOLFSSL_CLIENT_END) { |
3300 | | if (enc) { |
3301 | | CcmRet = wc_Sm4SetKey(enc->sm4, keys->client_write_key, |
3302 | | specs->key_size); |
3303 | | if (CcmRet != 0) { |
3304 | | return CcmRet; |
3305 | | } |
3306 | | XMEMCPY(keys->aead_enc_imp_IV, keys->client_write_IV, |
3307 | | AEAD_MAX_IMP_SZ); |
3308 | | } |
3309 | | if (dec) { |
3310 | | CcmRet = wc_Sm4SetKey(dec->sm4, keys->server_write_key, |
3311 | | specs->key_size); |
3312 | | if (CcmRet != 0) { |
3313 | | return CcmRet; |
3314 | | } |
3315 | | XMEMCPY(keys->aead_dec_imp_IV, keys->server_write_IV, |
3316 | | AEAD_MAX_IMP_SZ); |
3317 | | } |
3318 | | } |
3319 | | else { |
3320 | | if (enc) { |
3321 | | CcmRet = wc_Sm4SetKey(enc->sm4, keys->server_write_key, |
3322 | | specs->key_size); |
3323 | | if (CcmRet != 0) { |
3324 | | return CcmRet; |
3325 | | } |
3326 | | XMEMCPY(keys->aead_enc_imp_IV, keys->server_write_IV, |
3327 | | AEAD_MAX_IMP_SZ); |
3328 | | } |
3329 | | if (dec) { |
3330 | | CcmRet = wc_Sm4SetKey(dec->sm4, keys->client_write_key, |
3331 | | specs->key_size); |
3332 | | if (CcmRet != 0) { |
3333 | | return CcmRet; |
3334 | | } |
3335 | | XMEMCPY(keys->aead_dec_imp_IV, keys->client_write_IV, |
3336 | | AEAD_MAX_IMP_SZ); |
3337 | | } |
3338 | | } |
3339 | | if (enc) |
3340 | | enc->setup = 1; |
3341 | | if (dec) |
3342 | | dec->setup = 1; |
3343 | | } |
3344 | | #endif /* WOLFSSL_SM4_CCM */ |
3345 | | |
3346 | | #ifdef HAVE_NULL_CIPHER |
3347 | | if (specs->bulk_cipher_algorithm == wolfssl_cipher_null) { |
3348 | | #ifdef WOLFSSL_TLS13 |
3349 | | if (tls13) { |
3350 | | int hmacRet; |
3351 | | int hashType = WC_HASH_TYPE_NONE; |
3352 | | |
3353 | | switch (specs->mac_algorithm) { |
3354 | | case sha256_mac: |
3355 | | hashType = WC_SHA256; |
3356 | | break; |
3357 | | case sha384_mac: |
3358 | | hashType = WC_SHA384; |
3359 | | break; |
3360 | | default: |
3361 | | break; |
3362 | | } |
3363 | | |
3364 | | if (enc && enc->hmac == NULL) { |
3365 | | enc->hmac = (Hmac*)XMALLOC(sizeof(Hmac), heap, |
3366 | | DYNAMIC_TYPE_CIPHER); |
3367 | | if (enc->hmac == NULL) |
3368 | | return MEMORY_E; |
3369 | | |
3370 | | if (wc_HmacInit(enc->hmac, heap, devId) != 0) { |
3371 | | WOLFSSL_MSG("HmacInit failed in SetKeys"); |
3372 | | XFREE(enc->hmac, heap, DYNAMIC_TYPE_CIPHER); |
3373 | | enc->hmac = NULL; |
3374 | | return ASYNC_INIT_E; |
3375 | | } |
3376 | | } |
3377 | | |
3378 | | if (dec && dec->hmac == NULL) { |
3379 | | dec->hmac = (Hmac*)XMALLOC(sizeof(Hmac), heap, |
3380 | | DYNAMIC_TYPE_CIPHER); |
3381 | | if (dec->hmac == NULL) |
3382 | | return MEMORY_E; |
3383 | | |
3384 | | if (wc_HmacInit(dec->hmac, heap, devId) != 0) { |
3385 | | WOLFSSL_MSG("HmacInit failed in SetKeys"); |
3386 | | XFREE(dec->hmac, heap, DYNAMIC_TYPE_CIPHER); |
3387 | | dec->hmac = NULL; |
3388 | | return ASYNC_INIT_E; |
3389 | | } |
3390 | | } |
3391 | | |
3392 | | if (side == WOLFSSL_CLIENT_END) { |
3393 | | if (enc) { |
3394 | | XMEMCPY(keys->aead_enc_imp_IV, keys->client_write_IV, |
3395 | | specs->iv_size); |
3396 | | hmacRet = wc_HmacSetKey(enc->hmac, hashType, |
3397 | | keys->client_write_key, specs->key_size); |
3398 | | if (hmacRet != 0) return hmacRet; |
3399 | | } |
3400 | | if (dec) { |
3401 | | XMEMCPY(keys->aead_dec_imp_IV, keys->server_write_IV, |
3402 | | specs->iv_size); |
3403 | | hmacRet = wc_HmacSetKey(dec->hmac, hashType, |
3404 | | keys->server_write_key, specs->key_size); |
3405 | | if (hmacRet != 0) return hmacRet; |
3406 | | } |
3407 | | } |
3408 | | else { |
3409 | | if (enc) { |
3410 | | XMEMCPY(keys->aead_enc_imp_IV, keys->server_write_IV, |
3411 | | specs->iv_size); |
3412 | | hmacRet = wc_HmacSetKey(enc->hmac, hashType, |
3413 | | keys->server_write_key, specs->key_size); |
3414 | | if (hmacRet != 0) return hmacRet; |
3415 | | } |
3416 | | if (dec) { |
3417 | | XMEMCPY(keys->aead_dec_imp_IV, keys->client_write_IV, |
3418 | | specs->iv_size); |
3419 | | hmacRet = wc_HmacSetKey(dec->hmac, hashType, |
3420 | | keys->client_write_key, specs->key_size); |
3421 | | if (hmacRet != 0) return hmacRet; |
3422 | | } |
3423 | | } |
3424 | | } |
3425 | | #endif |
3426 | | if (enc) |
3427 | | enc->setup = 1; |
3428 | | if (dec) |
3429 | | dec->setup = 1; |
3430 | | } |
3431 | | #endif |
3432 | | |
3433 | | if (enc) { |
3434 | | keys->sequence_number_hi = 0; |
3435 | | keys->sequence_number_lo = 0; |
3436 | | } |
3437 | | if (dec) { |
3438 | | keys->peer_sequence_number_hi = 0; |
3439 | | keys->peer_sequence_number_lo = 0; |
3440 | | } |
3441 | | (void)side; |
3442 | | (void)heap; |
3443 | | (void)enc; |
3444 | | (void)dec; |
3445 | | (void)specs; |
3446 | | (void)devId; |
3447 | | |
3448 | | return 0; |
3449 | | } |
3450 | | |
3451 | | |
3452 | | #ifdef HAVE_ONE_TIME_AUTH |
3453 | | /* set one time authentication keys */ |
3454 | | static int SetAuthKeys(OneTimeAuth* authentication, Keys* keys, |
3455 | | CipherSpecs* specs, void* heap, int devId) |
3456 | 52 | { |
3457 | | |
3458 | 52 | #ifdef HAVE_POLY1305 |
3459 | | /* set up memory space for poly1305 */ |
3460 | 52 | if (authentication && authentication->poly1305 == NULL) |
3461 | 52 | authentication->poly1305 = |
3462 | 52 | (Poly1305*)XMALLOC(sizeof(Poly1305), heap, DYNAMIC_TYPE_CIPHER); |
3463 | 52 | if (authentication && authentication->poly1305 == NULL) |
3464 | 0 | return MEMORY_E; |
3465 | | #ifdef WOLFSSL_CHECK_MEM_ZERO |
3466 | | wc_MemZero_Add("SSL auth keys poly1305", authentication->poly1305, |
3467 | | sizeof(Poly1305)); |
3468 | | #endif |
3469 | 52 | if (authentication) |
3470 | 52 | authentication->setup = 1; |
3471 | 52 | #endif |
3472 | 52 | (void)authentication; |
3473 | 52 | (void)heap; |
3474 | 52 | (void)keys; |
3475 | 52 | (void)specs; |
3476 | 52 | (void)devId; |
3477 | | |
3478 | 52 | return 0; |
3479 | 52 | } |
3480 | | #endif /* HAVE_ONE_TIME_AUTH */ |
3481 | | |
3482 | | #ifdef HAVE_SECURE_RENEGOTIATION |
3483 | | /* function name is for cache_status++ |
3484 | | * This function was added because of error incrementing enum type when |
3485 | | * compiling with a C++ compiler. |
3486 | | */ |
3487 | | static void CacheStatusPP(SecureRenegotiation* cache) |
3488 | | { |
3489 | | switch (cache->cache_status) { |
3490 | | case SCR_CACHE_NULL: |
3491 | | cache->cache_status = SCR_CACHE_NEEDED; |
3492 | | break; |
3493 | | |
3494 | | case SCR_CACHE_NEEDED: |
3495 | | cache->cache_status = SCR_CACHE_COPY; |
3496 | | break; |
3497 | | |
3498 | | case SCR_CACHE_COPY: |
3499 | | cache->cache_status = SCR_CACHE_PARTIAL; |
3500 | | break; |
3501 | | |
3502 | | case SCR_CACHE_PARTIAL: |
3503 | | cache->cache_status = SCR_CACHE_COMPLETE; |
3504 | | break; |
3505 | | |
3506 | | case SCR_CACHE_COMPLETE: |
3507 | | WOLFSSL_MSG("SCR Cache state Complete"); |
3508 | | break; |
3509 | | |
3510 | | default: |
3511 | | WOLFSSL_MSG("Unknown cache state!!"); |
3512 | | } |
3513 | | } |
3514 | | #endif /* HAVE_SECURE_RENEGOTIATION */ |
3515 | | |
3516 | | |
3517 | | /* Set wc_encrypt/wc_decrypt or both sides of key setup |
3518 | | * note: use wc_encrypt to avoid shadowing global encrypt |
3519 | | * declared in unistd.h |
3520 | | */ |
3521 | | int SetKeysSide(WOLFSSL* ssl, enum encrypt_side side) |
3522 | | { |
3523 | | int ret, copy = 0; |
3524 | | Ciphers* wc_encrypt = NULL; |
3525 | | Ciphers* wc_decrypt = NULL; |
3526 | | Keys* keys = &ssl->keys; |
3527 | | |
3528 | | (void)copy; |
3529 | | |
3530 | | /* Cipher activation invalidates the cached AEAD record overhead. Covers |
3531 | | * TLS 1.2 / TLS 1.3 handshake completion, secure renegotiation, early |
3532 | | * data flips, and DTLS 1.3 epoch transitions (Dtls13SetEpochKeys() calls |
3533 | | * SetKeysSide() at the bottom). */ |
3534 | | ssl->recordSzOverhead = 0; |
3535 | | |
3536 | | #ifdef HAVE_SECURE_RENEGOTIATION |
3537 | | if (ssl->secure_renegotiation && |
3538 | | ssl->secure_renegotiation->cache_status != SCR_CACHE_NULL) { |
3539 | | keys = &ssl->secure_renegotiation->tmp_keys; |
3540 | | #ifdef WOLFSSL_DTLS |
3541 | | /* For DTLS, copy is done in StoreKeys */ |
3542 | | if (!ssl->options.dtls) |
3543 | | #endif |
3544 | | copy = 1; |
3545 | | } |
3546 | | #endif /* HAVE_SECURE_RENEGOTIATION */ |
3547 | | |
3548 | | switch (side) { |
3549 | | case ENCRYPT_SIDE_ONLY: |
3550 | | #ifdef WOLFSSL_DEBUG_TLS |
3551 | | WOLFSSL_MSG("Provisioning ENCRYPT key"); |
3552 | | if (ssl->options.side == WOLFSSL_CLIENT_END) { |
3553 | | WOLFSSL_BUFFER(keys->client_write_key, ssl->specs.key_size); |
3554 | | } |
3555 | | else { |
3556 | | WOLFSSL_BUFFER(keys->server_write_key, ssl->specs.key_size); |
3557 | | } |
3558 | | #endif |
3559 | | wc_encrypt = &ssl->encrypt; |
3560 | | break; |
3561 | | |
3562 | | case DECRYPT_SIDE_ONLY: |
3563 | | #ifdef WOLFSSL_DEBUG_TLS |
3564 | | WOLFSSL_MSG("Provisioning DECRYPT key"); |
3565 | | if (ssl->options.side == WOLFSSL_CLIENT_END) { |
3566 | | WOLFSSL_BUFFER(keys->server_write_key, ssl->specs.key_size); |
3567 | | } |
3568 | | else { |
3569 | | WOLFSSL_BUFFER(keys->client_write_key, ssl->specs.key_size); |
3570 | | } |
3571 | | #endif |
3572 | | wc_decrypt = &ssl->decrypt; |
3573 | | break; |
3574 | | |
3575 | | case ENCRYPT_AND_DECRYPT_SIDE: |
3576 | | #ifdef WOLFSSL_DEBUG_TLS |
3577 | | WOLFSSL_MSG("Provisioning ENCRYPT key"); |
3578 | | if (ssl->options.side == WOLFSSL_CLIENT_END) { |
3579 | | WOLFSSL_BUFFER(keys->client_write_key, ssl->specs.key_size); |
3580 | | } |
3581 | | else { |
3582 | | WOLFSSL_BUFFER(keys->server_write_key, ssl->specs.key_size); |
3583 | | } |
3584 | | WOLFSSL_MSG("Provisioning DECRYPT key"); |
3585 | | if (ssl->options.side == WOLFSSL_CLIENT_END) { |
3586 | | WOLFSSL_BUFFER(keys->server_write_key, ssl->specs.key_size); |
3587 | | } |
3588 | | else { |
3589 | | WOLFSSL_BUFFER(keys->client_write_key, ssl->specs.key_size); |
3590 | | } |
3591 | | #endif |
3592 | | wc_encrypt = &ssl->encrypt; |
3593 | | wc_decrypt = &ssl->decrypt; |
3594 | | break; |
3595 | | |
3596 | | default: |
3597 | | return BAD_FUNC_ARG; |
3598 | | } |
3599 | | |
3600 | | #ifdef HAVE_ONE_TIME_AUTH |
3601 | | if (!ssl->auth.setup && ssl->specs.bulk_cipher_algorithm == wolfssl_chacha){ |
3602 | | ret = SetAuthKeys(&ssl->auth, keys, &ssl->specs, ssl->heap, ssl->devId); |
3603 | | if (ret != 0) |
3604 | | return ret; |
3605 | | } |
3606 | | #endif |
3607 | | |
3608 | | #if !defined(NO_CERTS) && defined(HAVE_PK_CALLBACKS) |
3609 | | ret = WC_NO_ERR_TRACE(PROTOCOLCB_UNAVAILABLE); |
3610 | | if (ssl->ctx->EncryptKeysCb) { |
3611 | | void* ctx = wolfSSL_GetEncryptKeysCtx(ssl); |
3612 | | #if defined(WOLFSSL_RENESAS_FSPSM_TLS) |
3613 | | FSPSM_ST* cbInfo = (FSPSM_ST*)ctx; |
3614 | | cbInfo->internal->side = side; |
3615 | | #elif defined(WOLFSSL_RENESAS_TSIP_TLS) |
3616 | | TsipUserCtx* cbInfo = (TsipUserCtx*)ctx; |
3617 | | cbInfo->internal->key_side = side; |
3618 | | #endif |
3619 | | ret = ssl->ctx->EncryptKeysCb(ssl, ctx); |
3620 | | } |
3621 | | if (!ssl->ctx->EncryptKeysCb || |
3622 | | ret == WC_NO_ERR_TRACE(PROTOCOLCB_UNAVAILABLE)) |
3623 | | #endif |
3624 | | { |
3625 | | ret = SetKeys(wc_encrypt, wc_decrypt, keys, &ssl->specs, ssl->options.side, |
3626 | | ssl->heap, ssl->devId, ssl->rng, ssl->options.tls1_3); |
3627 | | } |
3628 | | |
3629 | | /* Zero the TLS-layer staging key buffers once the CryptoCB callback |
3630 | | * has imported the key into a Secure Element. |
3631 | | * |
3632 | | * Convention: after a successful wc_AesSetKey / wc_AesGcmSetKey where |
3633 | | * the CryptoCB handled the key import, the callback leaves |
3634 | | * aes->devCtx != NULL and the software key schedule (aes->key, |
3635 | | * aes->devKey, aes->gcm.H / aes->gcm.M0) is NOT populated. The TLS |
3636 | | * layer may therefore destroy its staging copy of the traffic key. |
3637 | | * |
3638 | | * Only the key buffers (client_write_key / server_write_key) are |
3639 | | * zeroed. The static IVs (client_write_IV / server_write_IV) and |
3640 | | * the AEAD implicit-IV copies (aead_{enc,dec}_imp_IV) are NOT |
3641 | | * zeroed: BuildTls13Nonce() in tls13.c reads keys->aead_*_imp_IV on |
3642 | | * every AEAD record to construct the per-record nonce |
3643 | | * (nonce = static_iv XOR seq_num, RFC 8446 Section 5.3). Zeroing |
3644 | | * them would break the record path or, if applied symmetrically on |
3645 | | * both peers, silently degenerate the nonce to the bare sequence |
3646 | | * number and break interop with any unpatched peer. The static_iv |
3647 | | * is not a confidentiality-critical secret in the same sense as |
3648 | | * the traffic key; losing it does not compromise plaintext. |
3649 | | * |
3650 | | * Scope: |
3651 | | * - TLS 1.3 only. TLS 1.2 additionally reads |
3652 | | * keys->{client,server}_write_key for rehandshake/secure |
3653 | | * renegotiation flows. |
3654 | | * - Non-DTLS. Dtls13EpochCopyKeys (called from Dtls13NewEpoch) |
3655 | | * references keys->*_write_key for epoch switching; DTLS 1.3 |
3656 | | * needs separate analysis. |
3657 | | * - Non-QUIC. QUIC traffic secrets live outside these buffers |
3658 | | * but the interaction with stack-installed QUIC handlers has |
3659 | | * not been audited; exclude until it is. |
3660 | | * |
3661 | | * When called with ENCRYPT_SIDE_ONLY or DECRYPT_SIDE_ONLY, only the |
3662 | | * buffer consumed by this call is zeroed; the complementary buffer |
3663 | | * is written in a later SetKeysSide() from its own DeriveTls13Keys() |
3664 | | * and StoreKeys() pair (StoreKeys gates on PROVISION_CLIENT / |
3665 | | * PROVISION_SERVER so only the provisioned side is written). |
3666 | | * |
3667 | | * Ordering: this block must run AFTER SetKeys() (so offload has |
3668 | | * happened) and BEFORE Dtls13SetRecordNumberKeys() / |
3669 | | * wolfSSL_quic_keys_active() below, in case a future refactor in |
3670 | | * either starts reading keys->*_write_key. The DTLS and QUIC gates |
3671 | | * in this block mean neither currently executes on the same ssl, |
3672 | | * but keep the order explicit. */ |
3673 | | #if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_AES_SETKEY) |
3674 | | if (ret == 0 && ssl->options.tls1_3 && !ssl->options.dtls |
3675 | | && !WOLFSSL_IS_QUIC(ssl)) { |
3676 | | int encOffloaded = (wc_encrypt != NULL && wc_encrypt->aes != NULL && |
3677 | | wc_encrypt->aes->devCtx != NULL); |
3678 | | int decOffloaded = (wc_decrypt != NULL && wc_decrypt->aes != NULL && |
3679 | | wc_decrypt->aes->devCtx != NULL); |
3680 | | |
3681 | | if (encOffloaded || decOffloaded) { |
3682 | | if (ssl->options.side == WOLFSSL_CLIENT_END) { |
3683 | | if (encOffloaded) |
3684 | | ForceZero(keys->client_write_key, ssl->specs.key_size); |
3685 | | if (decOffloaded) |
3686 | | ForceZero(keys->server_write_key, ssl->specs.key_size); |
3687 | | } |
3688 | | else { |
3689 | | if (encOffloaded) |
3690 | | ForceZero(keys->server_write_key, ssl->specs.key_size); |
3691 | | if (decOffloaded) |
3692 | | ForceZero(keys->client_write_key, ssl->specs.key_size); |
3693 | | } |
3694 | | } |
3695 | | } |
3696 | | #endif /* WOLF_CRYPTO_CB && WOLF_CRYPTO_CB_AES_SETKEY */ |
3697 | | |
3698 | | #ifdef WOLFSSL_DTLS13 |
3699 | | if (ret == 0 && ssl->options.dtls && IsAtLeastTLSv1_3(ssl->version)) |
3700 | | ret = Dtls13SetRecordNumberKeys(ssl, side); |
3701 | | #endif /* WOLFSSL_DTLS13 */ |
3702 | | #ifdef WOLFSSL_QUIC |
3703 | | if (ret == 0 && WOLFSSL_IS_QUIC(ssl)) { |
3704 | | ret = wolfSSL_quic_keys_active(ssl, side); |
3705 | | } |
3706 | | #endif /* WOLFSSL_QUIC */ |
3707 | | |
3708 | | #ifdef HAVE_SECURE_RENEGOTIATION |
3709 | | #ifdef WOLFSSL_DTLS |
3710 | | if (ret == 0 && ssl->options.dtls && !ssl->options.tls1_3) { |
3711 | | if (wc_encrypt) |
3712 | | wc_encrypt->src = keys == &ssl->keys ? KEYS : SCR; |
3713 | | if (wc_decrypt) |
3714 | | wc_decrypt->src = keys == &ssl->keys ? KEYS : SCR; |
3715 | | } |
3716 | | #endif |
3717 | | |
3718 | | if (copy) { |
3719 | | int clientCopy = 0; |
3720 | | |
3721 | | /* Sanity check that keys == ssl->secure_renegotiation->tmp_keys. |
3722 | | * Otherwise the memcpy calls would copy overlapping memory |
3723 | | * and cause UB. Fail early. */ |
3724 | | if (keys == &ssl->keys) |
3725 | | return BAD_FUNC_ARG; |
3726 | | |
3727 | | if (ssl->options.side == WOLFSSL_CLIENT_END && wc_encrypt) |
3728 | | clientCopy = 1; |
3729 | | else if (ssl->options.side == WOLFSSL_SERVER_END && wc_decrypt) |
3730 | | clientCopy = 1; |
3731 | | |
3732 | | if (clientCopy) { |
3733 | | #ifndef WOLFSSL_AEAD_ONLY |
3734 | | XMEMCPY(ssl->keys.client_write_MAC_secret, |
3735 | | keys->client_write_MAC_secret, WC_MAX_DIGEST_SIZE); |
3736 | | #endif |
3737 | | XMEMCPY(ssl->keys.client_write_key, |
3738 | | keys->client_write_key, AES_256_KEY_SIZE); |
3739 | | XMEMCPY(ssl->keys.client_write_IV, |
3740 | | keys->client_write_IV, MAX_WRITE_IV_SZ); |
3741 | | } else { |
3742 | | #ifndef WOLFSSL_AEAD_ONLY |
3743 | | XMEMCPY(ssl->keys.server_write_MAC_secret, |
3744 | | keys->server_write_MAC_secret, WC_MAX_DIGEST_SIZE); |
3745 | | #endif |
3746 | | XMEMCPY(ssl->keys.server_write_key, |
3747 | | keys->server_write_key, AES_256_KEY_SIZE); |
3748 | | XMEMCPY(ssl->keys.server_write_IV, |
3749 | | keys->server_write_IV, MAX_WRITE_IV_SZ); |
3750 | | } |
3751 | | if (wc_encrypt) { |
3752 | | ssl->keys.sequence_number_hi = keys->sequence_number_hi; |
3753 | | ssl->keys.sequence_number_lo = keys->sequence_number_lo; |
3754 | | #ifdef HAVE_AEAD |
3755 | | if (ssl->specs.cipher_type == aead) { |
3756 | | /* Initialize the AES-GCM/CCM explicit IV to a zero. */ |
3757 | | XMEMCPY(ssl->keys.aead_exp_IV, keys->aead_exp_IV, |
3758 | | AEAD_MAX_EXP_SZ); |
3759 | | |
3760 | | /* Initialize encrypt implicit IV by encrypt side */ |
3761 | | if (ssl->options.side == WOLFSSL_CLIENT_END) { |
3762 | | XMEMCPY(ssl->keys.aead_enc_imp_IV, |
3763 | | keys->client_write_IV, AEAD_MAX_IMP_SZ); |
3764 | | } else { |
3765 | | XMEMCPY(ssl->keys.aead_enc_imp_IV, |
3766 | | keys->server_write_IV, AEAD_MAX_IMP_SZ); |
3767 | | } |
3768 | | } |
3769 | | #endif |
3770 | | } |
3771 | | if (wc_decrypt) { |
3772 | | ssl->keys.peer_sequence_number_hi = keys->peer_sequence_number_hi; |
3773 | | ssl->keys.peer_sequence_number_lo = keys->peer_sequence_number_lo; |
3774 | | #ifdef HAVE_AEAD |
3775 | | if (ssl->specs.cipher_type == aead) { |
3776 | | /* Initialize decrypt implicit IV by decrypt side */ |
3777 | | if (ssl->options.side == WOLFSSL_SERVER_END) { |
3778 | | XMEMCPY(ssl->keys.aead_dec_imp_IV, |
3779 | | keys->client_write_IV, AEAD_MAX_IMP_SZ); |
3780 | | } else { |
3781 | | XMEMCPY(ssl->keys.aead_dec_imp_IV, |
3782 | | keys->server_write_IV, AEAD_MAX_IMP_SZ); |
3783 | | } |
3784 | | } |
3785 | | #endif |
3786 | | } |
3787 | | CacheStatusPP(ssl->secure_renegotiation); |
3788 | | } |
3789 | | #endif /* HAVE_SECURE_RENEGOTIATION */ |
3790 | | |
3791 | | return ret; |
3792 | | } |
3793 | | |
3794 | | |
3795 | | /* TLS can call too */ |
3796 | | int StoreKeys(WOLFSSL* ssl, const byte* keyData, int side) |
3797 | 0 | { |
3798 | 0 | size_t sz; |
3799 | 0 | int i = 0; |
3800 | 0 | Keys* keys = &ssl->keys; |
3801 | | #ifdef WOLFSSL_DTLS |
3802 | | /* In case of DTLS, ssl->keys is updated here */ |
3803 | | int scr_copy = 0; |
3804 | | #endif |
3805 | |
|
3806 | | #ifdef HAVE_SECURE_RENEGOTIATION |
3807 | | if (ssl->secure_renegotiation && |
3808 | | ssl->secure_renegotiation->cache_status == SCR_CACHE_NEEDED) { |
3809 | | keys = &ssl->secure_renegotiation->tmp_keys; |
3810 | | #ifdef WOLFSSL_DTLS |
3811 | | if (ssl->options.dtls) { |
3812 | | /* epoch is incremented after StoreKeys is called */ |
3813 | | ssl->secure_renegotiation->tmp_keys.dtls_epoch = ssl->keys.dtls_epoch + 1; |
3814 | | /* we only need to copy keys on second and future renegotiations */ |
3815 | | if (ssl->keys.dtls_epoch > 1) |
3816 | | scr_copy = 1; |
3817 | | ssl->encrypt.src = KEYS_NOT_SET; |
3818 | | ssl->decrypt.src = KEYS_NOT_SET; |
3819 | | } |
3820 | | #endif |
3821 | | CacheStatusPP(ssl->secure_renegotiation); |
3822 | | } |
3823 | | #endif /* HAVE_SECURE_RENEGOTIATION */ |
3824 | |
|
3825 | | #ifdef WOLFSSL_MULTICAST |
3826 | | if (ssl->options.haveMcast) { |
3827 | | /* Use the same keys for encrypt and decrypt. */ |
3828 | | if (ssl->specs.cipher_type != aead) { |
3829 | | sz = ssl->specs.hash_size; |
3830 | | #ifndef WOLFSSL_AEAD_ONLY |
3831 | | |
3832 | | #ifdef WOLFSSL_DTLS |
3833 | | if (scr_copy) { |
3834 | | XMEMCPY(ssl->keys.client_write_MAC_secret, |
3835 | | keys->client_write_MAC_secret, sz); |
3836 | | XMEMCPY(ssl->keys.server_write_MAC_secret, |
3837 | | keys->server_write_MAC_secret, sz); |
3838 | | } |
3839 | | #endif |
3840 | | XMEMCPY(keys->client_write_MAC_secret,&keyData[i], sz); |
3841 | | XMEMCPY(keys->server_write_MAC_secret,&keyData[i], sz); |
3842 | | #endif |
3843 | | i += (int)sz; |
3844 | | } |
3845 | | sz = ssl->specs.key_size; |
3846 | | #ifdef WOLFSSL_DTLS |
3847 | | if (scr_copy) { |
3848 | | XMEMCPY(ssl->keys.client_write_key, |
3849 | | keys->client_write_key, sz); |
3850 | | XMEMCPY(ssl->keys.server_write_key, |
3851 | | keys->server_write_key, sz); |
3852 | | } |
3853 | | #endif |
3854 | | XMEMCPY(keys->client_write_key, &keyData[i], sz); |
3855 | | XMEMCPY(keys->server_write_key, &keyData[i], sz); |
3856 | | i += (int)sz; |
3857 | | |
3858 | | sz = ssl->specs.iv_size; |
3859 | | #ifdef WOLFSSL_DTLS |
3860 | | if (scr_copy) { |
3861 | | XMEMCPY(ssl->keys.client_write_IV, |
3862 | | keys->client_write_IV, sz); |
3863 | | XMEMCPY(ssl->keys.server_write_IV, |
3864 | | keys->server_write_IV, sz); |
3865 | | } |
3866 | | #endif |
3867 | | XMEMCPY(keys->client_write_IV, &keyData[i], sz); |
3868 | | XMEMCPY(keys->server_write_IV, &keyData[i], sz); |
3869 | | |
3870 | | #ifdef HAVE_AEAD |
3871 | | if (ssl->specs.cipher_type == aead) { |
3872 | | /* Initialize the AES-GCM/CCM explicit IV to a zero. */ |
3873 | | #ifdef WOLFSSL_DTLS |
3874 | | if (scr_copy) { |
3875 | | XMEMCPY(ssl->keys.aead_exp_IV, |
3876 | | keys->aead_exp_IV, AEAD_MAX_EXP_SZ); |
3877 | | } |
3878 | | #endif |
3879 | | XMEMSET(keys->aead_exp_IV, 0, AEAD_MAX_EXP_SZ); |
3880 | | } |
3881 | | #endif /* HAVE_AEAD */ |
3882 | | |
3883 | | return 0; |
3884 | | } |
3885 | | #endif /* WOLFSSL_MULTICAST */ |
3886 | |
|
3887 | 0 | if (ssl->specs.cipher_type != aead) { |
3888 | 0 | sz = ssl->specs.hash_size; |
3889 | 0 | if (side & PROVISION_CLIENT) { |
3890 | 0 | #ifndef WOLFSSL_AEAD_ONLY |
3891 | | #ifdef WOLFSSL_DTLS |
3892 | | if (scr_copy) |
3893 | | XMEMCPY(ssl->keys.client_write_MAC_secret, |
3894 | | keys->client_write_MAC_secret, sz); |
3895 | | #endif |
3896 | 0 | XMEMCPY(keys->client_write_MAC_secret,&keyData[i], sz); |
3897 | 0 | #endif |
3898 | 0 | i += (int)sz; |
3899 | 0 | } |
3900 | 0 | if (side & PROVISION_SERVER) { |
3901 | 0 | #ifndef WOLFSSL_AEAD_ONLY |
3902 | | #ifdef WOLFSSL_DTLS |
3903 | | if (scr_copy) |
3904 | | XMEMCPY(ssl->keys.server_write_MAC_secret, |
3905 | | keys->server_write_MAC_secret, sz); |
3906 | | #endif |
3907 | 0 | XMEMCPY(keys->server_write_MAC_secret,&keyData[i], sz); |
3908 | 0 | #endif |
3909 | 0 | i += (int)sz; |
3910 | 0 | } |
3911 | 0 | } |
3912 | 0 | sz = ssl->specs.key_size; |
3913 | 0 | if (side & PROVISION_CLIENT) { |
3914 | | #ifdef WOLFSSL_DTLS |
3915 | | if (scr_copy) |
3916 | | XMEMCPY(ssl->keys.client_write_key, |
3917 | | keys->client_write_key, sz); |
3918 | | #endif |
3919 | 0 | XMEMCPY(keys->client_write_key, &keyData[i], sz); |
3920 | 0 | i += (int)sz; |
3921 | 0 | } |
3922 | 0 | if (side & PROVISION_SERVER) { |
3923 | | #ifdef WOLFSSL_DTLS |
3924 | | if (scr_copy) |
3925 | | XMEMCPY(ssl->keys.server_write_key, |
3926 | | keys->server_write_key, sz); |
3927 | | #endif |
3928 | 0 | XMEMCPY(keys->server_write_key, &keyData[i], sz); |
3929 | 0 | i += (int)sz; |
3930 | 0 | } |
3931 | |
|
3932 | 0 | sz = ssl->specs.iv_size; |
3933 | 0 | if (side & PROVISION_CLIENT) { |
3934 | | #ifdef WOLFSSL_DTLS |
3935 | | if (scr_copy) |
3936 | | XMEMCPY(ssl->keys.client_write_IV, |
3937 | | keys->client_write_IV, sz); |
3938 | | #endif |
3939 | 0 | XMEMCPY(keys->client_write_IV, &keyData[i], sz); |
3940 | 0 | i += (int)sz; |
3941 | 0 | } |
3942 | 0 | if (side & PROVISION_SERVER) { |
3943 | | #ifdef WOLFSSL_DTLS |
3944 | | if (scr_copy) |
3945 | | XMEMCPY(ssl->keys.server_write_IV, |
3946 | | keys->server_write_IV, sz); |
3947 | | #endif |
3948 | 0 | XMEMCPY(keys->server_write_IV, &keyData[i], sz); |
3949 | 0 | } |
3950 | |
|
3951 | 0 | #ifdef HAVE_AEAD |
3952 | 0 | if (ssl->specs.cipher_type == aead) { |
3953 | | /* Initialize the AES-GCM/CCM explicit IV to a zero. */ |
3954 | | #ifdef WOLFSSL_DTLS |
3955 | | if (scr_copy) |
3956 | | XMEMMOVE(ssl->keys.aead_exp_IV, |
3957 | | keys->aead_exp_IV, AEAD_MAX_EXP_SZ); |
3958 | | #endif |
3959 | 0 | XMEMSET(keys->aead_exp_IV, 0, AEAD_MAX_EXP_SZ); |
3960 | 0 | } |
3961 | 0 | #endif |
3962 | |
|
3963 | 0 | return 0; |
3964 | 0 | } |
3965 | | |
3966 | | #if !defined(NO_OLD_TLS) || defined(HAVE_EXTENDED_MASTER) |
3967 | | static void CleanPreMaster(WOLFSSL* ssl) |
3968 | 10 | { |
3969 | | /* Wipe all of it, not the recorded length, which a caller can shrink |
3970 | | * after a larger write. A wc_MemZero_Check() here would alias the whole |
3971 | | * "SSL Arrays" entry, which starts at the same address. */ |
3972 | 10 | ForceZero(ssl->arrays->preMasterSecret, MAX_PREMASTER_SZ); |
3973 | 10 | ssl->arrays->preMasterSz = 0; |
3974 | 10 | } |
3975 | | #endif /* !NO_OLD_TLS || HAVE_EXTENDED_MASTER */ |
3976 | | |
3977 | | #ifndef NO_OLD_TLS |
3978 | | int DeriveKeys(WOLFSSL* ssl) |
3979 | | { |
3980 | | int length = 2 * ssl->specs.hash_size + |
3981 | | 2 * ssl->specs.key_size + |
3982 | | 2 * ssl->specs.iv_size; |
3983 | | int rounds = (length + WC_MD5_DIGEST_SIZE - 1 ) / WC_MD5_DIGEST_SIZE; |
3984 | | int ret = 0; |
3985 | | |
3986 | | #ifdef WOLFSSL_SMALL_STACK |
3987 | | byte* shaOutput; |
3988 | | byte* md5Input; |
3989 | | byte* shaInput; |
3990 | | byte* keyData; |
3991 | | wc_Md5* md5; |
3992 | | wc_Sha* sha; |
3993 | | #else |
3994 | | byte shaOutput[WC_SHA_DIGEST_SIZE]; |
3995 | | byte md5Input[SECRET_LEN + WC_SHA_DIGEST_SIZE]; |
3996 | | byte shaInput[KEY_PREFIX + SECRET_LEN + 2 * RAN_LEN]; |
3997 | | byte keyData[KEY_PREFIX * WC_MD5_DIGEST_SIZE]; |
3998 | | wc_Md5 md5[1]; |
3999 | | wc_Sha sha[1]; |
4000 | | #endif |
4001 | | |
4002 | | #ifdef WOLFSSL_SMALL_STACK |
4003 | | shaOutput = (byte*)XMALLOC(WC_SHA_DIGEST_SIZE, |
4004 | | NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4005 | | md5Input = (byte*)XMALLOC(SECRET_LEN + WC_SHA_DIGEST_SIZE, |
4006 | | NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4007 | | shaInput = (byte*)XMALLOC(KEY_PREFIX + SECRET_LEN + 2 * RAN_LEN, |
4008 | | NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4009 | | keyData = (byte*)XMALLOC(KEY_PREFIX * WC_MD5_DIGEST_SIZE, |
4010 | | NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4011 | | md5 = (wc_Md5*)XMALLOC(sizeof(wc_Md5), NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4012 | | sha = (wc_Sha*)XMALLOC(sizeof(wc_Sha), NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4013 | | |
4014 | | if (shaOutput == NULL || md5Input == NULL || shaInput == NULL || |
4015 | | keyData == NULL || md5 == NULL || sha == NULL) { |
4016 | | XFREE(shaOutput, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4017 | | XFREE(md5Input, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4018 | | XFREE(shaInput, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4019 | | XFREE(keyData, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4020 | | XFREE(md5, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4021 | | XFREE(sha, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4022 | | |
4023 | | return MEMORY_E; |
4024 | | } |
4025 | | #endif |
4026 | | |
4027 | | XMEMSET(shaOutput, 0, WC_SHA_DIGEST_SIZE); |
4028 | | ret = wc_InitMd5(md5); |
4029 | | if (ret == 0) { |
4030 | | ret = wc_InitSha(sha); |
4031 | | } |
4032 | | if (ret == 0) { |
4033 | | int i; |
4034 | | |
4035 | | XMEMCPY(md5Input, ssl->arrays->masterSecret, SECRET_LEN); |
4036 | | |
4037 | | for (i = 0; i < rounds; ++i) { |
4038 | | int j = i + 1; |
4039 | | int idx = j; |
4040 | | |
4041 | | if (!SetPrefix(shaInput, i)) { |
4042 | | ret = PREFIX_ERROR; |
4043 | | break; |
4044 | | } |
4045 | | |
4046 | | XMEMCPY(shaInput + idx, ssl->arrays->masterSecret, SECRET_LEN); |
4047 | | idx += SECRET_LEN; |
4048 | | XMEMCPY(shaInput + idx, ssl->arrays->serverRandom, RAN_LEN); |
4049 | | idx += RAN_LEN; |
4050 | | XMEMCPY(shaInput + idx, ssl->arrays->clientRandom, RAN_LEN); |
4051 | | if (ret == 0) { |
4052 | | ret = wc_ShaUpdate(sha, shaInput, |
4053 | | (KEY_PREFIX + SECRET_LEN + 2 * RAN_LEN) - KEY_PREFIX + |
4054 | | (word32)(j)); |
4055 | | } |
4056 | | if (ret == 0) { |
4057 | | ret = wc_ShaFinal(sha, shaOutput); |
4058 | | } |
4059 | | |
4060 | | XMEMCPY(md5Input + SECRET_LEN, shaOutput, WC_SHA_DIGEST_SIZE); |
4061 | | if (ret == 0) { |
4062 | | ret = wc_Md5Update(md5, md5Input, SECRET_LEN + WC_SHA_DIGEST_SIZE); |
4063 | | } |
4064 | | if (ret == 0) { |
4065 | | ret = wc_Md5Final(md5, keyData + i * WC_MD5_DIGEST_SIZE); |
4066 | | } |
4067 | | } |
4068 | | |
4069 | | if (ret == 0) |
4070 | | ret = StoreKeys(ssl, keyData, PROVISION_CLIENT_SERVER); |
4071 | | } |
4072 | | |
4073 | | #ifdef WOLFSSL_CHECK_MEM_ZERO |
4074 | | wc_MemZero_Add("DeriveKeys shaOutput", shaOutput, WC_SHA_DIGEST_SIZE); |
4075 | | wc_MemZero_Add("DeriveKeys md5Input", md5Input, |
4076 | | SECRET_LEN + WC_SHA_DIGEST_SIZE); |
4077 | | wc_MemZero_Add("DeriveKeys shaInput", shaInput, |
4078 | | KEY_PREFIX + SECRET_LEN + 2 * RAN_LEN); |
4079 | | wc_MemZero_Add("DeriveKeys keyData", keyData, |
4080 | | KEY_PREFIX * WC_MD5_DIGEST_SIZE); |
4081 | | #endif |
4082 | | ForceZero(shaOutput, WC_SHA_DIGEST_SIZE); |
4083 | | ForceZero(md5Input, SECRET_LEN + WC_SHA_DIGEST_SIZE); |
4084 | | ForceZero(shaInput, KEY_PREFIX + SECRET_LEN + 2 * RAN_LEN); |
4085 | | ForceZero(keyData, KEY_PREFIX * WC_MD5_DIGEST_SIZE); |
4086 | | #ifdef WOLFSSL_CHECK_MEM_ZERO |
4087 | | wc_MemZero_Check(shaOutput, WC_SHA_DIGEST_SIZE); |
4088 | | wc_MemZero_Check(md5Input, SECRET_LEN + WC_SHA_DIGEST_SIZE); |
4089 | | wc_MemZero_Check(shaInput, KEY_PREFIX + SECRET_LEN + 2 * RAN_LEN); |
4090 | | wc_MemZero_Check(keyData, KEY_PREFIX * WC_MD5_DIGEST_SIZE); |
4091 | | #endif |
4092 | | |
4093 | | WC_FREE_VAR_EX(shaOutput, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4094 | | WC_FREE_VAR_EX(md5Input, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4095 | | WC_FREE_VAR_EX(shaInput, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4096 | | WC_FREE_VAR_EX(keyData, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4097 | | WC_FREE_VAR_EX(md5, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4098 | | WC_FREE_VAR_EX(sha, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4099 | | |
4100 | | return ret; |
4101 | | } |
4102 | | |
4103 | | |
4104 | | /* Create and store the master secret see page 32, 6.1 */ |
4105 | | static int MakeSslMasterSecret(WOLFSSL* ssl) |
4106 | | { |
4107 | | int i, ret; |
4108 | | word32 idx; |
4109 | | word32 pmsSz = ssl->arrays->preMasterSz; |
4110 | | |
4111 | | #ifdef WOLFSSL_SMALL_STACK |
4112 | | byte* shaOutput; |
4113 | | byte* md5Input; |
4114 | | byte* shaInput; |
4115 | | wc_Md5* md5; |
4116 | | wc_Sha* sha; |
4117 | | #else |
4118 | | byte shaOutput[WC_SHA_DIGEST_SIZE]; |
4119 | | byte md5Input[MAX_PREMASTER_SZ + WC_SHA_DIGEST_SIZE]; |
4120 | | byte shaInput[PREFIX + MAX_PREMASTER_SZ + 2 * RAN_LEN]; |
4121 | | wc_Md5 md5[1]; |
4122 | | wc_Sha sha[1]; |
4123 | | #endif |
4124 | | |
4125 | | #ifdef SHOW_SECRETS |
4126 | | { |
4127 | | word32 j; |
4128 | | printf("pre master secret: "); |
4129 | | for (j = 0; j < pmsSz; j++) |
4130 | | printf("%02x", ssl->arrays->preMasterSecret[j]); |
4131 | | printf("\n"); |
4132 | | } |
4133 | | #endif |
4134 | | |
4135 | | #ifdef WOLFSSL_SMALL_STACK |
4136 | | shaOutput = (byte*)XMALLOC(WC_SHA_DIGEST_SIZE, |
4137 | | NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4138 | | md5Input = (byte*)XMALLOC(MAX_PREMASTER_SZ + WC_SHA_DIGEST_SIZE, |
4139 | | NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4140 | | shaInput = (byte*)XMALLOC(PREFIX + MAX_PREMASTER_SZ + 2 * RAN_LEN, |
4141 | | NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4142 | | md5 = (wc_Md5*)XMALLOC(sizeof(wc_Md5), NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4143 | | sha = (wc_Sha*)XMALLOC(sizeof(wc_Sha), NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4144 | | |
4145 | | if (shaOutput == NULL || md5Input == NULL || shaInput == NULL || |
4146 | | md5 == NULL || sha == NULL) { |
4147 | | XFREE(shaOutput, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4148 | | XFREE(md5Input, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4149 | | XFREE(shaInput, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4150 | | XFREE(md5, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4151 | | XFREE(sha, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4152 | | |
4153 | | return MEMORY_E; |
4154 | | } |
4155 | | #endif |
4156 | | #ifdef WOLFSSL_CHECK_MEM_ZERO |
4157 | | wc_MemZero_Add("MakeSslMasterSecret md5Input", md5Input, |
4158 | | MAX_PREMASTER_SZ + WC_SHA_DIGEST_SIZE); |
4159 | | wc_MemZero_Add("MakeSslMasterSecret shaInput", shaInput, |
4160 | | PREFIX + MAX_PREMASTER_SZ + 2 * RAN_LEN); |
4161 | | wc_MemZero_Add("MakeSslMasterSecret shaOutput", shaOutput, |
4162 | | WC_SHA_DIGEST_SIZE); |
4163 | | #endif |
4164 | | |
4165 | | XMEMSET(shaOutput, 0, WC_SHA_DIGEST_SIZE); |
4166 | | |
4167 | | ret = wc_InitMd5(md5); |
4168 | | if (ret == 0) { |
4169 | | ret = wc_InitSha(sha); |
4170 | | } |
4171 | | if (ret == 0) { |
4172 | | XMEMCPY(md5Input, ssl->arrays->preMasterSecret, pmsSz); |
4173 | | |
4174 | | for (i = 0; i < MASTER_ROUNDS; ++i) { |
4175 | | byte prefix[KEY_PREFIX]; /* only need PREFIX bytes but static */ |
4176 | | if (!SetPrefix(prefix, i)) { /* analysis thinks will overrun */ |
4177 | | ret = PREFIX_ERROR; |
4178 | | break; |
4179 | | } |
4180 | | |
4181 | | idx = 0; |
4182 | | XMEMCPY(shaInput, prefix, (size_t)(i + 1)); |
4183 | | idx += (word32)(i + 1); |
4184 | | |
4185 | | XMEMCPY(shaInput + idx, ssl->arrays->preMasterSecret, pmsSz); |
4186 | | idx += pmsSz; |
4187 | | XMEMCPY(shaInput + idx, ssl->arrays->clientRandom, RAN_LEN); |
4188 | | idx += RAN_LEN; |
4189 | | XMEMCPY(shaInput + idx, ssl->arrays->serverRandom, RAN_LEN); |
4190 | | idx += RAN_LEN; |
4191 | | if (ret == 0) { |
4192 | | ret = wc_ShaUpdate(sha, shaInput, idx); |
4193 | | } |
4194 | | if (ret == 0) { |
4195 | | ret = wc_ShaFinal(sha, shaOutput); |
4196 | | } |
4197 | | idx = pmsSz; /* preSz */ |
4198 | | XMEMCPY(md5Input + idx, shaOutput, WC_SHA_DIGEST_SIZE); |
4199 | | idx += WC_SHA_DIGEST_SIZE; |
4200 | | if (ret == 0) { |
4201 | | ret = wc_Md5Update(md5, md5Input, idx); |
4202 | | } |
4203 | | if (ret == 0) { |
4204 | | ret = wc_Md5Final(md5, |
4205 | | &ssl->arrays->masterSecret[i * WC_MD5_DIGEST_SIZE]); |
4206 | | } |
4207 | | } |
4208 | | |
4209 | | #ifdef SHOW_SECRETS |
4210 | | { |
4211 | | word32 j; |
4212 | | printf("master secret: "); |
4213 | | for (j = 0; j < SECRET_LEN; j++) |
4214 | | printf("%02x", ssl->arrays->masterSecret[j]); |
4215 | | printf("\n"); |
4216 | | } |
4217 | | #endif |
4218 | | |
4219 | | if (ret == 0) |
4220 | | ret = DeriveKeys(ssl); |
4221 | | } |
4222 | | |
4223 | | ForceZero(md5Input, MAX_PREMASTER_SZ + WC_SHA_DIGEST_SIZE); |
4224 | | ForceZero(shaInput, PREFIX + MAX_PREMASTER_SZ + 2 * RAN_LEN); |
4225 | | ForceZero(shaOutput, WC_SHA_DIGEST_SIZE); |
4226 | | #ifdef WOLFSSL_CHECK_MEM_ZERO |
4227 | | wc_MemZero_Check(md5Input, MAX_PREMASTER_SZ + WC_SHA_DIGEST_SIZE); |
4228 | | wc_MemZero_Check(shaInput, PREFIX + MAX_PREMASTER_SZ + 2 * RAN_LEN); |
4229 | | wc_MemZero_Check(shaOutput, WC_SHA_DIGEST_SIZE); |
4230 | | #endif |
4231 | | |
4232 | | WC_FREE_VAR_EX(shaOutput, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4233 | | WC_FREE_VAR_EX(md5Input, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4234 | | WC_FREE_VAR_EX(shaInput, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4235 | | WC_FREE_VAR_EX(md5, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4236 | | WC_FREE_VAR_EX(sha, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
4237 | | |
4238 | | CleanPreMaster(ssl); |
4239 | | |
4240 | | return ret; |
4241 | | } |
4242 | | #endif |
4243 | | |
4244 | | |
4245 | | /* Master wrapper, doesn't use SSL stack space in TLS mode */ |
4246 | | int MakeMasterSecret(WOLFSSL* ssl) |
4247 | 0 | { |
4248 | 0 | #ifdef HAVE_EXTENDED_MASTER |
4249 | | /* User requires EMS but it was not negotiated: abort rather than derive |
4250 | | * a standard master secret (RFC 7627). */ |
4251 | 0 | if (ssl->options.requireEMS && !ssl->options.haveEMS) { |
4252 | 0 | WOLFSSL_MSG("EMS required but not negotiated with peer"); |
4253 | 0 | SendAlert(ssl, alert_fatal, handshake_failure); |
4254 | 0 | WOLFSSL_ERROR_VERBOSE(EXT_MASTER_SECRET_NEEDED_E); |
4255 | 0 | CleanPreMaster(ssl); |
4256 | 0 | return EXT_MASTER_SECRET_NEEDED_E; |
4257 | 0 | } |
4258 | 0 | #endif |
4259 | | /* append secret to premaster : premaster | SerSi | CliSi */ |
4260 | | #ifndef NO_OLD_TLS |
4261 | | if (ssl->options.tls) return MakeTlsMasterSecret(ssl); |
4262 | | return MakeSslMasterSecret(ssl); |
4263 | | #elif !defined(WOLFSSL_NO_TLS12) && !defined(NO_TLS) |
4264 | 0 | return MakeTlsMasterSecret(ssl); |
4265 | | #else |
4266 | | (void)ssl; |
4267 | | return 0; |
4268 | | #endif |
4269 | 0 | } |
4270 | | |
4271 | | #endif /* !WOLFCRYPT_ONLY && !NO_TLS */ |