Improve generate nonce test
Make sure the generated nonce works to encrypt test data if the generated nonce is valid. Signed-off-by: Paul Elliott <paul.elliott@arm.com>
This commit is contained in:
parent
95271f10c3
commit
3bd5dbacc1
2 changed files with 42 additions and 7 deletions
|
@ -2576,23 +2576,23 @@ aead_multipart_decrypt:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f90
|
|||
|
||||
PSA Multipart Nonce Generation, AES - GCM, CAVS 14.0, IV = 12
|
||||
depends_on:PSA_WANT_ALG_GCM:PSA_WANT_KEY_TYPE_AES
|
||||
aead_multipart_generate_nonce:PSA_KEY_TYPE_AES:"aa740abfadcda779220d3b406c5d7ec09a77fe9d94104539":PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_GCM,16):12:PSA_SUCCESS
|
||||
aead_multipart_generate_nonce:PSA_KEY_TYPE_AES:"aa740abfadcda779220d3b406c5d7ec09a77fe9d94104539":PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_GCM,16):12:"290322092d57479e20f6281e331d95a9":"e7fb0631eebf9bdba87045b33650c4ce":PSA_SUCCESS
|
||||
|
||||
PSA Multipart Nonce Generation, AES - GCM, CAVS 14.0, IV = 0
|
||||
depends_on:PSA_WANT_ALG_GCM:PSA_WANT_KEY_TYPE_AES
|
||||
aead_multipart_generate_nonce:PSA_KEY_TYPE_AES:"aa740abfadcda779220d3b406c5d7ec09a77fe9d94104539":PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_GCM,16):0:PSA_ERROR_BUFFER_TOO_SMALL
|
||||
aead_multipart_generate_nonce:PSA_KEY_TYPE_AES:"aa740abfadcda779220d3b406c5d7ec09a77fe9d94104539":PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_GCM,16):0:"":"":PSA_ERROR_BUFFER_TOO_SMALL
|
||||
|
||||
PSA Multipart Nonce Generation: ChaCha20 - Poly1305, IV = 12
|
||||
depends_on:PSA_WANT_ALG_CHACHA20_POLY1305:PSA_WANT_KEY_TYPE_CHACHA20
|
||||
aead_multipart_generate_nonce:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:12:PSA_SUCCESS
|
||||
aead_multipart_generate_nonce:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:12:"50515253c0c1c2c3c4c5c6c7":"4c616469657320616e642047656e746c656d656e206f662074686520636c617373206f66202739393a204966204920636f756c64206f6666657220796f75206f6e6c79206f6e652074697020666f7220746865206675747572652c2073756e73637265656e20776f756c642062652069742e":PSA_SUCCESS
|
||||
|
||||
PSA Multipart Nonce Generation: ChaCha20 - Poly1305, IV = 8
|
||||
depends_on:PSA_WANT_ALG_CHACHA20_POLY1305:PSA_WANT_KEY_TYPE_CHACHA20
|
||||
aead_multipart_generate_nonce:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:8:PSA_ERROR_BUFFER_TOO_SMALL
|
||||
aead_multipart_generate_nonce:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:8:"":"":PSA_ERROR_BUFFER_TOO_SMALL
|
||||
|
||||
PSA Multipart Nonce Generation: ChaCha20 - Poly1305, IV = 0
|
||||
depends_on:PSA_WANT_ALG_CHACHA20_POLY1305:PSA_WANT_KEY_TYPE_CHACHA20
|
||||
aead_multipart_generate_nonce:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:0:PSA_ERROR_BUFFER_TOO_SMALL
|
||||
aead_multipart_generate_nonce:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:0:"":"":PSA_ERROR_BUFFER_TOO_SMALL
|
||||
|
||||
PSA Multipart State Checks, AES - GCM
|
||||
depends_on:PSA_WANT_ALG_GCM:PSA_WANT_KEY_TYPE_AES
|
||||
|
|
|
@ -3699,7 +3699,9 @@ void aead_multipart_decrypt( int key_type_arg, data_t *key_data,
|
|||
void aead_multipart_generate_nonce( int key_type_arg, data_t *key_data,
|
||||
int alg_arg,
|
||||
int nonce_len,
|
||||
int expected_result_arg )
|
||||
data_t *additional_data,
|
||||
data_t *input_data,
|
||||
int expected_status_arg )
|
||||
{
|
||||
|
||||
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
|
||||
|
@ -3710,6 +3712,13 @@ void aead_multipart_generate_nonce( int key_type_arg, data_t *key_data,
|
|||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
|
||||
size_t nonce_generated_len = 0;
|
||||
unsigned char *output_data = NULL;
|
||||
unsigned char *final_data = NULL;
|
||||
size_t output_size = 0;
|
||||
size_t finish_output_size = 0;
|
||||
size_t output_length = 0;
|
||||
size_t tag_length = 0;
|
||||
uint8_t tag_buffer[PSA_AEAD_TAG_MAX_SIZE];
|
||||
|
||||
PSA_ASSERT( psa_crypto_init( ) );
|
||||
|
||||
|
@ -3722,6 +3731,16 @@ void aead_multipart_generate_nonce( int key_type_arg, data_t *key_data,
|
|||
|
||||
PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
|
||||
|
||||
output_size = PSA_AEAD_UPDATE_OUTPUT_SIZE( key_type, alg, input_data->len );
|
||||
|
||||
ASSERT_ALLOC( output_data, output_size );
|
||||
|
||||
finish_output_size = PSA_AEAD_FINISH_OUTPUT_SIZE( key_type, alg );
|
||||
|
||||
TEST_ASSERT( finish_output_size <= PSA_AEAD_FINISH_OUTPUT_MAX_SIZE );
|
||||
|
||||
ASSERT_ALLOC( final_data, finish_output_size );
|
||||
|
||||
operation = psa_aead_operation_init( );
|
||||
|
||||
status = psa_aead_encrypt_setup( &operation, key, alg );
|
||||
|
@ -3743,7 +3762,23 @@ void aead_multipart_generate_nonce( int key_type_arg, data_t *key_data,
|
|||
nonce_len,
|
||||
&nonce_generated_len );
|
||||
|
||||
TEST_ASSERT( status == expected_result_arg );
|
||||
TEST_ASSERT( status == expected_status_arg );
|
||||
|
||||
if( expected_status_arg == PSA_SUCCESS )
|
||||
{
|
||||
|
||||
/* Ensure we can still complete operation. */
|
||||
|
||||
PSA_ASSERT( psa_aead_update_ad( &operation, additional_data->x,
|
||||
additional_data->len ) );
|
||||
|
||||
PSA_ASSERT( psa_aead_update( &operation, input_data->x, input_data->len,
|
||||
output_data, output_size, &output_length ) );
|
||||
|
||||
PSA_ASSERT( psa_aead_finish( &operation, final_data, finish_output_size,
|
||||
&output_length, tag_buffer,
|
||||
PSA_AEAD_TAG_MAX_SIZE, &tag_length ) );
|
||||
}
|
||||
|
||||
exit:
|
||||
psa_destroy_key( key );
|
||||
|
|
Loading…
Reference in a new issue