Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion crypto_libraries/inc/nx_crypto_ec.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* SPDX-License-Identifier: MIT
**************************************************************************/

/* Portions of this file were generated with AI assistance. */


/**************************************************************************/
/**************************************************************************/
Expand Down Expand Up @@ -460,12 +462,21 @@ extern NX_CRYPTO_CONST NX_CRYPTO_EC _nx_crypto_ec_secp224r1;
extern NX_CRYPTO_CONST NX_CRYPTO_EC _nx_crypto_ec_secp256r1;
extern NX_CRYPTO_CONST NX_CRYPTO_EC _nx_crypto_ec_secp384r1;
extern NX_CRYPTO_CONST NX_CRYPTO_EC _nx_crypto_ec_secp521r1;
extern NX_CRYPTO_CONST NX_CRYPTO_EC _nx_crypto_ec_brainpoolp256r1;
extern NX_CRYPTO_CONST NX_CRYPTO_EC _nx_crypto_ec_brainpoolp384r1;
extern NX_CRYPTO_CONST NX_CRYPTO_EC _nx_crypto_ec_brainpoolp512r1;
extern NX_CRYPTO_METHOD crypto_method_ec_brainpoolp256;
extern NX_CRYPTO_METHOD crypto_method_ec_brainpoolp384;
extern NX_CRYPTO_METHOD crypto_method_ec_brainpoolp512;

#define NX_CRYPTO_EC_GET_SECP192R1(curve) curve = (NX_CRYPTO_EC *)&_nx_crypto_ec_secp192r1
#define NX_CRYPTO_EC_GET_SECP224R1(curve) curve = (NX_CRYPTO_EC *)&_nx_crypto_ec_secp224r1
#define NX_CRYPTO_EC_GET_SECP256R1(curve) curve = (NX_CRYPTO_EC *)&_nx_crypto_ec_secp256r1
#define NX_CRYPTO_EC_GET_SECP384R1(curve) curve = (NX_CRYPTO_EC *)&_nx_crypto_ec_secp384r1
#define NX_CRYPTO_EC_GET_SECP521R1(curve) curve = (NX_CRYPTO_EC *)&_nx_crypto_ec_secp521r1
#define NX_CRYPTO_EC_GET_BRAINPOOLP256R1(curve) curve = (NX_CRYPTO_EC *)&_nx_crypto_ec_brainpoolp256r1
#define NX_CRYPTO_EC_GET_BRAINPOOLP384R1(curve) curve = (NX_CRYPTO_EC *)&_nx_crypto_ec_brainpoolp384r1
#define NX_CRYPTO_EC_GET_BRAINPOOLP512R1(curve) curve = (NX_CRYPTO_EC *)&_nx_crypto_ec_brainpoolp512r1

UINT _nx_crypto_ec_point_is_infinite(NX_CRYPTO_EC_POINT *point);
VOID _nx_crypto_ec_point_set_infinite(NX_CRYPTO_EC_POINT *point);
Expand Down Expand Up @@ -614,6 +625,16 @@ UINT _nx_crypto_method_ec_secp521r1_operation(UINT op,
VOID *crypto_metadata, ULONG crypto_metadata_size,
VOID *packet_ptr,
VOID (*nx_crypto_hw_process_callback)(VOID *, UINT));
UINT _nx_crypto_method_ec_brainpool_operation(UINT op,
VOID *handle,
struct NX_CRYPTO_METHOD_STRUCT *method,
UCHAR *key, NX_CRYPTO_KEY_SIZE key_size_in_bits,
UCHAR *input, ULONG input_length_in_byte,
UCHAR *iv_ptr,
UCHAR *output, ULONG output_length_in_byte,
VOID *crypto_metadata, ULONG crypto_metadata_size,
VOID *packet_ptr,
VOID (*nx_crypto_hw_process_callback)(VOID *, UINT));

#ifdef NX_CRYPTO_ENABLE_CURVE25519_448
extern NX_CRYPTO_CONST NX_CRYPTO_EC _nx_crypto_ec_x25519;
Expand Down Expand Up @@ -659,4 +680,3 @@ UINT _nx_crypto_ec_extract_fixed_size_le(NX_CRYPTO_HUGE_NUMBER *number,
#endif

#endif /* NX_CRYPTO_EC_H */

385 changes: 375 additions & 10 deletions crypto_libraries/src/nx_crypto_ec.c

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion crypto_libraries/src/nx_crypto_generic_ciphersuites.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* SPDX-License-Identifier: MIT
**************************************************************************/

/* Portions of this file were generated with AI assistance. */


/**************************************************************************/
/**************************************************************************/
Expand Down Expand Up @@ -80,6 +82,9 @@ extern NX_CRYPTO_METHOD crypto_method_auth_psk;
extern NX_CRYPTO_METHOD crypto_method_ec_secp256;
extern NX_CRYPTO_METHOD crypto_method_ec_secp384;
extern NX_CRYPTO_METHOD crypto_method_ec_secp521;
extern NX_CRYPTO_METHOD crypto_method_ec_brainpoolp256;
extern NX_CRYPTO_METHOD crypto_method_ec_brainpoolp384;
extern NX_CRYPTO_METHOD crypto_method_ec_brainpoolp512;
extern NX_CRYPTO_METHOD crypto_method_ec_x25519;
extern NX_CRYPTO_METHOD crypto_method_ec_x448;
extern NX_CRYPTO_METHOD crypto_method_md5;
Expand Down Expand Up @@ -294,6 +299,9 @@ const USHORT nx_crypto_ecc_supported_groups[] =
#endif /* NX_CRYPTO_ENABLE_CURVE25519_448 */
(USHORT)NX_CRYPTO_EC_SECP384R1,
(USHORT)NX_CRYPTO_EC_SECP521R1,
(USHORT)NX_CRYPTO_EC_BRAINPOOLP256r1,
(USHORT)NX_CRYPTO_EC_BRAINPOOLP384r1,
(USHORT)NX_CRYPTO_EC_BRAINPOOLP512r1,
};

const NX_CRYPTO_METHOD *nx_crypto_ecc_curves[] =
Expand All @@ -305,6 +313,9 @@ const NX_CRYPTO_METHOD *nx_crypto_ecc_curves[] =
#endif /* NX_CRYPTO_ENABLE_CURVE25519_448 */
&crypto_method_ec_secp384,
&crypto_method_ec_secp521,
&crypto_method_ec_brainpoolp256,
&crypto_method_ec_brainpoolp384,
&crypto_method_ec_brainpoolp512,
};

const UINT nx_crypto_ecc_supported_groups_size = sizeof(nx_crypto_ecc_supported_groups) / sizeof(USHORT);
Expand Down Expand Up @@ -616,6 +627,9 @@ const NX_CRYPTO_METHOD *supported_crypto[] =
#endif /* NX_CRYPTO_ENABLE_CURVE25519_448 */
&crypto_method_ec_secp384,
&crypto_method_ec_secp521,
&crypto_method_ec_brainpoolp256,
&crypto_method_ec_brainpoolp384,
&crypto_method_ec_brainpoolp512,
};

const UINT supported_crypto_size = sizeof(supported_crypto) / sizeof(NX_CRYPTO_METHOD*);
Expand Down Expand Up @@ -649,4 +663,3 @@ const UINT ciphersuite_map_size = sizeof(ciphersuite_map) / sizeof(NX_CRYPTO_CIP




23 changes: 23 additions & 0 deletions crypto_libraries/src/nx_crypto_methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* SPDX-License-Identifier: MIT
**************************************************************************/

/* Portions of this file were generated with AI assistance. */


/**************************************************************************/
/**************************************************************************/
Expand Down Expand Up @@ -505,6 +507,27 @@ NX_CRYPTO_METHOD crypto_method_ec_secp521 =
_nx_crypto_method_ec_secp521r1_operation, /* Operation */
};

/* Declare the Brainpool P256r1 curve method. */
NX_CRYPTO_METHOD crypto_method_ec_brainpoolp256 =
{
NX_CRYPTO_EC_BRAINPOOLP256r1, 256, 0, 0, 0, 0,
NX_CRYPTO_NULL, NX_CRYPTO_NULL, _nx_crypto_method_ec_brainpool_operation
};

/* Declare the Brainpool P384r1 curve method. */
NX_CRYPTO_METHOD crypto_method_ec_brainpoolp384 =
{
NX_CRYPTO_EC_BRAINPOOLP384r1, 384, 0, 0, 0, 0,
NX_CRYPTO_NULL, NX_CRYPTO_NULL, _nx_crypto_method_ec_brainpool_operation
};

/* Declare the Brainpool P512r1 curve method. */
NX_CRYPTO_METHOD crypto_method_ec_brainpoolp512 =
{
NX_CRYPTO_EC_BRAINPOOLP512r1, 512, 0, 0, 0, 0,
NX_CRYPTO_NULL, NX_CRYPTO_NULL, _nx_crypto_method_ec_brainpool_operation
};

#ifdef NX_CRYPTO_ENABLE_CURVE25519_448

/* Declare a placeholder for EC x25519. */
Expand Down
5 changes: 5 additions & 0 deletions nx_secure/inc/nx_secure_tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,9 @@ typedef struct NX_SECURE_VERSIONS_LIST_STRUCT
#define NX_SECURE_TLS_SIGNATURE_ECDSA_SHA256 (((UINT)NX_SECURE_TLS_HASH_ALGORITHM_SHA256 << 8) + (UINT)NX_SECURE_TLS_SIGNATURE_ALGORITHM_ECDSA)
#define NX_SECURE_TLS_SIGNATURE_ECDSA_SHA384 (((UINT)NX_SECURE_TLS_HASH_ALGORITHM_SHA384 << 8) + (UINT)NX_SECURE_TLS_SIGNATURE_ALGORITHM_ECDSA)
#define NX_SECURE_TLS_SIGNATURE_ECDSA_SHA512 (((UINT)NX_SECURE_TLS_HASH_ALGORITHM_SHA512 << 8) + (UINT)NX_SECURE_TLS_SIGNATURE_ALGORITHM_ECDSA)
#define NX_SECURE_TLS_SIGNATURE_ECDSA_BRAINPOOLP256R1_SHA256 0x081Au
#define NX_SECURE_TLS_SIGNATURE_ECDSA_BRAINPOOLP384R1_SHA384 0x081Bu
#define NX_SECURE_TLS_SIGNATURE_ECDSA_BRAINPOOLP512R1_SHA512 0x081Cu


/* Session key generation and assignment constants. */
Expand Down Expand Up @@ -1641,6 +1644,8 @@ UINT _nx_secure_tls_ecc_generate_keys(const NX_SECURE_TLS_CIPHERSUITE_INFO *ciph
VOID *public_auth_metadata, ULONG public_auth_metadata_size);
UINT _nx_secure_tls_find_curve_method(NX_SECURE_TLS_ECC *tls_ecc, USHORT named_curve,
const NX_CRYPTO_METHOD **curve_method, UINT *curve_priority);
USHORT _nx_secure_tls_brainpool_group_to_wire(USHORT named_curve);
USHORT _nx_secure_tls_brainpool_group_from_wire(USHORT named_group);
UINT _nx_secure_tls_proc_clienthello_sec_sa_extension(NX_SECURE_TLS_SESSION *tls_session,
NX_SECURE_TLS_HELLO_EXTENSION *exts,
UINT num_extensions,
Expand Down
6 changes: 5 additions & 1 deletion nx_secure/inc/nx_secure_x509.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* SPDX-License-Identifier: MIT
**************************************************************************/

/* Portions of this file were generated with AI assistance. */


/**************************************************************************/
/**************************************************************************/
Expand Down Expand Up @@ -367,6 +369,9 @@ extern "C" {
#define NX_SECURE_TLS_X509_EC_SECP256R1 0x00060017
#define NX_SECURE_TLS_X509_EC_SECP384R1 0x00060018
#define NX_SECURE_TLS_X509_EC_SECP521R1 0x00060019
#define NX_SECURE_TLS_X509_EC_BRAINPOOLP256R1 0x0006001A
#define NX_SECURE_TLS_X509_EC_BRAINPOOLP384R1 0x0006001B
#define NX_SECURE_TLS_X509_EC_BRAINPOOLP512R1 0x0006001C

/* Bitfield mappings for Distinguished name comparison. When using nx_secure_x509_distinguished_name_compare,
these values are used for the "compare_fields" parameter - bitwise OR these values together to compare
Expand Down Expand Up @@ -1045,4 +1050,3 @@ UINT nx_secure_x509_key_usage_extension_parse(NX_SECURE_X509_CERT *certificate,
#endif

#endif /* SRC_NX_SECURE_X509_H_ */

23 changes: 23 additions & 0 deletions nx_secure/src/nx_secure_tls_find_curve_method.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* SPDX-License-Identifier: MIT
**************************************************************************/

/* Portions of this file were generated with AI assistance. */


/**************************************************************************/
/**************************************************************************/
Expand All @@ -26,6 +28,27 @@

#ifdef NX_SECURE_ENABLE_ECC_CIPHERSUITE

/* Map RFC 7027 Brainpool curve IDs to their RFC 8734 TLS 1.3 group IDs. */
USHORT _nx_secure_tls_brainpool_group_to_wire(USHORT named_curve)
{
if ((named_curve >= (USHORT)NX_CRYPTO_EC_BRAINPOOLP256r1) &&
(named_curve <= (USHORT)NX_CRYPTO_EC_BRAINPOOLP512r1))
{
return((USHORT)(named_curve + 5u));
}
return(named_curve);
}

/* Map RFC 8734 TLS 1.3 group IDs to the corresponding crypto curve IDs. */
USHORT _nx_secure_tls_brainpool_group_from_wire(USHORT named_group)
{
if ((named_group >= 0x001Fu) && (named_group <= 0x0021u))
{
return((USHORT)(named_group - 5u));
}
return(named_group);
}

/**************************************************************************/
/* */
/* FUNCTION RELEASE */
Expand Down
10 changes: 9 additions & 1 deletion nx_secure/src/nx_secure_tls_process_certificate_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ UINT extension_type;
case NX_CRYPTO_EC_SECP521R1:
expected_sign_alg = NX_SECURE_TLS_SIGNATURE_ECDSA_SHA512;
break;
case NX_CRYPTO_EC_BRAINPOOLP256r1:
expected_sign_alg = NX_SECURE_TLS_SIGNATURE_ECDSA_BRAINPOOLP256R1_SHA256;
break;
case NX_CRYPTO_EC_BRAINPOOLP384r1:
expected_sign_alg = NX_SECURE_TLS_SIGNATURE_ECDSA_BRAINPOOLP384R1_SHA384;
break;
case NX_CRYPTO_EC_BRAINPOOLP512r1:
expected_sign_alg = NX_SECURE_TLS_SIGNATURE_ECDSA_BRAINPOOLP512R1_SHA512;
break;
default:
return(NX_SECURE_TLS_UNSUPPORTED_CERT_SIGN_ALG);
}
Expand Down Expand Up @@ -337,4 +346,3 @@ UINT extension_type;
return(NX_NOT_SUPPORTED);
#endif /* NX_SECURE_DISABLE_X509 */
}

33 changes: 32 additions & 1 deletion nx_secure/src/nx_secure_tls_process_certificate_verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ UCHAR *pss_scratch;
#ifdef NX_SECURE_ENABLE_ECC_CIPHERSUITE
const NX_CRYPTO_METHOD *curve_method_cert;
NX_SECURE_EC_PUBLIC_KEY *ec_pubkey;
#if (NX_SECURE_TLS_TLS_1_3_ENABLED)
UINT brainpool_expected_curve = 0u;
#endif
UCHAR *ecdsa_hash;
#endif /* NX_SECURE_ENABLE_ECC_CIPHERSUITE */

Expand Down Expand Up @@ -185,6 +188,24 @@ UCHAR *ecdsa_hash;
case NX_SECURE_TLS_SIGNATURE_ECDSA_SHA512:
signature_algorithm = NX_SECURE_TLS_X509_TYPE_ECDSA_SHA_512;
break;
case NX_SECURE_TLS_SIGNATURE_ECDSA_BRAINPOOLP256R1_SHA256:
signature_algorithm = NX_SECURE_TLS_X509_TYPE_ECDSA_SHA_256;
#ifdef NX_SECURE_ENABLE_ECC_CIPHERSUITE
brainpool_expected_curve = NX_CRYPTO_EC_BRAINPOOLP256r1;
#endif
break;
case NX_SECURE_TLS_SIGNATURE_ECDSA_BRAINPOOLP384R1_SHA384:
signature_algorithm = NX_SECURE_TLS_X509_TYPE_ECDSA_SHA_384;
#ifdef NX_SECURE_ENABLE_ECC_CIPHERSUITE
brainpool_expected_curve = NX_CRYPTO_EC_BRAINPOOLP384r1;
#endif
break;
case NX_SECURE_TLS_SIGNATURE_ECDSA_BRAINPOOLP512R1_SHA512:
signature_algorithm = NX_SECURE_TLS_X509_TYPE_ECDSA_SHA_512;
#ifdef NX_SECURE_ENABLE_ECC_CIPHERSUITE
brainpool_expected_curve = NX_CRYPTO_EC_BRAINPOOLP512r1;
#endif
break;
case 0x0804u: /* rsa_pss_rsae_sha256 */
signature_algorithm = NX_SECURE_TLS_X509_TYPE_RSA_SHA_256;
break;
Expand Down Expand Up @@ -827,6 +848,17 @@ UCHAR *ecdsa_hash;

ec_pubkey = &client_certificate -> nx_secure_x509_public_key.ec_public_key;

#if (NX_SECURE_TLS_TLS_1_3_ENABLED)
if (tls_session -> nx_secure_tls_1_3 &&
((brainpool_expected_curve != 0u) ||
((ec_pubkey -> nx_secure_ec_named_curve >= NX_CRYPTO_EC_BRAINPOOLP256r1) &&
(ec_pubkey -> nx_secure_ec_named_curve <= NX_CRYPTO_EC_BRAINPOOLP512r1))) &&
(brainpool_expected_curve != ec_pubkey -> nx_secure_ec_named_curve))
{
return(NX_SECURE_TLS_UNSUPPORTED_CERT_SIGN_ALG);
}
#endif

/* Find out which named curve the remote certificate is using. */
status = _nx_secure_tls_find_curve_method(&tls_session -> nx_secure_tls_ecc, (USHORT)(ec_pubkey -> nx_secure_ec_named_curve), &curve_method_cert, NX_NULL);

Expand Down Expand Up @@ -953,4 +985,3 @@ UCHAR *ecdsa_hash;
return(NX_NOT_SUPPORTED);
#endif
}

30 changes: 27 additions & 3 deletions nx_secure/src/nx_secure_tls_process_clienthello_extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* SPDX-License-Identifier: MIT
**************************************************************************/

/* Portions of this file were generated with AI assistance. */


/**************************************************************************/
/**************************************************************************/
Expand Down Expand Up @@ -533,6 +535,12 @@ UCHAR expected_signature = 0;
for (j = 0; j < groups_len; j += 2)
{
group = (USHORT)((groups[j] << 8) + groups[j + 1]);
#if (NX_SECURE_TLS_TLS_1_3_ENABLED)
if (tls_session -> nx_secure_tls_1_3)
{
group = _nx_secure_tls_brainpool_group_from_wire(group);
}
#endif

status = _nx_secure_tls_find_curve_method(&tls_session -> nx_secure_tls_ecc, group, &curve_method, &new_curve_priority);

Expand Down Expand Up @@ -780,6 +788,7 @@ NX_SECURE_TLS_ECC *ecc_info;

/* Get the key group. */
key_group = (USHORT)((packet_buffer[offset] << 8) + packet_buffer[offset + 1]);
key_group = _nx_secure_tls_brainpool_group_from_wire(key_group);
offset = (USHORT)(offset + 2);

/* Get the key length. */
Expand Down Expand Up @@ -1116,6 +1125,15 @@ NX_SECURE_X509_CERT *local_certificate = NX_NULL;
case NX_CRYPTO_EC_SECP521R1:
expected_sign_alg = NX_SECURE_TLS_SIGNATURE_ECDSA_SHA512;
break;
case NX_CRYPTO_EC_BRAINPOOLP256r1:
expected_sign_alg = NX_SECURE_TLS_SIGNATURE_ECDSA_BRAINPOOLP256R1_SHA256;
break;
case NX_CRYPTO_EC_BRAINPOOLP384r1:
expected_sign_alg = NX_SECURE_TLS_SIGNATURE_ECDSA_BRAINPOOLP384R1_SHA384;
break;
case NX_CRYPTO_EC_BRAINPOOLP512r1:
expected_sign_alg = NX_SECURE_TLS_SIGNATURE_ECDSA_BRAINPOOLP512R1_SHA512;
break;
default:
return;
}
Expand Down Expand Up @@ -1216,6 +1234,15 @@ VOID _nx_secure_tls_get_signature_algorithm_id(UINT signature_algorithm, USHORT
case NX_SECURE_TLS_SIGNATURE_ECDSA_SHA512:
*signature_algorithm_id = NX_SECURE_TLS_X509_TYPE_ECDSA_SHA_512;
break;
case NX_SECURE_TLS_SIGNATURE_ECDSA_BRAINPOOLP256R1_SHA256:
*signature_algorithm_id = NX_SECURE_TLS_X509_TYPE_ECDSA_SHA_256;
break;
case NX_SECURE_TLS_SIGNATURE_ECDSA_BRAINPOOLP384R1_SHA384:
*signature_algorithm_id = NX_SECURE_TLS_X509_TYPE_ECDSA_SHA_384;
break;
case NX_SECURE_TLS_SIGNATURE_ECDSA_BRAINPOOLP512R1_SHA512:
*signature_algorithm_id = NX_SECURE_TLS_X509_TYPE_ECDSA_SHA_512;
break;
/* RSASSA-PSS schemes (RFC 8446 §4.2.3). Mapped to the same internal IDs
as PKCS#1 v1.5 so the certificate cipher table lookup finds the (RSA,
SHA-x) pair. PSS-vs-PKCS1 dispatch is done at signature-verify time. */
Expand Down Expand Up @@ -1571,6 +1598,3 @@ NX_SECURE_TLS_PSK_STORE *psk_store;
return(NX_SUCCESS);
}
#endif



3 changes: 3 additions & 0 deletions nx_secure/src/nx_secure_tls_process_serverhello_extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* SPDX-License-Identifier: MIT
**************************************************************************/

/* Portions of this file were generated with AI assistance. */


/**************************************************************************/
/**************************************************************************/
Expand Down Expand Up @@ -805,6 +807,7 @@ NX_SECURE_TLS_ECC *ecc_info;

/* Check the key group. */
key_group = (USHORT)((ULONG)key_group | NX_CRYPTO_EC_MASK);
key_group = _nx_secure_tls_brainpool_group_from_wire(key_group);


/* Loop through all supported ECC curves in this session. */
Expand Down
Loading
Loading