diff --git a/src/modules/rangeproof/tests_impl.h b/src/modules/rangeproof/tests_impl.h index bd5b5b89..7b8a610c 100644 --- a/src/modules/rangeproof/tests_impl.h +++ b/src/modules/rangeproof/tests_impl.h @@ -280,11 +280,11 @@ static void test_pedersen(void) { } totalv = 0; for (i = 0; i < inputs; i++) { - values[i] = secp256k1_rands64(0, INT64_MAX - totalv); + values[i] = secp256k1_testrandi64(0, INT64_MAX - totalv); totalv += values[i]; } for (i = 0; i < outputs - 1; i++) { - values[i + inputs] = secp256k1_rands64(0, totalv); + values[i + inputs] = secp256k1_testrandi64(0, totalv); totalv -= values[i + inputs]; } values[total - 1] = totalv; @@ -480,7 +480,7 @@ static void test_rangeproof(void) { secp256k1_testrand256(blind); { /*Malleability test.*/ - v = secp256k1_rands64(0, 255); + v = secp256k1_testrandi64(0, 255); CHECK(secp256k1_pedersen_commit(ctx, &commit, blind, v, secp256k1_generator_h)); len = 5134; CHECK(secp256k1_rangeproof_sign(ctx, proof, &len, 0, &commit, blind, commit.data, 0, 3, v, NULL, 0, NULL, 0, secp256k1_generator_h)); @@ -501,19 +501,19 @@ static void test_rangeproof(void) { for (i = 0; i < (size_t) 2*count; i++) { int exp; int min_bits; - v = secp256k1_rands64(0, UINT64_MAX >> (secp256k1_testrand32()&63)); + v = secp256k1_testrandi64(0, UINT64_MAX >> (secp256k1_testrand32()&63)); vmin = 0; if ((v < INT64_MAX) && (secp256k1_testrand32()&1)) { - vmin = secp256k1_rands64(0, v); + vmin = secp256k1_testrandi64(0, v); } secp256k1_testrand256(blind); CHECK(secp256k1_pedersen_commit(ctx, &commit, blind, v, secp256k1_generator_h)); len = 5134; - exp = (int)secp256k1_rands64(0,18)-(int)secp256k1_rands64(0,18); + exp = (int)secp256k1_testrandi64(0,18)-(int)secp256k1_testrandi64(0,18); if (exp < 0) { exp = -exp; } - min_bits = (int)secp256k1_rands64(0,64)-(int)secp256k1_rands64(0,64); + min_bits = (int)secp256k1_testrandi64(0,64)-(int)secp256k1_testrandi64(0,64); if (min_bits < 0) { min_bits = -min_bits; } @@ -540,7 +540,7 @@ static void test_rangeproof(void) { len = k; CHECK(!secp256k1_rangeproof_verify(ctx, &minv, &maxv, &commit2, proof, len, NULL, 0, secp256k1_generator_h)); } - len = secp256k1_rands64(0, 3072); + len = secp256k1_testrandi64(0, 3072); CHECK(!secp256k1_rangeproof_verify(ctx, &minv, &maxv, &commit2, proof, len, NULL, 0, secp256k1_generator_h)); } } @@ -582,11 +582,11 @@ void test_multiple_generators(void) { /* Compute all the values -- can be positive or negative */ total_value = 0; for (i = 0; i < n_outputs; i++) { - value[n_inputs + i] = secp256k1_rands64(0, INT64_MAX - total_value); + value[n_inputs + i] = secp256k1_testrandi64(0, INT64_MAX - total_value); total_value += value[n_inputs + i]; } for (i = 0; i < n_inputs - 1; i++) { - value[i] = secp256k1_rands64(0, total_value); + value[i] = secp256k1_testrandi64(0, total_value); total_value -= value[i]; } value[i] = total_value; diff --git a/src/testrand_impl.h b/src/testrand_impl.h index 725ef9cc..d80cae03 100644 --- a/src/testrand_impl.h +++ b/src/testrand_impl.h @@ -109,7 +109,7 @@ static void secp256k1_testrand256_test(unsigned char *b32) { secp256k1_testrand_bytes_test(b32, 32); } -SECP256K1_INLINE static int64_t secp256k1_rands64(uint64_t min, uint64_t max) { +SECP256K1_INLINE static int64_t secp256k1_testrandi64(uint64_t min, uint64_t max) { uint64_t range; uint64_t r; uint64_t clz; diff --git a/src/tests.c b/src/tests.c index 223608eb..33aef6ed 100644 --- a/src/tests.c +++ b/src/tests.c @@ -171,11 +171,11 @@ void run_util_tests(void) { for (i = 0; i < 10; i++) { CHECK(secp256k1_clz64_var((~0ULL) - secp256k1_testrand32()) == 0); r = ((uint64_t)secp256k1_testrand32() << 32) | secp256k1_testrand32(); - r2 = secp256k1_rands64(0, r); + r2 = secp256k1_testrandi64(0, r); CHECK(r2 <= r); - r3 = secp256k1_rands64(r2, r); + r3 = secp256k1_testrandi64(r2, r); CHECK((r3 >= r2) && (r3 <= r)); - r = secp256k1_rands64(0, INT64_MAX); + r = secp256k1_testrandi64(0, INT64_MAX); s = (int64_t)r * (secp256k1_testrand32()&1?-1:1); CHECK(secp256k1_sign_and_abs64(&r2, s) == (s < 0)); CHECK(r2 == r);