tests: refactor: drop secp256k1_ prefix from testrand.h functions
The rename was done with the following command: $ sed -i 's/secp256k1_testrand/testrand/g' $(git grep -l secp256k1_testrand)
This commit is contained in:
@@ -231,7 +231,7 @@ void run_ellswift_tests(void) {
|
||||
/* Generate random public key and random randomizer. */
|
||||
testutil_random_ge_test(&g);
|
||||
secp256k1_pubkey_save(&pubkey, &g);
|
||||
secp256k1_testrand256(rnd32);
|
||||
testrand256(rnd32);
|
||||
/* Convert the public key to ElligatorSwift and back. */
|
||||
secp256k1_ellswift_encode(CTX, ell64, &pubkey, rnd32);
|
||||
secp256k1_ellswift_decode(CTX, &pubkey2, ell64);
|
||||
@@ -249,7 +249,7 @@ void run_ellswift_tests(void) {
|
||||
unsigned char ell64[64];
|
||||
int ret;
|
||||
/* Generate random secret key and random randomizer. */
|
||||
if (i & 1) secp256k1_testrand256_test(auxrnd32);
|
||||
if (i & 1) testrand256_test(auxrnd32);
|
||||
testutil_random_scalar_order_test(&sec);
|
||||
secp256k1_scalar_get_b32(sec32, &sec);
|
||||
/* Construct ElligatorSwift-encoded public keys for that key. */
|
||||
@@ -274,8 +274,8 @@ void run_ellswift_tests(void) {
|
||||
testutil_random_scalar_order_test(&sec);
|
||||
secp256k1_scalar_get_b32(sec32, &sec);
|
||||
/* Generate random ElligatorSwift encoding for the remote key and decode it. */
|
||||
secp256k1_testrand256_test(ell64);
|
||||
secp256k1_testrand256_test(ell64 + 32);
|
||||
testrand256_test(ell64);
|
||||
testrand256_test(ell64 + 32);
|
||||
secp256k1_ellswift_decode(CTX, &pub, ell64);
|
||||
secp256k1_pubkey_load(CTX, &dec, &pub);
|
||||
secp256k1_gej_set_ge(&decj, &dec);
|
||||
@@ -313,14 +313,14 @@ void run_ellswift_tests(void) {
|
||||
data = NULL;
|
||||
} else {
|
||||
hash_function = secp256k1_ellswift_xdh_hash_function_prefix;
|
||||
secp256k1_testrand256_test(prefix64);
|
||||
secp256k1_testrand256_test(prefix64 + 32);
|
||||
testrand256_test(prefix64);
|
||||
testrand256_test(prefix64 + 32);
|
||||
data = prefix64;
|
||||
}
|
||||
|
||||
/* Generate random secret keys and random randomizers. */
|
||||
secp256k1_testrand256_test(auxrnd32a);
|
||||
secp256k1_testrand256_test(auxrnd32b);
|
||||
testrand256_test(auxrnd32a);
|
||||
testrand256_test(auxrnd32b);
|
||||
testutil_random_scalar_order_test(&seca);
|
||||
/* Draw secb uniformly at random to make sure that the secret keys
|
||||
* differ */
|
||||
@@ -349,13 +349,13 @@ void run_ellswift_tests(void) {
|
||||
/* Verify that the shared secret doesn't match if other side's public key is incorrect. */
|
||||
/* For A (using a bad public key for B): */
|
||||
memcpy(ell64b_bad, ell64b, sizeof(ell64a_bad));
|
||||
secp256k1_testrand_flip(ell64b_bad, sizeof(ell64b_bad));
|
||||
testrand_flip(ell64b_bad, sizeof(ell64b_bad));
|
||||
ret = secp256k1_ellswift_xdh(CTX, share32_bad, ell64a, ell64b_bad, sec32a, 0, hash_function, data);
|
||||
CHECK(ret); /* Mismatching encodings don't get detected by secp256k1_ellswift_xdh. */
|
||||
CHECK(secp256k1_memcmp_var(share32_bad, share32a, 32) != 0);
|
||||
/* For B (using a bad public key for A): */
|
||||
memcpy(ell64a_bad, ell64a, sizeof(ell64a_bad));
|
||||
secp256k1_testrand_flip(ell64a_bad, sizeof(ell64a_bad));
|
||||
testrand_flip(ell64a_bad, sizeof(ell64a_bad));
|
||||
ret = secp256k1_ellswift_xdh(CTX, share32_bad, ell64a_bad, ell64b, sec32b, 1, hash_function, data);
|
||||
CHECK(ret);
|
||||
CHECK(secp256k1_memcmp_var(share32_bad, share32b, 32) != 0);
|
||||
@@ -363,12 +363,12 @@ void run_ellswift_tests(void) {
|
||||
/* Verify that the shared secret doesn't match if the private key is incorrect. */
|
||||
/* For A: */
|
||||
memcpy(sec32a_bad, sec32a, sizeof(sec32a_bad));
|
||||
secp256k1_testrand_flip(sec32a_bad, sizeof(sec32a_bad));
|
||||
testrand_flip(sec32a_bad, sizeof(sec32a_bad));
|
||||
ret = secp256k1_ellswift_xdh(CTX, share32_bad, ell64a, ell64b, sec32a_bad, 0, hash_function, data);
|
||||
CHECK(!ret || secp256k1_memcmp_var(share32_bad, share32a, 32) != 0);
|
||||
/* For B: */
|
||||
memcpy(sec32b_bad, sec32b, sizeof(sec32b_bad));
|
||||
secp256k1_testrand_flip(sec32b_bad, sizeof(sec32b_bad));
|
||||
testrand_flip(sec32b_bad, sizeof(sec32b_bad));
|
||||
ret = secp256k1_ellswift_xdh(CTX, share32_bad, ell64a, ell64b, sec32b_bad, 1, hash_function, data);
|
||||
CHECK(!ret || secp256k1_memcmp_var(share32_bad, share32b, 32) != 0);
|
||||
|
||||
@@ -376,7 +376,7 @@ void run_ellswift_tests(void) {
|
||||
/* Verify that the shared secret doesn't match when a different encoding of the same public key is used. */
|
||||
/* For A (changing B's public key): */
|
||||
memcpy(auxrnd32b_bad, auxrnd32b, sizeof(auxrnd32b_bad));
|
||||
secp256k1_testrand_flip(auxrnd32b_bad, sizeof(auxrnd32b_bad));
|
||||
testrand_flip(auxrnd32b_bad, sizeof(auxrnd32b_bad));
|
||||
ret = secp256k1_ellswift_create(CTX, ell64b_bad, sec32b, auxrnd32b_bad);
|
||||
CHECK(ret);
|
||||
ret = secp256k1_ellswift_xdh(CTX, share32_bad, ell64a, ell64b_bad, sec32a, 0, hash_function, data);
|
||||
@@ -384,7 +384,7 @@ void run_ellswift_tests(void) {
|
||||
CHECK(secp256k1_memcmp_var(share32_bad, share32a, 32) != 0);
|
||||
/* For B (changing A's public key): */
|
||||
memcpy(auxrnd32a_bad, auxrnd32a, sizeof(auxrnd32a_bad));
|
||||
secp256k1_testrand_flip(auxrnd32a_bad, sizeof(auxrnd32a_bad));
|
||||
testrand_flip(auxrnd32a_bad, sizeof(auxrnd32a_bad));
|
||||
ret = secp256k1_ellswift_create(CTX, ell64a_bad, sec32a, auxrnd32a_bad);
|
||||
CHECK(ret);
|
||||
ret = secp256k1_ellswift_xdh(CTX, share32_bad, ell64a_bad, ell64b, sec32b, 1, hash_function, data);
|
||||
|
||||
@@ -23,9 +23,9 @@ static void test_xonly_pubkey(void) {
|
||||
int pk_parity;
|
||||
int i;
|
||||
|
||||
secp256k1_testrand256(sk);
|
||||
testrand256(sk);
|
||||
memset(ones32, 0xFF, 32);
|
||||
secp256k1_testrand256(xy_sk);
|
||||
testrand256(xy_sk);
|
||||
CHECK(secp256k1_ec_pubkey_create(CTX, &pk, sk) == 1);
|
||||
CHECK(secp256k1_xonly_pubkey_from_pubkey(CTX, &xonly_pk, &pk_parity, &pk) == 1);
|
||||
|
||||
@@ -95,7 +95,7 @@ static void test_xonly_pubkey(void) {
|
||||
* the curve) then xonly_pubkey_parse should fail as well. */
|
||||
for (i = 0; i < COUNT; i++) {
|
||||
unsigned char rand33[33];
|
||||
secp256k1_testrand256(&rand33[1]);
|
||||
testrand256(&rand33[1]);
|
||||
rand33[0] = SECP256K1_TAG_PUBKEY_EVEN;
|
||||
if (!secp256k1_ec_pubkey_parse(CTX, &pk, rand33, 33)) {
|
||||
memset(&xonly_pk, 1, sizeof(xonly_pk));
|
||||
@@ -152,8 +152,8 @@ static void test_xonly_pubkey_tweak(void) {
|
||||
int i;
|
||||
|
||||
memset(overflows, 0xff, sizeof(overflows));
|
||||
secp256k1_testrand256(tweak);
|
||||
secp256k1_testrand256(sk);
|
||||
testrand256(tweak);
|
||||
testrand256(sk);
|
||||
CHECK(secp256k1_ec_pubkey_create(CTX, &internal_pk, sk) == 1);
|
||||
CHECK(secp256k1_xonly_pubkey_from_pubkey(CTX, &internal_xonly_pk, &pk_parity, &internal_pk) == 1);
|
||||
|
||||
@@ -190,7 +190,7 @@ static void test_xonly_pubkey_tweak(void) {
|
||||
|
||||
/* Invalid pk with a valid tweak */
|
||||
memset(&internal_xonly_pk, 0, sizeof(internal_xonly_pk));
|
||||
secp256k1_testrand256(tweak);
|
||||
testrand256(tweak);
|
||||
CHECK_ILLEGAL(CTX, secp256k1_xonly_pubkey_tweak_add(CTX, &output_pk, &internal_xonly_pk, tweak));
|
||||
CHECK(secp256k1_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0);
|
||||
}
|
||||
@@ -209,8 +209,8 @@ static void test_xonly_pubkey_tweak_check(void) {
|
||||
unsigned char tweak[32];
|
||||
|
||||
memset(overflows, 0xff, sizeof(overflows));
|
||||
secp256k1_testrand256(tweak);
|
||||
secp256k1_testrand256(sk);
|
||||
testrand256(tweak);
|
||||
testrand256(sk);
|
||||
CHECK(secp256k1_ec_pubkey_create(CTX, &internal_pk, sk) == 1);
|
||||
CHECK(secp256k1_xonly_pubkey_from_pubkey(CTX, &internal_xonly_pk, &pk_parity, &internal_pk) == 1);
|
||||
|
||||
@@ -256,7 +256,7 @@ static void test_xonly_pubkey_tweak_recursive(void) {
|
||||
unsigned char tweak[N_PUBKEYS - 1][32];
|
||||
int i;
|
||||
|
||||
secp256k1_testrand256(sk);
|
||||
testrand256(sk);
|
||||
CHECK(secp256k1_ec_pubkey_create(CTX, &pk[0], sk) == 1);
|
||||
/* Add tweaks */
|
||||
for (i = 0; i < N_PUBKEYS - 1; i++) {
|
||||
@@ -292,7 +292,7 @@ static void test_keypair(void) {
|
||||
memset(overflows, 0xFF, sizeof(overflows));
|
||||
|
||||
/* Test keypair_create */
|
||||
secp256k1_testrand256(sk);
|
||||
testrand256(sk);
|
||||
CHECK(secp256k1_keypair_create(CTX, &keypair, sk) == 1);
|
||||
CHECK(secp256k1_memcmp_var(zeros96, &keypair, sizeof(keypair)) != 0);
|
||||
CHECK(secp256k1_keypair_create(CTX, &keypair, sk) == 1);
|
||||
@@ -311,7 +311,7 @@ static void test_keypair(void) {
|
||||
CHECK(secp256k1_memcmp_var(zeros96, &keypair, sizeof(keypair)) == 0);
|
||||
|
||||
/* Test keypair_pub */
|
||||
secp256k1_testrand256(sk);
|
||||
testrand256(sk);
|
||||
CHECK(secp256k1_keypair_create(CTX, &keypair, sk) == 1);
|
||||
CHECK(secp256k1_keypair_pub(CTX, &pk, &keypair) == 1);
|
||||
CHECK_ILLEGAL(CTX, secp256k1_keypair_pub(CTX, NULL, &keypair));
|
||||
@@ -330,7 +330,7 @@ static void test_keypair(void) {
|
||||
CHECK(secp256k1_memcmp_var(&pk, &pk_tmp, sizeof(pk)) == 0);
|
||||
|
||||
/** Test keypair_xonly_pub **/
|
||||
secp256k1_testrand256(sk);
|
||||
testrand256(sk);
|
||||
CHECK(secp256k1_keypair_create(CTX, &keypair, sk) == 1);
|
||||
CHECK(secp256k1_keypair_xonly_pub(CTX, &xonly_pk, &pk_parity, &keypair) == 1);
|
||||
CHECK_ILLEGAL(CTX, secp256k1_keypair_xonly_pub(CTX, NULL, &pk_parity, &keypair));
|
||||
@@ -353,7 +353,7 @@ static void test_keypair(void) {
|
||||
CHECK(pk_parity == pk_parity_tmp);
|
||||
|
||||
/* Test keypair_seckey */
|
||||
secp256k1_testrand256(sk);
|
||||
testrand256(sk);
|
||||
CHECK(secp256k1_keypair_create(CTX, &keypair, sk) == 1);
|
||||
CHECK(secp256k1_keypair_sec(CTX, sk_tmp, &keypair) == 1);
|
||||
CHECK_ILLEGAL(CTX, secp256k1_keypair_sec(CTX, NULL, &keypair));
|
||||
@@ -381,8 +381,8 @@ static void test_keypair_add(void) {
|
||||
int i;
|
||||
|
||||
CHECK(sizeof(zeros96) == sizeof(keypair));
|
||||
secp256k1_testrand256(sk);
|
||||
secp256k1_testrand256(tweak);
|
||||
testrand256(sk);
|
||||
testrand256(tweak);
|
||||
memset(overflows, 0xFF, 32);
|
||||
CHECK(secp256k1_keypair_create(CTX, &keypair, sk) == 1);
|
||||
|
||||
@@ -407,7 +407,7 @@ static void test_keypair_add(void) {
|
||||
for (i = 0; i < COUNT; i++) {
|
||||
secp256k1_scalar scalar_tweak;
|
||||
secp256k1_keypair keypair_tmp;
|
||||
secp256k1_testrand256(sk);
|
||||
testrand256(sk);
|
||||
CHECK(secp256k1_keypair_create(CTX, &keypair, sk) == 1);
|
||||
memcpy(&keypair_tmp, &keypair, sizeof(keypair));
|
||||
/* Because sk may be negated before adding, we need to try with tweak =
|
||||
@@ -423,7 +423,7 @@ static void test_keypair_add(void) {
|
||||
|
||||
/* Invalid keypair with a valid tweak */
|
||||
memset(&keypair, 0, sizeof(keypair));
|
||||
secp256k1_testrand256(tweak);
|
||||
testrand256(tweak);
|
||||
CHECK_ILLEGAL(CTX, secp256k1_keypair_xonly_tweak_add(CTX, &keypair, tweak));
|
||||
CHECK(secp256k1_memcmp_var(&keypair, zeros96, sizeof(keypair)) == 0);
|
||||
/* Only seckey part of keypair invalid */
|
||||
@@ -446,7 +446,7 @@ static void test_keypair_add(void) {
|
||||
unsigned char sk32[32];
|
||||
int pk_parity;
|
||||
|
||||
secp256k1_testrand256(tweak);
|
||||
testrand256(tweak);
|
||||
CHECK(secp256k1_keypair_xonly_pub(CTX, &internal_pk, NULL, &keypair) == 1);
|
||||
CHECK(secp256k1_keypair_xonly_tweak_add(CTX, &keypair, tweak) == 1);
|
||||
CHECK(secp256k1_keypair_xonly_pub(CTX, &output_pk, &pk_parity, &keypair) == 1);
|
||||
|
||||
@@ -25,7 +25,7 @@ static int recovery_test_nonce_function(unsigned char *nonce32, const unsigned c
|
||||
}
|
||||
/* On the next run, return a valid nonce, but flip a coin as to whether or not to fail signing. */
|
||||
memset(nonce32, 1, 32);
|
||||
return secp256k1_testrand_bits(1);
|
||||
return testrand_bits(1);
|
||||
}
|
||||
|
||||
static void test_ecdsa_recovery_api(void) {
|
||||
@@ -141,7 +141,7 @@ static void test_ecdsa_recovery_end_to_end(void) {
|
||||
CHECK(secp256k1_memcmp_var(&pubkey, &recpubkey, sizeof(pubkey)) == 0);
|
||||
/* Serialize/destroy/parse signature and verify again. */
|
||||
CHECK(secp256k1_ecdsa_recoverable_signature_serialize_compact(CTX, sig, &recid, &rsignature[4]) == 1);
|
||||
sig[secp256k1_testrand_bits(6)] += 1 + secp256k1_testrand_int(255);
|
||||
sig[testrand_bits(6)] += 1 + testrand_int(255);
|
||||
CHECK(secp256k1_ecdsa_recoverable_signature_parse_compact(CTX, &rsignature[4], sig, recid) == 1);
|
||||
CHECK(secp256k1_ecdsa_recoverable_signature_convert(CTX, &signature[4], &rsignature[4]) == 1);
|
||||
CHECK(secp256k1_ecdsa_verify(CTX, &signature[4], message, &pubkey) == 0);
|
||||
|
||||
@@ -104,7 +104,7 @@ static void test_exhaustive_schnorrsig_verify(const secp256k1_context *ctx, cons
|
||||
while (e_count_done < EXHAUSTIVE_TEST_ORDER) {
|
||||
secp256k1_scalar e;
|
||||
unsigned char msg32[32];
|
||||
secp256k1_testrand256(msg32);
|
||||
testrand256(msg32);
|
||||
secp256k1_schnorrsig_challenge(&e, sig64, msg32, sizeof(msg32), pk32);
|
||||
/* Only do work if we hit a challenge we haven't tried before. */
|
||||
if (!e_done[e]) {
|
||||
@@ -120,7 +120,7 @@ static void test_exhaustive_schnorrsig_verify(const secp256k1_context *ctx, cons
|
||||
expect_valid = actual_k != -1 && s != EXHAUSTIVE_TEST_ORDER &&
|
||||
(s == (actual_k + actual_d * e) % EXHAUSTIVE_TEST_ORDER);
|
||||
} else {
|
||||
secp256k1_testrand256(sig64 + 32);
|
||||
testrand256(sig64 + 32);
|
||||
expect_valid = 0;
|
||||
}
|
||||
valid = secp256k1_schnorrsig_verify(ctx, sig64, msg32, sizeof(msg32), &pubkeys[d - 1]);
|
||||
@@ -161,7 +161,7 @@ static void test_exhaustive_schnorrsig_sign(const secp256k1_context *ctx, unsign
|
||||
/* Generate random messages until all challenges have been tried. */
|
||||
while (e_count_done < EXHAUSTIVE_TEST_ORDER) {
|
||||
secp256k1_scalar e;
|
||||
secp256k1_testrand256(msg32);
|
||||
testrand256(msg32);
|
||||
secp256k1_schnorrsig_challenge(&e, xonly_pubkey_bytes[k - 1], msg32, sizeof(msg32), xonly_pubkey_bytes[d - 1]);
|
||||
/* Only do work if we hit a challenge we haven't tried before. */
|
||||
if (!e_done[e]) {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
static void nonce_function_bip340_bitflip(unsigned char **args, size_t n_flip, size_t n_bytes, size_t msglen, size_t algolen) {
|
||||
unsigned char nonces[2][32];
|
||||
CHECK(nonce_function_bip340(nonces[0], args[0], msglen, 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_bip340(nonces[1], args[0], msglen, args[1], args[2], args[3], algolen, args[4]) == 1);
|
||||
CHECK(secp256k1_memcmp_var(nonces[0], nonces[1], 32) != 0);
|
||||
}
|
||||
@@ -50,10 +50,10 @@ static void run_nonce_function_bip340_tests(void) {
|
||||
secp256k1_nonce_function_bip340_sha256_tagged_aux(&sha_optimized);
|
||||
test_sha256_eq(&sha, &sha_optimized);
|
||||
|
||||
secp256k1_testrand256(msg);
|
||||
secp256k1_testrand256(key);
|
||||
secp256k1_testrand256(pk);
|
||||
secp256k1_testrand256(aux_rand);
|
||||
testrand256(msg);
|
||||
testrand256(key);
|
||||
testrand256(pk);
|
||||
testrand256(aux_rand);
|
||||
|
||||
/* Check that a bitflip in an argument results in different nonces. */
|
||||
args[0] = msg;
|
||||
@@ -76,12 +76,12 @@ static void run_nonce_function_bip340_tests(void) {
|
||||
CHECK(nonce_function_bip340(nonce, msg, msglen, key, pk, NULL, 0, NULL) == 0);
|
||||
CHECK(nonce_function_bip340(nonce, msg, msglen, key, pk, algo, algolen, NULL) == 1);
|
||||
/* Other algo is fine */
|
||||
secp256k1_testrand_bytes_test(algo, algolen);
|
||||
testrand_bytes_test(algo, algolen);
|
||||
CHECK(nonce_function_bip340(nonce, msg, msglen, key, pk, algo, algolen, NULL) == 1);
|
||||
|
||||
for (i = 0; i < COUNT; i++) {
|
||||
unsigned char nonce2[32];
|
||||
uint32_t offset = secp256k1_testrand_int(msglen - 1);
|
||||
uint32_t offset = testrand_int(msglen - 1);
|
||||
size_t msglen_tmp = (msglen + offset) % msglen;
|
||||
size_t algolen_tmp;
|
||||
|
||||
@@ -90,7 +90,7 @@ static void run_nonce_function_bip340_tests(void) {
|
||||
CHECK(secp256k1_memcmp_var(nonce, nonce2, 32) != 0);
|
||||
|
||||
/* Different algolen gives different nonce */
|
||||
offset = secp256k1_testrand_int(algolen - 1);
|
||||
offset = testrand_int(algolen - 1);
|
||||
algolen_tmp = (algolen + offset) % algolen;
|
||||
CHECK(nonce_function_bip340(nonce2, msg, msglen, key, pk, algo, algolen_tmp, NULL) == 1);
|
||||
CHECK(secp256k1_memcmp_var(nonce, nonce2, 32) != 0);
|
||||
@@ -116,10 +116,10 @@ static void test_schnorrsig_api(void) {
|
||||
secp256k1_schnorrsig_extraparams extraparams = SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT;
|
||||
secp256k1_schnorrsig_extraparams invalid_extraparams = {{ 0 }, NULL, NULL};
|
||||
|
||||
secp256k1_testrand256(sk1);
|
||||
secp256k1_testrand256(sk2);
|
||||
secp256k1_testrand256(sk3);
|
||||
secp256k1_testrand256(msg);
|
||||
testrand256(sk1);
|
||||
testrand256(sk2);
|
||||
testrand256(sk3);
|
||||
testrand256(msg);
|
||||
CHECK(secp256k1_keypair_create(CTX, &keypairs[0], sk1) == 1);
|
||||
CHECK(secp256k1_keypair_create(CTX, &keypairs[1], sk2) == 1);
|
||||
CHECK(secp256k1_keypair_create(CTX, &keypairs[2], sk3) == 1);
|
||||
@@ -813,8 +813,8 @@ static void test_schnorrsig_sign(void) {
|
||||
secp256k1_schnorrsig_extraparams extraparams = SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT;
|
||||
unsigned char aux_rand[32];
|
||||
|
||||
secp256k1_testrand256(sk);
|
||||
secp256k1_testrand256(aux_rand);
|
||||
testrand256(sk);
|
||||
testrand256(aux_rand);
|
||||
CHECK(secp256k1_keypair_create(CTX, &keypair, sk));
|
||||
CHECK(secp256k1_keypair_xonly_pub(CTX, &pk, NULL, &keypair));
|
||||
CHECK(secp256k1_schnorrsig_sign32(CTX, sig, msg, &keypair, NULL) == 1);
|
||||
@@ -861,12 +861,12 @@ static void test_schnorrsig_sign_verify(void) {
|
||||
secp256k1_xonly_pubkey pk;
|
||||
secp256k1_scalar s;
|
||||
|
||||
secp256k1_testrand256(sk);
|
||||
testrand256(sk);
|
||||
CHECK(secp256k1_keypair_create(CTX, &keypair, sk));
|
||||
CHECK(secp256k1_keypair_xonly_pub(CTX, &pk, NULL, &keypair));
|
||||
|
||||
for (i = 0; i < N_SIGS; i++) {
|
||||
secp256k1_testrand256(msg[i]);
|
||||
testrand256(msg[i]);
|
||||
CHECK(secp256k1_schnorrsig_sign32(CTX, sig[i], msg[i], &keypair, NULL));
|
||||
CHECK(secp256k1_schnorrsig_verify(CTX, sig[i], msg[i], sizeof(msg[i]), &pk));
|
||||
}
|
||||
@@ -874,19 +874,19 @@ static void test_schnorrsig_sign_verify(void) {
|
||||
{
|
||||
/* Flip a few bits in the signature and in the message and check that
|
||||
* verify and verify_batch (TODO) fail */
|
||||
size_t sig_idx = secp256k1_testrand_int(N_SIGS);
|
||||
size_t byte_idx = secp256k1_testrand_bits(5);
|
||||
unsigned char xorbyte = secp256k1_testrand_int(254)+1;
|
||||
size_t sig_idx = testrand_int(N_SIGS);
|
||||
size_t byte_idx = testrand_bits(5);
|
||||
unsigned char xorbyte = testrand_int(254)+1;
|
||||
sig[sig_idx][byte_idx] ^= xorbyte;
|
||||
CHECK(!secp256k1_schnorrsig_verify(CTX, sig[sig_idx], msg[sig_idx], sizeof(msg[sig_idx]), &pk));
|
||||
sig[sig_idx][byte_idx] ^= xorbyte;
|
||||
|
||||
byte_idx = secp256k1_testrand_bits(5);
|
||||
byte_idx = testrand_bits(5);
|
||||
sig[sig_idx][32+byte_idx] ^= xorbyte;
|
||||
CHECK(!secp256k1_schnorrsig_verify(CTX, sig[sig_idx], msg[sig_idx], sizeof(msg[sig_idx]), &pk));
|
||||
sig[sig_idx][32+byte_idx] ^= xorbyte;
|
||||
|
||||
byte_idx = secp256k1_testrand_bits(5);
|
||||
byte_idx = testrand_bits(5);
|
||||
msg[sig_idx][byte_idx] ^= xorbyte;
|
||||
CHECK(!secp256k1_schnorrsig_verify(CTX, sig[sig_idx], msg[sig_idx], sizeof(msg[sig_idx]), &pk));
|
||||
msg[sig_idx][byte_idx] ^= xorbyte;
|
||||
@@ -916,9 +916,9 @@ static void test_schnorrsig_sign_verify(void) {
|
||||
{
|
||||
/* Test varying message lengths */
|
||||
unsigned char msg_large[32 * 8];
|
||||
uint32_t msglen = secp256k1_testrand_int(sizeof(msg_large));
|
||||
uint32_t msglen = testrand_int(sizeof(msg_large));
|
||||
for (i = 0; i < sizeof(msg_large); i += 32) {
|
||||
secp256k1_testrand256(&msg_large[i]);
|
||||
testrand256(&msg_large[i]);
|
||||
}
|
||||
CHECK(secp256k1_schnorrsig_sign_custom(CTX, sig[0], msg_large, msglen, &keypair, NULL) == 1);
|
||||
CHECK(secp256k1_schnorrsig_verify(CTX, sig[0], msg_large, msglen, &pk) == 1);
|
||||
@@ -942,7 +942,7 @@ static void test_schnorrsig_taproot(void) {
|
||||
unsigned char sig[64];
|
||||
|
||||
/* Create output key */
|
||||
secp256k1_testrand256(sk);
|
||||
testrand256(sk);
|
||||
CHECK(secp256k1_keypair_create(CTX, &keypair, sk) == 1);
|
||||
CHECK(secp256k1_keypair_xonly_pub(CTX, &internal_pk, NULL, &keypair) == 1);
|
||||
/* In actual taproot the tweak would be hash of internal_pk */
|
||||
@@ -952,7 +952,7 @@ static void test_schnorrsig_taproot(void) {
|
||||
CHECK(secp256k1_xonly_pubkey_serialize(CTX, output_pk_bytes, &output_pk) == 1);
|
||||
|
||||
/* Key spend */
|
||||
secp256k1_testrand256(msg);
|
||||
testrand256(msg);
|
||||
CHECK(secp256k1_schnorrsig_sign32(CTX, sig, msg, &keypair, NULL) == 1);
|
||||
/* Verify key spend */
|
||||
CHECK(secp256k1_xonly_pubkey_parse(CTX, &output_pk, output_pk_bytes) == 1);
|
||||
|
||||
Reference in New Issue
Block a user