tls.h
Go to the documentation of this file.
1 /**
2  * @file tls.h
3  * @brief TLS (Transport Layer Security)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2022 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneSSL Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.2.0
29  **/
30 
31 #ifndef _TLS_H
32 #define _TLS_H
33 
34 //Forward declaration of TlsContext structure
35 struct _TlsContext;
36 #define TlsContext struct _TlsContext
37 
38 //Forward declaration of TlsEncryptionEngine structure
40 #define TlsEncryptionEngine struct _TlsEncryptionEngine
41 
42 //Dependencies
43 #include "os_port.h"
44 #include "core/crypto.h"
45 #include "tls_config.h"
46 #include "tls_legacy.h"
47 #include "tls13_misc.h"
48 #include "dtls_misc.h"
49 #include "mac/hmac.h"
50 #include "aead/aead_algorithms.h"
51 #include "pkc/rsa.h"
52 #include "pkc/dsa.h"
53 #include "ecc/ecdsa.h"
54 #include "pkc/dh.h"
55 #include "ecc/ecdh.h"
56 #include "pkix/x509_common.h"
57 
58 
59 /*
60  * CycloneSSL Open is licensed under GPL version 2. In particular:
61  *
62  * - If you link your program to CycloneSSL Open, the result is a derivative
63  * work that can only be distributed under the same GPL license terms.
64  *
65  * - If additions or changes to CycloneSSL Open are made, the result is a
66  * derivative work that can only be distributed under the same license terms.
67  *
68  * - The GPL license requires that you make the source code available to
69  * whoever you make the binary available to.
70  *
71  * - If you sell or distribute a hardware product that runs CycloneSSL Open,
72  * the GPL license requires you to provide public and full access to all
73  * source code on a nondiscriminatory basis.
74  *
75  * If you fully understand and accept the terms of the GPL license, then edit
76  * the os_port_config.h header and add the following directive:
77  *
78  * #define GPL_LICENSE_TERMS_ACCEPTED
79  */
80 
81 #ifndef GPL_LICENSE_TERMS_ACCEPTED
82  #error Before compiling CycloneSSL Open, you must accept the terms of the GPL license
83 #endif
84 
85 //Version string
86 #define CYCLONE_SSL_VERSION_STRING "2.2.0"
87 //Major version
88 #define CYCLONE_SSL_MAJOR_VERSION 2
89 //Minor version
90 #define CYCLONE_SSL_MINOR_VERSION 2
91 //Revision number
92 #define CYCLONE_SSL_REV_NUMBER 0
93 
94 //TLS version numbers
95 #define SSL_VERSION_3_0 0x0300
96 #define TLS_VERSION_1_0 0x0301
97 #define TLS_VERSION_1_1 0x0302
98 #define TLS_VERSION_1_2 0x0303
99 #define TLS_VERSION_1_3 0x0304
100 
101 //TLS support
102 #ifndef TLS_SUPPORT
103  #define TLS_SUPPORT ENABLED
104 #elif (TLS_SUPPORT != ENABLED && TLS_SUPPORT != DISABLED)
105  #error TLS_SUPPORT parameter is not valid
106 #endif
107 
108 //Client mode of operation
109 #ifndef TLS_CLIENT_SUPPORT
110  #define TLS_CLIENT_SUPPORT ENABLED
111 #elif (TLS_CLIENT_SUPPORT != ENABLED && TLS_CLIENT_SUPPORT != DISABLED)
112  #error TLS_CLIENT_SUPPORT parameter is not valid
113 #endif
114 
115 //Server mode of operation
116 #ifndef TLS_SERVER_SUPPORT
117  #define TLS_SERVER_SUPPORT ENABLED
118 #elif (TLS_SERVER_SUPPORT != ENABLED && TLS_SERVER_SUPPORT != DISABLED)
119  #error TLS_SERVER_SUPPORT parameter is not valid
120 #endif
121 
122 //Minimum TLS version that can be negotiated
123 #ifndef TLS_MIN_VERSION
124  #define TLS_MIN_VERSION TLS_VERSION_1_2
125 #elif (TLS_MIN_VERSION < TLS_VERSION_1_0)
126  #error TLS_MIN_VERSION parameter is not valid
127 #endif
128 
129 //Maximum TLS version that can be negotiated
130 #ifndef TLS_MAX_VERSION
131  #define TLS_MAX_VERSION TLS_VERSION_1_3
132 #elif (TLS_MAX_VERSION > TLS_VERSION_1_3 || TLS_MAX_VERSION < TLS_MIN_VERSION)
133  #error TLS_MAX_VERSION parameter is not valid
134 #endif
135 
136 //Session resumption mechanism
137 #ifndef TLS_SESSION_RESUME_SUPPORT
138  #define TLS_SESSION_RESUME_SUPPORT ENABLED
139 #elif (TLS_SESSION_RESUME_SUPPORT != ENABLED && TLS_SESSION_RESUME_SUPPORT != DISABLED)
140  #error TLS_SESSION_RESUME_SUPPORT parameter is not valid
141 #endif
142 
143 //Lifetime of session cache entries
144 #ifndef TLS_SESSION_CACHE_LIFETIME
145  #define TLS_SESSION_CACHE_LIFETIME 3600000
146 #elif (TLS_SESSION_CACHE_LIFETIME < 1000)
147  #error TLS_SESSION_CACHE_LIFETIME parameter is not valid
148 #endif
149 
150 //Session ticket mechanism
151 #ifndef TLS_TICKET_SUPPORT
152  #define TLS_TICKET_SUPPORT DISABLED
153 #elif (TLS_TICKET_SUPPORT != ENABLED && TLS_TICKET_SUPPORT != DISABLED)
154  #error TLS_TICKET_SUPPORT parameter is not valid
155 #endif
156 
157 //Maximum size for session tickets
158 #ifndef TLS_MAX_TICKET_SIZE
159  #define TLS_MAX_TICKET_SIZE 1024
160 #elif (TLS_MAX_TICKET_SIZE < 32)
161  #error TLS_MAX_TICKET_SIZE parameter is not valid
162 #endif
163 
164 //Lifetime of session tickets
165 #ifndef TLS_TICKET_LIFETIME
166  #define TLS_TICKET_LIFETIME 3600000
167 #elif (TLS_TICKET_LIFETIME < 0)
168  #error TLS_TICKET_LIFETIME parameter is not valid
169 #endif
170 
171 //SNI (Server Name Indication) extension
172 #ifndef TLS_SNI_SUPPORT
173  #define TLS_SNI_SUPPORT ENABLED
174 #elif (TLS_SNI_SUPPORT != ENABLED && TLS_SNI_SUPPORT != DISABLED)
175  #error TLS_SNI_SUPPORT parameter is not valid
176 #endif
177 
178 //Maximum Fragment Length extension
179 #ifndef TLS_MAX_FRAG_LEN_SUPPORT
180  #define TLS_MAX_FRAG_LEN_SUPPORT DISABLED
181 #elif (TLS_MAX_FRAG_LEN_SUPPORT != ENABLED && TLS_MAX_FRAG_LEN_SUPPORT != DISABLED)
182  #error TLS_MAX_FRAG_LEN_SUPPORT parameter is not valid
183 #endif
184 
185 //Record Size Limit extension
186 #ifndef TLS_RECORD_SIZE_LIMIT_SUPPORT
187  #define TLS_RECORD_SIZE_LIMIT_SUPPORT ENABLED
188 #elif (TLS_RECORD_SIZE_LIMIT_SUPPORT != ENABLED && TLS_RECORD_SIZE_LIMIT_SUPPORT != DISABLED)
189  #error TLS_RECORD_SIZE_LIMIT_SUPPORT parameter is not valid
190 #endif
191 
192 //ALPN (Application-Layer Protocol Negotiation) extension
193 #ifndef TLS_ALPN_SUPPORT
194  #define TLS_ALPN_SUPPORT DISABLED
195 #elif (TLS_ALPN_SUPPORT != ENABLED && TLS_ALPN_SUPPORT != DISABLED)
196  #error TLS_ALPN_SUPPORT parameter is not valid
197 #endif
198 
199 //Extended Master Secret extension
200 #ifndef TLS_EXT_MASTER_SECRET_SUPPORT
201  #define TLS_EXT_MASTER_SECRET_SUPPORT ENABLED
202 #elif (TLS_EXT_MASTER_SECRET_SUPPORT != ENABLED && TLS_EXT_MASTER_SECRET_SUPPORT != DISABLED)
203  #error TLS_EXT_MASTER_SECRET_SUPPORT parameter is not valid
204 #endif
205 
206 //ClientHello Padding extension
207 #ifndef TLS_CLIENT_HELLO_PADDING_SUPPORT
208  #define TLS_CLIENT_HELLO_PADDING_SUPPORT ENABLED
209 #elif (TLS_CLIENT_HELLO_PADDING_SUPPORT != ENABLED && TLS_CLIENT_HELLO_PADDING_SUPPORT != DISABLED)
210  #error TLS_CLIENT_HELLO_PADDING_SUPPORT parameter is not valid
211 #endif
212 
213 //Signature Algorithms Certificate extension
214 #ifndef TLS_SIGN_ALGOS_CERT_SUPPORT
215  #define TLS_SIGN_ALGOS_CERT_SUPPORT DISABLED
216 #elif (TLS_SIGN_ALGOS_CERT_SUPPORT != ENABLED && TLS_SIGN_ALGOS_CERT_SUPPORT != DISABLED)
217  #error TLS_SIGN_ALGOS_CERT_SUPPORT parameter is not valid
218 #endif
219 
220 //RPK (Raw Public Key) support
221 #ifndef TLS_RAW_PUBLIC_KEY_SUPPORT
222  #define TLS_RAW_PUBLIC_KEY_SUPPORT DISABLED
223 #elif (TLS_RAW_PUBLIC_KEY_SUPPORT != ENABLED && TLS_RAW_PUBLIC_KEY_SUPPORT != DISABLED)
224  #error TLS_RAW_PUBLIC_KEY_SUPPORT parameter is not valid
225 #endif
226 
227 //Secure renegotiation support
228 #ifndef TLS_SECURE_RENEGOTIATION_SUPPORT
229  #define TLS_SECURE_RENEGOTIATION_SUPPORT DISABLED
230 #elif (TLS_SECURE_RENEGOTIATION_SUPPORT != ENABLED && TLS_SECURE_RENEGOTIATION_SUPPORT != DISABLED)
231  #error TLS_SECURE_RENEGOTIATION_SUPPORT parameter is not valid
232 #endif
233 
234 //Fallback SCSV support
235 #ifndef TLS_FALLBACK_SCSV_SUPPORT
236  #define TLS_FALLBACK_SCSV_SUPPORT DISABLED
237 #elif (TLS_FALLBACK_SCSV_SUPPORT != ENABLED && TLS_FALLBACK_SCSV_SUPPORT != DISABLED)
238  #error TLS_FALLBACK_SCSV_SUPPORT parameter is not valid
239 #endif
240 
241 //ECC callback functions
242 #ifndef TLS_ECC_CALLBACK_SUPPORT
243  #define TLS_ECC_CALLBACK_SUPPORT DISABLED
244 #elif (TLS_ECC_CALLBACK_SUPPORT != ENABLED && TLS_ECC_CALLBACK_SUPPORT != DISABLED)
245  #error TLS_ECC_CALLBACK_SUPPORT parameter is not valid
246 #endif
247 
248 //Maximum number of certificates the end entity can load
249 #ifndef TLS_MAX_CERTIFICATES
250  #define TLS_MAX_CERTIFICATES 3
251 #elif (TLS_MAX_CERTIFICATES < 1)
252  #error TLS_MAX_CERTIFICATES parameter is not valid
253 #endif
254 
255 //RSA key exchange support
256 #ifndef TLS_RSA_KE_SUPPORT
257  #define TLS_RSA_KE_SUPPORT ENABLED
258 #elif (TLS_RSA_KE_SUPPORT != ENABLED && TLS_RSA_KE_SUPPORT != DISABLED)
259  #error TLS_RSA_KE_SUPPORT parameter is not valid
260 #endif
261 
262 //DHE_RSA key exchange support
263 #ifndef TLS_DHE_RSA_KE_SUPPORT
264  #define TLS_DHE_RSA_KE_SUPPORT ENABLED
265 #elif (TLS_DHE_RSA_KE_SUPPORT != ENABLED && TLS_DHE_RSA_KE_SUPPORT != DISABLED)
266  #error TLS_DHE_RSA_KE_SUPPORT parameter is not valid
267 #endif
268 
269 //DHE_DSS key exchange support
270 #ifndef TLS_DHE_DSS_KE_SUPPORT
271  #define TLS_DHE_DSS_KE_SUPPORT DISABLED
272 #elif (TLS_DHE_DSS_KE_SUPPORT != ENABLED && TLS_DHE_DSS_KE_SUPPORT != DISABLED)
273  #error TLS_DHE_DSS_KE_SUPPORT parameter is not valid
274 #endif
275 
276 //DH_anon key exchange support (insecure)
277 #ifndef TLS_DH_ANON_KE_SUPPORT
278  #define TLS_DH_ANON_KE_SUPPORT DISABLED
279 #elif (TLS_DH_ANON_KE_SUPPORT != ENABLED && TLS_DH_ANON_KE_SUPPORT != DISABLED)
280  #error TLS_DH_ANON_KE_SUPPORT parameter is not valid
281 #endif
282 
283 //ECDHE_RSA key exchange support
284 #ifndef TLS_ECDHE_RSA_KE_SUPPORT
285  #define TLS_ECDHE_RSA_KE_SUPPORT ENABLED
286 #elif (TLS_ECDHE_RSA_KE_SUPPORT != ENABLED && TLS_ECDHE_RSA_KE_SUPPORT != DISABLED)
287  #error TLS_ECDHE_RSA_KE_SUPPORT parameter is not valid
288 #endif
289 
290 //ECDHE_ECDSA key exchange support
291 #ifndef TLS_ECDHE_ECDSA_KE_SUPPORT
292  #define TLS_ECDHE_ECDSA_KE_SUPPORT ENABLED
293 #elif (TLS_ECDHE_ECDSA_KE_SUPPORT != ENABLED && TLS_ECDHE_ECDSA_KE_SUPPORT != DISABLED)
294  #error TLS_ECDHE_ECDSA_KE_SUPPORT parameter is not valid
295 #endif
296 
297 //ECDH_anon key exchange support (insecure)
298 #ifndef TLS_ECDH_ANON_KE_SUPPORT
299  #define TLS_ECDH_ANON_KE_SUPPORT DISABLED
300 #elif (TLS_ECDH_ANON_KE_SUPPORT != ENABLED && TLS_ECDH_ANON_KE_SUPPORT != DISABLED)
301  #error TLS_ECDH_ANON_KE_SUPPORT parameter is not valid
302 #endif
303 
304 //PSK key exchange support
305 #ifndef TLS_PSK_KE_SUPPORT
306  #define TLS_PSK_KE_SUPPORT DISABLED
307 #elif (TLS_PSK_KE_SUPPORT != ENABLED && TLS_PSK_KE_SUPPORT != DISABLED)
308  #error TLS_PSK_KE_SUPPORT parameter is not valid
309 #endif
310 
311 //RSA_PSK key exchange support
312 #ifndef TLS_RSA_PSK_KE_SUPPORT
313  #define TLS_RSA_PSK_KE_SUPPORT DISABLED
314 #elif (TLS_RSA_PSK_KE_SUPPORT != ENABLED && TLS_RSA_PSK_KE_SUPPORT != DISABLED)
315  #error TLS_RSA_PSK_KE_SUPPORT parameter is not valid
316 #endif
317 
318 //DHE_PSK key exchange support
319 #ifndef TLS_DHE_PSK_KE_SUPPORT
320  #define TLS_DHE_PSK_KE_SUPPORT DISABLED
321 #elif (TLS_DHE_PSK_KE_SUPPORT != ENABLED && TLS_DHE_PSK_KE_SUPPORT != DISABLED)
322  #error TLS_DHE_PSK_KE_SUPPORT parameter is not valid
323 #endif
324 
325 //ECDHE_PSK key exchange support
326 #ifndef TLS_ECDHE_PSK_KE_SUPPORT
327  #define TLS_ECDHE_PSK_KE_SUPPORT DISABLED
328 #elif (TLS_ECDHE_PSK_KE_SUPPORT != ENABLED && TLS_ECDHE_PSK_KE_SUPPORT != DISABLED)
329  #error TLS_ECDHE_PSK_KE_SUPPORT parameter is not valid
330 #endif
331 
332 //RSA signature capability
333 #ifndef TLS_RSA_SIGN_SUPPORT
334  #define TLS_RSA_SIGN_SUPPORT ENABLED
335 #elif (TLS_RSA_SIGN_SUPPORT != ENABLED && TLS_RSA_SIGN_SUPPORT != DISABLED)
336  #error TLS_RSA_SIGN_SUPPORT parameter is not valid
337 #endif
338 
339 //RSA-PSS signature capability
340 #ifndef TLS_RSA_PSS_SIGN_SUPPORT
341  #define TLS_RSA_PSS_SIGN_SUPPORT ENABLED
342 #elif (TLS_RSA_PSS_SIGN_SUPPORT != ENABLED && TLS_RSA_PSS_SIGN_SUPPORT != DISABLED)
343  #error TLS_RSA_PSS_SIGN_SUPPORT parameter is not valid
344 #endif
345 
346 //DSA signature capability
347 #ifndef TLS_DSA_SIGN_SUPPORT
348  #define TLS_DSA_SIGN_SUPPORT DISABLED
349 #elif (TLS_DSA_SIGN_SUPPORT != ENABLED && TLS_DSA_SIGN_SUPPORT != DISABLED)
350  #error TLS_DSA_SIGN_SUPPORT parameter is not valid
351 #endif
352 
353 //ECDSA signature capability
354 #ifndef TLS_ECDSA_SIGN_SUPPORT
355  #define TLS_ECDSA_SIGN_SUPPORT ENABLED
356 #elif (TLS_ECDSA_SIGN_SUPPORT != ENABLED && TLS_ECDSA_SIGN_SUPPORT != DISABLED)
357  #error TLS_ECDSA_SIGN_SUPPORT parameter is not valid
358 #endif
359 
360 //EdDSA signature capability
361 #ifndef TLS_EDDSA_SIGN_SUPPORT
362  #define TLS_EDDSA_SIGN_SUPPORT DISABLED
363 #elif (TLS_EDDSA_SIGN_SUPPORT != ENABLED && TLS_EDDSA_SIGN_SUPPORT != DISABLED)
364  #error TLS_EDDSA_SIGN_SUPPORT parameter is not valid
365 #endif
366 
367 //NULL cipher support (insecure)
368 #ifndef TLS_NULL_CIPHER_SUPPORT
369  #define TLS_NULL_CIPHER_SUPPORT DISABLED
370 #elif (TLS_NULL_CIPHER_SUPPORT != ENABLED && TLS_NULL_CIPHER_SUPPORT != DISABLED)
371  #error TLS_NULL_CIPHER_SUPPORT parameter is not valid
372 #endif
373 
374 //Stream cipher support
375 #ifndef TLS_STREAM_CIPHER_SUPPORT
376  #define TLS_STREAM_CIPHER_SUPPORT DISABLED
377 #elif (TLS_STREAM_CIPHER_SUPPORT != ENABLED && TLS_STREAM_CIPHER_SUPPORT != DISABLED)
378  #error TLS_STREAM_CIPHER_SUPPORT parameter is not valid
379 #endif
380 
381 //CBC block cipher support
382 #ifndef TLS_CBC_CIPHER_SUPPORT
383  #define TLS_CBC_CIPHER_SUPPORT ENABLED
384 #elif (TLS_CBC_CIPHER_SUPPORT != ENABLED && TLS_CBC_CIPHER_SUPPORT != DISABLED)
385  #error TLS_CBC_CIPHER_SUPPORT parameter is not valid
386 #endif
387 
388 //CCM AEAD support
389 #ifndef TLS_CCM_CIPHER_SUPPORT
390  #define TLS_CCM_CIPHER_SUPPORT DISABLED
391 #elif (TLS_CCM_CIPHER_SUPPORT != ENABLED && TLS_CCM_CIPHER_SUPPORT != DISABLED)
392  #error TLS_CCM_CIPHER_SUPPORT parameter is not valid
393 #endif
394 
395 //CCM_8 AEAD support
396 #ifndef TLS_CCM_8_CIPHER_SUPPORT
397  #define TLS_CCM_8_CIPHER_SUPPORT DISABLED
398 #elif (TLS_CCM_8_CIPHER_SUPPORT != ENABLED && TLS_CCM_8_CIPHER_SUPPORT != DISABLED)
399  #error TLS_CCM_8_CIPHER_SUPPORT parameter is not valid
400 #endif
401 
402 //GCM AEAD support
403 #ifndef TLS_GCM_CIPHER_SUPPORT
404  #define TLS_GCM_CIPHER_SUPPORT ENABLED
405 #elif (TLS_GCM_CIPHER_SUPPORT != ENABLED && TLS_GCM_CIPHER_SUPPORT != DISABLED)
406  #error TLS_GCM_CIPHER_SUPPORT parameter is not valid
407 #endif
408 
409 //ChaCha20Poly1305 AEAD support
410 #ifndef TLS_CHACHA20_POLY1305_SUPPORT
411  #define TLS_CHACHA20_POLY1305_SUPPORT DISABLED
412 #elif (TLS_CHACHA20_POLY1305_SUPPORT != ENABLED && TLS_CHACHA20_POLY1305_SUPPORT != DISABLED)
413  #error TLS_CHACHA20_POLY1305_SUPPORT parameter is not valid
414 #endif
415 
416 //RC4 cipher support (insecure)
417 #ifndef TLS_RC4_SUPPORT
418  #define TLS_RC4_SUPPORT DISABLED
419 #elif (TLS_RC4_SUPPORT != ENABLED && TLS_RC4_SUPPORT != DISABLED)
420  #error TLS_RC4_SUPPORT parameter is not valid
421 #endif
422 
423 //IDEA cipher support (insecure)
424 #ifndef TLS_IDEA_SUPPORT
425  #define TLS_IDEA_SUPPORT DISABLED
426 #elif (TLS_IDEA_SUPPORT != ENABLED && TLS_IDEA_SUPPORT != DISABLED)
427  #error TLS_IDEA_SUPPORT parameter is not valid
428 #endif
429 
430 //DES cipher support (insecure)
431 #ifndef TLS_DES_SUPPORT
432  #define TLS_DES_SUPPORT DISABLED
433 #elif (TLS_DES_SUPPORT != ENABLED && TLS_DES_SUPPORT != DISABLED)
434  #error TLS_DES_SUPPORT parameter is not valid
435 #endif
436 
437 //Triple DES cipher support (weak)
438 #ifndef TLS_3DES_SUPPORT
439  #define TLS_3DES_SUPPORT DISABLED
440 #elif (TLS_3DES_SUPPORT != ENABLED && TLS_3DES_SUPPORT != DISABLED)
441  #error TLS_3DES_SUPPORT parameter is not valid
442 #endif
443 
444 //AES 128-bit cipher support
445 #ifndef TLS_AES_128_SUPPORT
446  #define TLS_AES_128_SUPPORT ENABLED
447 #elif (TLS_AES_128_SUPPORT != ENABLED && TLS_AES_128_SUPPORT != DISABLED)
448  #error TLS_AES_128_SUPPORT parameter is not valid
449 #endif
450 
451 //AES 256-bit cipher support
452 #ifndef TLS_AES_256_SUPPORT
453  #define TLS_AES_256_SUPPORT ENABLED
454 #elif (TLS_AES_256_SUPPORT != ENABLED && TLS_AES_256_SUPPORT != DISABLED)
455  #error TLS_AES_256_SUPPORT parameter is not valid
456 #endif
457 
458 //Camellia 128-bit cipher support
459 #ifndef TLS_CAMELLIA_128_SUPPORT
460  #define TLS_CAMELLIA_128_SUPPORT DISABLED
461 #elif (TLS_CAMELLIA_128_SUPPORT != ENABLED && TLS_CAMELLIA_128_SUPPORT != DISABLED)
462  #error TLS_CAMELLIA_128_SUPPORT parameter is not valid
463 #endif
464 
465 //Camellia 256-bit cipher support
466 #ifndef TLS_CAMELLIA_256_SUPPORT
467  #define TLS_CAMELLIA_256_SUPPORT DISABLED
468 #elif (TLS_CAMELLIA_256_SUPPORT != ENABLED && TLS_CAMELLIA_256_SUPPORT != DISABLED)
469  #error TLS_CAMELLIA_256_SUPPORT parameter is not valid
470 #endif
471 
472 //ARIA 128-bit cipher support
473 #ifndef TLS_ARIA_128_SUPPORT
474  #define TLS_ARIA_128_SUPPORT DISABLED
475 #elif (TLS_ARIA_128_SUPPORT != ENABLED && TLS_ARIA_128_SUPPORT != DISABLED)
476  #error TLS_ARIA_128_SUPPORT parameter is not valid
477 #endif
478 
479 //ARIA 256-bit cipher support
480 #ifndef TLS_ARIA_256_SUPPORT
481  #define TLS_ARIA_256_SUPPORT DISABLED
482 #elif (TLS_ARIA_256_SUPPORT != ENABLED && TLS_ARIA_256_SUPPORT != DISABLED)
483  #error TLS_ARIA_256_SUPPORT parameter is not valid
484 #endif
485 
486 //SEED cipher support
487 #ifndef TLS_SEED_SUPPORT
488  #define TLS_SEED_SUPPORT DISABLED
489 #elif (TLS_SEED_SUPPORT != ENABLED && TLS_SEED_SUPPORT != DISABLED)
490  #error TLS_SEED_SUPPORT parameter is not valid
491 #endif
492 
493 //MD5 hash support (insecure)
494 #ifndef TLS_MD5_SUPPORT
495  #define TLS_MD5_SUPPORT DISABLED
496 #elif (TLS_MD5_SUPPORT != ENABLED && TLS_MD5_SUPPORT != DISABLED)
497  #error TLS_MD5_SUPPORT parameter is not valid
498 #endif
499 
500 //SHA-1 hash support (weak)
501 #ifndef TLS_SHA1_SUPPORT
502  #define TLS_SHA1_SUPPORT ENABLED
503 #elif (TLS_SHA1_SUPPORT != ENABLED && TLS_SHA1_SUPPORT != DISABLED)
504  #error TLS_SHA1_SUPPORT parameter is not valid
505 #endif
506 
507 //SHA-224 hash support (weak)
508 #ifndef TLS_SHA224_SUPPORT
509  #define TLS_SHA224_SUPPORT DISABLED
510 #elif (TLS_SHA224_SUPPORT != ENABLED && TLS_SHA224_SUPPORT != DISABLED)
511  #error TLS_SHA224_SUPPORT parameter is not valid
512 #endif
513 
514 //SHA-256 hash support
515 #ifndef TLS_SHA256_SUPPORT
516  #define TLS_SHA256_SUPPORT ENABLED
517 #elif (TLS_SHA256_SUPPORT != ENABLED && TLS_SHA256_SUPPORT != DISABLED)
518  #error TLS_SHA256_SUPPORT parameter is not valid
519 #endif
520 
521 //SHA-384 hash support
522 #ifndef TLS_SHA384_SUPPORT
523  #define TLS_SHA384_SUPPORT ENABLED
524 #elif (TLS_SHA384_SUPPORT != ENABLED && TLS_SHA384_SUPPORT != DISABLED)
525  #error TLS_SHA384_SUPPORT parameter is not valid
526 #endif
527 
528 //SHA-512 hash support
529 #ifndef TLS_SHA512_SUPPORT
530  #define TLS_SHA512_SUPPORT DISABLED
531 #elif (TLS_SHA512_SUPPORT != ENABLED && TLS_SHA512_SUPPORT != DISABLED)
532  #error TLS_SHA512_SUPPORT parameter is not valid
533 #endif
534 
535 //FFDHE key exchange mechanism
536 #ifndef TLS_FFDHE_SUPPORT
537  #define TLS_FFDHE_SUPPORT DISABLED
538 #elif (TLS_FFDHE_SUPPORT != ENABLED && TLS_FFDHE_SUPPORT != DISABLED)
539  #error TLS_FFDHE_SUPPORT parameter is not valid
540 #endif
541 
542 //ffdhe2048 group support
543 #ifndef TLS_FFDHE2048_SUPPORT
544  #define TLS_FFDHE2048_SUPPORT ENABLED
545 #elif (TLS_FFDHE2048_SUPPORT != ENABLED && TLS_FFDHE2048_SUPPORT != DISABLED)
546  #error TLS_FFDHE2048_SUPPORT parameter is not valid
547 #endif
548 
549 //ffdhe3072 group support
550 #ifndef TLS_FFDHE3072_SUPPORT
551  #define TLS_FFDHE3072_SUPPORT DISABLED
552 #elif (TLS_FFDHE3072_SUPPORT != ENABLED && TLS_FFDHE3072_SUPPORT != DISABLED)
553  #error TLS_FFDHE3072_SUPPORT parameter is not valid
554 #endif
555 
556 //ffdhe4096 group support
557 #ifndef TLS_FFDHE4096_SUPPORT
558  #define TLS_FFDHE4096_SUPPORT DISABLED
559 #elif (TLS_FFDHE4096_SUPPORT != ENABLED && TLS_FFDHE4096_SUPPORT != DISABLED)
560  #error TLS_FFDHE4096_SUPPORT parameter is not valid
561 #endif
562 
563 //secp160k1 elliptic curve support (weak)
564 #ifndef TLS_SECP160K1_SUPPORT
565  #define TLS_SECP160K1_SUPPORT DISABLED
566 #elif (TLS_SECP160K1_SUPPORT != ENABLED && TLS_SECP160K1_SUPPORT != DISABLED)
567  #error TLS_SECP160K1_SUPPORT parameter is not valid
568 #endif
569 
570 //secp160r1 elliptic curve support (weak)
571 #ifndef TLS_SECP160R1_SUPPORT
572  #define TLS_SECP160R1_SUPPORT DISABLED
573 #elif (TLS_SECP160R1_SUPPORT != ENABLED && TLS_SECP160R1_SUPPORT != DISABLED)
574  #error TLS_SECP160R1_SUPPORT parameter is not valid
575 #endif
576 
577 //secp160r2 elliptic curve support (weak)
578 #ifndef TLS_SECP160R2_SUPPORT
579  #define TLS_SECP160R2_SUPPORT DISABLED
580 #elif (TLS_SECP160R2_SUPPORT != ENABLED && TLS_SECP160R2_SUPPORT != DISABLED)
581  #error TLS_SECP160R2_SUPPORT parameter is not valid
582 #endif
583 
584 //secp192k1 elliptic curve support
585 #ifndef TLS_SECP192K1_SUPPORT
586  #define TLS_SECP192K1_SUPPORT DISABLED
587 #elif (TLS_SECP192K1_SUPPORT != ENABLED && TLS_SECP192K1_SUPPORT != DISABLED)
588  #error TLS_SECP192K1_SUPPORT parameter is not valid
589 #endif
590 
591 //secp192r1 elliptic curve support (NIST P-192)
592 #ifndef TLS_SECP192R1_SUPPORT
593  #define TLS_SECP192R1_SUPPORT DISABLED
594 #elif (TLS_SECP192R1_SUPPORT != ENABLED && TLS_SECP192R1_SUPPORT != DISABLED)
595  #error TLS_SECP192R1_SUPPORT parameter is not valid
596 #endif
597 
598 //secp224k1 elliptic curve support
599 #ifndef TLS_SECP224K1_SUPPORT
600  #define TLS_SECP224K1_SUPPORT DISABLED
601 #elif (TLS_SECP224K1_SUPPORT != ENABLED && TLS_SECP224K1_SUPPORT != DISABLED)
602  #error TLS_SECP224K1_SUPPORT parameter is not valid
603 #endif
604 
605 //secp224r1 elliptic curve support (NIST P-224)
606 #ifndef TLS_SECP224R1_SUPPORT
607  #define TLS_SECP224R1_SUPPORT DISABLED
608 #elif (TLS_SECP224R1_SUPPORT != ENABLED && TLS_SECP224R1_SUPPORT != DISABLED)
609  #error TLS_SECP224R1_SUPPORT parameter is not valid
610 #endif
611 
612 //secp256k1 elliptic curve support
613 #ifndef TLS_SECP256K1_SUPPORT
614  #define TLS_SECP256K1_SUPPORT DISABLED
615 #elif (TLS_SECP256K1_SUPPORT != ENABLED && TLS_SECP256K1_SUPPORT != DISABLED)
616  #error TLS_SECP256K1_SUPPORT parameter is not valid
617 #endif
618 
619 //secp256r1 elliptic curve support (NIST P-256)
620 #ifndef TLS_SECP256R1_SUPPORT
621  #define TLS_SECP256R1_SUPPORT ENABLED
622 #elif (TLS_SECP256R1_SUPPORT != ENABLED && TLS_SECP256R1_SUPPORT != DISABLED)
623  #error TLS_SECP256R1_SUPPORT parameter is not valid
624 #endif
625 
626 //secp384r1 elliptic curve support (NIST P-384)
627 #ifndef TLS_SECP384R1_SUPPORT
628  #define TLS_SECP384R1_SUPPORT ENABLED
629 #elif (TLS_SECP384R1_SUPPORT != ENABLED && TLS_SECP384R1_SUPPORT != DISABLED)
630  #error TLS_SECP384R1_SUPPORT parameter is not valid
631 #endif
632 
633 //secp521r1 elliptic curve support (NIST P-521)
634 #ifndef TLS_SECP521R1_SUPPORT
635  #define TLS_SECP521R1_SUPPORT DISABLED
636 #elif (TLS_SECP521R1_SUPPORT != ENABLED && TLS_SECP521R1_SUPPORT != DISABLED)
637  #error TLS_SECP521R1_SUPPORT parameter is not valid
638 #endif
639 
640 //brainpoolP256r1 elliptic curve support
641 #ifndef TLS_BRAINPOOLP256R1_SUPPORT
642  #define TLS_BRAINPOOLP256R1_SUPPORT DISABLED
643 #elif (TLS_BRAINPOOLP256R1_SUPPORT != ENABLED && TLS_BRAINPOOLP256R1_SUPPORT != DISABLED)
644  #error TLS_BRAINPOOLP256R1_SUPPORT parameter is not valid
645 #endif
646 
647 //brainpoolP384r1 elliptic curve support
648 #ifndef TLS_BRAINPOOLP384R1_SUPPORT
649  #define TLS_BRAINPOOLP384R1_SUPPORT DISABLED
650 #elif (TLS_BRAINPOOLP384R1_SUPPORT != ENABLED && TLS_BRAINPOOLP384R1_SUPPORT != DISABLED)
651  #error TLS_BRAINPOOLP384R1_SUPPORT parameter is not valid
652 #endif
653 
654 //brainpoolP512r1 elliptic curve support
655 #ifndef TLS_BRAINPOOLP512R1_SUPPORT
656  #define TLS_BRAINPOOLP512R1_SUPPORT DISABLED
657 #elif (TLS_BRAINPOOLP512R1_SUPPORT != ENABLED && TLS_BRAINPOOLP512R1_SUPPORT != DISABLED)
658  #error TLS_BRAINPOOLP512R1_SUPPORT parameter is not valid
659 #endif
660 
661 //Curve25519 elliptic curve support
662 #ifndef TLS_X25519_SUPPORT
663  #define TLS_X25519_SUPPORT DISABLED
664 #elif (TLS_X25519_SUPPORT != ENABLED && TLS_X25519_SUPPORT != DISABLED)
665  #error TLS_X25519_SUPPORT parameter is not valid
666 #endif
667 
668 //Curve448 elliptic curve support
669 #ifndef TLS_X448_SUPPORT
670  #define TLS_X448_SUPPORT DISABLED
671 #elif (TLS_X448_SUPPORT != ENABLED && TLS_X448_SUPPORT != DISABLED)
672  #error TLS_X448_SUPPORT parameter is not valid
673 #endif
674 
675 //Ed25519 elliptic curve support
676 #ifndef TLS_ED25519_SUPPORT
677  #define TLS_ED25519_SUPPORT ENABLED
678 #elif (TLS_ED25519_SUPPORT != ENABLED && TLS_ED25519_SUPPORT != DISABLED)
679  #error TLS_ED25519_SUPPORT parameter is not valid
680 #endif
681 
682 //Ed448 elliptic curve support
683 #ifndef TLS_ED448_SUPPORT
684  #define TLS_ED448_SUPPORT DISABLED
685 #elif (TLS_ED448_SUPPORT != ENABLED && TLS_ED448_SUPPORT != DISABLED)
686  #error TLS_ED448_SUPPORT parameter is not valid
687 #endif
688 
689 //Certificate key usage verification
690 #ifndef TLS_CERT_KEY_USAGE_SUPPORT
691  #define TLS_CERT_KEY_USAGE_SUPPORT ENABLED
692 #elif (TLS_CERT_KEY_USAGE_SUPPORT != ENABLED && TLS_CERT_KEY_USAGE_SUPPORT != DISABLED)
693  #error TLS_CERT_KEY_USAGE_SUPPORT parameter is not valid
694 #endif
695 
696 //Key logging (for debugging purpose only)
697 #ifndef TLS_KEY_LOG_SUPPORT
698  #define TLS_KEY_LOG_SUPPORT DISABLED
699 #elif (TLS_KEY_LOG_SUPPORT != ENABLED && TLS_KEY_LOG_SUPPORT != DISABLED)
700  #error TLS_KEY_LOG_SUPPORT parameter is not valid
701 #endif
702 
703 //Maximum acceptable length for server names
704 #ifndef TLS_MAX_SERVER_NAME_LEN
705  #define TLS_MAX_SERVER_NAME_LEN 255
706 #elif (TLS_MAX_SERVER_NAME_LEN < 1)
707  #error TLS_MAX_SERVER_NAME_LEN parameter is not valid
708 #endif
709 
710 //Minimum acceptable size for Diffie-Hellman prime modulus
711 #ifndef TLS_MIN_DH_MODULUS_SIZE
712  #define TLS_MIN_DH_MODULUS_SIZE 1024
713 #elif (TLS_MIN_DH_MODULUS_SIZE < 512)
714  #error TLS_MIN_DH_MODULUS_SIZE parameter is not valid
715 #endif
716 
717 //Maximum acceptable size for Diffie-Hellman prime modulus
718 #ifndef TLS_MAX_DH_MODULUS_SIZE
719  #define TLS_MAX_DH_MODULUS_SIZE 2048
720 #elif (TLS_MAX_DH_MODULUS_SIZE < TLS_MIN_DH_MODULUS_SIZE)
721  #error TLS_MAX_DH_MODULUS_SIZE parameter is not valid
722 #endif
723 
724 //Minimum acceptable size for RSA modulus
725 #ifndef TLS_MIN_RSA_MODULUS_SIZE
726  #define TLS_MIN_RSA_MODULUS_SIZE 1024
727 #elif (TLS_MIN_RSA_MODULUS_SIZE < 512)
728  #error TLS_MIN_RSA_MODULUS_SIZE parameter is not valid
729 #endif
730 
731 //Maximum acceptable size for RSA modulus
732 #ifndef TLS_MAX_RSA_MODULUS_SIZE
733  #define TLS_MAX_RSA_MODULUS_SIZE 4096
734 #elif (TLS_MAX_RSA_MODULUS_SIZE < TLS_MIN_RSA_MODULUS_SIZE)
735  #error TLS_MAX_RSA_MODULUS_SIZE parameter is not valid
736 #endif
737 
738 //Minimum acceptable size for DSA prime modulus
739 #ifndef TLS_MIN_DSA_MODULUS_SIZE
740  #define TLS_MIN_DSA_MODULUS_SIZE 1024
741 #elif (TLS_MIN_DSA_MODULUS_SIZE < 512)
742  #error TLS_MIN_DSA_MODULUS_SIZE parameter is not valid
743 #endif
744 
745 //Maximum acceptable size for DSA prime modulus
746 #ifndef TLS_MAX_DSA_MODULUS_SIZE
747  #define TLS_MAX_DSA_MODULUS_SIZE 4096
748 #elif (TLS_MAX_DSA_MODULUS_SIZE < TLS_MIN_DSA_MODULUS_SIZE)
749  #error TLS_MAX_DSA_MODULUS_SIZE parameter is not valid
750 #endif
751 
752 //Master secret size
753 #ifndef TLS_MASTER_SECRET_SIZE
754  #define TLS_MASTER_SECRET_SIZE 48
755 #elif (TLS_MASTER_SECRET_SIZE < 48)
756  #error TLS_MASTER_SECRET_SIZE parameter is not valid
757 #endif
758 
759 //Maximum size for premaster secret
760 #ifndef TLS_PREMASTER_SECRET_SIZE
761  #define TLS_PREMASTER_SECRET_SIZE (TLS_MAX_DH_MODULUS_SIZE / 8)
762 #elif (TLS_PREMASTER_SECRET_SIZE < 48)
763  #error TLS_PREMASTER_SECRET_SIZE parameter is not valid
764 #endif
765 
766 //Maximum number of consecutive warning alerts
767 #ifndef TLS_MAX_WARNING_ALERTS
768  #define TLS_MAX_WARNING_ALERTS 5
769 #elif (TLS_MAX_WARNING_ALERTS < 0)
770  #error TLS_MAX_WARNING_ALERTS parameter is not valid
771 #endif
772 
773 //Maximum number of consecutive empty records
774 #ifndef TLS_MAX_EMPTY_RECORDS
775  #define TLS_MAX_EMPTY_RECORDS 10
776 #elif (TLS_MAX_EMPTY_RECORDS < 0)
777  #error TLS_MAX_EMPTY_RECORDS parameter is not valid
778 #endif
779 
780 //Maximum number of consecutive ChangeCipherSpec messages
781 #ifndef TLS_MAX_CHANGE_CIPHER_SPEC_MESSAGES
782  #define TLS_MAX_CHANGE_CIPHER_SPEC_MESSAGES 5
783 #elif (TLS_MAX_CHANGE_CIPHER_SPEC_MESSAGES < 0)
784  #error TLS_MAX_CHANGE_CIPHER_SPEC_MESSAGES parameter is not valid
785 #endif
786 
787 //Maximum number of consecutive KeyUpdate messages
788 #ifndef TLS_MAX_KEY_UPDATE_MESSAGES
789  #define TLS_MAX_KEY_UPDATE_MESSAGES 5
790 #elif (TLS_MAX_KEY_UPDATE_MESSAGES < 0)
791  #error TLS_MAX_KEY_UPDATE_MESSAGES parameter is not valid
792 #endif
793 
794 //Application specific context (TLS context)
795 #ifndef TLS_PRIVATE_CONTEXT
796  #define TLS_PRIVATE_CONTEXT
797 #endif
798 
799 //Application specific context (encryption engine)
800 #ifndef TLS_PRIVATE_ENCRYPTION_ENGINE
801  #define TLS_PRIVATE_ENCRYPTION_ENGINE
802 #endif
803 
804 //Allocate memory block
805 #ifndef tlsAllocMem
806  #define tlsAllocMem(size) osAllocMem(size)
807 #endif
808 
809 //Deallocate memory block
810 #ifndef tlsFreeMem
811  #define tlsFreeMem(p) osFreeMem(p)
812 #endif
813 
814 //Support for Diffie-Hellman?
815 #if ((TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_2) && \
816  (TLS_DH_ANON_KE_SUPPORT == ENABLED || TLS_DHE_RSA_KE_SUPPORT == ENABLED || \
817  TLS_DHE_DSS_KE_SUPPORT == ENABLED || TLS_DHE_PSK_KE_SUPPORT == ENABLED))
818  #define TLS_DH_SUPPORT ENABLED
819 #elif ((TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3) && \
820  (TLS13_DHE_KE_SUPPORT == ENABLED || TLS13_PSK_DHE_KE_SUPPORT == ENABLED))
821  #define TLS_DH_SUPPORT ENABLED
822 #else
823  #define TLS_DH_SUPPORT DISABLED
824 #endif
825 
826 //Support for ECDH?
827 #if ((TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_2) && \
828  (TLS_ECDH_ANON_KE_SUPPORT == ENABLED || TLS_ECDHE_RSA_KE_SUPPORT == ENABLED || \
829  TLS_ECDHE_ECDSA_KE_SUPPORT == ENABLED || TLS_ECDHE_PSK_KE_SUPPORT == ENABLED))
830  #define TLS_ECDH_SUPPORT ENABLED
831 #elif ((TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3) && \
832  (TLS13_ECDHE_KE_SUPPORT == ENABLED || TLS13_PSK_ECDHE_KE_SUPPORT == ENABLED))
833  #define TLS_ECDH_SUPPORT ENABLED
834 #else
835  #define TLS_ECDH_SUPPORT DISABLED
836 #endif
837 
838 //Support for RSA?
839 #if ((TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_2) && \
840  (TLS_RSA_SIGN_SUPPORT == ENABLED || TLS_RSA_PSS_SIGN_SUPPORT == ENABLED || \
841  TLS_RSA_KE_SUPPORT == ENABLED || TLS_DHE_RSA_KE_SUPPORT == ENABLED || \
842  TLS_ECDHE_RSA_KE_SUPPORT == ENABLED || TLS_RSA_PSK_KE_SUPPORT == ENABLED))
843  #define TLS_RSA_SUPPORT ENABLED
844 #elif ((TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3) && \
845  (TLS_RSA_SIGN_SUPPORT == ENABLED || TLS_RSA_PSS_SIGN_SUPPORT == ENABLED))
846  #define TLS_RSA_SUPPORT ENABLED
847 #else
848  #define TLS_RSA_SUPPORT DISABLED
849 #endif
850 
851 //Support for PSK?
852 #if ((TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_2) && \
853  (TLS_PSK_KE_SUPPORT == ENABLED || TLS_RSA_PSK_KE_SUPPORT == ENABLED || \
854  TLS_DHE_PSK_KE_SUPPORT == ENABLED || TLS_ECDHE_PSK_KE_SUPPORT == ENABLED))
855  #define TLS_PSK_SUPPORT ENABLED
856 #elif ((TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3) && \
857  (TLS13_PSK_KE_SUPPORT == ENABLED || TLS13_PSK_DHE_KE_SUPPORT == ENABLED || \
858  TLS13_PSK_ECDHE_KE_SUPPORT == ENABLED))
859  #define TLS_PSK_SUPPORT ENABLED
860 #else
861  #define TLS_PSK_SUPPORT DISABLED
862 #endif
863 
864 //Maximum size for HKDF digests
865 #if (TLS_SHA384_SUPPORT == ENABLED)
866  #define TLS_MAX_HKDF_DIGEST_SIZE 48
867 #else
868  #define TLS_MAX_HKDF_DIGEST_SIZE 32
869 #endif
870 
871 //Bind TLS to a particular socket
872 #define tlsSetSocket(context, socket) tlsSetSocketCallbacks(context, \
873  (TlsSocketSendCallback) socketSend, (TlsSocketReceiveCallback) socketReceive, \
874  (TlsSocketHandle) socket)
875 
876 //Minimum plaintext record length
877 #define TLS_MIN_RECORD_LENGTH 512
878 //Maximum plaintext record length
879 #define TLS_MAX_RECORD_LENGTH 16384
880 //Data overhead caused by record encryption
881 #define TLS_MAX_RECORD_OVERHEAD 512
882 //Size of client and server random values
883 #define TLS_RANDOM_SIZE 32
884 
885 //C++ guard
886 #ifdef __cplusplus
887 extern "C" {
888 #endif
889 
890 
891 /**
892  * @brief TLS transport protocols
893  **/
894 
895 typedef enum
896 {
900 
901 
902 /**
903  * @brief TLS connection end
904  **/
905 
906 typedef enum
907 {
911 
912 
913 /**
914  * @brief Client authentication mode
915  **/
916 
917 typedef enum
918 {
923 
924 
925 /**
926  * @brief Early data status
927  **/
928 
929 typedef enum
930 {
934 
935 
936 /**
937  * @brief Flags used by read and write functions
938  **/
939 
940 typedef enum
941 {
942  TLS_FLAG_PEEK = 0x0200,
948  TLS_FLAG_DELAY = 0x8000
950 
951 
952 //The TLS_FLAG_BREAK macro causes the read function to stop reading
953 //data whenever the specified break character is encountered
954 #define TLS_FLAG_BREAK(c) (TLS_FLAG_BREAK_CHAR | LSB(c))
955 
956 
957 /**
958  * @brief Content type
959  **/
960 
961 typedef enum
962 {
970  TLS_TYPE_ACK = 26
972 
973 
974 /**
975  * @brief Handshake message type
976  **/
977 
978 typedef enum
979 {
1003  TLS_TYPE_MESSAGE_HASH = 254
1005 
1006 
1007 /**
1008  * @brief Alert level
1009  **/
1010 
1011 typedef enum
1012 {
1015 } TlsAlertLevel;
1016 
1017 
1018 /**
1019  * @brief Alert description
1020  **/
1021 
1022 typedef enum
1023 {
1060 
1061 
1062 /**
1063  * @brief Compression methods
1064  **/
1065 
1066 typedef enum
1067 {
1071 
1072 
1073 /**
1074  * @brief Key exchange methods
1075  **/
1076 
1077 typedef enum
1078 {
1104 
1105 
1106 /**
1107  * @brief Certificate formats
1108  **/
1109 
1110 typedef enum
1111 {
1117 
1118 
1119 /**
1120  * @brief Certificate types
1121  **/
1122 
1123 typedef enum
1124 {
1138  TLS_CERT_RSA_PSS_SIGN = 256, //For internal use only
1139  TLS_CERT_ED25519_SIGN = 257, //For internal use only
1140  TLS_CERT_ED448_SIGN = 258 //For internal use only
1142 
1143 
1144 /**
1145  * @brief Hash algorithms
1146  **/
1147 
1148 typedef enum
1149 {
1159 
1160 
1161 /**
1162  * @brief Signature algorithms
1163  **/
1164 
1165 typedef enum
1166 {
1185 
1186 
1187 /**
1188  * @brief TLS extension types
1189  **/
1190 
1191 typedef enum
1192 {
1246 
1247 
1248 /**
1249  * @brief Name type
1250  **/
1251 
1252 typedef enum
1253 {
1256 
1257 
1258 /**
1259  * @brief Maximum fragment length
1260  **/
1261 
1262 typedef enum
1263 {
1269 
1270 
1271 /**
1272  * @brief Named groups
1273  **/
1274 
1275 typedef enum
1276 {
1278  TLS_GROUP_SECT163K1 = 1, //RFC 4492
1279  TLS_GROUP_SECT163R1 = 2, //RFC 4492
1280  TLS_GROUP_SECT163R2 = 3, //RFC 4492
1281  TLS_GROUP_SECT193R1 = 4, //RFC 4492
1282  TLS_GROUP_SECT193R2 = 5, //RFC 4492
1283  TLS_GROUP_SECT233K1 = 6, //RFC 4492
1284  TLS_GROUP_SECT233R1 = 7, //RFC 4492
1285  TLS_GROUP_SECT239K1 = 8, //RFC 4492
1286  TLS_GROUP_SECT283K1 = 9, //RFC 4492
1287  TLS_GROUP_SECT283R1 = 10, //RFC 4492
1288  TLS_GROUP_SECT409K1 = 11, //RFC 4492
1289  TLS_GROUP_SECT409R1 = 12, //RFC 4492
1290  TLS_GROUP_SECT571K1 = 13, //RFC 4492
1291  TLS_GROUP_SECT571R1 = 14, //RFC 4492
1292  TLS_GROUP_SECP160K1 = 15, //RFC 4492
1293  TLS_GROUP_SECP160R1 = 16, //RFC 4492
1294  TLS_GROUP_SECP160R2 = 17, //RFC 4492
1295  TLS_GROUP_SECP192K1 = 18, //RFC 4492
1296  TLS_GROUP_SECP192R1 = 19, //RFC 4492
1297  TLS_GROUP_SECP224K1 = 20, //RFC 4492
1298  TLS_GROUP_SECP224R1 = 21, //RFC 4492
1299  TLS_GROUP_SECP256K1 = 22, //RFC 4492
1300  TLS_GROUP_SECP256R1 = 23, //RFC 4492
1301  TLS_GROUP_SECP384R1 = 24, //RFC 4492
1302  TLS_GROUP_SECP521R1 = 25, //RFC 4492
1303  TLS_GROUP_BRAINPOOLP256R1 = 26, //RFC 7027
1304  TLS_GROUP_BRAINPOOLP384R1 = 27, //RFC 7027
1305  TLS_GROUP_BRAINPOOLP512R1 = 28, //RFC 7027
1306  TLS_GROUP_ECDH_X25519 = 29, //RFC 8422
1307  TLS_GROUP_ECDH_X448 = 30, //RFC 8422
1311  TLS_GROUP_GC256A = 34, //RFC 9189
1312  TLS_GROUP_GC256B = 35, //RFC 9189
1313  TLS_GROUP_GC256C = 36, //RFC 9189
1314  TLS_GROUP_GC256D = 37, //RFC 9189
1315  TLS_GROUP_GC512A = 38, //RFC 9189
1316  TLS_GROUP_GC512B = 39, //RFC 9189
1317  TLS_GROUP_GC512C = 40, //RFC 9189
1318  TLS_GROUP_SM2 = 41, //RFC 8998
1319  TLS_GROUP_FFDHE2048 = 256, //RFC 7919
1320  TLS_GROUP_FFDHE3072 = 257, //RFC 7919
1321  TLS_GROUP_FFDHE4096 = 258, //RFC 7919
1322  TLS_GROUP_FFDHE6144 = 259, //RFC 7919
1323  TLS_GROUP_FFDHE8192 = 260, //RFC 7919
1324  TLS_GROUP_FFDHE_MAX = 511, //RFC 7919
1326  TLS_GROUP_EXPLICIT_CHAR2_CURVE = 65282 //RFC 4492
1328 
1329 
1330 /**
1331  * @brief EC point formats
1332  **/
1333 
1334 typedef enum
1335 {
1340 
1341 
1342 /**
1343  * @brief EC curve types
1344  **/
1345 
1346 typedef enum
1347 {
1352 
1353 
1354 /**
1355  * @brief TLS FSM states
1356  **/
1357 
1358 typedef enum
1359 {
1392  TLS_STATE_CLOSED = 32
1394 
1395 
1396 //CodeWarrior or Win32 compiler?
1397 #if defined(__CWCC__) || defined(_WIN32)
1398  #pragma pack(push, 1)
1399 #endif
1400 
1401 
1402 /**
1403  * @brief Sequence number
1404  **/
1405 
1406 typedef __start_packed struct
1407 {
1408  uint8_t b[8];
1410 
1411 
1412 /**
1413  * @brief Cipher suites
1414  **/
1415 
1416 typedef __start_packed struct
1417 {
1418  uint16_t length; //0-1
1419  uint16_t value[]; //2
1421 
1422 
1423 /**
1424  * @brief Compression methods
1425  **/
1426 
1427 typedef __start_packed struct
1428 {
1429  uint8_t length; //0
1430  uint8_t value[]; //1
1432 
1433 
1434 /**
1435  * @brief Signature algorithm
1436  **/
1437 
1438 typedef __start_packed struct
1439 {
1440  uint8_t hash; //0
1441  uint8_t signature; //1
1443 
1444 
1445 /**
1446  * @brief List of signature algorithms
1447  **/
1448 
1449 typedef __start_packed struct
1450 {
1451  uint16_t length; //0-1
1452  TlsSignHashAlgo value[]; //2
1454 
1455 
1456 /**
1457  * @brief List of certificates
1458  **/
1459 
1460 typedef __start_packed struct
1461 {
1462  uint8_t length[3]; //0-2
1463  uint8_t value[]; //3
1465 
1466 
1467 /**
1468  * @brief List of certificate authorities
1469  **/
1470 
1471 typedef __start_packed struct
1472 {
1473  uint16_t length; //0-1
1474  uint8_t value[]; //2
1476 
1477 
1478 /**
1479  * @brief TLS extension
1480  **/
1481 
1482 typedef __start_packed struct
1483 {
1484  uint16_t type; //0-1
1485  uint16_t length; //2-3
1486  uint8_t value[]; //4
1488 
1489 
1490 /**
1491  * @brief List of TLS extensions
1492  **/
1493 
1494 typedef __start_packed struct
1495 {
1496  uint16_t length; //0-1
1497  uint8_t value[]; //2
1499 
1500 
1501 /**
1502  * @brief List of supported versions
1503  **/
1504 
1505 typedef __start_packed struct
1506 {
1507  uint8_t length; //0
1508  uint16_t value[]; //1
1510 
1511 
1512 /**
1513  * @brief Server name
1514  **/
1515 
1516 typedef __start_packed struct
1517 {
1518  uint8_t type; //0
1519  uint16_t length; //1-2
1522 
1523 
1524 /**
1525  * @brief List of server names
1526  **/
1527 
1528 typedef __start_packed struct
1529 {
1530  uint16_t length; //0-1
1531  uint8_t value[]; //2
1533 
1534 
1535 /**
1536  * @brief Protocol name
1537  **/
1538 
1539 typedef __start_packed struct
1540 {
1541  uint8_t length; //0
1542  char_t value[]; //1
1544 
1545 
1546 /**
1547  * @brief List of protocol names
1548  **/
1549 
1550 typedef __start_packed struct
1551 {
1552  uint16_t length; //0-1
1553  uint8_t value[]; //2
1555 
1556 
1557 /**
1558  * @brief List of supported groups
1559  **/
1560 
1561 typedef __start_packed struct
1562 {
1563  uint16_t length; //0-1
1564  uint16_t value[]; //2
1566 
1567 
1568 /**
1569  * @brief List of supported EC point formats
1570  **/
1571 
1572 typedef __start_packed struct
1573 {
1574  uint8_t length; //0
1575  uint8_t value[]; //1
1577 
1578 
1579 /**
1580  * @brief List of supported certificate types
1581  **/
1582 
1583 typedef __start_packed struct
1584 {
1585  uint8_t length; //0
1586  uint8_t value[]; //1
1588 
1589 
1590 /**
1591  * @brief Renegotiated connection
1592  **/
1593 
1594 typedef __start_packed struct
1595 {
1596  uint8_t length; //0
1597  uint8_t value[]; //1
1599 
1600 
1601 /**
1602  * @brief PSK identity
1603  **/
1604 
1605 typedef __start_packed struct
1606 {
1607  uint16_t length; //0-1
1608  uint8_t value[]; //2
1610 
1611 
1612 /**
1613  * @brief PSK identity hint
1614  **/
1615 
1616 typedef __start_packed struct
1617 {
1618  uint16_t length; //0-1
1619  uint8_t value[]; //2
1621 
1622 
1623 /**
1624  * @brief Digitally-signed element (TLS 1.0 and TLS 1.1)
1625  **/
1626 
1627 typedef __start_packed struct
1628 {
1629  uint16_t length; //0-1
1630  uint8_t value[]; //2
1632 
1633 
1634 /**
1635  * @brief Digitally-signed element (TLS 1.2)
1636  **/
1637 
1638 typedef __start_packed struct
1639 {
1641  uint16_t length; //2-3
1642  uint8_t value[]; //4
1644 
1645 
1646 /**
1647  * @brief TLS record
1648  **/
1649 
1650 typedef __start_packed struct
1651 {
1652  uint8_t type; //0
1653  uint16_t version; //1-2
1654  uint16_t length; //3-4
1655  uint8_t data[]; //5
1657 
1658 
1659 /**
1660  * @brief TLS handshake message
1661  **/
1662 
1663 typedef __start_packed struct
1664 {
1665  uint8_t msgType; //0
1666  uint8_t length[3]; //1-3
1667  uint8_t data[]; //4
1669 
1670 
1671 /**
1672  * @brief HelloRequest message
1673  **/
1674 
1675 typedef void TlsHelloRequest;
1676 
1677 
1678 /**
1679  * @brief ClientHello message
1680  **/
1681 
1682 typedef __start_packed struct
1683 {
1684  uint16_t clientVersion; //0-1
1685  uint8_t random[32]; //2-33
1686  uint8_t sessionIdLen; //34
1687  uint8_t sessionId[]; //35
1689 
1690 
1691 /**
1692  * @brief ServerHello message
1693  **/
1694 
1695 typedef __start_packed struct
1696 {
1697  uint16_t serverVersion; //0-1
1698  uint8_t random[32]; //2-33
1699  uint8_t sessionIdLen; //34
1700  uint8_t sessionId[]; //35
1702 
1703 
1704 /**
1705  * @brief Certificate message
1706  **/
1707 
1708 typedef void TlsCertificate;
1709 
1710 
1711 /**
1712  * @brief ServerKeyExchange message
1713  **/
1714 
1716 
1717 
1718 /**
1719  * @brief CertificateRequest message
1720  **/
1721 
1722 typedef __start_packed struct
1723 {
1724  uint8_t certificateTypesLen; //0
1725  uint8_t certificateTypes[]; //1
1727 
1728 
1729 /**
1730  * @brief ServerHelloDone message
1731  **/
1732 
1733 typedef void TlsServerHelloDone;
1734 
1735 
1736 /**
1737  * @brief ClientKeyExchange message
1738  **/
1739 
1741 
1742 
1743 /**
1744  * @brief CertificateVerify message
1745  **/
1746 
1748 
1749 
1750 /**
1751  * @brief NewSessionTicket message
1752  **/
1753 
1754 typedef __start_packed struct
1755 {
1756  uint32_t ticketLifetimeHint; //0-3
1757  uint16_t ticketLen; //4-5
1758  uint8_t ticket[]; //6
1760 
1761 
1762 /**
1763  * @brief Finished message
1764  **/
1765 
1766 typedef void TlsFinished;
1767 
1768 
1769 /**
1770  * @brief ChangeCipherSpec message
1771  **/
1772 
1773 typedef __start_packed struct
1774 {
1775  uint8_t type; //0
1777 
1778 
1779 /**
1780  * @brief Alert message
1781  **/
1782 
1783 typedef __start_packed struct
1784 {
1785  uint8_t level; //0
1786  uint8_t description; //1
1788 
1789 
1790 /**
1791  * @brief Session state information
1792  **/
1793 
1794 typedef __start_packed struct
1795 {
1796  uint16_t version; ///<Protocol version
1797  uint16_t cipherSuite; ///<Cipher suite identifier
1798  uint8_t secret[48]; ///<Master secret
1799  systime_t ticketTimestamp; ///<Timestamp to manage ticket lifetime
1800  uint32_t ticketLifetime; ///<Lifetime of the ticket
1801 #if (TLS_EXT_MASTER_SECRET_SUPPORT == ENABLED)
1802  bool_t extendedMasterSecret; ///<Extended master secret computation
1803 #endif
1805 
1806 
1807 //CodeWarrior or Win32 compiler?
1808 #if defined(__CWCC__) || defined(_WIN32)
1809  #pragma pack(pop)
1810 #endif
1811 
1812 
1813 /**
1814  * @brief Socket handle
1815  **/
1816 
1817 typedef void *TlsSocketHandle;
1818 
1819 
1820 /**
1821  * @brief Socket send callback function
1822  **/
1823 
1825  const void *data, size_t length, size_t *written, uint_t flags);
1826 
1827 
1828 /**
1829  * @brief Socket receive callback function
1830  **/
1831 
1833  void *data, size_t size, size_t *received, uint_t flags);
1834 
1835 
1836 /**
1837  * @brief ALPN callback function
1838  **/
1839 
1840 typedef error_t (*TlsAlpnCallback)(TlsContext *context,
1841  const char_t *selectedProtocol);
1842 
1843 
1844 /**
1845  * @brief Pre-shared key callback function
1846  **/
1847 
1848 typedef error_t (*TlsPskCallback)(TlsContext *context,
1849  const uint8_t *pskIdentity, size_t pskIdentityLen);
1850 
1851 
1852 /**
1853  * @brief Certificate verification callback function
1854  **/
1855 
1857  const X509CertificateInfo *certInfo, uint_t pathLen, void *param);
1858 
1859 
1860 /**
1861  * @brief Raw public key verification callback function
1862  **/
1863 
1865  const uint8_t *rawPublicKey, size_t rawPublicKeyLen);
1866 
1867 
1868 /**
1869  * @brief Ticket encryption callback function
1870  **/
1871 
1873  const uint8_t *plaintext, size_t plaintextLen, uint8_t *ciphertext,
1874  size_t *ciphertextLen, void *param);
1875 
1876 
1877 /**
1878  * @brief Ticket decryption callback function
1879  **/
1880 
1882  const uint8_t *ciphertext, size_t ciphertextLen, uint8_t *plaintext,
1883  size_t *plaintextLen, void *param);
1884 
1885 
1886 /**
1887  * @brief ECDH key agreement callback function
1888  **/
1889 
1890 typedef error_t (*TlsEcdhCallback)(TlsContext *context);
1891 
1892 
1893 /**
1894  * @brief ECDSA signature generation callback function
1895  **/
1896 
1898  const uint8_t *digest, size_t digestLen, EcdsaSignature *signature);
1899 
1900 
1901 /**
1902  * @brief ECDSA signature verification callback function
1903  **/
1904 
1906  const uint8_t *digest, size_t digestLen, EcdsaSignature *signature);
1907 
1908 
1909 /**
1910  * @brief Key logging callback function (for debugging purpose only)
1911  **/
1912 
1913 typedef void (*TlsKeyLogCallback)(TlsContext *context, const char_t *key);
1914 
1915 
1916 /**
1917  * @brief Structure describing a cipher suite
1918  **/
1919 
1920 typedef struct
1921 {
1922  uint16_t identifier;
1923  const char_t *name;
1929  uint8_t macKeyLen;
1930  uint8_t encKeyLen;
1931  uint8_t fixedIvLen;
1932  uint8_t recordIvLen;
1933  uint8_t authTagLen;
1934  uint8_t verifyDataLen;
1936 
1937 
1938 /**
1939  * @brief TLS session state
1940  **/
1941 
1942 typedef struct
1943 {
1944  uint16_t version; ///<TLS protocol version
1945  uint16_t cipherSuite; ///<Cipher suite identifier
1946  systime_t timestamp; ///<Time stamp to manage entry lifetime
1947  uint8_t secret[48]; ///<Master secret (TLS 1.2) or ticket PSK (TLS 1.3)
1948 #if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_2)
1949  uint8_t sessionId[32]; ///<Session identifier
1950  size_t sessionIdLen; ///<Length of the session identifier
1951  bool_t extendedMasterSecret; ///<Extended master secret computation
1952 #endif
1953  uint8_t *ticket; ///<Session ticket
1954  size_t ticketLen; ///<Length of the session ticket
1955 #if (TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
1956  systime_t ticketTimestamp; ///<Timestamp to manage ticket lifetime
1957  uint32_t ticketLifetime; ///<Lifetime of the ticket
1958  uint32_t ticketAgeAdd; ///<Random value used to obscure the age of the ticket
1959  TlsHashAlgo ticketHashAlgo; ///<Hash algorithm associated with the ticket
1960  char_t *ticketAlpn; ///<ALPN protocol associated with the ticket
1961  uint32_t maxEarlyDataSize; ///<Maximum amount of 0-RTT data that the client is allowed to send
1962 #endif
1963 #if (TLS_SNI_SUPPORT == ENABLED)
1964  char_t *serverName; ///<ServerName extension
1965 #endif
1966 } TlsSessionState;
1967 
1968 
1969 /**
1970  * @brief Session cache
1971  **/
1972 
1973 typedef struct
1974 {
1975  OsMutex mutex; ///<Mutex preventing simultaneous access to the cache
1976  uint_t size; ///<Maximum number of entries
1977  TlsSessionState sessions[]; ///<Cache entries
1978 } TlsCache;
1979 
1980 
1981 /**
1982  * @brief Certificate descriptor
1983  **/
1984 
1985 typedef struct
1986 {
1987  const char_t *certChain; ///<End entity certificate chain (PEM format)
1988  size_t certChainLen; ///<Length of the certificate chain
1989  const char_t *privateKey; ///<Private key (PEM format)
1990  size_t privateKeyLen; ///<Length of the private key
1991  TlsCertificateType type; ///<End entity certificate type
1992  TlsSignatureAlgo signAlgo; ///<Signature algorithm used to sign the end entity certificate
1993  TlsHashAlgo hashAlgo; ///<Hash algorithm used to sign the end entity certificate
1994  TlsNamedGroup namedCurve; ///<Named curve used to generate the EC public key
1995 } TlsCertDesc;
1996 
1997 
1998 /**
1999  * @brief Hello extensions
2000  **/
2001 
2002 typedef struct
2003 {
2004  const TlsSupportedVersionList *supportedVersionList; ///<SupportedVersions extension (ClientHello)
2005  const TlsExtension *selectedVersion; ///<SupportedVersions extension (ServerHello)
2006  const TlsServerNameList *serverNameList; ///<ServerName extension
2007  const TlsSupportedGroupList *supportedGroupList; ///<SupportedGroups extension
2008  const TlsEcPointFormatList *ecPointFormatList; ///<EcPointFormats extension
2009  const TlsSignHashAlgos *signAlgoList; ///<SignatureAlgorithms extension
2010  const TlsSignHashAlgos *certSignAlgoList; ///<SignatureAlgorithmsCert extension
2011 #if (TLS_MAX_FRAG_LEN_SUPPORT == ENABLED)
2012  const TlsExtension *maxFragLen; ///<MaxFragmentLength extension
2013 #endif
2014 #if (TLS_RECORD_SIZE_LIMIT_SUPPORT == ENABLED)
2015  const TlsExtension *recordSizeLimit; ///<RecordSizeLimit extension
2016 #endif
2017 #if (TLS_ALPN_SUPPORT == ENABLED)
2018  const TlsProtocolNameList *protocolNameList; ///<ALPN extension
2019 #endif
2020 #if (TLS_RAW_PUBLIC_KEY_SUPPORT == ENABLED)
2021  const TlsCertTypeList *clientCertTypeList; ///<ClientCertType extension
2023  const TlsCertTypeList *serverCertTypeList; ///<ServerCertType extension
2025 #endif
2026 #if (TLS_EXT_MASTER_SECRET_SUPPORT == ENABLED)
2027  const TlsExtension *extendedMasterSecret; ///<ExtendedMasterSecret extension
2028 #endif
2029 #if (TLS_TICKET_SUPPORT == ENABLED)
2030  const TlsExtension *sessionTicket; ///<SessionTicket extension
2031 #endif
2032 #if (TLS_SECURE_RENEGOTIATION_SUPPORT == ENABLED)
2033  const TlsRenegoInfo *renegoInfo; ///<RenegotiationInfo extension
2034 #endif
2035 #if (TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
2036  const Tls13Cookie *cookie; ///<Cookie extension
2037  const Tls13KeyShareList *keyShareList; ///<KeyShare extension (ClientHello)
2038  const TlsExtension *selectedGroup; ///<KeyShare extension (HelloRetryRequest)
2039  const Tls13KeyShareEntry *serverShare; ///<KeyShare extension (ServerHello)
2040  const Tls13PskKeModeList *pskKeModeList; ///<PskKeyExchangeModes extension
2041  const Tls13PskIdentityList *identityList; ///<PreSharedKey extension (ClientHello)
2043  const TlsExtension *selectedIdentity; ///<PreSharedKey extension (ServerHello)
2044  const TlsExtension *earlyDataIndication; ///<EarlyData extension
2045 #endif
2047 
2048 
2049 /**
2050  * @brief Encryption engine
2051  **/
2052 
2054 {
2055  uint16_t version; ///<Negotiated TLS version
2056  uint8_t macKey[48]; ///<MAC key
2057  size_t macKeyLen; ///<Length of the MAC key
2058  uint8_t encKey[48]; ///<Encryption key
2059  size_t encKeyLen; ///<Length of the encryption key
2060  uint8_t iv[16]; ///<Initialization vector
2061  size_t fixedIvLen; ///<Length of the fixed part of the IV
2062  size_t recordIvLen; ///<Length of the IV
2063  size_t authTagLen; ///<Length of the authentication tag
2064  const CipherAlgo *cipherAlgo; ///<Cipher algorithm
2065  void *cipherContext; ///<Cipher context
2066  CipherMode cipherMode; ///<Cipher mode of operation
2067  const HashAlgo *hashAlgo; ///<Hash algorithm for MAC operations
2068  HmacContext *hmacContext; ///<HMAC context
2069 #if (TLS_GCM_CIPHER_SUPPORT == ENABLED)
2070  GcmContext *gcmContext; ///<GCM context
2071 #endif
2072  TlsSequenceNumber seqNum; ///<TLS sequence number
2073 #if (DTLS_SUPPORT == ENABLED)
2074  uint16_t epoch; ///<Counter value incremented on every cipher state change
2075  DtlsSequenceNumber dtlsSeqNum; ///<Record sequence number
2076 #endif
2077 #if (TLS_RECORD_SIZE_LIMIT_SUPPORT == ENABLED)
2078  size_t recordSizeLimit; ///<Maximum size of record in octets
2079  TLS_PRIVATE_ENCRYPTION_ENGINE ///<Application specific context
2080 #endif
2081 };
2082 
2083 
2084 /**
2085  * @brief TLS context
2086  *
2087  * An opaque data structure that represents a TLS connection
2088  *
2089  **/
2090 
2092 {
2093  TlsState state; ///<TLS handshake finite state machine
2094  TlsTransportProtocol transportProtocol; ///<Transport protocol (stream or datagram)
2095  TlsConnectionEnd entity; ///<Client or server operation
2096 
2097  TlsSocketHandle socketHandle; ///<Socket handle
2098  TlsSocketSendCallback socketSendCallback; ///<Socket send callback function
2099  TlsSocketReceiveCallback socketReceiveCallback; ///<Socket receive callback function
2100 
2101  const PrngAlgo *prngAlgo; ///<Pseudo-random number generator to be used
2102  void *prngContext; ///<Pseudo-random number generator context
2103 
2104  const uint16_t *cipherSuites; ///<List of supported cipher suites
2105  uint_t numCipherSuites; ///<Number of cipher suites in the list
2106 
2107  const uint16_t *supportedGroups; ///<List of supported named groups
2108  uint_t numSupportedGroups; ///<Number of named groups in the list
2109 
2110  char_t *serverName; ///<Fully qualified DNS hostname of the server
2111 
2112 #if (TLS_ECC_CALLBACK_SUPPORT == ENABLED)
2116 #endif
2117 
2118  TlsCertDesc certs[TLS_MAX_CERTIFICATES]; ///<End entity certificates (PEM format)
2119  uint_t numCerts; ///<Number of certificates available
2120  const char_t *trustedCaList; ///<List of trusted CA (PEM format)
2121  size_t trustedCaListLen; ///<Number of trusted CA in the list
2122  TlsCertVerifyCallback certVerifyCallback; ///<Certificate verification callback function
2123  void *certVerifyParam; ///<Opaque pointer passed to the certificate verification callback
2124  TlsCertDesc *cert; ///<Pointer to the currently selected certificate
2125 
2126  TlsCache *cache; ///<TLS session cache
2127  uint8_t sessionId[32]; ///<Session identifier
2128  size_t sessionIdLen; ///<Length of the session identifier
2129 
2130  uint16_t clientVersion; ///<Latest version supported by the client
2131  uint16_t version; ///<Negotiated TLS version
2132  uint16_t versionMin; ///<Minimum version accepted by the implementation
2133  uint16_t versionMax; ///<Maximum version accepted by the implementation
2134 
2135  uint8_t *cookie; ///<Cookie
2136  size_t cookieLen; ///<Length of the cookie
2137 
2138  uint8_t *ticket; ///<Session ticket
2139  size_t ticketLen; ///<Length of the session ticket
2140  systime_t ticketTimestamp; ///<Timestamp to manage ticket lifetime
2141  uint32_t ticketLifetime; ///<Lifetime of the ticket
2142 
2143  TlsCipherSuiteInfo cipherSuite; ///<Negotiated cipher suite
2144  TlsKeyExchMethod keyExchMethod; ///<Key exchange method
2145  TlsSignatureAlgo signAlgo; ///<Signature algorithm to be used
2146  TlsHashAlgo signHashAlgo; ///<Hash algorithm used for signing
2147  uint16_t namedGroup; ///<ECDHE or FFDHE named group
2148 
2149  TlsCertificateType peerCertType; ///<Peer's certificate type
2150  TlsClientAuthMode clientAuthMode; ///<Client authentication mode
2151  bool_t clientCertRequested; ///<This flag tells whether the client certificate is requested
2152 
2153  bool_t resume; ///<The connection is established by resuming a session
2154  bool_t fatalAlertSent; ///<A fatal alert message has been sent
2155  bool_t fatalAlertReceived; ///<A fatal alert message has been received from the peer
2156  bool_t closeNotifySent; ///<A closure alert has been sent
2157  bool_t closeNotifyReceived; ///<A closure alert has been received from the peer
2158 
2159  uint8_t *txBuffer; ///<TX buffer
2160  size_t txBufferSize; ///<TX buffer size
2161  size_t txBufferMaxLen; ///<Maximum number of plaintext data the TX buffer can hold
2162  TlsContentType txBufferType; ///<Type of data that resides in the TX buffer
2163  size_t txBufferLen; ///<Number of bytes that are pending to be sent
2164  size_t txBufferPos; ///<Current position in TX buffer
2165  size_t txRecordLen; ///<Length of the TLS record
2166  size_t txRecordPos; ///<Current position in the TLS record
2167 
2168  uint8_t *rxBuffer; ///<RX buffer
2169  size_t rxBufferSize; ///<RX buffer size
2170  size_t rxBufferMaxLen; ///<Maximum number of plaintext data the RX buffer can hold
2171  TlsContentType rxBufferType; ///<Type of data that resides in the RX buffer
2172  size_t rxBufferLen; ///<Number of bytes available for reading
2173  size_t rxBufferPos; ///<Current position in RX buffer
2174  size_t rxRecordLen; ///<Length of the TLS record
2175  size_t rxRecordPos; ///<Current position in the TLS record
2176 
2177  uint8_t clientRandom[TLS_RANDOM_SIZE]; ///<Client random value
2178  uint8_t serverRandom[TLS_RANDOM_SIZE]; ///<Server random value
2179  uint8_t premasterSecret[TLS_PREMASTER_SECRET_SIZE]; ///<Premaster secret
2180  size_t premasterSecretLen; ///<Length of the premaster secret
2181  uint8_t clientVerifyData[64]; ///<Client verify data
2182  size_t clientVerifyDataLen; ///<Length of the client verify data
2183  uint8_t serverVerifyData[64]; ///<Server verify data
2184  size_t serverVerifyDataLen; ///<Length of the server verify data
2185 
2186  TlsEncryptionEngine encryptionEngine; ///<Encryption engine
2187  TlsEncryptionEngine decryptionEngine; ///<Decryption engine
2188 
2189 #if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_0)
2190  size_t txLastRecordLen; ///<Length of the previous TLS record
2191 #endif
2192 
2193 #if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_1)
2194  Md5Context *transcriptMd5Context; ///<MD5 context used to compute verify data
2195 #endif
2196 
2197 #if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_2)
2198  uint8_t masterSecret[TLS_MASTER_SECRET_SIZE]; ///<Master secret
2199  uint8_t keyBlock[192]; ///<Key material
2200  HmacContext hmacContext; ///<HMAC context
2201  Sha1Context *transcriptSha1Context; ///<SHA-1 context used to compute verify data
2202 #endif
2203 
2204 #if (TLS_MAX_VERSION >= TLS_VERSION_1_2 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
2205  HashContext *transcriptHashContext; ///<Hash context used to compute verify data
2206 #endif
2207 
2208 #if (TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
2209  uint16_t preferredGroup; ///<Preferred ECDHE or FFDHE named group
2210  systime_t clientHelloTimestamp; ///<Time at which the ClientHello message was sent
2211  bool_t updatedClientHelloReceived; ///<An updated ClientHello message has been received
2212  uint8_t *certRequestContext; ///<Certificate request context
2213  size_t certRequestContextLen; ///<Length of the certificate request context
2214  int_t selectedIdentity; ///<Selected PSK identity
2215  bool_t pskKeModeSupported; ///<PSK key establishment supported by the client
2216 
2225 
2226  uint_t newSessionTicketCount; ///<Number of NewSessionTicket messages that have been sent
2227 
2228  uint8_t ticketPsk[TLS_MAX_HKDF_DIGEST_SIZE]; ///<PSK associated with the ticket
2229  size_t ticketPskLen; ///<Length of the PSK associated with the ticket
2230  uint32_t ticketAgeAdd; ///<Random value used to obscure the age of the ticket
2231  uint32_t ticketNonce; ///<A per-ticket value that is unique across all tickets issued
2232  uint16_t ticketCipherSuite; ///<Cipher suite associated with the ticket
2233  TlsHashAlgo ticketHashAlgo; ///<Hash algorithm associated with the ticket
2234  char_t *ticketAlpn; ///<ALPN protocol associated with the ticket
2235 
2236  size_t maxEarlyDataSize; ///<Maximum amount of 0-RTT data that the client is allowed to send
2237  size_t earlyDataLen; ///<Total amount of 0-RTT data that have been sent by the client
2238  bool_t earlyDataEnabled; ///<EarlyData is enabled
2239  bool_t earlyDataRejected; ///<The 0-RTT data have been rejected by the server
2240  bool_t earlyDataExtReceived; ///<The EarlyData extension has been received
2241  TlsSequenceNumber earlyDataSeqNum; ///<Early data sequence number
2242 #endif
2243 
2244 #if (TLS_DH_SUPPORT == ENABLED)
2245  DhContext dhContext; ///<Diffie-Hellman context
2246 #endif
2247 
2248 #if (TLS_ECDH_SUPPORT == ENABLED)
2249  EcdhContext ecdhContext; ///<ECDH context
2250  bool_t ecPointFormatsExtReceived; ///<The EcPointFormats extension has been received
2251 #endif
2252 
2253 #if (TLS_RSA_SUPPORT == ENABLED)
2254  RsaPublicKey peerRsaPublicKey; ///<Peer's RSA public key
2255 #endif
2256 
2257 #if (TLS_DSA_SIGN_SUPPORT == ENABLED)
2258  DsaPublicKey peerDsaPublicKey; ///<Peer's DSA public key
2259 #endif
2260 
2261 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED || TLS_EDDSA_SIGN_SUPPORT == ENABLED)
2262  EcDomainParameters peerEcParams; ///<Peer's EC domain parameters
2263  EcPublicKey peerEcPublicKey; ///<Peer's EC public key
2264 #endif
2265 
2266 #if (TLS_PSK_SUPPORT == ENABLED)
2267  uint8_t *psk; ///<Pre-shared key
2268  size_t pskLen; ///<Length of the pre-shared key, in bytes
2269  char_t *pskIdentity; ///<PSK identity
2270  char_t *pskIdentityHint; ///<PSK identity hint
2271  TlsPskCallback pskCallback; ///<PSK callback function
2272  uint16_t pskCipherSuite; ///<Cipher suite associated with the PSK
2273  TlsHashAlgo pskHashAlgo; ///<Hash algorithm associated with the PSK
2274 #endif
2275 
2276 #if (TLS_MAX_FRAG_LEN_SUPPORT == ENABLED)
2277  size_t maxFragLen; ///<Maximum plaintext fragment length
2278  bool_t maxFragLenExtReceived; ///<The MaxFragmentLength extension has been received
2279 #endif
2280 
2281 #if (TLS_RECORD_SIZE_LIMIT_SUPPORT == ENABLED)
2282  size_t recordSizeLimit; ///<Maximum record size the peer is willing to receive
2283  bool_t recordSizeLimitExtReceived; ///<The RecordSizeLimit extension has been received
2284 #endif
2285 
2286 #if (TLS_ALPN_SUPPORT == ENABLED)
2287  bool_t unknownProtocolsAllowed; ///<Unknown ALPN protocols allowed
2288  char_t *protocolList; ///<List of supported ALPN protocols
2289  char_t *selectedProtocol; ///<Selected ALPN protocol
2290  TlsAlpnCallback alpnCallback; ///<ALPN callback function
2291 #endif
2292 
2293 #if (TLS_EXT_MASTER_SECRET_SUPPORT == ENABLED)
2294  bool_t emsExtReceived; ///<The ExtendedMasterSecret extension has been received
2295 #endif
2296 
2297 #if (TLS_RAW_PUBLIC_KEY_SUPPORT == ENABLED)
2298  TlsCertificateFormat certFormat; ///<Certificate format
2299  TlsCertificateFormat peerCertFormat; ///<Peer's certificate format
2300  TlsRpkVerifyCallback rpkVerifyCallback; ///<Raw public key verification callback function
2301  bool_t clientCertTypeExtReceived; ///<The ClientCertType extension has been received
2302  bool_t serverCertTypeExtReceived; ///<The ServerCertType extension has been received
2303 #endif
2304 
2305 #if (TLS_TICKET_SUPPORT == ENABLED)
2306  bool_t sessionTicketEnabled; ///<Session ticket mechanism enabled
2307  bool_t sessionTicketExtReceived; ///<The SessionTicket extension has been received
2308  bool_t sessionTicketExtSent; ///<The SessionTicket extension has been sent
2309  TlsTicketEncryptCallback ticketEncryptCallback; ///<Ticket encryption callback function
2310  TlsTicketDecryptCallback ticketDecryptCallback; ///<Ticket decryption callback function
2311  void *ticketParam; ///<Opaque pointer passed to the ticket callbacks
2312 #endif
2313 
2314 #if (TLS_SECURE_RENEGOTIATION_SUPPORT == ENABLED)
2315  bool_t secureRenegoEnabled; ///<Secure renegotiation enabled
2316  bool_t secureRenegoFlag; ///<Secure renegotiation flag
2317 #endif
2318 
2319 #if (TLS_FALLBACK_SCSV_SUPPORT == ENABLED)
2320  bool_t fallbackScsvEnabled; ///<Support for FALLBACK_SCSV
2321 #endif
2322 
2323 #if (TLS_KEY_LOG_SUPPORT == ENABLED)
2324  TlsKeyLogCallback keyLogCallback; ///<Key logging callback (for debugging purpose only)
2325 #endif
2326 
2327 #if (TLS_MAX_WARNING_ALERTS > 0)
2328  uint_t alertCount; ///<Count of consecutive warning alerts
2329 #endif
2330 
2331 #if (TLS_MAX_EMPTY_RECORDS > 0)
2332  uint_t emptyRecordCount; ///<Count of consecutive empty records
2333 #endif
2334 
2335 #if (TLS_MAX_CHANGE_CIPHER_SPEC_MESSAGES > 0)
2336  uint_t changeCipherSpecCount; ///<Count of consecutive ChangeCipherSpec messages
2337 #endif
2338 
2339 #if (TLS_MAX_KEY_UPDATE_MESSAGES > 0)
2340  uint_t keyUpdateCount; ///<Count of consecutive KeyUpdate messages
2341 #endif
2342 
2343 #if (DTLS_SUPPORT == ENABLED)
2344  size_t pmtu; ///<PMTU value
2345  systime_t timeout; ///<Timeout for blocking calls
2347 
2348  DtlsCookieGenerateCallback cookieGenerateCallback; ///<Cookie generation callback function
2349  DtlsCookieVerifyCallback cookieVerifyCallback; ///<Cookie verification callback function
2350  void *cookieParam; ///<Opaque pointer passed to the cookie callbacks
2351 
2352  uint_t retransmitCount; ///<Retransmission counter
2353  systime_t retransmitTimestamp; ///<Time at which the datagram was sent
2354  systime_t retransmitTimeout; ///<Retransmission timeout
2355 
2356  uint16_t txMsgSeq; ///<Send sequence number
2357  size_t txDatagramLen; ///<Length of the outgoing datagram, in bytes
2358 
2359  uint16_t rxMsgSeq; ///<Next receive sequence number
2360  size_t rxFragQueueLen; ///<Length of the reassembly queue
2361  size_t rxDatagramLen; ///<Length of the incoming datagram, in bytes
2363  uint16_t rxRecordVersion; ///<Version of the incoming record
2364 
2366 #endif
2367 
2368 #if (DTLS_SUPPORT == ENABLED && DTLS_REPLAY_DETECTION_SUPPORT == ENABLED)
2369  bool_t replayDetectionEnabled; ///<Anti-replay mechanism enabled
2370  uint32_t replayWindow[(DTLS_REPLAY_WINDOW_SIZE + 31) / 32];
2371 #endif
2372 
2373  TLS_PRIVATE_CONTEXT ///<Application specific context
2374 };
2375 
2376 
2377 //TLS application programming interface (API)
2378 TlsContext *tlsInit(void);
2379 TlsState tlsGetState(TlsContext *context);
2380 
2382  TlsSocketSendCallback socketSendCallback,
2383  TlsSocketReceiveCallback socketReceiveCallback, TlsSocketHandle handle);
2384 
2385 error_t tlsSetVersion(TlsContext *context, uint16_t versionMin,
2386  uint16_t versionMax);
2387 
2389  TlsTransportProtocol transportProtocol);
2390 
2392 
2393 error_t tlsSetPrng(TlsContext *context, const PrngAlgo *prngAlgo,
2394  void *prngContext);
2395 
2396 error_t tlsSetServerName(TlsContext *context, const char_t *serverName);
2397 const char_t *tlsGetServerName(TlsContext *context);
2398 
2399 error_t tlsSetCache(TlsContext *context, TlsCache *cache);
2401 
2402 error_t tlsSetBufferSize(TlsContext *context, size_t txBufferSize,
2403  size_t rxBufferSize);
2404 
2405 error_t tlsSetMaxFragmentLength(TlsContext *context, size_t maxFragLen);
2406 
2407 error_t tlsSetCipherSuites(TlsContext *context, const uint16_t *cipherSuites,
2408  uint_t length);
2409 
2410 error_t tlsSetSupportedGroups(TlsContext *context, const uint16_t *groups,
2411  uint_t length);
2412 
2413 error_t tlsSetPreferredGroup(TlsContext *context, uint16_t group);
2414 
2415 error_t tlsSetDhParameters(TlsContext *context, const char_t *params,
2416  size_t length);
2417 
2418 error_t tlsSetEcdhCallback(TlsContext *context, TlsEcdhCallback ecdhCallback);
2419 
2421  TlsEcdsaSignCallback ecdsaSignCallback);
2422 
2424  TlsEcdsaVerifyCallback ecdsaVerifyCallback);
2425 
2427  TlsKeyLogCallback keyLogCallback);
2428 
2430 error_t tlsSetAlpnProtocolList(TlsContext *context, const char_t *protocolList);
2431 error_t tlsSetAlpnCallback(TlsContext *context, TlsAlpnCallback alpnCallback);
2432 const char_t *tlsGetAlpnProtocol(TlsContext *context);
2433 
2434 error_t tlsSetPsk(TlsContext *context, const uint8_t *psk, size_t length);
2435 error_t tlsSetPskIdentity(TlsContext *context, const char_t *pskIdentity);
2436 error_t tlsSetPskIdentityHint(TlsContext *context, const char_t *pskIdentityHint);
2437 error_t tlsSetPskCallback(TlsContext *context, TlsPskCallback pskCallback);
2438 
2440  TlsRpkVerifyCallback rpkVerifyCallback);
2441 
2443  const char_t *trustedCaList, size_t length);
2444 
2445 error_t tlsAddCertificate(TlsContext *context, const char_t *certChain,
2446  size_t certChainLen, const char_t *privateKey, size_t privateKeyLen);
2447 
2449  TlsCertVerifyCallback certVerifyCallback, void *param);
2450 
2453 error_t tlsEnableFallbackScsv(TlsContext *context, bool_t enabled);
2454 
2456  TlsTicketEncryptCallback ticketEncryptCallback,
2457  TlsTicketDecryptCallback ticketDecryptCallback, void *param);
2458 
2459 error_t tlsSetPmtu(TlsContext *context, size_t pmtu);
2460 error_t tlsSetTimeout(TlsContext *context, systime_t timeout);
2461 
2463  DtlsCookieGenerateCallback cookieGenerateCallback,
2464  DtlsCookieVerifyCallback cookieVerifyCallback, void *param);
2465 
2467 
2468 error_t tlsSetMaxEarlyDataSize(TlsContext *context, size_t maxEarlyDataSize);
2469 
2470 error_t tlsWriteEarlyData(TlsContext *context, const void *data,
2471  size_t length, size_t *written, uint_t flags);
2472 
2473 error_t tlsConnect(TlsContext *context);
2474 
2476 
2477 error_t tlsWrite(TlsContext *context, const void *data,
2478  size_t length, size_t *written, uint_t flags);
2479 
2480 error_t tlsRead(TlsContext *context, void *data,
2481  size_t size, size_t *received, uint_t flags);
2482 
2483 bool_t tlsIsTxReady(TlsContext *context);
2484 bool_t tlsIsRxReady(TlsContext *context);
2485 
2486 error_t tlsShutdown(TlsContext *context);
2487 error_t tlsShutdownEx(TlsContext *context, bool_t waitForCloseNotify);
2488 
2489 void tlsFree(TlsContext *context);
2490 
2492 
2493 error_t tlsSaveSessionState(const TlsContext *context,
2494  TlsSessionState *session);
2495 
2497  const TlsSessionState *session);
2498 
2499 void tlsFreeSessionState(TlsSessionState *session);
2500 
2502 void tlsFreeCache(TlsCache *cache);
2503 
2504 //C++ guard
2505 #ifdef __cplusplus
2506 }
2507 #endif
2508 
2509 #endif
@ TLS_CERT_ECDSA_FIXED_ECDH
Definition: tls.h:1135
error_t tlsSetCertificateVerifyCallback(TlsContext *context, TlsCertVerifyCallback certVerifyCallback, void *param)
Set certificate verification callback.
Definition: tls.c:1280
@ TLS13_KEY_EXCH_PSK
Definition: tls.h:1100
__start_packed struct @14 TlsSupportedGroupList
List of supported groups.
TlsRpkVerifyCallback rpkVerifyCallback
Raw public key verification callback function.
Definition: tls.h:2300
@ TLS_EXT_PSK_KEY_EXCHANGE_MODES
Definition: tls.h:1232
@ TLS_GROUP_BRAINPOOLP512R1_TLS13
Definition: tls.h:1310
size_t ticketLen
Length of the session ticket.
Definition: tls.h:1954
@ TLS_TYPE_MESSAGE_HASH
Definition: tls.h:1003
@ TLS_EXT_MAX_FRAGMENT_LENGTH
Definition: tls.h:1194
@ TLS_SIGN_ALGO_RSA_PSS_RSAE_SHA256
Definition: tls.h:1171
DTLS (Datagram Transport Layer Security)
ECDSA signature.
Definition: ecdsa.h:49
@ TLS_SIGN_ALGO_DSA
Definition: tls.h:1169
uint8_t sessionId[32]
Session identifier.
Definition: tls.h:2127
@ TLS_CERT_FORMAT_RAW_PUBLIC_KEY
Definition: tls.h:1114
X.509 common definitions.
uint8_t masterSecret[TLS_MASTER_SECRET_SIZE]
Master secret.
Definition: tls.h:2198
@ TLS_ALERT_DECODE_ERROR
Definition: tls.h:1040
@ TLS_GROUP_SECT163R2
Definition: tls.h:1280
size_t sessionIdLen
Length of the session identifier.
Definition: tls.h:2128
@ TLS_ALERT_UNEXPECTED_MESSAGE
Definition: tls.h:1025
EcPublicKey peerEcPublicKey
Peer's EC public key.
Definition: tls.h:2263
@ TLS_GROUP_BRAINPOOLP256R1_TLS13
Definition: tls.h:1308
bool_t ecPointFormatsExtReceived
The EcPointFormats extension has been received.
Definition: tls.h:2250
Generic hash algorithm context.
uint16_t length
Definition: tls.h:1418
TlsHashAlgo ticketHashAlgo
Hash algorithm associated with the ticket.
Definition: tls.h:2233
__start_packed struct @1 TlsCipherSuites
Cipher suites.
uint8_t secret[TLS_MAX_HKDF_DIGEST_SIZE]
Definition: tls.h:2217
@ TLS_STATE_HELLO_RETRY_REQUEST
Definition: tls.h:1365
int bool_t
Definition: compiler_port.h:48
@ TLS_SIGN_ALGO_ECDSA_BRAINPOOLP512R1_TLS13_SHA512
Definition: tls.h:1181
@ TLS_GROUP_SECP160R2
Definition: tls.h:1294
HMAC algorithm context.
Definition: hmac.h:59
uint_t numSupportedGroups
Number of named groups in the list.
Definition: tls.h:2108
uint8_t encKey[48]
Encryption key.
Definition: tls.h:2058
uint32_t ticketLifetimeHint
Definition: tls.h:1756
uint16_t cipherSuite
Cipher suite identifier.
Definition: tls.h:1797
@ TLS_EXT_OID_FILTERS
Definition: tls.h:1234
@ TLS_TYPE_NEW_CONNECTION_ID
Definition: tls.h:989
@ TLS_ALERT_CERTIFICATE_REQUIRED
Definition: tls.h:1057
error_t(* TlsTicketEncryptCallback)(TlsContext *context, const uint8_t *plaintext, size_t plaintextLen, uint8_t *ciphertext, size_t *ciphertextLen, void *param)
Ticket encryption callback function.
Definition: tls.h:1872
uint8_t * cookie
Cookie.
Definition: tls.h:2135
char_t * pskIdentity
PSK identity.
Definition: tls.h:2269
const Tls13PskKeModeList * pskKeModeList
PskKeyExchangeModes extension.
Definition: tls.h:2040
@ TLS_ALERT_CLOSE_NOTIFY
Definition: tls.h:1024
error_t tlsConnect(TlsContext *context)
Initiate the TLS handshake.
Definition: tls.c:1630
@ TLS_ALERT_NO_RENEGOTIATION
Definition: tls.h:1049
@ TLS_SIGN_ALGO_ANONYMOUS
Definition: tls.h:1167
systime_t ticketTimestamp
Timestamp to manage ticket lifetime.
Definition: tls.h:1956
void TlsServerHelloDone
ServerHelloDone message.
Definition: tls.h:1733
bool_t secureRenegoFlag
Secure renegotiation flag.
Definition: tls.h:2316
@ TLS13_KEY_EXCH_PSK_DHE
Definition: tls.h:1101
error_t(* TlsEcdsaVerifyCallback)(TlsContext *context, const uint8_t *digest, size_t digestLen, EcdsaSignature *signature)
ECDSA signature verification callback function.
Definition: tls.h:1905
error_t tlsSetEcdsaSignCallback(TlsContext *context, TlsEcdsaSignCallback ecdsaSignCallback)
ECDSA signature generation callback function.
Definition: tls.c:705
signed int int_t
Definition: compiler_port.h:44
DtlsSequenceNumber dtlsSeqNum
Record sequence number.
Definition: tls.h:2075
@ TLS_CERT_FORMAT_OPENPGP
Definition: tls.h:1113
@ TLS_STATE_SERVER_KEY_EXCHANGE
Definition: tls.h:1372
const TlsExtension * sessionTicket
SessionTicket extension.
Definition: tls.h:2030
@ TLS_TYPE_SERVER_HELLO_DONE
Definition: tls.h:993
size_t premasterSecretLen
Length of the premaster secret.
Definition: tls.h:2180
@ TLS_COMPRESSION_METHOD_NULL
Definition: tls.h:1068
@ TLS_SIGN_ALGO_GOSTR34102012_256
Definition: tls.h:1182
@ TLS_ALERT_ILLEGAL_PARAMETER
Definition: tls.h:1037
@ TLS_GROUP_SECT571K1
Definition: tls.h:1290
TlsKeyExchMethod keyExchMethod
Key exchange method.
Definition: tls.h:2144
TlsEcPointFormat
EC point formats.
Definition: tls.h:1335
uint8_t * ticket
Session ticket.
Definition: tls.h:1953
#define PrngAlgo
Definition: crypto.h:833
@ TLS_EXT_CLIENT_AUTHZ
Definition: tls.h:1200
@ TLS_EARLY_DATA_REJECTED
Definition: tls.h:931
uint32_t ticketLifetime
Lifetime of the ticket.
Definition: tls.h:2141
@ TLS_EXT_PWD_PROTECT
Definition: tls.h:1221
TlsCache * tlsInitCache(uint_t size)
Session cache initialization.
Definition: tls_cache.c:51
error_t tlsShutdownEx(TlsContext *context, bool_t waitForCloseNotify)
Gracefully close TLS session.
Definition: tls.c:2183
@ TLS_ALERT_UNSUPPORTED_EXTENSION
Definition: tls.h:1051
TlsState
TLS FSM states.
Definition: tls.h:1359
@ TLS_TYPE_CERTIFICATE_STATUS
Definition: tls.h:998
const Tls13PskBinderList * binderList
Definition: tls.h:2042
uint8_t clientRandom[TLS_RANDOM_SIZE]
Client random value.
Definition: tls.h:2177
size_t rxBufferSize
RX buffer size.
Definition: tls.h:2169
bool_t closeNotifySent
A closure alert has been sent.
Definition: tls.h:2156
@ TLS_EXT_SUPPORTED_VERSIONS
Definition: tls.h:1230
ECDSA (Elliptic Curve Digital Signature Algorithm)
uint16_t versionMin
Minimum version accepted by the implementation.
Definition: tls.h:2132
bool_t maxFragLenExtReceived
The MaxFragmentLength extension has been received.
Definition: tls.h:2278
TlsState tlsGetState(TlsContext *context)
Retrieve current state.
Definition: tls.c:194
@ TLS_ALERT_RECORD_OVERFLOW
Definition: tls.h:1028
uint16_t version
Protocol version.
Definition: tls.h:1653
#define TLS_PRIVATE_CONTEXT
Definition: tls.h:796
TlsTransportProtocol transportProtocol
Transport protocol (stream or datagram)
Definition: tls.h:2094
size_t txRecordPos
Current position in the TLS record.
Definition: tls.h:2166
@ TLS_EXT_EXTERNAL_ID_HASH
Definition: tls.h:1240
TlsConnectionEnd
TLS connection end.
Definition: tls.h:907
size_t rxDatagramPos
Definition: tls.h:2362
const TlsExtension * selectedGroup
KeyShare extension (HelloRetryRequest)
Definition: tls.h:2038
systime_t timestamp
Time stamp to manage entry lifetime.
Definition: tls.h:1946
@ TLS_GROUP_SECP256K1
Definition: tls.h:1299
uint8_t * txBuffer
TX buffer.
Definition: tls.h:2159
TlsContext * tlsInit(void)
TLS context initialization.
Definition: tls.c:66
bool_t fatalAlertSent
A fatal alert message has been sent.
Definition: tls.h:2154
HashContext * transcriptHashContext
Hash context used to compute verify data.
Definition: tls.h:2205
uint8_t clientHsTrafficSecret[TLS_MAX_HKDF_DIGEST_SIZE]
Definition: tls.h:2219
@ TLS_GROUP_EXPLICIT_CHAR2_CURVE
Definition: tls.h:1326
error_t(* DtlsCookieGenerateCallback)(TlsContext *context, const DtlsClientParameters *clientParams, uint8_t *cookie, size_t *length, void *param)
DTLS cookie generation callback function.
Definition: dtls_misc.h:236
TlsConnectionEnd entity
Client or server operation.
Definition: tls.h:2095
@ TLS_SIGN_ALGO_RSA_PSS_PSS_SHA384
Definition: tls.h:1177
@ TLS_EXT_PWD_CLEAR
Definition: tls.h:1222
TlsCertificateFormat peerCertFormat
Peer's certificate format.
Definition: tls.h:2299
@ TLS_STATE_CERTIFICATE_REQUEST
Definition: tls.h:1374
void * cookieParam
Opaque pointer passed to the cookie callbacks.
Definition: tls.h:2350
@ TLS_TYPE_CHANGE_CIPHER_SPEC
Definition: tls.h:964
size_t maxFragLen
Maximum plaintext fragment length.
Definition: tls.h:2277
const TlsProtocolNameList * protocolNameList
ALPN extension.
Definition: tls.h:2018
@ TLS_GROUP_SECP256R1
Definition: tls.h:1300
const TlsExtension * earlyDataIndication
EarlyData extension.
Definition: tls.h:2044
error_t tlsRestoreSessionState(TlsContext *context, const TlsSessionState *session)
Restore TLS session.
Definition: tls.c:2555
@ TLS_TYPE_HANDSHAKE
Definition: tls.h:966
error_t tlsSetAlpnCallback(TlsContext *context, TlsAlpnCallback alpnCallback)
Register ALPN callback function.
Definition: tls.c:861
#define TLS_PRIVATE_ENCRYPTION_ENGINE
Definition: tls.h:801
error_t(* TlsSocketReceiveCallback)(TlsSocketHandle handle, void *data, size_t size, size_t *received, uint_t flags)
Socket receive callback function.
Definition: tls.h:1832
@ TLS_GROUP_SECP224K1
Definition: tls.h:1297
TlsHashAlgo hashAlgo
Hash algorithm used to sign the end entity certificate.
Definition: tls.h:1993
@ TLS_EXT_CONNECTION_ID
Definition: tls.h:1239
TlsTicketDecryptCallback ticketDecryptCallback
Ticket decryption callback function.
Definition: tls.h:2310
TlsCertificateType type
End entity certificate type.
Definition: tls.h:1991
X.509 certificate.
Definition: x509_common.h:932
@ TLS_GROUP_SECT239K1
Definition: tls.h:1285
bool_t clientCertTypeExtReceived
The ClientCertType extension has been received.
Definition: tls.h:2301
size_t pmtu
PMTU value.
Definition: tls.h:2344
@ TLS_TRANSPORT_PROTOCOL_DATAGRAM
Definition: tls.h:898
TlsSignatureAlgo signAlgo
Signature algorithm to be used.
Definition: tls.h:2145
@ TLS_TYPE_COMPRESSED_CERTIFICATE
Definition: tls.h:1001
@ TLS_ALERT_ACCESS_DENIED
Definition: tls.h:1039
uint8_t signature
Definition: tls.h:1441
@ TLS_KEY_EXCH_SRP_SHA_RSA
Definition: tls.h:1096
@ TLS_ALERT_INSUFFICIENT_SECURITY
Definition: tls.h:1045
#define DTLS_REPLAY_WINDOW_SIZE
Definition: dtls_misc.h:69
@ TLS_CERT_FORTEZZA_DMS
Definition: tls.h:1132
HmacContext * hmacContext
HMAC context.
Definition: tls.h:2068
TlsMessageType
Handshake message type.
Definition: tls.h:979
TlsSocketHandle socketHandle
Socket handle.
Definition: tls.h:2097
const char_t * name
Definition: tls.h:1923
Structure describing a cipher suite.
Definition: tls.h:1921
@ TLS_ALERT_BAD_CERTIFICATE_HASH_VALUE
Definition: tls.h:1055
@ TLS_HASH_ALGO_SHA1
Definition: tls.h:1152
@ TLS_STATE_APPLICATION_DATA
Definition: tls.h:1390
@ TLS_COMPRESSION_METHOD_DEFLATE
Definition: tls.h:1069
size_t txDatagramLen
Length of the outgoing datagram, in bytes.
Definition: tls.h:2357
size_t sessionIdLen
Length of the session identifier.
Definition: tls.h:1950
size_t authTagLen
Length of the authentication tag.
Definition: tls.h:2063
@ TLS_GROUP_GC512A
Definition: tls.h:1315
@ TLS_ALERT_DECOMPRESSION_FAILURE
Definition: tls.h:1029
const TlsCertTypeList * clientCertTypeList
ClientCertType extension.
Definition: tls.h:2021
bool_t secureRenegoEnabled
Secure renegotiation enabled.
Definition: tls.h:2315
@ TLS_GROUP_GC256D
Definition: tls.h:1314
error_t tlsSetVersion(TlsContext *context, uint16_t versionMin, uint16_t versionMax)
Set minimum and maximum versions permitted.
Definition: tls.c:250
@ TLS_KEY_EXCH_DH_DSS
Definition: tls.h:1083
ECDH (Elliptic Curve Diffie-Hellman) key exchange.
TlsHashAlgo
Hash algorithms.
Definition: tls.h:1149
bool_t closeNotifyReceived
A closure alert has been received from the peer.
Definition: tls.h:2157
error_t tlsSetMaxFragmentLength(TlsContext *context, size_t maxFragLen)
Set maximum fragment length.
Definition: tls.c:531
@ TLS_ALERT_CERTIFICATE_UNOBTAINABLE
Definition: tls.h:1052
const HashAlgo * hashAlgo
Hash algorithm for MAC operations.
Definition: tls.h:2067
@ TLS_ALERT_NO_CERTIFICATE
Definition: tls.h:1031
@ TLS_TYPE_ACK
Definition: tls.h:970
TlsEncryptionEngine prevEncryptionEngine
Definition: tls.h:2365
TlsAlpnCallback alpnCallback
ALPN callback function.
Definition: tls.h:2290
@ TLS13_KEY_EXCH_ECDHE
Definition: tls.h:1099
@ TLS_STATE_SERVER_APP_TRAFFIC_KEYS
Definition: tls.h:1387
@ TLS_CERT_DSS_SIGN
Definition: tls.h:1127
@ TLS_KEY_EXCH_SRP_SHA_DSS
Definition: tls.h:1097
void * prngContext
Pseudo-random number generator context.
Definition: tls.h:2102
TlsAlertDescription
Alert description.
Definition: tls.h:1023
CipherMode cipherMode
Definition: tls.h:1926
__start_packed struct @23 TlsHandshake
TLS handshake message.
error_t tlsSetAlpnProtocolList(TlsContext *context, const char_t *protocolList)
Set the list of supported ALPN protocols.
Definition: tls.c:812
uint16_t value[]
Definition: tls.h:1419
OsMutex mutex
Mutex preventing simultaneous access to the cache.
Definition: tls.h:1975
@ TLS_EXT_TICKET_PINNING
Definition: tls.h:1224
uint8_t clientVerifyData[64]
Client verify data.
Definition: tls.h:2181
@ TLS_SIGN_ALGO_RSA_PSS_PSS_SHA512
Definition: tls.h:1178
DhContext dhContext
Diffie-Hellman context.
Definition: tls.h:2245
@ TLS_EXT_SERVER_AUTHZ
Definition: tls.h:1201
@ TLS_GROUP_SM2
Definition: tls.h:1318
@ TLS_ALERT_DECRYPT_ERROR
Definition: tls.h:1041
@ TLS_KEY_EXCH_ECDH_RSA
Definition: tls.h:1086
char_t * ticketAlpn
ALPN protocol associated with the ticket.
Definition: tls.h:2234
TlsContentType txBufferType
Type of data that resides in the TX buffer.
Definition: tls.h:2162
Session cache.
Definition: tls.h:1974
__start_packed struct @25 TlsServerHello
ServerHello message.
TlsTicketEncryptCallback ticketEncryptCallback
Ticket encryption callback function.
Definition: tls.h:2309
const TlsSignHashAlgos * signAlgoList
SignatureAlgorithms extension.
Definition: tls.h:2009
EC domain parameters.
Definition: ec.h:76
size_t rxDatagramLen
Length of the incoming datagram, in bytes.
Definition: tls.h:2361
const TlsSupportedVersionList * supportedVersionList
SupportedVersions extension (ClientHello)
Definition: tls.h:2004
systime_t retransmitTimeout
Retransmission timeout.
Definition: tls.h:2354
size_t pskLen
Length of the pre-shared key, in bytes.
Definition: tls.h:2268
uint16_t rxMsgSeq
Next receive sequence number.
Definition: tls.h:2359
uint8_t certificateTypes[]
Definition: tls.h:1725
uint8_t * psk
Pre-shared key.
Definition: tls.h:2267
uint_t emptyRecordCount
Count of consecutive empty records.
Definition: tls.h:2332
size_t earlyDataLen
Total amount of 0-RTT data that have been sent by the client.
Definition: tls.h:2237
#define TLS_RANDOM_SIZE
Definition: tls.h:883
@ TLS_GROUP_BRAINPOOLP256R1
Definition: tls.h:1303
@ TLS_EXT_COMPRESS_CERTIFICATE
Definition: tls.h:1219
size_t fixedIvLen
Length of the fixed part of the IV.
Definition: tls.h:2061
@ TLS_EXT_EARLY_DATA
Definition: tls.h:1229
@ TLS_EXT_TRUNCATED_HMAC
Definition: tls.h:1197
@ TLS_EXT_SESSION_TICKET
Definition: tls.h:1226
@ TLS_TYPE_END_OF_EARLY_DATA
Definition: tls.h:985
uint8_t authTagLen
Definition: tls.h:1933
error_t(* TlsSocketSendCallback)(TlsSocketHandle handle, const void *data, size_t length, size_t *written, uint_t flags)
Socket send callback function.
Definition: tls.h:1824
__start_packed struct @27 TlsNewSessionTicket
NewSessionTicket message.
@ TLS_GROUP_FFDHE6144
Definition: tls.h:1322
error_t tlsAllowUnknownAlpnProtocols(TlsContext *context, bool_t allowed)
Allow unknown ALPN protocols.
Definition: tls.c:786
@ TLS_SIGN_ALGO_ED448
Definition: tls.h:1175
@ TLS_MAX_FRAGMENT_LENGTH_4096
Definition: tls.h:1267
@ TLS_HASH_ALGO_NONE
Definition: tls.h:1150
__start_packed struct @3 Tls13PskKeModeList
List of PSK key exchange modes.
error_t tlsSetTimeout(TlsContext *context, systime_t timeout)
Set timeout for blocking calls (for DTLS only)
Definition: tls.c:1446
uint16_t preferredGroup
Preferred ECDHE or FFDHE named group.
Definition: tls.h:2209
size_t maxEarlyDataSize
Maximum amount of 0-RTT data that the client is allowed to send.
Definition: tls.h:2236
const Tls13Cookie * cookie
Cookie extension.
Definition: tls.h:2036
@ TLS_EXT_QUIC_TRANSPORT_PARAMETERS
Definition: tls.h:1242
TlsKeyExchMethod keyExchMethod
Definition: tls.h:1924
error_t tlsSetCache(TlsContext *context, TlsCache *cache)
Set session cache.
Definition: tls.c:440
uint8_t sessionIdLen
Definition: tls.h:1686
uint8_t serverVerifyData[64]
Server verify data.
Definition: tls.h:2183
@ TLS_STATE_CLIENT_HELLO
Definition: tls.h:1361
bool_t extendedMasterSecret
Extended master secret computation.
Definition: tls.h:1802
@ TLS_ALERT_EXPORT_RESTRICTION
Definition: tls.h:1043
error_t tlsSetPsk(TlsContext *context, const uint8_t *psk, size_t length)
Set the pre-shared key to be used.
Definition: tls.c:914
uint8_t * rxBuffer
RX buffer.
Definition: tls.h:2168
TLS 1.3 helper functions.
const Tls13KeyShareEntry * serverShare
KeyShare extension (ServerHello)
Definition: tls.h:2039
@ TLS_EXT_SERVER_NAME
Definition: tls.h:1193
@ TLS_EXT_SIGNATURE_ALGORITHMS_CERT
Definition: tls.h:1236
uint8_t level
Definition: tls.h:1785
@ TLS_HASH_ALGO_SHA224
Definition: tls.h:1153
@ TLS_KEY_EXCH_RSA
Definition: tls.h:1080
const Tls13KeyShareList * keyShareList
KeyShare extension (ClientHello)
Definition: tls.h:2037
uint8_t resumptionMasterSecret[TLS_MAX_HKDF_DIGEST_SIZE]
Definition: tls.h:2224
CipherMode cipherMode
Cipher mode of operation.
Definition: tls.h:2066
@ TLS_EXT_CERT_TYPE
Definition: tls.h:1202
error_t(* TlsAlpnCallback)(TlsContext *context, const char_t *selectedProtocol)
ALPN callback function.
Definition: tls.h:1840
__start_packed struct @29 TlsAlert
Alert message.
@ TLS_EXT_SUPPORTED_EKT_CIPHERS
Definition: tls.h:1227
@ TLS_TYPE_CERTIFICATE
Definition: tls.h:990
Encryption engine.
Definition: tls.h:2054
@ TLS_CERT_RSA_EPHEMERAL_DH
Definition: tls.h:1130
@ TLS_ALERT_UNKNOWN_CA
Definition: tls.h:1038
void TlsFinished
Finished message.
Definition: tls.h:1766
@ TLS_STATE_SERVER_HELLO
Definition: tls.h:1366
@ TLS_STATE_HELLO_VERIFY_REQUEST
Definition: tls.h:1364
@ TLS_EXT_TRUSTED_CA_KEYS
Definition: tls.h:1196
error_t(* TlsRpkVerifyCallback)(TlsContext *context, const uint8_t *rawPublicKey, size_t rawPublicKeyLen)
Raw public key verification callback function.
Definition: tls.h:1864
uint32_t ticketNonce
A per-ticket value that is unique across all tickets issued.
Definition: tls.h:2231
const TlsCertTypeList * serverCertTypeList
ServerCertType extension.
Definition: tls.h:2023
size_t recordSizeLimit
Maximum record size the peer is willing to receive.
Definition: tls.h:2282
@ TLS_ALERT_LEVEL_WARNING
Definition: tls.h:1013
size_t txBufferSize
TX buffer size.
Definition: tls.h:2160
@ TLS_HASH_ALGO_SHA512
Definition: tls.h:1156
uint16_t cipherSuite
Cipher suite identifier.
Definition: tls.h:1945
@ TLS_ALERT_UNKNOWN_PSK_IDENTITY
Definition: tls.h:1056
const TlsExtension * maxFragLen
MaxFragmentLength extension.
Definition: tls.h:2012
@ TLS_KEY_EXCH_ECDHE_ECDSA
Definition: tls.h:1089
error_t tlsSetSocketCallbacks(TlsContext *context, TlsSocketSendCallback socketSendCallback, TlsSocketReceiveCallback socketReceiveCallback, TlsSocketHandle handle)
Set socket send and receive callbacks.
Definition: tls.c:218
TlsKeyLogCallback keyLogCallback
Key logging callback (for debugging purpose only)
Definition: tls.h:2324
__start_packed struct @2 TlsCompressMethods
Compression methods.
@ TLS_STATE_KEY_UPDATE
Definition: tls.h:1389
@ TLS_CERT_FORMAT_1609DOT2
Definition: tls.h:1115
@ TLS_KEY_EXCH_ECDHE_RSA
Definition: tls.h:1087
const TlsEcPointFormatList * ecPointFormatList
EcPointFormats extension.
Definition: tls.h:2008
uint16_t version
Negotiated TLS version.
Definition: tls.h:2131
__start_packed struct @9 TlsSupportedVersionList
List of supported versions.
size_t certChainLen
Length of the certificate chain.
Definition: tls.h:1988
uint16_t clientVersion
Definition: tls.h:1684
Diffie-Hellman context.
Definition: dh.h:60
@ TLS_KEY_EXCH_ECDH_ANON
Definition: tls.h:1090
uint8_t premasterSecret[TLS_PREMASTER_SECRET_SIZE]
Premaster secret.
Definition: tls.h:2179
__start_packed struct @3 TlsSignHashAlgo
Signature algorithm.
__start_packed struct @7 Tls13PskBinderList
List of PSK binders.
Diffie-Hellman key exchange.
size_t rxRecordLen
Length of the TLS record.
Definition: tls.h:2174
DSA public key.
Definition: dsa.h:61
HmacContext hmacContext
HMAC context.
Definition: tls.h:2200
uint8_t serverHsTrafficSecret[TLS_MAX_HKDF_DIGEST_SIZE]
Definition: tls.h:2220
@ TLS_FLAG_PEEK
Definition: tls.h:942
const char_t * trustedCaList
List of trusted CA (PEM format)
Definition: tls.h:2120
uint32_t ticketAgeAdd
Random value used to obscure the age of the ticket.
Definition: tls.h:2230
uint8_t * ticket
Session ticket.
Definition: tls.h:2138
@ TLS_GROUP_GC256B
Definition: tls.h:1312
__start_packed struct @2 Tls13KeyShareList
List of key shares.
size_t clientVerifyDataLen
Length of the client verify data.
Definition: tls.h:2182
@ TLS_GROUP_ECDH_X25519
Definition: tls.h:1306
TlsCertificateFormat
Certificate formats.
Definition: tls.h:1111
@ TLS_EXT_CLIENT_CERT_TYPE
Definition: tls.h:1212
#define TlsContext
Definition: tls.h:36
error_t
Error codes.
Definition: error.h:43
@ TLS_ALERT_BAD_RECORD_MAC
Definition: tls.h:1026
error_t tlsShutdown(TlsContext *context)
Gracefully close TLS session.
Definition: tls.c:2170
size_t txRecordLen
Length of the TLS record.
Definition: tls.h:2165
@ TLS_EXT_EXTENDED_MASTER_SECRET
Definition: tls.h:1216
@ TLS_CERT_ED25519_SIGN
Definition: tls.h:1139
@ TLS_CONNECTION_END_SERVER
Definition: tls.h:909
size_t cookieLen
Length of the cookie.
Definition: tls.h:2136
void tlsFreeSessionState(TlsSessionState *session)
Properly dispose a session state.
Definition: tls.c:2608
@ TLS_EXT_TOKEN_BINDING
Definition: tls.h:1217
TlsClientAuthMode
Client authentication mode.
Definition: tls.h:918
TlsKeyExchMethod
Key exchange methods.
Definition: tls.h:1078
@ TLS_EXT_SUPPORTED_GROUPS
Definition: tls.h:1203
bool_t fallbackScsvEnabled
Support for FALLBACK_SCSV.
Definition: tls.h:2320
error_t tlsSetSupportedGroups(TlsContext *context, const uint16_t *groups, uint_t length)
Specify the list of allowed ECDHE and FFDHE groups.
Definition: tls.c:596
error_t tlsAddCertificate(TlsContext *context, const char_t *certChain, size_t certChainLen, const char_t *privateKey, size_t privateKeyLen)
Import a certificate and the corresponding private key.
Definition: tls.c:1159
@ TLS_EXT_HEARTBEAT
Definition: tls.h:1208
@ TLS_FLAG_WAIT_ALL
Definition: tls.h:943
#define TLS_PREMASTER_SECRET_SIZE
Definition: tls.h:761
@ TLS_GROUP_NONE
Definition: tls.h:1277
@ TLS_GROUP_GC512B
Definition: tls.h:1316
void TlsCertificateVerify
CertificateVerify message.
Definition: tls.h:1747
uint8_t keyBlock[192]
Key material.
Definition: tls.h:2199
@ TLS_KEY_EXCH_DH_ANON
Definition: tls.h:1085
error_t(* TlsEcdhCallback)(TlsContext *context)
ECDH key agreement callback function.
Definition: tls.h:1890
const CipherAlgo * cipherAlgo
Definition: tls.h:1925
size_t rxBufferPos
Current position in RX buffer.
Definition: tls.h:2173
@ TLS_EXT_RENEGOTIATION_INFO
Definition: tls.h:1244
@ TLS_GROUP_SECT283K1
Definition: tls.h:1286
@ TLS_GROUP_SECT409K1
Definition: tls.h:1288
__start_packed struct @19 TlsPskIdentityHint
PSK identity hint.
@ TLS_GROUP_EXPLICIT_PRIME_CURVE
Definition: tls.h:1325
error_t tlsSetClientAuthMode(TlsContext *context, TlsClientAuthMode mode)
Set client authentication mode (for servers only)
Definition: tls.c:461
@ TLS13_KEY_EXCH_DHE
Definition: tls.h:1098
TlsCertificateFormat certFormat
Certificate format.
Definition: tls.h:2298
@ TLS_HASH_ALGO_INTRINSIC
Definition: tls.h:1157
TlsEncryptionEngine decryptionEngine
Decryption engine.
Definition: tls.h:2187
@ TLS_KEY_EXCH_ECDH_ECDSA
Definition: tls.h:1088
const char_t * tlsGetAlpnProtocol(TlsContext *context)
Get the name of the selected ALPN protocol.
Definition: tls.c:886
@ TLS_EXT_ENCRYPT_THEN_MAC
Definition: tls.h:1215
@ TLS_GROUP_FFDHE4096
Definition: tls.h:1321
RSA public key.
Definition: rsa.h:50
@ TLS_TYPE_APPLICATION_DATA
Definition: tls.h:967
@ TLS_TYPE_CLIENT_HELLO
Definition: tls.h:981
uint8_t fixedIvLen
Definition: tls.h:1931
@ TLS_CERT_GOST_SIGN256
Definition: tls.h:1136
@ TLS_STATE_SERVER_FINISHED
Definition: tls.h:1385
@ TLS_EXT_KEY_SHARE
Definition: tls.h:1237
uint16_t identifier
Definition: tls.h:1922
__start_packed struct @8 TlsExtensionList
List of TLS extensions.
error_t tlsEnableReplayDetection(TlsContext *context, bool_t enabled)
Enable anti-replay mechanism (for DTLS only)
Definition: tls.c:1510
@ TLS_GROUP_SECT163K1
Definition: tls.h:1278
__start_packed struct @0 TlsSequenceNumber
Sequence number.
error_t tlsSetBufferSize(TlsContext *context, size_t txBufferSize, size_t rxBufferSize)
Set TLS buffer size.
Definition: tls.c:483
@ TLS_EC_CURVE_TYPE_EXPLICIT_PRIME
Definition: tls.h:1348
@ TLS_ALERT_UNSUPPORTED_CERTIFICATE
Definition: tls.h:1033
size_t serverVerifyDataLen
Length of the server verify data.
Definition: tls.h:2184
error_t tlsSetServerName(TlsContext *context, const char_t *serverName)
Set the server name.
Definition: tls.c:367
@ TLS_TYPE_REQUEST_CONNECTION_ID
Definition: tls.h:988
uint16_t epoch
Counter value incremented on every cipher state change.
Definition: tls.h:2074
bool_t fatalAlertReceived
A fatal alert message has been received from the peer.
Definition: tls.h:2155
@ TLS_TYPE_ALERT
Definition: tls.h:965
error_t tlsSetCookieCallbacks(TlsContext *context, DtlsCookieGenerateCallback cookieGenerateCallback, DtlsCookieVerifyCallback cookieVerifyCallback, void *param)
Set cookie generation/verification callbacks (for DTLS only)
Definition: tls.c:1474
@ TLS_STATE_EARLY_DATA
Definition: tls.h:1363
size_t txBufferPos
Current position in TX buffer.
Definition: tls.h:2164
@ TLS_TYPE_SERVER_HELLO
Definition: tls.h:982
@ TLS_HASH_ALGO_SHA384
Definition: tls.h:1155
TlsClientAuthMode clientAuthMode
Client authentication mode.
Definition: tls.h:2150
uint32_t ticketLifetime
Lifetime of the ticket.
Definition: tls.h:1800
@ TLS_CERT_RSA_PSS_SIGN
Definition: tls.h:1138
uint8_t ticketPsk[TLS_MAX_HKDF_DIGEST_SIZE]
PSK associated with the ticket.
Definition: tls.h:2228
@ TLS_GROUP_GC256C
Definition: tls.h:1313
error_t tlsSetPrng(TlsContext *context, const PrngAlgo *prngAlgo, void *prngContext)
Set the pseudo-random number generator to be used.
Definition: tls.c:339
const char_t * tlsGetServerName(TlsContext *context)
Get the server name.
Definition: tls.c:415
@ TLS_TYPE_ENCRYPTED_EXTENSIONS
Definition: tls.h:987
@ TLS_GROUP_SECT233K1
Definition: tls.h:1283
TlsSequenceNumber earlyDataSeqNum
Early data sequence number.
Definition: tls.h:2241
@ TLS_MAX_FRAGMENT_LENGTH_2048
Definition: tls.h:1266
error_t tlsSetPmtu(TlsContext *context, size_t pmtu)
Set PMTU value (for DTLS only)
Definition: tls.c:1416
@ TLS_CERT_DSS_EPHEMERAL_DH
Definition: tls.h:1131
size_t ticketLen
Length of the session ticket.
Definition: tls.h:2139
@ TLS_GROUP_SECP384R1
Definition: tls.h:1301
General definitions for cryptographic algorithms.
@ TLS_GROUP_SECP192K1
Definition: tls.h:1295
__start_packed struct @4 TlsSignHashAlgos
List of signature algorithms.
uint8_t exporterMasterSecret[TLS_MAX_HKDF_DIGEST_SIZE]
Definition: tls.h:2223
RSA public-key cryptography standard.
size_t rxBufferMaxLen
Maximum number of plaintext data the RX buffer can hold.
Definition: tls.h:2170
uint16_t clientVersion
Latest version supported by the client.
Definition: tls.h:2130
@ TLS_FLAG_WAIT_ACK
Definition: tls.h:946
__start_packed struct _Ipv4Header __end_packed
@ TLS_ALERT_UNRECOGNIZED_NAME
Definition: tls.h:1053
uint16_t serverVersion
Definition: tls.h:1697
@ TLS_EXT_COOKIE
Definition: tls.h:1231
error_t tlsSaveSessionState(const TlsContext *context, TlsSessionState *session)
Save TLS session.
Definition: tls.c:2486
@ TLS_STATE_CLIENT_CERTIFICATE_VERIFY
Definition: tls.h:1378
@ TLS_TYPE_CERTIFICATE_VERIFY
Definition: tls.h:994
@ TLS_STATE_SERVER_CHANGE_CIPHER_SPEC
Definition: tls.h:1383
EcdhContext ecdhContext
ECDH context.
Definition: tls.h:2249
const TlsRenegoInfo * renegoInfo
RenegotiationInfo extension.
Definition: tls.h:2033
@ TLS_EXT_CLIENT_CERTIFICATE_URL
Definition: tls.h:1195
@ TLS_ALERT_MISSING_EXTENSION
Definition: tls.h:1050
#define TLS_MAX_CERTIFICATES
Definition: tls.h:250
EcDomainParameters peerEcParams
Peer's EC domain parameters.
Definition: tls.h:2262
DsaPublicKey peerDsaPublicKey
Peer's DSA public key.
Definition: tls.h:2258
size_t recordSizeLimit
Maximum size of record in octets.
Definition: tls.h:2078
uint8_t recordIvLen
Definition: tls.h:1932
uint8_t b[8]
Definition: tls.h:1408
@ TLS_SIGN_ALGO_ED25519
Definition: tls.h:1174
MD5 algorithm context.
Definition: md5.h:64
DSA (Digital Signature Algorithm)
@ TLS_GROUP_SECT283R1
Definition: tls.h:1287
uint_t numCipherSuites
Number of cipher suites in the list.
Definition: tls.h:2105
__start_packed struct @28 TlsChangeCipherSpec
ChangeCipherSpec message.
@ TLS_STATE_SERVER_HELLO_3
Definition: tls.h:1368
@ TLS_HASH_ALGO_SHA256
Definition: tls.h:1154
TlsExtensionType
TLS extension types.
Definition: tls.h:1192
@ TLS_ALERT_USER_CANCELED
Definition: tls.h:1048
@ TLS_CERT_ED448_SIGN
Definition: tls.h:1140
__start_packed struct @5 TlsCertificateList
List of certificates.
__start_packed struct @6 TlsCertAuthorities
List of certificate authorities.
systime_t ticketTimestamp
Timestamp to manage ticket lifetime.
Definition: tls.h:2140
@ TLS_EXT_CERTIFICATE_AUTHORITIES
Definition: tls.h:1233
@ TLS_STATE_END_OF_EARLY_DATA
Definition: tls.h:1386
@ TLS_FLAG_NO_DELAY
Definition: tls.h:947
error_t tlsSetEcdhCallback(TlsContext *context, TlsEcdhCallback ecdhCallback)
Register ECDH key agreement callback function.
Definition: tls.c:679
bool_t pskKeModeSupported
PSK key establishment supported by the client.
Definition: tls.h:2215
@ TLS_EC_CURVE_TYPE_EXPLICIT_CHAR2
Definition: tls.h:1349
@ TLS_CERT_RSA_SIGN
Definition: tls.h:1126
uint8_t certificateTypesLen
Definition: tls.h:1724
__start_packed struct @5 Tls13PskIdentityList
List of PSK identities.
@ TLS_EC_POINT_FORMAT_UNCOMPRESSED
Definition: tls.h:1336
@ TLS_EXT_DNSSEC_CHAIN
Definition: tls.h:1243
@ TLS_KEY_EXCH_SRP_SHA
Definition: tls.h:1095
error_t tlsSetTicketCallbacks(TlsContext *context, TlsTicketEncryptCallback ticketEncryptCallback, TlsTicketDecryptCallback ticketDecryptCallback, void *param)
Set ticket encryption/decryption callbacks.
Definition: tls.c:1384
@ TLS_GROUP_SECT409R1
Definition: tls.h:1289
@ TLS_FLAG_BREAK_CRLF
Definition: tls.h:945
uint_t numCerts
Number of certificates available.
Definition: tls.h:2119
@ TLS_GROUP_BRAINPOOLP512R1
Definition: tls.h:1305
TlsSocketReceiveCallback socketReceiveCallback
Socket receive callback function.
Definition: tls.h:2099
@ TLS_GROUP_FFDHE2048
Definition: tls.h:1319
error_t tlsWrite(TlsContext *context, const void *data, size_t length, size_t *written, uint_t flags)
Send application data to the remote host using TLS.
Definition: tls.c:1721
@ TLS_STATE_CLIENT_APP_TRAFFIC_KEYS
Definition: tls.h:1382
bool_t sessionTicketEnabled
Session ticket mechanism enabled.
Definition: tls.h:2306
const TlsExtension * extendedMasterSecret
ExtendedMasterSecret extension.
Definition: tls.h:2027
@ TLS_CLIENT_AUTH_NONE
Definition: tls.h:919
@ TLS_TYPE_HELLO_VERIFY_REQUEST
Definition: tls.h:983
@ TLS_GROUP_SECP160K1
Definition: tls.h:1292
__start_packed struct @11 TlsServerNameList
List of server names.
@ TLS_TYPE_CLIENT_KEY_EXCHANGE
Definition: tls.h:995
@ TLS_KEY_EXCH_DHE_PSK
Definition: tls.h:1093
uint_t keyUpdateCount
Count of consecutive KeyUpdate messages.
Definition: tls.h:2340
@ TLS_STATE_NEW_SESSION_TICKET
Definition: tls.h:1388
bool_t resume
The connection is established by resuming a session.
Definition: tls.h:2153
uint32_t ticketAgeAdd
Random value used to obscure the age of the ticket.
Definition: tls.h:1958
CipherMode
Cipher operation modes.
Definition: crypto.h:857
@ TLS_FLAG_DELAY
Definition: tls.h:948
systime_t ticketTimestamp
Timestamp to manage ticket lifetime.
Definition: tls.h:1799
__start_packed struct @22 TlsRecord
TLS record.
@ TLS_EXT_TRANSPARENCY_INFO
Definition: tls.h:1238
@ TLS_EXT_STATUS_REQUEST_V2
Definition: tls.h:1210
size_t txBufferMaxLen
Maximum number of plaintext data the TX buffer can hold.
Definition: tls.h:2161
TlsMaxFragmentLength
Maximum fragment length.
Definition: tls.h:1263
__start_packed struct @21 Tls12DigitalSignature
Digitally-signed element (TLS 1.2)
@ TLS_STATE_CLIENT_CHANGE_CIPHER_SPEC
Definition: tls.h:1379
@ TLS_ALERT_TOO_MANY_CIDS_REQUESTED
Definition: tls.h:1042
@ TLS_EXT_EC_POINT_FORMATS
Definition: tls.h:1204
TlsCompressMethod
Compression methods.
Definition: tls.h:1067
void * ticketParam
Opaque pointer passed to the ticket callbacks.
Definition: tls.h:2311
@ TLS_EXT_TLS_CERT_WITH_EXTERN_PSK
Definition: tls.h:1225
@ TLS_SIGN_ALGO_GOSTR34102012_512
Definition: tls.h:1183
@ TLS_GROUP_SECP521R1
Definition: tls.h:1302
@ TLS_GROUP_SECP192R1
Definition: tls.h:1296
@ TLS_CERT_GOST_SIGN512
Definition: tls.h:1137
@ TLS_EXT_ALPN
Definition: tls.h:1209
@ TLS_GROUP_FFDHE3072
Definition: tls.h:1320
@ TLS_ALERT_PROTOCOL_VERSION
Definition: tls.h:1044
Hello extensions.
Definition: tls.h:2003
@ TLS_GROUP_SECP160R1
Definition: tls.h:1293
@ TLS_ALERT_DECRYPTION_FAILED
Definition: tls.h:1027
TlsCertificateType
Certificate types.
Definition: tls.h:1124
TlsCertDesc * cert
Pointer to the currently selected certificate.
Definition: tls.h:2124
size_t encKeyLen
Length of the encryption key.
Definition: tls.h:2059
TlsEncryptionEngine encryptionEngine
Encryption engine.
Definition: tls.h:2186
#define TLS_MASTER_SECRET_SIZE
Definition: tls.h:754
size_t privateKeyLen
Length of the private key.
Definition: tls.h:1990
@ TLS_GROUP_BRAINPOOLP384R1_TLS13
Definition: tls.h:1309
@ TLS_HASH_ALGO_MD5
Definition: tls.h:1151
Certificate descriptor.
Definition: tls.h:1986
__start_packed struct @13 TlsProtocolNameList
List of protocol names.
uint_t size
Maximum number of entries.
Definition: tls.h:1976
TlsHashAlgo pskHashAlgo
Hash algorithm associated with the PSK.
Definition: tls.h:2273
const TlsSignHashAlgos * certSignAlgoList
SignatureAlgorithmsCert extension.
Definition: tls.h:2010
@ TLS_STATE_HANDSHAKE_TRAFFIC_KEYS
Definition: tls.h:1369
@ TLS_KEY_EXCH_RSA_PSK
Definition: tls.h:1092
@ TLS_FLAG_BREAK_CHAR
Definition: tls.h:944
Mutex object.
__start_packed struct @1 Tls13KeyShareEntry
Key share entry.
@ TLS_EXT_USER_MAPPING
Definition: tls.h:1199
Sha1Context * transcriptSha1Context
SHA-1 context used to compute verify data.
Definition: tls.h:2201
__start_packed struct @0 DtlsSequenceNumber
Sequence number.
char_t * serverName
ServerName extension.
Definition: tls.h:1964
error_t tlsSetConnectionEnd(TlsContext *context, TlsConnectionEnd entity)
Set operation mode (client or server)
Definition: tls.c:313
uint8_t hash
Definition: tls.h:1440
uint32_t systime_t
System time.
@ TLS_CLIENT_AUTH_OPTIONAL
Definition: tls.h:920
uint16_t type
Definition: tls.h:1484
error_t tlsSetMaxEarlyDataSize(TlsContext *context, size_t maxEarlyDataSize)
Send the maximum amount of 0-RTT data the server can accept.
Definition: tls.c:1538
__start_packed struct @0 Tls13Cookie
Cookie.
EC public key.
Definition: ec.h:94
size_t ticketPskLen
Length of the PSK associated with the ticket.
Definition: tls.h:2229
@ TLS_TYPE_SERVER_KEY_EXCHANGE
Definition: tls.h:991
@ TLS_GROUP_GC512C
Definition: tls.h:1317
DtlsCookieGenerateCallback cookieGenerateCallback
Cookie generation callback function.
Definition: tls.h:2348
TlsPskCallback pskCallback
PSK callback function.
Definition: tls.h:2271
@ TLS_EC_CURVE_TYPE_NAMED_CURVE
Definition: tls.h:1350
uint16_t group
Definition: tls13_misc.h:206
uint8_t flags
Definition: tcp.h:349
@ TLS_TYPE_NONE
Definition: tls.h:963
uint32_t maxEarlyDataSize
Maximum amount of 0-RTT data that the client is allowed to send.
Definition: tls.h:1961
const TlsExtension * selectedIdentity
PreSharedKey extension (ServerHello)
Definition: tls.h:2043
@ TLS_TYPE_EKT_KEY
Definition: tls.h:1002
uint16_t namedGroup
ECDHE or FFDHE named group.
Definition: tls.h:2147
error_t(* TlsEcdsaSignCallback)(TlsContext *context, const uint8_t *digest, size_t digestLen, EcdsaSignature *signature)
ECDSA signature generation callback function.
Definition: tls.h:1897
TlsSignatureAlgo signAlgo
Signature algorithm used to sign the end entity certificate.
Definition: tls.h:1992
const uint16_t * cipherSuites
List of supported cipher suites.
Definition: tls.h:2104
char char_t
Definition: compiler_port.h:43
uint16_t ticketCipherSuite
Cipher suite associated with the ticket.
Definition: tls.h:2232
uint16_t txMsgSeq
Send sequence number.
Definition: tls.h:2356
@ TLS_GROUP_SECP224R1
Definition: tls.h:1298
uint8_t iv[16]
Initialization vector.
Definition: tls.h:2060
GCM context.
Definition: gcm.h:64
uint8_t ticket[]
Definition: tls.h:1758
@ TLS_KEY_EXCH_NONE
Definition: tls.h:1079
TlsNameType
Name type.
Definition: tls.h:1253
const TlsExtension * clientCertType
Definition: tls.h:2022
__start_packed struct @18 TlsPskIdentity
PSK identity.
@ TLS13_KEY_EXCH_PSK_ECDHE
Definition: tls.h:1102
@ TLS_STATE_CLIENT_HELLO_2
Definition: tls.h:1362
@ TLS_ALERT_BAD_CERTIFICATE
Definition: tls.h:1032
__start_packed struct @10 TlsServerName
Server name.
bool_t replayDetectionEnabled
Anti-replay mechanism enabled.
Definition: tls.h:2369
const HashAlgo * hashAlgo
Definition: tls.h:1927
TlsContentType
Content type.
Definition: tls.h:962
@ TLS_STATE_CLOSING
Definition: tls.h:1391
@ TLS_STATE_SERVER_CERTIFICATE_VERIFY
Definition: tls.h:1373
size_t rxBufferLen
Number of bytes available for reading.
Definition: tls.h:2172
@ TLS_EXT_EXTERNAL_SESSION_ID
Definition: tls.h:1241
@ TLS_ALERT_INAPPROPRIATE_FALLBACK
Definition: tls.h:1047
@ TLS_EARLY_DATA_ACCEPTED
Definition: tls.h:932
error_t tlsSetRpkVerifyCallback(TlsContext *context, TlsRpkVerifyCallback rpkVerifyCallback)
Register the raw public key verification callback function.
Definition: tls.c:1099
uint8_t macKey[48]
MAC key.
Definition: tls.h:2056
void TlsClientKeyExchange
ClientKeyExchange message.
Definition: tls.h:1740
@ TLS_STATE_SERVER_CERTIFICATE
Definition: tls.h:1371
TlsEcCurveType
EC curve types.
Definition: tls.h:1347
@ TLS_CLIENT_AUTH_REQUIRED
Definition: tls.h:921
@ TLS_EXT_PADDING
Definition: tls.h:1214
@ TLS_ALERT_LEVEL_FATAL
Definition: tls.h:1014
TLS session state.
Definition: tls.h:1943
error_t tlsInitSessionState(TlsSessionState *session)
Initialize session state.
Definition: tls.c:2465
size_t rxFragQueueLen
Length of the reassembly queue.
Definition: tls.h:2360
@ TLS_GROUP_SECT193R2
Definition: tls.h:1282
uint16_t versionMax
Maximum version accepted by the implementation.
Definition: tls.h:2133
uint32_t replayWindow[(DTLS_REPLAY_WINDOW_SIZE+31)/32]
Definition: tls.h:2370
@ TLS_STATE_CLIENT_KEY_EXCHANGE
Definition: tls.h:1377
const CipherAlgo * cipherAlgo
Cipher algorithm.
Definition: tls.h:2064
__start_packed struct @16 TlsCertTypeList
List of supported certificate types.
uint8_t verifyDataLen
Definition: tls.h:1934
error_t tlsSetCipherSuites(TlsContext *context, const uint16_t *cipherSuites, uint_t length)
Specify the list of allowed cipher suites.
Definition: tls.c:567
TlsTransportProtocol
TLS transport protocols.
Definition: tls.h:896
error_t(* DtlsCookieVerifyCallback)(TlsContext *context, const DtlsClientParameters *clientParams, const uint8_t *cookie, size_t length, void *param)
DTLS cookie verification callback function.
Definition: dtls_misc.h:245
@ TLS_TYPE_FINISHED
Definition: tls.h:996
void TlsHelloRequest
HelloRequest message.
Definition: tls.h:1675
@ TLS_GROUP_SECT193R1
Definition: tls.h:1281
@ TLS_SIGN_ALGO_RSA_PSS_RSAE_SHA512
Definition: tls.h:1173
bool_t serverCertTypeExtReceived
The ServerCertType extension has been received.
Definition: tls.h:2302
@ TLS_STATE_CLIENT_CERTIFICATE
Definition: tls.h:1376
TlsCertVerifyCallback certVerifyCallback
Certificate verification callback function.
Definition: tls.h:2122
void * certVerifyParam
Opaque pointer passed to the certificate verification callback.
Definition: tls.h:2123
@ TLS_SIGN_ALGO_RSA_PSS_PSS_SHA256
Definition: tls.h:1176
error_t tlsWriteEarlyData(TlsContext *context, const void *data, size_t length, size_t *written, uint_t flags)
Send early data to the remote TLS server.
Definition: tls.c:1567
uint8_t msgType
Definition: tls.h:1665
@ TLS_STATE_CLIENT_CHANGE_CIPHER_SPEC_2
Definition: tls.h:1380
TlsHashAlgo ticketHashAlgo
Hash algorithm associated with the ticket.
Definition: tls.h:1959
uint_t alertCount
Count of consecutive warning alerts.
Definition: tls.h:2328
error_t tlsSetDhParameters(TlsContext *context, const char_t *params, size_t length)
Import Diffie-Hellman parameters.
Definition: tls.c:651
@ TLS_ALERT_CERTIFICATE_EXPIRED
Definition: tls.h:1035
@ TLS_STATE_ENCRYPTED_EXTENSIONS
Definition: tls.h:1370
@ TLS_EXT_SERVER_CERT_TYPE
Definition: tls.h:1213
@ TLS_KEY_EXCH_PSK
Definition: tls.h:1091
@ TLS_STATE_INIT
Definition: tls.h:1360
uint8_t * certRequestContext
Certificate request context.
Definition: tls.h:2212
@ TLS_EXT_PASSWORD_SALT
Definition: tls.h:1223
@ TLS_KEY_EXCH_ECDHE_PSK
Definition: tls.h:1094
@ TLS_NAME_TYPE_HOSTNAME
Definition: tls.h:1254
TlsSocketSendCallback socketSendCallback
Socket send callback function.
Definition: tls.h:2098
@ TLS_ALERT_NO_APPLICATION_PROTOCOL
Definition: tls.h:1058
uint8_t sessionId[]
Definition: tls.h:1687
const PrngAlgo * prngAlgo
Pseudo-random number generator to be used.
Definition: tls.h:2101
@ TLS_CERT_RSA_FIXED_ECDH
Definition: tls.h:1134
#define TLS_MAX_HKDF_DIGEST_SIZE
Definition: tls.h:866
@ TLS_TYPE_HEARTBEAT
Definition: tls.h:968
systime_t clientHelloTimestamp
Time at which the ClientHello message was sent.
Definition: tls.h:2210
TlsSignatureAlgo
Signature algorithms.
Definition: tls.h:1166
uint8_t serverRandom[TLS_RANDOM_SIZE]
Server random value.
Definition: tls.h:2178
size_t certRequestContextLen
Length of the certificate request context.
Definition: tls.h:2213
__start_packed struct @7 TlsExtension
TLS extension.
@ TLS_EXT_SRP
Definition: tls.h:1205
error_t tlsSetEcdsaVerifyCallback(TlsContext *context, TlsEcdsaVerifyCallback ecdsaVerifyCallback)
Register ECDSA signature verification callback function.
Definition: tls.c:732
@ TLS_CONNECTION_END_CLIENT
Definition: tls.h:908
char_t * pskIdentityHint
PSK identity hint.
Definition: tls.h:2270
TlsCipherSuiteInfo cipherSuite
Negotiated cipher suite.
Definition: tls.h:2143
bool_t tlsIsRxReady(TlsContext *context)
Check whether some data is available in the receive buffer.
Definition: tls.c:2125
uint8_t clientAppTrafficSecret[TLS_MAX_HKDF_DIGEST_SIZE]
Definition: tls.h:2221
@ TLS_MAX_FRAGMENT_LENGTH_1024
Definition: tls.h:1265
TlsAlertLevel
Alert level.
Definition: tls.h:1012
@ TLS_EXT_CACHED_INFO
Definition: tls.h:1218
uint_t changeCipherSpecCount
Count of consecutive ChangeCipherSpec messages.
Definition: tls.h:2336
Common interface for encryption algorithms.
Definition: crypto.h:952
__start_packed struct @15 TlsEcPointFormatList
List of supported EC point formats.
@ TLS_TYPE_CERTIFICATE_REQUEST
Definition: tls.h:992
uint8_t encKeyLen
Definition: tls.h:1930
@ TLS_EXT_PRE_SHARED_KEY
Definition: tls.h:1228
@ TLS_EC_POINT_FORMAT_ANSI_X962_COMPRESSED_PRIME
Definition: tls.h:1337
void tlsFree(TlsContext *context)
Release TLS context.
Definition: tls.c:2330
uint8_t secret[48]
Master secret.
Definition: tls.h:1798
@ TLS_GROUP_SECT571R1
Definition: tls.h:1291
error_t tlsRead(TlsContext *context, void *data, size_t size, size_t *received, uint_t flags)
Receive application data from a the remote host using TLS.
Definition: tls.c:1856
@ TLS_GROUP_FFDHE_MAX
Definition: tls.h:1324
TlsCache * cache
TLS session cache.
Definition: tls.h:2126
TlsState state
TLS handshake finite state machine.
Definition: tls.h:2093
TlsContentType rxBufferType
Type of data that resides in the RX buffer.
Definition: tls.h:2171
char_t * serverName
Fully qualified DNS hostname of the server.
Definition: tls.h:2110
@ TLS_SIGN_ALGO_RSA
Definition: tls.h:1168
size_t rxRecordPos
Current position in the TLS record.
Definition: tls.h:2175
char_t hostname[]
Definition: tls.h:1520
@ TLS_TYPE_TLS12_CID
Definition: tls.h:969
error_t tlsSetPskIdentity(TlsContext *context, const char_t *pskIdentity)
Set the PSK identity to be used by the client.
Definition: tls.c:975
uint16_t version
TLS protocol version.
Definition: tls.h:1944
@ TLS_TYPE_SUPPLEMENTAL_DATA
Definition: tls.h:999
bool_t sessionTicketExtSent
The SessionTicket extension has been sent.
Definition: tls.h:2308
SHA-1 algorithm context.
Definition: sha1.h:64
@ TLS_CERT_ECDSA_SIGN
Definition: tls.h:1133
@ TLS_ALERT_BAD_CERTIFICATE_STATUS_RESPONSE
Definition: tls.h:1054
const TlsExtension * recordSizeLimit
RecordSizeLimit extension.
Definition: tls.h:2015
systime_t startTime
Definition: tls.h:2346
@ TLS_KEY_EXCH_DHE_DSS
Definition: tls.h:1084
bool_t clientCertRequested
This flag tells whether the client certificate is requested.
Definition: tls.h:2151
@ TLS_TRANSPORT_PROTOCOL_STREAM
Definition: tls.h:897
uint16_t version
Negotiated TLS version.
Definition: tls.h:2055
uint8_t mode
Definition: ntp_common.h:149
uint_t newSessionTicketCount
Number of NewSessionTicket messages that have been sent.
Definition: tls.h:2226
error_t tlsSetTransportProtocol(TlsContext *context, TlsTransportProtocol transportProtocol)
Set the transport protocol to be used.
Definition: tls.c:284
uint8_t random[32]
Definition: tls.h:1685
TlsEcdhCallback ecdhCallback
Definition: tls.h:2113
bool_t earlyDataEnabled
EarlyData is enabled.
Definition: tls.h:2238
const char_t * certChain
End entity certificate chain (PEM format)
Definition: tls.h:1987
bool_t recordSizeLimitExtReceived
The RecordSizeLimit extension has been received.
Definition: tls.h:2283
RsaPublicKey peerRsaPublicKey
Peer's RSA public key.
Definition: tls.h:2254
bool_t unknownProtocolsAllowed
Unknown ALPN protocols allowed.
Definition: tls.h:2287
@ TLS_EXT_SIGNATURE_ALGORITHMS
Definition: tls.h:1206
uint32_t ticketLifetime
Lifetime of the ticket.
Definition: tls.h:1957
Common interface for hash algorithms.
Definition: crypto.h:930
@ TLS_CERT_NONE
Definition: tls.h:1125
char_t * selectedProtocol
Selected ALPN protocol.
Definition: tls.h:2289
error_t(* TlsPskCallback)(TlsContext *context, const uint8_t *pskIdentity, size_t pskIdentityLen)
Pre-shared key callback function.
Definition: tls.h:1848
const TlsServerNameList * serverNameList
ServerName extension.
Definition: tls.h:2006
TlsEarlyDataStatus tlsGetEarlyDataStatus(TlsContext *context)
Check whether the server has accepted or rejected the early data.
Definition: tls.c:1678
@ TLS_GROUP_GC256A
Definition: tls.h:1311
size_t trustedCaListLen
Number of trusted CA in the list.
Definition: tls.h:2121
systime_t retransmitTimestamp
Time at which the datagram was sent.
Definition: tls.h:2353
const TlsExtension * selectedVersion
SupportedVersions extension (ServerHello)
Definition: tls.h:2005
@ TLS_EXT_POST_HANDSHAKE_AUTH
Definition: tls.h:1235
TlsSequenceNumber seqNum
TLS sequence number.
Definition: tls.h:2072
uint8_t clientEarlyTrafficSecret[TLS_MAX_HKDF_DIGEST_SIZE]
Definition: tls.h:2218
@ TLS_STATE_SERVER_CHANGE_CIPHER_SPEC_2
Definition: tls.h:1384
@ TLS_GROUP_SECT233R1
Definition: tls.h:1284
void * cipherContext
Cipher context.
Definition: tls.h:2065
@ TLS_TYPE_NEW_SESSION_TICKET
Definition: tls.h:984
TlsEcdsaSignCallback ecdsaSignCallback
Definition: tls.h:2114
TlsNamedGroup
Named groups.
Definition: tls.h:1276
@ TLS_TYPE_HELLO_REQUEST
Definition: tls.h:980
bool_t earlyDataRejected
The 0-RTT data have been rejected by the server.
Definition: tls.h:2239
uint16_t ticketLen
Definition: tls.h:1757
const char_t * privateKey
Private key (PEM format)
Definition: tls.h:1989
error_t tlsSetPskIdentityHint(TlsContext *context, const char_t *pskIdentityHint)
Set the PSK identity hint to be used by the server.
Definition: tls.c:1024
@ TLS_EXT_STATUS_REQUEST
Definition: tls.h:1198
void(* TlsKeyLogCallback)(TlsContext *context, const char_t *key)
Key logging callback function (for debugging purpose only)
Definition: tls.h:1913
__start_packed struct @12 TlsProtocolName
Protocol name.
size_t macKeyLen
Length of the MAC key.
Definition: tls.h:2057
__start_packed struct @17 TlsRenegoInfo
Renegotiated connection.
@ TLS_TYPE_HELLO_RETRY_REQUEST
Definition: tls.h:986
bool_t updatedClientHelloReceived
An updated ClientHello message has been received.
Definition: tls.h:2211
error_t(* TlsCertVerifyCallback)(TlsContext *context, const X509CertificateInfo *certInfo, uint_t pathLen, void *param)
Certificate verification callback function.
Definition: tls.h:1856
bool_t tlsIsTxReady(TlsContext *context)
Check whether some data is ready for transmission.
Definition: tls.c:2092
unsigned int uint_t
Definition: compiler_port.h:45
GcmContext * gcmContext
GCM context.
Definition: tls.h:2070
error_t tlsSetPreferredGroup(TlsContext *context, uint16_t group)
Specify the preferred ECDHE or FFDHE group.
Definition: tls.c:623
TlsFlags
Flags used by read and write functions.
Definition: tls.h:941
@ TLS_GROUP_SECT163R1
Definition: tls.h:1279
TlsHashAlgo signHashAlgo
Hash algorithm used for signing.
Definition: tls.h:2146
@ TLS_ALERT_CERTIFICATE_REVOKED
Definition: tls.h:1034
error_t tlsEnableSecureRenegotiation(TlsContext *context, bool_t enabled)
Enable secure renegotiation.
Definition: tls.c:1330
size_t txBufferLen
Number of bytes that are pending to be sent.
Definition: tls.h:2163
uint_t retransmitCount
Retransmission counter.
Definition: tls.h:2352
uint16_t rxRecordVersion
Version of the incoming record.
Definition: tls.h:2363
@ TLS_GROUP_ECDH_X448
Definition: tls.h:1307
@ TLS_STATE_SERVER_HELLO_DONE
Definition: tls.h:1375
__start_packed struct @26 TlsCertificateRequest
CertificateRequest message.
size_t recordIvLen
Length of the IV.
Definition: tls.h:2062
@ TLS_STATE_SERVER_HELLO_2
Definition: tls.h:1367
@ TLS_EXT_USE_SRTP
Definition: tls.h:1207
@ TLS_ALERT_HANDSHAKE_FAILURE
Definition: tls.h:1030
@ TLS_STATE_CLIENT_FINISHED
Definition: tls.h:1381
__start_packed struct @30 TlsPlaintextSessionState
Session state information.
int_t selectedIdentity
Selected PSK identity.
Definition: tls.h:2214
TlsSignHashAlgo algorithm
Definition: tls.h:1640
@ TLS_SIGN_ALGO_ECDSA_BRAINPOOLP384R1_TLS13_SHA384
Definition: tls.h:1180
uint8_t macKeyLen
Definition: tls.h:1929
@ TLS_CERT_DSS_FIXED_DH
Definition: tls.h:1129
DtlsCookieVerifyCallback cookieVerifyCallback
Cookie verification callback function.
Definition: tls.h:2349
Legacy definitions.
@ TLS_ALERT_INTERNAL_ERROR
Definition: tls.h:1046
@ TLS_CERT_RSA_FIXED_DH
Definition: tls.h:1128
__start_packed struct @20 TlsDigitalSignature
Digitally-signed element (TLS 1.0 and TLS 1.1)
const uint16_t * supportedGroups
List of supported named groups.
Definition: tls.h:2107
error_t tlsEnableFallbackScsv(TlsContext *context, bool_t enabled)
Perform fallback retry (for clients only)
Definition: tls.c:1356
@ TLS_SIGN_ALGO_ECDSA_BRAINPOOLP256R1_TLS13_SHA256
Definition: tls.h:1179
@ TLS_TYPE_KEY_UPDATE
Definition: tls.h:1000
@ TLS_SIGN_ALGO_ECDSA
Definition: tls.h:1170
TlsCertDesc certs[TLS_MAX_CERTIFICATES]
End entity certificates (PEM format)
Definition: tls.h:2118
error_t(* TlsTicketDecryptCallback)(TlsContext *context, const uint8_t *ciphertext, size_t ciphertextLen, uint8_t *plaintext, size_t *plaintextLen, void *param)
Ticket decryption callback function.
Definition: tls.h:1881
RTOS abstraction layer.
@ TLS_KEY_EXCH_DHE_RSA
Definition: tls.h:1082
__start_packed struct @24 TlsClientHello
ClientHello message.
error_t tlsEnableSessionTickets(TlsContext *context, bool_t enabled)
Enable session ticket mechanism.
Definition: tls.c:1304
#define TlsEncryptionEngine
Definition: tls.h:40
uint16_t pskCipherSuite
Cipher suite associated with the PSK.
Definition: tls.h:2272
bool_t extendedMasterSecret
Extended master secret computation.
Definition: tls.h:1951
error_t tlsSetTrustedCaList(TlsContext *context, const char_t *trustedCaList, size_t length)
Import a trusted CA list.
Definition: tls.c:1127
void TlsServerKeyExchange
ServerKeyExchange message.
Definition: tls.h:1715
@ TLS_SIGN_ALGO_RSA_PSS_RSAE_SHA384
Definition: tls.h:1172
bool_t earlyDataExtReceived
The EarlyData extension has been received.
Definition: tls.h:2240
const HashAlgo * prfHashAlgo
Definition: tls.h:1928
@ TLS_GROUP_FFDHE8192
Definition: tls.h:1323
uint8_t serverAppTrafficSecret[TLS_MAX_HKDF_DIGEST_SIZE]
Definition: tls.h:2222
const TlsSupportedGroupList * supportedGroupList
SupportedGroups extension.
Definition: tls.h:2007
TlsNamedGroup namedCurve
Named curve used to generate the EC public key.
Definition: tls.h:1994
ECDH context.
Definition: ecdh.h:59
systime_t timeout
Timeout for blocking calls.
Definition: tls.h:2345
TlsEcdsaVerifyCallback ecdsaVerifyCallback
Definition: tls.h:2115
const TlsExtension * serverCertType
Definition: tls.h:2024
TlsCertificateType peerCertType
Peer's certificate type.
Definition: tls.h:2149
@ TLS_EXT_RECORD_SIZE_LIMIT
Definition: tls.h:1220
HMAC (Keyed-Hashing for Message Authentication)
error_t tlsSetPskCallback(TlsContext *context, TlsPskCallback pskCallback)
Register PSK callback function.
Definition: tls.c:1073
bool_t sessionTicketExtReceived
The SessionTicket extension has been received.
Definition: tls.h:2307
@ TLS_KEY_EXCH_DH_RSA
Definition: tls.h:1081
@ TLS_CERT_FORMAT_X509
Definition: tls.h:1112
void * TlsSocketHandle
Socket handle.
Definition: tls.h:1817
TlsEarlyDataStatus
Early data status.
Definition: tls.h:930
@ TLS_GROUP_BRAINPOOLP384R1
Definition: tls.h:1304
@ TLS_EXT_SIGNED_CERT_TIMESTAMP
Definition: tls.h:1211
char_t * ticketAlpn
ALPN protocol associated with the ticket.
Definition: tls.h:1960
@ TLS_MAX_FRAGMENT_LENGTH_512
Definition: tls.h:1264
error_t tlsSetKeyLogCallback(TlsContext *context, TlsKeyLogCallback keyLogCallback)
Register key logging callback function (for debugging purpose only)
Definition: tls.c:759
@ TLS_ALERT_CERTIFICATE_UNKNOWN
Definition: tls.h:1036
bool_t emsExtReceived
The ExtendedMasterSecret extension has been received.
Definition: tls.h:2294
void TlsCertificate
Certificate message.
Definition: tls.h:1708
@ TLS_EC_POINT_FORMAT_ANSI_X962_COMPRESSED_CHAR2
Definition: tls.h:1338
uint8_t description
Definition: tls.h:1786
const Tls13PskIdentityList * identityList
PreSharedKey extension (ClientHello)
Definition: tls.h:2041
TLS context.
Definition: tls.h:2092
char_t * protocolList
List of supported ALPN protocols.
Definition: tls.h:2288
@ TLS_TYPE_CERTIFICATE_URL
Definition: tls.h:997
void tlsFreeCache(TlsCache *cache)
Properly dispose a session cache.
Definition: tls_cache.c:320
uint8_t data[]
Definition: tls.h:1655
@ TLS_STATE_CLOSED
Definition: tls.h:1392