1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** NetX Crypto Component                                                 */
17 /**                                                                       */
18 /**   Transport Layer Security (TLS)                                      */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #ifndef NX_CRYPTO_STANDALONE_ENABLE
24 #include "nx_secure_tls.h"
25 
26 
27 /**************************************************************************/
28 /*                                                                        */
29 /*  FUNCTION                                               RELEASE        */
30 /*                                                                        */
31 /*    nx_crypto_generic_ciphersuites                      PORTABLE C      */
32 /*                                                           6.2.1       */
33 /*  AUTHOR                                                                */
34 /*                                                                        */
35 /*    Timothy Stapko, Microsoft Corporation                               */
36 /*                                                                        */
37 /*  DESCRIPTION                                                           */
38 /*                                                                        */
39 /*     This table of function pointers provides a mapping from TLS        */
40 /*     ciphersuites to the necessary cryptographic methods for a given    */
41 /*     platform. It can be used as a model to develop a hardware-specific */
42 /*     cryptography table for TLS.                                        */
43 /*                                                                        */
44 /*  INPUT                                                                 */
45 /*                                                                        */
46 /*    None                                                                */
47 /*                                                                        */
48 /*  OUTPUT                                                                */
49 /*                                                                        */
50 /*    None                                                                */
51 /*                                                                        */
52 /*  CALLS                                                                 */
53 /*                                                                        */
54 /*    None                                                                */
55 /*                                                                        */
56 /*  CALLED BY                                                             */
57 /*                                                                        */
58 /*    Application Code                                                    */
59 /*                                                                        */
60 /*  RELEASE HISTORY                                                       */
61 /*                                                                        */
62 /*    DATE              NAME                      DESCRIPTION             */
63 /*                                                                        */
64 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
65 /*  09-30-2020     Timothy Stapko           Modified comment(s), added    */
66 /*                                            curves in the crypto array, */
67 /*                                            added TLS ciphersuite entry,*/
68 /*                                            resulting in version 6.1    */
69 /*  04-25-2022     Yuxin Zhou               Modified comment(s), added    */
70 /*                                            x25519 and x448 curves,     */
71 /*                                            resulting in version 6.1.11 */
72 /*  07-29-2022     Yuxin Zhou               Modified comment(s),          */
73 /*                                            added x448 curves,          */
74 /*                                            resulting in version 6.1.12 */
75 /*  10-31-2022     Yanwu Cai                Modified comment(s),          */
76 /*                                            resulting in version 6.2.0  */
77 /*  03-08-2023     Yanwu Cai                Modified comment(s),          */
78 /*                                            fixed compiler errors when  */
79 /*                                            x509 is disabled,           */
80 /*                                            resulting in version 6.2.1  */
81 /*                                                                        */
82 /**************************************************************************/
83 
84 /* Define cryptographic methods for use with TLS. */
85 
86 extern NX_CRYPTO_METHOD crypto_method_none;
87 extern NX_CRYPTO_METHOD crypto_method_null;
88 extern NX_CRYPTO_METHOD crypto_method_aes_cbc_128;
89 extern NX_CRYPTO_METHOD crypto_method_aes_cbc_256;
90 extern NX_CRYPTO_METHOD crypto_method_aes_ccm_8;
91 extern NX_CRYPTO_METHOD crypto_method_aes_ccm_16;
92 extern NX_CRYPTO_METHOD crypto_method_aes_128_gcm_16;
93 extern NX_CRYPTO_METHOD crypto_method_aes_256_gcm_16;
94 extern NX_CRYPTO_METHOD crypto_method_ecdsa;
95 extern NX_CRYPTO_METHOD crypto_method_ecdhe;
96 extern NX_CRYPTO_METHOD crypto_method_hmac_sha1;
97 extern NX_CRYPTO_METHOD crypto_method_hmac_sha256;
98 extern NX_CRYPTO_METHOD crypto_method_hmac_md5;
99 extern NX_CRYPTO_METHOD crypto_method_rsa;
100 extern NX_CRYPTO_METHOD crypto_method_pkcs1;
101 extern NX_CRYPTO_METHOD crypto_method_auth_psk;
102 extern NX_CRYPTO_METHOD crypto_method_ec_secp256;
103 extern NX_CRYPTO_METHOD crypto_method_ec_secp384;
104 extern NX_CRYPTO_METHOD crypto_method_ec_secp521;
105 extern NX_CRYPTO_METHOD crypto_method_ec_x25519;
106 extern NX_CRYPTO_METHOD crypto_method_ec_x448;
107 extern NX_CRYPTO_METHOD crypto_method_md5;
108 extern NX_CRYPTO_METHOD crypto_method_sha1;
109 extern NX_CRYPTO_METHOD crypto_method_sha224;
110 extern NX_CRYPTO_METHOD crypto_method_sha256;
111 extern NX_CRYPTO_METHOD crypto_method_sha384;
112 extern NX_CRYPTO_METHOD crypto_method_sha512;
113 extern NX_CRYPTO_METHOD crypto_method_hkdf_sha1;
114 extern NX_CRYPTO_METHOD crypto_method_hkdf_sha256;
115 extern NX_CRYPTO_METHOD crypto_method_tls_prf_1;
116 extern NX_CRYPTO_METHOD crypto_method_tls_prf_sha256;
117 extern NX_CRYPTO_METHOD crypto_method_tls_prf_sha384;
118 extern NX_CRYPTO_METHOD crypto_method_hkdf;
119 extern NX_CRYPTO_METHOD crypto_method_hmac;
120 
121 
122 /* Ciphersuite table without ECC. */
123 /* Lookup table used to map ciphersuites to cryptographic routines. */
124 /* For TLS Web servers, define NX_SECURE_ENABLE_AEAD_CIPHER to allow web browsers to connect using AES_128_GCM cipher suites. */
125 NX_SECURE_TLS_CIPHERSUITE_INFO _nx_crypto_ciphersuite_lookup_table[] =
126 {
127     /* Ciphersuite,                           public cipher,            public_auth,              session cipher & cipher mode,   iv size, key size,  hash method,                    hash size, TLS PRF */
128 #ifndef NX_SECURE_DISABLE_X509
129 #ifdef NX_SECURE_ENABLE_AEAD_CIPHER
130     {TLS_RSA_WITH_AES_128_GCM_SHA256,         &crypto_method_rsa,       &crypto_method_rsa,       &crypto_method_aes_128_gcm_16,  16,      16,        &crypto_method_null,            0,         &crypto_method_tls_prf_sha256},
131 #endif /* NX_SECURE_ENABLE_AEAD_CIPHER */
132     {TLS_RSA_WITH_AES_256_CBC_SHA256,         &crypto_method_rsa,       &crypto_method_rsa,       &crypto_method_aes_cbc_256,     16,      32,        &crypto_method_hmac_sha256,     32,        &crypto_method_tls_prf_sha256},
133     {TLS_RSA_WITH_AES_128_CBC_SHA256,         &crypto_method_rsa,       &crypto_method_rsa,       &crypto_method_aes_cbc_128,     16,      16,        &crypto_method_hmac_sha256,     32,        &crypto_method_tls_prf_sha256},
134 #endif /* NX_SECURE_DISABLE_X509 */
135 
136 #ifdef NX_SECURE_ENABLE_PSK_CIPHERSUITES
137     {TLS_PSK_WITH_AES_128_CBC_SHA256,         &crypto_method_null,      &crypto_method_auth_psk,  &crypto_method_aes_cbc_128,     16,      16,        &crypto_method_hmac_sha256,     32,        &crypto_method_tls_prf_sha256},
138 #ifdef NX_SECURE_ENABLE_AEAD_CIPHER
139     {TLS_PSK_WITH_AES_128_CCM_8,              &crypto_method_null,      &crypto_method_auth_psk,  &crypto_method_aes_ccm_8,       16,      16,        &crypto_method_null,            0,         &crypto_method_tls_prf_sha256},
140 #endif
141 #endif /* NX_SECURE_ENABLE_PSK_CIPHERSUITES */
142 };
143 
144 const UINT _nx_crypto_ciphersuite_lookup_table_size = sizeof(_nx_crypto_ciphersuite_lookup_table) / sizeof(NX_SECURE_TLS_CIPHERSUITE_INFO);
145 
146 #ifndef NX_SECURE_DISABLE_X509
147 /* Lookup table for X.509 digital certificates - they need a public-key algorithm and a hash routine for verification. */
148 NX_SECURE_X509_CRYPTO _nx_crypto_x509_cipher_lookup_table[] =
149 {
150     /* OID identifier,                        public cipher,            hash method */
151     {NX_SECURE_TLS_X509_TYPE_RSA_SHA_256,    &crypto_method_rsa,       &crypto_method_sha256},
152     {NX_SECURE_TLS_X509_TYPE_RSA_SHA_384,    &crypto_method_rsa,       &crypto_method_sha384},
153     {NX_SECURE_TLS_X509_TYPE_RSA_SHA_512,    &crypto_method_rsa,       &crypto_method_sha512},
154     {NX_SECURE_TLS_X509_TYPE_RSA_SHA_1,      &crypto_method_rsa,       &crypto_method_sha1},
155     {NX_SECURE_TLS_X509_TYPE_RSA_MD5,        &crypto_method_rsa,       &crypto_method_md5},
156 };
157 
158 const UINT _nx_crypto_x509_cipher_lookup_table_size = sizeof(_nx_crypto_x509_cipher_lookup_table) / sizeof(NX_SECURE_X509_CRYPTO);
159 #endif /* NX_SECURE_DISABLE_X509 */
160 
161 /* Define the object we can pass into TLS. */
162 NX_SECURE_TLS_CRYPTO nx_crypto_tls_ciphers =
163 {
164     /* Ciphersuite lookup table and size. */
165     _nx_crypto_ciphersuite_lookup_table,
166     sizeof(_nx_crypto_ciphersuite_lookup_table) / sizeof(NX_SECURE_TLS_CIPHERSUITE_INFO),
167 
168 #ifndef NX_SECURE_DISABLE_X509
169     /* X.509 certificate cipher table and size. */
170     _nx_crypto_x509_cipher_lookup_table,
171     sizeof(_nx_crypto_x509_cipher_lookup_table) / sizeof(NX_SECURE_X509_CRYPTO),
172 #endif
173 
174     /* TLS version-specific methods. */
175 #if (NX_SECURE_TLS_TLS_1_0_ENABLED || NX_SECURE_TLS_TLS_1_1_ENABLED)
176     &crypto_method_md5,
177     &crypto_method_sha1,
178     &crypto_method_tls_prf_1,
179 #endif
180 
181 #if (NX_SECURE_TLS_TLS_1_2_ENABLED)
182     &crypto_method_sha256,
183     &crypto_method_tls_prf_sha256,
184 #endif
185 
186 #if (NX_SECURE_TLS_TLS_1_3_ENABLED)
187     &crypto_method_hkdf,
188     &crypto_method_hmac,
189     &crypto_method_ecdhe,
190 #endif
191 };
192 
193 
194 #ifdef NX_SECURE_ENABLE_ECC_CIPHERSUITE
195 
196 #ifndef NX_SECURE_DISABLE_X509
197 
198 /* Lookup table for X.509 digital certificates - they need a public-key algorithm and a hash routine for verification. */
199 NX_SECURE_X509_CRYPTO _nx_crypto_x509_cipher_lookup_table_ecc[] =
200 {
201     /* OID identifier,                        public cipher,            hash method */
202     {NX_SECURE_TLS_X509_TYPE_ECDSA_SHA_256,  &crypto_method_ecdsa,     &crypto_method_sha256},
203     {NX_SECURE_TLS_X509_TYPE_ECDSA_SHA_384,  &crypto_method_ecdsa,     &crypto_method_sha384},
204     {NX_SECURE_TLS_X509_TYPE_ECDSA_SHA_512,  &crypto_method_ecdsa,     &crypto_method_sha512},
205     {NX_SECURE_TLS_X509_TYPE_RSA_SHA_256,    &crypto_method_rsa,       &crypto_method_sha256},
206     {NX_SECURE_TLS_X509_TYPE_RSA_SHA_384,    &crypto_method_rsa,       &crypto_method_sha384},
207     {NX_SECURE_TLS_X509_TYPE_RSA_SHA_512,    &crypto_method_rsa,       &crypto_method_sha512},
208     {NX_SECURE_TLS_X509_TYPE_ECDSA_SHA_224,  &crypto_method_ecdsa,     &crypto_method_sha224},
209     {NX_SECURE_TLS_X509_TYPE_ECDSA_SHA_1,    &crypto_method_ecdsa,     &crypto_method_sha1},
210     {NX_SECURE_TLS_X509_TYPE_RSA_SHA_1,      &crypto_method_rsa,       &crypto_method_sha1},
211     {NX_SECURE_TLS_X509_TYPE_RSA_MD5,        &crypto_method_rsa,       &crypto_method_md5},
212 };
213 
214 const UINT _nx_crypto_x509_cipher_lookup_table_ecc_size = sizeof(_nx_crypto_x509_cipher_lookup_table_ecc) / sizeof(NX_SECURE_X509_CRYPTO);
215 
216 #if (NX_SECURE_TLS_TLS_1_3_ENABLED)
217 NX_SECURE_TLS_CIPHERSUITE_INFO _nx_crypto_ciphersuite_lookup_table_tls_1_3[] =
218 {
219 #ifdef NX_SECURE_ENABLE_AEAD_CIPHER
220     {TLS_AES_128_GCM_SHA256,                  &crypto_method_ecdhe,      &crypto_method_ecdsa,     &crypto_method_aes_128_gcm_16,  96,      16,        &crypto_method_sha256,         32,         &crypto_method_hkdf},
221     /* SHA-384 ciphersuites not yet supported... {TLS_AES_256_GCM_SHA384,                  &crypto_method_ecdhe,      &crypto_method_rsa,     &crypto_method_aes_256_gcm_16,  16,      16,        &crypto_method_sha384,         48,         &crypto_method_hkdf},*/
222     {TLS_AES_128_CCM_SHA256,                  &crypto_method_ecdhe,      &crypto_method_ecdsa,     &crypto_method_aes_ccm_16,       96,      16,        &crypto_method_sha256,         32,         &crypto_method_hkdf},
223     {TLS_AES_128_CCM_8_SHA256,                &crypto_method_ecdhe,      &crypto_method_ecdsa,     &crypto_method_aes_ccm_8,       96,      16,        &crypto_method_sha256,         32,         &crypto_method_hkdf},
224 #endif
225 };
226 
227 const UINT _nx_crypto_ciphersuite_lookup_table_tls_1_3_size = sizeof(_nx_crypto_ciphersuite_lookup_table_tls_1_3) / sizeof(NX_SECURE_TLS_CIPHERSUITE_INFO);
228 #endif
229 #endif
230 
231 /* Ciphersuite table with ECC. */
232 /* Lookup table used to map ciphersuites to cryptographic routines. */
233 /* Ciphersuites are negotiated IN ORDER - top priority first. Ciphersuites lower in the list are considered less secure. */
234 /* For TLS Web servers, define NX_SECURE_ENABLE_AEAD_CIPHER to allow web browsers to connect using AES_128_GCM cipher suites. */
235 NX_SECURE_TLS_CIPHERSUITE_INFO _nx_crypto_ciphersuite_lookup_table_ecc[] =
236 {
237     /* Ciphersuite,                           public cipher,            public_auth,              session cipher & cipher mode,   iv size, key size,  hash method,                    hash size, TLS PRF */
238 #ifndef NX_SECURE_DISABLE_X509
239 #if (NX_SECURE_TLS_TLS_1_3_ENABLED)
240     {TLS_AES_128_GCM_SHA256,                  &crypto_method_ecdhe,     &crypto_method_ecdsa,     &crypto_method_aes_128_gcm_16,  96,      16,        &crypto_method_sha256,         32,         &crypto_method_hkdf},
241     {TLS_AES_128_CCM_SHA256,                  &crypto_method_ecdhe,     &crypto_method_ecdsa,     &crypto_method_aes_ccm_16,      96,      16,        &crypto_method_sha256,         32,         &crypto_method_hkdf},
242     {TLS_AES_128_CCM_8_SHA256,                &crypto_method_ecdhe,     &crypto_method_ecdsa,     &crypto_method_aes_ccm_8,       96,      16,        &crypto_method_sha256,         32,         &crypto_method_hkdf},
243 #endif
244 
245 #ifdef NX_SECURE_ENABLE_AEAD_CIPHER
246     {TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, &crypto_method_ecdhe,     &crypto_method_ecdsa,     &crypto_method_aes_128_gcm_16,  16,      16,        &crypto_method_null,            0,         &crypto_method_tls_prf_sha256},
247     {TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,   &crypto_method_ecdhe,     &crypto_method_rsa,       &crypto_method_aes_128_gcm_16,  16,      16,        &crypto_method_null,            0,         &crypto_method_tls_prf_sha256},
248 #endif /* NX_SECURE_ENABLE_AEAD_CIPHER */
249 
250     {TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, &crypto_method_ecdhe,     &crypto_method_ecdsa,     &crypto_method_aes_cbc_128,     16,      16,        &crypto_method_hmac_sha256,     32,        &crypto_method_tls_prf_sha256},
251     {TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,   &crypto_method_ecdhe,     &crypto_method_rsa,       &crypto_method_aes_cbc_128,     16,      16,        &crypto_method_hmac_sha256,     32,        &crypto_method_tls_prf_sha256},
252 
253 #ifdef NX_SECURE_ENABLE_AEAD_CIPHER
254     {TLS_RSA_WITH_AES_128_GCM_SHA256,         &crypto_method_rsa,       &crypto_method_rsa,       &crypto_method_aes_128_gcm_16,  16,      16,        &crypto_method_null,            0,         &crypto_method_tls_prf_sha256},
255 #endif /* NX_SECURE_ENABLE_AEAD_CIPHER */
256 
257     {TLS_RSA_WITH_AES_256_CBC_SHA256,         &crypto_method_rsa,       &crypto_method_rsa,       &crypto_method_aes_cbc_256,     16,      32,        &crypto_method_hmac_sha256,     32,        &crypto_method_tls_prf_sha256},
258     {TLS_RSA_WITH_AES_128_CBC_SHA256,         &crypto_method_rsa,       &crypto_method_rsa,       &crypto_method_aes_cbc_128,     16,      16,        &crypto_method_hmac_sha256,     32,        &crypto_method_tls_prf_sha256},
259 #endif
260 
261 #ifdef NX_SECURE_ENABLE_PSK_CIPHERSUITES
262     {TLS_PSK_WITH_AES_128_CBC_SHA256,         &crypto_method_null,      &crypto_method_auth_psk,  &crypto_method_aes_cbc_128,     16,      16,        &crypto_method_hmac_sha256,     32,        &crypto_method_tls_prf_sha256},
263 #ifdef NX_SECURE_ENABLE_AEAD_CIPHER
264     {TLS_PSK_WITH_AES_128_CCM_8,              &crypto_method_null,      &crypto_method_auth_psk,  &crypto_method_aes_ccm_8,       16,      16,        &crypto_method_null,            0,         &crypto_method_tls_prf_sha256},
265 #endif
266 #endif /* NX_SECURE_ENABLE_PSK_CIPHERSUITES */
267 
268 
269 };
270 
271 const UINT _nx_crypto_ciphersuite_lookup_table_ecc_size = sizeof(_nx_crypto_ciphersuite_lookup_table_ecc) / sizeof(NX_SECURE_TLS_CIPHERSUITE_INFO);
272 
273 
274 /* Define the object we can pass into TLS. */
275 const NX_SECURE_TLS_CRYPTO nx_crypto_tls_ciphers_ecc =
276 {
277     /* Ciphersuite lookup table and size. */
278     _nx_crypto_ciphersuite_lookup_table_ecc,
279     sizeof(_nx_crypto_ciphersuite_lookup_table_ecc) / sizeof(NX_SECURE_TLS_CIPHERSUITE_INFO),
280 
281 #ifndef NX_SECURE_DISABLE_X509
282     /* X.509 certificate cipher table and size. */
283     _nx_crypto_x509_cipher_lookup_table_ecc,
284     sizeof(_nx_crypto_x509_cipher_lookup_table_ecc) / sizeof(NX_SECURE_X509_CRYPTO),
285 #endif
286 
287     /* TLS version-specific methods. */
288 #if (NX_SECURE_TLS_TLS_1_0_ENABLED || NX_SECURE_TLS_TLS_1_1_ENABLED)
289     &crypto_method_md5,
290     &crypto_method_sha1,
291     &crypto_method_tls_prf_1,
292 #endif
293 
294 #if (NX_SECURE_TLS_TLS_1_2_ENABLED)
295     &crypto_method_sha256,
296     &crypto_method_tls_prf_sha256,
297 #endif
298 
299 #if (NX_SECURE_TLS_TLS_1_3_ENABLED)
300     &crypto_method_hkdf,
301     &crypto_method_hmac,
302     &crypto_method_ecdhe,
303 #endif
304 
305 
306 };
307 
308 const USHORT nx_crypto_ecc_supported_groups[] =
309 {
310     (USHORT)NX_CRYPTO_EC_SECP256R1,
311 #ifdef NX_CRYPTO_ENABLE_CURVE25519_448
312     (USHORT)NX_CRYPTO_EC_X25519,
313     (USHORT)NX_CRYPTO_EC_X448,
314 #endif /* NX_CRYPTO_ENABLE_CURVE25519_448 */
315     (USHORT)NX_CRYPTO_EC_SECP384R1,
316     (USHORT)NX_CRYPTO_EC_SECP521R1,
317 };
318 
319 const NX_CRYPTO_METHOD *nx_crypto_ecc_curves[] =
320 {
321     &crypto_method_ec_secp256,
322 #ifdef NX_CRYPTO_ENABLE_CURVE25519_448
323     &crypto_method_ec_x25519,
324     &crypto_method_ec_x448,
325 #endif /* NX_CRYPTO_ENABLE_CURVE25519_448 */
326     &crypto_method_ec_secp384,
327     &crypto_method_ec_secp521,
328 };
329 
330 const UINT nx_crypto_ecc_supported_groups_size = sizeof(nx_crypto_ecc_supported_groups) / sizeof(USHORT);
331 #endif /* NX_SECURE_ENABLE_ECC_CIPHERSUITE */
332 
333 
334 
335 #if 0  /* This ciphersuite is provided for reference only. It can be used to construct legacy ciphersuites
336           for use with TLS 1.0 or TLS 1.1 (SHA-1 based ciphersuites are not currently supported in TLS 1.2). */
337 const NX_CRYPTO_CIPHERSUITE nx_crypto_tls_rsa_with_aes_128_cbc_sha =
338 /* TLS ciphersuite entry. */
339 {   TLS_RSA_WITH_AES_128_CBC_SHA,       /* Ciphersuite ID. */
340     NX_SECURE_APPLICATION_TLS,          /* Internal application label. */
341     16,                                 /* Symmetric key size. */
342     {   /* Cipher role array. */
343         {NX_CRYPTO_KEY_EXCHANGE_RSA,             NX_CRYPTO_ROLE_KEY_EXCHANGE},
344         {NX_CRYPTO_DIGITAL_SIGNATURE_RSA,        NX_CRYPTO_ROLE_SIGNATURE_CRYPTO},
345         {NX_CRYPTO_ENCRYPTION_AES_CBC,           NX_CRYPTO_ROLE_SYMMETRIC},
346         {NX_CRYPTO_AUTHENTICATION_HMAC_SHA1_160, NX_CRYPTO_ROLE_MAC_HASH},
347         {NX_CRYPTO_HASH_SHA1,                    NX_CRYPTO_ROLE_RAW_HASH},
348         {NX_CRYPTO_HASH_HMAC,                    NX_CRYPTO_ROLE_HMAC},
349         {NX_CRYPTO_PRF_HMAC_SHA2_256,            NX_CRYPTO_ROLE_PRF},
350         {NX_CRYPTO_NONE,                         NX_CRYPTO_ROLE_NONE}
351     },
352     /* TLS/DTLS Versions supported. */
353     (NX_SECURE_TLS_BITFIELD_VERSIONS_PRE_1_3 | NX_SECURE_DTLS_BITFIELD_VERSIONS_PRE_1_3)
354 };
355 #endif
356 
357 const NX_CRYPTO_CIPHERSUITE nx_crypto_tls_rsa_with_aes_128_cbc_sha256 =
358 /* TLS ciphersuite entry. */
359 {   TLS_RSA_WITH_AES_128_CBC_SHA256,    /* Ciphersuite ID. */
360     NX_SECURE_APPLICATION_TLS,          /* Internal application label. */
361     16,                                 /* Symmetric key size. */
362     {   /* Cipher role array. */
363         {NX_CRYPTO_KEY_EXCHANGE_RSA,             NX_CRYPTO_ROLE_KEY_EXCHANGE},
364         {NX_CRYPTO_KEY_EXCHANGE_RSA,             NX_CRYPTO_ROLE_SIGNATURE_CRYPTO},
365         {NX_CRYPTO_ENCRYPTION_AES_CBC,           NX_CRYPTO_ROLE_SYMMETRIC},
366         {NX_CRYPTO_AUTHENTICATION_HMAC_SHA2_256, NX_CRYPTO_ROLE_MAC_HASH},
367         {NX_CRYPTO_HASH_SHA256,                  NX_CRYPTO_ROLE_RAW_HASH},
368         {NX_CRYPTO_HASH_HMAC,                    NX_CRYPTO_ROLE_HMAC},
369         {NX_CRYPTO_PRF_HMAC_SHA2_256,            NX_CRYPTO_ROLE_PRF},
370         {NX_CRYPTO_NONE,                         NX_CRYPTO_ROLE_NONE}
371     },
372     /* TLS/DTLS Versions supported. */
373     (NX_SECURE_TLS_BITFIELD_VERSIONS_PRE_1_3 | NX_SECURE_DTLS_BITFIELD_VERSIONS_PRE_1_3)
374 };
375 
376 const NX_CRYPTO_CIPHERSUITE nx_crypto_tls_ecdhe_rsa_with_aes_128_cbc_sha256 =
377 /* TLS ciphersuite entry. */
378 {   TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,   /* Ciphersuite ID. */
379     NX_SECURE_APPLICATION_TLS,               /* Internal application label. */
380     16,                                      /* Symmetric key size. */
381     {   /* Cipher role array. */
382         {NX_CRYPTO_KEY_EXCHANGE_ECDHE,           NX_CRYPTO_ROLE_KEY_EXCHANGE},
383         {NX_CRYPTO_KEY_EXCHANGE_RSA,             NX_CRYPTO_ROLE_SIGNATURE_CRYPTO},
384         {NX_CRYPTO_ENCRYPTION_AES_CBC,           NX_CRYPTO_ROLE_SYMMETRIC},
385         {NX_CRYPTO_AUTHENTICATION_HMAC_SHA2_256, NX_CRYPTO_ROLE_MAC_HASH},
386         {NX_CRYPTO_HASH_SHA256,                  NX_CRYPTO_ROLE_RAW_HASH},
387         {NX_CRYPTO_HASH_HMAC,                    NX_CRYPTO_ROLE_HMAC},
388         {NX_CRYPTO_PRF_HMAC_SHA2_256,            NX_CRYPTO_ROLE_PRF},
389         {NX_CRYPTO_NONE,                         NX_CRYPTO_ROLE_NONE}
390     },
391     /* TLS/DTLS Versions supported. */
392     (NX_SECURE_TLS_BITFIELD_VERSIONS_PRE_1_3 | NX_SECURE_DTLS_BITFIELD_VERSIONS_PRE_1_3)
393 };
394 
395 const NX_CRYPTO_CIPHERSUITE nx_crypto_tls_ecdhe_rsa_with_aes_128_gcm_sha256 =
396 /* TLS ciphersuite entry. */
397 {   TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,   /* Ciphersuite ID. */
398     NX_SECURE_APPLICATION_TLS,               /* Internal application label. */
399     16,                                      /* Symmetric key size. */
400     {   /* Cipher role array. */
401         {NX_CRYPTO_KEY_EXCHANGE_ECDHE,           NX_CRYPTO_ROLE_KEY_EXCHANGE},
402         {NX_CRYPTO_KEY_EXCHANGE_RSA,             NX_CRYPTO_ROLE_SIGNATURE_CRYPTO},
403         {NX_CRYPTO_ENCRYPTION_AES_GCM_16,        NX_CRYPTO_ROLE_SYMMETRIC},
404         {NX_CRYPTO_NONE,                         NX_CRYPTO_ROLE_MAC_HASH},
405         {NX_CRYPTO_HASH_SHA256,                  NX_CRYPTO_ROLE_RAW_HASH},
406         {NX_CRYPTO_HASH_HMAC,                    NX_CRYPTO_ROLE_HMAC},
407         {NX_CRYPTO_PRF_HMAC_SHA2_256,            NX_CRYPTO_ROLE_PRF},
408         {NX_CRYPTO_NONE,                         NX_CRYPTO_ROLE_NONE}
409     },
410     /* TLS/DTLS Versions supported. */
411     (NX_SECURE_TLS_BITFIELD_VERSIONS_PRE_1_3 | NX_SECURE_DTLS_BITFIELD_VERSIONS_PRE_1_3)
412 };
413 
414 const NX_CRYPTO_CIPHERSUITE nx_crypto_tls_ecdhe_ecdsa_with_aes_128_gcm_sha256 =
415 /* TLS ciphersuite entry. */
416 {   TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, /* Ciphersuite ID. */
417     NX_SECURE_APPLICATION_TLS,               /* Internal application label. */
418     16,                                      /* Symmetric key size. */
419     {   /* Cipher role array. */
420         {NX_CRYPTO_KEY_EXCHANGE_ECDHE,           NX_CRYPTO_ROLE_KEY_EXCHANGE},
421         {NX_CRYPTO_DIGITAL_SIGNATURE_ECDSA,      NX_CRYPTO_ROLE_SIGNATURE_CRYPTO},
422         {NX_CRYPTO_ENCRYPTION_AES_GCM_16,        NX_CRYPTO_ROLE_SYMMETRIC},
423         {NX_CRYPTO_NONE,                         NX_CRYPTO_ROLE_MAC_HASH},
424         {NX_CRYPTO_HASH_SHA256,                  NX_CRYPTO_ROLE_RAW_HASH},
425         {NX_CRYPTO_HASH_HMAC,                    NX_CRYPTO_ROLE_HMAC},
426         {NX_CRYPTO_PRF_HMAC_SHA2_256,            NX_CRYPTO_ROLE_PRF},
427         {NX_CRYPTO_NONE,                         NX_CRYPTO_ROLE_NONE}
428     },
429     /* TLS/DTLS Versions supported. */
430     (NX_SECURE_TLS_BITFIELD_VERSIONS_PRE_1_3 | NX_SECURE_DTLS_BITFIELD_VERSIONS_PRE_1_3)
431 };
432 
433 #if (NX_SECURE_TLS_TLS_1_3_ENABLED)
434 const NX_CRYPTO_CIPHERSUITE nx_crypto_tls_aes_128_gcm_sha256 =
435 /* TLS ciphersuite entry. */
436 {   TLS_AES_128_GCM_SHA256,             /* Ciphersuite ID. */
437     NX_SECURE_APPLICATION_TLS,          /* Internal application label. */
438     16,                                 /* Symmetric key size. */
439     {   /* Cipher role array. */
440         {NX_CRYPTO_KEY_EXCHANGE_ECDHE,           NX_CRYPTO_ROLE_KEY_EXCHANGE},
441         {NX_CRYPTO_DIGITAL_SIGNATURE_ECDSA,      NX_CRYPTO_ROLE_SIGNATURE_CRYPTO},
442         {NX_CRYPTO_ENCRYPTION_AES_GCM_16,        NX_CRYPTO_ROLE_SYMMETRIC},
443         {NX_CRYPTO_HASH_SHA256,                  NX_CRYPTO_ROLE_MAC_HASH},
444         {NX_CRYPTO_HASH_SHA256,                  NX_CRYPTO_ROLE_RAW_HASH},
445         {NX_CRYPTO_HKDF_METHOD,                  NX_CRYPTO_ROLE_PRF},
446         {NX_CRYPTO_NONE,                         NX_CRYPTO_ROLE_NONE}
447     },
448     /* TLS/DTLS Versions supported. */
449     (NX_SECURE_TLS_BITFIELD_VERSION_1_3 | NX_SECURE_DTLS_BITFIELD_VERSION_1_3)
450 };
451 #endif
452 
453 const NX_CRYPTO_CIPHERSUITE nx_crypto_x509_rsa_md5 =
454 /* X.509 ciphersuite entry. */
455 {
456     NX_SECURE_TLS_X509_TYPE_RSA_MD5,
457     NX_SECURE_APPLICATION_X509,
458     0,                                 /* Symmetric key size. */
459     {
460         {NX_CRYPTO_KEY_EXCHANGE_RSA,         NX_CRYPTO_ROLE_SIGNATURE_CRYPTO},
461         {NX_CRYPTO_HASH_MD5,                 NX_CRYPTO_ROLE_SIGNATURE_HASH},
462         {NX_CRYPTO_NONE,                     NX_CRYPTO_ROLE_NONE}
463     },
464     /* Versions supported. */
465     NX_SECURE_X509_BITFIELD_VERSION_3
466 };
467 
468 
469 const NX_CRYPTO_CIPHERSUITE nx_crypto_x509_rsa_sha_1 =
470 /* X.509 ciphersuite entry. */
471 {
472     NX_SECURE_TLS_X509_TYPE_RSA_SHA_1,
473     NX_SECURE_APPLICATION_X509,
474     0,                                 /* Symmetric key size. */
475     {
476         {NX_CRYPTO_KEY_EXCHANGE_RSA,         NX_CRYPTO_ROLE_SIGNATURE_CRYPTO},
477         {NX_CRYPTO_HASH_SHA1,                NX_CRYPTO_ROLE_SIGNATURE_HASH},
478         {NX_CRYPTO_NONE,                     NX_CRYPTO_ROLE_NONE}
479     },
480     /* Versions supported. */
481     NX_SECURE_X509_BITFIELD_VERSION_3
482 };
483 
484 const NX_CRYPTO_CIPHERSUITE nx_crypto_x509_rsa_sha_256 =
485 /* X.509 ciphersuite entry. */
486 {
487     NX_SECURE_TLS_X509_TYPE_RSA_SHA_256,
488     NX_SECURE_APPLICATION_X509,
489     0,                                 /* Symmetric key size. */
490     {
491         {NX_CRYPTO_KEY_EXCHANGE_RSA,         NX_CRYPTO_ROLE_SIGNATURE_CRYPTO},
492         {NX_CRYPTO_HASH_SHA256,              NX_CRYPTO_ROLE_SIGNATURE_HASH},
493         {NX_CRYPTO_NONE,                     NX_CRYPTO_ROLE_NONE}
494     },
495     /* Versions supported. */
496     NX_SECURE_X509_BITFIELD_VERSION_3
497 };
498 
499 const NX_CRYPTO_CIPHERSUITE nx_crypto_x509_rsa_sha_384 =
500 /* X.509 ciphersuite entry. */
501 {
502     NX_SECURE_TLS_X509_TYPE_RSA_SHA_384,
503     NX_SECURE_APPLICATION_X509,
504     0,                                 /* Symmetric key size. */
505     {
506         {NX_CRYPTO_KEY_EXCHANGE_RSA,         NX_CRYPTO_ROLE_SIGNATURE_CRYPTO},
507         {NX_CRYPTO_HASH_SHA384,              NX_CRYPTO_ROLE_SIGNATURE_HASH},
508         {NX_CRYPTO_NONE,                     NX_CRYPTO_ROLE_NONE}
509     },
510     /* Versions supported. */
511     NX_SECURE_X509_BITFIELD_VERSION_3
512 };
513 
514 const NX_CRYPTO_CIPHERSUITE nx_crypto_x509_rsa_sha_512 =
515 /* X.509 ciphersuite entry. */
516 {
517     NX_SECURE_TLS_X509_TYPE_RSA_SHA_512,
518     NX_SECURE_APPLICATION_X509,
519     0,                                 /* Symmetric key size. */
520     {
521         {NX_CRYPTO_KEY_EXCHANGE_RSA,         NX_CRYPTO_ROLE_SIGNATURE_CRYPTO},
522         {NX_CRYPTO_HASH_SHA512,              NX_CRYPTO_ROLE_SIGNATURE_HASH},
523         {NX_CRYPTO_NONE,                     NX_CRYPTO_ROLE_NONE}
524     },
525     /* Versions supported. */
526     NX_SECURE_X509_BITFIELD_VERSION_3
527 };
528 
529 
530 
531 const NX_CRYPTO_CIPHERSUITE nx_crypto_x509_ecdsa_sha_1 =
532 /* X.509 ciphersuite entry. */
533 {
534     NX_SECURE_TLS_X509_TYPE_ECDSA_SHA_1,
535     NX_SECURE_APPLICATION_X509,
536     0,                                 /* Symmetric key size. */
537     {
538         {NX_CRYPTO_DIGITAL_SIGNATURE_ECDSA,  NX_CRYPTO_ROLE_SIGNATURE_CRYPTO},
539         {NX_CRYPTO_HASH_SHA1,                NX_CRYPTO_ROLE_SIGNATURE_HASH},
540         {NX_CRYPTO_NONE,                     NX_CRYPTO_ROLE_NONE}
541     },
542     /* Versions supported. */
543     NX_SECURE_X509_BITFIELD_VERSION_3
544 };
545 
546 const NX_CRYPTO_CIPHERSUITE nx_crypto_x509_ecdsa_sha_224 =
547 /* X.509 ciphersuite entry. */
548 {
549     NX_SECURE_TLS_X509_TYPE_ECDSA_SHA_224,
550     NX_SECURE_APPLICATION_X509,
551     0,                                 /* Symmetric key size. */
552     {
553         {NX_CRYPTO_DIGITAL_SIGNATURE_ECDSA,  NX_CRYPTO_ROLE_SIGNATURE_CRYPTO},
554         {NX_CRYPTO_HASH_SHA224,              NX_CRYPTO_ROLE_SIGNATURE_HASH},
555         {NX_CRYPTO_NONE,                     NX_CRYPTO_ROLE_NONE}
556     },
557     /* Versions supported. */
558     NX_SECURE_X509_BITFIELD_VERSION_3
559 };
560 
561 const NX_CRYPTO_CIPHERSUITE nx_crypto_x509_ecdsa_sha_256 =
562 /* X.509 ciphersuite entry. */
563 {
564     NX_SECURE_TLS_X509_TYPE_ECDSA_SHA_256,
565     NX_SECURE_APPLICATION_X509,
566     0,                                 /* Symmetric key size. */
567     {
568         {NX_CRYPTO_DIGITAL_SIGNATURE_ECDSA,  NX_CRYPTO_ROLE_SIGNATURE_CRYPTO},
569         {NX_CRYPTO_HASH_SHA256,              NX_CRYPTO_ROLE_SIGNATURE_HASH},
570         {NX_CRYPTO_NONE,                     NX_CRYPTO_ROLE_NONE}
571     },
572     /* Versions supported. */
573     NX_SECURE_X509_BITFIELD_VERSION_3
574 };
575 
576 const NX_CRYPTO_CIPHERSUITE nx_crypto_x509_ecdsa_sha_384 =
577 /* X.509 ciphersuite entry. */
578 {
579     NX_SECURE_TLS_X509_TYPE_ECDSA_SHA_384,
580     NX_SECURE_APPLICATION_X509,
581     0,                                 /* Symmetric key size. */
582     {
583         {NX_CRYPTO_DIGITAL_SIGNATURE_ECDSA,  NX_CRYPTO_ROLE_SIGNATURE_CRYPTO},
584         {NX_CRYPTO_HASH_SHA384,              NX_CRYPTO_ROLE_SIGNATURE_HASH},
585         {NX_CRYPTO_NONE,                     NX_CRYPTO_ROLE_NONE}
586     },
587     /* Versions supported. */
588     NX_SECURE_X509_BITFIELD_VERSION_3
589 };
590 
591 const NX_CRYPTO_CIPHERSUITE nx_crypto_x509_ecdsa_sha_512 =
592 /* X.509 ciphersuite entry. */
593 {
594     NX_SECURE_TLS_X509_TYPE_ECDSA_SHA_512,
595     NX_SECURE_APPLICATION_X509,
596     0,                                 /* Symmetric key size. */
597     {
598         {NX_CRYPTO_DIGITAL_SIGNATURE_ECDSA,  NX_CRYPTO_ROLE_SIGNATURE_CRYPTO},
599         {NX_CRYPTO_HASH_SHA512,              NX_CRYPTO_ROLE_SIGNATURE_HASH},
600         {NX_CRYPTO_NONE,                     NX_CRYPTO_ROLE_NONE}
601     },
602     /* Versions supported. */
603     NX_SECURE_X509_BITFIELD_VERSION_3
604 };
605 
606 
607 const NX_CRYPTO_METHOD *supported_crypto[] =
608 {
609     &crypto_method_none,
610     &crypto_method_rsa,
611     &crypto_method_pkcs1,
612     &crypto_method_ecdhe,
613     &crypto_method_ecdsa,
614     &crypto_method_aes_ccm_8,
615     &crypto_method_aes_cbc_128,
616     &crypto_method_aes_cbc_256,
617     &crypto_method_aes_128_gcm_16,
618     &crypto_method_aes_256_gcm_16,
619     &crypto_method_hmac,
620     &crypto_method_hmac_md5,
621     &crypto_method_hmac_sha1,
622     &crypto_method_hmac_sha256,
623     &crypto_method_md5,
624     &crypto_method_sha1,
625     &crypto_method_sha224,
626     &crypto_method_sha256,
627     &crypto_method_sha384,
628     &crypto_method_sha512,
629     &crypto_method_tls_prf_1,
630     &crypto_method_tls_prf_sha256,
631     &crypto_method_hkdf,
632     &crypto_method_ec_secp256,
633 #ifdef NX_CRYPTO_ENABLE_CURVE25519_448
634     &crypto_method_ec_x25519,
635     &crypto_method_ec_x448,
636 #endif /* NX_CRYPTO_ENABLE_CURVE25519_448 */
637     &crypto_method_ec_secp384,
638     &crypto_method_ec_secp521,
639 };
640 
641 const UINT supported_crypto_size = sizeof(supported_crypto) / sizeof(NX_CRYPTO_METHOD*);
642 
643 const NX_CRYPTO_CIPHERSUITE *ciphersuite_map[] =
644 {
645     /* TLS ciphersuites. */
646 #if (NX_SECURE_TLS_TLS_1_3_ENABLED)
647     &nx_crypto_tls_aes_128_gcm_sha256,
648 #endif
649     &nx_crypto_tls_ecdhe_rsa_with_aes_128_gcm_sha256,
650     &nx_crypto_tls_ecdhe_ecdsa_with_aes_128_gcm_sha256,
651     &nx_crypto_tls_rsa_with_aes_128_cbc_sha256,
652 
653     /* X.509 ciphersuites. */
654     &nx_crypto_x509_ecdsa_sha_256,
655     &nx_crypto_x509_ecdsa_sha_384,
656     &nx_crypto_x509_ecdsa_sha_512,
657     &nx_crypto_x509_rsa_sha_256,
658     &nx_crypto_x509_rsa_sha_384,
659     &nx_crypto_x509_rsa_sha_512,
660     &nx_crypto_x509_ecdsa_sha_224,
661     &nx_crypto_x509_ecdsa_sha_1,
662     &nx_crypto_x509_rsa_sha_1,
663     &nx_crypto_x509_rsa_md5,
664 };
665 
666 const UINT ciphersuite_map_size = sizeof(ciphersuite_map) / sizeof(NX_CRYPTO_CIPHERSUITE*);
667 
668 #endif /* NX_CRYPTO_STANDALONE_ENABLE */
669 
670 
671 
672 
673