mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-01 10:06:53 +03:00
Allow importing Montgomery public keys in PSA Crypto
PSA Crypto was checking the byte length of a to-be-imported public ECP key against the expected length for Weierstrass keys, forgetting that Curve25519/Curve448 exists. Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
This commit is contained in:
@ -252,6 +252,10 @@ PSA import/export EC brainpoolP256r1 public key: good
|
||||
depends_on:MBEDTLS_PK_PARSE_C:MBEDTLS_PK_WRITE_C:MBEDTLS_ECP_C:MBEDTLS_ECP_DP_BP256R1_ENABLED
|
||||
import_export:"04768c8cae4abca6306db0ed81b0c4a6215c378066ec6d616c146e13f1c7df809b96ab6911c27d8a02339f0926840e55236d3d1efbe2669d090e4c4c660fada91d":PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_FAMILY_BRAINPOOL_P_R1):PSA_KEY_USAGE_EXPORT:PSA_ALG_ECDSA_ANY:256:0:PSA_SUCCESS:1
|
||||
|
||||
PSA import/export curve25519 public key: good
|
||||
depends_on:MBEDTLS_PK_PARSE_C:MBEDTLS_PK_WRITE_C:MBEDTLS_ECP_C:MBEDTLS_ECP_DP_CURVE25519_ENABLED
|
||||
import_export:"8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a":PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_FAMILY_MONTGOMERY):PSA_KEY_USAGE_EXPORT:PSA_ALG_ECDH:255:0:PSA_SUCCESS:1
|
||||
|
||||
PSA import/export AES key: policy forbids export
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
import_export:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":PSA_KEY_TYPE_AES:PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT:PSA_ALG_CTR:128:0:PSA_ERROR_NOT_PERMITTED:1
|
||||
|
@ -961,14 +961,23 @@ static int exported_key_sanity_check( psa_key_type_t type, size_t bits,
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
if( PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY( type ) )
|
||||
{
|
||||
/* The representation of an ECC public key is:
|
||||
* - The byte 0x04;
|
||||
* - `x_P` as a `ceiling(m/8)`-byte string, big-endian;
|
||||
* - `y_P` as a `ceiling(m/8)`-byte string, big-endian;
|
||||
* - where m is the bit size associated with the curve.
|
||||
*/
|
||||
TEST_EQUAL( p + 1 + 2 * PSA_BITS_TO_BYTES( bits ), end );
|
||||
TEST_EQUAL( p[0], 4 );
|
||||
if( PSA_KEY_TYPE_ECC_GET_FAMILY( type ) == PSA_ECC_FAMILY_MONTGOMERY )
|
||||
{
|
||||
/* The representation of an ECC Montgomery public key is
|
||||
* the raw compressed point */
|
||||
TEST_EQUAL( p + PSA_BITS_TO_BYTES( bits ), end );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The representation of an ECC Weierstrass public key is:
|
||||
* - The byte 0x04;
|
||||
* - `x_P` as a `ceiling(m/8)`-byte string, big-endian;
|
||||
* - `y_P` as a `ceiling(m/8)`-byte string, big-endian;
|
||||
* - where m is the bit size associated with the curve.
|
||||
*/
|
||||
TEST_EQUAL( p + 1 + 2 * PSA_BITS_TO_BYTES( bits ), end );
|
||||
TEST_EQUAL( p[0], 4 );
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
|
Reference in New Issue
Block a user