Add a platform function to return a random uint32_t
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
diff --git a/include/mbedtls/platform_util.h b/include/mbedtls/platform_util.h
index 4e0f989..7d16074 100644
--- a/include/mbedtls/platform_util.h
+++ b/include/mbedtls/platform_util.h
@@ -232,6 +232,18 @@
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.
*
* This function is meant to provide a global RNG to be used
diff --git a/library/platform_util.c b/library/platform_util.c
index de2fa2b..fc6eb5a 100644
--- a/library/platform_util.c
+++ b/library/platform_util.c
@@ -172,6 +172,20 @@
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)