Skip to content

Commit

Permalink
Introduce SECP256K1_B macro for curve b coefficient
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Jan 10, 2023
1 parent 82d8bbc commit 0db5bec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
7 changes: 1 addition & 6 deletions sage/gen_exhaustive_groups.sage
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ def output_generator(g, name):
print(")")

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

print("")
print("")
Expand Down Expand Up @@ -104,14 +101,12 @@ for f in sorted(gens.keys()):
print(f"# {'if' if first else 'elif'} EXHAUSTIVE_TEST_ORDER == {f}")
first = False
print(f"static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G_ORDER_{f};")
print("")
output_b(b)
print("# else")
print("# error No known generator for the specified exhaustive test group order.")
print("# endif")
print("#else")
print("static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G;")
print("")
output_b(7)
print("#endif")

Expand Down
20 changes: 5 additions & 15 deletions src/group_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,20 @@
#if defined(EXHAUSTIVE_TEST_ORDER)
# if EXHAUSTIVE_TEST_ORDER == 13
static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G_ORDER_13;

static const secp256k1_fe secp256k1_fe_const_b = SECP256K1_FE_CONST(
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000002
);
#define SECP256K1_B 2U
# elif EXHAUSTIVE_TEST_ORDER == 199
static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G_ORDER_199;

static const secp256k1_fe secp256k1_fe_const_b = SECP256K1_FE_CONST(
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000004
);
#define SECP256K1_B 4U
# else
# error No known generator for the specified exhaustive test group order.
# endif
#else
static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G;

static const secp256k1_fe secp256k1_fe_const_b = SECP256K1_FE_CONST(
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000007
);
#define SECP256K1_B 7U
#endif

static const secp256k1_fe secp256k1_fe_const_b = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, SECP256K1_B);

static void secp256k1_ge_set_gej_zinv(secp256k1_ge *r, const secp256k1_gej *a, const secp256k1_fe *zi) {
secp256k1_fe zi2;
secp256k1_fe zi3;
Expand Down

0 comments on commit 0db5bec

Please sign in to comment.