Skip to content

Commit ce60785

Browse files
committed
Introduce SECP256K1_B macro for curve b coefficient
1 parent 4934aa7 commit ce60785

File tree

2 files changed

+7
-26
lines changed

2 files changed

+7
-26
lines changed

sage/gen_exhaustive_groups.sage

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

9898
def output_b(b):
99-
print("static const secp256k1_fe secp256k1_fe_const_b = SECP256K1_FE_CONST(")
100-
print(" 0x%08x, 0x%08x, 0x%08x, 0x%08x," % tuple((int(b) >> (32 * (7 - i))) & 0xffffffff for i in range(4)))
101-
print(" 0x%08x, 0x%08x, 0x%08x, 0x%08x" % tuple((int(b) >> (32 * (7 - i))) & 0xffffffff for i in range(4, 8)))
102-
print(");")
99+
print(f"#define SECP256K1_B {int(b)}")
103100

104101
print()
105102
print("To be put in src/group_impl.h:")
@@ -128,7 +125,6 @@ for f in sorted(solutions.keys()):
128125
first = False
129126
print()
130127
print(f"static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G_ORDER_{f};")
131-
print("")
132128
output_b(b)
133129
print()
134130
print("# else")
@@ -137,7 +133,6 @@ print("# endif")
137133
print("#else")
138134
print()
139135
print("static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G;")
140-
print("")
141136
output_b(7)
142137
print()
143138
print("#endif")

src/group_impl.h

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,45 +49,31 @@
4949
# if EXHAUSTIVE_TEST_ORDER == 7
5050

5151
static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G_ORDER_7;
52-
53-
static const secp256k1_fe secp256k1_fe_const_b = SECP256K1_FE_CONST(
54-
0x00000000, 0x00000000, 0x00000000, 0x00000000,
55-
0x00000000, 0x00000000, 0x00000000, 0x00000006
56-
);
52+
#define SECP256K1_B 6
5753

5854
# elif EXHAUSTIVE_TEST_ORDER == 13
5955

6056
static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G_ORDER_13;
61-
62-
static const secp256k1_fe secp256k1_fe_const_b = SECP256K1_FE_CONST(
63-
0x00000000, 0x00000000, 0x00000000, 0x00000000,
64-
0x00000000, 0x00000000, 0x00000000, 0x00000002
65-
);
57+
#define SECP256K1_B 2
6658

6759
# elif EXHAUSTIVE_TEST_ORDER == 199
6860

6961
static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G_ORDER_199;
70-
71-
static const secp256k1_fe secp256k1_fe_const_b = SECP256K1_FE_CONST(
72-
0x00000000, 0x00000000, 0x00000000, 0x00000000,
73-
0x00000000, 0x00000000, 0x00000000, 0x00000004
74-
);
62+
#define SECP256K1_B 4
7563

7664
# else
7765
# error No known generator for the specified exhaustive test group order.
7866
# endif
7967
#else
8068

8169
static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G;
82-
83-
static const secp256k1_fe secp256k1_fe_const_b = SECP256K1_FE_CONST(
84-
0x00000000, 0x00000000, 0x00000000, 0x00000000,
85-
0x00000000, 0x00000000, 0x00000000, 0x00000007
86-
);
70+
#define SECP256K1_B 7
8771

8872
#endif
8973
/* End of section generated by sage/gen_exhaustive_groups.sage. */
9074

75+
static const secp256k1_fe secp256k1_fe_const_b = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, SECP256K1_B);
76+
9177
static void secp256k1_ge_set_gej_zinv(secp256k1_ge *r, const secp256k1_gej *a, const secp256k1_fe *zi) {
9278
secp256k1_fe zi2;
9379
secp256k1_fe zi3;

0 commit comments

Comments
 (0)