Skip to content

Commit 78f6cdf

Browse files
committed
Make the curve B constant a secp256k1_fe
1 parent d7f39ae commit 78f6cdf

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/group_impl.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/* These points can be generated in sage as follows:
1515
*
1616
* 0. Setup a worksheet with the following parameters.
17-
* b = 4 # whatever CURVE_B will be set to
17+
* b = 4 # whatever secp256k1_fe_const_b will be set to
1818
* F = FiniteField (0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F)
1919
* C = EllipticCurve ([F (0), F (b)])
2020
*
@@ -45,15 +45,18 @@ static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_GE_CONST(
4545
0x48DF246C, 0x808DAE72, 0xCFE52572, 0x7F0501ED
4646
);
4747

48-
static const int CURVE_B = 4;
48+
static const secp256k1_fe secp256k1_fe_const_b = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 4);
49+
4950
# elif EXHAUSTIVE_TEST_ORDER == 13
5051
static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_GE_CONST(
5152
0xedc60018, 0xa51a786b, 0x2ea91f4d, 0x4c9416c0,
5253
0x9de54c3b, 0xa1316554, 0x6cf4345c, 0x7277ef15,
5354
0x54cb1b6b, 0xdc8c1273, 0x087844ea, 0x43f4603e,
5455
0x0eaf9a43, 0xf6effe55, 0x939f806d, 0x37adf8ac
5556
);
56-
static const int CURVE_B = 2;
57+
58+
static const secp256k1_fe secp256k1_fe_const_b = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 2);
59+
5760
# else
5861
# error No known generator for the specified exhaustive test group order.
5962
# endif
@@ -68,7 +71,7 @@ static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_GE_CONST(
6871
0xFD17B448UL, 0xA6855419UL, 0x9C47D08FUL, 0xFB10D4B8UL
6972
);
7073

71-
static const int CURVE_B = 7;
74+
static const secp256k1_fe secp256k1_fe_const_b = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 7);
7275
#endif
7376

7477
static void secp256k1_ge_set_gej_zinv(secp256k1_ge *r, const secp256k1_gej *a, const secp256k1_fe *zi) {
@@ -219,14 +222,13 @@ static void secp256k1_ge_clear(secp256k1_ge *r) {
219222
}
220223

221224
static int secp256k1_ge_set_xquad(secp256k1_ge *r, const secp256k1_fe *x) {
222-
secp256k1_fe x2, x3, c;
225+
secp256k1_fe x2, x3;
223226
r->x = *x;
224227
secp256k1_fe_sqr(&x2, x);
225228
secp256k1_fe_mul(&x3, x, &x2);
226229
r->infinity = 0;
227-
secp256k1_fe_set_int(&c, CURVE_B);
228-
secp256k1_fe_add(&c, &x3);
229-
return secp256k1_fe_sqrt(&r->y, &c);
230+
secp256k1_fe_add(&x3, &secp256k1_fe_const_b);
231+
return secp256k1_fe_sqrt(&r->y, &x3);
230232
}
231233

232234
static int secp256k1_ge_set_xo_var(secp256k1_ge *r, const secp256k1_fe *x, int odd) {
@@ -270,15 +272,14 @@ static int secp256k1_gej_is_infinity(const secp256k1_gej *a) {
270272
}
271273

272274
static int secp256k1_ge_is_valid_var(const secp256k1_ge *a) {
273-
secp256k1_fe y2, x3, c;
275+
secp256k1_fe y2, x3;
274276
if (a->infinity) {
275277
return 0;
276278
}
277279
/* y^2 = x^3 + 7 */
278280
secp256k1_fe_sqr(&y2, &a->y);
279281
secp256k1_fe_sqr(&x3, &a->x); secp256k1_fe_mul(&x3, &x3, &a->x);
280-
secp256k1_fe_set_int(&c, CURVE_B);
281-
secp256k1_fe_add(&x3, &c);
282+
secp256k1_fe_add(&x3, &secp256k1_fe_const_b);
282283
secp256k1_fe_normalize_weak(&x3);
283284
return secp256k1_fe_equal_var(&y2, &x3);
284285
}

0 commit comments

Comments
 (0)