Skip to content

Commit b475654

Browse files
committed
Merge #1745: test: introduce group order byte-array constant for deduplication
0c91c56 test: introduce group order byte-array constant for deduplication (Sebastian Falbesoner) Pull request description: ACKs for top commit: real-or-random: utACK 0c91c56 furszy: ACK 0c91c56 jonasnick: ACK 0c91c56 Tree-SHA512: c33fc43cdccd7d27e1aa0a7660b91581d663a77130849ee0946fe41a61d6f1ba37304d307ee5c69333336e1f191c4e686e2b423053c8e3ae7bced2d31005b99c
2 parents 88be4e8 + 0c91c56 commit b475654

File tree

3 files changed

+13
-25
lines changed

3 files changed

+13
-25
lines changed

src/modules/ecdh/tests_impl.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,7 @@ static void test_ecdh_generator_basepoint(void) {
9090

9191
static void test_bad_scalar(void) {
9292
unsigned char s_zero[32] = { 0 };
93-
unsigned char s_overflow[32] = {
94-
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
95-
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
96-
0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b,
97-
0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41
98-
};
93+
unsigned char s_overflow[32] = { 0 };
9994
unsigned char s_rand[32] = { 0 };
10095
unsigned char output[32];
10196
secp256k1_scalar rand;
@@ -107,6 +102,7 @@ static void test_bad_scalar(void) {
107102
CHECK(secp256k1_ec_pubkey_create(CTX, &point, s_rand) == 1);
108103

109104
/* Try to multiply it by bad values */
105+
memcpy(s_overflow, secp256k1_group_order_bytes, 32);
110106
CHECK(secp256k1_ecdh(CTX, output, &point, s_zero, NULL, NULL) == 0);
111107
CHECK(secp256k1_ecdh(CTX, output, &point, s_overflow, NULL, NULL) == 0);
112108
/* ...and a good one */

src/tests.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6036,12 +6036,7 @@ static void run_ec_pubkey_parse_test(void) {
60366036
}
60376037

60386038
static void run_eckey_edge_case_test(void) {
6039-
const unsigned char orderc[32] = {
6040-
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
6041-
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
6042-
0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b,
6043-
0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41
6044-
};
6039+
const unsigned char *orderc = secp256k1_group_order_bytes;
60456040
const unsigned char zeros[sizeof(secp256k1_pubkey)] = {0x00};
60466041
unsigned char ctmp[33];
60476042
unsigned char ctmp2[33];
@@ -6355,13 +6350,7 @@ static int nonce_function_test_retry(unsigned char *nonce32, const unsigned char
63556350
return 1;
63566351
}
63576352
if (counter < 5) {
6358-
static const unsigned char order[] = {
6359-
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
6360-
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,
6361-
0xBA,0xAE,0xDC,0xE6,0xAF,0x48,0xA0,0x3B,
6362-
0xBF,0xD2,0x5E,0x8C,0xD0,0x36,0x41,0x41
6363-
};
6364-
memcpy(nonce32, order, 32);
6353+
memcpy(nonce32, secp256k1_group_order_bytes, 32);
63656354
if (counter == 4) {
63666355
nonce32[31]++;
63676356
}
@@ -7379,12 +7368,7 @@ static void test_ecdsa_edge_cases(void) {
73797368
/* Privkey export where pubkey is the point at infinity. */
73807369
{
73817370
unsigned char privkey[300];
7382-
unsigned char seckey[32] = {
7383-
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
7384-
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
7385-
0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b,
7386-
0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41,
7387-
};
7371+
const unsigned char *seckey = secp256k1_group_order_bytes;
73887372
size_t outlen = 300;
73897373
CHECK(!ec_privkey_export_der(CTX, privkey, &outlen, seckey, 0));
73907374
outlen = 300;

src/testutil.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
#include "testrand.h"
1212
#include "util.h"
1313

14+
/* group order of the secp256k1 curve in 32-byte big endian representation */
15+
static const unsigned char secp256k1_group_order_bytes[32] = {
16+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
17+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
18+
0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b,
19+
0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41
20+
};
21+
1422
static void testutil_random_fe(secp256k1_fe *x) {
1523
unsigned char bin[32];
1624
do {

0 commit comments

Comments
 (0)