mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 20:05:38 +01:00
Exercise the AES-CTR multipart driver and check it gets called
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
This commit is contained in:
parent
8b12225717
commit
d53c1bf6f2
@ -39,3 +39,87 @@ generate_key:PSA_ERROR_NOT_SUPPORTED:"":PSA_SUCCESS
|
||||
|
||||
generate_key through transparent driver: error
|
||||
generate_key:PSA_ERROR_GENERIC_ERROR:"":PSA_ERROR_GENERIC_ERROR
|
||||
|
||||
PSA symmetric encrypt: AES-CTR, 16 bytes, good
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_encrypt:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a":"8f9408fe80a81d3e813da3c7b0b2bd32":PSA_SUCCESS
|
||||
|
||||
PSA symmetric encrypt: AES-CTR, 15 bytes, good
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_encrypt:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e11739317":"8f9408fe80a81d3e813da3c7b0b2bd":PSA_SUCCESS
|
||||
|
||||
PSA symmetric decrypt: AES-CTR, 16 bytes, good
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_decrypt:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"396ee84fb75fdbb5c2b13c7fe5a654aa":"dd3b5e5319b7591daab1e1a92687feb2":PSA_SUCCESS
|
||||
|
||||
PSA symmetric encryption multipart: AES-CTR, 11+5 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_encrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a":11:11:5:"8f9408fe80a81d3e813da3c7b0b2bd32"
|
||||
|
||||
PSA symmetric encryption multipart: AES-CTR, 16+16 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_encrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a5434f378a597bcef1389318c7fc865ef":16:16:16:"8f9408fe80a81d3e813da3c7b0b2bd321c965bb1de7baf71025f6ef6393ca587"
|
||||
|
||||
PSA symmetric encryption multipart: AES-CTR, 12+20 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_encrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a5434f378a597bcef1389318c7fc865ef":12:12:20:"8f9408fe80a81d3e813da3c7b0b2bd321c965bb1de7baf71025f6ef6393ca587"
|
||||
|
||||
PSA symmetric encryption multipart: AES-CTR, 20+12 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_encrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a5434f378a597bcef1389318c7fc865ef":20:20:12:"8f9408fe80a81d3e813da3c7b0b2bd321c965bb1de7baf71025f6ef6393ca587"
|
||||
|
||||
PSA symmetric encryption multipart: AES-CTR, 12+10 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_encrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a5434f378a597":12:12:10:"8f9408fe80a81d3e813da3c7b0b2bd321c965bb1de7b"
|
||||
|
||||
PSA symmetric encryption multipart: AES-CTR, 0+15 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_encrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e11739317":0:0:15:"8f9408fe80a81d3e813da3c7b0b2bd"
|
||||
|
||||
PSA symmetric encryption multipart: AES-CTR, 15+0 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_encrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e11739317":15:15:0:"8f9408fe80a81d3e813da3c7b0b2bd"
|
||||
|
||||
PSA symmetric encryption multipart: AES-CTR, 0+16 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_encrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a":0:0:16:"8f9408fe80a81d3e813da3c7b0b2bd32"
|
||||
|
||||
PSA symmetric encryption multipart: AES-CTR, 16+0 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_encrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a":16:16:0:"8f9408fe80a81d3e813da3c7b0b2bd32"
|
||||
|
||||
PSA symmetric decryption multipart: AES-CTR, 11+5 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_decrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a":11:11:5:"8f9408fe80a81d3e813da3c7b0b2bd32"
|
||||
|
||||
PSA symmetric decryption multipart: AES-CTR, 16+16 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_decrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a5434f378a597bcef1389318c7fc865ef":16:16:16:"8f9408fe80a81d3e813da3c7b0b2bd321c965bb1de7baf71025f6ef6393ca587"
|
||||
|
||||
PSA symmetric decryption multipart: AES-CTR, 12+20 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_decrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a5434f378a597bcef1389318c7fc865ef":12:12:20:"8f9408fe80a81d3e813da3c7b0b2bd321c965bb1de7baf71025f6ef6393ca587"
|
||||
|
||||
PSA symmetric decryption multipart: AES-CTR, 20+12 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_decrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a5434f378a597bcef1389318c7fc865ef":20:20:12:"8f9408fe80a81d3e813da3c7b0b2bd321c965bb1de7baf71025f6ef6393ca587"
|
||||
|
||||
PSA symmetric decryption multipart: AES-CTR, 12+10 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_decrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a5434f378a597":12:12:10:"8f9408fe80a81d3e813da3c7b0b2bd321c965bb1de7b"
|
||||
|
||||
PSA symmetric decryption multipart: AES-CTR, 0+15 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_decrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e11739317":0:0:15:"8f9408fe80a81d3e813da3c7b0b2bd"
|
||||
|
||||
PSA symmetric decryption multipart: AES-CTR, 15+0 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_decrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e11739317":15:15:0:"8f9408fe80a81d3e813da3c7b0b2bd"
|
||||
|
||||
PSA symmetric decryption multipart: AES-CTR, 0+16 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_decrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a":0:0:16:"8f9408fe80a81d3e813da3c7b0b2bd32"
|
||||
|
||||
PSA symmetric decryption multipart: AES-CTR, 16+0 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_decrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a":16:16:0:"8f9408fe80a81d3e813da3c7b0b2bd32"
|
||||
|
@ -183,3 +183,322 @@ exit:
|
||||
test_driver_keygen_hooks = test_driver_keygen_hooks_init();
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void cipher_encrypt( int alg_arg, int key_type_arg,
|
||||
data_t *key, data_t *iv,
|
||||
data_t *input, data_t *expected_output,
|
||||
int expected_status_arg )
|
||||
{
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_status_t status;
|
||||
psa_key_type_t key_type = key_type_arg;
|
||||
psa_algorithm_t alg = alg_arg;
|
||||
psa_status_t expected_status = expected_status_arg;
|
||||
unsigned char *output = NULL;
|
||||
size_t output_buffer_size = 0;
|
||||
size_t function_output_length = 0;
|
||||
size_t total_output_length = 0;
|
||||
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
test_transparent_cipher_hit = 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->x, key->len, &handle ) );
|
||||
|
||||
PSA_ASSERT( psa_cipher_encrypt_setup( &operation,
|
||||
handle, alg ) );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 1);
|
||||
test_transparent_cipher_hit = 0;
|
||||
|
||||
PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 1);
|
||||
test_transparent_cipher_hit = 0;
|
||||
|
||||
output_buffer_size = ( (size_t) input->len +
|
||||
PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type ) );
|
||||
ASSERT_ALLOC( output, output_buffer_size );
|
||||
|
||||
PSA_ASSERT( psa_cipher_update( &operation,
|
||||
input->x, input->len,
|
||||
output, output_buffer_size,
|
||||
&function_output_length ) );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 1);
|
||||
test_transparent_cipher_hit = 0;
|
||||
|
||||
total_output_length += function_output_length;
|
||||
status = psa_cipher_finish( &operation,
|
||||
output + total_output_length,
|
||||
output_buffer_size - total_output_length,
|
||||
&function_output_length );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 2);
|
||||
test_transparent_cipher_hit = 0;
|
||||
|
||||
total_output_length += function_output_length;
|
||||
|
||||
TEST_EQUAL( status, expected_status );
|
||||
if( expected_status == PSA_SUCCESS )
|
||||
{
|
||||
PSA_ASSERT( psa_cipher_abort( &operation ) );
|
||||
// driver function should've been called as part of the finish() core routine
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 0);
|
||||
test_transparent_cipher_hit = 0;
|
||||
ASSERT_COMPARE( expected_output->x, expected_output->len,
|
||||
output, total_output_length );
|
||||
}
|
||||
|
||||
exit:
|
||||
psa_cipher_abort( &operation );
|
||||
mbedtls_free( output );
|
||||
psa_destroy_key( handle );
|
||||
PSA_DONE( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void cipher_encrypt_multipart( int alg_arg, int key_type_arg,
|
||||
data_t *key, data_t *iv,
|
||||
data_t *input,
|
||||
int first_part_size_arg,
|
||||
int output1_length_arg, int output2_length_arg,
|
||||
data_t *expected_output )
|
||||
{
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_key_type_t key_type = key_type_arg;
|
||||
psa_algorithm_t alg = alg_arg;
|
||||
size_t first_part_size = first_part_size_arg;
|
||||
size_t output1_length = output1_length_arg;
|
||||
size_t output2_length = output2_length_arg;
|
||||
unsigned char *output = NULL;
|
||||
size_t output_buffer_size = 0;
|
||||
size_t function_output_length = 0;
|
||||
size_t total_output_length = 0;
|
||||
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
test_transparent_cipher_hit = 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->x, key->len, &handle ) );
|
||||
|
||||
PSA_ASSERT( psa_cipher_encrypt_setup( &operation,
|
||||
handle, alg ) );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 1);
|
||||
test_transparent_cipher_hit = 0;
|
||||
|
||||
PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 1);
|
||||
test_transparent_cipher_hit = 0;
|
||||
|
||||
output_buffer_size = ( (size_t) input->len +
|
||||
PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type ) );
|
||||
ASSERT_ALLOC( output, output_buffer_size );
|
||||
|
||||
TEST_ASSERT( first_part_size <= input->len );
|
||||
PSA_ASSERT( psa_cipher_update( &operation, input->x, first_part_size,
|
||||
output, output_buffer_size,
|
||||
&function_output_length ) );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 1);
|
||||
test_transparent_cipher_hit = 0;
|
||||
|
||||
TEST_ASSERT( function_output_length == output1_length );
|
||||
total_output_length += function_output_length;
|
||||
PSA_ASSERT( psa_cipher_update( &operation,
|
||||
input->x + first_part_size,
|
||||
input->len - first_part_size,
|
||||
output + total_output_length,
|
||||
output_buffer_size - total_output_length,
|
||||
&function_output_length ) );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 1);
|
||||
test_transparent_cipher_hit = 0;
|
||||
TEST_ASSERT( function_output_length == output2_length );
|
||||
total_output_length += function_output_length;
|
||||
PSA_ASSERT( psa_cipher_finish( &operation,
|
||||
output + total_output_length,
|
||||
output_buffer_size - total_output_length,
|
||||
&function_output_length ) );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 2);
|
||||
test_transparent_cipher_hit = 0;
|
||||
total_output_length += function_output_length;
|
||||
PSA_ASSERT( psa_cipher_abort( &operation ) );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 0);
|
||||
|
||||
ASSERT_COMPARE( expected_output->x, expected_output->len,
|
||||
output, total_output_length );
|
||||
|
||||
exit:
|
||||
psa_cipher_abort( &operation );
|
||||
mbedtls_free( output );
|
||||
psa_destroy_key( handle );
|
||||
PSA_DONE( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
|
||||
data_t *key, data_t *iv,
|
||||
data_t *input,
|
||||
int first_part_size_arg,
|
||||
int output1_length_arg, int output2_length_arg,
|
||||
data_t *expected_output )
|
||||
{
|
||||
psa_key_handle_t handle = 0;
|
||||
|
||||
psa_key_type_t key_type = key_type_arg;
|
||||
psa_algorithm_t alg = alg_arg;
|
||||
size_t first_part_size = first_part_size_arg;
|
||||
size_t output1_length = output1_length_arg;
|
||||
size_t output2_length = output2_length_arg;
|
||||
unsigned char *output = NULL;
|
||||
size_t output_buffer_size = 0;
|
||||
size_t function_output_length = 0;
|
||||
size_t total_output_length = 0;
|
||||
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
test_transparent_cipher_hit = 0;
|
||||
|
||||
PSA_ASSERT( psa_crypto_init( ) );
|
||||
|
||||
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DECRYPT );
|
||||
psa_set_key_algorithm( &attributes, alg );
|
||||
psa_set_key_type( &attributes, key_type );
|
||||
|
||||
PSA_ASSERT( psa_import_key( &attributes, key->x, key->len, &handle ) );
|
||||
|
||||
PSA_ASSERT( psa_cipher_decrypt_setup( &operation,
|
||||
handle, alg ) );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 1);
|
||||
test_transparent_cipher_hit = 0;
|
||||
|
||||
PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 1);
|
||||
test_transparent_cipher_hit = 0;
|
||||
|
||||
output_buffer_size = ( (size_t) input->len +
|
||||
PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type ) );
|
||||
ASSERT_ALLOC( output, output_buffer_size );
|
||||
|
||||
TEST_ASSERT( first_part_size <= input->len );
|
||||
PSA_ASSERT( psa_cipher_update( &operation,
|
||||
input->x, first_part_size,
|
||||
output, output_buffer_size,
|
||||
&function_output_length ) );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 1);
|
||||
test_transparent_cipher_hit = 0;
|
||||
|
||||
TEST_ASSERT( function_output_length == output1_length );
|
||||
total_output_length += function_output_length;
|
||||
PSA_ASSERT( psa_cipher_update( &operation,
|
||||
input->x + first_part_size,
|
||||
input->len - first_part_size,
|
||||
output + total_output_length,
|
||||
output_buffer_size - total_output_length,
|
||||
&function_output_length ) );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 1);
|
||||
test_transparent_cipher_hit = 0;
|
||||
|
||||
TEST_ASSERT( function_output_length == output2_length );
|
||||
total_output_length += function_output_length;
|
||||
PSA_ASSERT( psa_cipher_finish( &operation,
|
||||
output + total_output_length,
|
||||
output_buffer_size - total_output_length,
|
||||
&function_output_length ) );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 2);
|
||||
test_transparent_cipher_hit = 0;
|
||||
total_output_length += function_output_length;
|
||||
PSA_ASSERT( psa_cipher_abort( &operation ) );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 0);
|
||||
|
||||
ASSERT_COMPARE( expected_output->x, expected_output->len,
|
||||
output, total_output_length );
|
||||
|
||||
exit:
|
||||
psa_cipher_abort( &operation );
|
||||
mbedtls_free( output );
|
||||
psa_destroy_key( handle );
|
||||
PSA_DONE( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void cipher_decrypt( int alg_arg, int key_type_arg,
|
||||
data_t *key, data_t *iv,
|
||||
data_t *input, data_t *expected_output,
|
||||
int expected_status_arg )
|
||||
{
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_status_t status;
|
||||
psa_key_type_t key_type = key_type_arg;
|
||||
psa_algorithm_t alg = alg_arg;
|
||||
psa_status_t expected_status = expected_status_arg;
|
||||
unsigned char *output = NULL;
|
||||
size_t output_buffer_size = 0;
|
||||
size_t function_output_length = 0;
|
||||
size_t total_output_length = 0;
|
||||
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
test_transparent_cipher_hit = 0;
|
||||
|
||||
PSA_ASSERT( psa_crypto_init( ) );
|
||||
|
||||
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DECRYPT );
|
||||
psa_set_key_algorithm( &attributes, alg );
|
||||
psa_set_key_type( &attributes, key_type );
|
||||
|
||||
PSA_ASSERT( psa_import_key( &attributes, key->x, key->len, &handle ) );
|
||||
|
||||
PSA_ASSERT( psa_cipher_decrypt_setup( &operation,
|
||||
handle, alg ) );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 1);
|
||||
test_transparent_cipher_hit = 0;
|
||||
|
||||
PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 1);
|
||||
test_transparent_cipher_hit = 0;
|
||||
|
||||
output_buffer_size = ( (size_t) input->len +
|
||||
PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type ) );
|
||||
ASSERT_ALLOC( output, output_buffer_size );
|
||||
|
||||
PSA_ASSERT( psa_cipher_update( &operation,
|
||||
input->x, input->len,
|
||||
output, output_buffer_size,
|
||||
&function_output_length ) );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 1);
|
||||
test_transparent_cipher_hit = 0;
|
||||
|
||||
total_output_length += function_output_length;
|
||||
status = psa_cipher_finish( &operation,
|
||||
output + total_output_length,
|
||||
output_buffer_size - total_output_length,
|
||||
&function_output_length );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 2);
|
||||
test_transparent_cipher_hit = 0;
|
||||
|
||||
total_output_length += function_output_length;
|
||||
TEST_EQUAL( status, expected_status );
|
||||
|
||||
if( expected_status == PSA_SUCCESS )
|
||||
{
|
||||
PSA_ASSERT( psa_cipher_abort( &operation ) );
|
||||
TEST_EQUAL( test_transparent_cipher_hit, 0);
|
||||
ASSERT_COMPARE( expected_output->x, expected_output->len,
|
||||
output, total_output_length );
|
||||
}
|
||||
|
||||
exit:
|
||||
psa_cipher_abort( &operation );
|
||||
mbedtls_free( output );
|
||||
psa_destroy_key( handle );
|
||||
PSA_DONE( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
Loading…
Reference in New Issue
Block a user