Skip to content

Commit f92fd5c

Browse files
committed
Merge #303: ci: backport upstream string-initializer fixes and clean up related tests
7d779c6 examples/musig: use brace-enclosed initializer for 32-byte msg (BEULAHEVANJALIN) 53fd89b musig/tests: initialize keypair (Jonas Nick) 40bd854 musig/test: Remove dead code (Tim Ruffing) c457030 test/fix: refactor unterminated string initializers to brace arrays - Mirror upstream fix (bitcoin-core/secp256k1 fa67b675) - Convert tags, test vectors, and constants in -zkp-only modules (ecdsa_adaptor, ecdsa_s2c, musig, bppp, rangeproof, schnorrsig_halfagg) - Avoid -Wunterminated-string-initialization without changing behavior (BEULAHEVANJALIN) 654a8c3 refactor: Use array initialization for unterminated strings (MarcoFalke) Pull request description: ACKs for top commit: real-or-random: utACK 7d779c6 thanks! jonasnick: ACK 7d779c6 Tree-SHA512: edb9885a36eab499dee05e0c87a184f139ba6f68c01128ae692ab1195546ba8ff77d0c0b06faa22164fd89fd27935fd68b1e9c04a1fc9bcd0b7d6472515095dd
2 parents f9a04ae + 7d779c6 commit f92fd5c

File tree

14 files changed

+44
-45
lines changed

14 files changed

+44
-45
lines changed

examples/musig.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static int sign(const secp256k1_context* ctx, struct signer_secrets *signer_secr
169169
const secp256k1_pubkey *pubkeys_ptr[N_SIGNERS];
170170
secp256k1_xonly_pubkey agg_pk;
171171
secp256k1_musig_keyagg_cache cache;
172-
unsigned char msg[32] = "this_could_be_the_hash_of_a_msg!";
172+
unsigned char msg[] = {'t', 'h', 'i', 's', '_', 'c', 'o', 'u', 'l', 'd', ' ', 'b', 'e', ' ', 't', 'h', 'e', '_', 'h', 'a', 's', 'h', '_', 'o', 'f', '_', 'a', '_', 'm', 's', 'g', '!'};
173173
unsigned char sig[64];
174174

175175
/* Create a secp256k1 context */

examples/schnorr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#include "examples_util.h"
1919

2020
int main(void) {
21-
unsigned char msg[12] = "Hello World!";
21+
unsigned char msg[] = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!'};
2222
unsigned char msg_hash[32];
23-
unsigned char tag[17] = "my_fancy_protocol";
23+
unsigned char tag[] = {'m', 'y', '_', 'f', 'a', 'n', 'c', 'y', '_', 'p', 'r', 'o', 't', 'o', 'c', 'o', 'l'};
2424
unsigned char seckey[32];
2525
unsigned char randomize[32];
2626
unsigned char auxiliary_rand[32];

src/modules/bppp/tests_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static void test_bppp_generators_fixed(void) {
103103
}
104104

105105
static void test_bppp_tagged_hash(void) {
106-
unsigned char tag_data[29] = "Bulletproofs_pp/v0/commitment";
106+
unsigned char tag_data[] = {'B', 'u', 'l', 'l', 'e', 't', 'p', 'r', 'o', 'o', 'f', 's', '_', 'p', 'p', '/', 'v', '0', '/', 'c', 'o', 'm', 'm', 'i', 't', 'm', 'e', 'n', 't'};
107107
secp256k1_sha256 sha;
108108
secp256k1_sha256 sha_cached;
109109
unsigned char output[32];

src/modules/ecdsa_adaptor/dleq_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static void secp256k1_nonce_function_dleq_sha256_tagged(secp256k1_sha256 *sha) {
1818
}
1919

2020
/* algo argument for nonce_function_ecdsa_adaptor to derive the nonce using a tagged hash function. */
21-
static const unsigned char dleq_algo[4] = "DLEQ";
21+
static const unsigned char dleq_algo[] = {'D','L','E','Q'};
2222

2323
static int secp256k1_dleq_hash_point(secp256k1_sha256 *sha, secp256k1_ge *p) {
2424
unsigned char buf[33];

src/modules/ecdsa_adaptor/main_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static void secp256k1_nonce_function_ecdsa_adaptor_sha256_tagged_aux(secp256k1_s
9898
}
9999

100100
/* algo argument for nonce_function_ecdsa_adaptor to derive the nonce using a tagged hash function. */
101-
static const unsigned char ecdsa_adaptor_algo[16] = "ECDSAadaptor/non";
101+
static const unsigned char ecdsa_adaptor_algo[] = {'E', 'C', 'D', 'S', 'A', 'a', 'd', 'a', 'p', 't', 'o', 'r', '/', 'n', 'o', 'n'};
102102

103103
/* Modified BIP-340 nonce function */
104104
static int nonce_function_ecdsa_adaptor(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *pk33, const unsigned char *algo, size_t algolen, void *data) {

src/modules/ecdsa_adaptor/tests_impl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,11 +730,11 @@ static void ecdsa_adaptor_test_sha256_eq(const secp256k1_sha256 *sha1, const sec
730730
}
731731

732732
static void run_nonce_function_ecdsa_adaptor_tests(void) {
733-
unsigned char tag[16] = "ECDSAadaptor/non";
734-
unsigned char aux_tag[16] = "ECDSAadaptor/aux";
735-
unsigned char algo[16] = "ECDSAadaptor/non";
733+
unsigned char tag[] = {'E', 'C', 'D', 'S', 'A', 'a', 'd', 'a', 'p', 't', 'o', 'r', '/', 'n', 'o', 'n'};
734+
unsigned char aux_tag[] = {'E', 'C', 'D', 'S', 'A', 'a', 'd', 'a', 'p', 't', 'o', 'r', '/', 'a', 'u', 'x'};
735+
unsigned char algo[] = {'E', 'C', 'D', 'S', 'A', 'a', 'd', 'a', 'p', 't', 'o', 'r', '/', 'n', 'o', 'n'};
736736
size_t algolen = sizeof(algo);
737-
unsigned char dleq_tag[4] = "DLEQ";
737+
unsigned char dleq_tag[] = {'D', 'L', 'E', 'Q'};
738738
secp256k1_sha256 sha;
739739
secp256k1_sha256 sha_optimized;
740740
unsigned char nonce[32];

src/modules/ecdsa_s2c/tests_impl.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include "../../../include/secp256k1_ecdsa_s2c.h"
1111

1212
static void test_ecdsa_s2c_tagged_hash(void) {
13-
unsigned char tag_data[14] = "s2c/ecdsa/data";
14-
unsigned char tag_point[15] = "s2c/ecdsa/point";
13+
unsigned char tag_data[] = {'s', '2', 'c', '/', 'e', 'c', 'd', 's', 'a', '/', 'd', 'a', 't', 'a'};
14+
unsigned char tag_point[] = {'s', '2', 'c', '/', 'e', 'c', 'd', 's', 'a', '/', 'p', 'o', 'i', 'n', 't'};
1515
secp256k1_sha256 sha;
1616
secp256k1_sha256 sha_optimized;
1717
unsigned char output[32];
@@ -78,10 +78,10 @@ static void run_s2c_opening_test(void) {
7878
static void test_ecdsa_s2c_api(void) {
7979
secp256k1_ecdsa_s2c_opening s2c_opening;
8080
secp256k1_ecdsa_signature sig;
81-
const unsigned char msg[32] = "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm";
82-
const unsigned char sec[32] = "ssssssssssssssssssssssssssssssss";
83-
const unsigned char s2c_data[32] = "dddddddddddddddddddddddddddddddd";
84-
const unsigned char hostrand[32] = "hrhrhrhrhrhrhrhrhrhrhrhrhrhrhrhr";
81+
const unsigned char msg[] = {'m', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm'};
82+
const unsigned char sec[] = {'s', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's'};
83+
const unsigned char s2c_data[] = {'d', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd'};
84+
const unsigned char hostrand[] = {'h', 'r', 'h', 'r', 'h', 'r', 'h', 'r', 'h', 'r', 'h', 'r', 'h', 'r', 'h', 'r', 'h', 'r', 'h', 'r', 'h', 'r', 'h', 'r', 'h', 'r', 'h', 'r', 'h', 'r', 'h', 'r'};
8585
unsigned char hostrand_commitment[32];
8686
secp256k1_pubkey pk;
8787

@@ -148,14 +148,14 @@ typedef struct {
148148

149149
static ecdsa_s2c_test ecdsa_s2c_tests[] = {
150150
{
151-
"\x1b\xf6\xfb\x42\xf4\x1e\xb8\x76\xc4\xd7\xaa\x0d\x67\x24\x2b\x00\xba\xab\x99\xdc\x20\x84\x49\x3e\x4e\x63\x27\x7f\xa1\xf7\x7f\x22",
152-
"\x03\xf0\x30\xde\xf3\x18\x8c\x0f\x56\xfc\xea\x87\x43\x5b\x30\x76\x43\xf4\x5d\xaf\xe2\x2c\xbc\x82\xfd\x56\x03\x4f\xae\x97\x41\x7d\x3a",
153-
"\x02\xdf\x63\x75\x5d\x1f\x32\x92\xbf\xfe\xd8\x29\x86\xb1\x06\x49\x7c\x93\xb1\xf8\xbd\xc0\x45\x4b\x6b\x0b\x0a\x47\x79\xc0\xef\x71\x88",
151+
{0x1b, 0xf6, 0xfb, 0x42, 0xf4, 0x1e, 0xb8, 0x76, 0xc4, 0xd7, 0xaa, 0x0d, 0x67, 0x24, 0x2b, 0x00, 0xba, 0xab, 0x99, 0xdc, 0x20, 0x84, 0x49, 0x3e, 0x4e, 0x63, 0x27, 0x7f, 0xa1, 0xf7, 0x7f, 0x22},
152+
{0x03, 0xf0, 0x30, 0xde, 0xf3, 0x18, 0x8c, 0x0f, 0x56, 0xfc, 0xea, 0x87, 0x43, 0x5b, 0x30, 0x76, 0x43, 0xf4, 0x5d, 0xaf, 0xe2, 0x2c, 0xbc, 0x82, 0xfd, 0x56, 0x03, 0x4f, 0xae, 0x97, 0x41, 0x7d, 0x3a},
153+
{0x02, 0xdf, 0x63, 0x75, 0x5d, 0x1f, 0x32, 0x92, 0xbf, 0xfe, 0xd8, 0x29, 0x86, 0xb1, 0x06, 0x49, 0x7c, 0x93, 0xb1, 0xf8, 0xbd, 0xc0, 0x45, 0x4b, 0x6b, 0x0b, 0x0a, 0x47, 0x79, 0xc0, 0xef, 0x71, 0x88},
154154
},
155155
{
156-
"\x35\x19\x9a\x8f\xbf\x84\xad\x6e\xf6\x9a\x18\x4c\x1b\x19\x28\x5b\xef\xbe\x06\xe6\x0b\x62\x64\xe6\xd3\x73\x89\x3f\x68\x55\xe2\x4a",
157-
"\x03\x90\x17\x17\xce\x7c\x74\x84\xa2\xce\x1b\x7d\xc7\x40\x3b\x14\xe0\x35\x49\x71\x39\x3e\xc0\x92\xa7\xf3\xe0\xc8\xe4\xe2\xd2\x63\x9d",
158-
"\x02\xc0\x4a\xc7\xf7\x71\xe8\xeb\xdb\xf3\x15\xff\x5e\x58\xb7\xfe\x95\x16\x10\x21\x03\x50\x00\x66\x17\x2c\x4f\xac\x5b\x20\xf9\xe0\xea",
156+
{0x35, 0x19, 0x9a, 0x8f, 0xbf, 0x84, 0xad, 0x6e, 0xf6, 0x9a, 0x18, 0x4c, 0x1b, 0x19, 0x28, 0x5b, 0xef, 0xbe, 0x06, 0xe6, 0x0b, 0x62, 0x64, 0xe6, 0xd3, 0x73, 0x89, 0x3f, 0x68, 0x55, 0xe2, 0x4a},
157+
{0x03, 0x90, 0x17, 0x17, 0xce, 0x7c, 0x74, 0x84, 0xa2, 0xce, 0x1b, 0x7d, 0xc7, 0x40, 0x3b, 0x14, 0xe0, 0x35, 0x49, 0x71, 0x39, 0x3e, 0xc0, 0x92, 0xa7, 0xf3, 0xe0, 0xc8, 0xe4, 0xe2, 0xd2, 0x63, 0x9d},
158+
{0x02, 0xc0, 0x4a, 0xc7, 0xf7, 0x71, 0xe8, 0xeb, 0xdb, 0xf3, 0x15, 0xff, 0x5e, 0x58, 0xb7, 0xfe, 0x95, 0x16, 0x10, 0x21, 0x03, 0x50, 0x00, 0x66, 0x17, 0x2c, 0x4f, 0xac, 0x5b, 0x20, 0xf9, 0xe0, 0xea},
159159
},
160160
};
161161

@@ -207,7 +207,7 @@ static void test_ecdsa_s2c_sign_verify(void) {
207207

208208
{ /* invalid privkeys */
209209
unsigned char zero_privkey[32] = {0};
210-
unsigned char overflow_privkey[32] = "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
210+
unsigned char overflow_privkey[32] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
211211
CHECK(secp256k1_ecdsa_s2c_sign(CTX, &signature, NULL, message, zero_privkey, s2c_data) == 0);
212212
CHECK(secp256k1_ecdsa_s2c_sign(CTX, &signature, NULL, message, overflow_privkey, s2c_data) == 0);
213213
}

src/modules/ellswift/tests_impl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,9 @@ void run_ellswift_tests(void) {
406406
/* Test hash initializers. */
407407
{
408408
secp256k1_sha256 sha, sha_optimized;
409-
static const unsigned char encode_tag[25] = "secp256k1_ellswift_encode";
410-
static const unsigned char create_tag[25] = "secp256k1_ellswift_create";
411-
static const unsigned char bip324_tag[26] = "bip324_ellswift_xonly_ecdh";
409+
static const unsigned char encode_tag[] = {'s', 'e', 'c', 'p', '2', '5', '6', 'k', '1', '_', 'e', 'l', 'l', 's', 'w', 'i', 'f', 't', '_', 'e', 'n', 'c', 'o', 'd', 'e'};
410+
static const unsigned char create_tag[] = {'s', 'e', 'c', 'p', '2', '5', '6', 'k', '1', '_', 'e', 'l', 'l', 's', 'w', 'i', 'f', 't', '_', 'c', 'r', 'e', 'a', 't', 'e'};
411+
static const unsigned char bip324_tag[] = {'b', 'i', 'p', '3', '2', '4', '_', 'e', 'l', 'l', 's', 'w', 'i', 'f', 't', '_', 'x', 'o', 'n', 'l', 'y', '_', 'e', 'c', 'd', 'h'};
412412

413413
/* Check that hash initialized by
414414
* secp256k1_ellswift_sha256_init_encode has the expected

src/modules/musig/tests_impl.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,8 @@ static void scriptless_atomic_swap(secp256k1_scratch_space *scratch) {
579579
int nonce_parity_b;
580580
unsigned char seed_a[2][32] = { "a0", "a1" };
581581
unsigned char seed_b[2][32] = { "b0", "b1" };
582-
const unsigned char msg32_a[32] = "this is the message blockchain a";
583-
const unsigned char msg32_b[32] = "this is the message blockchain b";
582+
const unsigned char msg32_a[32] = {'t', 'h', 'i', 's', ' ', 'i', 's', ' ', 't', 'h', 'e', ' ', 'm', 'e', 's', 's', 'a', 'g', 'e', ' ', 'b', 'l', 'o', 'c', 'k', 'c', 'h', 'a', 'i', 'n', ' ', 'a'};
583+
const unsigned char msg32_b[32] = {'t', 'h', 'i', 's', ' ', 'i', 's', ' ', 't', 'h', 'e', ' ', 'm', 'e', 's', 's', 'a', 'g', 'e', ' ', 'b', 'l', 'o', 'c', 'k', 'c', 'h', 'a', 'i', 'n', ' ', 'b'};
584584
int i;
585585

586586
/* Step 1: key setup */
@@ -676,12 +676,12 @@ static void sha256_tag_test_internal(secp256k1_sha256 *sha_tagged, unsigned char
676676
static void sha256_tag_test(void) {
677677
secp256k1_sha256 sha_tagged;
678678
{
679-
char tag[11] = "KeyAgg list";
679+
char tag[] = {'K', 'e', 'y', 'A', 'g', 'g', ' ', 'l', 'i', 's', 't'};
680680
secp256k1_musig_keyagglist_sha256(&sha_tagged);
681681
sha256_tag_test_internal(&sha_tagged, (unsigned char*)tag, sizeof(tag));
682682
}
683683
{
684-
char tag[18] = "KeyAgg coefficient";
684+
char tag[] = {'K', 'e', 'y', 'A', 'g', 'g', ' ', 'c', 'o', 'e', 'f', 'f', 'i', 'c', 'i', 'e', 'n', 't'};
685685
secp256k1_musig_keyaggcoef_sha256(&sha_tagged);
686686
sha256_tag_test_internal(&sha_tagged, (unsigned char*)tag, sizeof(tag));
687687
}
@@ -1013,6 +1013,8 @@ static void musig_test_vectors_signverify(void) {
10131013
if (!expected) {
10141014
continue;
10151015
}
1016+
CHECK(secp256k1_ec_pubkey_parse(CTX, &pubkey, vector->pubkeys[0], sizeof(vector->pubkeys[0])));
1017+
CHECK(secp256k1_keypair_create(CTX, &keypair, vector->sk));
10161018

10171019
expected = c->error != MUSIG_AGGNONCE;
10181020
CHECK(expected == secp256k1_musig_aggnonce_parse(CTX, &aggnonce, vector->aggnonces[c->aggnonce_index]));
@@ -1022,13 +1024,10 @@ static void musig_test_vectors_signverify(void) {
10221024
CHECK(secp256k1_musig_nonce_process(CTX, &session, &aggnonce, vector->msgs[c->msg_index], &keyagg_cache, NULL));
10231025

10241026
CHECK(secp256k1_ec_pubkey_parse(CTX, &pubkey, vector->pubkeys[0], sizeof(vector->pubkeys[0])));
1025-
musig_test_set_secnonce(&secnonce, vector->secnonces[c->secnonce_index], &pubkey);
10261027
expected = c->error != MUSIG_SECNONCE;
1027-
if (expected) {
1028-
CHECK(secp256k1_musig_partial_sign(CTX, &partial_sig, &secnonce, &keypair, &keyagg_cache, &session));
1029-
} else {
1030-
CHECK_ILLEGAL(CTX, secp256k1_musig_partial_sign(CTX, &partial_sig, &secnonce, &keypair, &keyagg_cache, &session));
1031-
}
1028+
CHECK(!expected);
1029+
musig_test_set_secnonce(&secnonce, vector->secnonces[c->secnonce_index], &pubkey);
1030+
CHECK_ILLEGAL(CTX, secp256k1_musig_partial_sign(CTX, &partial_sig, &secnonce, &keypair, &keyagg_cache, &session));
10321031
}
10331032
for (i = 0; i < sizeof(vector->verify_fail_case)/sizeof(vector->verify_fail_case[0]); i++) {
10341033
const struct musig_verify_fail_error_case *c = &vector->verify_fail_case[i];

src/modules/rangeproof/tests_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ static void test_single_value_proof(uint64_t val) {
414414
unsigned char blind[32];
415415
unsigned char blind_out[32];
416416
unsigned char nonce[32];
417-
const unsigned char message[1] = " "; /* no message will fit into a single-value proof */
417+
const unsigned char message[] = { ' ' }; /* no message will fit into a single-value proof */
418418
unsigned char message_out[sizeof(proof)] = { 0 };
419419
size_t plen = sizeof(proof);
420420
uint64_t min_val_out = 0;

0 commit comments

Comments
 (0)