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