mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
library: Move mbedtls_ecc helper functions to psa_util
Move the mbedtls_ecc helper functions from psa_core to psa_util. These files are not implemented as part of the PSA API and should not be part of the PSA crypto implementation. Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
This commit is contained in:
@ -408,181 +408,6 @@ static void psa_wipe_tag_output_buffer(uint8_t *output_buffer, psa_status_t stat
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/****************************************************************/
|
||||
/* Key management */
|
||||
/****************************************************************/
|
||||
|
||||
#if defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY)
|
||||
psa_ecc_family_t mbedtls_ecc_group_to_psa(mbedtls_ecp_group_id grpid,
|
||||
size_t *bits)
|
||||
{
|
||||
switch (grpid) {
|
||||
#if defined(MBEDTLS_ECP_HAVE_SECP192R1)
|
||||
case MBEDTLS_ECP_DP_SECP192R1:
|
||||
*bits = 192;
|
||||
return PSA_ECC_FAMILY_SECP_R1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_SECP224R1)
|
||||
case MBEDTLS_ECP_DP_SECP224R1:
|
||||
*bits = 224;
|
||||
return PSA_ECC_FAMILY_SECP_R1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_SECP256R1)
|
||||
case MBEDTLS_ECP_DP_SECP256R1:
|
||||
*bits = 256;
|
||||
return PSA_ECC_FAMILY_SECP_R1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_SECP384R1)
|
||||
case MBEDTLS_ECP_DP_SECP384R1:
|
||||
*bits = 384;
|
||||
return PSA_ECC_FAMILY_SECP_R1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_SECP521R1)
|
||||
case MBEDTLS_ECP_DP_SECP521R1:
|
||||
*bits = 521;
|
||||
return PSA_ECC_FAMILY_SECP_R1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_BP256R1)
|
||||
case MBEDTLS_ECP_DP_BP256R1:
|
||||
*bits = 256;
|
||||
return PSA_ECC_FAMILY_BRAINPOOL_P_R1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_BP384R1)
|
||||
case MBEDTLS_ECP_DP_BP384R1:
|
||||
*bits = 384;
|
||||
return PSA_ECC_FAMILY_BRAINPOOL_P_R1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_BP512R1)
|
||||
case MBEDTLS_ECP_DP_BP512R1:
|
||||
*bits = 512;
|
||||
return PSA_ECC_FAMILY_BRAINPOOL_P_R1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_CURVE25519)
|
||||
case MBEDTLS_ECP_DP_CURVE25519:
|
||||
*bits = 255;
|
||||
return PSA_ECC_FAMILY_MONTGOMERY;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_SECP192K1)
|
||||
case MBEDTLS_ECP_DP_SECP192K1:
|
||||
*bits = 192;
|
||||
return PSA_ECC_FAMILY_SECP_K1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_SECP224K1)
|
||||
case MBEDTLS_ECP_DP_SECP224K1:
|
||||
*bits = 224;
|
||||
return PSA_ECC_FAMILY_SECP_K1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_SECP256K1)
|
||||
case MBEDTLS_ECP_DP_SECP256K1:
|
||||
*bits = 256;
|
||||
return PSA_ECC_FAMILY_SECP_K1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_CURVE448)
|
||||
case MBEDTLS_ECP_DP_CURVE448:
|
||||
*bits = 448;
|
||||
return PSA_ECC_FAMILY_MONTGOMERY;
|
||||
#endif
|
||||
default:
|
||||
*bits = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
mbedtls_ecp_group_id mbedtls_ecc_group_of_psa(psa_ecc_family_t curve,
|
||||
size_t bits,
|
||||
int bits_is_sloppy)
|
||||
{
|
||||
switch (curve) {
|
||||
case PSA_ECC_FAMILY_SECP_R1:
|
||||
switch (bits) {
|
||||
#if defined(PSA_WANT_ECC_SECP_R1_192)
|
||||
case 192:
|
||||
return MBEDTLS_ECP_DP_SECP192R1;
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_SECP_R1_224)
|
||||
case 224:
|
||||
return MBEDTLS_ECP_DP_SECP224R1;
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_SECP_R1_256)
|
||||
case 256:
|
||||
return MBEDTLS_ECP_DP_SECP256R1;
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_SECP_R1_384)
|
||||
case 384:
|
||||
return MBEDTLS_ECP_DP_SECP384R1;
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_SECP_R1_521)
|
||||
case 521:
|
||||
return MBEDTLS_ECP_DP_SECP521R1;
|
||||
case 528:
|
||||
if (bits_is_sloppy) {
|
||||
return MBEDTLS_ECP_DP_SECP521R1;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case PSA_ECC_FAMILY_BRAINPOOL_P_R1:
|
||||
switch (bits) {
|
||||
#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_256)
|
||||
case 256:
|
||||
return MBEDTLS_ECP_DP_BP256R1;
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_384)
|
||||
case 384:
|
||||
return MBEDTLS_ECP_DP_BP384R1;
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_512)
|
||||
case 512:
|
||||
return MBEDTLS_ECP_DP_BP512R1;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case PSA_ECC_FAMILY_MONTGOMERY:
|
||||
switch (bits) {
|
||||
#if defined(PSA_WANT_ECC_MONTGOMERY_255)
|
||||
case 255:
|
||||
return MBEDTLS_ECP_DP_CURVE25519;
|
||||
case 256:
|
||||
if (bits_is_sloppy) {
|
||||
return MBEDTLS_ECP_DP_CURVE25519;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_MONTGOMERY_448)
|
||||
case 448:
|
||||
return MBEDTLS_ECP_DP_CURVE448;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case PSA_ECC_FAMILY_SECP_K1:
|
||||
switch (bits) {
|
||||
#if defined(PSA_WANT_ECC_SECP_K1_192)
|
||||
case 192:
|
||||
return MBEDTLS_ECP_DP_SECP192K1;
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_SECP_K1_224)
|
||||
case 224:
|
||||
return MBEDTLS_ECP_DP_SECP224K1;
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_SECP_K1_256)
|
||||
case 256:
|
||||
return MBEDTLS_ECP_DP_SECP256K1;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
(void) bits_is_sloppy;
|
||||
return MBEDTLS_ECP_DP_NONE;
|
||||
}
|
||||
#endif /* PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY */
|
||||
|
||||
psa_status_t psa_validate_unstructured_key_bit_size(psa_key_type_t type,
|
||||
size_t bits)
|
||||
{
|
||||
|
@ -156,4 +156,178 @@ int psa_pk_status_to_mbedtls(psa_status_t status)
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_PK_C */
|
||||
|
||||
/****************************************************************/
|
||||
/* Key management */
|
||||
/****************************************************************/
|
||||
|
||||
#if defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY)
|
||||
psa_ecc_family_t mbedtls_ecc_group_to_psa(mbedtls_ecp_group_id grpid,
|
||||
size_t *bits)
|
||||
{
|
||||
switch (grpid) {
|
||||
#if defined(MBEDTLS_ECP_HAVE_SECP192R1)
|
||||
case MBEDTLS_ECP_DP_SECP192R1:
|
||||
*bits = 192;
|
||||
return PSA_ECC_FAMILY_SECP_R1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_SECP224R1)
|
||||
case MBEDTLS_ECP_DP_SECP224R1:
|
||||
*bits = 224;
|
||||
return PSA_ECC_FAMILY_SECP_R1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_SECP256R1)
|
||||
case MBEDTLS_ECP_DP_SECP256R1:
|
||||
*bits = 256;
|
||||
return PSA_ECC_FAMILY_SECP_R1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_SECP384R1)
|
||||
case MBEDTLS_ECP_DP_SECP384R1:
|
||||
*bits = 384;
|
||||
return PSA_ECC_FAMILY_SECP_R1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_SECP521R1)
|
||||
case MBEDTLS_ECP_DP_SECP521R1:
|
||||
*bits = 521;
|
||||
return PSA_ECC_FAMILY_SECP_R1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_BP256R1)
|
||||
case MBEDTLS_ECP_DP_BP256R1:
|
||||
*bits = 256;
|
||||
return PSA_ECC_FAMILY_BRAINPOOL_P_R1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_BP384R1)
|
||||
case MBEDTLS_ECP_DP_BP384R1:
|
||||
*bits = 384;
|
||||
return PSA_ECC_FAMILY_BRAINPOOL_P_R1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_BP512R1)
|
||||
case MBEDTLS_ECP_DP_BP512R1:
|
||||
*bits = 512;
|
||||
return PSA_ECC_FAMILY_BRAINPOOL_P_R1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_CURVE25519)
|
||||
case MBEDTLS_ECP_DP_CURVE25519:
|
||||
*bits = 255;
|
||||
return PSA_ECC_FAMILY_MONTGOMERY;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_SECP192K1)
|
||||
case MBEDTLS_ECP_DP_SECP192K1:
|
||||
*bits = 192;
|
||||
return PSA_ECC_FAMILY_SECP_K1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_SECP224K1)
|
||||
case MBEDTLS_ECP_DP_SECP224K1:
|
||||
*bits = 224;
|
||||
return PSA_ECC_FAMILY_SECP_K1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_SECP256K1)
|
||||
case MBEDTLS_ECP_DP_SECP256K1:
|
||||
*bits = 256;
|
||||
return PSA_ECC_FAMILY_SECP_K1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_HAVE_CURVE448)
|
||||
case MBEDTLS_ECP_DP_CURVE448:
|
||||
*bits = 448;
|
||||
return PSA_ECC_FAMILY_MONTGOMERY;
|
||||
#endif
|
||||
default:
|
||||
*bits = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
mbedtls_ecp_group_id mbedtls_ecc_group_of_psa(psa_ecc_family_t curve,
|
||||
size_t bits,
|
||||
int bits_is_sloppy)
|
||||
{
|
||||
switch (curve) {
|
||||
case PSA_ECC_FAMILY_SECP_R1:
|
||||
switch (bits) {
|
||||
#if defined(PSA_WANT_ECC_SECP_R1_192)
|
||||
case 192:
|
||||
return MBEDTLS_ECP_DP_SECP192R1;
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_SECP_R1_224)
|
||||
case 224:
|
||||
return MBEDTLS_ECP_DP_SECP224R1;
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_SECP_R1_256)
|
||||
case 256:
|
||||
return MBEDTLS_ECP_DP_SECP256R1;
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_SECP_R1_384)
|
||||
case 384:
|
||||
return MBEDTLS_ECP_DP_SECP384R1;
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_SECP_R1_521)
|
||||
case 521:
|
||||
return MBEDTLS_ECP_DP_SECP521R1;
|
||||
case 528:
|
||||
if (bits_is_sloppy) {
|
||||
return MBEDTLS_ECP_DP_SECP521R1;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case PSA_ECC_FAMILY_BRAINPOOL_P_R1:
|
||||
switch (bits) {
|
||||
#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_256)
|
||||
case 256:
|
||||
return MBEDTLS_ECP_DP_BP256R1;
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_384)
|
||||
case 384:
|
||||
return MBEDTLS_ECP_DP_BP384R1;
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_512)
|
||||
case 512:
|
||||
return MBEDTLS_ECP_DP_BP512R1;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case PSA_ECC_FAMILY_MONTGOMERY:
|
||||
switch (bits) {
|
||||
#if defined(PSA_WANT_ECC_MONTGOMERY_255)
|
||||
case 255:
|
||||
return MBEDTLS_ECP_DP_CURVE25519;
|
||||
case 256:
|
||||
if (bits_is_sloppy) {
|
||||
return MBEDTLS_ECP_DP_CURVE25519;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_MONTGOMERY_448)
|
||||
case 448:
|
||||
return MBEDTLS_ECP_DP_CURVE448;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case PSA_ECC_FAMILY_SECP_K1:
|
||||
switch (bits) {
|
||||
#if defined(PSA_WANT_ECC_SECP_K1_192)
|
||||
case 192:
|
||||
return MBEDTLS_ECP_DP_SECP192K1;
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_SECP_K1_224)
|
||||
case 224:
|
||||
return MBEDTLS_ECP_DP_SECP224K1;
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_SECP_K1_256)
|
||||
case 256:
|
||||
return MBEDTLS_ECP_DP_SECP256K1;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
(void) bits_is_sloppy;
|
||||
return MBEDTLS_ECP_DP_NONE;
|
||||
}
|
||||
#endif /* PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY */
|
||||
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_C */
|
||||
|
Reference in New Issue
Block a user