PSA: Reject curves that are not enabled in the PSA configuration
If an elliptic curve was enabled in the Mbed TLS classic API (#define MBEDTLS_ECP_DP_xxx), but not enabled in the PSA configuration (#define PSA_WANT_ECC_xxx), it would still work if you tried to use it through PSA. This is generally benign, but could be a security issue if you want to disable a curve in PSA for some security reason (such as a known bug in its implementation, which may not matter in the classic API if Mbed TLS is running in a secure enclave and is only reachable from untrusted callers through the PSA API). More urgently, this broke test_suite_psa_crypto_not_supported.generated. So if a curve is not enabled in the PSA configuration, ensure that it's treated as unsupported through the PSA software implementation. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
398413024d
commit
a1684f42d3
1 changed files with 26 additions and 0 deletions
|
@ -423,58 +423,84 @@ mbedtls_ecp_group_id mbedtls_ecc_group_of_psa( psa_ecc_family_t curve,
|
||||||
case PSA_ECC_FAMILY_SECP_R1:
|
case PSA_ECC_FAMILY_SECP_R1:
|
||||||
switch( bits )
|
switch( bits )
|
||||||
{
|
{
|
||||||
|
#if defined(PSA_WANT_ECC_SECP_R1_192)
|
||||||
case 192:
|
case 192:
|
||||||
return( MBEDTLS_ECP_DP_SECP192R1 );
|
return( MBEDTLS_ECP_DP_SECP192R1 );
|
||||||
|
#endif
|
||||||
|
#if defined(PSA_WANT_ECC_SECP_R1_224)
|
||||||
case 224:
|
case 224:
|
||||||
return( MBEDTLS_ECP_DP_SECP224R1 );
|
return( MBEDTLS_ECP_DP_SECP224R1 );
|
||||||
|
#endif
|
||||||
|
#if defined(PSA_WANT_ECC_SECP_R1_256)
|
||||||
case 256:
|
case 256:
|
||||||
return( MBEDTLS_ECP_DP_SECP256R1 );
|
return( MBEDTLS_ECP_DP_SECP256R1 );
|
||||||
|
#endif
|
||||||
|
#if defined(PSA_WANT_ECC_SECP_R1_384)
|
||||||
case 384:
|
case 384:
|
||||||
return( MBEDTLS_ECP_DP_SECP384R1 );
|
return( MBEDTLS_ECP_DP_SECP384R1 );
|
||||||
|
#endif
|
||||||
|
#if defined(PSA_WANT_ECC_SECP_R1_521)
|
||||||
case 521:
|
case 521:
|
||||||
return( MBEDTLS_ECP_DP_SECP521R1 );
|
return( MBEDTLS_ECP_DP_SECP521R1 );
|
||||||
case 528:
|
case 528:
|
||||||
if( bits_is_sloppy )
|
if( bits_is_sloppy )
|
||||||
return( MBEDTLS_ECP_DP_SECP521R1 );
|
return( MBEDTLS_ECP_DP_SECP521R1 );
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PSA_ECC_FAMILY_BRAINPOOL_P_R1:
|
case PSA_ECC_FAMILY_BRAINPOOL_P_R1:
|
||||||
switch( bits )
|
switch( bits )
|
||||||
{
|
{
|
||||||
|
#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_256)
|
||||||
case 256:
|
case 256:
|
||||||
return( MBEDTLS_ECP_DP_BP256R1 );
|
return( MBEDTLS_ECP_DP_BP256R1 );
|
||||||
|
#endif
|
||||||
|
#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_384)
|
||||||
case 384:
|
case 384:
|
||||||
return( MBEDTLS_ECP_DP_BP384R1 );
|
return( MBEDTLS_ECP_DP_BP384R1 );
|
||||||
|
#endif
|
||||||
|
#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_512)
|
||||||
case 512:
|
case 512:
|
||||||
return( MBEDTLS_ECP_DP_BP512R1 );
|
return( MBEDTLS_ECP_DP_BP512R1 );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PSA_ECC_FAMILY_MONTGOMERY:
|
case PSA_ECC_FAMILY_MONTGOMERY:
|
||||||
switch( bits )
|
switch( bits )
|
||||||
{
|
{
|
||||||
|
#if defined(PSA_WANT_ECC_MONTGOMERY_255)
|
||||||
case 255:
|
case 255:
|
||||||
return( MBEDTLS_ECP_DP_CURVE25519 );
|
return( MBEDTLS_ECP_DP_CURVE25519 );
|
||||||
case 256:
|
case 256:
|
||||||
if( bits_is_sloppy )
|
if( bits_is_sloppy )
|
||||||
return( MBEDTLS_ECP_DP_CURVE25519 );
|
return( MBEDTLS_ECP_DP_CURVE25519 );
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#if defined(PSA_WANT_ECC_MONTGOMERY_448)
|
||||||
case 448:
|
case 448:
|
||||||
return( MBEDTLS_ECP_DP_CURVE448 );
|
return( MBEDTLS_ECP_DP_CURVE448 );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PSA_ECC_FAMILY_SECP_K1:
|
case PSA_ECC_FAMILY_SECP_K1:
|
||||||
switch( bits )
|
switch( bits )
|
||||||
{
|
{
|
||||||
|
#if defined(PSA_WANT_ECC_SECP_K1_192)
|
||||||
case 192:
|
case 192:
|
||||||
return( MBEDTLS_ECP_DP_SECP192K1 );
|
return( MBEDTLS_ECP_DP_SECP192K1 );
|
||||||
|
#endif
|
||||||
|
#if defined(PSA_WANT_ECC_SECP_K1_224)
|
||||||
case 224:
|
case 224:
|
||||||
return( MBEDTLS_ECP_DP_SECP224K1 );
|
return( MBEDTLS_ECP_DP_SECP224K1 );
|
||||||
|
#endif
|
||||||
|
#if defined(PSA_WANT_ECC_SECP_K1_256)
|
||||||
case 256:
|
case 256:
|
||||||
return( MBEDTLS_ECP_DP_SECP256K1 );
|
return( MBEDTLS_ECP_DP_SECP256K1 );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue