mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-18 14:42:24 +00:00
Factor duplicated code into exercise_key
Also fail the test if the test code lacks a way to exercise the key.
This commit is contained in:
parent
1ae051409f
commit
02b750781f
@ -345,6 +345,36 @@ static int exercise_asymmetric_encryption_key( psa_key_slot_t key,
|
|||||||
exit:
|
exit:
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int exercise_key( psa_key_slot_t slot,
|
||||||
|
psa_key_usage_t usage,
|
||||||
|
psa_algorithm_t alg )
|
||||||
|
{
|
||||||
|
int ok;
|
||||||
|
if( alg == 0 )
|
||||||
|
ok = 1; /* If no algorihm, do nothing (used for raw data "keys"). */
|
||||||
|
else if( PSA_ALG_IS_MAC( alg ) )
|
||||||
|
ok = exercise_mac_key( slot, usage, alg );
|
||||||
|
else if( PSA_ALG_IS_CIPHER( alg ) )
|
||||||
|
ok = exercise_cipher_key( slot, usage, alg );
|
||||||
|
else if( PSA_ALG_IS_AEAD( alg ) )
|
||||||
|
ok = exercise_aead_key( slot, usage, alg );
|
||||||
|
else if( PSA_ALG_IS_SIGN( alg ) )
|
||||||
|
ok = exercise_signature_key( slot, usage, alg );
|
||||||
|
else if( PSA_ALG_IS_ASYMMETRIC_ENCRYPTION( alg ) )
|
||||||
|
ok = exercise_asymmetric_encryption_key( slot, usage, alg );
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char message[40];
|
||||||
|
mbedtls_snprintf( message, sizeof( message ),
|
||||||
|
"No code to exercise alg=0x%08lx",
|
||||||
|
(unsigned long) alg );
|
||||||
|
test_fail( message, __LINE__, __FILE__ );
|
||||||
|
ok = 0;
|
||||||
|
}
|
||||||
|
return( ok );
|
||||||
|
}
|
||||||
|
|
||||||
/* END_HEADER */
|
/* END_HEADER */
|
||||||
|
|
||||||
/* BEGIN_DEPENDENCIES
|
/* BEGIN_DEPENDENCIES
|
||||||
@ -640,16 +670,8 @@ void import_and_exercise_key( data_t *data,
|
|||||||
TEST_ASSERT( got_bits == bits );
|
TEST_ASSERT( got_bits == bits );
|
||||||
|
|
||||||
/* Do something with the key according to its type and permitted usage. */
|
/* Do something with the key according to its type and permitted usage. */
|
||||||
if( PSA_ALG_IS_MAC( alg ) )
|
if( ! exercise_key( slot, usage, alg ) )
|
||||||
exercise_mac_key( slot, usage, alg );
|
goto exit;
|
||||||
else if( PSA_ALG_IS_CIPHER( alg ) )
|
|
||||||
exercise_cipher_key( slot, usage, alg );
|
|
||||||
else if( PSA_ALG_IS_AEAD( alg ) )
|
|
||||||
exercise_aead_key( slot, usage, alg );
|
|
||||||
else if( PSA_ALG_IS_SIGN( alg ) )
|
|
||||||
exercise_signature_key( slot, usage, alg );
|
|
||||||
else if( PSA_ALG_IS_ASYMMETRIC_ENCRYPTION( alg ) )
|
|
||||||
exercise_asymmetric_encryption_key( slot, usage, alg );
|
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
psa_destroy_key( slot );
|
psa_destroy_key( slot );
|
||||||
@ -2260,16 +2282,8 @@ void generate_key( int type_arg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Do something with the key according to its type and permitted usage. */
|
/* Do something with the key according to its type and permitted usage. */
|
||||||
if( PSA_ALG_IS_MAC( alg ) )
|
if( ! exercise_key( slot, usage, alg ) )
|
||||||
exercise_mac_key( slot, usage, alg );
|
goto exit;
|
||||||
else if( PSA_ALG_IS_CIPHER( alg ) )
|
|
||||||
exercise_cipher_key( slot, usage, alg );
|
|
||||||
else if( PSA_ALG_IS_AEAD( alg ) )
|
|
||||||
exercise_aead_key( slot, usage, alg );
|
|
||||||
else if( PSA_ALG_IS_SIGN( alg ) )
|
|
||||||
exercise_signature_key( slot, usage, alg );
|
|
||||||
else if( PSA_ALG_IS_ASYMMETRIC_ENCRYPTION( alg ) )
|
|
||||||
exercise_asymmetric_encryption_key( slot, usage, alg );
|
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
psa_destroy_key( slot );
|
psa_destroy_key( slot );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user