2018-11-20 20:56:14 +01:00
|
|
|
/* BEGIN_HEADER */
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_PSA_CRYPTO_SPM)
|
|
|
|
#include "spm/psa_defs.h"
|
|
|
|
#endif
|
|
|
|
#include "psa/crypto.h"
|
|
|
|
|
|
|
|
/* END_HEADER */
|
|
|
|
|
|
|
|
/* BEGIN_DEPENDENCIES
|
|
|
|
* depends_on:MBEDTLS_PSA_CRYPTO_C
|
|
|
|
* END_DEPENDENCIES
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
2018-11-20 21:00:42 +01:00
|
|
|
void init_deinit( int count )
|
2018-11-20 20:56:14 +01:00
|
|
|
{
|
|
|
|
psa_status_t status;
|
|
|
|
int i;
|
2018-11-20 21:00:42 +01:00
|
|
|
for( i = 0; i < count; i++ )
|
2018-11-20 20:56:14 +01:00
|
|
|
{
|
|
|
|
status = psa_crypto_init( );
|
|
|
|
TEST_ASSERT( status == PSA_SUCCESS );
|
|
|
|
status = psa_crypto_init( );
|
|
|
|
TEST_ASSERT( status == PSA_SUCCESS );
|
|
|
|
mbedtls_psa_crypto_free( );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2018-11-20 21:42:52 +01:00
|
|
|
/* BEGIN_CASE */
|
|
|
|
void deinit_without_init( int count )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for( i = 0; i < count; i++ )
|
|
|
|
{
|
|
|
|
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
|
|
|
mbedtls_psa_crypto_free( );
|
|
|
|
}
|
|
|
|
mbedtls_psa_crypto_free( );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2018-11-20 20:56:14 +01:00
|
|
|
/* BEGIN_CASE */
|
2018-11-20 21:00:42 +01:00
|
|
|
void validate_module_init_generate_random( int count )
|
2018-11-20 20:56:14 +01:00
|
|
|
{
|
|
|
|
psa_status_t status;
|
|
|
|
uint8_t random[10] = { 0 };
|
2018-11-20 21:00:42 +01:00
|
|
|
int i;
|
|
|
|
for( i = 0; i < count; i++ )
|
|
|
|
{
|
|
|
|
status = psa_crypto_init( );
|
|
|
|
TEST_ASSERT( status == PSA_SUCCESS );
|
|
|
|
mbedtls_psa_crypto_free( );
|
|
|
|
}
|
2018-11-20 20:56:14 +01:00
|
|
|
status = psa_generate_random( random, sizeof( random ) );
|
|
|
|
TEST_ASSERT( status == PSA_ERROR_BAD_STATE );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
2018-11-20 21:00:42 +01:00
|
|
|
void validate_module_init_key_based( int count )
|
2018-11-20 20:56:14 +01:00
|
|
|
{
|
|
|
|
psa_status_t status;
|
|
|
|
uint8_t data[10] = { 0 };
|
2018-11-20 21:00:42 +01:00
|
|
|
int i;
|
|
|
|
for( i = 0; i < count; i++ )
|
|
|
|
{
|
|
|
|
status = psa_crypto_init( );
|
|
|
|
TEST_ASSERT( status == PSA_SUCCESS );
|
|
|
|
mbedtls_psa_crypto_free( );
|
|
|
|
}
|
2018-11-20 20:56:14 +01:00
|
|
|
status = psa_import_key( 1, PSA_KEY_TYPE_RAW_DATA, data, sizeof( data ) );
|
|
|
|
TEST_ASSERT( status == PSA_ERROR_BAD_STATE );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|