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