Skip to content

Commit e06a99e

Browse files
committed
Allow user to override weak entropy source
1 parent 4aa9927 commit e06a99e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/we_random.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,13 @@ static int we_rand_add(const void *buf, int num, double entropy)
247247
}
248248

249249
#ifndef WE_STATIC_WOLFSSL
250+
251+
#ifdef ADD_WEAK_ENTROPY_OVERRIDE
252+
/* Prototype for user implemenations of XADD_WEAK_ENTROPY() */
253+
extern int my_add_weak_entropy(unsigned char* buf, int num);
254+
#define XADD_WEAK_ENTROPY(b, n) my_add_weak_entropy(b, n)
255+
#endif /* ADD_WEAK_ENTROPY_OVERRIDE */
256+
250257
/**
251258
* Add weak entropy to the input buffer. Used by we_rand_bytes to add entropy
252259
* for RNG. Uses thread ID, a timer value, and PID.
@@ -257,6 +264,9 @@ static int we_rand_add(const void *buf, int num, double entropy)
257264
*/
258265
static int we_rand_add_weak_entropy(unsigned char* buf, int num)
259266
{
267+
#ifdef ADD_WEAK_ENTROPY_OVERRIDE
268+
return XADD_WEAK_ENTROPY(buf, num);
269+
#else
260270
int ret = 1;
261271
unsigned char* idx;
262272
#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
@@ -339,6 +349,7 @@ static int we_rand_add_weak_entropy(unsigned char* buf, int num)
339349
WOLFENGINE_LEAVE(WE_LOG_RNG, "we_rand_add_weak_entropy", ret);
340350

341351
return ret;
352+
#endif /* ADD_WEAK_ENTROPY_OVERRIDE */
342353
}
343354
#endif /* WE_STATIC_WOLFSSL */
344355

0 commit comments

Comments
 (0)