Skip to content

Commit 34b898d

Browse files
committed
Additional comments for the testing PRNG and a seeding fix.
Rw has additional short-cycle inputs because 2^32/0x464fffff >= 2.
1 parent 6efd6e7 commit 34b898d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/testrand.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
#include "libsecp256k1-config.h"
1212
#endif
1313

14-
/** Seed the pseudorandom number generator. */
14+
/* A non-cryptographic RNG used only for test infrastructure. */
15+
16+
/** Seed the pseudorandom number generator for testing. */
1517
SECP256K1_INLINE static void secp256k1_rand_seed(uint64_t v);
1618

1719
/** Generate a pseudorandom 32-bit number. */

src/testrand_impl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@ SECP256K1_INLINE static void secp256k1_rand_seed(uint64_t v) {
1818
secp256k1_Rz = v >> 32;
1919
secp256k1_Rw = v;
2020

21+
/* There are two seeds with short (length 1) cycles for the Rz PRNG. */
2122
if (secp256k1_Rz == 0 || secp256k1_Rz == 0x9068ffffU) {
2223
secp256k1_Rz = 111;
2324
}
24-
if (secp256k1_Rw == 0 || secp256k1_Rw == 0x464fffffU) {
25+
/* There are four seeds with short (length 1) cycles for the Rw PRNG. */
26+
if (secp256k1_Rw == 0 || secp256k1_Rw == 0x464fffffU ||
27+
secp256k1_Rw == 0x8c9ffffeU || secp256k1_Rw == 0xd2effffdU) {
2528
secp256k1_Rw = 111;
2629
}
2730
}
2831

2932
SECP256K1_INLINE static uint32_t secp256k1_rand32(void) {
33+
/* MWC PRNG for tests. */
3034
secp256k1_Rz = 36969 * (secp256k1_Rz & 0xFFFF) + (secp256k1_Rz >> 16);
3135
secp256k1_Rw = 18000 * (secp256k1_Rw & 0xFFFF) + (secp256k1_Rw >> 16);
3236
return (secp256k1_Rw << 16) + (secp256k1_Rw >> 16) + secp256k1_Rz;

0 commit comments

Comments
 (0)