2019-06-24 13:47:24 +02:00
|
|
|
/* BEGIN_HEADER */
|
|
|
|
#include "psa_crypto_helpers.h"
|
|
|
|
#include "psa/crypto_se_driver.h"
|
|
|
|
|
2019-06-24 14:34:59 +02:00
|
|
|
#include "psa_crypto_se.h"
|
|
|
|
|
|
|
|
/* The minimum valid lifetime value for a secure element driver. */
|
|
|
|
#define MIN_DRIVER_LIFETIME 2
|
|
|
|
|
2019-06-24 13:47:24 +02:00
|
|
|
/* END_HEADER */
|
|
|
|
|
|
|
|
/* BEGIN_DEPENDENCIES
|
2019-06-26 11:24:49 +02:00
|
|
|
* depends_on:MBEDTLS_PSA_CRYPTO_SE_C
|
2019-06-24 13:47:24 +02:00
|
|
|
* END_DEPENDENCIES
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
|
|
|
void register_one( int lifetime, int version, int expected_status_arg )
|
|
|
|
{
|
|
|
|
psa_status_t expected_status = expected_status_arg;
|
|
|
|
psa_drv_se_t driver;
|
|
|
|
|
|
|
|
memset( &driver, 0, sizeof( driver ) );
|
|
|
|
driver.hal_version = version;
|
|
|
|
|
|
|
|
TEST_EQUAL( psa_register_se_driver( lifetime, &driver ),
|
|
|
|
expected_status );
|
|
|
|
|
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
|
|
|
|
|
|
|
exit:
|
|
|
|
PSA_DONE( );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
2019-06-24 14:34:59 +02:00
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
|
|
|
void register_twice( int count )
|
|
|
|
{
|
|
|
|
psa_drv_se_t driver;
|
|
|
|
psa_key_lifetime_t lifetime;
|
|
|
|
psa_key_lifetime_t max = MIN_DRIVER_LIFETIME + count;
|
|
|
|
|
|
|
|
memset( &driver, 0, sizeof( driver ) );
|
|
|
|
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
|
|
|
|
|
|
|
|
for( lifetime = MIN_DRIVER_LIFETIME; lifetime < max; lifetime++ )
|
|
|
|
PSA_ASSERT( psa_register_se_driver( lifetime, &driver ) );
|
|
|
|
for( lifetime = MIN_DRIVER_LIFETIME; lifetime < max; lifetime++ )
|
|
|
|
TEST_EQUAL( psa_register_se_driver( lifetime, &driver ),
|
|
|
|
PSA_ERROR_ALREADY_EXISTS );
|
|
|
|
|
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
|
|
|
|
|
|
|
exit:
|
|
|
|
PSA_DONE( );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
|
|
|
void register_max( )
|
|
|
|
{
|
|
|
|
psa_drv_se_t driver;
|
|
|
|
psa_key_lifetime_t lifetime;
|
|
|
|
psa_key_lifetime_t max = MIN_DRIVER_LIFETIME + PSA_MAX_SE_DRIVERS;
|
|
|
|
|
|
|
|
memset( &driver, 0, sizeof( driver ) );
|
|
|
|
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
|
|
|
|
|
|
|
|
for( lifetime = MIN_DRIVER_LIFETIME; lifetime < max; lifetime++ )
|
|
|
|
PSA_ASSERT( psa_register_se_driver( lifetime, &driver ) );
|
|
|
|
|
|
|
|
TEST_EQUAL( psa_register_se_driver( lifetime, &driver ),
|
|
|
|
PSA_ERROR_INSUFFICIENT_MEMORY );
|
|
|
|
|
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
|
|
|
|
|
|
|
exit:
|
|
|
|
PSA_DONE( );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|