Skip to content

Commit ad15215

Browse files
committed
update max scalar in scalar_cmov_test and fix schnorrsig_verify exhaustive test
- `secp256k1_scalar_set_int` in scalar_low uses input mod EXHAUSTIVE_TEST_ORDER - directly store s in sig64 without reducing it mod the group order for testing
1 parent 0fa84f8 commit ad15215

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/modules/schnorrsig/tests_exhaustive_impl.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@ static void test_exhaustive_schnorrsig_verify(const secp256k1_context *ctx, cons
110110
if (!e_done[e]) {
111111
/* Iterate over the possible valid last 32 bytes in the signature.
112112
0..order=that s value; order+1=random bytes */
113-
int count_valid = 0, s;
113+
int count_valid = 0;
114+
unsigned int s;
114115
for (s = 0; s <= EXHAUSTIVE_TEST_ORDER + 1; ++s) {
115116
int expect_valid, valid;
116117
if (s <= EXHAUSTIVE_TEST_ORDER) {
117-
secp256k1_scalar s_s;
118-
secp256k1_scalar_set_int(&s_s, s);
119-
secp256k1_scalar_get_b32(sig64 + 32, &s_s);
118+
memset(sig64 + 32, 0, 32);
119+
secp256k1_write_be32(sig64 + 60, s);
120120
expect_valid = actual_k != -1 && s != EXHAUSTIVE_TEST_ORDER &&
121-
(s_s == (actual_k + actual_d * e) % EXHAUSTIVE_TEST_ORDER);
121+
(s == (actual_k + actual_d * e) % EXHAUSTIVE_TEST_ORDER);
122122
} else {
123123
secp256k1_testrand256(sig64 + 32);
124124
expect_valid = 0;

src/scalar_low_impl.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ SECP256K1_INLINE static int secp256k1_scalar_is_even(const secp256k1_scalar *a)
1818
}
1919

2020
SECP256K1_INLINE static void secp256k1_scalar_clear(secp256k1_scalar *r) { *r = 0; }
21-
SECP256K1_INLINE static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsigned int v) { *r = v; }
21+
22+
SECP256K1_INLINE static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsigned int v) {
23+
*r = v % EXHAUSTIVE_TEST_ORDER;
24+
}
2225

2326
SECP256K1_INLINE static unsigned int secp256k1_scalar_get_bits(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {
2427
if (offset < 32)

src/tests.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -7652,8 +7652,8 @@ static void scalar_cmov_test(void) {
76527652
static const secp256k1_scalar zero = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0);
76537653
static const secp256k1_scalar one = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 1);
76547654
static const secp256k1_scalar max = SECP256K1_SCALAR_CONST(
7655-
0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL,
7656-
0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL
7655+
0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFEUL,
7656+
0xBAAEDCE6UL, 0xAF48A03BUL, 0xBFD25E8CUL, 0xD0364140UL
76577657
);
76587658
secp256k1_scalar r = max;
76597659
secp256k1_scalar a = zero;

0 commit comments

Comments
 (0)