Skip to content

Commit 17af09d

Browse files
committed
tests: refactor schnorrsig module tagged hash tests
Add a comment for each tag. Make character arrays static const unsigned char. Update to use the sha256_tag_test_internal helper function.
1 parent b20fe62 commit 17af09d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/modules/schnorrsig/tests_impl.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ static void nonce_function_bip340_bitflip(unsigned char **args, size_t n_flip, s
2121
}
2222

2323
static void run_nonce_function_bip340_tests(void) {
24-
unsigned char tag[] = {'B', 'I', 'P', '0', '3', '4', '0', '/', 'n', 'o', 'n', 'c', 'e'};
25-
unsigned char aux_tag[] = {'B', 'I', 'P', '0', '3', '4', '0', '/', 'a', 'u', 'x'};
24+
/* "BIP0340/nonce" */
25+
static const unsigned char tag[] = {'B', 'I', 'P', '0', '3', '4', '0', '/', 'n', 'o', 'n', 'c', 'e'};
26+
/* "BIP0340/aux" */
27+
static const unsigned char aux_tag[] = {'B', 'I', 'P', '0', '3', '4', '0', '/', 'a', 'u', 'x'};
2628
unsigned char algo[] = {'B', 'I', 'P', '0', '3', '4', '0', '/', 'n', 'o', 'n', 'c', 'e'};
2729
size_t algolen = sizeof(algo);
28-
secp256k1_sha256 sha;
2930
secp256k1_sha256 sha_optimized;
3031
unsigned char nonce[32], nonce_z[32];
3132
unsigned char msg[32];
@@ -39,16 +40,15 @@ static void run_nonce_function_bip340_tests(void) {
3940
/* Check that hash initialized by
4041
* secp256k1_nonce_function_bip340_sha256_tagged has the expected
4142
* state. */
42-
secp256k1_sha256_initialize_tagged(&sha, tag, sizeof(tag));
4343
secp256k1_nonce_function_bip340_sha256_tagged(&sha_optimized);
44-
test_sha256_eq(&sha, &sha_optimized);
44+
sha256_tag_test_internal(&sha_optimized, tag, sizeof(tag));
45+
4546

4647
/* Check that hash initialized by
4748
* secp256k1_nonce_function_bip340_sha256_tagged_aux has the expected
4849
* state. */
49-
secp256k1_sha256_initialize_tagged(&sha, aux_tag, sizeof(aux_tag));
5050
secp256k1_nonce_function_bip340_sha256_tagged_aux(&sha_optimized);
51-
test_sha256_eq(&sha, &sha_optimized);
51+
sha256_tag_test_internal(&sha_optimized, aux_tag, sizeof(aux_tag));
5252

5353
testrand256(msg);
5454
testrand256(key);

0 commit comments

Comments
 (0)