Skip to content

Commit 0a2e0b2

Browse files
committed
Make secp256k1_{fe,ge,gej}_verify work as no-op if non-VERIFY
1 parent f202667 commit 0a2e0b2

File tree

5 files changed

+15
-119
lines changed

5 files changed

+15
-119
lines changed

src/field.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ static void secp256k1_fe_get_bounds(secp256k1_fe *r, int m);
143143
/** Determine whether a is a square (modulo p). */
144144
static int secp256k1_fe_is_square_var(const secp256k1_fe *a);
145145

146-
#ifdef VERIFY
147-
/** Check invariants on a field element. */
146+
/** Check invariants on a field element (no-op unless VERIFY is enabled). */
148147
static void secp256k1_fe_verify(const secp256k1_fe *a);
149-
#endif
150148

151149
#endif /* SECP256K1_FIELD_H */

src/field_10x26_impl.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
* - 2*M*(2^26-1) is the max (inclusive) of the remaining limbs
2222
*/
2323

24-
#ifdef VERIFY
2524
static void secp256k1_fe_verify(const secp256k1_fe *a) {
25+
#ifdef VERIFY
2626
const uint32_t *d = a->n;
2727
int m = a->normalized ? 1 : 2 * a->magnitude, r = 1;
2828
r &= (d[0] <= 0x3FFFFFFUL * m);
@@ -47,8 +47,9 @@ static void secp256k1_fe_verify(const secp256k1_fe *a) {
4747
}
4848
}
4949
VERIFY_CHECK(r == 1);
50-
}
5150
#endif
51+
(void)a;
52+
}
5253

5354
static void secp256k1_fe_get_bounds(secp256k1_fe *r, int m) {
5455
VERIFY_CHECK(m >= 0);
@@ -458,9 +459,7 @@ SECP256K1_INLINE static void secp256k1_fe_mul_int(secp256k1_fe *r, int a) {
458459
}
459460

460461
SECP256K1_INLINE static void secp256k1_fe_add(secp256k1_fe *r, const secp256k1_fe *a) {
461-
#ifdef VERIFY
462462
secp256k1_fe_verify(a);
463-
#endif
464463
r->n[0] += a->n[0];
465464
r->n[1] += a->n[1];
466465
r->n[2] += a->n[2];
@@ -479,11 +478,9 @@ SECP256K1_INLINE static void secp256k1_fe_add(secp256k1_fe *r, const secp256k1_f
479478
}
480479

481480
SECP256K1_INLINE static void secp256k1_fe_add_int(secp256k1_fe *r, int a) {
482-
#ifdef VERIFY
483481
secp256k1_fe_verify(r);
484482
VERIFY_CHECK(a >= 0);
485483
VERIFY_CHECK(a <= 0x7FFF);
486-
#endif
487484
r->n[0] += a;
488485
#ifdef VERIFY
489486
r->magnitude += 1;

src/field_5x52_impl.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
* 0 or 1, and its value is already reduced modulo the order of the field.
3434
*/
3535

36-
#ifdef VERIFY
3736
static void secp256k1_fe_verify(const secp256k1_fe *a) {
37+
#ifdef VERIFY
3838
const uint64_t *d = a->n;
3939
int m = a->normalized ? 1 : 2 * a->magnitude, r = 1;
4040
/* secp256k1 'p' value defined in "Standards for Efficient Cryptography" (SEC2) 2.7.1. */
@@ -52,8 +52,9 @@ static void secp256k1_fe_verify(const secp256k1_fe *a) {
5252
}
5353
}
5454
VERIFY_CHECK(r == 1);
55-
}
5655
#endif
56+
(void)a;
57+
}
5758

5859
static void secp256k1_fe_get_bounds(secp256k1_fe *r, int m) {
5960
VERIFY_CHECK(m >= 0);
@@ -422,11 +423,9 @@ SECP256K1_INLINE static void secp256k1_fe_mul_int(secp256k1_fe *r, int a) {
422423
}
423424

424425
SECP256K1_INLINE static void secp256k1_fe_add_int(secp256k1_fe *r, int a) {
425-
#ifdef VERIFY
426426
secp256k1_fe_verify(r);
427427
VERIFY_CHECK(a >= 0);
428428
VERIFY_CHECK(a <= 0x7FFF);
429-
#endif
430429
r->n[0] += a;
431430
#ifdef VERIFY
432431
r->magnitude += 1;
@@ -436,9 +435,7 @@ SECP256K1_INLINE static void secp256k1_fe_add_int(secp256k1_fe *r, int a) {
436435
}
437436

438437
SECP256K1_INLINE static void secp256k1_fe_add(secp256k1_fe *r, const secp256k1_fe *a) {
439-
#ifdef VERIFY
440438
secp256k1_fe_verify(a);
441-
#endif
442439
r->n[0] += a->n[0];
443440
r->n[1] += a->n[1];
444441
r->n[2] += a->n[2];

src/group.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,10 @@ static void secp256k1_gej_rescale(secp256k1_gej *r, const secp256k1_fe *b);
164164
*/
165165
static int secp256k1_ge_is_in_correct_subgroup(const secp256k1_ge* ge);
166166

167-
#ifdef VERIFY
168-
/** Check invariants on an affine group element. */
167+
/** Check invariants on an affine group element (no-op unless VERIFY is enabled). */
169168
static void secp256k1_ge_verify(const secp256k1_ge *a);
170169

171-
/** Check invariants on a Jacobian group element. */
170+
/** Check invariants on a Jacobian group element (no-op unless VERIFY is enabled). */
172171
static void secp256k1_gej_verify(const secp256k1_gej *a);
173-
#endif
174172

175173
#endif /* SECP256K1_GROUP_H */

0 commit comments

Comments
 (0)