Skip to content

Commit 486518b

Browse files
committed
Make exhaustive tests's scalar_inverse(&x,&x) work
The old code overwrote the input at the start of the function, making a call like secp256k1_scalar_inverse(&x,&x) always fail.
1 parent ab45c3e commit 486518b

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/scalar_low_impl.h

+11-6
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,22 @@ static SECP256K1_INLINE void secp256k1_scalar_cmov(secp256k1_scalar *r, const se
169169

170170
static void secp256k1_scalar_inverse(secp256k1_scalar *r, const secp256k1_scalar *x) {
171171
int i;
172-
*r = 0;
172+
uint32_t res = 0;
173173
SECP256K1_SCALAR_VERIFY(x);
174174

175-
for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++)
176-
if ((i * *x) % EXHAUSTIVE_TEST_ORDER == 1)
177-
*r = i;
175+
for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) {
176+
if ((i * *x) % EXHAUSTIVE_TEST_ORDER == 1) {
177+
res = i;
178+
break;
179+
}
180+
}
178181

179-
SECP256K1_SCALAR_VERIFY(r);
180182
/* If this VERIFY_CHECK triggers we were given a noninvertible scalar (and thus
181183
* have a composite group order; fix it in exhaustive_tests.c). */
182-
VERIFY_CHECK(*r != 0);
184+
VERIFY_CHECK(res != 0);
185+
*r = res;
186+
187+
SECP256K1_SCALAR_VERIFY(r);
183188
}
184189

185190
static void secp256k1_scalar_inverse_var(secp256k1_scalar *r, const secp256k1_scalar *x) {

0 commit comments

Comments
 (0)