Normalize whitespace

Normalize whitespace to Mbed TLS standards. There are only whitespace
changes in this commit.
This commit is contained in:
Gilles Peskine 2018-06-18 15:41:12 +02:00 committed by itayzafrir
parent 6de7a179c8
commit 2d2778650b
4 changed files with 225 additions and 219 deletions

View file

@ -1304,8 +1304,8 @@ psa_status_t psa_encrypt_set_iv(psa_cipher_operation_t *operation,
psa_status_t psa_cipher_update(psa_cipher_operation_t *operation, psa_status_t psa_cipher_update(psa_cipher_operation_t *operation,
const uint8_t *input, const uint8_t *input,
size_t input_length, size_t input_length,
unsigned char *output, unsigned char *output,
size_t output_size, size_t output_size,
size_t *output_length); size_t *output_length);
psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation, psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation,

View file

@ -48,7 +48,7 @@
#if defined(MBEDTLS_SHA512_C) #if defined(MBEDTLS_SHA512_C)
#define PSA_CRYPTO_MD_MAX_SIZE 64 #define PSA_CRYPTO_MD_MAX_SIZE 64
#define PSA_CRYPTO_MD_BLOCK_SIZE 128 #define PSA_CRYPTO_MD_BLOCK_SIZE 128
#else #else
#define PSA_CRYPTO_MD_MAX_SIZE 32 #define PSA_CRYPTO_MD_MAX_SIZE 32
#define PSA_CRYPTO_MD_BLOCK_SIZE 64 #define PSA_CRYPTO_MD_BLOCK_SIZE 64
#endif #endif
@ -84,7 +84,8 @@ struct psa_hash_operation_s
}; };
typedef struct { typedef struct
{
/** The hash context. */ /** The hash context. */
struct psa_hash_operation_s hash_ctx; struct psa_hash_operation_s hash_ctx;
/** The HMAC part of the context. */ /** The HMAC part of the context. */

View file

@ -94,12 +94,15 @@ static inline int safer_memcmp( const uint8_t *a, const uint8_t *b, size_t n )
* The value is a compile-time constant for now, for simplicity. */ * The value is a compile-time constant for now, for simplicity. */
#define MBEDTLS_PSA_KEY_SLOT_COUNT 32 #define MBEDTLS_PSA_KEY_SLOT_COUNT 32
typedef struct { typedef struct
{
psa_key_type_t type; psa_key_type_t type;
psa_key_policy_t policy; psa_key_policy_t policy;
psa_key_lifetime_t lifetime; psa_key_lifetime_t lifetime;
union { union
struct raw_data { {
struct raw_data
{
uint8_t *data; uint8_t *data;
size_t bytes; size_t bytes;
} raw; } raw;
@ -112,7 +115,8 @@ typedef struct {
} data; } data;
} key_slot_t; } key_slot_t;
typedef struct { typedef struct
{
int initialized; int initialized;
mbedtls_entropy_context entropy; mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg; mbedtls_ctr_drbg_context ctr_drbg;
@ -305,10 +309,10 @@ static psa_status_t mbedtls_to_psa_error( int ret )
/* Key management */ /* Key management */
/****************************************************************/ /****************************************************************/
psa_status_t psa_import_key(psa_key_slot_t key, psa_status_t psa_import_key( psa_key_slot_t key,
psa_key_type_t type, psa_key_type_t type,
const uint8_t *data, const uint8_t *data,
size_t data_length) size_t data_length )
{ {
key_slot_t *slot; key_slot_t *slot;
@ -380,7 +384,7 @@ psa_status_t psa_import_key(psa_key_slot_t key,
return( PSA_SUCCESS ); return( PSA_SUCCESS );
} }
psa_status_t psa_destroy_key(psa_key_slot_t key) psa_status_t psa_destroy_key( psa_key_slot_t key )
{ {
key_slot_t *slot; key_slot_t *slot;
@ -424,9 +428,9 @@ psa_status_t psa_destroy_key(psa_key_slot_t key)
return( PSA_SUCCESS ); return( PSA_SUCCESS );
} }
psa_status_t psa_get_key_information(psa_key_slot_t key, psa_status_t psa_get_key_information( psa_key_slot_t key,
psa_key_type_t *type, psa_key_type_t *type,
size_t *bits) size_t *bits )
{ {
key_slot_t *slot; key_slot_t *slot;
@ -472,11 +476,11 @@ psa_status_t psa_get_key_information(psa_key_slot_t key,
return( PSA_SUCCESS ); return( PSA_SUCCESS );
} }
static psa_status_t psa_internal_export_key(psa_key_slot_t key, static psa_status_t psa_internal_export_key( psa_key_slot_t key,
uint8_t *data, uint8_t *data,
size_t data_size, size_t data_size,
size_t *data_length, size_t *data_length,
int export_public_key) int export_public_key )
{ {
key_slot_t *slot; key_slot_t *slot;
@ -492,7 +496,7 @@ static psa_status_t psa_internal_export_key(psa_key_slot_t key,
if( ( !export_public_key ) && ( !( PSA_KEY_TYPE_IS_PUBLIC_KEY( slot->type ) ) ) && if( ( !export_public_key ) && ( !( PSA_KEY_TYPE_IS_PUBLIC_KEY( slot->type ) ) ) &&
( !( slot->policy.usage & PSA_KEY_USAGE_EXPORT ) ) ) ( !( slot->policy.usage & PSA_KEY_USAGE_EXPORT ) ) )
return( PSA_ERROR_NOT_PERMITTED ); return( PSA_ERROR_NOT_PERMITTED );
if( PSA_KEY_TYPE_IS_RAW_BYTES( slot->type ) ) if( PSA_KEY_TYPE_IS_RAW_BYTES( slot->type ) )
{ {
if( slot->data.raw.bytes > data_size ) if( slot->data.raw.bytes > data_size )
@ -542,23 +546,23 @@ static psa_status_t psa_internal_export_key(psa_key_slot_t key,
} }
} }
psa_status_t psa_export_key(psa_key_slot_t key, psa_status_t psa_export_key( psa_key_slot_t key,
uint8_t *data, uint8_t *data,
size_t data_size, size_t data_size,
size_t *data_length) size_t *data_length )
{ {
return psa_internal_export_key( key, data, data_size, return psa_internal_export_key( key, data, data_size,
data_length, 0 ); data_length, 0 );
} }
psa_status_t psa_export_public_key(psa_key_slot_t key, psa_status_t psa_export_public_key( psa_key_slot_t key,
uint8_t *data, uint8_t *data,
size_t data_size, size_t data_size,
size_t *data_length) size_t *data_length )
{ {
return psa_internal_export_key( key, data, data_size, return psa_internal_export_key( key, data, data_size,
data_length, 1 ); data_length, 1 );
} }
/****************************************************************/ /****************************************************************/
@ -884,9 +888,9 @@ psa_status_t psa_hash_finish( psa_hash_operation_t *operation,
} }
} }
psa_status_t psa_hash_verify(psa_hash_operation_t *operation, psa_status_t psa_hash_verify( psa_hash_operation_t *operation,
const uint8_t *hash, const uint8_t *hash,
size_t hash_length) size_t hash_length )
{ {
uint8_t actual_hash[MBEDTLS_MD_MAX_SIZE]; uint8_t actual_hash[MBEDTLS_MD_MAX_SIZE];
size_t actual_hash_length; size_t actual_hash_length;
@ -912,7 +916,7 @@ psa_status_t psa_hash_verify(psa_hash_operation_t *operation,
static const mbedtls_cipher_info_t *mbedtls_cipher_info_from_psa( static const mbedtls_cipher_info_t *mbedtls_cipher_info_from_psa(
psa_algorithm_t alg, psa_algorithm_t alg,
psa_key_type_t key_type, psa_key_type_t key_type,
size_t key_bits, size_t key_bits,
mbedtls_cipher_id_t* cipher_id ) mbedtls_cipher_id_t* cipher_id )
{ {
mbedtls_cipher_mode_t mode; mbedtls_cipher_mode_t mode;
@ -987,7 +991,7 @@ static const mbedtls_cipher_info_t *mbedtls_cipher_info_from_psa(
static size_t psa_get_hash_block_size( psa_algorithm_t alg ) static size_t psa_get_hash_block_size( psa_algorithm_t alg )
{ {
switch(alg) switch( alg )
{ {
case PSA_ALG_MD2: case PSA_ALG_MD2:
return( 16 ); return( 16 );
@ -1006,9 +1010,9 @@ static size_t psa_get_hash_block_size( psa_algorithm_t alg )
case PSA_ALG_SHA_384: case PSA_ALG_SHA_384:
return( 128 ); return( 128 );
case PSA_ALG_SHA_512: case PSA_ALG_SHA_512:
return ( 128 ); return( 128 );
default: default:
return ( 0 ); return( 0 );
} }
} }
@ -1032,8 +1036,7 @@ psa_status_t psa_mac_abort( psa_mac_operation_t *operation )
return( PSA_ERROR_NOT_SUPPORTED ); return( PSA_ERROR_NOT_SUPPORTED );
psa_hash_abort( &operation->ctx.hmac.hash_ctx ); psa_hash_abort( &operation->ctx.hmac.hash_ctx );
mbedtls_zeroize( operation->ctx.hmac.opad, mbedtls_zeroize( operation->ctx.hmac.opad, block_size );
block_size);
} }
else else
#endif /* MBEDTLS_MD_C */ #endif /* MBEDTLS_MD_C */
@ -1241,7 +1244,7 @@ psa_status_t psa_mac_update( psa_mac_operation_t *operation,
if( PSA_ALG_IS_HMAC( operation->alg ) ) if( PSA_ALG_IS_HMAC( operation->alg ) )
{ {
status = psa_hash_update( &operation->ctx.hmac.hash_ctx, input, status = psa_hash_update( &operation->ctx.hmac.hash_ctx, input,
input_length ); input_length );
} }
else else
#endif /* MBEDTLS_MD_C */ #endif /* MBEDTLS_MD_C */
@ -1250,10 +1253,10 @@ psa_status_t psa_mac_update( psa_mac_operation_t *operation,
} }
break; break;
} }
if ( ( ret != 0 ) || ( status != PSA_SUCCESS ) ) if( ( ret != 0 ) || ( status != PSA_SUCCESS ) )
{ {
psa_mac_abort( operation ); psa_mac_abort( operation );
if ( ret != 0 ) if( ret != 0 )
status = mbedtls_to_psa_error( ret ); status = mbedtls_to_psa_error( ret );
} }
@ -1261,9 +1264,9 @@ psa_status_t psa_mac_update( psa_mac_operation_t *operation,
} }
static psa_status_t psa_mac_finish_internal( psa_mac_operation_t *operation, static psa_status_t psa_mac_finish_internal( psa_mac_operation_t *operation,
uint8_t *mac, uint8_t *mac,
size_t mac_size, size_t mac_size,
size_t *mac_length ) size_t *mac_length )
{ {
int ret = 0; int ret = 0;
psa_status_t status = PSA_SUCCESS; psa_status_t status = PSA_SUCCESS;
@ -1296,7 +1299,7 @@ static psa_status_t psa_mac_finish_internal( psa_mac_operation_t *operation,
unsigned char *opad = operation->ctx.hmac.opad; unsigned char *opad = operation->ctx.hmac.opad;
size_t hash_size = 0; size_t hash_size = 0;
size_t block_size = size_t block_size =
psa_get_hash_block_size( ( PSA_ALG_HMAC_HASH( operation->alg ) ) ); psa_get_hash_block_size( ( PSA_ALG_HMAC_HASH( operation->alg ) ) );
if( block_size == 0 ) if( block_size == 0 )
return( PSA_ERROR_NOT_SUPPORTED ); return( PSA_ERROR_NOT_SUPPORTED );
@ -1318,7 +1321,7 @@ static psa_status_t psa_mac_finish_internal( psa_mac_operation_t *operation,
goto hmac_cleanup; goto hmac_cleanup;
status = psa_hash_update( &operation->ctx.hmac.hash_ctx, tmp, status = psa_hash_update( &operation->ctx.hmac.hash_ctx, tmp,
hash_size); hash_size );
if( status != PSA_SUCCESS ) if( status != PSA_SUCCESS )
goto hmac_cleanup; goto hmac_cleanup;
@ -1336,7 +1339,7 @@ static psa_status_t psa_mac_finish_internal( psa_mac_operation_t *operation,
} }
cleanup: cleanup:
if( ( ret == 0 ) && (status == PSA_SUCCESS) ) if( ( ret == 0 ) && ( status == PSA_SUCCESS ) )
{ {
return( psa_mac_abort( operation ) ); return( psa_mac_abort( operation ) );
} }
@ -1344,7 +1347,7 @@ cleanup:
{ {
psa_mac_abort( operation ); psa_mac_abort( operation );
if( ret != 0 ) if( ret != 0 )
status = mbedtls_to_psa_error(ret); status = mbedtls_to_psa_error( ret );
return status; return status;
} }
@ -1362,9 +1365,9 @@ psa_status_t psa_mac_finish( psa_mac_operation_t *operation,
mac_size, mac_length ) ); mac_size, mac_length ) );
} }
#define MBEDTLS_PSA_MAC_MAX_SIZE \ #define MBEDTLS_PSA_MAC_MAX_SIZE \
( MBEDTLS_MD_MAX_SIZE > MBEDTLS_MAX_BLOCK_LENGTH ? \ ( MBEDTLS_MD_MAX_SIZE > MBEDTLS_MAX_BLOCK_LENGTH ? \
MBEDTLS_MD_MAX_SIZE : \ MBEDTLS_MD_MAX_SIZE : \
MBEDTLS_MAX_BLOCK_LENGTH ) MBEDTLS_MAX_BLOCK_LENGTH )
psa_status_t psa_mac_verify( psa_mac_operation_t *operation, psa_status_t psa_mac_verify( psa_mac_operation_t *operation,
const uint8_t *mac, const uint8_t *mac,
@ -1598,7 +1601,7 @@ psa_status_t psa_asymmetric_verify( psa_key_slot_t key,
{ {
mbedtls_ecp_keypair *ecdsa = slot->data.ecp; mbedtls_ecp_keypair *ecdsa = slot->data.ecp;
int ret; int ret;
(void)alg; (void) alg;
ret = mbedtls_ecdsa_read_signature( ecdsa, hash, hash_length, ret = mbedtls_ecdsa_read_signature( ecdsa, hash, hash_length,
signature, signature_size ); signature, signature_size );
return( mbedtls_to_psa_error( ret ) ); return( mbedtls_to_psa_error( ret ) );
@ -2015,31 +2018,31 @@ psa_status_t psa_cipher_abort( psa_cipher_operation_t *operation )
/* Key Policy */ /* Key Policy */
/****************************************************************/ /****************************************************************/
void psa_key_policy_init(psa_key_policy_t *policy) void psa_key_policy_init( psa_key_policy_t *policy )
{ {
memset( policy, 0, sizeof( psa_key_policy_t ) ); memset( policy, 0, sizeof( psa_key_policy_t ) );
} }
void psa_key_policy_set_usage(psa_key_policy_t *policy, void psa_key_policy_set_usage( psa_key_policy_t *policy,
psa_key_usage_t usage, psa_key_usage_t usage,
psa_algorithm_t alg) psa_algorithm_t alg )
{ {
policy->usage = usage; policy->usage = usage;
policy->alg = alg; policy->alg = alg;
} }
psa_key_usage_t psa_key_policy_get_usage(psa_key_policy_t *policy) psa_key_usage_t psa_key_policy_get_usage( psa_key_policy_t *policy )
{ {
return( policy->usage ); return( policy->usage );
} }
psa_algorithm_t psa_key_policy_get_algorithm(psa_key_policy_t *policy) psa_algorithm_t psa_key_policy_get_algorithm( psa_key_policy_t *policy )
{ {
return( policy->alg ); return( policy->alg );
} }
psa_status_t psa_set_key_policy(psa_key_slot_t key, psa_status_t psa_set_key_policy( psa_key_slot_t key,
const psa_key_policy_t *policy) const psa_key_policy_t *policy )
{ {
key_slot_t *slot; key_slot_t *slot;
@ -2051,8 +2054,8 @@ psa_status_t psa_set_key_policy(psa_key_slot_t key,
return( PSA_ERROR_OCCUPIED_SLOT ); return( PSA_ERROR_OCCUPIED_SLOT );
if( ( policy->usage & ~( PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT if( ( policy->usage & ~( PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT
| PSA_KEY_USAGE_DECRYPT | PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_DECRYPT | PSA_KEY_USAGE_SIGN
| PSA_KEY_USAGE_VERIFY ) ) != 0 ) | PSA_KEY_USAGE_VERIFY ) ) != 0 )
return( PSA_ERROR_INVALID_ARGUMENT ); return( PSA_ERROR_INVALID_ARGUMENT );
slot->policy = *policy; slot->policy = *policy;
@ -2060,8 +2063,8 @@ psa_status_t psa_set_key_policy(psa_key_slot_t key,
return( PSA_SUCCESS ); return( PSA_SUCCESS );
} }
psa_status_t psa_get_key_policy(psa_key_slot_t key, psa_status_t psa_get_key_policy( psa_key_slot_t key,
psa_key_policy_t *policy) psa_key_policy_t *policy )
{ {
key_slot_t *slot; key_slot_t *slot;
@ -2081,8 +2084,8 @@ psa_status_t psa_get_key_policy(psa_key_slot_t key,
/* Key Lifetime */ /* Key Lifetime */
/****************************************************************/ /****************************************************************/
psa_status_t psa_get_key_lifetime(psa_key_slot_t key, psa_status_t psa_get_key_lifetime( psa_key_slot_t key,
psa_key_lifetime_t *lifetime) psa_key_lifetime_t *lifetime )
{ {
key_slot_t *slot; key_slot_t *slot;
@ -2096,8 +2099,8 @@ psa_status_t psa_get_key_lifetime(psa_key_slot_t key,
return( PSA_SUCCESS ); return( PSA_SUCCESS );
} }
psa_status_t psa_set_key_lifetime(psa_key_slot_t key, psa_status_t psa_set_key_lifetime( psa_key_slot_t key,
const psa_key_lifetime_t lifetime) const psa_key_lifetime_t lifetime )
{ {
key_slot_t *slot; key_slot_t *slot;
@ -2146,7 +2149,7 @@ psa_status_t psa_aead_encrypt( psa_key_slot_t key,
size_t tag_length; size_t tag_length;
mbedtls_cipher_id_t cipher_id; mbedtls_cipher_id_t cipher_id;
const mbedtls_cipher_info_t *cipher_info = NULL; const mbedtls_cipher_info_t *cipher_info = NULL;
*ciphertext_length = 0; *ciphertext_length = 0;
status = psa_get_key_information( key, &key_type, &key_bits ); status = psa_get_key_information( key, &key_type, &key_bits );
@ -2154,18 +2157,18 @@ psa_status_t psa_aead_encrypt( psa_key_slot_t key,
return( status ); return( status );
slot = &global_data.key_slots[key]; slot = &global_data.key_slots[key];
if( slot->type == PSA_KEY_TYPE_NONE ) if( slot->type == PSA_KEY_TYPE_NONE )
return( PSA_ERROR_EMPTY_SLOT ); return( PSA_ERROR_EMPTY_SLOT );
cipher_info = mbedtls_cipher_info_from_psa( alg, key_type, cipher_info = mbedtls_cipher_info_from_psa( alg, key_type,
key_bits, &cipher_id ); key_bits, &cipher_id );
if( cipher_info == NULL ) if( cipher_info == NULL )
return( PSA_ERROR_NOT_SUPPORTED ); return( PSA_ERROR_NOT_SUPPORTED );
if( !( slot->policy.usage & PSA_KEY_USAGE_ENCRYPT ) ) if( !( slot->policy.usage & PSA_KEY_USAGE_ENCRYPT ) )
return( PSA_ERROR_NOT_PERMITTED ); return( PSA_ERROR_NOT_PERMITTED );
if ( ( key_type & PSA_KEY_TYPE_CATEGORY_MASK ) != if( ( key_type & PSA_KEY_TYPE_CATEGORY_MASK ) !=
PSA_KEY_TYPE_CATEGORY_SYMMETRIC ) PSA_KEY_TYPE_CATEGORY_SYMMETRIC )
return( PSA_ERROR_INVALID_ARGUMENT ); return( PSA_ERROR_INVALID_ARGUMENT );
if( alg == PSA_ALG_GCM ) if( alg == PSA_ALG_GCM )
@ -2238,13 +2241,13 @@ psa_status_t psa_aead_encrypt( psa_key_slot_t key,
{ {
return( PSA_ERROR_NOT_SUPPORTED ); return( PSA_ERROR_NOT_SUPPORTED );
} }
if( ret != 0 ) if( ret != 0 )
{ {
memset( ciphertext, 0, ciphertext_size ); memset( ciphertext, 0, ciphertext_size );
return( mbedtls_to_psa_error( ret ) ); return( mbedtls_to_psa_error( ret ) );
} }
*ciphertext_length = plaintext_length + tag_length; *ciphertext_length = plaintext_length + tag_length;
return( PSA_SUCCESS ); return( PSA_SUCCESS );
} }
@ -2291,7 +2294,7 @@ psa_status_t psa_aead_decrypt( psa_key_slot_t key,
size_t tag_length; size_t tag_length;
mbedtls_cipher_id_t cipher_id; mbedtls_cipher_id_t cipher_id;
const mbedtls_cipher_info_t *cipher_info = NULL; const mbedtls_cipher_info_t *cipher_info = NULL;
*plaintext_length = 0; *plaintext_length = 0;
status = psa_get_key_information( key, &key_type, &key_bits ); status = psa_get_key_information( key, &key_type, &key_bits );
@ -2299,18 +2302,18 @@ psa_status_t psa_aead_decrypt( psa_key_slot_t key,
return( status ); return( status );
slot = &global_data.key_slots[key]; slot = &global_data.key_slots[key];
if( slot->type == PSA_KEY_TYPE_NONE ) if( slot->type == PSA_KEY_TYPE_NONE )
return( PSA_ERROR_EMPTY_SLOT ); return( PSA_ERROR_EMPTY_SLOT );
cipher_info = mbedtls_cipher_info_from_psa( alg, key_type, cipher_info = mbedtls_cipher_info_from_psa( alg, key_type,
key_bits, &cipher_id ); key_bits, &cipher_id );
if( cipher_info == NULL ) if( cipher_info == NULL )
return( PSA_ERROR_NOT_SUPPORTED ); return( PSA_ERROR_NOT_SUPPORTED );
if( !( slot->policy.usage & PSA_KEY_USAGE_DECRYPT ) ) if( !( slot->policy.usage & PSA_KEY_USAGE_DECRYPT ) )
return( PSA_ERROR_NOT_PERMITTED ); return( PSA_ERROR_NOT_PERMITTED );
if ( ( key_type & PSA_KEY_TYPE_CATEGORY_MASK ) != if( ( key_type & PSA_KEY_TYPE_CATEGORY_MASK ) !=
PSA_KEY_TYPE_CATEGORY_SYMMETRIC ) PSA_KEY_TYPE_CATEGORY_SYMMETRIC )
return( PSA_ERROR_INVALID_ARGUMENT ); return( PSA_ERROR_INVALID_ARGUMENT );
if( alg == PSA_ALG_GCM ) if( alg == PSA_ALG_GCM )

View file

@ -4,9 +4,9 @@
#include "mbedtls/md.h" #include "mbedtls/md.h"
#if(UINT32_MAX > SIZE_MAX) #if(UINT32_MAX > SIZE_MAX)
#define PSA_CRYPTO_TEST_SIZE_T_RANGE(x) ((x) <= SIZE_MAX) #define PSA_CRYPTO_TEST_SIZE_T_RANGE( x ) ( ( x ) <= SIZE_MAX )
#else #else
#define PSA_CRYPTO_TEST_SIZE_T_RANGE(x) 1 #define PSA_CRYPTO_TEST_SIZE_T_RANGE( x ) 1
#endif #endif
/* END_HEADER */ /* END_HEADER */
@ -16,7 +16,7 @@
*/ */
/* BEGIN_CASE */ /* BEGIN_CASE */
void init_deinit() void init_deinit( )
{ {
psa_status_t status; psa_status_t status;
int i; int i;
@ -148,11 +148,11 @@ exit:
/* BEGIN_CASE */ /* BEGIN_CASE */
void import_export_public_key( data_t *data, void import_export_public_key( data_t *data,
int type_arg, int type_arg,
int alg_arg, int alg_arg,
int expected_bits, int expected_bits,
int public_key_expected_length, int public_key_expected_length,
int expected_export_status ) int expected_export_status )
{ {
int slot = 1; int slot = 1;
psa_key_type_t type = type_arg; psa_key_type_t type = type_arg;
@ -182,18 +182,18 @@ void import_export_public_key( data_t *data,
/* Import the key */ /* Import the key */
TEST_ASSERT( psa_import_key( slot, type, TEST_ASSERT( psa_import_key( slot, type,
data->x, (size_t) data->len ) == data->x, (size_t) data->len ) ==
PSA_SUCCESS ); PSA_SUCCESS );
/* Test the key information */ /* Test the key information */
TEST_ASSERT( psa_get_key_information( slot, TEST_ASSERT( psa_get_key_information( slot,
&got_type, &got_bits ) == PSA_SUCCESS ); &got_type, &got_bits ) == PSA_SUCCESS );
TEST_ASSERT( got_type == type ); TEST_ASSERT( got_type == type );
TEST_ASSERT( got_bits == (size_t) expected_bits ); TEST_ASSERT( got_bits == (size_t) expected_bits );
/* Export the key */ /* Export the key */
status = psa_export_public_key( slot, status = psa_export_public_key( slot,
exported, export_size, exported, export_size,
&exported_length ); &exported_length );
TEST_ASSERT( status == (psa_status_t) expected_export_status ); TEST_ASSERT( status == (psa_status_t) expected_export_status );
if( status != PSA_SUCCESS ) if( status != PSA_SUCCESS )
goto destroy; goto destroy;
@ -230,7 +230,7 @@ void hash_finish( int alg_arg, data_t *input, data_t *expected_hash )
TEST_ASSERT( psa_hash_start( &operation, alg ) == PSA_SUCCESS ); TEST_ASSERT( psa_hash_start( &operation, alg ) == PSA_SUCCESS );
TEST_ASSERT( psa_hash_update( &operation, TEST_ASSERT( psa_hash_update( &operation,
input->x, (size_t) input->len ) == input->x, (size_t) input->len ) ==
PSA_SUCCESS ); PSA_SUCCESS );
TEST_ASSERT( psa_hash_finish( &operation, TEST_ASSERT( psa_hash_finish( &operation,
actual_hash, sizeof( actual_hash ), actual_hash, sizeof( actual_hash ),
&actual_hash_length ) == PSA_SUCCESS ); &actual_hash_length ) == PSA_SUCCESS );
@ -259,11 +259,11 @@ void hash_verify( int alg_arg, data_t *input, data_t *expected_hash )
TEST_ASSERT( psa_hash_start( &operation, alg ) == PSA_SUCCESS ); TEST_ASSERT( psa_hash_start( &operation, alg ) == PSA_SUCCESS );
TEST_ASSERT( psa_hash_update( &operation, TEST_ASSERT( psa_hash_update( &operation,
input->x, (size_t) input->len ) == input->x, (size_t) input->len ) ==
PSA_SUCCESS ); PSA_SUCCESS );
TEST_ASSERT( psa_hash_verify( &operation, TEST_ASSERT( psa_hash_verify( &operation,
expected_hash->x, expected_hash->x,
(size_t) expected_hash->len ) == (size_t) expected_hash->len ) ==
PSA_SUCCESS ); PSA_SUCCESS );
exit: exit:
mbedtls_psa_crypto_free( ); mbedtls_psa_crypto_free( );
@ -305,7 +305,7 @@ void mac_verify( int key_type_arg, data_t *key,
TEST_ASSERT( psa_destroy_key( key_slot ) == PSA_SUCCESS ); TEST_ASSERT( psa_destroy_key( key_slot ) == PSA_SUCCESS );
TEST_ASSERT( psa_mac_update( &operation, TEST_ASSERT( psa_mac_update( &operation,
input->x, (size_t) input->len ) == input->x, (size_t) input->len ) ==
PSA_SUCCESS ); PSA_SUCCESS );
TEST_ASSERT( psa_mac_verify( &operation, TEST_ASSERT( psa_mac_verify( &operation,
expected_mac->x, expected_mac->x,
(size_t) expected_mac->len ) == PSA_SUCCESS ); (size_t) expected_mac->len ) == PSA_SUCCESS );
@ -441,7 +441,7 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg,
TEST_ASSERT( total_output_length == (size_t) expected_output->len ); TEST_ASSERT( total_output_length == (size_t) expected_output->len );
TEST_ASSERT( memcmp( expected_output->x, output, TEST_ASSERT( memcmp( expected_output->x, output,
(size_t) expected_output->len ) == 0 ); (size_t) expected_output->len ) == 0 );
exit: exit:
mbedtls_free( output ); mbedtls_free( output );
@ -510,8 +510,8 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS ); TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS );
TEST_ASSERT( total_output_length == (size_t) expected_output->len ); TEST_ASSERT( total_output_length == (size_t) expected_output->len );
TEST_ASSERT( memcmp( expected_output->x, output, TEST_ASSERT( memcmp( expected_output->x, output,
(size_t) expected_output->len ) == 0 ); (size_t) expected_output->len ) == 0 );
exit: exit:
mbedtls_free( output ); mbedtls_free( output );
@ -776,8 +776,8 @@ exit:
/* BEGIN_CASE */ /* BEGIN_CASE */
void aead_encrypt_decrypt( int key_type_arg, data_t * key_data, void aead_encrypt_decrypt( int key_type_arg, data_t * key_data,
int alg_arg, data_t * input_data, data_t * nonce, int alg_arg, data_t * input_data, data_t * nonce,
data_t * additional_data, int expected_result_arg ) data_t * additional_data, int expected_result_arg )
{ {
int slot = 1; int slot = 1;
psa_key_type_t key_type = key_type_arg; psa_key_type_t key_type = key_type_arg;
@ -816,13 +816,13 @@ void aead_encrypt_decrypt( int key_type_arg, data_t * key_data,
key_data->x, (size_t) key_data->len ) == PSA_SUCCESS ); key_data->x, (size_t) key_data->len ) == PSA_SUCCESS );
TEST_ASSERT( psa_aead_encrypt( slot, alg, TEST_ASSERT( psa_aead_encrypt( slot, alg,
nonce->x, (size_t) nonce->len, nonce->x, (size_t) nonce->len,
additional_data->x, additional_data->x,
(size_t) additional_data->len, (size_t) additional_data->len,
input_data->x, (size_t) input_data->len, input_data->x, (size_t) input_data->len,
output_data, output_data,
output_size, &output_length ) == output_size, &output_length ) ==
expected_result ); expected_result );
if( PSA_SUCCESS == expected_result ) if( PSA_SUCCESS == expected_result )
{ {
@ -830,18 +830,18 @@ void aead_encrypt_decrypt( int key_type_arg, data_t * key_data,
TEST_ASSERT( output_data2 != NULL ); TEST_ASSERT( output_data2 != NULL );
TEST_ASSERT( psa_aead_decrypt( slot, alg, TEST_ASSERT( psa_aead_decrypt( slot, alg,
nonce->x, (size_t) nonce->len, nonce->x, (size_t) nonce->len,
additional_data->x, additional_data->x,
(size_t) additional_data->len, (size_t) additional_data->len,
output_data, output_length, output_data2, output_data, output_length, output_data2,
output_length, &output_length2 ) == output_length, &output_length2 ) ==
expected_result ); expected_result );
TEST_ASSERT( memcmp( input_data->x, output_data2, TEST_ASSERT( memcmp( input_data->x, output_data2,
(size_t) input_data->len ) == 0 ); (size_t) input_data->len ) == 0 );
} }
exit: exit:
psa_destroy_key( slot ); psa_destroy_key( slot );
@ -853,9 +853,9 @@ exit:
/* BEGIN_CASE */ /* BEGIN_CASE */
void aead_encrypt( int key_type_arg, data_t * key_data, void aead_encrypt( int key_type_arg, data_t * key_data,
int alg_arg, data_t * input_data, int alg_arg, data_t * input_data,
data_t * additional_data, data_t * nonce, data_t * additional_data, data_t * nonce,
data_t * expected_result ) data_t * expected_result )
{ {
int slot = 1; int slot = 1;
psa_key_type_t key_type = key_type_arg; psa_key_type_t key_type = key_type_arg;
@ -880,7 +880,7 @@ void aead_encrypt( int key_type_arg, data_t * key_data,
output_size = (size_t) input_data->len + tag_length; output_size = (size_t) input_data->len + tag_length;
output_data = mbedtls_calloc( 1, output_size ); output_data = mbedtls_calloc( 1, output_size );
TEST_ASSERT( output_data != NULL ); TEST_ASSERT( output_data != NULL );
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
psa_key_policy_init( &policy ); psa_key_policy_init( &policy );
@ -891,20 +891,20 @@ void aead_encrypt( int key_type_arg, data_t * key_data,
TEST_ASSERT( psa_import_key( slot, key_type, TEST_ASSERT( psa_import_key( slot, key_type,
key_data->x, (size_t) key_data->len ) == key_data->x, (size_t) key_data->len ) ==
PSA_SUCCESS ); PSA_SUCCESS );
TEST_ASSERT( psa_aead_encrypt( slot, alg, TEST_ASSERT( psa_aead_encrypt( slot, alg,
nonce->x, (size_t) nonce->len, nonce->x, (size_t) nonce->len,
additional_data->x, additional_data->x,
(size_t) additional_data->len, (size_t) additional_data->len,
input_data->x, (size_t) input_data->len, input_data->x, (size_t) input_data->len,
output_data, output_data,
output_size, &output_length ) == PSA_SUCCESS ); output_size, &output_length ) == PSA_SUCCESS );
TEST_ASSERT( memcmp( output_data, expected_result->x, TEST_ASSERT( memcmp( output_data, expected_result->x,
output_length ) == 0 ); output_length ) == 0 );
exit: exit:
psa_destroy_key( slot ); psa_destroy_key( slot );
@ -915,9 +915,9 @@ exit:
/* BEGIN_CASE */ /* BEGIN_CASE */
void aead_decrypt( int key_type_arg, data_t * key_data, void aead_decrypt( int key_type_arg, data_t * key_data,
int alg_arg, data_t * input_data, int alg_arg, data_t * input_data,
data_t * additional_data, data_t * nonce, data_t * additional_data, data_t * nonce,
data_t * expected_data, int expected_result_arg ) data_t * expected_data, int expected_result_arg )
{ {
int slot = 1; int slot = 1;
psa_key_type_t key_type = key_type_arg; psa_key_type_t key_type = key_type_arg;
@ -944,7 +944,7 @@ void aead_decrypt( int key_type_arg, data_t * key_data,
output_size = (size_t) input_data->len + tag_length; output_size = (size_t) input_data->len + tag_length;
output_data = mbedtls_calloc( 1, output_size ); output_data = mbedtls_calloc( 1, output_size );
TEST_ASSERT( output_data != NULL ); TEST_ASSERT( output_data != NULL );
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
psa_key_policy_init( &policy ); psa_key_policy_init( &policy );
@ -955,24 +955,24 @@ void aead_decrypt( int key_type_arg, data_t * key_data,
TEST_ASSERT( psa_import_key( slot, key_type, TEST_ASSERT( psa_import_key( slot, key_type,
key_data->x, (size_t) key_data->len ) == key_data->x, (size_t) key_data->len ) ==
PSA_SUCCESS ); PSA_SUCCESS );
TEST_ASSERT( psa_aead_decrypt( slot, alg, TEST_ASSERT( psa_aead_decrypt( slot, alg,
nonce->x, (size_t) nonce->len, nonce->x, (size_t) nonce->len,
additional_data->x, (size_t) additional_data->len, additional_data->x, (size_t) additional_data->len,
input_data->x, (size_t) input_data->len, input_data->x, (size_t) input_data->len,
output_data, output_data,
output_size, &output_length ) == output_size, &output_length ) ==
expected_result ); expected_result );
if ( expected_result == PSA_SUCCESS ) if( expected_result == PSA_SUCCESS )
{ {
TEST_ASSERT( memcmp( output_data, expected_data->x, TEST_ASSERT( memcmp( output_data, expected_data->x,
output_length ) == 0 ); output_length ) == 0 );
} }
exit: exit:
psa_destroy_key( slot ); psa_destroy_key( slot );
@ -986,7 +986,7 @@ void signature_size( int type_arg, int bits, int alg_arg, int expected_size_arg
{ {
psa_key_type_t type = type_arg; psa_key_type_t type = type_arg;
psa_algorithm_t alg = alg_arg; psa_algorithm_t alg = alg_arg;
size_t actual_size = PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE(type, bits, alg); size_t actual_size = PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE( type, bits, alg );
TEST_ASSERT( actual_size == (size_t) expected_size_arg ); TEST_ASSERT( actual_size == (size_t) expected_size_arg );
exit: exit:
; ;
@ -1039,8 +1039,8 @@ void sign_deterministic( int key_type_arg, data_t *key_data,
signature, signature_size, signature, signature_size,
&signature_length ) == PSA_SUCCESS ); &signature_length ) == PSA_SUCCESS );
TEST_ASSERT( signature_length == (size_t) output_data->len ); TEST_ASSERT( signature_length == (size_t) output_data->len );
TEST_ASSERT( memcmp( signature, output_data->x, (size_t) output_data->len ) TEST_ASSERT( memcmp( signature, output_data->x,
== 0 ); (size_t) output_data->len ) == 0 );
exit: exit:
psa_destroy_key( slot ); psa_destroy_key( slot );
@ -1081,7 +1081,7 @@ void sign_fail( int key_type_arg, data_t *key_data,
TEST_ASSERT( psa_import_key( slot, key_type, TEST_ASSERT( psa_import_key( slot, key_type,
key_data->x, (size_t) key_data->len ) == key_data->x, (size_t) key_data->len ) ==
PSA_SUCCESS ); PSA_SUCCESS );
actual_status = psa_asymmetric_sign( slot, alg, actual_status = psa_asymmetric_sign( slot, alg,
input_data->x, input_data->x,
@ -1112,14 +1112,14 @@ void key_policy( int usage_arg, int alg_arg )
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
psa_key_policy_init(& policy_set ); psa_key_policy_init( &policy_set );
psa_key_policy_init(& policy_get ); psa_key_policy_init( &policy_get );
psa_key_policy_set_usage( &policy_set, usage_arg, alg_arg ); psa_key_policy_set_usage( &policy_set, usage_arg, alg_arg );
TEST_ASSERT( psa_key_policy_get_usage( &policy_set ) == ( psa_key_usage_t )usage_arg ); TEST_ASSERT( psa_key_policy_get_usage( &policy_set ) == (psa_key_usage_t) usage_arg );
TEST_ASSERT( psa_key_policy_get_algorithm( &policy_set) == ( psa_algorithm_t )alg_arg ); TEST_ASSERT( psa_key_policy_get_algorithm( &policy_set ) == (psa_algorithm_t) alg_arg );
TEST_ASSERT( psa_set_key_policy( key_slot, &policy_set ) == PSA_SUCCESS ); TEST_ASSERT( psa_set_key_policy( key_slot, &policy_set ) == PSA_SUCCESS );
@ -1159,11 +1159,13 @@ void key_policy_fail( int usage_arg, int alg_arg, int expected_status,
TEST_ASSERT( keypair != NULL ); TEST_ASSERT( keypair != NULL );
TEST_ASSERT( PSA_CRYPTO_TEST_SIZE_T_RANGE( keypair->len ) ); TEST_ASSERT( PSA_CRYPTO_TEST_SIZE_T_RANGE( keypair->len ) );
TEST_ASSERT( psa_import_key( key_slot, PSA_KEY_TYPE_RSA_KEYPAIR, TEST_ASSERT( psa_import_key( key_slot, PSA_KEY_TYPE_RSA_KEYPAIR,
keypair->x, (size_t) keypair->len ) == keypair->x, (size_t) keypair->len ) ==
PSA_SUCCESS ); PSA_SUCCESS );
actual_status = psa_asymmetric_sign( key_slot, actual_status = psa_asymmetric_sign( key_slot,
( psa_algorithm_t )alg_arg, NULL, 0, NULL, 0, (psa_algorithm_t) alg_arg,
NULL, 0, &signature_length ); NULL, 0,
NULL, 0,
NULL, 0, &signature_length );
} }
if( usage_arg & PSA_KEY_USAGE_SIGN ) if( usage_arg & PSA_KEY_USAGE_SIGN )
@ -1171,8 +1173,8 @@ void key_policy_fail( int usage_arg, int alg_arg, int expected_status,
TEST_ASSERT( keypair != NULL ); TEST_ASSERT( keypair != NULL );
TEST_ASSERT( PSA_CRYPTO_TEST_SIZE_T_RANGE( keypair->len ) ); TEST_ASSERT( PSA_CRYPTO_TEST_SIZE_T_RANGE( keypair->len ) );
TEST_ASSERT( psa_import_key( key_slot, PSA_KEY_TYPE_RSA_KEYPAIR, TEST_ASSERT( psa_import_key( key_slot, PSA_KEY_TYPE_RSA_KEYPAIR,
keypair->x, (size_t) keypair->len ) == keypair->x, (size_t) keypair->len ) ==
PSA_SUCCESS ); PSA_SUCCESS );
actual_status = psa_export_key( key_slot, NULL, 0, NULL ); actual_status = psa_export_key( key_slot, NULL, 0, NULL );
} }
@ -1198,13 +1200,13 @@ void key_lifetime( int lifetime_arg )
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
TEST_ASSERT( psa_set_key_lifetime( key_slot, TEST_ASSERT( psa_set_key_lifetime( key_slot,
lifetime_set ) == PSA_SUCCESS ); lifetime_set ) == PSA_SUCCESS );
TEST_ASSERT( psa_import_key( key_slot, key_type, TEST_ASSERT( psa_import_key( key_slot, key_type,
key, sizeof( key ) ) == PSA_SUCCESS ); key, sizeof( key ) ) == PSA_SUCCESS );
TEST_ASSERT( psa_get_key_lifetime( key_slot, TEST_ASSERT( psa_get_key_lifetime( key_slot,
&lifetime_get ) == PSA_SUCCESS ); &lifetime_get ) == PSA_SUCCESS );
TEST_ASSERT( lifetime_get == lifetime_set ); TEST_ASSERT( lifetime_get == lifetime_set );
@ -1265,14 +1267,14 @@ void asymmetric_verify( int key_type_arg, data_t *key_data,
TEST_ASSERT( psa_import_key( slot, key_type, TEST_ASSERT( psa_import_key( slot, key_type,
key_data->x, (size_t) key_data->len ) == key_data->x, (size_t) key_data->len ) ==
PSA_SUCCESS ); PSA_SUCCESS );
TEST_ASSERT( psa_asymmetric_verify( slot, alg, TEST_ASSERT( psa_asymmetric_verify( slot, alg,
hash_data->x, (size_t) hash_data->len, hash_data->x, (size_t) hash_data->len,
NULL, 0, NULL, 0,
signature_data->x, signature_data->x,
(size_t) signature_data->len ) == (size_t) signature_data->len ) ==
PSA_SUCCESS ); PSA_SUCCESS );
exit: exit:
psa_destroy_key( slot ); psa_destroy_key( slot );
mbedtls_psa_crypto_free( ); mbedtls_psa_crypto_free( );
@ -1310,13 +1312,13 @@ void asymmetric_verify_fail( int key_type_arg, data_t *key_data,
TEST_ASSERT( psa_import_key( slot, key_type, TEST_ASSERT( psa_import_key( slot, key_type,
key_data->x, (size_t) key_data->len ) == key_data->x, (size_t) key_data->len ) ==
PSA_SUCCESS ); PSA_SUCCESS );
actual_status = psa_asymmetric_verify( slot, alg, actual_status = psa_asymmetric_verify( slot, alg,
hash_data->x, (size_t) hash_data->len, hash_data->x, (size_t) hash_data->len,
NULL, 0, NULL, 0,
signature_data->x, signature_data->x,
(size_t) signature_data->len ); (size_t) signature_data->len );
TEST_ASSERT( actual_status == expected_status ); TEST_ASSERT( actual_status == expected_status );
@ -1363,28 +1365,28 @@ void asymmetric_encrypt_decrypt( int key_type_arg, data_t *key_data,
TEST_ASSERT( psa_import_key( slot, key_type, TEST_ASSERT( psa_import_key( slot, key_type,
key_data->x, (size_t) key_data->len ) == key_data->x, (size_t) key_data->len ) ==
PSA_SUCCESS ); PSA_SUCCESS );
/* We test encryption by checking that encrypt-then-decrypt gives back /* We test encryption by checking that encrypt-then-decrypt gives back
* the original plaintext because of the non-optional random * the original plaintext because of the non-optional random
* part of encryption process which prevents using fixed vectors. */ * part of encryption process which prevents using fixed vectors. */
TEST_ASSERT( psa_asymmetric_encrypt(slot, alg, TEST_ASSERT( psa_asymmetric_encrypt( slot, alg,
input_data->x, input_data->x,
(size_t) input_data->len, (size_t) input_data->len,
NULL, 0, NULL, 0,
output, output,
output_size, output_size,
&output_length) == PSA_SUCCESS ); &output_length ) == PSA_SUCCESS );
TEST_ASSERT( psa_asymmetric_decrypt(slot, alg, TEST_ASSERT( psa_asymmetric_decrypt( slot, alg,
output, output,
output_length, output_length,
NULL, 0, NULL, 0,
output2, output2,
output2_size, output2_size,
&output2_length) == PSA_SUCCESS ); &output2_length ) == PSA_SUCCESS );
TEST_ASSERT( memcmp( input_data->x, output2, (size_t) input_data->len ) TEST_ASSERT( memcmp( input_data->x, output2, (size_t) input_data->len )
== 0 ); == 0 );
exit: exit:
psa_destroy_key( slot ); psa_destroy_key( slot );
@ -1398,8 +1400,8 @@ exit:
/* BEGIN_CASE */ /* BEGIN_CASE */
void asymmetric_encrypt_fail( int key_type_arg, data_t *key_data, void asymmetric_encrypt_fail( int key_type_arg, data_t *key_data,
int alg_arg, data_t *input_data, int alg_arg, data_t *input_data,
int expected_status_arg ) int expected_status_arg )
{ {
@ -1430,15 +1432,15 @@ void asymmetric_encrypt_fail( int key_type_arg, data_t *key_data,
TEST_ASSERT( psa_import_key( slot, key_type, TEST_ASSERT( psa_import_key( slot, key_type,
key_data->x, (size_t) key_data->len ) == key_data->x, (size_t) key_data->len ) ==
PSA_SUCCESS ); PSA_SUCCESS );
actual_status = psa_asymmetric_encrypt(slot, alg, actual_status = psa_asymmetric_encrypt( slot, alg,
input_data->x, input_data->x,
(size_t) input_data->len, (size_t) input_data->len,
NULL, 0, NULL, 0,
output, output,
output_size, output_size,
&output_length); &output_length );
TEST_ASSERT( actual_status == expected_status ); TEST_ASSERT( actual_status == expected_status );
exit: exit:
@ -1481,17 +1483,17 @@ void asymmetric_decrypt( int key_type_arg, data_t *key_data,
TEST_ASSERT( psa_import_key( slot, key_type, TEST_ASSERT( psa_import_key( slot, key_type,
key_data->x, (size_t) key_data->len ) == key_data->x, (size_t) key_data->len ) ==
PSA_SUCCESS ); PSA_SUCCESS );
TEST_ASSERT( psa_asymmetric_decrypt( slot, alg, TEST_ASSERT( psa_asymmetric_decrypt( slot, alg,
input_data->x, input_data->x,
(size_t) input_data->len, (size_t) input_data->len,
NULL, 0, NULL, 0,
output, output,
output_size, output_size,
&output_length) == PSA_SUCCESS ); &output_length ) == PSA_SUCCESS );
TEST_ASSERT( ((size_t)expected_size) == output_length ); TEST_ASSERT( ( (size_t) expected_size ) == output_length );
TEST_ASSERT( memcmp( expected_data->x, output, (output_length) ) == 0 ); TEST_ASSERT( memcmp( expected_data->x, output, ( output_length ) ) == 0 );
exit: exit:
psa_destroy_key( slot ); psa_destroy_key( slot );
@ -1505,8 +1507,8 @@ exit:
/* BEGIN_CASE */ /* BEGIN_CASE */
void asymmetric_decrypt_fail( int key_type_arg, data_t *key_data, void asymmetric_decrypt_fail( int key_type_arg, data_t *key_data,
int alg_arg, data_t *input_data, int alg_arg, data_t *input_data,
int expected_status_arg ) int expected_status_arg )
{ {
int slot = 1; int slot = 1;
@ -1536,20 +1538,20 @@ void asymmetric_decrypt_fail( int key_type_arg, data_t *key_data,
TEST_ASSERT( psa_import_key( slot, key_type, TEST_ASSERT( psa_import_key( slot, key_type,
key_data->x, (size_t) key_data->len ) == key_data->x, (size_t) key_data->len ) ==
PSA_SUCCESS ); PSA_SUCCESS );
actual_status = psa_asymmetric_decrypt(slot, alg, actual_status = psa_asymmetric_decrypt( slot, alg,
input_data->x, input_data->x,
(size_t) input_data->len, (size_t) input_data->len,
NULL, 0, NULL, 0,
output, output,
output_size, output_size,
&output_length); &output_length );
TEST_ASSERT( actual_status == expected_status ); TEST_ASSERT( actual_status == expected_status );
exit: exit:
psa_destroy_key( slot ); psa_destroy_key( slot );
mbedtls_free( output); mbedtls_free( output );
mbedtls_psa_crypto_free( ); mbedtls_psa_crypto_free( );
} }
/* END_CASE */ /* END_CASE */