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