Skip to content

Commit 5d89bc0

Browse files
committed
remove superfluous #ifdef VERIFY/#endif preprocessor conditions
Now that the `VERIFY_CHECK` compiles to empty in non-VERIFY mode, blocks that only consist of these macros don't need surrounding `#ifdef VERIFY` conditions anymore. At some places intentional blank lines are inserted for grouping and better readadbility.
1 parent c2688f8 commit 5d89bc0

11 files changed

+31
-97
lines changed

src/ecmult_const_impl.h

-6
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,7 @@ static int secp256k1_ecmult_const_xonly(secp256k1_fe* r, const secp256k1_fe *n,
349349
secp256k1_fe_mul(&g, &g, n);
350350
if (d) {
351351
secp256k1_fe b;
352-
#ifdef VERIFY
353352
VERIFY_CHECK(!secp256k1_fe_normalizes_to_zero(d));
354-
#endif
355353
secp256k1_fe_sqr(&b, d);
356354
VERIFY_CHECK(SECP256K1_B <= 8); /* magnitude of b will be <= 8 after the next call */
357355
secp256k1_fe_mul_int(&b, SECP256K1_B);
@@ -384,13 +382,9 @@ static int secp256k1_ecmult_const_xonly(secp256k1_fe* r, const secp256k1_fe *n,
384382
p.infinity = 0;
385383

386384
/* Perform x-only EC multiplication of P with q. */
387-
#ifdef VERIFY
388385
VERIFY_CHECK(!secp256k1_scalar_is_zero(q));
389-
#endif
390386
secp256k1_ecmult_const(&rj, &p, q);
391-
#ifdef VERIFY
392387
VERIFY_CHECK(!secp256k1_gej_is_infinity(&rj));
393-
#endif
394388

395389
/* The resulting (X, Y, Z) point on the effective-affine isomorphic curve corresponds to
396390
* (X, Y, Z*v) on the secp256k1 curve. The affine version of that has X coordinate

src/field_10x26_impl.h

-4
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,7 @@ void secp256k1_fe_sqr_inner(uint32_t *r, const uint32_t *a);
403403

404404
#else
405405

406-
#ifdef VERIFY
407406
#define VERIFY_BITS(x, n) VERIFY_CHECK(((x) >> (n)) == 0)
408-
#else
409-
#define VERIFY_BITS(x, n) do { } while(0)
410-
#endif
411407

412408
SECP256K1_INLINE static void secp256k1_fe_mul_inner(uint32_t *r, const uint32_t *a, const uint32_t * SECP256K1_RESTRICT b) {
413409
uint64_t c, d;

src/field_5x52_int128_impl.h

-5
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@
1212
#include "int128.h"
1313
#include "util.h"
1414

15-
#ifdef VERIFY
1615
#define VERIFY_BITS(x, n) VERIFY_CHECK(((x) >> (n)) == 0)
1716
#define VERIFY_BITS_128(x, n) VERIFY_CHECK(secp256k1_u128_check_bits((x), (n)))
18-
#else
19-
#define VERIFY_BITS(x, n) do { } while(0)
20-
#define VERIFY_BITS_128(x, n) do { } while(0)
21-
#endif
2217

2318
SECP256K1_INLINE static void secp256k1_fe_mul_inner(uint64_t *r, const uint64_t *a, const uint64_t * SECP256K1_RESTRICT b) {
2419
secp256k1_uint128 c, d;

src/group_impl.h

+1-6
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,7 @@ static int secp256k1_gej_eq_x_var(const secp256k1_fe *x, const secp256k1_gej *a)
362362
secp256k1_fe r;
363363
secp256k1_fe_verify(x);
364364
secp256k1_gej_verify(a);
365-
#ifdef VERIFY
366365
VERIFY_CHECK(!a->infinity);
367-
#endif
368366

369367
secp256k1_fe_sqr(&r, &a->z); secp256k1_fe_mul(&r, &r, x);
370368
return secp256k1_fe_equal(&r, &a->x);
@@ -809,9 +807,7 @@ static void secp256k1_gej_rescale(secp256k1_gej *r, const secp256k1_fe *s) {
809807
secp256k1_fe zz;
810808
secp256k1_gej_verify(r);
811809
secp256k1_fe_verify(s);
812-
#ifdef VERIFY
813810
VERIFY_CHECK(!secp256k1_fe_normalizes_to_zero_var(s));
814-
#endif
815811

816812
secp256k1_fe_sqr(&zz, s);
817813
secp256k1_fe_mul(&r->x, &r->x, &zz); /* r->x *= s^2 */
@@ -907,9 +903,8 @@ static int secp256k1_ge_x_frac_on_curve_var(const secp256k1_fe *xn, const secp25
907903
* (xn/xd)^3 + 7 is square <=> xd*xn^3 + 7*xd^4 is square (multiplying by xd^4, a square).
908904
*/
909905
secp256k1_fe r, t;
910-
#ifdef VERIFY
911906
VERIFY_CHECK(!secp256k1_fe_normalizes_to_zero_var(xd));
912-
#endif
907+
913908
secp256k1_fe_mul(&r, xd, xn); /* r = xd*xn */
914909
secp256k1_fe_sqr(&t, xn); /* t = xn^2 */
915910
secp256k1_fe_mul(&r, &r, &t); /* r = xd*xn^3 */

src/modinv32_impl.h

+11-22
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ static void secp256k1_modinv32_normalize_30(secp256k1_modinv32_signed30 *r, int3
144144
r->v[7] = r7;
145145
r->v[8] = r8;
146146

147-
#ifdef VERIFY
148147
VERIFY_CHECK(r0 >> 30 == 0);
149148
VERIFY_CHECK(r1 >> 30 == 0);
150149
VERIFY_CHECK(r2 >> 30 == 0);
@@ -156,7 +155,6 @@ static void secp256k1_modinv32_normalize_30(secp256k1_modinv32_signed30 *r, int3
156155
VERIFY_CHECK(r8 >> 30 == 0);
157156
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(r, 9, &modinfo->modulus, 0) >= 0); /* r >= 0 */
158157
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(r, 9, &modinfo->modulus, 1) < 0); /* r < modulus */
159-
#endif
160158
}
161159

162160
/* Data type for transition matrices (see section 3 of explanation).
@@ -413,14 +411,13 @@ static void secp256k1_modinv32_update_de_30(secp256k1_modinv32_signed30 *d, secp
413411
int32_t di, ei, md, me, sd, se;
414412
int64_t cd, ce;
415413
int i;
416-
#ifdef VERIFY
417414
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(d, 9, &modinfo->modulus, -2) > 0); /* d > -2*modulus */
418415
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(d, 9, &modinfo->modulus, 1) < 0); /* d < modulus */
419416
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(e, 9, &modinfo->modulus, -2) > 0); /* e > -2*modulus */
420417
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(e, 9, &modinfo->modulus, 1) < 0); /* e < modulus */
421418
VERIFY_CHECK(labs(u) <= (M30 + 1 - labs(v))); /* |u|+|v| <= 2^30 */
422419
VERIFY_CHECK(labs(q) <= (M30 + 1 - labs(r))); /* |q|+|r| <= 2^30 */
423-
#endif
420+
424421
/* [md,me] start as zero; plus [u,q] if d is negative; plus [v,r] if e is negative. */
425422
sd = d->v[8] >> 31;
426423
se = e->v[8] >> 31;
@@ -455,12 +452,11 @@ static void secp256k1_modinv32_update_de_30(secp256k1_modinv32_signed30 *d, secp
455452
/* What remains is limb 9 of t*[d,e]+modulus*[md,me]; store it as output limb 8. */
456453
d->v[8] = (int32_t)cd;
457454
e->v[8] = (int32_t)ce;
458-
#ifdef VERIFY
455+
459456
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(d, 9, &modinfo->modulus, -2) > 0); /* d > -2*modulus */
460457
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(d, 9, &modinfo->modulus, 1) < 0); /* d < modulus */
461458
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(e, 9, &modinfo->modulus, -2) > 0); /* e > -2*modulus */
462459
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(e, 9, &modinfo->modulus, 1) < 0); /* e < modulus */
463-
#endif
464460
}
465461

466462
/* Compute (t/2^30) * [f, g], where t is a transition matrix for 30 divsteps.
@@ -550,25 +546,23 @@ static void secp256k1_modinv32(secp256k1_modinv32_signed30 *x, const secp256k1_m
550546
/* Update d,e using that transition matrix. */
551547
secp256k1_modinv32_update_de_30(&d, &e, &t, modinfo);
552548
/* Update f,g using that transition matrix. */
553-
#ifdef VERIFY
554549
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, -1) > 0); /* f > -modulus */
555550
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, 1) <= 0); /* f <= modulus */
556551
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, 9, &modinfo->modulus, -1) > 0); /* g > -modulus */
557552
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, 9, &modinfo->modulus, 1) < 0); /* g < modulus */
558-
#endif
553+
559554
secp256k1_modinv32_update_fg_30(&f, &g, &t);
560-
#ifdef VERIFY
555+
561556
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, -1) > 0); /* f > -modulus */
562557
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, 1) <= 0); /* f <= modulus */
563558
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, 9, &modinfo->modulus, -1) > 0); /* g > -modulus */
564559
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, 9, &modinfo->modulus, 1) < 0); /* g < modulus */
565-
#endif
566560
}
567561

568562
/* At this point sufficient iterations have been performed that g must have reached 0
569563
* and (if g was not originally 0) f must now equal +/- GCD of the initial f, g
570564
* values i.e. +/- 1, and d now contains +/- the modular inverse. */
571-
#ifdef VERIFY
565+
572566
/* g == 0 */
573567
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, 9, &SECP256K1_SIGNED30_ONE, 0) == 0);
574568
/* |f| == 1, or (x == 0 and d == 0 and |f|=modulus) */
@@ -578,7 +572,6 @@ static void secp256k1_modinv32(secp256k1_modinv32_signed30 *x, const secp256k1_m
578572
secp256k1_modinv32_mul_cmp_30(&d, 9, &SECP256K1_SIGNED30_ONE, 0) == 0 &&
579573
(secp256k1_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, 1) == 0 ||
580574
secp256k1_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, -1) == 0)));
581-
#endif
582575

583576
/* Optionally negate d, normalize to [0,modulus), and return it. */
584577
secp256k1_modinv32_normalize_30(&d, f.v[8], modinfo);
@@ -607,12 +600,12 @@ static void secp256k1_modinv32_var(secp256k1_modinv32_signed30 *x, const secp256
607600
/* Update d,e using that transition matrix. */
608601
secp256k1_modinv32_update_de_30(&d, &e, &t, modinfo);
609602
/* Update f,g using that transition matrix. */
610-
#ifdef VERIFY
603+
611604
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, -1) > 0); /* f > -modulus */
612605
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */
613606
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, -1) > 0); /* g > -modulus */
614607
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 1) < 0); /* g < modulus */
615-
#endif
608+
616609
secp256k1_modinv32_update_fg_30_var(len, &f, &g, &t);
617610
/* If the bottom limb of g is 0, there is a chance g=0. */
618611
if (g.v[0] == 0) {
@@ -637,18 +630,17 @@ static void secp256k1_modinv32_var(secp256k1_modinv32_signed30 *x, const secp256
637630
g.v[len - 2] |= (uint32_t)gn << 30;
638631
--len;
639632
}
640-
#ifdef VERIFY
633+
641634
VERIFY_CHECK(++i < 25); /* We should never need more than 25*30 = 750 divsteps */
642635
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, -1) > 0); /* f > -modulus */
643636
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */
644637
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, -1) > 0); /* g > -modulus */
645638
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 1) < 0); /* g < modulus */
646-
#endif
647639
}
648640

649641
/* At this point g is 0 and (if g was not originally 0) f must now equal +/- GCD of
650642
* the initial f, g values i.e. +/- 1, and d now contains +/- the modular inverse. */
651-
#ifdef VERIFY
643+
652644
/* g == 0 */
653645
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, len, &SECP256K1_SIGNED30_ONE, 0) == 0);
654646
/* |f| == 1, or (x == 0 and d == 0 and |f|=modulus) */
@@ -658,7 +650,6 @@ static void secp256k1_modinv32_var(secp256k1_modinv32_signed30 *x, const secp256
658650
secp256k1_modinv32_mul_cmp_30(&d, 9, &SECP256K1_SIGNED30_ONE, 0) == 0 &&
659651
(secp256k1_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 1) == 0 ||
660652
secp256k1_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, -1) == 0)));
661-
#endif
662653

663654
/* Optionally negate d, normalize to [0,modulus), and return it. */
664655
secp256k1_modinv32_normalize_30(&d, f.v[len - 1], modinfo);
@@ -697,12 +688,11 @@ static int secp256k1_jacobi32_maybe_var(const secp256k1_modinv32_signed30 *x, co
697688
secp256k1_modinv32_trans2x2 t;
698689
eta = secp256k1_modinv32_posdivsteps_30_var(eta, f.v[0] | ((uint32_t)f.v[1] << 30), g.v[0] | ((uint32_t)g.v[1] << 30), &t, &jac);
699690
/* Update f,g using that transition matrix. */
700-
#ifdef VERIFY
701691
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 0) > 0); /* f > 0 */
702692
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */
703693
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 0) > 0); /* g > 0 */
704694
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 1) < 0); /* g < modulus */
705-
#endif
695+
706696
secp256k1_modinv32_update_fg_30_var(len, &f, &g, &t);
707697
/* If the bottom limb of f is 1, there is a chance that f=1. */
708698
if (f.v[0] == 1) {
@@ -723,12 +713,11 @@ static int secp256k1_jacobi32_maybe_var(const secp256k1_modinv32_signed30 *x, co
723713
cond |= gn;
724714
/* If so, reduce length. */
725715
if (cond == 0) --len;
726-
#ifdef VERIFY
716+
727717
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 0) > 0); /* f > 0 */
728718
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */
729719
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 0) > 0); /* g > 0 */
730720
VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 1) < 0); /* g < modulus */
731-
#endif
732721
}
733722

734723
/* The loop failed to converge to f=g after 1500 iterations. Return 0, indicating unknown result. */

0 commit comments

Comments
 (0)