From 0e03d170e62110441d5d59e47b8e2bccaa02c8f4 Mon Sep 17 00:00:00 2001 From: David Adrian Date: Wed, 16 Oct 2013 17:22:22 -0400 Subject: [PATCH] Fix bug where only 16 bits of entropy was used Always use aesrand_getword() & 0xFFFFFFFF not 0xFFFF. This was causing the groups used over multiple runs of ZMap to have identical generators too often. --- src/cyclic.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cyclic.c b/src/cyclic.c index 814a49c..912c958 100644 --- a/src/cyclic.c +++ b/src/cyclic.c @@ -126,7 +126,8 @@ static int check_coprime(uint64_t check, const cyclic_group_t *group) static uint64_t find_primroot(const cyclic_group_t *group) { // what luck, rand() returns a uint32_t! - uint32_t candidate = (uint32_t) aesrand_getword() & 0xFFFF; + uint32_t candidate = (uint32_t) aesrand_getword() & 0xFFFFFFFF; + printf("Candidate: %u\n", (unsigned) candidate); while(check_coprime(candidate, group) != COPRIME) { ++candidate; } @@ -186,14 +187,14 @@ int cyclic_init(uint32_t primroot_, uint32_t current_) primroot = find_primroot(cur_group); } while (primroot >= (1LL << 32)); log_debug(LSRC, "primitive root: %lld", primroot); - current = (uint32_t) aesrand_getword() & 0xFFFF; + current = (uint32_t) aesrand_getword() & 0xFFFFFFFF; log_debug(LSRC, "starting point: %lld", current); } else { primroot = primroot_; log_debug(LSRC, "primitive root %lld specified by caller", primroot); if (!current_) { - current = (uint32_t) aesrand_getword() & 0xFFFF; + current = (uint32_t) aesrand_getword() & 0xFFFFFFFF; log_debug(LSRC, "no cyclic starting point, " "selected random startpoint: %lld", current);