mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-23 12:01:11 +00:00
Make RNG exclude the given maximum value
The RNG will give numbers in range of [0, num), so that the given maximum is excluded.
This commit is contained in:
parent
0ff7109b7c
commit
f5ebe2a7ce
|
@ -225,8 +225,9 @@ int mbedtls_platform_memcmp( const void *buf1, const void *buf2, size_t num );
|
|||
* cryptographically secure RNG, but provide an RNG for utility
|
||||
* functions.
|
||||
*
|
||||
* \param num Max-value for the generated random number.
|
||||
*
|
||||
* \param num Max-value for the generated random number, exclusive.
|
||||
* The generated number will be on range [0, num).
|
||||
* \return The generated random number.
|
||||
*/
|
||||
uint32_t mbedtls_platform_random_in_range( size_t num );
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ void mbedtls_platform_memset( void *ptr, int value, size_t num )
|
|||
/* Randomize start offset. */
|
||||
size_t start_offset = (size_t) mbedtls_platform_random_in_range( num );
|
||||
/* Randomize data */
|
||||
size_t data = (size_t) mbedtls_platform_random_in_range( 0xff );
|
||||
size_t data = (size_t) mbedtls_platform_random_in_range( 256 );
|
||||
|
||||
/* Perform a pair of memset operations from random locations with
|
||||
* random data */
|
||||
|
@ -101,7 +101,7 @@ void mbedtls_platform_memcpy( void *dst, const void *src, size_t num )
|
|||
/* Randomize start offset. */
|
||||
size_t start_offset = (size_t) mbedtls_platform_random_in_range( num );
|
||||
/* Randomize initial data to prevent leakage while copying */
|
||||
size_t data = (size_t) mbedtls_platform_random_in_range( 0xff );
|
||||
size_t data = (size_t) mbedtls_platform_random_in_range( 256 );
|
||||
|
||||
memset( (void *) dst, data, num );
|
||||
memcpy( (void *) ( (unsigned char *) dst + start_offset ),
|
||||
|
|
Loading…
Reference in a new issue