Skip to content

Commit 173e8d0

Browse files
Implement current magnitude assumptions
Remove also the explicit magnitude restriction `a->x.magnitude <= 31` in `secp256k1_gej_eq_x_var` (introduced in commit 07c0e8b), as this is implied by the new limits. Co-authored-by: Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
1 parent 49afd2f commit 173e8d0

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/group.h

+8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ typedef struct {
4444

4545
#define SECP256K1_GE_STORAGE_CONST_GET(t) SECP256K1_FE_STORAGE_CONST_GET(t.x), SECP256K1_FE_STORAGE_CONST_GET(t.y)
4646

47+
/** Maximum allowed magnitudes for group element coordinates
48+
* in affine (x, y) and jacobian (x, y, z) representation. */
49+
#define SECP256K1_GE_X_MAGNITUDE_MAX 8
50+
#define SECP256K1_GE_Y_MAGNITUDE_MAX 8
51+
#define SECP256K1_GEJ_X_MAGNITUDE_MAX 8
52+
#define SECP256K1_GEJ_Y_MAGNITUDE_MAX 8
53+
#define SECP256K1_GEJ_Z_MAGNITUDE_MAX 8
54+
4755
/** Set a group element equal to the point with given X and Y coordinates */
4856
static void secp256k1_ge_set_xy(secp256k1_ge *r, const secp256k1_fe *x, const secp256k1_fe *y);
4957

src/group_impl.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ static void secp256k1_ge_verify(const secp256k1_ge *a) {
7777
#ifdef VERIFY
7878
secp256k1_fe_verify(&a->x);
7979
secp256k1_fe_verify(&a->y);
80+
secp256k1_fe_verify_magnitude(&a->x, SECP256K1_GE_X_MAGNITUDE_MAX);
81+
secp256k1_fe_verify_magnitude(&a->y, SECP256K1_GE_Y_MAGNITUDE_MAX);
8082
VERIFY_CHECK(a->infinity == 0 || a->infinity == 1);
8183
#endif
8284
(void)a;
@@ -87,6 +89,9 @@ static void secp256k1_gej_verify(const secp256k1_gej *a) {
8789
secp256k1_fe_verify(&a->x);
8890
secp256k1_fe_verify(&a->y);
8991
secp256k1_fe_verify(&a->z);
92+
secp256k1_fe_verify_magnitude(&a->x, SECP256K1_GEJ_X_MAGNITUDE_MAX);
93+
secp256k1_fe_verify_magnitude(&a->y, SECP256K1_GEJ_Y_MAGNITUDE_MAX);
94+
secp256k1_fe_verify_magnitude(&a->z, SECP256K1_GEJ_Z_MAGNITUDE_MAX);
9095
VERIFY_CHECK(a->infinity == 0 || a->infinity == 1);
9196
#endif
9297
(void)a;
@@ -358,7 +363,6 @@ static int secp256k1_gej_eq_x_var(const secp256k1_fe *x, const secp256k1_gej *a)
358363
secp256k1_fe_verify(x);
359364
secp256k1_gej_verify(a);
360365
#ifdef VERIFY
361-
VERIFY_CHECK(a->x.magnitude <= 31);
362366
VERIFY_CHECK(!a->infinity);
363367
#endif
364368

0 commit comments

Comments
 (0)