Skip to content

Commit

Permalink
Implement current magnitude assumptions
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
peterdettman and theStack committed Jul 21, 2023
1 parent 49afd2f commit 173e8d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ typedef struct {

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

/** Maximum allowed magnitudes for group element coordinates
* in affine (x, y) and jacobian (x, y, z) representation. */
#define SECP256K1_GE_X_MAGNITUDE_MAX 8
#define SECP256K1_GE_Y_MAGNITUDE_MAX 8
#define SECP256K1_GEJ_X_MAGNITUDE_MAX 8
#define SECP256K1_GEJ_Y_MAGNITUDE_MAX 8
#define SECP256K1_GEJ_Z_MAGNITUDE_MAX 8

/** Set a group element equal to the point with given X and Y coordinates */
static void secp256k1_ge_set_xy(secp256k1_ge *r, const secp256k1_fe *x, const secp256k1_fe *y);

Expand Down
6 changes: 5 additions & 1 deletion src/group_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ static void secp256k1_ge_verify(const secp256k1_ge *a) {
#ifdef VERIFY
secp256k1_fe_verify(&a->x);
secp256k1_fe_verify(&a->y);
secp256k1_fe_verify_magnitude(&a->x, SECP256K1_GE_X_MAGNITUDE_MAX);
secp256k1_fe_verify_magnitude(&a->y, SECP256K1_GE_Y_MAGNITUDE_MAX);
VERIFY_CHECK(a->infinity == 0 || a->infinity == 1);
#endif
(void)a;
Expand All @@ -87,6 +89,9 @@ static void secp256k1_gej_verify(const secp256k1_gej *a) {
secp256k1_fe_verify(&a->x);
secp256k1_fe_verify(&a->y);
secp256k1_fe_verify(&a->z);
secp256k1_fe_verify_magnitude(&a->x, SECP256K1_GEJ_X_MAGNITUDE_MAX);
secp256k1_fe_verify_magnitude(&a->y, SECP256K1_GEJ_Y_MAGNITUDE_MAX);
secp256k1_fe_verify_magnitude(&a->z, SECP256K1_GEJ_Z_MAGNITUDE_MAX);
VERIFY_CHECK(a->infinity == 0 || a->infinity == 1);
#endif
(void)a;
Expand Down Expand Up @@ -358,7 +363,6 @@ static int secp256k1_gej_eq_x_var(const secp256k1_fe *x, const secp256k1_gej *a)
secp256k1_fe_verify(x);
secp256k1_gej_verify(a);
#ifdef VERIFY
VERIFY_CHECK(a->x.magnitude <= 31);
VERIFY_CHECK(!a->infinity);
#endif

Expand Down

0 comments on commit 173e8d0

Please sign in to comment.