mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-03-24 22:25:11 +00:00
Add Tests for psa crypto entropy incjection
Adjust code to handle and work with MBEDTLS_ENTROPY_BLOCK_SIZE definition option
This commit is contained in:
parent
ee2ffd311b
commit
21f37cbbec
|
@ -91,8 +91,10 @@ void mbedtls_psa_crypto_free( void );
|
||||||
*
|
*
|
||||||
* \param seed[in] Buffer containing the seed value to inject.
|
* \param seed[in] Buffer containing the seed value to inject.
|
||||||
* \param seed_size Size of the \p seed buffer.
|
* \param seed_size Size of the \p seed buffer.
|
||||||
* The size of the seed must be
|
* The size of the seed must be equal or larger than any
|
||||||
* at least #MBEDTLS_ENTROPY_MIN_PLATFORM bytes
|
* of the values defined both in
|
||||||
|
* #MBEDTLS_ENTROPY_MIN_PLATFORM
|
||||||
|
* and in the #MBEDTLS_ENTROPY_BLOCK_SIZE defines
|
||||||
* and at most #MBEDTLS_ENTROPY_MAX_SEED_SIZE bytes.
|
* and at most #MBEDTLS_ENTROPY_MAX_SEED_SIZE bytes.
|
||||||
*
|
*
|
||||||
* \retval #PSA_SUCCESS
|
* \retval #PSA_SUCCESS
|
||||||
|
|
|
@ -4234,8 +4234,12 @@ psa_status_t mbedtls_psa_inject_entropy( const unsigned char *seed,
|
||||||
struct psa_its_info_t p_info;
|
struct psa_its_info_t p_info;
|
||||||
if( global_data.initialized )
|
if( global_data.initialized )
|
||||||
return( PSA_ERROR_NOT_PERMITTED );
|
return( PSA_ERROR_NOT_PERMITTED );
|
||||||
if( ( seed_size < MBEDTLS_ENTROPY_MIN_PLATFORM ) || ( seed_size > MBEDTLS_ENTROPY_MAX_SEED_SIZE ) )
|
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
if( ( ( seed_size < MBEDTLS_ENTROPY_MIN_PLATFORM ) ||
|
||||||
|
( seed_size < MBEDTLS_ENTROPY_BLOCK_SIZE ) ) ||
|
||||||
|
( seed_size > MBEDTLS_ENTROPY_MAX_SEED_SIZE ) )
|
||||||
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
|
||||||
status = psa_its_get_info( MBED_RANDOM_SEED_ITS_UID, &p_info );
|
status = psa_its_get_info( MBED_RANDOM_SEED_ITS_UID, &p_info );
|
||||||
if( PSA_ITS_ERROR_KEY_NOT_FOUND == status ) /* No seed exists */
|
if( PSA_ITS_ERROR_KEY_NOT_FOUND == status ) /* No seed exists */
|
||||||
{
|
{
|
||||||
|
|
|
@ -402,6 +402,9 @@ static const char *features[] = {
|
||||||
#if defined(MBEDTLS_ENTROPY_NV_SEED)
|
#if defined(MBEDTLS_ENTROPY_NV_SEED)
|
||||||
"MBEDTLS_ENTROPY_NV_SEED",
|
"MBEDTLS_ENTROPY_NV_SEED",
|
||||||
#endif /* MBEDTLS_ENTROPY_NV_SEED */
|
#endif /* MBEDTLS_ENTROPY_NV_SEED */
|
||||||
|
#if defined(MBEDTLS_PSA_HAS_ITS_IO)
|
||||||
|
"MBEDTLS_PSA_HAS_ITS_IO",
|
||||||
|
#endif /* MBEDTLS_PSA_HAS_ITS_IO */
|
||||||
#if defined(MBEDTLS_MEMORY_DEBUG)
|
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||||
"MBEDTLS_MEMORY_DEBUG",
|
"MBEDTLS_MEMORY_DEBUG",
|
||||||
#endif /* MBEDTLS_MEMORY_DEBUG */
|
#endif /* MBEDTLS_MEMORY_DEBUG */
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
PSA validate entropy injection: good, minimum size
|
PSA validate entropy injection: good, minimum size
|
||||||
validate_entropy_seed_injection:MBEDTLS_ENTROPY_MIN_PLATFORM:PSA_SUCCESS:MBEDTLS_ENTROPY_MIN_PLATFORM:PSA_ERROR_NOT_PERMITTED
|
validate_entropy_seed_injection:MBEDTLS_ENTROPY_BLOCK_SIZE:PSA_SUCCESS:MBEDTLS_ENTROPY_BLOCK_SIZE:PSA_ERROR_NOT_PERMITTED
|
||||||
|
|
||||||
PSA validate entropy injection: good, max size
|
PSA validate entropy injection: good, max size
|
||||||
validate_entropy_seed_injection:MBEDTLS_ENTROPY_MAX_SEED_SIZE:PSA_SUCCESS:MBEDTLS_ENTROPY_MAX_SEED_SIZE:PSA_ERROR_NOT_PERMITTED
|
validate_entropy_seed_injection:MBEDTLS_ENTROPY_MAX_SEED_SIZE:PSA_SUCCESS:MBEDTLS_ENTROPY_MAX_SEED_SIZE:PSA_ERROR_NOT_PERMITTED
|
||||||
|
|
||||||
PSA validate entropy injection: bad, too big
|
PSA validate entropy injection: bad, too big
|
||||||
validate_entropy_seed_injection:MBEDTLS_ENTROPY_MAX_SEED_SIZE+1:PSA_ERROR_INVALID_ARGUMENT:MBEDTLS_ENTROPY_MIN_PLATFORM:PSA_SUCCESS
|
validate_entropy_seed_injection:MBEDTLS_ENTROPY_MAX_SEED_SIZE+1:PSA_ERROR_INVALID_ARGUMENT:MBEDTLS_ENTROPY_BLOCK_SIZE:PSA_SUCCESS
|
||||||
|
|
||||||
PSA validate entropy injection: bad, too small
|
PSA validate entropy injection: bad, too small
|
||||||
validate_entropy_seed_injection:MBEDTLS_ENTROPY_MIN_PLATFORM-1:PSA_ERROR_INVALID_ARGUMENT:MBEDTLS_ENTROPY_MIN_PLATFORM:PSA_SUCCESS
|
validate_entropy_seed_injection:MBEDTLS_ENTROPY_BLOCK_SIZE-1:PSA_ERROR_INVALID_ARGUMENT:MBEDTLS_ENTROPY_BLOCK_SIZE:PSA_SUCCESS
|
||||||
|
|
||||||
PSA validate entropy injection: before and after crypto_init
|
PSA validate entropy injection: before and after crypto_init
|
||||||
run_entropy_inject_with_crypto_init:
|
run_entropy_inject_with_crypto_init:
|
||||||
|
|
||||||
|
|
|
@ -62,24 +62,24 @@ void run_entropy_inject_with_crypto_init( )
|
||||||
psa_its_status_t its_status;
|
psa_its_status_t its_status;
|
||||||
psa_status_t status;
|
psa_status_t status;
|
||||||
int i;
|
int i;
|
||||||
uint8_t seed[MBEDTLS_ENTROPY_MIN_PLATFORM] = {0};
|
uint8_t seed[MBEDTLS_ENTROPY_BLOCK_SIZE] = {0};
|
||||||
/* fill seed in some data */
|
/* fill seed in some data */
|
||||||
for( i = 0; i < MBEDTLS_ENTROPY_MIN_PLATFORM; ++i)
|
for( i = 0; i < MBEDTLS_ENTROPY_BLOCK_SIZE; ++i)
|
||||||
{
|
{
|
||||||
seed[i] = i;
|
seed[i] = i;
|
||||||
}
|
}
|
||||||
its_status = psa_its_remove(MBED_RANDOM_SEED_ITS_UID);
|
its_status = psa_its_remove(MBED_RANDOM_SEED_ITS_UID);
|
||||||
TEST_ASSERT( (its_status == PSA_ITS_SUCCESS) || (its_status == PSA_ITS_ERROR_KEY_NOT_FOUND) );
|
TEST_ASSERT( (its_status == PSA_ITS_SUCCESS) || (its_status == PSA_ITS_ERROR_KEY_NOT_FOUND) );
|
||||||
status = mbedtls_psa_inject_entropy( seed, MBEDTLS_ENTROPY_MIN_PLATFORM );
|
status = mbedtls_psa_inject_entropy( seed, MBEDTLS_ENTROPY_BLOCK_SIZE );
|
||||||
TEST_ASSERT( status == PSA_SUCCESS );
|
TEST_ASSERT( status == PSA_SUCCESS );
|
||||||
its_status = psa_its_remove(MBED_RANDOM_SEED_ITS_UID);
|
its_status = psa_its_remove(MBED_RANDOM_SEED_ITS_UID);
|
||||||
TEST_ASSERT( its_status == PSA_ITS_SUCCESS );
|
TEST_ASSERT( its_status == PSA_ITS_SUCCESS );
|
||||||
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
||||||
status = mbedtls_psa_inject_entropy( seed, MBEDTLS_ENTROPY_MIN_PLATFORM );
|
status = mbedtls_psa_inject_entropy( seed, MBEDTLS_ENTROPY_BLOCK_SIZE );
|
||||||
TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED );
|
TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED );
|
||||||
mbedtls_psa_crypto_free( );
|
mbedtls_psa_crypto_free( );
|
||||||
/* The seed is written by nv_seed callback functions therefore the injection will fail */
|
/* The seed is written by nv_seed callback functions therefore the injection will fail */
|
||||||
status = mbedtls_psa_inject_entropy( seed, MBEDTLS_ENTROPY_MIN_PLATFORM );
|
status = mbedtls_psa_inject_entropy( seed, MBEDTLS_ENTROPY_BLOCK_SIZE );
|
||||||
TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED );
|
TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED );
|
||||||
exit:
|
exit:
|
||||||
psa_its_remove(MBED_RANDOM_SEED_ITS_UID);
|
psa_its_remove(MBED_RANDOM_SEED_ITS_UID);
|
||||||
|
|
Loading…
Reference in a new issue