mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-10-27 12:15:33 +03:00
Make the fallback behavior of mbedtls_test_rnd_buffer_rand optional
If a fallback is not explicitly configured in the mbedtls_test_rnd_buf_info structure, fail after the buffer is exhausted. There is no intended behavior change in this commit: all existing uses of mbedtls_test_rnd_buffer_rand() have been updated to set mbedtls_test_rnd_std_rand as the fallback. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
@@ -35,6 +35,8 @@
|
||||
#include <test/random.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mbedtls/entropy.h>
|
||||
|
||||
int mbedtls_test_rnd_std_rand( void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len )
|
||||
@@ -91,8 +93,16 @@ int mbedtls_test_rnd_buffer_rand( void *rng_state,
|
||||
}
|
||||
|
||||
if( len - use_len > 0 )
|
||||
return( mbedtls_test_rnd_std_rand( NULL, output + use_len,
|
||||
len - use_len ) );
|
||||
{
|
||||
if( info->fallback_f_rng != NULL )
|
||||
{
|
||||
return( info->fallback_f_rng( info->fallback_p_rng,
|
||||
output + use_len,
|
||||
len - use_len ) );
|
||||
}
|
||||
else
|
||||
return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user