Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions library/rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -2890,14 +2890,18 @@ void mbedtls_rsa_free(mbedtls_rsa_context *ctx)
static int myrand(void *rng_state, unsigned char *output, size_t len)
{
#if !defined(__OpenBSD__) && !defined(__NetBSD__)
size_t i;

if (rng_state != NULL) {
rng_state = NULL;
}

for (i = 0; i < len; ++i) {
output[i] = rand();
while (len > 0) {
#if (RAND_MAX >= 0x00FFFFFF)
*output = (unsigned char) (rand() >> 16);
#else
*output = (unsigned char) rand() ; /* e. g. Visual C */
#endif
output += 1;
len -= 1;
}
#else
if (rng_state != NULL) {
Expand Down
26 changes: 18 additions & 8 deletions programs/fuzz/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ int fuzz_recv(void *ctx, unsigned char *buf, size_t len)
int dummy_random(void *p_rng, unsigned char *output, size_t output_len)
{
int ret;
size_t i;

#if defined(MBEDTLS_CTR_DRBG_C)
//mbedtls_ctr_drbg_random requires a valid mbedtls_ctr_drbg_context in p_rng
Expand All @@ -74,24 +73,35 @@ int dummy_random(void *p_rng, unsigned char *output, size_t output_len)
(void) p_rng;
ret = 0;
#endif
for (i = 0; i < output_len; i++) {
//replace result with pseudo random
output[i] = (unsigned char) rand();
//replace result with pseudo random
while (output_len > 0) {
#if (RAND_MAX >= 0x00FFFFFF)
*output = (unsigned char) (rand() >> 16);
#else
*output = (unsigned char) rand() ; /* e. g. Visual C */
#endif
output += 1;
output_len -= 1;
}
return ret;
}

int dummy_entropy(void *data, unsigned char *output, size_t len)
{
size_t i;
(void) data;

//use mbedtls_entropy_func to find bugs in it
//test performance impact of entropy
//ret = mbedtls_entropy_func(data, output, len);
for (i = 0; i < len; i++) {
//replace result with pseudo random
output[i] = (unsigned char) rand();
//replace result with pseudo random
while (len > 0) {
#if (RAND_MAX >= 0x00FFFFFF)
*output = (unsigned char) (rand() >> 16);
#else
*output = (unsigned char) rand() ; /* e. g. Visual C */
#endif
output += 1;
len -= 1;
}
return 0;
}
Expand Down
13 changes: 9 additions & 4 deletions programs/ssl/ssl_test_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,19 @@ mbedtls_time_t dummy_constant_time(mbedtls_time_t *time)
#if !defined(MBEDTLS_TEST_USE_PSA_CRYPTO_RNG)
static int dummy_entropy(void *data, unsigned char *output, size_t len)
{
size_t i;
int ret;
(void) data;

ret = mbedtls_entropy_func(data, output, len);
for (i = 0; i < len; i++) {
//replace result with pseudo random
output[i] = (unsigned char) rand();
//replace result with pseudo random
while (len > 0) {
#if (RAND_MAX >= 0x00FFFFFF)
*output = (unsigned char) (rand() >> 16);
#else
*output = (unsigned char) rand() ; /* e. g. Visual C */
#endif
output += 1;
len -= 1;
}
return ret;
}
Expand Down
19 changes: 7 additions & 12 deletions programs/test/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,23 +455,18 @@ static void mbedtls_set_alarm(int seconds)

static int myrand(void *rng_state, unsigned char *output, size_t len)
{
size_t use_len;
int rnd;

if (rng_state != NULL) {
rng_state = NULL;
}

while (len > 0) {
use_len = len;
if (use_len > sizeof(int)) {
use_len = sizeof(int);
}

rnd = rand();
memcpy(output, &rnd, use_len);
output += use_len;
len -= use_len;
#if (RAND_MAX >= 0x00FFFFFF)
*output = (unsigned char) (rand() >> 16);
#else
*output = (unsigned char) rand() ; /* e. g. Visual C */
#endif
output += 1;
len -= 1;
}

return 0;
Expand Down
10 changes: 8 additions & 2 deletions tests/src/test_helpers/ssl_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@
int mbedtls_test_random(void *p_rng, unsigned char *output, size_t output_len)
{
(void) p_rng;
for (size_t i = 0; i < output_len; i++) {
output[i] = rand();
while (output_len > 0) {
#if (RAND_MAX >= 0x00FFFFFF)
*output = (unsigned char) (rand() >> 16);
#else
*output = (unsigned char) rand() ; /* e. g. Visual C */
#endif
output += 1;
output_len -= 1;
}

return 0;
Expand Down