mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-29 22:20:30 +00:00
Add multipart set nonce test
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
This commit is contained in:
parent
ecce901907
commit
863864a2f7
@ -2537,6 +2537,34 @@ PSA Multipart Nonce Generation: ChaCha20 - Poly1305, IV = 16
|
||||
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:16:12:"":"":PSA_SUCCESS
|
||||
|
||||
PSA Multipart Set Nonce, AES - GCM, IV = 0
|
||||
depends_on:PSA_WANT_ALG_GCM:PSA_WANT_KEY_TYPE_AES
|
||||
aead_multipart_set_nonce:PSA_KEY_TYPE_AES:"aa740abfadcda779220d3b406c5d7ec09a77fe9d94104539":PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_GCM,16):0:"":"":PSA_ERROR_INVALID_ARGUMENT
|
||||
|
||||
PSA Multipart Set Nonce, AES - GCM, IV = 16
|
||||
depends_on:PSA_WANT_ALG_GCM:PSA_WANT_KEY_TYPE_AES
|
||||
aead_multipart_set_nonce:PSA_KEY_TYPE_AES:"aa740abfadcda779220d3b406c5d7ec09a77fe9d94104539":PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_GCM,16):16:"290322092d57479e20f6281e331d95a9":"e7fb0631eebf9bdba87045b33650c4ce":PSA_SUCCESS
|
||||
|
||||
PSA Multipart Set Nonce, AES - GCM, IV = 20
|
||||
depends_on:PSA_WANT_ALG_GCM:PSA_WANT_KEY_TYPE_AES
|
||||
aead_multipart_set_nonce:PSA_KEY_TYPE_AES:"aa740abfadcda779220d3b406c5d7ec09a77fe9d94104539":PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_GCM,16):20:"290322092d57479e20f6281e331d95a9":"e7fb0631eebf9bdba87045b33650c4ce":PSA_SUCCESS
|
||||
|
||||
PSA Multipart Set Nonce: ChaCha20 - Poly1305, IV = 12
|
||||
depends_on:PSA_WANT_ALG_CHACHA20_POLY1305:PSA_WANT_KEY_TYPE_CHACHA20
|
||||
aead_multipart_set_nonce:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:12:"50515253c0c1c2c3c4c5c6c7":"4c616469657320616e642047656e746c656d656e206f662074686520636c617373206f66202739393a204966204920636f756c64206f6666657220796f75206f6e6c79206f6e652074697020666f7220746865206675747572652c2073756e73637265656e20776f756c642062652069742e":PSA_SUCCESS
|
||||
|
||||
PSA Multipart Set Nonce: ChaCha20 - Poly1305, IV = 8
|
||||
depends_on:PSA_WANT_ALG_CHACHA20_POLY1305:PSA_WANT_KEY_TYPE_CHACHA20
|
||||
aead_multipart_set_nonce:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:8:"":"":PSA_ERROR_INVALID_ARGUMENT
|
||||
|
||||
PSA Multipart Set Nonce: ChaCha20 - Poly1305, IV = 0
|
||||
depends_on:PSA_WANT_ALG_CHACHA20_POLY1305:PSA_WANT_KEY_TYPE_CHACHA20
|
||||
aead_multipart_set_nonce:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:0:"":"":PSA_ERROR_INVALID_ARGUMENT
|
||||
|
||||
PSA Multipart Set Nonce: ChaCha20 - Poly1305, IV = 16
|
||||
depends_on:PSA_WANT_ALG_CHACHA20_POLY1305:PSA_WANT_KEY_TYPE_CHACHA20
|
||||
aead_multipart_set_nonce:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:16:"":"":PSA_ERROR_INVALID_ARGUMENT
|
||||
|
||||
PSA Multipart State Checks, AES - GCM
|
||||
depends_on:PSA_WANT_ALG_GCM:PSA_WANT_KEY_TYPE_AES
|
||||
aead_multipart_state_test:PSA_KEY_TYPE_AES:"C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF":PSA_ALG_GCM:"000102030405060708090A0B0C0D0E0F":"000102030405060708090A0B":"0C0D0E0F101112131415161718191A1B1C1D1E"
|
||||
|
@ -3766,6 +3766,104 @@ exit:
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void aead_multipart_set_nonce( int key_type_arg, data_t *key_data,
|
||||
int alg_arg,
|
||||
int nonce_len,
|
||||
data_t *additional_data,
|
||||
data_t *input_data,
|
||||
int expected_status_arg )
|
||||
{
|
||||
|
||||
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
|
||||
psa_key_type_t key_type = key_type_arg;
|
||||
psa_algorithm_t alg = alg_arg;
|
||||
psa_aead_operation_t operation;
|
||||
uint8_t *nonce_buffer = NULL;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
|
||||
psa_status_t expected_status = expected_status_arg;
|
||||
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];
|
||||
int index = 0;
|
||||
|
||||
PSA_ASSERT( psa_crypto_init( ) );
|
||||
|
||||
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
|
||||
psa_set_key_algorithm( &attributes, alg );
|
||||
psa_set_key_type( &attributes, key_type );
|
||||
|
||||
PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
|
||||
&key ) );
|
||||
|
||||
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 );
|
||||
|
||||
/* If the operation is not supported, just skip and not fail in case the
|
||||
* encryption involves a common limitation of cryptography hardwares and
|
||||
* an alternative implementation. */
|
||||
if( status == PSA_ERROR_NOT_SUPPORTED )
|
||||
{
|
||||
MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192( key_type, key_data->len * 8 );
|
||||
MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE( alg, nonce_len );
|
||||
}
|
||||
|
||||
PSA_ASSERT( status );
|
||||
|
||||
ASSERT_ALLOC( nonce_buffer, nonce_len );
|
||||
|
||||
for( index = 0; index < nonce_len - 1; ++index)
|
||||
{
|
||||
nonce_buffer[index] = 'a' + index;
|
||||
}
|
||||
|
||||
status = psa_aead_set_nonce( &operation, nonce_buffer, nonce_len );
|
||||
|
||||
TEST_ASSERT( status == expected_status );
|
||||
|
||||
if( expected_status == 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 );
|
||||
mbedtls_free( output_data );
|
||||
mbedtls_free( final_data );
|
||||
mbedtls_free( nonce_buffer );
|
||||
psa_aead_abort( &operation );
|
||||
PSA_DONE( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void aead_multipart_state_test( int key_type_arg, data_t *key_data,
|
||||
int alg_arg,
|
||||
|
Loading…
x
Reference in New Issue
Block a user