Additional comments for the testing PRNG and a seeding fix.

Rw has additional short-cycle inputs because 2^32/0x464fffff >= 2.
pull/11871/head
Gregory Maxwell 10 years ago
parent 6efd6e7777
commit 34b898dc84

@ -11,7 +11,9 @@
#include "libsecp256k1-config.h" #include "libsecp256k1-config.h"
#endif #endif
/** Seed the pseudorandom number generator. */ /* A non-cryptographic RNG used only for test infrastructure. */
/** Seed the pseudorandom number generator for testing. */
SECP256K1_INLINE static void secp256k1_rand_seed(uint64_t v); SECP256K1_INLINE static void secp256k1_rand_seed(uint64_t v);
/** Generate a pseudorandom 32-bit number. */ /** Generate a pseudorandom 32-bit number. */

@ -18,15 +18,19 @@ SECP256K1_INLINE static void secp256k1_rand_seed(uint64_t v) {
secp256k1_Rz = v >> 32; secp256k1_Rz = v >> 32;
secp256k1_Rw = v; secp256k1_Rw = v;
/* There are two seeds with short (length 1) cycles for the Rz PRNG. */
if (secp256k1_Rz == 0 || secp256k1_Rz == 0x9068ffffU) { if (secp256k1_Rz == 0 || secp256k1_Rz == 0x9068ffffU) {
secp256k1_Rz = 111; secp256k1_Rz = 111;
} }
if (secp256k1_Rw == 0 || secp256k1_Rw == 0x464fffffU) { /* There are four seeds with short (length 1) cycles for the Rw PRNG. */
if (secp256k1_Rw == 0 || secp256k1_Rw == 0x464fffffU ||
secp256k1_Rw == 0x8c9ffffeU || secp256k1_Rw == 0xd2effffdU) {
secp256k1_Rw = 111; secp256k1_Rw = 111;
} }
} }
SECP256K1_INLINE static uint32_t secp256k1_rand32(void) { SECP256K1_INLINE static uint32_t secp256k1_rand32(void) {
/* MWC PRNG for tests. */
secp256k1_Rz = 36969 * (secp256k1_Rz & 0xFFFF) + (secp256k1_Rz >> 16); secp256k1_Rz = 36969 * (secp256k1_Rz & 0xFFFF) + (secp256k1_Rz >> 16);
secp256k1_Rw = 18000 * (secp256k1_Rw & 0xFFFF) + (secp256k1_Rw >> 16); secp256k1_Rw = 18000 * (secp256k1_Rw & 0xFFFF) + (secp256k1_Rw >> 16);
return (secp256k1_Rw << 16) + (secp256k1_Rw >> 16) + secp256k1_Rz; return (secp256k1_Rw << 16) + (secp256k1_Rw >> 16) + secp256k1_Rz;

Loading…
Cancel
Save