mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-22 17:45:38 +01:00
exported_key_sanity_check: simplify the logic for public keys
Remove a conditional imbrication level. Get rid of some minor overhead for ECC public keys dating back from when they had ASN.1 wrapping. No behavior change. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
e50b578218
commit
ad557e58bf
@ -659,13 +659,11 @@ int mbedtls_test_psa_exported_key_sanity_check(
|
||||
else
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
|
||||
if( PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) )
|
||||
{
|
||||
uint8_t *p = exported;
|
||||
uint8_t *end = exported + exported_length;
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
if( type == PSA_KEY_TYPE_RSA_PUBLIC_KEY )
|
||||
{
|
||||
uint8_t *p = exported;
|
||||
uint8_t *end = exported + exported_length;
|
||||
size_t len;
|
||||
/* RSAPublicKey ::= SEQUENCE {
|
||||
* modulus INTEGER, -- n
|
||||
@ -684,6 +682,7 @@ int mbedtls_test_psa_exported_key_sanity_check(
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_RSA_C */
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
if( PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY( type ) )
|
||||
{
|
||||
@ -691,7 +690,7 @@ int mbedtls_test_psa_exported_key_sanity_check(
|
||||
{
|
||||
/* The representation of an ECC Montgomery public key is
|
||||
* the raw compressed point */
|
||||
TEST_EQUAL( p + PSA_BITS_TO_BYTES( bits ), end );
|
||||
TEST_EQUAL( PSA_BITS_TO_BYTES( bits ), exported_length );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -701,23 +700,22 @@ int mbedtls_test_psa_exported_key_sanity_check(
|
||||
* - `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 );
|
||||
TEST_EQUAL( 1 + 2 * PSA_BITS_TO_BYTES( bits ), exported_length );
|
||||
TEST_EQUAL( exported[0], 4 );
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
|
||||
if( PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) )
|
||||
{
|
||||
char message[47];
|
||||
mbedtls_snprintf( message, sizeof( message ),
|
||||
"No sanity check for public key type=0x%08lx",
|
||||
(unsigned long) type );
|
||||
mbedtls_test_fail( message, __LINE__, __FILE__ );
|
||||
(void) p;
|
||||
(void) end;
|
||||
return( 0 );
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user