Merge remote-tracking branch 'psa/psa-wrapper-apis-march-12' into feature-psa
diff --git a/include/psa/crypto.h b/include/psa/crypto.h
index c8a05a4..975edb4 100755
--- a/include/psa/crypto.h
+++ b/include/psa/crypto.h
@@ -322,6 +322,10 @@
#define PSA_ALG_CTR ((psa_algorithm_t)0x04800001)
#define PSA_ALG_ARC4 ((psa_algorithm_t)0x04800002)
+#define PSA_ALG_IS_STREAM_CIPHER(alg) \
+ (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_CIPHER_SUBCATEGORY_MASK)) == \
+ PSA_ALG_STREAM_CIPHER)
+
#define PSA_ALG_CCM ((psa_algorithm_t)0x06000001)
#define PSA_ALG_GCM ((psa_algorithm_t)0x06000002)
@@ -1060,12 +1064,15 @@
psa_status_t psa_cipher_update(psa_cipher_operation_t *operation,
const uint8_t *input,
- size_t input_length);
+ size_t input_length,
+ unsigned char *output,
+ size_t output_size,
+ size_t *output_length);
psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation,
- uint8_t *mac,
- size_t mac_size,
- size_t *mac_length);
+ uint8_t *output,
+ size_t output_size,
+ size_t *output_length);
psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation);
diff --git a/include/psa/crypto_struct.h b/include/psa/crypto_struct.h
index eba4862..639c15e 100644
--- a/include/psa/crypto_struct.h
+++ b/include/psa/crypto_struct.h
@@ -101,12 +101,13 @@
{
psa_algorithm_t alg;
int key_set : 1;
+ int iv_required : 1;
int iv_set : 1;
uint8_t iv_size;
uint8_t block_size;
union
{
- unsigned dummy; /* Make the union non-empty even with no supported algorithms. */
+ mbedtls_cipher_context_t cipher;
} ctx;
};
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index 0082772..438f0f0 100755
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -301,8 +301,6 @@
}
}
-
-
/****************************************************************/
/* Key management */
/****************************************************************/
@@ -920,7 +918,9 @@
if( PSA_ALG_IS_CIPHER( alg ) || PSA_ALG_IS_AEAD( alg ) )
{
if( PSA_ALG_IS_BLOCK_CIPHER( alg ) )
- alg &= ~PSA_ALG_BLOCK_CIPHER_MODE_MASK;
+ {
+ alg &= ~PSA_ALG_BLOCK_CIPHER_PADDING_MASK;
+ }
switch( alg )
{
case PSA_ALG_STREAM_CIPHER:
@@ -996,11 +996,13 @@
#endif /* MBEDTLS_MD_C */
return( PSA_ERROR_NOT_SUPPORTED );
}
+
operation->alg = 0;
operation->key_set = 0;
operation->iv_set = 0;
operation->iv_required = 0;
operation->has_input = 0;
+
return( PSA_SUCCESS );
}
@@ -1378,6 +1380,269 @@
}
+/****************************************************************/
+/* Symmetric cryptography */
+/****************************************************************/
+
+static psa_status_t psa_cipher_setup( psa_cipher_operation_t *operation,
+ psa_key_slot_t key,
+ psa_algorithm_t alg,
+ mbedtls_operation_t cipher_operation )
+{
+ int ret = MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+ psa_status_t status;
+ key_slot_t *slot;
+ psa_key_type_t key_type;
+ size_t key_bits;
+ const mbedtls_cipher_info_t *cipher_info = NULL;
+
+ operation->alg = alg;
+ operation->key_set = 0;
+ operation->iv_set = 0;
+ operation->iv_required = 1;
+ operation->iv_size = 0;
+ operation->block_size = 0;
+
+ status = psa_get_key_information( key, &key_type, &key_bits );
+ if( status != PSA_SUCCESS )
+ return( status );
+ slot = &global_data.key_slots[key];
+
+ cipher_info = mbedtls_cipher_info_from_psa( alg, key_type, key_bits );
+ if( cipher_info == NULL )
+ return( PSA_ERROR_NOT_SUPPORTED );
+
+ mbedtls_cipher_init( &operation->ctx.cipher );
+ ret = mbedtls_cipher_setup( &operation->ctx.cipher, cipher_info );
+ if( ret != 0 )
+ {
+ psa_cipher_abort( operation );
+ return( mbedtls_to_psa_error( ret ) );
+ }
+
+ ret = mbedtls_cipher_setkey( &operation->ctx.cipher, slot->data.raw.data,
+ key_bits, cipher_operation );
+ if( ret != 0 )
+ {
+ psa_cipher_abort( operation );
+ return( mbedtls_to_psa_error( ret ) );
+ }
+
+#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
+ if( ( alg & ~PSA_ALG_BLOCK_CIPHER_PADDING_MASK ) == PSA_ALG_CBC_BASE )
+ {
+ psa_algorithm_t padding_mode = alg & PSA_ALG_BLOCK_CIPHER_PADDING_MASK;
+ mbedtls_cipher_padding_t mode;
+
+ switch ( padding_mode )
+ {
+ case PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:
+ mode = MBEDTLS_PADDING_PKCS7;
+ break;
+ case PSA_ALG_BLOCK_CIPHER_PAD_NONE:
+ mode = MBEDTLS_PADDING_NONE;
+ break;
+ default:
+ psa_cipher_abort( operation );
+ return( PSA_ERROR_INVALID_ARGUMENT );
+ }
+ ret = mbedtls_cipher_set_padding_mode( &operation->ctx.cipher, mode );
+ if( ret != 0 )
+ {
+ psa_cipher_abort( operation );
+ return( mbedtls_to_psa_error( ret ) );
+ }
+ }
+#endif //MBEDTLS_CIPHER_MODE_WITH_PADDING
+
+ operation->key_set = 1;
+ operation->alg = alg;
+ operation->block_size = ( PSA_ALG_IS_BLOCK_CIPHER( alg ) ?
+ PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type ) :
+ 1 );
+ if( PSA_ALG_IS_BLOCK_CIPHER( alg ) || ( alg == PSA_ALG_CTR ) )
+ {
+ operation->iv_size = PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type );
+ }
+
+ return( PSA_SUCCESS );
+}
+
+psa_status_t psa_encrypt_setup( psa_cipher_operation_t *operation,
+ psa_key_slot_t key,
+ psa_algorithm_t alg )
+{
+ return psa_cipher_setup( operation, key, alg, MBEDTLS_ENCRYPT );
+}
+
+psa_status_t psa_decrypt_setup( psa_cipher_operation_t *operation,
+ psa_key_slot_t key,
+ psa_algorithm_t alg )
+{
+ return psa_cipher_setup( operation, key, alg, MBEDTLS_DECRYPT );
+}
+
+psa_status_t psa_encrypt_generate_iv( psa_cipher_operation_t *operation,
+ unsigned char *iv,
+ size_t iv_size,
+ size_t *iv_length )
+{
+ int ret = PSA_SUCCESS;
+ if( operation->iv_set || !( operation->iv_required ) )
+ return( PSA_ERROR_BAD_STATE );
+ if( iv_size < operation->iv_size )
+ {
+ ret = PSA_ERROR_BUFFER_TOO_SMALL;
+ goto exit;
+ }
+ ret = mbedtls_ctr_drbg_random( &global_data.ctr_drbg,
+ iv, operation->iv_size );
+ if( ret != 0 )
+ {
+ ret = mbedtls_to_psa_error( ret );
+ goto exit;
+ }
+
+ *iv_length = operation->iv_size;
+ ret = psa_encrypt_set_iv( operation, iv, *iv_length );
+
+exit:
+ if( ret != PSA_SUCCESS )
+ psa_cipher_abort( operation );
+ return( ret );
+}
+
+psa_status_t psa_encrypt_set_iv( psa_cipher_operation_t *operation,
+ const unsigned char *iv,
+ size_t iv_length )
+{
+ int ret = PSA_SUCCESS;
+ if( operation->iv_set || !( operation->iv_required ) )
+ return( PSA_ERROR_BAD_STATE );
+ if( iv_length != operation->iv_size )
+ {
+ psa_cipher_abort( operation );
+ return( PSA_ERROR_INVALID_ARGUMENT );
+ }
+ ret = mbedtls_cipher_set_iv( &operation->ctx.cipher, iv, iv_length );
+ if( ret != 0 )
+ {
+ psa_cipher_abort( operation );
+ return( mbedtls_to_psa_error( ret ) );
+ }
+
+ operation->iv_set = 1;
+
+ return( PSA_SUCCESS );
+}
+
+psa_status_t psa_cipher_update( psa_cipher_operation_t *operation,
+ const uint8_t *input,
+ size_t input_length,
+ unsigned char *output,
+ size_t output_size,
+ size_t *output_length )
+{
+ int ret = MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+ size_t expected_output_size;
+ if( PSA_ALG_IS_BLOCK_CIPHER( operation->alg ) )
+ {
+ /* Take the unprocessed partial block left over from previous
+ * update calls, if any, plus the input to this call. Remove
+ * the last partial block, if any. You get the data that will be
+ * output in this call. */
+ expected_output_size =
+ ( operation->ctx.cipher.unprocessed_len + input_length )
+ / operation->block_size * operation->block_size;
+ }
+ else
+ {
+ expected_output_size = input_length;
+ }
+ if( output_size < expected_output_size )
+ return( PSA_ERROR_BUFFER_TOO_SMALL );
+
+ ret = mbedtls_cipher_update( &operation->ctx.cipher, input,
+ input_length, output, output_length );
+ if( ret != 0 )
+ {
+ psa_cipher_abort( operation );
+ return( mbedtls_to_psa_error( ret ) );
+ }
+
+ return( PSA_SUCCESS );
+}
+
+psa_status_t psa_cipher_finish( psa_cipher_operation_t *operation,
+ uint8_t *output,
+ size_t output_size,
+ size_t *output_length )
+{
+ int ret = MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+ uint8_t temp_output_buffer[MBEDTLS_MAX_BLOCK_LENGTH];
+
+ if( ! operation->key_set )
+ {
+ psa_cipher_abort( operation );
+ return( PSA_ERROR_BAD_STATE );
+ }
+ if( operation->iv_required && ! operation->iv_set )
+ {
+ psa_cipher_abort( operation );
+ return( PSA_ERROR_BAD_STATE );
+ }
+ if( operation->ctx.cipher.operation == MBEDTLS_ENCRYPT &&
+ PSA_ALG_IS_BLOCK_CIPHER( operation->alg ) )
+ {
+ psa_algorithm_t padding_mode =
+ operation->alg & PSA_ALG_BLOCK_CIPHER_PADDING_MASK;
+ if( operation->ctx.cipher.unprocessed_len >= operation->block_size )
+ {
+ psa_cipher_abort( operation );
+ return( PSA_ERROR_TAMPERING_DETECTED );
+ }
+ if( padding_mode == PSA_ALG_BLOCK_CIPHER_PAD_NONE )
+ {
+ if( operation->ctx.cipher.unprocessed_len != 0 )
+ {
+ psa_cipher_abort( operation );
+ return( PSA_ERROR_INVALID_ARGUMENT );
+ }
+ }
+ }
+
+ ret = mbedtls_cipher_finish( &operation->ctx.cipher, temp_output_buffer,
+ output_length );
+ if( ret != 0 )
+ {
+ psa_cipher_abort( operation );
+ return( mbedtls_to_psa_error( ret ) );
+ }
+ if( output_size >= *output_length )
+ memcpy( output, temp_output_buffer, *output_length );
+ else
+ {
+ psa_cipher_abort( operation );
+ return( PSA_ERROR_BUFFER_TOO_SMALL );
+ }
+
+ return( PSA_SUCCESS );
+}
+
+psa_status_t psa_cipher_abort( psa_cipher_operation_t *operation )
+{
+ mbedtls_cipher_free( &operation->ctx.cipher );
+
+ operation->alg = 0;
+ operation->key_set = 0;
+ operation->iv_set = 0;
+ operation->iv_size = 0;
+ operation->block_size = 0;
+ operation->iv_required = 0;
+
+ return( PSA_SUCCESS );
+}
+
/****************************************************************/
/* Key Policy */
diff --git a/tests/suites/test_suite_psa_crypto.data b/tests/suites/test_suite_psa_crypto.data
index 9778a55..2d6db6b 100755
--- a/tests/suites/test_suite_psa_crypto.data
+++ b/tests/suites/test_suite_psa_crypto.data
@@ -69,6 +69,106 @@
depends_on:MBEDTLS_CMAC_C:MBEDTLS_AES_C
mac_verify:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":PSA_ALG_CMAC:"":"6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411":"dfa66747de9ae63030ca32611497c827"
+PSA Symmetric encryption: AES-CBC-nopad, 16 bytes, good
+depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
+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_encrypt:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a":"a076ec9dfbe47d52afc357336f20743bca7e8a15dc3c776436314293031cd4f3":PSA_SUCCESS
+
+PSA Symmetric encryption: AES-CBC-PKCS#7, 15 bytes, good
+depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
+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_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_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_encrypt:PSA_ALG_CTR | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e11739317":"8f9408fe80a81d3e813da3c7b0b2bd":PSA_SUCCESS
+
+PSA Symmetric decryption: AES-CBC-nopad, 16 bytes, good
+depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
+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, 16 bytes, good
+depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
+cipher_decrypt:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"a076ec9dfbe47d52afc357336f20743bca7e8a15dc3c776436314293031cd4f3":"6bc1bee22e409f96e93d7e117393172a":PSA_SUCCESS
+
+PSA Symmetric decryption: AES-CBC-PKCS#7, 15 bytes, good
+depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
+cipher_decrypt:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6279b49d7f7a8dd87b685175d4276e24":"6bc1bee22e409f96e93d7e11739317":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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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
@@ -105,7 +205,7 @@
sign_fail:PSA_KEY_TYPE_RSA_KEYPAIR:"3082025e02010002818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc3020301000102818100874bf0ffc2f2a71d14671ddd0171c954d7fdbf50281e4f6d99ea0e1ebcf82faa58e7b595ffb293d1abe17f110b37c48cc0f36c37e84d876621d327f64bbe08457d3ec4098ba2fa0a319fba411c2841ed7be83196a8cdf9daa5d00694bc335fc4c32217fe0488bce9cb7202e59468b1ead119000477db2ca797fac19eda3f58c1024100e2ab760841bb9d30a81d222de1eb7381d82214407f1b975cbbfe4e1a9467fd98adbd78f607836ca5be1928b9d160d97fd45c12d6b52e2c9871a174c66b488113024100c5ab27602159ae7d6f20c3c2ee851e46dc112e689e28d5fcbbf990a99ef8a90b8bb44fd36467e7fc1789ceb663abda338652c3c73f111774902e840565927091024100b6cdbd354f7df579a63b48b3643e353b84898777b48b15f94e0bfc0567a6ae5911d57ad6409cf7647bf96264e9bd87eb95e263b7110b9a1f9f94acced0fafa4d024071195eec37e8d257decfc672b07ae639f10cbb9b0c739d0c809968d644a94e3fd6ed9287077a14583f379058f76a8aecd43c62dc8c0f41766650d725275ac4a1024100bb32d133edc2e048d463388b7be9cb4be29f4b6250be603e70e3647501c97ddde20a4e71be95fd5e71784e25aca4baf25be5738aae59bbfe1c997781447a2b24":PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256):"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad":127:PSA_ERROR_BUFFER_TOO_SMALL
PSA Key Policy set and get
-key_policy:PSA_KEY_USAGE_ENCRYPT:PSA_ALG_CBC_BASE
+key_policy:PSA_KEY_USAGE_ENCRYPT:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE
PSA Key Policy enforcement - export
key_policy_fail:PSA_KEY_USAGE_EXPORT:PSA_ALG_RSA_PKCS1V15_SIGN_RAW:PSA_ERROR_NOT_PERMITTED:"3082025e02010002818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc3020301000102818100874bf0ffc2f2a71d14671ddd0171c954d7fdbf50281e4f6d99ea0e1ebcf82faa58e7b595ffb293d1abe17f110b37c48cc0f36c37e84d876621d327f64bbe08457d3ec4098ba2fa0a319fba411c2841ed7be83196a8cdf9daa5d00694bc335fc4c32217fe0488bce9cb7202e59468b1ead119000477db2ca797fac19eda3f58c1024100e2ab760841bb9d30a81d222de1eb7381d82214407f1b975cbbfe4e1a9467fd98adbd78f607836ca5be1928b9d160d97fd45c12d6b52e2c9871a174c66b488113024100c5ab27602159ae7d6f20c3c2ee851e46dc112e689e28d5fcbbf990a99ef8a90b8bb44fd36467e7fc1789ceb663abda338652c3c73f111774902e840565927091024100b6cdbd354f7df579a63b48b3643e353b84898777b48b15f94e0bfc0567a6ae5911d57ad6409cf7647bf96264e9bd87eb95e263b7110b9a1f9f94acced0fafa4d024071195eec37e8d257decfc672b07ae639f10cbb9b0c739d0c809968d644a94e3fd6ed9287077a14583f379058f76a8aecd43c62dc8c0f41766650d725275ac4a1024100bb32d133edc2e048d463388b7be9cb4be29f4b6250be603e70e3647501c97ddde20a4e71be95fd5e71784e25aca4baf25be5738aae59bbfe1c997781447a2b24"
diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function
index 49fcb36..68bddd9 100755
--- a/tests/suites/test_suite_psa_crypto.function
+++ b/tests/suites/test_suite_psa_crypto.function
@@ -334,6 +334,501 @@
}
/* END_CASE */
+
+/* BEGIN_CASE */
+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;
+ size_t total_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 );
+ total_output_length += function_output_length;
+ status = psa_cipher_finish( &operation,
+ output + function_output_length,
+ output_buffer_size,
+ &function_output_length );
+ total_output_length += 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( total_output_length == 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_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;
+ size_t total_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 );
+ total_output_length += function_output_length;
+ TEST_ASSERT( psa_cipher_update( &operation,
+ input + first_part_size,
+ input_size - first_part_size,
+ output, output_buffer_size,
+ &function_output_length ) == PSA_SUCCESS );
+ total_output_length += function_output_length;
+ TEST_ASSERT( psa_cipher_finish( &operation,
+ output + function_output_length,
+ output_buffer_size,
+ &function_output_length ) == PSA_SUCCESS );
+ total_output_length += function_output_length;
+ TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS );
+
+ TEST_ASSERT( total_output_length == 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;
+ size_t total_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 );
+ total_output_length += function_output_length;
+ TEST_ASSERT( psa_cipher_update( &operation,
+ input + first_part_size,
+ input_size - first_part_size,
+ output, output_buffer_size,
+ &function_output_length ) == PSA_SUCCESS );
+ total_output_length += function_output_length;
+ TEST_ASSERT( psa_cipher_finish( &operation,
+ output + function_output_length,
+ output_buffer_size,
+ &function_output_length ) == PSA_SUCCESS );
+ total_output_length += function_output_length;
+ TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS );
+
+ TEST_ASSERT( total_output_length == 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;
+ size_t total_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 );
+ total_output_length += function_output_length;
+ status = psa_cipher_finish( &operation,
+ output + function_output_length,
+ output_buffer_size,
+ &function_output_length );
+ total_output_length += 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( total_output_length == 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_verify_output( int alg_arg, int key_type_arg,
+ char *key_hex,
+ char *input_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};
+ 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 function_output_length = 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( output1 != NULL );
+
+ TEST_ASSERT( psa_cipher_update( &operation1, input, input_size,
+ output1, output1_size,
+ &output1_length ) == PSA_SUCCESS );
+ TEST_ASSERT( psa_cipher_finish( &operation1,
+ output1 + output1_length, output1_size,
+ &function_output_length ) == PSA_SUCCESS );
+
+ output1_length += function_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 );
+ function_output_length = 0;
+ TEST_ASSERT( psa_cipher_finish( &operation2,
+ output2 + output2_length,
+ output2_size,
+ &function_output_length ) == PSA_SUCCESS );
+
+ output2_length += function_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 );
+ psa_destroy_key( key_slot );
+ mbedtls_psa_crypto_free( );
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
+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;
+ 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_buffer_size = 0;
+ size_t output1_length = 0;
+ unsigned char *output2;
+ size_t output2_buffer_size = 0;
+ size_t output2_length = 0;
+ size_t function_output_length;
+ 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_buffer_size = input_size + operation1.block_size;
+ output1 = mbedtls_calloc( 1, output1_buffer_size );
+
+ TEST_ASSERT( (unsigned int) first_part_size < input_size );
+
+ TEST_ASSERT( psa_cipher_update( &operation1, input, first_part_size,
+ output1, output1_buffer_size,
+ &function_output_length ) == PSA_SUCCESS );
+ output1_length += function_output_length;
+
+ TEST_ASSERT( psa_cipher_update( &operation1,
+ input + first_part_size,
+ input_size - first_part_size,
+ output1, output1_buffer_size,
+ &function_output_length ) == PSA_SUCCESS );
+ output1_length += function_output_length;
+
+ TEST_ASSERT( psa_cipher_finish( &operation1,
+ output1 + output1_length,
+ output1_buffer_size - output1_length,
+ &function_output_length ) == PSA_SUCCESS );
+ output1_length += function_output_length;
+
+ TEST_ASSERT( psa_cipher_abort( &operation1 ) == PSA_SUCCESS );
+
+ output2_buffer_size = output1_length;
+ output2 = mbedtls_calloc( 1, output2_buffer_size );
+
+ TEST_ASSERT( psa_encrypt_set_iv( &operation2,
+ iv, iv_length ) == PSA_SUCCESS );
+
+ TEST_ASSERT( psa_cipher_update( &operation2, output1, first_part_size,
+ output2, output2_buffer_size,
+ &function_output_length ) == PSA_SUCCESS );
+ output2_length += function_output_length;
+
+ TEST_ASSERT( psa_cipher_update( &operation2,
+ output1 + first_part_size,
+ output1_length - first_part_size,
+ output2, output2_buffer_size,
+ &function_output_length ) == PSA_SUCCESS );
+ output2_length += function_output_length;
+
+ TEST_ASSERT( psa_cipher_finish( &operation2,
+ output2 + output2_length,
+ output2_buffer_size - output2_length,
+ &function_output_length ) == PSA_SUCCESS );
+ output2_length += function_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 );
+ 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 )
{
@@ -471,7 +966,6 @@
psa_key_policy_t policy_set = {0};
psa_key_policy_t policy_get = {0};
-
memset( key, 0x2a, sizeof( key ) );
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
@@ -495,9 +989,6 @@
TEST_ASSERT( policy_get.usage == policy_set.usage );
TEST_ASSERT( policy_get.alg == policy_set.alg );
-
-
-
exit:
psa_destroy_key( key_slot );
mbedtls_psa_crypto_free( );
@@ -559,21 +1050,29 @@
unsigned char key[32] = {0};
psa_key_lifetime_t lifetime_set = (psa_key_lifetime_t) lifetime_arg;
psa_key_lifetime_t lifetime_get;
+
memset( key, 0x2a, sizeof( key ) );
+
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
+
TEST_ASSERT( psa_set_key_lifetime( key_slot,
lifetime_set ) == PSA_SUCCESS );
+
TEST_ASSERT( psa_import_key( key_slot, key_type,
key, sizeof( key ) ) == PSA_SUCCESS );
+
TEST_ASSERT( psa_get_key_lifetime( key_slot,
&lifetime_get ) == PSA_SUCCESS );
+
TEST_ASSERT( lifetime_get == lifetime_set );
+
exit:
psa_destroy_key( key_slot );
mbedtls_psa_crypto_free( );
}
/* END_CASE */
+
/* BEGIN_CASE */
void key_lifetime_set_fail( int key_slot_arg, int lifetime_arg, int expected_status_arg )
{