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