Skip to content

Commit 0db5bec

Browse files
committed
Introduce SECP256K1_B macro for curve b coefficient
1 parent 82d8bbc commit 0db5bec

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

sage/gen_exhaustive_groups.sage

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ def output_generator(g, name):
7272
print(")")
7373

7474
def output_b(b):
75-
print("static const secp256k1_fe secp256k1_fe_const_b = SECP256K1_FE_CONST(")
76-
print(" 0x%08x, 0x%08x, 0x%08x, 0x%08x," % tuple((int(b) >> (32 * (7 - i))) & 0xffffffff for i in range(4)))
77-
print(" 0x%08x, 0x%08x, 0x%08x, 0x%08x" % tuple((int(b) >> (32 * (7 - i))) & 0xffffffff for i in range(4, 8)))
78-
print(");")
75+
print(f"#define SECP256K1_B {int(b)}U")
7976

8077
print("")
8178
print("")
@@ -104,14 +101,12 @@ for f in sorted(gens.keys()):
104101
print(f"# {'if' if first else 'elif'} EXHAUSTIVE_TEST_ORDER == {f}")
105102
first = False
106103
print(f"static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G_ORDER_{f};")
107-
print("")
108104
output_b(b)
109105
print("# else")
110106
print("# error No known generator for the specified exhaustive test group order.")
111107
print("# endif")
112108
print("#else")
113109
print("static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G;")
114-
print("")
115110
output_b(7)
116111
print("#endif")
117112

src/group_impl.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,20 @@
4343
#if defined(EXHAUSTIVE_TEST_ORDER)
4444
# if EXHAUSTIVE_TEST_ORDER == 13
4545
static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G_ORDER_13;
46-
47-
static const secp256k1_fe secp256k1_fe_const_b = SECP256K1_FE_CONST(
48-
0x00000000, 0x00000000, 0x00000000, 0x00000000,
49-
0x00000000, 0x00000000, 0x00000000, 0x00000002
50-
);
46+
#define SECP256K1_B 2U
5147
# elif EXHAUSTIVE_TEST_ORDER == 199
5248
static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G_ORDER_199;
53-
54-
static const secp256k1_fe secp256k1_fe_const_b = SECP256K1_FE_CONST(
55-
0x00000000, 0x00000000, 0x00000000, 0x00000000,
56-
0x00000000, 0x00000000, 0x00000000, 0x00000004
57-
);
49+
#define SECP256K1_B 4U
5850
# else
5951
# error No known generator for the specified exhaustive test group order.
6052
# endif
6153
#else
6254
static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G;
63-
64-
static const secp256k1_fe secp256k1_fe_const_b = SECP256K1_FE_CONST(
65-
0x00000000, 0x00000000, 0x00000000, 0x00000000,
66-
0x00000000, 0x00000000, 0x00000000, 0x00000007
67-
);
55+
#define SECP256K1_B 7U
6856
#endif
6957

58+
static const secp256k1_fe secp256k1_fe_const_b = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, SECP256K1_B);
59+
7060
static void secp256k1_ge_set_gej_zinv(secp256k1_ge *r, const secp256k1_gej *a, const secp256k1_fe *zi) {
7161
secp256k1_fe zi2;
7262
secp256k1_fe zi3;

0 commit comments

Comments
 (0)