Skip to content

Commit

Permalink
Merge bitcoin-core/secp256k1#959: tests: really test the non-var scal…
Browse files Browse the repository at this point in the history
…ar inverse

41ed139 tests: really test the non-var scalar inverse (Nicolas Iooss)

Pull request description:

ACKs for top commit:
  real-or-random:
    ACK 41ed139
  jonasnick:
    ACK 41ed139

Tree-SHA512: d501300fea3f24af669556317ca899f6d184a2b1b64a3705417fce7c028288348555942604672eafa3ec59884849655a55cd9aacdd9ca8e34edf21b081702438
  • Loading branch information
jonasnick committed Jun 28, 2021
2 parents 8ae56e3 + 41ed139 commit 75ce488
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -2595,7 +2595,7 @@ void test_inverse_scalar(secp256k1_scalar* out, const secp256k1_scalar* x, int v
{
secp256k1_scalar l, r, t;

(var ? secp256k1_scalar_inverse_var : secp256k1_scalar_inverse_var)(&l, x); /* l = 1/x */
(var ? secp256k1_scalar_inverse_var : secp256k1_scalar_inverse)(&l, x); /* l = 1/x */
if (out) *out = l;
if (secp256k1_scalar_is_zero(x)) {
CHECK(secp256k1_scalar_is_zero(&l));
Expand All @@ -2605,9 +2605,9 @@ void test_inverse_scalar(secp256k1_scalar* out, const secp256k1_scalar* x, int v
CHECK(secp256k1_scalar_is_one(&t)); /* x*(1/x) == 1 */
secp256k1_scalar_add(&r, x, &scalar_minus_one); /* r = x-1 */
if (secp256k1_scalar_is_zero(&r)) return;
(var ? secp256k1_scalar_inverse_var : secp256k1_scalar_inverse_var)(&r, &r); /* r = 1/(x-1) */
(var ? secp256k1_scalar_inverse_var : secp256k1_scalar_inverse)(&r, &r); /* r = 1/(x-1) */
secp256k1_scalar_add(&l, &scalar_minus_one, &l); /* l = 1/x-1 */
(var ? secp256k1_scalar_inverse_var : secp256k1_scalar_inverse_var)(&l, &l); /* l = 1/(1/x-1) */
(var ? secp256k1_scalar_inverse_var : secp256k1_scalar_inverse)(&l, &l); /* l = 1/(1/x-1) */
secp256k1_scalar_add(&l, &l, &secp256k1_scalar_one); /* l = 1/(1/x-1)+1 */
secp256k1_scalar_add(&l, &r, &l); /* l = 1/(1/x-1)+1 + 1/(x-1) */
CHECK(secp256k1_scalar_is_zero(&l)); /* l == 0 */
Expand Down

0 comments on commit 75ce488

Please sign in to comment.