Change the value type in the mbedtls_platform_random_in_range()

Signed-off-by: Piotr Nowicki <piotr.nowicki@arm.com>
This commit is contained in:
Piotr Nowicki 2020-06-23 12:30:40 +02:00
parent fa635dfaa1
commit 8656fc6525
2 changed files with 8 additions and 8 deletions

View file

@ -264,7 +264,7 @@ uint32_t mbedtls_platform_random_uint32( void );
* *
* \return The generated random number. * \return The generated random number.
*/ */
uint32_t mbedtls_platform_random_in_range( size_t num ); uint32_t mbedtls_platform_random_in_range( uint32_t num );
/** /**
* \brief Random delay function. * \brief Random delay function.

View file

@ -96,7 +96,7 @@ void mbedtls_platform_zeroize( void *buf, size_t len )
void *mbedtls_platform_memset( void *ptr, int value, size_t num ) void *mbedtls_platform_memset( void *ptr, int value, size_t num )
{ {
/* Randomize start offset. */ /* Randomize start offset. */
size_t start_offset = (size_t) mbedtls_platform_random_in_range( num ); size_t start_offset = (size_t) mbedtls_platform_random_in_range( (uint32_t) num );
/* Randomize data */ /* Randomize data */
uint32_t data = mbedtls_platform_random_in_range( 256 ); uint32_t data = mbedtls_platform_random_in_range( 256 );
@ -113,7 +113,7 @@ void *mbedtls_platform_memset( void *ptr, int value, size_t num )
void *mbedtls_platform_memcpy( void *dst, const void *src, size_t num ) void *mbedtls_platform_memcpy( void *dst, const void *src, size_t num )
{ {
/* Randomize start offset. */ /* Randomize start offset. */
size_t start_offset = (size_t) mbedtls_platform_random_in_range( num ); size_t start_offset = (size_t) mbedtls_platform_random_in_range( (uint32_t) num );
/* Randomize initial data to prevent leakage while copying */ /* Randomize initial data to prevent leakage while copying */
uint32_t data = mbedtls_platform_random_in_range( 256 ); uint32_t data = mbedtls_platform_random_in_range( 256 );
@ -152,7 +152,7 @@ int mbedtls_platform_memequal( const void *buf1, const void *buf2, size_t num )
/* Start from a random location and check the correct number of iterations */ /* Start from a random location and check the correct number of iterations */
size_t i, flow_counter = 0; size_t i, flow_counter = 0;
size_t start_offset = (size_t) mbedtls_platform_random_in_range( num ); size_t start_offset = (size_t) mbedtls_platform_random_in_range( (uint32_t) num );
for( i = start_offset; i < num; i++ ) for( i = start_offset; i < num; i++ )
{ {
@ -186,7 +186,7 @@ uint32_t mbedtls_platform_random_uint32( )
#endif #endif
} }
uint32_t mbedtls_platform_random_in_range( size_t num ) uint32_t mbedtls_platform_random_in_range( uint32_t num )
{ {
#if !defined(MBEDTLS_ENTROPY_HARDWARE_ALT) #if !defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
(void) num; (void) num;
@ -216,7 +216,7 @@ void mbedtls_platform_random_delay( void )
#if !defined(MBEDTLS_ENTROPY_HARDWARE_ALT) #if !defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
return; return;
#else #else
size_t rn_1, rn_2, rn_3; uint32_t rn_1, rn_2, rn_3;
volatile size_t i = 0; volatile size_t i = 0;
uint8_t shift; uint8_t shift;
@ -232,9 +232,9 @@ void mbedtls_platform_random_delay( void )
* of its behaviour */ * of its behaviour */
shift = rn_2 & 0x07; shift = rn_2 & 0x07;
if ( i % 2 ) if ( i % 2 )
rn_2 = (uint32_t)( rn_2 >> shift | rn_2 << ( 32 - shift ) ); rn_2 = ( rn_2 >> shift ) | ( rn_2 << ( 32 - shift ) );
else else
rn_3 = (uint32_t)( rn_3 << shift | rn_3 >> ( 32 - shift ) ); rn_3 = ( rn_3 << shift ) | ( rn_3 >> ( 32 - shift ) );
rn_2 ^= rn_3; rn_2 ^= rn_3;
} while( i < rn_1 || rn_2 == 0 || rn_3 == 0 ); } while( i < rn_1 || rn_2 == 0 || rn_3 == 0 );