Random delay can be disabled in configuration
Use random delay depending on whether MBEDTLS_FI_COUNTERMEASURES is defined
Signed-off-by: Piotr Nowicki <piotr.nowicki@arm.com>
diff --git a/include/mbedtls/platform_util.h b/include/mbedtls/platform_util.h
index 6f09209..8d00eba 100644
--- a/include/mbedtls/platform_util.h
+++ b/include/mbedtls/platform_util.h
@@ -262,6 +262,10 @@
*
* Duration of the delay is random as number of variable increments
* is randomized.
+ *
+ * \note This function works only if the MBEDTLS_FI_COUNTERMEASURES flag
+ * is defined in the configuration. Otherwise, the function does
+ * nothing.
*/
void mbedtls_platform_random_delay( void );
diff --git a/library/platform_util.c b/library/platform_util.c
index 641172a..3fa9437 100644
--- a/library/platform_util.c
+++ b/library/platform_util.c
@@ -255,6 +255,7 @@
void mbedtls_platform_random_delay( void )
{
+#if defined(MBEDTLS_FI_COUNTERMEASURES)
uint32_t rn_1, rn_2, rn_3;
volatile size_t i = 0;
uint8_t shift;
@@ -276,6 +277,9 @@
rn_3 = ( rn_3 << shift ) | ( rn_3 >> ( 32 - shift ) );
rn_2 ^= rn_3;
} while( i < rn_1 || rn_2 == 0 || rn_3 == 0 );
+
+#endif /* MBEDTLS_FI_COUNTERMEASURES */
+ return;
}
#if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_PLATFORM_GMTIME_R_ALT)