Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bench_whitelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static void random_scalar_order(secp256k1_scalar *num) {
do {
unsigned char b32[32];
int overflow = 0;
secp256k1_testrand256(b32);
testrand256(b32);
secp256k1_scalar_set_b32(num, b32, &overflow);
if (overflow || secp256k1_scalar_is_zero(num)) {
continue;
Expand Down
34 changes: 17 additions & 17 deletions src/modules/bppp/tests_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,20 +208,20 @@ static void test_serialize_two_points(void) {
int i;

for (i = 0; i < COUNT; i++) {
random_group_element_test(&X);
random_group_element_test(&R);
testutil_random_ge_test(&X);
testutil_random_ge_test(&R);
test_serialize_two_points_roundtrip(&X, &R);
}

for (i = 0; i < COUNT; i++) {
random_group_element_test(&X);
testutil_random_ge_test(&X);
secp256k1_ge_set_infinity(&R);
test_serialize_two_points_roundtrip(&X, &R);
}

for (i = 0; i < COUNT; i++) {
secp256k1_ge_set_infinity(&X);
random_group_element_test(&R);
testutil_random_ge_test(&R);
test_serialize_two_points_roundtrip(&X, &R);
}

Expand All @@ -233,12 +233,12 @@ static void test_serialize_two_points(void) {
{
secp256k1_ge X_tmp, R_tmp;
unsigned char buf[65];
random_group_element_test(&X);
random_group_element_test(&R);
testutil_random_ge_test(&X);
testutil_random_ge_test(&R);
secp256k1_bppp_serialize_points(buf, &X, &R);

/* buf is valid if 0 <= buf[0] < 4. */
buf[0] = (unsigned char)secp256k1_testrandi64(4, 255);
buf[0] = (unsigned char)testrandi64(4, 255);
CHECK(!secp256k1_bppp_parse_one_of_points(&X_tmp, buf, 0));
CHECK(!secp256k1_bppp_parse_one_of_points(&R_tmp, buf, 0));
}
Expand All @@ -247,8 +247,8 @@ static void test_serialize_two_points(void) {
secp256k1_ge X_tmp, R_tmp;
unsigned char buf[65];
int expect;
random_group_element_test(&X);
random_group_element_test(&R);
testutil_random_ge_test(&X);
testutil_random_ge_test(&R);
secp256k1_bppp_serialize_points(buf, &X, &R);
memset(&buf[1], 0, 32);
if ((buf[0] & 2) == 0) {
Expand Down Expand Up @@ -446,12 +446,12 @@ static void norm_arg_verify_zero_len(void) {
secp256k1_bppp_generators *gs = secp256k1_bppp_generators_create(CTX, n_vec_len + c_vec_len);
size_t plen = sizeof(proof);

random_scalar_order(&rho);
testutil_random_scalar_order(&rho);
secp256k1_scalar_sqr(&mu, &rho);

random_scalar_order(&n_vec[0]);
random_scalar_order(&c_vec[0]);
random_scalar_order(&l_vec[0]);
testutil_random_scalar_order(&n_vec[0]);
testutil_random_scalar_order(&c_vec[0]);
testutil_random_scalar_order(&l_vec[0]);
CHECK(secp256k1_bppp_commit(CTX, scratch, &commit, gs, n_vec, n_vec_len, l_vec, c_vec_len, c_vec, c_vec_len, &mu));
CHECK(secp256k1_norm_arg_prove(scratch, proof, &plen, &rho, gs, n_vec, n_vec_len, l_vec, c_vec_len, c_vec, c_vec_len, &commit));
CHECK(secp256k1_norm_arg_verify(scratch, proof, plen, &rho, gs, n_vec_len, c_vec, c_vec_len, &commit));
Expand All @@ -472,16 +472,16 @@ static void norm_arg_test(unsigned int n, unsigned int m) {
secp256k1_scratch *scratch = secp256k1_scratch_space_create(CTX, 1000*1000); /* shouldn't need much */
unsigned char proof[1000];
plen = 1000;
random_scalar_order(&rho);
testutil_random_scalar_order(&rho);
secp256k1_scalar_sqr(&mu, &rho);

for (i = 0; i < n; i++) {
random_scalar_order(&n_vec[i]);
testutil_random_scalar_order(&n_vec[i]);
}

for (i = 0; i < m; i++) {
random_scalar_order(&l_vec[i]);
random_scalar_order(&c_vec[i]);
testutil_random_scalar_order(&l_vec[i]);
testutil_random_scalar_order(&c_vec[i]);
}

res = secp256k1_bppp_commit(CTX, scratch, &commit, gs, n_vec, n, l_vec, m, c_vec, m, &mu);
Expand Down
6 changes: 3 additions & 3 deletions src/modules/ecdh/tests_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static void test_ecdh_generator_basepoint(void) {
size_t point_ser_len = sizeof(point_ser);
secp256k1_scalar s;

random_scalar_order(&s);
testutil_random_scalar_order(&s);
secp256k1_scalar_get_b32(s_b32, &s);

CHECK(secp256k1_ec_pubkey_create(CTX, &point[0], s_one) == 1);
Expand Down Expand Up @@ -95,7 +95,7 @@ static void test_bad_scalar(void) {
secp256k1_pubkey point;

/* Create random point */
random_scalar_order(&rand);
testutil_random_scalar_order(&rand);
secp256k1_scalar_get_b32(s_rand, &rand);
CHECK(secp256k1_ec_pubkey_create(CTX, &point, s_rand) == 1);

Expand Down Expand Up @@ -127,7 +127,7 @@ static void test_result_basepoint(void) {
CHECK(secp256k1_ecdh(CTX, out_base, &point, s_one, NULL, NULL) == 1);

for (i = 0; i < 2 * COUNT; i++) {
random_scalar_order(&rand);
testutil_random_scalar_order(&rand);
secp256k1_scalar_get_b32(s, &rand);
secp256k1_scalar_inverse(&rand, &rand);
secp256k1_scalar_get_b32(s_inv, &rand);
Expand Down
50 changes: 25 additions & 25 deletions src/modules/ecdsa_adaptor/tests_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

static void rand_scalar(secp256k1_scalar *scalar) {
unsigned char buf32[32];
secp256k1_testrand256(buf32);
testrand256(buf32);
secp256k1_scalar_set_b32(scalar, buf32, NULL);
}

Expand All @@ -22,7 +22,7 @@ static void dleq_nonce_bitflip(unsigned char **args, size_t n_flip, size_t n_byt
secp256k1_scalar k1, k2;

CHECK(secp256k1_dleq_nonce(&k1, args[0], args[1], args[2], args[3], NULL, args[4]) == 1);
secp256k1_testrand_flip(args[n_flip], n_bytes);
testrand_flip(args[n_flip], n_bytes);
CHECK(secp256k1_dleq_nonce(&k2, args[0], args[1], args[2], args[3], NULL, args[4]) == 1);
CHECK(secp256k1_scalar_eq(&k1, &k2) == 0);
}
Expand Down Expand Up @@ -73,11 +73,11 @@ static void dleq_tests(void) {
CHECK(secp256k1_eckey_pubkey_serialize(&p2, p2_33, &pubkey_size, 1));
CHECK(secp256k1_dleq_nonce(&k, sk32, gen2_33, p1_33, p2_33, NULL, NULL) == 1);

secp256k1_testrand_bytes_test(sk32, sizeof(sk32));
secp256k1_testrand_bytes_test(gen2_33, sizeof(gen2_33));
secp256k1_testrand_bytes_test(p1_33, sizeof(p1_33));
secp256k1_testrand_bytes_test(p2_33, sizeof(p2_33));
secp256k1_testrand_bytes_test(aux_rand, sizeof(aux_rand));
testrand_bytes_test(sk32, sizeof(sk32));
testrand_bytes_test(gen2_33, sizeof(gen2_33));
testrand_bytes_test(p1_33, sizeof(p1_33));
testrand_bytes_test(p2_33, sizeof(p2_33));
testrand_bytes_test(aux_rand, sizeof(aux_rand));

/* Check that a bitflip in an argument results in different nonces. */
args[0] = sk32;
Expand All @@ -101,7 +101,7 @@ static void dleq_tests(void) {
}

static void rand_flip_bit(unsigned char *array, size_t n) {
array[secp256k1_testrand_int(n)] ^= 1 << secp256k1_testrand_int(8);
array[testrand_int(n)] ^= 1 << testrand_int(8);
}

/* Helper function for test_ecdsa_adaptor_spec_vectors
Expand Down Expand Up @@ -713,7 +713,7 @@ static int ecdsa_adaptor_nonce_function_overflowing(unsigned char *nonce32, cons
static void nonce_function_ecdsa_adaptor_bitflip(unsigned char **args, size_t n_flip, size_t n_bytes, size_t algolen) {
unsigned char nonces[2][32];
CHECK(nonce_function_ecdsa_adaptor(nonces[0], args[0], args[1], args[2], args[3], algolen, args[4]) == 1);
secp256k1_testrand_flip(args[n_flip], n_bytes);
testrand_flip(args[n_flip], n_bytes);
CHECK(nonce_function_ecdsa_adaptor(nonces[1], args[0], args[1], args[2], args[3], algolen, args[4]) == 1);
CHECK(secp256k1_memcmp_var(nonces[0], nonces[1], 32) != 0);
}
Expand Down Expand Up @@ -766,10 +766,10 @@ static void run_nonce_function_ecdsa_adaptor_tests(void) {
secp256k1_nonce_function_dleq_sha256_tagged(&sha_optimized);
ecdsa_adaptor_test_sha256_eq(&sha, &sha_optimized);

secp256k1_testrand_bytes_test(msg, sizeof(msg));
secp256k1_testrand_bytes_test(key, sizeof(key));
secp256k1_testrand_bytes_test(pk, sizeof(pk));
secp256k1_testrand_bytes_test(aux_rand, sizeof(aux_rand));
testrand_bytes_test(msg, sizeof(msg));
testrand_bytes_test(key, sizeof(key));
testrand_bytes_test(pk, sizeof(pk));
testrand_bytes_test(aux_rand, sizeof(aux_rand));

/* Check that a bitflip in an argument results in different nonces. */
args[0] = msg;
Expand Down Expand Up @@ -802,7 +802,7 @@ static void run_nonce_function_ecdsa_adaptor_tests(void) {
/* Different algolen gives different nonce */
for (i = 0; i < COUNT; i++) {
unsigned char nonce2[32];
uint32_t offset = secp256k1_testrand_int(algolen - 1);
uint32_t offset = testrand_int(algolen - 1);
size_t algolen_tmp = (algolen + offset) % algolen;

CHECK(nonce_function_ecdsa_adaptor(nonce2, msg, key, pk, algo, algolen_tmp, NULL) == 1);
Expand All @@ -824,9 +824,9 @@ static void test_ecdsa_adaptor_api(void) {
unsigned char deckey[32];

/** setup **/
secp256k1_testrand256(sk);
secp256k1_testrand256(msg);
secp256k1_testrand256(deckey);
testrand256(sk);
testrand256(msg);
testrand256(deckey);
CHECK(secp256k1_ec_pubkey_create(CTX, &pubkey, sk) == 1);
CHECK(secp256k1_ec_pubkey_create(CTX, &enckey, deckey) == 1);
memset(&zero_pk, 0, sizeof(zero_pk));
Expand Down Expand Up @@ -877,9 +877,9 @@ static void adaptor_tests(void) {
unsigned char zeros64[64] = { 0 };
unsigned char big[32];

secp256k1_testrand256(seckey);
secp256k1_testrand256(msg);
secp256k1_testrand256(deckey);
testrand256(seckey);
testrand256(msg);
testrand256(deckey);

CHECK(secp256k1_ec_pubkey_create(CTX, &pubkey, seckey) == 1);
CHECK(secp256k1_ec_pubkey_create(CTX, &enckey, deckey) == 1);
Expand Down Expand Up @@ -1082,19 +1082,19 @@ static void multi_hop_lock_tests(void) {
secp256k1_scalar deckey;
secp256k1_ecdsa_signature sig_ab, sig_bc;

secp256k1_testrand256(seckey_a);
secp256k1_testrand256(seckey_b);
testrand256(seckey_a);
testrand256(seckey_b);

CHECK(secp256k1_ec_pubkey_create(CTX, &pubkey_a, seckey_a));
CHECK(secp256k1_ec_pubkey_create(CTX, &pubkey_b, seckey_b));

/* Carol setup */
/* Proof of payment */
secp256k1_testrand256(pop);
testrand256(pop);
CHECK(secp256k1_ec_pubkey_create(CTX, &pubkey_pop, pop));

/* Alice setup */
secp256k1_testrand256(tx_ab);
testrand256(tx_ab);
rand_scalar(&t1);
rand_scalar(&t2);
secp256k1_scalar_add(&tp, &t1, &t2);
Expand All @@ -1110,7 +1110,7 @@ static void multi_hop_lock_tests(void) {

/* Bob setup */
CHECK(secp256k1_ecdsa_adaptor_verify(CTX, asig_ab, &pubkey_a, tx_ab, &l));
secp256k1_testrand256(tx_bc);
testrand256(tx_bc);
CHECK(secp256k1_ecdsa_adaptor_encrypt(CTX, asig_bc, seckey_b, &r, tx_bc, NULL, NULL));

/* Carol decrypt */
Expand Down
20 changes: 10 additions & 10 deletions src/modules/ecdsa_s2c/tests_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static void run_s2c_opening_test(void) {
CHECK(secp256k1_ecdsa_s2c_opening_serialize(CTX, output, &opening) == 1);
CHECK(secp256k1_memcmp_var(output, input, sizeof(output)) == 0);
}
secp256k1_testrand256(&input[1]);
testrand256(&input[1]);
/* Set pubkey oddness tag to first bit of input[1] */
input[0] = (input[1] & 1) + 2;
}
Expand Down Expand Up @@ -195,14 +195,14 @@ static void test_ecdsa_s2c_sign_verify(void) {
/* Generate a random key, message, noncedata and s2c_data. */
{
secp256k1_scalar key;
random_scalar_order_test(&key);
testutil_random_scalar_order_test(&key);
secp256k1_scalar_get_b32(privkey, &key);
CHECK(secp256k1_ec_pubkey_create(CTX, &pubkey, privkey) == 1);

secp256k1_testrand256_test(message);
secp256k1_testrand256_test(noncedata);
secp256k1_testrand256_test(s2c_data);
secp256k1_testrand256_test(s2c_data2);
testrand256_test(message);
testrand256_test(noncedata);
testrand256_test(s2c_data);
testrand256_test(s2c_data2);
}

{ /* invalid privkeys */
Expand Down Expand Up @@ -270,11 +270,11 @@ static void test_ecdsa_anti_exfil(void) {
/* Generate a random key, message. */
{
secp256k1_scalar key;
random_scalar_order_test(&key);
testutil_random_scalar_order_test(&key);
secp256k1_scalar_get_b32(signer_privkey, &key);
CHECK(secp256k1_ec_pubkey_create(CTX, &signer_pubkey, signer_privkey) == 1);
secp256k1_testrand256_test(host_msg);
secp256k1_testrand256_test(host_nonce_contribution);
testrand256_test(host_msg);
testrand256_test(host_nonce_contribution);
}

/* Protocol step 1. */
Expand Down Expand Up @@ -307,7 +307,7 @@ static void test_ecdsa_anti_exfil(void) {
}
{ /* host_verify: message does not match */
unsigned char bad_msg[32];
secp256k1_testrand256_test(bad_msg);
testrand256_test(bad_msg);
CHECK(secp256k1_anti_exfil_host_verify(CTX, &signature, host_msg, &signer_pubkey, host_nonce_contribution, &s2c_opening) == 1);
CHECK(secp256k1_anti_exfil_host_verify(CTX, &signature, bad_msg, &signer_pubkey, host_nonce_contribution, &s2c_opening) == 0);
}
Expand Down
Loading
Loading