Skip to content

Commit 19d96e1

Browse files
committed
Split off .c file from precomputed_ecmult.h
1 parent 1a6691a commit 19d96e1

7 files changed

+16486
-16485
lines changed

.gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
src/precomputed_ecmult.h linguist-generated
1+
src/precomputed_ecmult.c linguist-generated
22
src/precomputed_ecmult_gen.c linguist-generated

Makefile.am

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ noinst_HEADERS += src/modinv32.h
4444
noinst_HEADERS += src/modinv32_impl.h
4545
noinst_HEADERS += src/modinv64.h
4646
noinst_HEADERS += src/modinv64_impl.h
47+
noinst_HEADERS += src/precomputed_ecmult.h
4748
noinst_HEADERS += src/precomputed_ecmult_gen.h
4849
noinst_HEADERS += src/assumptions.h
4950
noinst_HEADERS += src/util.h
@@ -65,7 +66,7 @@ noinst_HEADERS += contrib/lax_der_privatekey_parsing.c
6566

6667
PRECOMPUTED_LIB = libsecp256k1_precomputed.la
6768
noinst_LTLIBRARIES = $(PRECOMPUTED_LIB)
68-
libsecp256k1_precomputed_la_SOURCES = src/precomputed_ecmult_gen.c
69+
libsecp256k1_precomputed_la_SOURCES = src/precomputed_ecmult.c src/precomputed_ecmult_gen.c
6970
libsecp256k1_precomputed_la_CPPFLAGS = $(SECP_INCLUDES)
7071

7172
if USE_EXTERNAL_ASM
@@ -156,15 +157,14 @@ precompute_ecmult_gen_LDADD = $(SECP_LIBS) $(COMMON_LIB)
156157
# build by a normal user) depends on mtimes, and thus is very fragile.
157158
# This means that rebuilds of the prebuilt files always need to be
158159
# forced by deleting them, e.g., by invoking `make clean-precomp`.
159-
src/precomputed_ecmult.h:
160+
src/precomputed_ecmult.c:
160161
$(MAKE) $(AM_MAKEFLAGS) precompute_ecmult$(EXEEXT)
161162
./precompute_ecmult$(EXEEXT)
162163
src/precomputed_ecmult_gen.c:
163164
$(MAKE) $(AM_MAKEFLAGS) precompute_ecmult_gen$(EXEEXT)
164165
./precompute_ecmult_gen$(EXEEXT)
165166

166-
PRECOMP = src/precomputed_ecmult_gen.c
167-
noinst_HEADERS += src/precomputed_ecmult.h
167+
PRECOMP = src/precomputed_ecmult_gen.c src/precomputed_ecmult.c
168168
precomp: $(PRECOMP)
169169

170170
# Ensure the prebuilt files will be build first (only if they don't exist,

configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE|auto],
152152
[window size for ecmult precomputation for verification, specified as integer in range [2..24].]
153153
[Larger values result in possibly better performance at the cost of an exponentially larger precomputed table.]
154154
[The table will store 2^(SIZE-1) * 64 bytes of data but can be larger in memory due to platform-specific padding and alignment.]
155-
[A window size larger than 15 will require you delete the prebuilt precomputed_ecmult.h file so that it can be rebuilt.]
155+
[A window size larger than 15 will require you delete the prebuilt precomputed_ecmult.c file so that it can be rebuilt.]
156156
[For very large window sizes, use "make -j 1" to reduce memory use during compilation.]
157157
["auto" is a reasonable setting for desktop machines (currently 15). [default=auto]]
158158
)],

src/ecmult_impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static void secp256k1_ecmult_odd_multiples_table(int n, secp256k1_gej *prej, sec
103103
* It only operates on tables sized for WINDOW_A wnaf multiples.
104104
*
105105
* To compute a*P + b*G, we compute a table for P using this function,
106-
* and use the precomputed table in <precomputed_ecmult.h> for G.
106+
* and use the precomputed table in <precomputed_ecmult.c> for G.
107107
*/
108108
static void secp256k1_ecmult_odd_multiples_table_globalz_windowa(secp256k1_ge *pre, secp256k1_fe *globalz, const secp256k1_gej *a) {
109109
secp256k1_gej prej[ECMULT_TABLE_SIZE(WINDOW_A)];

src/precompute_ecmult.c

+12-26
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static void print_table(FILE *fp, const char *name, int window_g, const secp256k
2525
int j;
2626
int i;
2727

28-
fprintf(fp, "static const secp256k1_ge_storage %s[ECMULT_TABLE_SIZE(WINDOW_G)] = {\n", name);
28+
fprintf(fp, "const secp256k1_ge_storage %s[ECMULT_TABLE_SIZE(WINDOW_G)] = {\n", name);
2929
fprintf(fp, " S(%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32
3030
",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32")\n",
3131
SECP256K1_GE_STORAGE_CONST_GET(table[0]));
@@ -57,11 +57,9 @@ static void print_two_tables(FILE *fp, int window_g) {
5757
}
5858

5959
int main(void) {
60-
const int window_g_13 = 4;
61-
const int window_g_199 = 8;
6260
FILE* fp;
6361

64-
fp = fopen("src/precomputed_ecmult.h","w");
62+
fp = fopen("src/precomputed_ecmult.c","w");
6563
if (fp == NULL) {
6664
fprintf(stderr, "Could not open src/precomputed_ecmult.h for writing!\n");
6765
return -1;
@@ -71,36 +69,24 @@ int main(void) {
7169
fprintf(fp, "/* This file contains an array secp256k1_pre_g with odd multiples of the base point G and\n");
7270
fprintf(fp, " * an array secp256k1_pre_g_128 with odd multiples of 2^128*G for accelerating the computation of a*P + b*G.\n");
7371
fprintf(fp, " */\n");
74-
fprintf(fp, "#ifndef SECP256K1_PRECOMPUTED_ECMULT_H\n");
75-
fprintf(fp, "#define SECP256K1_PRECOMPUTED_ECMULT_H\n");
76-
fprintf(fp, "#include \"group.h\"\n");
77-
fprintf(fp, "#ifdef S\n");
78-
fprintf(fp, " #error macro identifier S already in use.\n");
72+
fprintf(fp, "#if defined HAVE_CONFIG_H\n");
73+
fprintf(fp, "#include \"libsecp256k1-config.h\"\n");
7974
fprintf(fp, "#endif\n");
80-
fprintf(fp, "#define S(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) "
81-
"SECP256K1_GE_STORAGE_CONST(0x##a##u,0x##b##u,0x##c##u,0x##d##u,0x##e##u,0x##f##u,0x##g##u,"
82-
"0x##h##u,0x##i##u,0x##j##u,0x##k##u,0x##l##u,0x##m##u,0x##n##u,0x##o##u,0x##p##u)\n");
75+
fprintf(fp, "#include \"../include/secp256k1.h\"\n");
76+
fprintf(fp, "#include \"group.h\"\n");
77+
fprintf(fp, "#include \"ecmult.h\"\n");
78+
fprintf(fp, "#define S(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) SECP256K1_GE_STORAGE_CONST(0x##a##u,0x##b##u,0x##c##u,0x##d##u,0x##e##u,0x##f##u,0x##g##u,0x##h##u,0x##i##u,0x##j##u,0x##k##u,0x##l##u,0x##m##u,0x##n##u,0x##o##u,0x##p##u)\n");
8379
fprintf(fp, "#if ECMULT_TABLE_SIZE(ECMULT_WINDOW_SIZE) > %ld\n", ECMULT_TABLE_SIZE(ECMULT_WINDOW_SIZE));
84-
fprintf(fp, " #error configuration mismatch, invalid ECMULT_WINDOW_SIZE. Try deleting precomputed_ecmult.h before the build.\n");
85-
fprintf(fp, "#endif\n");
86-
fprintf(fp, "#if defined(EXHAUSTIVE_TEST_ORDER)\n");
87-
fprintf(fp, "#if EXHAUSTIVE_TEST_ORDER == 13\n");
88-
fprintf(fp, "#define WINDOW_G %d\n", window_g_13);
89-
fprintf(fp, "#elif EXHAUSTIVE_TEST_ORDER == 199\n");
90-
fprintf(fp, "#define WINDOW_G %d\n", window_g_199);
91-
fprintf(fp, "#else\n");
92-
fprintf(fp, " #error No known generator for the specified exhaustive test group order.\n");
80+
fprintf(fp, " #error configuration mismatch, invalid ECMULT_WINDOW_SIZE. Try deleting precomputed_ecmult.c before the build.\n");
9381
fprintf(fp, "#endif\n");
94-
fprintf(fp, "static secp256k1_ge_storage secp256k1_pre_g[ECMULT_TABLE_SIZE(WINDOW_G)];\n");
95-
fprintf(fp, "static secp256k1_ge_storage secp256k1_pre_g_128[ECMULT_TABLE_SIZE(WINDOW_G)];\n");
96-
fprintf(fp, "#else /* !defined(EXHAUSTIVE_TEST_ORDER) */\n");
82+
fprintf(fp, "#ifdef EXHAUSTIVE_TEST_ORDER\n");
83+
fprintf(fp, "#error Cannot compile precomputed_ecmult.c in exhaustive test mode\n");
84+
fprintf(fp, "#endif /* EXHAUSTIVE_TEST_ORDER */\n");
9785
fprintf(fp, "#define WINDOW_G ECMULT_WINDOW_SIZE\n");
9886

9987
print_two_tables(fp, ECMULT_WINDOW_SIZE);
10088

101-
fprintf(fp, "#endif /* defined(EXHAUSTIVE_TEST_ORDER) */\n");
10289
fprintf(fp, "#undef S\n");
103-
fprintf(fp, "#endif /* SECP256K1_PRECOMPUTED_ECMULT_H */\n");
10490
fclose(fp);
10591

10692
return 0;

0 commit comments

Comments
 (0)