diff --git a/include/mbedtls/platform_util.h b/include/mbedtls/platform_util.h index 4e0f9897a..7d16074e2 100644 --- a/include/mbedtls/platform_util.h +++ b/include/mbedtls/platform_util.h @@ -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. * diff --git a/library/platform_util.c b/library/platform_util.c index de2fa2bd0..fc6eb5abb 100644 --- a/library/platform_util.c +++ b/library/platform_util.c @@ -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)