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