Merge commits '4392f0f7 ' into temp-merge-1533

This commit is contained in:
mllwchrry
2026-02-09 13:10:17 +02:00
21 changed files with 578 additions and 581 deletions

View File

@@ -18,7 +18,7 @@
static uint64_t secp256k1_test_state[4];
SECP256K1_INLINE static void secp256k1_testrand_seed(const unsigned char *seed16) {
SECP256K1_INLINE static void testrand_seed(const unsigned char *seed16) {
static const unsigned char PREFIX[] = {'s', 'e', 'c', 'p', '2', '5', '6', 'k', '1', ' ', 't', 'e', 's', 't', ' ', 'i', 'n', 'i', 't'};
unsigned char out32[32];
secp256k1_sha256 hash;
@@ -41,7 +41,7 @@ SECP256K1_INLINE static uint64_t rotl(const uint64_t x, int k) {
return (x << k) | (x >> (64 - k));
}
SECP256K1_INLINE static uint64_t secp256k1_testrand64(void) {
SECP256K1_INLINE static uint64_t testrand64(void) {
/* Test-only Xoshiro256++ RNG. See https://prng.di.unimi.it/ */
const uint64_t result = rotl(secp256k1_test_state[0] + secp256k1_test_state[3], 23) + secp256k1_test_state[0];
const uint64_t t = secp256k1_test_state[1] << 17;
@@ -54,16 +54,16 @@ SECP256K1_INLINE static uint64_t secp256k1_testrand64(void) {
return result;
}
SECP256K1_INLINE static uint64_t secp256k1_testrand_bits(int bits) {
SECP256K1_INLINE static uint64_t testrand_bits(int bits) {
if (bits == 0) return 0;
return secp256k1_testrand64() >> (64 - bits);
return testrand64() >> (64 - bits);
}
SECP256K1_INLINE static uint32_t secp256k1_testrand32(void) {
return secp256k1_testrand64() >> 32;
SECP256K1_INLINE static uint32_t testrand32(void) {
return testrand64() >> 32;
}
static uint32_t secp256k1_testrand_int(uint32_t range) {
static uint32_t testrand_int(uint32_t range) {
uint32_t mask = 0;
uint32_t range_copy;
/* Reduce range by 1, changing its meaning to "maximum value". */
@@ -77,15 +77,15 @@ static uint32_t secp256k1_testrand_int(uint32_t range) {
}
/* Generation loop. */
while (1) {
uint32_t val = secp256k1_testrand64() & mask;
uint32_t val = testrand64() & mask;
if (val <= range) return val;
}
}
static void secp256k1_testrand256(unsigned char *b32) {
static void testrand256(unsigned char *b32) {
int i;
for (i = 0; i < 4; ++i) {
uint64_t val = secp256k1_testrand64();
uint64_t val = testrand64();
b32[0] = val;
b32[1] = val >> 8;
b32[2] = val >> 16;
@@ -98,14 +98,14 @@ static void secp256k1_testrand256(unsigned char *b32) {
}
}
static void secp256k1_testrand_bytes_test(unsigned char *bytes, size_t len) {
static void testrand_bytes_test(unsigned char *bytes, size_t len) {
size_t bits = 0;
memset(bytes, 0, len);
while (bits < len * 8) {
int now;
uint32_t val;
now = 1 + (secp256k1_testrand_bits(6) * secp256k1_testrand_bits(5) + 16) / 31;
val = secp256k1_testrand_bits(1);
now = 1 + (testrand_bits(6) * testrand_bits(5) + 16) / 31;
val = testrand_bits(1);
while (now > 0 && bits < len * 8) {
bytes[bits / 8] |= val << (bits % 8);
now--;
@@ -114,11 +114,11 @@ static void secp256k1_testrand_bytes_test(unsigned char *bytes, size_t len) {
}
}
static void secp256k1_testrand256_test(unsigned char *b32) {
secp256k1_testrand_bytes_test(b32, 32);
static void testrand256_test(unsigned char *b32) {
testrand_bytes_test(b32, 32);
}
SECP256K1_INLINE static int64_t secp256k1_testrandi64(uint64_t min, uint64_t max) {
SECP256K1_INLINE static int64_t testrandi64(uint64_t min, uint64_t max) {
uint64_t range;
uint64_t r;
uint64_t clz;
@@ -129,17 +129,17 @@ SECP256K1_INLINE static int64_t secp256k1_testrandi64(uint64_t min, uint64_t max
range = max - min;
clz = secp256k1_clz64_var(range);
do {
r = ((uint64_t)secp256k1_testrand32() << 32) | secp256k1_testrand32();
r = ((uint64_t)testrand32() << 32) | testrand32();
r >>= clz;
} while (r > range);
return min + (int64_t)r;
}
static void secp256k1_testrand_flip(unsigned char *b, size_t len) {
b[secp256k1_testrand_int(len)] ^= (1 << secp256k1_testrand_bits(3));
static void testrand_flip(unsigned char *b, size_t len) {
b[testrand_int(len)] ^= (1 << testrand_bits(3));
}
static void secp256k1_testrand_init(const char* hexseed) {
static void testrand_init(const char* hexseed) {
unsigned char seed16[16] = {0};
if (hexseed && strlen(hexseed) != 0) {
int pos = 0;
@@ -173,12 +173,12 @@ static void secp256k1_testrand_init(const char* hexseed) {
}
printf("random seed = %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", seed16[0], seed16[1], seed16[2], seed16[3], seed16[4], seed16[5], seed16[6], seed16[7], seed16[8], seed16[9], seed16[10], seed16[11], seed16[12], seed16[13], seed16[14], seed16[15]);
secp256k1_testrand_seed(seed16);
testrand_seed(seed16);
}
static void secp256k1_testrand_finish(void) {
static void testrand_finish(void) {
unsigned char run32[32];
secp256k1_testrand256(run32);
testrand256(run32);
printf("random run = %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", run32[0], run32[1], run32[2], run32[3], run32[4], run32[5], run32[6], run32[7], run32[8], run32[9], run32[10], run32[11], run32[12], run32[13], run32[14], run32[15]);
}