summaryrefslogtreecommitdiff
path: root/dbrandom.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2018-02-17 19:29:51 +0800
committerMatt Johnston <matt@ucc.asn.au>2018-02-17 19:29:51 +0800
commit104e39e9caf447cb416a6d83ea7eedd4481ce4c3 (patch)
treeb8b33aaee9f7336e592da7a916ee05bae3412c22 /dbrandom.c
parent2b551518f8625f87a22ea1fde40e3c7d841bf9d0 (diff)
parent769be133237df6d9a4028645e7e9924be8544c8f (diff)
downloaddropbear-104e39e9caf447cb416a6d83ea7eedd4481ce4c3.tar.gz
merge from main
Diffstat (limited to 'dbrandom.c')
-rw-r--r--dbrandom.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/dbrandom.c b/dbrandom.c
index a117b10..1907834 100644
--- a/dbrandom.c
+++ b/dbrandom.c
@@ -27,7 +27,7 @@
#include "dbutil.h"
#include "bignum.h"
#include "dbrandom.h"
-
+#include "runopts.h"
/* this is used to generate unique output from the same hashpool */
static uint32_t counter = 0;
@@ -145,6 +145,12 @@ void addrandom(const unsigned char * buf, unsigned int len)
{
hash_state hs;
+#ifdef DROPBEAR_FUZZ
+ if (fuzz.fuzzing || fuzz.recordf) {
+ return;
+ }
+#endif
+
/* hash in the new seed data */
sha1_init(&hs);
/* existing state (zeroes on startup) */
@@ -157,6 +163,11 @@ void addrandom(const unsigned char * buf, unsigned int len)
static void write_urandom()
{
+#ifdef DROPBEAR_FUZZ
+ if (fuzz.fuzzing || fuzz.recordf) {
+ return;
+ }
+#endif
#if !DROPBEAR_USE_PRNGD
/* This is opportunistic, don't worry about failure */
unsigned char buf[INIT_SEED_SIZE];
@@ -170,6 +181,18 @@ static void write_urandom()
#endif
}
+#ifdef DROPBEAR_FUZZ
+void fuzz_seed(void) {
+ hash_state hs;
+ sha1_init(&hs);
+ sha1_process(&hs, "fuzzfuzzfuzz", strlen("fuzzfuzzfuzz"));
+ sha1_done(&hs, hashpool);
+
+ counter = 0;
+ donerandinit = 1;
+}
+#endif
+
/* Initialise the prng from /dev/urandom or prngd. This function can
* be called multiple times */
void seedrandom() {
@@ -180,8 +203,15 @@ void seedrandom() {
struct timeval tv;
clock_t clockval;
+#ifdef DROPBEAR_FUZZ
+ if (fuzz.fuzzing || fuzz.recordf) {
+ return;
+ }
+#endif
+
/* hash in the new seed data */
sha1_init(&hs);
+
/* existing state */
sha1_process(&hs, (void*)hashpool, sizeof(hashpool));