fix and add tests case + fix for padding mode
diff --git a/tests/suites/test_suite_psa_crypto.data b/tests/suites/test_suite_psa_crypto.data
index 2126462..3ebbd59 100644
--- a/tests/suites/test_suite_psa_crypto.data
+++ b/tests/suites/test_suite_psa_crypto.data
@@ -55,28 +55,77 @@
PSA Symmetric encryption: AES-128
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"
+cipher_test_encrypt:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a":"a076ec9dfbe47d52afc357336f20743b":PSA_SUCCESS
+
+PSA Symmetric encryption: bad, input buffer too small AES-128
+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
PSA Symmetric decryption: AES-128
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"
+cipher_test_decrypt:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"396ee84fb75fdbb5c2b13c7fe5a654aa":"49e4e66c89a86b67758df89db9ad6955":PSA_SUCCESS
+
+PSA Symmetric decryption: AES-128 bad, input buffer too small AES-128
+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
+
PSA Symmetric encryption/decryption: AES-128
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"
-PSA Symmetric encryption multipart: AES-128, 7+9
+PSA Symmetric encryption/decryption: 16 bytes PKC padding
+depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
+cipher_test_verify_output:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a"
+
+PSA Symmetric encryption/decryption: 15 bytes PKC padding
+depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
+cipher_test_verify_output:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e11739317"
+
+PSA Symmetric encryption/decryption CTR alg: AES-128
+depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
+cipher_test_verify_output:PSA_ALG_CTR | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a"
+
+PSA Symmetric encryption multipart: AES-128 7+9
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"
-PSA Symmetric encryption multipart: AES-128, 3+13
+PSA Symmetric encryption multipart: AES-128 3+13
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"
-PSA Symmetric encryption multipart: AES-128, 11+5
+PSA Symmetric encryption multipart: AES-128 4+12
+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"
+
+PSA Symmetric encryption multipart: AES-128 11+5
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"
+PSA Symmetric decryption multipart: AES-128 7+9
+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"
+
+PSA Symmetric decryption multipart: AES-128 3+12
+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"
+
+PSA Symmetric decryption multipart: AES-128 11+5
+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"
+
+PSA Symmetric encryption + decryption multipart: AES-128 11+5
+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
+
+PSA Symmetric encryption + decryption multipart: AES-128 PKC padding, 4+12
+depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
+cipher_test_verify_output_multpart:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"a076ec9dfbe47d52afc357336f20743b":4
+
+PSA Symmetric encryption + decryption multipart: AES-128 16+16
+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":"a076ec9dfbe47d52afc357336f20743ba076ec9dfbe47d52afc357336f20743b":16
+
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
@@ -128,3 +177,5 @@
PSA Key Lifetime set fail, invalid key lifetime value
key_lifetime_set_fail:1:PSA_KEY_LIFETIME_PERSISTENT+1:PSA_ERROR_INVALID_ARGUMENT
+
+
diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function
index 5ac8721..8d16c6f 100644
--- a/tests/suites/test_suite_psa_crypto.function
+++ b/tests/suites/test_suite_psa_crypto.function
@@ -265,11 +265,13 @@
/* END_CASE */
/* BEGIN_CASE */
-void cipher_test_encrypt( int alg_arg, int key_type_arg,
- char *key_hex,
- char *input_hex, char *output_hex )
+void cipher_test_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;
@@ -279,7 +281,7 @@
size_t input_size = 0;
unsigned char *output;
unsigned char *expected_output;
- size_t output_size = 0;
+ size_t output_size, output_size_1 = 0;
size_t output_length = 0;
psa_cipher_operation_t operation;
@@ -294,7 +296,7 @@
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,
@@ -304,20 +306,22 @@
TEST_ASSERT( psa_encrypt_set_iv( &operation, iv,
sizeof( iv ) ) == PSA_SUCCESS );
-
- output = mbedtls_calloc(0, output_size);
+ output_size_1 = input_size + operation.block_size;
+ output = mbedtls_calloc(1, output_size_1);
TEST_ASSERT( psa_cipher_update( &operation, input, input_size,
- output, output_size,
+ output, output_size_1,
&output_length) == PSA_SUCCESS );
- TEST_ASSERT( psa_cipher_finish( &operation, output + output_length,
- output_size, &output_length) == PSA_SUCCESS );
+ status = psa_cipher_finish( &operation, output + output_length,
+ output_size_1, &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( psa_cipher_abort( &operation ) == PSA_SUCCESS );
-
- TEST_ASSERT( input_size == output_size );
- TEST_ASSERT( memcmp( expected_output, output, output_size ) == 0 );
-
+ TEST_ASSERT( input_size == output_size );
+ TEST_ASSERT( memcmp( expected_output, output, output_size ) == 0 );
+ }
exit:
mbedtls_free( key );
mbedtls_free( input );
@@ -327,7 +331,7 @@
/* END_CASE */
/* BEGIN_CASE */
-void cipher_test_encrypt_multipart( int alg_arg, int key_type_arg,
+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 )
@@ -342,7 +346,7 @@
size_t input_size = 0;
unsigned char *output;
unsigned char *expected_output;
- size_t output_size = 0;
+ size_t output_size, output_size_1 = 0;
size_t output_length = 0;
psa_cipher_operation_t operation;
@@ -357,7 +361,7 @@
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,
@@ -366,20 +370,19 @@
TEST_ASSERT( psa_encrypt_setup( &operation, key_slot, alg ) == PSA_SUCCESS );
TEST_ASSERT( psa_encrypt_set_iv( &operation, iv,
- sizeof( iv ) ) == PSA_SUCCESS );
-
- output = mbedtls_calloc(0, output_size);
+ sizeof( iv ) ) == PSA_SUCCESS );
+ output_size_1 = input_size + operation.block_size;
+ output = mbedtls_calloc(1, output_size_1);
TEST_ASSERT( (unsigned int)first_part_size < input_size );
TEST_ASSERT( psa_cipher_update( &operation, input, first_part_size,
- output, output_size,
+ output, output_size_1,
&output_length) == PSA_SUCCESS );
- TEST_ASSERT( psa_cipher_update( &operation, input + first_part_size,
- input_size - first_part_size,
- output, output_size,
+ TEST_ASSERT( psa_cipher_update( &operation, input + first_part_size, input_size - first_part_size,
+ output, output_size_1,
&output_length) == PSA_SUCCESS );
TEST_ASSERT( psa_cipher_finish( &operation, output + output_length,
- output_size, &output_length) == PSA_SUCCESS );
+ output_size_1, &output_length) == PSA_SUCCESS );
TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS );
@@ -395,11 +398,13 @@
/* END_CASE */
/* BEGIN_CASE */
-void cipher_test_decrypt( int alg_arg, int key_type_arg,
+void cipher_test_decrypt_multipart( int alg_arg, int key_type_arg,
char *key_hex,
- char *input_hex, char *output_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;
@@ -409,7 +414,7 @@
size_t input_size = 0;
unsigned char *output;
unsigned char *expected_output;
- size_t output_size = 0;
+ size_t output_size, output_size_1 = 0;
size_t output_length = 0;
psa_cipher_operation_t operation;
@@ -424,7 +429,7 @@
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,
@@ -435,14 +440,18 @@
TEST_ASSERT( psa_encrypt_set_iv( &operation, iv,
sizeof( iv ) ) == PSA_SUCCESS );
- output = mbedtls_calloc(0, output_size);
+ output_size_1 = input_size + operation.block_size;
+ output = mbedtls_calloc(1, output_size_1);
- TEST_ASSERT( psa_cipher_update( &operation, input, input_size,
- output, output_size,
+ TEST_ASSERT( (unsigned int)first_part_size < input_size );
+ TEST_ASSERT( psa_cipher_update( &operation, input, first_part_size,
+ output, output_size_1,
+ &output_length) == PSA_SUCCESS );
+ TEST_ASSERT( psa_cipher_update( &operation, input + first_part_size, input_size - first_part_size,
+ output, output_size_1,
&output_length) == PSA_SUCCESS );
TEST_ASSERT( psa_cipher_finish( &operation, output + output_length,
- output_size, &output_length) == PSA_SUCCESS );
-
+ output_size_1, &output_length) == PSA_SUCCESS );
TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS );
TEST_ASSERT( input_size == output_size );
@@ -458,7 +467,78 @@
/* BEGIN_CASE */
-void cipher_test_verify_output( int alg_arg, int key_type_arg,
+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 output_size, output_size_1 = 0;
+ size_t 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, &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_size_1 = input_size + operation.block_size;
+ output = mbedtls_calloc(1, output_size);
+
+ TEST_ASSERT( psa_cipher_update( &operation, input, input_size,
+ output, output_size_1,
+ &output_length) == PSA_SUCCESS );
+ status = psa_cipher_finish( &operation, output + output_length,
+ output_size_1, &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( input_size == output_size );
+ TEST_ASSERT( memcmp( expected_output, output, 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 )
{
@@ -487,7 +567,7 @@
input = unhexify_alloc( input_hex, &input_size );
TEST_ASSERT( input != NULL );
-
+
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
TEST_ASSERT( psa_import_key( key_slot, key_type,
@@ -498,45 +578,154 @@
TEST_ASSERT( psa_encrypt_generate_iv( &operation1, iv,
iv_size, &iv_length) == PSA_SUCCESS );
- output1_size = input_size;
- output1 = mbedtls_calloc(0, output1_size);
+ output1_size = input_size + operation1.block_size;
+ output1 = mbedtls_calloc(1, output1_size);
+ TEST_ASSERT( output1 != NULL);
+
TEST_ASSERT( psa_cipher_update( &operation1, input, input_size,
- output1, output1_size,
+ output1, output1_size,
&output1_length) == PSA_SUCCESS );
TEST_ASSERT( psa_cipher_finish( &operation1, output1 + output1_length,
- output1_size, &tmp_output_length) == PSA_SUCCESS );
+ output1_size, &tmp_output_length) == PSA_SUCCESS );
+
+ output1_length += tmp_output_length;
+
+ TEST_ASSERT( psa_cipher_abort( &operation1 ) == PSA_SUCCESS );
+
+ output2_size = output1_length;
+ output2 = mbedtls_calloc(1, output2_size);
+
+ TEST_ASSERT( psa_encrypt_set_iv( &operation2, iv,
+ iv_length) == PSA_SUCCESS );
+ TEST_ASSERT( psa_cipher_update( &operation2, output1, output1_length,
+ output2, output2_size, &output2_length) == PSA_SUCCESS );
+ tmp_output_length = 0;
+ TEST_ASSERT( psa_cipher_finish( &operation2, output2 + output2_length,
+ output2_size, &tmp_output_length) == PSA_SUCCESS );
+
+ output2_length += tmp_output_length;
+
+ TEST_ASSERT( psa_cipher_abort( &operation1 ) == PSA_SUCCESS );
+
+ TEST_ASSERT( input_size == output2_length );
+ TEST_ASSERT( memcmp( input, output2, input_size ) == 0 );
+
+exit:
+ mbedtls_free( key );
+ mbedtls_free( input );
+ mbedtls_free( output1 );
+ mbedtls_free( output2 );
+
+ psa_destroy_key( key_slot );
+ mbedtls_psa_crypto_free( );
+}
+/* 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 )
+{
+ 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};
+ size_t iv_size = 16;
+ size_t iv_length = 0;
+ unsigned char *input = NULL;
+ size_t input_size = 0;
+ unsigned char *output1;
+ size_t output1_size = 0;
+ size_t output1_length = 0;
+ unsigned char *output2;
+ size_t output2_size = 0;
+ size_t output2_length = 0;
+ size_t tmp_output_length , temp = 0;
+ psa_cipher_operation_t operation1;
+ psa_cipher_operation_t operation2;
+
+ key = unhexify_alloc( key_hex, &key_size );
+ TEST_ASSERT( key != NULL );
+
+ input = unhexify_alloc( input_hex, &input_size );
+ TEST_ASSERT( input != NULL );
+
+ 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( &operation1, key_slot, alg ) == PSA_SUCCESS );
+ TEST_ASSERT( psa_decrypt_setup( &operation2, key_slot, alg ) == PSA_SUCCESS );
+
+ TEST_ASSERT( psa_encrypt_generate_iv( &operation1, iv,
+ iv_size, &iv_length) == PSA_SUCCESS );
+ output1_size = input_size + operation1.block_size;
+ output1 = mbedtls_calloc(1, output1_size);
+
+ TEST_ASSERT( (unsigned int)first_part_size < input_size );
+
+ TEST_ASSERT( psa_cipher_update( &operation1, input, first_part_size,
+ output1, output1_size,
+ &output1_length) == PSA_SUCCESS );
+ temp = output1_length ;
+
+ TEST_ASSERT( psa_cipher_update( &operation1, input + first_part_size, input_size - first_part_size,
+ output1, output1_size,
+ &output1_length) == PSA_SUCCESS );
+ output1_length += temp;
+
+ TEST_ASSERT( psa_cipher_finish( &operation1, output1 + output1_length,
+ output1_size - output1_length, &tmp_output_length) == PSA_SUCCESS );
output1_length += tmp_output_length;
TEST_ASSERT( psa_cipher_abort( &operation1 ) == PSA_SUCCESS );
output2_size = output1_length;
- output2 = mbedtls_calloc(0, output2_size);
+ output2 = mbedtls_calloc(1, output2_size);
TEST_ASSERT( psa_encrypt_set_iv( &operation2, iv,
- iv_length) == PSA_SUCCESS );
- TEST_ASSERT( psa_cipher_update( &operation2, output1, output1_length,
- output2, output2_size, &output2_length) == PSA_SUCCESS );
+ iv_length) == PSA_SUCCESS );
+
+ TEST_ASSERT( psa_cipher_update( &operation2, output1, first_part_size,
+ output2, output2_size,
+ &output2_length) == PSA_SUCCESS );
+
+ temp = output2_length ;
+
+ TEST_ASSERT( psa_cipher_update( &operation2, output1 + first_part_size,
+ output1_length - first_part_size,
+ output2, output2_size,
+ &output2_length) == PSA_SUCCESS );
+
+ output2_length += temp;
tmp_output_length = 0;
TEST_ASSERT( psa_cipher_finish( &operation2, output2 + output2_length,
- output2_size, &tmp_output_length) == PSA_SUCCESS );
+ output2_size - output2_length, &tmp_output_length) == PSA_SUCCESS );
output2_length += tmp_output_length;
-
+
TEST_ASSERT( psa_cipher_abort( &operation1 ) == PSA_SUCCESS );
- TEST_ASSERT( input_size == output1_length );
- TEST_ASSERT( output1_length == output2_length );
+ TEST_ASSERT( input_size == output2_length );
TEST_ASSERT( memcmp( input, output2, input_size ) == 0 );
exit:
mbedtls_free( key );
mbedtls_free( input );
+ mbedtls_free( output1 );
+ mbedtls_free( output2 );
psa_destroy_key( key_slot );
mbedtls_psa_crypto_free( );
}
/* END_CASE */
+
/* BEGIN_CASE */
void signature_size( int type_arg, int bits, int alg_arg, int expected_size_arg )
{