We don't need _test_ in test function names

Also fix typo multpart -> multipart
This commit is contained in:
Gilles Peskine 2018-06-08 14:28:46 +02:00 committed by itayzafrir
parent 048b7f0802
commit 50e586b691
2 changed files with 317 additions and 317 deletions

View File

@ -55,95 +55,95 @@ mac_verify:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":PSA_ALG_CMAC:"":"
PSA Symmetric encryption: AES-CBC-nopad, 16 bytes, good
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
cipher_test_encrypt:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a":"a076ec9dfbe47d52afc357336f20743b":PSA_SUCCESS
cipher_encrypt:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a":"a076ec9dfbe47d52afc357336f20743b":PSA_SUCCESS
PSA Symmetric encryption: AES-CBC-PKCS#7, 16 bytes, good
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
cipher_test_encrypt:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a":"a076ec9dfbe47d52afc357336f20743b":PSA_SUCCESS
cipher_encrypt:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a":"a076ec9dfbe47d52afc357336f20743b":PSA_SUCCESS
PSA Symmetric encryption: AES-CBC-PKCS#7, 15 bytes, good
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
cipher_test_encrypt:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e11739317":"6279b49d7f7a8dd87b685175d4276e24":PSA_SUCCESS
cipher_encrypt:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e11739317":"6279b49d7f7a8dd87b685175d4276e24":PSA_SUCCESS
PSA Symmetric encryption: AES-CBC-nopad, input too short
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
cipher_test_encrypt:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee223":"6bc1bee223":PSA_ERROR_INVALID_ARGUMENT
cipher_encrypt:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee223":"6bc1bee223":PSA_ERROR_INVALID_ARGUMENT
PSA Symmetric encryption: AES-CTR, 16 bytes, good
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
cipher_test_encrypt:PSA_ALG_CTR | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a":"8f9408fe80a81d3e813da3c7b0b2bd32":PSA_SUCCESS
cipher_encrypt:PSA_ALG_CTR | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a":"8f9408fe80a81d3e813da3c7b0b2bd32":PSA_SUCCESS
PSA Symmetric encryption: AES-CTR, 15 bytes, good
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
cipher_test_encrypt:PSA_ALG_CTR | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e11739317":"8f9408fe80a81d3e813da3c7b0b2bd00":PSA_SUCCESS
cipher_encrypt:PSA_ALG_CTR | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e11739317":"8f9408fe80a81d3e813da3c7b0b2bd00":PSA_SUCCESS
PSA Symmetric decryption: AES-CBC-nopad, 16 bytes, good
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
cipher_test_decrypt:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"396ee84fb75fdbb5c2b13c7fe5a654aa":"49e4e66c89a86b67758df89db9ad6955":PSA_SUCCESS
cipher_decrypt:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"396ee84fb75fdbb5c2b13c7fe5a654aa":"49e4e66c89a86b67758df89db9ad6955":PSA_SUCCESS
PSA Symmetric decryption: AES-CBC-PKCS#7, 15 bytes, bad - cipher full block expected
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
cipher_test_decrypt:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e11739317":"49e4e66c89a86b67758df89db9ad6955":PSA_ERROR_BAD_STATE
cipher_decrypt:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e11739317":"49e4e66c89a86b67758df89db9ad6955":PSA_ERROR_BAD_STATE
PSA Symmetric decryption: AES-CTR, 16 bytes, good
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
cipher_test_decrypt:PSA_ALG_CTR | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"396ee84fb75fdbb5c2b13c7fe5a654aa":"dd3b5e5319b7591daab1e1a92687feb2":PSA_SUCCESS
cipher_decrypt:PSA_ALG_CTR | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"396ee84fb75fdbb5c2b13c7fe5a654aa":"dd3b5e5319b7591daab1e1a92687feb2":PSA_SUCCESS
PSA Symmetric decryption: AES-CBC-nopad, input too short
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
cipher_test_decrypt:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee223":"6bc1bee223":PSA_ERROR_BAD_STATE
cipher_decrypt:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee223":"6bc1bee223":PSA_ERROR_BAD_STATE
PSA Symmetric encryption/decryption: AES-CBC-nopad, 16 bytes, good
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
cipher_test_verify_output:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a"
cipher_verify_output:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a"
PSA Symmetric encryption/decryption: AES-CBC-PKCS#7, 16 bytes
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC:MBEDTLS_CIPHER_PADDING_PKCS7
cipher_test_verify_output:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a"
cipher_verify_output:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a"
PSA Symmetric encryption/decryption: AES-CBC-PKCS#7, 15 bytes
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC:MBEDTLS_CIPHER_PADDING_PKCS7
cipher_test_verify_output:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e11739317"
cipher_verify_output:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e11739317"
PSA Symmetric encryption/decryption: AES-CTR
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
cipher_test_verify_output:PSA_ALG_CTR | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a"
cipher_verify_output:PSA_ALG_CTR | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a"
PSA Symmetric encryption multipart: AES-CBC-nopad, 7+9 bytes
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
cipher_test_encrypt_multipart:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a":7:"a076ec9dfbe47d52afc357336f20743b"
cipher_encrypt_multipart:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a":7:"a076ec9dfbe47d52afc357336f20743b"
PSA Symmetric encryption multipart: AES-CBC-nopad, 3+13 bytes
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
cipher_test_encrypt_multipart:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a":3:"a076ec9dfbe47d52afc357336f20743b"
cipher_encrypt_multipart:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a":3:"a076ec9dfbe47d52afc357336f20743b"
PSA Symmetric encryption multipart: AES-CBC-nopad, 4+12 bytes
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
cipher_test_encrypt_multipart:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a":4:"a076ec9dfbe47d52afc357336f20743b"
cipher_encrypt_multipart:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a":4:"a076ec9dfbe47d52afc357336f20743b"
PSA Symmetric encryption multipart: AES-CBC-nopad, 11+5 bytes
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
cipher_test_encrypt_multipart:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a":11:"a076ec9dfbe47d52afc357336f20743b"
cipher_encrypt_multipart:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a":11:"a076ec9dfbe47d52afc357336f20743b"
PSA Symmetric decryption multipart: AES-CBC-nopad, 7+9 bytes
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
cipher_test_decrypt_multipart:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"a076ec9dfbe47d52afc357336f20743b":7:"6bc1bee22e409f96e93d7e117393172a"
cipher_decrypt_multipart:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"a076ec9dfbe47d52afc357336f20743b":7:"6bc1bee22e409f96e93d7e117393172a"
PSA Symmetric decryption multipart: AES-CBC-nopad, 3+13 bytes
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
cipher_test_decrypt_multipart:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"a076ec9dfbe47d52afc357336f20743b":3:"6bc1bee22e409f96e93d7e117393172a"
cipher_decrypt_multipart:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"a076ec9dfbe47d52afc357336f20743b":3:"6bc1bee22e409f96e93d7e117393172a"
PSA Symmetric decryption multipart: AES-CBC-nopad, 11+5 bytes
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
cipher_test_decrypt_multipart:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"a076ec9dfbe47d52afc357336f20743b":11:"6bc1bee22e409f96e93d7e117393172a"
cipher_decrypt_multipart:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"a076ec9dfbe47d52afc357336f20743b":11:"6bc1bee22e409f96e93d7e117393172a"
PSA Symmetric encryption + decryption multipart: AES-CBC-nopad, 11+5 bytes
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
cipher_test_verify_output_multpart:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"a076ec9dfbe47d52afc357336f20743b":11
cipher_verify_output_multipart:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"a076ec9dfbe47d52afc357336f20743b":11
PSA Symmetric encryption + decryption multipart: AES-CBC-PKCS#7 padding, 4+12 bytes
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC:MBEDTLS_CIPHER_PADDING_PKCS7
cipher_test_verify_output_multpart:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"a076ec9dfbe47d52afc357336f20743b":4
cipher_verify_output_multipart:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"a076ec9dfbe47d52afc357336f20743b":4
PSA signature size: RSA keypair, 1024 bits, PKCS#1 v1.5 raw
signature_size:PSA_KEY_TYPE_RSA_KEYPAIR:1024:PSA_ALG_RSA_PKCS1V15_SIGN_RAW:128

View File

@ -266,296 +266,296 @@ exit:
/* BEGIN_CASE */
void cipher_test_encrypt( int alg_arg, int key_type_arg,
void cipher_encrypt( int alg_arg, int key_type_arg,
char *key_hex,
char *input_hex, char *output_hex,
int expected_status )
{
int key_slot = 1;
psa_status_t status;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
unsigned char *key = NULL;
size_t key_size;
unsigned char iv[16] = {0};
unsigned char *input = NULL;
size_t input_size = 0;
unsigned char *output;
unsigned char *expected_output;
size_t expected_output_size;
size_t output_buffer_size = 0;
size_t function_output_length = 0;
psa_cipher_operation_t operation;
key = unhexify_alloc( key_hex, &key_size );
TEST_ASSERT( key != NULL );
input = unhexify_alloc( input_hex, &input_size );
TEST_ASSERT( input != NULL );
expected_output = unhexify_alloc( output_hex, &expected_output_size );
TEST_ASSERT( expected_output != NULL );
memset( iv, 0x2a, sizeof( iv ) );
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
TEST_ASSERT( psa_import_key( key_slot, key_type,
key, key_size ) == PSA_SUCCESS );
TEST_ASSERT( psa_encrypt_setup( &operation, key_slot, alg ) == PSA_SUCCESS );
TEST_ASSERT( psa_encrypt_set_iv( &operation,
iv, sizeof( iv ) ) == PSA_SUCCESS );
output_buffer_size = input_size + operation.block_size;
output = mbedtls_calloc( 1, output_buffer_size );
TEST_ASSERT( psa_cipher_update( &operation, input, input_size,
output, output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
status = psa_cipher_finish( &operation,
output + function_output_length,
output_buffer_size,
&function_output_length );
TEST_ASSERT( status == (psa_status_t) expected_status );
if( expected_status == PSA_SUCCESS )
{
TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS );
TEST_ASSERT( memcmp( expected_output, output,
expected_output_size ) == 0 );
}
exit:
mbedtls_free( key );
mbedtls_free( input );
psa_destroy_key( key_slot );
mbedtls_psa_crypto_free( );
}
/* END_CASE */
/* BEGIN_CASE */
void cipher_encrypt_multipart( int alg_arg, int key_type_arg,
char *key_hex,
char *input_hex,
int first_part_size, char *output_hex )
{
int key_slot = 1;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
unsigned char *key = NULL;
size_t key_size;
unsigned char iv[16] = {0};
unsigned char *input = NULL;
size_t input_size = 0;
unsigned char *output;
unsigned char *expected_output;
size_t expected_output_size;
size_t output_buffer_size = 0;
size_t function_output_length = 0;
psa_cipher_operation_t operation;
key = unhexify_alloc( key_hex, &key_size );
TEST_ASSERT( key != NULL );
input = unhexify_alloc( input_hex, &input_size );
TEST_ASSERT( input != NULL );
expected_output = unhexify_alloc( output_hex, &expected_output_size );
TEST_ASSERT( expected_output != NULL );
memset( iv, 0x2a, sizeof( iv ) );
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
TEST_ASSERT( psa_import_key( key_slot, key_type,
key, key_size ) == PSA_SUCCESS );
TEST_ASSERT( psa_encrypt_setup( &operation, key_slot, alg ) == PSA_SUCCESS );
TEST_ASSERT( psa_encrypt_set_iv( &operation,
iv, sizeof( iv ) ) == PSA_SUCCESS );
output_buffer_size = input_size + operation.block_size;
output = mbedtls_calloc( 1, output_buffer_size );
TEST_ASSERT( (unsigned int) first_part_size < input_size );
TEST_ASSERT( psa_cipher_update( &operation, input, first_part_size,
output, output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
TEST_ASSERT( psa_cipher_update( &operation,
input + first_part_size,
input_size - first_part_size,
output, output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
TEST_ASSERT( psa_cipher_finish( &operation,
output + function_output_length,
output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS );
TEST_ASSERT( input_size == expected_output_size );
TEST_ASSERT( memcmp( expected_output, output, expected_output_size ) == 0 );
exit:
mbedtls_free( key );
mbedtls_free( input );
psa_destroy_key( key_slot );
mbedtls_psa_crypto_free( );
}
/* END_CASE */
/* BEGIN_CASE */
void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
char *key_hex,
char *input_hex,
int first_part_size, char *output_hex )
{
int key_slot = 1;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
unsigned char *key = NULL;
size_t key_size;
unsigned char iv[16] = {0};
unsigned char *input = NULL;
size_t input_size = 0;
unsigned char *output;
unsigned char *expected_output;
size_t expected_output_size;
size_t output_buffer_size = 0;
size_t function_output_length = 0;
psa_cipher_operation_t operation;
key = unhexify_alloc( key_hex, &key_size );
TEST_ASSERT( key != NULL );
input = unhexify_alloc( input_hex, &input_size );
TEST_ASSERT( input != NULL );
expected_output = unhexify_alloc( output_hex, &expected_output_size );
TEST_ASSERT( expected_output != NULL );
memset( iv, 0x2a, sizeof( iv ) );
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
TEST_ASSERT( psa_import_key( key_slot, key_type,
key, key_size ) == PSA_SUCCESS );
TEST_ASSERT( psa_decrypt_setup( &operation, key_slot, alg ) == PSA_SUCCESS );
TEST_ASSERT( psa_encrypt_set_iv( &operation,
iv, sizeof( iv ) ) == PSA_SUCCESS );
output_buffer_size = input_size + operation.block_size;
output = mbedtls_calloc( 1, output_buffer_size );
TEST_ASSERT( (unsigned int) first_part_size < input_size );
TEST_ASSERT( psa_cipher_update( &operation, input, first_part_size,
output, output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
TEST_ASSERT( psa_cipher_update( &operation,
input + first_part_size,
input_size - first_part_size,
output, output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
TEST_ASSERT( psa_cipher_finish( &operation,
output + function_output_length,
output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS );
TEST_ASSERT( input_size == expected_output_size );
TEST_ASSERT( memcmp( expected_output, output, expected_output_size ) == 0 );
exit:
mbedtls_free( key );
mbedtls_free( input );
psa_destroy_key( key_slot );
mbedtls_psa_crypto_free( );
}
/* END_CASE */
/* BEGIN_CASE */
void cipher_decrypt( int alg_arg, int key_type_arg,
char *key_hex,
char *input_hex, char *output_hex,
int expected_status )
{
int key_slot = 1;
psa_status_t status;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
unsigned char *key = NULL;
size_t key_size;
unsigned char iv[16] = {0};
unsigned char *input = NULL;
size_t input_size = 0;
unsigned char *output;
unsigned char *expected_output;
size_t expected_output_size;
size_t output_buffer_size = 0;
size_t function_output_length = 0;
psa_cipher_operation_t operation;
key = unhexify_alloc( key_hex, &key_size );
TEST_ASSERT( key != NULL );
input = unhexify_alloc( input_hex, &input_size );
TEST_ASSERT( input != NULL );
expected_output = unhexify_alloc( output_hex, &expected_output_size );
TEST_ASSERT( expected_output != NULL );
memset( iv, 0x2a, sizeof( iv ) );
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
TEST_ASSERT( psa_import_key( key_slot, key_type,
key, key_size ) == PSA_SUCCESS );
TEST_ASSERT( psa_decrypt_setup( &operation, key_slot, alg ) == PSA_SUCCESS );
TEST_ASSERT( psa_encrypt_set_iv( &operation,
iv, sizeof( iv ) ) == PSA_SUCCESS );
output_buffer_size = input_size + operation.block_size;
output = mbedtls_calloc( 1, output_buffer_size );
TEST_ASSERT( psa_cipher_update( &operation, input, input_size,
output, output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
status = psa_cipher_finish( &operation,
output + function_output_length,
output_buffer_size,
&function_output_length );
TEST_ASSERT( status == (psa_status_t) expected_status );
if( expected_status == PSA_SUCCESS )
{
TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS );
TEST_ASSERT( memcmp( expected_output, output,
expected_output_size ) == 0 );
}
exit:
mbedtls_free( key );
mbedtls_free( input );
psa_destroy_key( key_slot );
mbedtls_psa_crypto_free( );
}
/* END_CASE */
/* BEGIN_CASE */
void cipher_verify_output( int alg_arg, int key_type_arg,
char *key_hex,
char *input_hex, char *output_hex,
int expected_status )
{
int key_slot = 1;
psa_status_t status;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
unsigned char *key = NULL;
size_t key_size;
unsigned char iv[16] = {0};
unsigned char *input = NULL;
size_t input_size = 0;
unsigned char *output;
unsigned char *expected_output;
size_t expected_output_size;
size_t output_buffer_size = 0;
size_t function_output_length = 0;
psa_cipher_operation_t operation;
key = unhexify_alloc( key_hex, &key_size );
TEST_ASSERT( key != NULL );
input = unhexify_alloc( input_hex, &input_size );
TEST_ASSERT( input != NULL );
expected_output = unhexify_alloc( output_hex, &expected_output_size );
TEST_ASSERT( expected_output != NULL );
memset( iv, 0x2a, sizeof( iv ) );
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
TEST_ASSERT( psa_import_key( key_slot, key_type,
key, key_size ) == PSA_SUCCESS );
TEST_ASSERT( psa_encrypt_setup( &operation, key_slot, alg ) == PSA_SUCCESS );
TEST_ASSERT( psa_encrypt_set_iv( &operation,
iv, sizeof( iv ) ) == PSA_SUCCESS );
output_buffer_size = input_size + operation.block_size;
output = mbedtls_calloc( 1, output_buffer_size );
TEST_ASSERT( psa_cipher_update( &operation, input, input_size,
output, output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
status = psa_cipher_finish( &operation,
output + function_output_length,
output_buffer_size,
&function_output_length );
TEST_ASSERT( status == (psa_status_t) expected_status );
if( expected_status == PSA_SUCCESS )
{
TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS );
TEST_ASSERT( memcmp( expected_output, output,
expected_output_size ) == 0 );
}
exit:
mbedtls_free( key );
mbedtls_free( input );
psa_destroy_key( key_slot );
mbedtls_psa_crypto_free( );
}
/* END_CASE */
/* BEGIN_CASE */
void cipher_test_encrypt_multipart( int alg_arg, int key_type_arg,
char *key_hex,
char *input_hex,
int first_part_size, char *output_hex )
{
int key_slot = 1;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
unsigned char *key = NULL;
size_t key_size;
unsigned char iv[16] = {0};
unsigned char *input = NULL;
size_t input_size = 0;
unsigned char *output;
unsigned char *expected_output;
size_t expected_output_size;
size_t output_buffer_size = 0;
size_t function_output_length = 0;
psa_cipher_operation_t operation;
key = unhexify_alloc( key_hex, &key_size );
TEST_ASSERT( key != NULL );
input = unhexify_alloc( input_hex, &input_size );
TEST_ASSERT( input != NULL );
expected_output = unhexify_alloc( output_hex, &expected_output_size );
TEST_ASSERT( expected_output != NULL );
memset( iv, 0x2a, sizeof( iv ) );
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
TEST_ASSERT( psa_import_key( key_slot, key_type,
key, key_size ) == PSA_SUCCESS );
TEST_ASSERT( psa_encrypt_setup( &operation, key_slot, alg ) == PSA_SUCCESS );
TEST_ASSERT( psa_encrypt_set_iv( &operation,
iv, sizeof( iv ) ) == PSA_SUCCESS );
output_buffer_size = input_size + operation.block_size;
output = mbedtls_calloc( 1, output_buffer_size );
TEST_ASSERT( (unsigned int) first_part_size < input_size );
TEST_ASSERT( psa_cipher_update( &operation, input, first_part_size,
output, output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
TEST_ASSERT( psa_cipher_update( &operation,
input + first_part_size,
input_size - first_part_size,
output, output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
TEST_ASSERT( psa_cipher_finish( &operation,
output + function_output_length,
output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS );
TEST_ASSERT( input_size == expected_output_size );
TEST_ASSERT( memcmp( expected_output, output, expected_output_size ) == 0 );
exit:
mbedtls_free( key );
mbedtls_free( input );
psa_destroy_key( key_slot );
mbedtls_psa_crypto_free( );
}
/* END_CASE */
/* BEGIN_CASE */
void cipher_test_decrypt_multipart( int alg_arg, int key_type_arg,
char *key_hex,
char *input_hex,
int first_part_size, char *output_hex )
{
int key_slot = 1;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
unsigned char *key = NULL;
size_t key_size;
unsigned char iv[16] = {0};
unsigned char *input = NULL;
size_t input_size = 0;
unsigned char *output;
unsigned char *expected_output;
size_t expected_output_size;
size_t output_buffer_size = 0;
size_t function_output_length = 0;
psa_cipher_operation_t operation;
key = unhexify_alloc( key_hex, &key_size );
TEST_ASSERT( key != NULL );
input = unhexify_alloc( input_hex, &input_size );
TEST_ASSERT( input != NULL );
expected_output = unhexify_alloc( output_hex, &expected_output_size );
TEST_ASSERT( expected_output != NULL );
memset( iv, 0x2a, sizeof( iv ) );
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
TEST_ASSERT( psa_import_key( key_slot, key_type,
key, key_size ) == PSA_SUCCESS );
TEST_ASSERT( psa_decrypt_setup( &operation, key_slot, alg ) == PSA_SUCCESS );
TEST_ASSERT( psa_encrypt_set_iv( &operation,
iv, sizeof( iv ) ) == PSA_SUCCESS );
output_buffer_size = input_size + operation.block_size;
output = mbedtls_calloc( 1, output_buffer_size );
TEST_ASSERT( (unsigned int) first_part_size < input_size );
TEST_ASSERT( psa_cipher_update( &operation, input, first_part_size,
output, output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
TEST_ASSERT( psa_cipher_update( &operation,
input + first_part_size,
input_size - first_part_size,
output, output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
TEST_ASSERT( psa_cipher_finish( &operation,
output + function_output_length,
output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS );
TEST_ASSERT( input_size == expected_output_size );
TEST_ASSERT( memcmp( expected_output, output, expected_output_size ) == 0 );
exit:
mbedtls_free( key );
mbedtls_free( input );
psa_destroy_key( key_slot );
mbedtls_psa_crypto_free( );
}
/* END_CASE */
/* BEGIN_CASE */
void cipher_test_decrypt( int alg_arg, int key_type_arg,
char *key_hex,
char *input_hex, char *output_hex,
int expected_status )
{
int key_slot = 1;
psa_status_t status;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
unsigned char *key = NULL;
size_t key_size;
unsigned char iv[16] = {0};
unsigned char *input = NULL;
size_t input_size = 0;
unsigned char *output;
unsigned char *expected_output;
size_t expected_output_size;
size_t output_buffer_size = 0;
size_t function_output_length = 0;
psa_cipher_operation_t operation;
key = unhexify_alloc( key_hex, &key_size );
TEST_ASSERT( key != NULL );
input = unhexify_alloc( input_hex, &input_size );
TEST_ASSERT( input != NULL );
expected_output = unhexify_alloc( output_hex, &expected_output_size );
TEST_ASSERT( expected_output != NULL );
memset( iv, 0x2a, sizeof( iv ) );
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
TEST_ASSERT( psa_import_key( key_slot, key_type,
key, key_size ) == PSA_SUCCESS );
TEST_ASSERT( psa_decrypt_setup( &operation, key_slot, alg ) == PSA_SUCCESS );
TEST_ASSERT( psa_encrypt_set_iv( &operation,
iv, sizeof( iv ) ) == PSA_SUCCESS );
output_buffer_size = input_size + operation.block_size;
output = mbedtls_calloc( 1, output_buffer_size );
TEST_ASSERT( psa_cipher_update( &operation, input, input_size,
output, output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
status = psa_cipher_finish( &operation,
output + function_output_length,
output_buffer_size,
&function_output_length );
TEST_ASSERT( status == (psa_status_t) expected_status );
if( expected_status == PSA_SUCCESS )
{
TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS );
TEST_ASSERT( memcmp( expected_output, output,
expected_output_size ) == 0 );
}
exit:
mbedtls_free( key );
mbedtls_free( input );
psa_destroy_key( key_slot );
mbedtls_psa_crypto_free( );
}
/* END_CASE */
/* BEGIN_CASE */
void cipher_test_verify_output( int alg_arg, int key_type_arg,
char *key_hex,
char *input_hex )
char *input_hex )
{
int key_slot = 1;
psa_key_type_t key_type = key_type_arg;
@ -639,11 +639,11 @@ exit:
/* END_CASE */
/* BEGIN_CASE */
void cipher_test_verify_output_multpart( int alg_arg,
int key_type_arg,
char *key_hex,
char *input_hex,
int first_part_size )
void cipher_verify_output_multipart( int alg_arg,
int key_type_arg,
char *key_hex,
char *input_hex,
int first_part_size )
{
int key_slot = 1;
psa_key_type_t key_type = key_type_arg;