Add a platform function to return a random uint32_t

Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
This commit is contained in:
Andrzej Kurek 2020-06-24 17:28:31 -04:00
parent 7e6075b7fd
commit 189ee74a82
No known key found for this signature in database
GPG Key ID: 89A90840DC388527
2 changed files with 26 additions and 0 deletions

View File

@ -231,6 +231,18 @@ int mbedtls_platform_memmove( void *dst, const void *src, size_t num );
*/
int mbedtls_platform_memcmp( const void *buf1, const void *buf2, size_t num );
/**
* \brief RNG-function for getting a random 32-bit integer.
*
*
* \note Currently the function is dependent of hardware providing an
* rng with MBEDTLS_ENTROPY_HARDWARE_ALT. By default, 0 is
* returned.
*
* \return The generated random number.
*/
uint32_t mbedtls_platform_random_uint32( void );
/**
* \brief RNG-function for getting a random in given range.
*

View File

@ -172,6 +172,20 @@ int mbedtls_platform_memcmp( const void *buf1, const void *buf2, size_t num )
return( (int) diff | (int) ( flow_counter ^ num ) );
}
uint32_t mbedtls_platform_random_uint32( )
{
#if !defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
return 0;
#else
uint32_t result = 0;
size_t olen = 0;
mbedtls_hardware_poll( NULL, (unsigned char *) &result, sizeof( result ),
&olen );
return( result );
#endif
}
uint32_t mbedtls_platform_random_in_range( size_t num )
{
#if !defined(MBEDTLS_ENTROPY_HARDWARE_ALT)