Skip to content

Commit 6173839

Browse files
real-or-randomsipa
authored andcommitted
Switch to our own memcmp function
Fixes #823.
1 parent 63150ab commit 6173839

File tree

12 files changed

+191
-173
lines changed

12 files changed

+191
-173
lines changed

src/modules/ecdh/tests_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void test_ecdh_generator_basepoint(void) {
8080
/* compute "explicitly" */
8181
CHECK(secp256k1_ec_pubkey_serialize(ctx, point_ser, &point_ser_len, &point[1], SECP256K1_EC_UNCOMPRESSED) == 1);
8282
/* compare */
83-
CHECK(memcmp(output_ecdh, point_ser, 65) == 0);
83+
CHECK(secp256k1_memcmp_var(output_ecdh, point_ser, 65) == 0);
8484

8585
/* compute using ECDH function with default hash function */
8686
CHECK(secp256k1_ecdh(ctx, output_ecdh, &point[0], s_b32, NULL, NULL) == 1);
@@ -90,7 +90,7 @@ void test_ecdh_generator_basepoint(void) {
9090
secp256k1_sha256_write(&sha, point_ser, point_ser_len);
9191
secp256k1_sha256_finalize(&sha, output_ser);
9292
/* compare */
93-
CHECK(memcmp(output_ecdh, output_ser, 32) == 0);
93+
CHECK(secp256k1_memcmp_var(output_ecdh, output_ser, 32) == 0);
9494
}
9595
}
9696

src/modules/extrakeys/main_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ int secp256k1_xonly_pubkey_tweak_add_check(const secp256k1_context* ctx, const u
124124
secp256k1_fe_normalize_var(&pk.y);
125125
secp256k1_fe_get_b32(pk_expected32, &pk.x);
126126

127-
return memcmp(&pk_expected32, tweaked_pubkey32, 32) == 0
127+
return secp256k1_memcmp_var(&pk_expected32, tweaked_pubkey32, 32) == 0
128128
&& secp256k1_fe_is_odd(&pk.y) == tweaked_pk_parity;
129129
}
130130

src/modules/extrakeys/tests_exhaustive_impl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ static void test_exhaustive_extrakeys(const secp256k1_context *ctx, const secp25
3838
/* Parse the xonly_pubkey back and verify it matches the previously serialized value. */
3939
CHECK(secp256k1_xonly_pubkey_parse(ctx, &xonly_pubkey[i - 1], xonly_pubkey_bytes[i - 1]));
4040
CHECK(secp256k1_xonly_pubkey_serialize(ctx, buf, &xonly_pubkey[i - 1]));
41-
CHECK(memcmp(xonly_pubkey_bytes[i - 1], buf, 32) == 0);
41+
CHECK(secp256k1_memcmp_var(xonly_pubkey_bytes[i - 1], buf, 32) == 0);
4242

4343
/* Construct the xonly_pubkey from the pubkey, and verify it matches the same. */
4444
CHECK(secp256k1_xonly_pubkey_from_pubkey(ctx, &xonly_pubkey[i - 1], &parity, &pubkey[i - 1]));
4545
CHECK(parity == parities[i - 1]);
4646
CHECK(secp256k1_xonly_pubkey_serialize(ctx, buf, &xonly_pubkey[i - 1]));
47-
CHECK(memcmp(xonly_pubkey_bytes[i - 1], buf, 32) == 0);
47+
CHECK(secp256k1_memcmp_var(xonly_pubkey_bytes[i - 1], buf, 32) == 0);
4848

4949
/* Compare the xonly_pubkey bytes against the precomputed group. */
5050
secp256k1_fe_set_b32(&fe, xonly_pubkey_bytes[i - 1]);
@@ -57,7 +57,7 @@ static void test_exhaustive_extrakeys(const secp256k1_context *ctx, const secp25
5757

5858
/* Verify that the higher half is identical to the lower half mirrored. */
5959
if (i > EXHAUSTIVE_TEST_ORDER / 2) {
60-
CHECK(memcmp(xonly_pubkey_bytes[i - 1], xonly_pubkey_bytes[EXHAUSTIVE_TEST_ORDER - i - 1], 32) == 0);
60+
CHECK(secp256k1_memcmp_var(xonly_pubkey_bytes[i - 1], xonly_pubkey_bytes[EXHAUSTIVE_TEST_ORDER - i - 1], 32) == 0);
6161
CHECK(parities[i - 1] == 1 - parities[EXHAUSTIVE_TEST_ORDER - i - 1]);
6262
}
6363
}

src/modules/extrakeys/tests_impl.h

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ void test_xonly_pubkey(void) {
6060
sk[0] = 1;
6161
CHECK(secp256k1_ec_pubkey_create(ctx, &pk, sk) == 1);
6262
CHECK(secp256k1_xonly_pubkey_from_pubkey(ctx, &xonly_pk, &pk_parity, &pk) == 1);
63-
CHECK(memcmp(&pk, &xonly_pk, sizeof(pk)) == 0);
63+
CHECK(secp256k1_memcmp_var(&pk, &xonly_pk, sizeof(pk)) == 0);
6464
CHECK(pk_parity == 0);
6565

6666
/* Choose a secret key such that pubkey and xonly_pubkey are each others
6767
* negation. */
6868
sk[0] = 2;
6969
CHECK(secp256k1_ec_pubkey_create(ctx, &pk, sk) == 1);
7070
CHECK(secp256k1_xonly_pubkey_from_pubkey(ctx, &xonly_pk, &pk_parity, &pk) == 1);
71-
CHECK(memcmp(&xonly_pk, &pk, sizeof(xonly_pk)) != 0);
71+
CHECK(secp256k1_memcmp_var(&xonly_pk, &pk, sizeof(xonly_pk)) != 0);
7272
CHECK(pk_parity == 1);
7373
secp256k1_pubkey_load(ctx, &pk1, &pk);
7474
secp256k1_pubkey_load(ctx, &pk2, (secp256k1_pubkey *) &xonly_pk);
@@ -81,7 +81,7 @@ void test_xonly_pubkey(void) {
8181
CHECK(secp256k1_xonly_pubkey_serialize(none, NULL, &xonly_pk) == 0);
8282
CHECK(ecount == 1);
8383
CHECK(secp256k1_xonly_pubkey_serialize(none, buf32, NULL) == 0);
84-
CHECK(memcmp(buf32, zeros64, 32) == 0);
84+
CHECK(secp256k1_memcmp_var(buf32, zeros64, 32) == 0);
8585
CHECK(ecount == 2);
8686
{
8787
/* A pubkey filled with 0s will fail to serialize due to pubkey_load
@@ -104,17 +104,17 @@ void test_xonly_pubkey(void) {
104104
CHECK(secp256k1_xonly_pubkey_from_pubkey(none, &xonly_pk, NULL, &pk) == 1);
105105
CHECK(secp256k1_xonly_pubkey_serialize(ctx, buf32, &xonly_pk) == 1);
106106
CHECK(secp256k1_xonly_pubkey_parse(ctx, &xonly_pk_tmp, buf32) == 1);
107-
CHECK(memcmp(&xonly_pk, &xonly_pk_tmp, sizeof(xonly_pk)) == 0);
107+
CHECK(secp256k1_memcmp_var(&xonly_pk, &xonly_pk_tmp, sizeof(xonly_pk)) == 0);
108108

109109
/* Test parsing invalid field elements */
110110
memset(&xonly_pk, 1, sizeof(xonly_pk));
111111
/* Overflowing field element */
112112
CHECK(secp256k1_xonly_pubkey_parse(none, &xonly_pk, ones32) == 0);
113-
CHECK(memcmp(&xonly_pk, zeros64, sizeof(xonly_pk)) == 0);
113+
CHECK(secp256k1_memcmp_var(&xonly_pk, zeros64, sizeof(xonly_pk)) == 0);
114114
memset(&xonly_pk, 1, sizeof(xonly_pk));
115115
/* There's no point with x-coordinate 0 on secp256k1 */
116116
CHECK(secp256k1_xonly_pubkey_parse(none, &xonly_pk, zeros64) == 0);
117-
CHECK(memcmp(&xonly_pk, zeros64, sizeof(xonly_pk)) == 0);
117+
CHECK(secp256k1_memcmp_var(&xonly_pk, zeros64, sizeof(xonly_pk)) == 0);
118118
/* If a random 32-byte string can not be parsed with ec_pubkey_parse
119119
* (because interpreted as X coordinate it does not correspond to a point on
120120
* the curve) then xonly_pubkey_parse should fail as well. */
@@ -125,7 +125,7 @@ void test_xonly_pubkey(void) {
125125
if (!secp256k1_ec_pubkey_parse(ctx, &pk, rand33, 33)) {
126126
memset(&xonly_pk, 1, sizeof(xonly_pk));
127127
CHECK(secp256k1_xonly_pubkey_parse(ctx, &xonly_pk, &rand33[1]) == 0);
128-
CHECK(memcmp(&xonly_pk, zeros64, sizeof(xonly_pk)) == 0);
128+
CHECK(secp256k1_memcmp_var(&xonly_pk, zeros64, sizeof(xonly_pk)) == 0);
129129
} else {
130130
CHECK(secp256k1_xonly_pubkey_parse(ctx, &xonly_pk, &rand33[1]) == 1);
131131
}
@@ -170,15 +170,15 @@ void test_xonly_pubkey_tweak(void) {
170170
CHECK(secp256k1_xonly_pubkey_tweak_add(verify, &output_pk, NULL, tweak) == 0);
171171
CHECK(ecount == 4);
172172
/* NULL internal_xonly_pk zeroes the output_pk */
173-
CHECK(memcmp(&output_pk, zeros64, sizeof(output_pk)) == 0);
173+
CHECK(secp256k1_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0);
174174
CHECK(secp256k1_xonly_pubkey_tweak_add(verify, &output_pk, &internal_xonly_pk, NULL) == 0);
175175
CHECK(ecount == 5);
176176
/* NULL tweak zeroes the output_pk */
177-
CHECK(memcmp(&output_pk, zeros64, sizeof(output_pk)) == 0);
177+
CHECK(secp256k1_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0);
178178

179179
/* Invalid tweak zeroes the output_pk */
180180
CHECK(secp256k1_xonly_pubkey_tweak_add(verify, &output_pk, &internal_xonly_pk, overflows) == 0);
181-
CHECK(memcmp(&output_pk, zeros64, sizeof(output_pk)) == 0);
181+
CHECK(secp256k1_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0);
182182

183183
/* A zero tweak is fine */
184184
CHECK(secp256k1_xonly_pubkey_tweak_add(verify, &output_pk, &internal_xonly_pk, zeros64) == 1);
@@ -193,7 +193,7 @@ void test_xonly_pubkey_tweak(void) {
193193
secp256k1_scalar_get_b32(tweak, &scalar_tweak);
194194
CHECK((secp256k1_xonly_pubkey_tweak_add(verify, &output_pk, &internal_xonly_pk, sk) == 0)
195195
|| (secp256k1_xonly_pubkey_tweak_add(verify, &output_pk, &internal_xonly_pk, tweak) == 0));
196-
CHECK(memcmp(&output_pk, zeros64, sizeof(output_pk)) == 0);
196+
CHECK(secp256k1_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0);
197197
}
198198

199199
/* Invalid pk with a valid tweak */
@@ -202,7 +202,7 @@ void test_xonly_pubkey_tweak(void) {
202202
ecount = 0;
203203
CHECK(secp256k1_xonly_pubkey_tweak_add(verify, &output_pk, &internal_xonly_pk, tweak) == 0);
204204
CHECK(ecount == 1);
205-
CHECK(memcmp(&output_pk, zeros64, sizeof(output_pk)) == 0);
205+
CHECK(secp256k1_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0);
206206

207207
secp256k1_context_destroy(none);
208208
secp256k1_context_destroy(sign);
@@ -268,7 +268,7 @@ void test_xonly_pubkey_tweak_check(void) {
268268
/* Overflowing tweak not allowed */
269269
CHECK(secp256k1_xonly_pubkey_tweak_add_check(ctx, output_pk32, pk_parity, &internal_xonly_pk, overflows) == 0);
270270
CHECK(secp256k1_xonly_pubkey_tweak_add(ctx, &output_pk, &internal_xonly_pk, overflows) == 0);
271-
CHECK(memcmp(&output_pk, zeros64, sizeof(output_pk)) == 0);
271+
CHECK(secp256k1_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0);
272272
CHECK(ecount == 5);
273273

274274
secp256k1_context_destroy(none);
@@ -329,23 +329,23 @@ void test_keypair(void) {
329329
ecount = 0;
330330
secp256k1_testrand256(sk);
331331
CHECK(secp256k1_keypair_create(none, &keypair, sk) == 0);
332-
CHECK(memcmp(zeros96, &keypair, sizeof(keypair)) == 0);
332+
CHECK(secp256k1_memcmp_var(zeros96, &keypair, sizeof(keypair)) == 0);
333333
CHECK(ecount == 1);
334334
CHECK(secp256k1_keypair_create(verify, &keypair, sk) == 0);
335-
CHECK(memcmp(zeros96, &keypair, sizeof(keypair)) == 0);
335+
CHECK(secp256k1_memcmp_var(zeros96, &keypair, sizeof(keypair)) == 0);
336336
CHECK(ecount == 2);
337337
CHECK(secp256k1_keypair_create(sign, &keypair, sk) == 1);
338338
CHECK(secp256k1_keypair_create(sign, NULL, sk) == 0);
339339
CHECK(ecount == 3);
340340
CHECK(secp256k1_keypair_create(sign, &keypair, NULL) == 0);
341-
CHECK(memcmp(zeros96, &keypair, sizeof(keypair)) == 0);
341+
CHECK(secp256k1_memcmp_var(zeros96, &keypair, sizeof(keypair)) == 0);
342342
CHECK(ecount == 4);
343343

344344
/* Invalid secret key */
345345
CHECK(secp256k1_keypair_create(sign, &keypair, zeros96) == 0);
346-
CHECK(memcmp(zeros96, &keypair, sizeof(keypair)) == 0);
346+
CHECK(secp256k1_memcmp_var(zeros96, &keypair, sizeof(keypair)) == 0);
347347
CHECK(secp256k1_keypair_create(sign, &keypair, overflows) == 0);
348-
CHECK(memcmp(zeros96, &keypair, sizeof(keypair)) == 0);
348+
CHECK(secp256k1_memcmp_var(zeros96, &keypair, sizeof(keypair)) == 0);
349349

350350
/* Test keypair_pub */
351351
ecount = 0;
@@ -356,18 +356,18 @@ void test_keypair(void) {
356356
CHECK(ecount == 1);
357357
CHECK(secp256k1_keypair_pub(none, &pk, NULL) == 0);
358358
CHECK(ecount == 2);
359-
CHECK(memcmp(zeros96, &pk, sizeof(pk)) == 0);
359+
CHECK(secp256k1_memcmp_var(zeros96, &pk, sizeof(pk)) == 0);
360360

361361
/* Using an invalid keypair is fine for keypair_pub */
362362
memset(&keypair, 0, sizeof(keypair));
363363
CHECK(secp256k1_keypair_pub(none, &pk, &keypair) == 1);
364-
CHECK(memcmp(zeros96, &pk, sizeof(pk)) == 0);
364+
CHECK(secp256k1_memcmp_var(zeros96, &pk, sizeof(pk)) == 0);
365365

366366
/* keypair holds the same pubkey as pubkey_create */
367367
CHECK(secp256k1_ec_pubkey_create(sign, &pk, sk) == 1);
368368
CHECK(secp256k1_keypair_create(sign, &keypair, sk) == 1);
369369
CHECK(secp256k1_keypair_pub(none, &pk_tmp, &keypair) == 1);
370-
CHECK(memcmp(&pk, &pk_tmp, sizeof(pk)) == 0);
370+
CHECK(secp256k1_memcmp_var(&pk, &pk_tmp, sizeof(pk)) == 0);
371371

372372
/** Test keypair_xonly_pub **/
373373
ecount = 0;
@@ -379,21 +379,21 @@ void test_keypair(void) {
379379
CHECK(secp256k1_keypair_xonly_pub(none, &xonly_pk, NULL, &keypair) == 1);
380380
CHECK(secp256k1_keypair_xonly_pub(none, &xonly_pk, &pk_parity, NULL) == 0);
381381
CHECK(ecount == 2);
382-
CHECK(memcmp(zeros96, &xonly_pk, sizeof(xonly_pk)) == 0);
382+
CHECK(secp256k1_memcmp_var(zeros96, &xonly_pk, sizeof(xonly_pk)) == 0);
383383
/* Using an invalid keypair will set the xonly_pk to 0 (first reset
384384
* xonly_pk). */
385385
CHECK(secp256k1_keypair_xonly_pub(none, &xonly_pk, &pk_parity, &keypair) == 1);
386386
memset(&keypair, 0, sizeof(keypair));
387387
CHECK(secp256k1_keypair_xonly_pub(none, &xonly_pk, &pk_parity, &keypair) == 0);
388-
CHECK(memcmp(zeros96, &xonly_pk, sizeof(xonly_pk)) == 0);
388+
CHECK(secp256k1_memcmp_var(zeros96, &xonly_pk, sizeof(xonly_pk)) == 0);
389389
CHECK(ecount == 3);
390390

391391
/** keypair holds the same xonly pubkey as pubkey_create **/
392392
CHECK(secp256k1_ec_pubkey_create(sign, &pk, sk) == 1);
393393
CHECK(secp256k1_xonly_pubkey_from_pubkey(none, &xonly_pk, &pk_parity, &pk) == 1);
394394
CHECK(secp256k1_keypair_create(sign, &keypair, sk) == 1);
395395
CHECK(secp256k1_keypair_xonly_pub(none, &xonly_pk_tmp, &pk_parity_tmp, &keypair) == 1);
396-
CHECK(memcmp(&xonly_pk, &xonly_pk_tmp, sizeof(pk)) == 0);
396+
CHECK(secp256k1_memcmp_var(&xonly_pk, &xonly_pk_tmp, sizeof(pk)) == 0);
397397
CHECK(pk_parity == pk_parity_tmp);
398398

399399
secp256k1_context_destroy(none);
@@ -429,12 +429,12 @@ void test_keypair_add(void) {
429429
CHECK(secp256k1_keypair_xonly_tweak_add(verify, &keypair, NULL) == 0);
430430
CHECK(ecount == 4);
431431
/* This does not set the keypair to zeroes */
432-
CHECK(memcmp(&keypair, zeros96, sizeof(keypair)) != 0);
432+
CHECK(secp256k1_memcmp_var(&keypair, zeros96, sizeof(keypair)) != 0);
433433

434434
/* Invalid tweak zeroes the keypair */
435435
CHECK(secp256k1_keypair_create(ctx, &keypair, sk) == 1);
436436
CHECK(secp256k1_keypair_xonly_tweak_add(ctx, &keypair, overflows) == 0);
437-
CHECK(memcmp(&keypair, zeros96, sizeof(keypair)) == 0);
437+
CHECK(secp256k1_memcmp_var(&keypair, zeros96, sizeof(keypair)) == 0);
438438

439439
/* A zero tweak is fine */
440440
CHECK(secp256k1_keypair_create(ctx, &keypair, sk) == 1);
@@ -454,8 +454,8 @@ void test_keypair_add(void) {
454454
secp256k1_scalar_get_b32(tweak, &scalar_tweak);
455455
CHECK((secp256k1_keypair_xonly_tweak_add(ctx, &keypair, sk) == 0)
456456
|| (secp256k1_keypair_xonly_tweak_add(ctx, &keypair_tmp, tweak) == 0));
457-
CHECK(memcmp(&keypair, zeros96, sizeof(keypair)) == 0
458-
|| memcmp(&keypair_tmp, zeros96, sizeof(keypair_tmp)) == 0);
457+
CHECK(secp256k1_memcmp_var(&keypair, zeros96, sizeof(keypair)) == 0
458+
|| secp256k1_memcmp_var(&keypair_tmp, zeros96, sizeof(keypair_tmp)) == 0);
459459
}
460460

461461
/* Invalid keypair with a valid tweak */
@@ -464,7 +464,7 @@ void test_keypair_add(void) {
464464
ecount = 0;
465465
CHECK(secp256k1_keypair_xonly_tweak_add(verify, &keypair, tweak) == 0);
466466
CHECK(ecount == 1);
467-
CHECK(memcmp(&keypair, zeros96, sizeof(keypair)) == 0);
467+
CHECK(secp256k1_memcmp_var(&keypair, zeros96, sizeof(keypair)) == 0);
468468
/* Only seckey part of keypair invalid */
469469
CHECK(secp256k1_keypair_create(ctx, &keypair, sk) == 1);
470470
memset(&keypair, 0, 32);
@@ -498,11 +498,11 @@ void test_keypair_add(void) {
498498
/* Check that the resulting pubkey matches xonly_pubkey_tweak_add */
499499
CHECK(secp256k1_keypair_pub(ctx, &output_pk_xy, &keypair) == 1);
500500
CHECK(secp256k1_xonly_pubkey_tweak_add(ctx, &output_pk_expected, &internal_pk, tweak) == 1);
501-
CHECK(memcmp(&output_pk_xy, &output_pk_expected, sizeof(output_pk_xy)) == 0);
501+
CHECK(secp256k1_memcmp_var(&output_pk_xy, &output_pk_expected, sizeof(output_pk_xy)) == 0);
502502

503503
/* Check that the secret key in the keypair is tweaked correctly */
504504
CHECK(secp256k1_ec_pubkey_create(ctx, &output_pk_expected, &keypair.data[0]) == 1);
505-
CHECK(memcmp(&output_pk_xy, &output_pk_expected, sizeof(output_pk_xy)) == 0);
505+
CHECK(secp256k1_memcmp_var(&output_pk_xy, &output_pk_expected, sizeof(output_pk_xy)) == 0);
506506
}
507507
secp256k1_context_destroy(none);
508508
secp256k1_context_destroy(sign);

src/modules/recovery/tests_impl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void test_ecdsa_recovery_end_to_end(void) {
184184
CHECK(secp256k1_ecdsa_sign_recoverable(ctx, &rsignature[3], message, privkey, NULL, extra) == 1);
185185
CHECK(secp256k1_ecdsa_recoverable_signature_serialize_compact(ctx, sig, &recid, &rsignature[4]) == 1);
186186
CHECK(secp256k1_ecdsa_recoverable_signature_convert(ctx, &signature[4], &rsignature[4]) == 1);
187-
CHECK(memcmp(&signature[4], &signature[0], 64) == 0);
187+
CHECK(secp256k1_memcmp_var(&signature[4], &signature[0], 64) == 0);
188188
CHECK(secp256k1_ecdsa_verify(ctx, &signature[4], message, &pubkey) == 1);
189189
memset(&rsignature[4], 0, sizeof(rsignature[4]));
190190
CHECK(secp256k1_ecdsa_recoverable_signature_parse_compact(ctx, &rsignature[4], sig, recid) == 1);
@@ -193,7 +193,7 @@ void test_ecdsa_recovery_end_to_end(void) {
193193
/* Parse compact (with recovery id) and recover. */
194194
CHECK(secp256k1_ecdsa_recoverable_signature_parse_compact(ctx, &rsignature[4], sig, recid) == 1);
195195
CHECK(secp256k1_ecdsa_recover(ctx, &recpubkey, &rsignature[4], message) == 1);
196-
CHECK(memcmp(&pubkey, &recpubkey, sizeof(pubkey)) == 0);
196+
CHECK(secp256k1_memcmp_var(&pubkey, &recpubkey, sizeof(pubkey)) == 0);
197197
/* Serialize/destroy/parse signature and verify again. */
198198
CHECK(secp256k1_ecdsa_recoverable_signature_serialize_compact(ctx, sig, &recid, &rsignature[4]) == 1);
199199
sig[secp256k1_testrand_bits(6)] += 1 + secp256k1_testrand_int(255);
@@ -202,7 +202,7 @@ void test_ecdsa_recovery_end_to_end(void) {
202202
CHECK(secp256k1_ecdsa_verify(ctx, &signature[4], message, &pubkey) == 0);
203203
/* Recover again */
204204
CHECK(secp256k1_ecdsa_recover(ctx, &recpubkey, &rsignature[4], message) == 0 ||
205-
memcmp(&pubkey, &recpubkey, sizeof(pubkey)) != 0);
205+
secp256k1_memcmp_var(&pubkey, &recpubkey, sizeof(pubkey)) != 0);
206206
}
207207

208208
/* Tests several edge cases. */

src/modules/schnorrsig/main_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static int nonce_function_bip340(unsigned char *nonce32, const unsigned char *ms
6868
/* Tag the hash with algo16 which is important to avoid nonce reuse across
6969
* algorithms. If this nonce function is used in BIP-340 signing as defined
7070
* in the spec, an optimized tagging implementation is used. */
71-
if (memcmp(algo16, bip340_algo16, 16) == 0) {
71+
if (secp256k1_memcmp_var(algo16, bip340_algo16, 16) == 0) {
7272
secp256k1_nonce_function_bip340_sha256_tagged(&sha);
7373
} else {
7474
int algo16_len = 16;

src/modules/schnorrsig/tests_exhaustive_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ static void test_exhaustive_schnorrsig_sign(const secp256k1_context *ctx, unsign
163163
/* Invoke the real function to construct a signature. */
164164
CHECK(secp256k1_schnorrsig_sign(ctx, sig64, msg32, &keypairs[d - 1], secp256k1_hardened_nonce_function_smallint, &k));
165165
/* The first 32 bytes must match the xonly pubkey for the specified k. */
166-
CHECK(memcmp(sig64, xonly_pubkey_bytes[k - 1], 32) == 0);
166+
CHECK(secp256k1_memcmp_var(sig64, xonly_pubkey_bytes[k - 1], 32) == 0);
167167
/* The last 32 bytes must match the expected s value. */
168-
CHECK(memcmp(sig64 + 32, expected_s_bytes, 32) == 0);
168+
CHECK(secp256k1_memcmp_var(sig64 + 32, expected_s_bytes, 32) == 0);
169169
/* Don't retry other messages that result in the same challenge. */
170170
e_done[e] = 1;
171171
++e_count_done;

0 commit comments

Comments
 (0)