mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-28 08:37:25 +00:00
Add init tests with entropy from NV seed
This commit is contained in:
parent
0b3b5733fc
commit
0fce4c5830
@ -39,3 +39,12 @@ fake_entropy_source:MBEDTLS_ENTROPY_BLOCK_SIZE:MBEDTLS_ENTROPY_BLOCK_SIZE - 1:1:
|
|||||||
|
|
||||||
Fake entropy: more than one block in two steps
|
Fake entropy: more than one block in two steps
|
||||||
fake_entropy_source:MBEDTLS_ENTROPY_BLOCK_SIZE:MBEDTLS_ENTROPY_BLOCK_SIZE - 1:MBEDTLS_ENTROPY_BLOCK_SIZE - 1:-1:-1:PSA_SUCCESS
|
fake_entropy_source:MBEDTLS_ENTROPY_BLOCK_SIZE:MBEDTLS_ENTROPY_BLOCK_SIZE - 1:MBEDTLS_ENTROPY_BLOCK_SIZE - 1:-1:-1:PSA_SUCCESS
|
||||||
|
|
||||||
|
NV seed only: less than minimum
|
||||||
|
entropy_from_nv_seed:MBEDTLS_ENTROPY_MIN_PLATFORM - 1:PSA_ERROR_INSUFFICIENT_ENTROPY
|
||||||
|
|
||||||
|
NV seed only: less than one block
|
||||||
|
entropy_from_nv_seed:MBEDTLS_ENTROPY_BLOCK_SIZE - 1:PSA_ERROR_INSUFFICIENT_ENTROPY
|
||||||
|
|
||||||
|
NV seed only: just enough
|
||||||
|
entropy_from_nv_seed:ENTROPY_MIN_NV_SEED_SIZE:PSA_SUCCESS
|
||||||
|
@ -11,8 +11,13 @@
|
|||||||
|
|
||||||
#include "mbedtls/entropy.h"
|
#include "mbedtls/entropy.h"
|
||||||
#include "mbedtls/entropy_poll.h"
|
#include "mbedtls/entropy_poll.h"
|
||||||
|
#include "mbedtls/platform.h"
|
||||||
|
|
||||||
#define MIN( x, y ) ( ( x ) < ( y ) ? ( x ) : ( y ) )
|
#define MIN( x, y ) ( ( x ) < ( y ) ? ( x ) : ( y ) )
|
||||||
|
#define MAX( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) )
|
||||||
|
|
||||||
|
#define ENTROPY_MIN_NV_SEED_SIZE \
|
||||||
|
MAX(MBEDTLS_ENTROPY_MIN_PLATFORM, MBEDTLS_ENTROPY_BLOCK_SIZE)
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@ -249,3 +254,33 @@ exit:
|
|||||||
mbedtls_psa_crypto_free( );
|
mbedtls_psa_crypto_free( );
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
|
/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED */
|
||||||
|
void entropy_from_nv_seed( int seed_size_arg,
|
||||||
|
int expected_init_status_arg )
|
||||||
|
{
|
||||||
|
psa_status_t expected_init_status = expected_init_status_arg;
|
||||||
|
uint8_t random[10] = { 0 };
|
||||||
|
uint8_t *seed = NULL;
|
||||||
|
size_t seed_size = seed_size_arg;
|
||||||
|
|
||||||
|
ASSERT_ALLOC( seed, seed_size );
|
||||||
|
TEST_ASSERT( mbedtls_nv_seed_write( seed, seed_size ) >= 0 );
|
||||||
|
|
||||||
|
custom_entropy_sources_mask = ENTROPY_SOURCE_NV_SEED;
|
||||||
|
TEST_ASSERT( mbedtls_psa_crypto_configure_entropy_sources(
|
||||||
|
custom_entropy_init, mbedtls_entropy_free ) ==
|
||||||
|
PSA_SUCCESS );
|
||||||
|
|
||||||
|
TEST_ASSERT( psa_crypto_init( ) == expected_init_status );
|
||||||
|
if( expected_init_status != PSA_SUCCESS )
|
||||||
|
goto exit;
|
||||||
|
|
||||||
|
TEST_ASSERT( psa_generate_random( random, sizeof( random ) ) ==
|
||||||
|
PSA_SUCCESS );
|
||||||
|
|
||||||
|
exit:
|
||||||
|
mbedtls_free( seed );
|
||||||
|
mbedtls_psa_crypto_free( );
|
||||||
|
}
|
||||||
|
/* END_CASE */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user