mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-29 16:14:20 +01:00
Add flow control to platform rnd buf
Signed-off-by: Shelly Liberman <shelly.liberman@arm.com>
This commit is contained in:
parent
26bea33674
commit
7326c62efb
@ -2988,7 +2988,7 @@
|
|||||||
*
|
*
|
||||||
* Uncomment to provide your own alternate implementation for mbedtls_platform_fault(),
|
* Uncomment to provide your own alternate implementation for mbedtls_platform_fault(),
|
||||||
* used in library/platform_util.c to signal a fault injection in either
|
* used in library/platform_util.c to signal a fault injection in either
|
||||||
* mbedtls_platform_memcpy or mbedtls_platform_memset.
|
* mbedtls_platform_memcpy, mbedtls_platform_memset or mbedtls_platform_random_buf.
|
||||||
*
|
*
|
||||||
* You will need to provide a header "platform_fault.h" and an implementation at
|
* You will need to provide a header "platform_fault.h" and an implementation at
|
||||||
* compile time.
|
* compile time.
|
||||||
|
@ -334,6 +334,7 @@ uint32_t mbedtls_platform_random_uint32( void )
|
|||||||
|
|
||||||
void mbedtls_platform_random_buf( uint8_t *buf, size_t len )
|
void mbedtls_platform_random_buf( uint8_t *buf, size_t len )
|
||||||
{
|
{
|
||||||
|
volatile size_t flow_control = 0;
|
||||||
uint16_t val;
|
uint16_t val;
|
||||||
|
|
||||||
while( len > 1 )
|
while( len > 1 )
|
||||||
@ -342,13 +343,19 @@ void mbedtls_platform_random_buf( uint8_t *buf, size_t len )
|
|||||||
buf[len-1] = (uint8_t)val;
|
buf[len-1] = (uint8_t)val;
|
||||||
buf[len-2] = (uint8_t)(val>>8);
|
buf[len-2] = (uint8_t)(val>>8);
|
||||||
len -= 2;
|
len -= 2;
|
||||||
|
flow_control += 2;
|
||||||
}
|
}
|
||||||
if( len == 1 )
|
if( len == 1 )
|
||||||
{
|
{
|
||||||
buf[0] = (uint8_t)mbedtls_platform_random_uint16();
|
buf[0] = (uint8_t)mbedtls_platform_random_uint16();
|
||||||
|
flow_control ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
if ( flow_control == len )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mbedtls_platform_fault();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t mbedtls_platform_random_in_range( uint32_t num )
|
uint32_t mbedtls_platform_random_in_range( uint32_t num )
|
||||||
|
Loading…
Reference in New Issue
Block a user