Skip to content

Commit 4e9661f

Browse files
peterdettmanreal-or-random
authored andcommitted
Add _fe_verify_magnitude (no-op unless VERIFY is enabled)
Co-authored-by: Tim Ruffing <crypto@timruffing.de>
1 parent 690b0fc commit 4e9661f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/field.h

+3
Original file line numberDiff line numberDiff line change
@@ -352,4 +352,7 @@ static int secp256k1_fe_is_square_var(const secp256k1_fe *a);
352352
/** Check invariants on a field element (no-op unless VERIFY is enabled). */
353353
static void secp256k1_fe_verify(const secp256k1_fe *a);
354354

355+
/** Check that magnitude of a is at most m (no-op unless VERIFY is enabled). */
356+
static void secp256k1_fe_verify_magnitude(const secp256k1_fe *a, int m);
357+
355358
#endif /* SECP256K1_FIELD_H */

src/field_impl.h

+7
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ static int secp256k1_fe_sqrt(secp256k1_fe * SECP256K1_RESTRICT r, const secp256k
159159

160160
#ifndef VERIFY
161161
static void secp256k1_fe_verify(const secp256k1_fe *a) { (void)a; }
162+
static void secp256k1_fe_verify_magnitude(const secp256k1_fe *a, int m) { (void)a; (void)m; }
162163
#else
163164
static void secp256k1_fe_impl_verify(const secp256k1_fe *a);
164165
static void secp256k1_fe_verify(const secp256k1_fe *a) {
@@ -172,6 +173,12 @@ static void secp256k1_fe_verify(const secp256k1_fe *a) {
172173
secp256k1_fe_impl_verify(a);
173174
}
174175

176+
static void secp256k1_fe_verify_magnitude(const secp256k1_fe *a, int m) {
177+
VERIFY_CHECK(m >= 0);
178+
VERIFY_CHECK(m <= 32);
179+
VERIFY_CHECK(a->magnitude <= m);
180+
}
181+
175182
static void secp256k1_fe_impl_normalize(secp256k1_fe *r);
176183
SECP256K1_INLINE static void secp256k1_fe_normalize(secp256k1_fe *r) {
177184
secp256k1_fe_verify(r);

0 commit comments

Comments
 (0)