Split off .c file from precomputed_ecmult.h
This commit is contained in:
parent
1a6691adae
commit
19d96e15f9
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -1,2 +1,2 @@
|
|||||||
src/precomputed_ecmult.h linguist-generated
|
src/precomputed_ecmult.c linguist-generated
|
||||||
src/precomputed_ecmult_gen.c linguist-generated
|
src/precomputed_ecmult_gen.c linguist-generated
|
||||||
|
@ -44,6 +44,7 @@ noinst_HEADERS += src/modinv32.h
|
|||||||
noinst_HEADERS += src/modinv32_impl.h
|
noinst_HEADERS += src/modinv32_impl.h
|
||||||
noinst_HEADERS += src/modinv64.h
|
noinst_HEADERS += src/modinv64.h
|
||||||
noinst_HEADERS += src/modinv64_impl.h
|
noinst_HEADERS += src/modinv64_impl.h
|
||||||
|
noinst_HEADERS += src/precomputed_ecmult.h
|
||||||
noinst_HEADERS += src/precomputed_ecmult_gen.h
|
noinst_HEADERS += src/precomputed_ecmult_gen.h
|
||||||
noinst_HEADERS += src/assumptions.h
|
noinst_HEADERS += src/assumptions.h
|
||||||
noinst_HEADERS += src/util.h
|
noinst_HEADERS += src/util.h
|
||||||
@ -65,7 +66,7 @@ noinst_HEADERS += contrib/lax_der_privatekey_parsing.c
|
|||||||
|
|
||||||
PRECOMPUTED_LIB = libsecp256k1_precomputed.la
|
PRECOMPUTED_LIB = libsecp256k1_precomputed.la
|
||||||
noinst_LTLIBRARIES = $(PRECOMPUTED_LIB)
|
noinst_LTLIBRARIES = $(PRECOMPUTED_LIB)
|
||||||
libsecp256k1_precomputed_la_SOURCES = src/precomputed_ecmult_gen.c
|
libsecp256k1_precomputed_la_SOURCES = src/precomputed_ecmult.c src/precomputed_ecmult_gen.c
|
||||||
libsecp256k1_precomputed_la_CPPFLAGS = $(SECP_INCLUDES)
|
libsecp256k1_precomputed_la_CPPFLAGS = $(SECP_INCLUDES)
|
||||||
|
|
||||||
if USE_EXTERNAL_ASM
|
if USE_EXTERNAL_ASM
|
||||||
@ -156,15 +157,14 @@ precompute_ecmult_gen_LDADD = $(SECP_LIBS) $(COMMON_LIB)
|
|||||||
# build by a normal user) depends on mtimes, and thus is very fragile.
|
# build by a normal user) depends on mtimes, and thus is very fragile.
|
||||||
# This means that rebuilds of the prebuilt files always need to be
|
# This means that rebuilds of the prebuilt files always need to be
|
||||||
# forced by deleting them, e.g., by invoking `make clean-precomp`.
|
# forced by deleting them, e.g., by invoking `make clean-precomp`.
|
||||||
src/precomputed_ecmult.h:
|
src/precomputed_ecmult.c:
|
||||||
$(MAKE) $(AM_MAKEFLAGS) precompute_ecmult$(EXEEXT)
|
$(MAKE) $(AM_MAKEFLAGS) precompute_ecmult$(EXEEXT)
|
||||||
./precompute_ecmult$(EXEEXT)
|
./precompute_ecmult$(EXEEXT)
|
||||||
src/precomputed_ecmult_gen.c:
|
src/precomputed_ecmult_gen.c:
|
||||||
$(MAKE) $(AM_MAKEFLAGS) precompute_ecmult_gen$(EXEEXT)
|
$(MAKE) $(AM_MAKEFLAGS) precompute_ecmult_gen$(EXEEXT)
|
||||||
./precompute_ecmult_gen$(EXEEXT)
|
./precompute_ecmult_gen$(EXEEXT)
|
||||||
|
|
||||||
PRECOMP = src/precomputed_ecmult_gen.c
|
PRECOMP = src/precomputed_ecmult_gen.c src/precomputed_ecmult.c
|
||||||
noinst_HEADERS += src/precomputed_ecmult.h
|
|
||||||
precomp: $(PRECOMP)
|
precomp: $(PRECOMP)
|
||||||
|
|
||||||
# Ensure the prebuilt files will be build first (only if they don't exist,
|
# Ensure the prebuilt files will be build first (only if they don't exist,
|
||||||
|
@ -152,7 +152,7 @@ AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE|auto],
|
|||||||
[window size for ecmult precomputation for verification, specified as integer in range [2..24].]
|
[window size for ecmult precomputation for verification, specified as integer in range [2..24].]
|
||||||
[Larger values result in possibly better performance at the cost of an exponentially larger precomputed table.]
|
[Larger values result in possibly better performance at the cost of an exponentially larger precomputed table.]
|
||||||
[The table will store 2^(SIZE-1) * 64 bytes of data but can be larger in memory due to platform-specific padding and alignment.]
|
[The table will store 2^(SIZE-1) * 64 bytes of data but can be larger in memory due to platform-specific padding and alignment.]
|
||||||
[A window size larger than 15 will require you delete the prebuilt precomputed_ecmult.h file so that it can be rebuilt.]
|
[A window size larger than 15 will require you delete the prebuilt precomputed_ecmult.c file so that it can be rebuilt.]
|
||||||
[For very large window sizes, use "make -j 1" to reduce memory use during compilation.]
|
[For very large window sizes, use "make -j 1" to reduce memory use during compilation.]
|
||||||
["auto" is a reasonable setting for desktop machines (currently 15). [default=auto]]
|
["auto" is a reasonable setting for desktop machines (currently 15). [default=auto]]
|
||||||
)],
|
)],
|
||||||
|
@ -103,7 +103,7 @@ static void secp256k1_ecmult_odd_multiples_table(int n, secp256k1_gej *prej, sec
|
|||||||
* It only operates on tables sized for WINDOW_A wnaf multiples.
|
* It only operates on tables sized for WINDOW_A wnaf multiples.
|
||||||
*
|
*
|
||||||
* To compute a*P + b*G, we compute a table for P using this function,
|
* To compute a*P + b*G, we compute a table for P using this function,
|
||||||
* and use the precomputed table in <precomputed_ecmult.h> for G.
|
* and use the precomputed table in <precomputed_ecmult.c> for G.
|
||||||
*/
|
*/
|
||||||
static void secp256k1_ecmult_odd_multiples_table_globalz_windowa(secp256k1_ge *pre, secp256k1_fe *globalz, const secp256k1_gej *a) {
|
static void secp256k1_ecmult_odd_multiples_table_globalz_windowa(secp256k1_ge *pre, secp256k1_fe *globalz, const secp256k1_gej *a) {
|
||||||
secp256k1_gej prej[ECMULT_TABLE_SIZE(WINDOW_A)];
|
secp256k1_gej prej[ECMULT_TABLE_SIZE(WINDOW_A)];
|
||||||
|
@ -25,7 +25,7 @@ static void print_table(FILE *fp, const char *name, int window_g, const secp256k
|
|||||||
int j;
|
int j;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
fprintf(fp, "static const secp256k1_ge_storage %s[ECMULT_TABLE_SIZE(WINDOW_G)] = {\n", name);
|
fprintf(fp, "const secp256k1_ge_storage %s[ECMULT_TABLE_SIZE(WINDOW_G)] = {\n", name);
|
||||||
fprintf(fp, " S(%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32
|
fprintf(fp, " S(%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32
|
||||||
",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32")\n",
|
",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32")\n",
|
||||||
SECP256K1_GE_STORAGE_CONST_GET(table[0]));
|
SECP256K1_GE_STORAGE_CONST_GET(table[0]));
|
||||||
@ -57,11 +57,9 @@ static void print_two_tables(FILE *fp, int window_g) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
const int window_g_13 = 4;
|
|
||||||
const int window_g_199 = 8;
|
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
|
|
||||||
fp = fopen("src/precomputed_ecmult.h","w");
|
fp = fopen("src/precomputed_ecmult.c","w");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
fprintf(stderr, "Could not open src/precomputed_ecmult.h for writing!\n");
|
fprintf(stderr, "Could not open src/precomputed_ecmult.h for writing!\n");
|
||||||
return -1;
|
return -1;
|
||||||
@ -71,36 +69,24 @@ int main(void) {
|
|||||||
fprintf(fp, "/* This file contains an array secp256k1_pre_g with odd multiples of the base point G and\n");
|
fprintf(fp, "/* This file contains an array secp256k1_pre_g with odd multiples of the base point G and\n");
|
||||||
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");
|
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");
|
||||||
fprintf(fp, " */\n");
|
fprintf(fp, " */\n");
|
||||||
fprintf(fp, "#ifndef SECP256K1_PRECOMPUTED_ECMULT_H\n");
|
fprintf(fp, "#if defined HAVE_CONFIG_H\n");
|
||||||
fprintf(fp, "#define SECP256K1_PRECOMPUTED_ECMULT_H\n");
|
fprintf(fp, "#include \"libsecp256k1-config.h\"\n");
|
||||||
|
fprintf(fp, "#endif\n");
|
||||||
|
fprintf(fp, "#include \"../include/secp256k1.h\"\n");
|
||||||
fprintf(fp, "#include \"group.h\"\n");
|
fprintf(fp, "#include \"group.h\"\n");
|
||||||
fprintf(fp, "#ifdef S\n");
|
fprintf(fp, "#include \"ecmult.h\"\n");
|
||||||
fprintf(fp, " #error macro identifier S already in use.\n");
|
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");
|
||||||
fprintf(fp, "#endif\n");
|
|
||||||
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");
|
|
||||||
fprintf(fp, "#if ECMULT_TABLE_SIZE(ECMULT_WINDOW_SIZE) > %ld\n", ECMULT_TABLE_SIZE(ECMULT_WINDOW_SIZE));
|
fprintf(fp, "#if ECMULT_TABLE_SIZE(ECMULT_WINDOW_SIZE) > %ld\n", ECMULT_TABLE_SIZE(ECMULT_WINDOW_SIZE));
|
||||||
fprintf(fp, " #error configuration mismatch, invalid ECMULT_WINDOW_SIZE. Try deleting precomputed_ecmult.h before the build.\n");
|
fprintf(fp, " #error configuration mismatch, invalid ECMULT_WINDOW_SIZE. Try deleting precomputed_ecmult.c before the build.\n");
|
||||||
fprintf(fp, "#endif\n");
|
fprintf(fp, "#endif\n");
|
||||||
fprintf(fp, "#if defined(EXHAUSTIVE_TEST_ORDER)\n");
|
fprintf(fp, "#ifdef EXHAUSTIVE_TEST_ORDER\n");
|
||||||
fprintf(fp, "#if EXHAUSTIVE_TEST_ORDER == 13\n");
|
fprintf(fp, "#error Cannot compile precomputed_ecmult.c in exhaustive test mode\n");
|
||||||
fprintf(fp, "#define WINDOW_G %d\n", window_g_13);
|
fprintf(fp, "#endif /* EXHAUSTIVE_TEST_ORDER */\n");
|
||||||
fprintf(fp, "#elif EXHAUSTIVE_TEST_ORDER == 199\n");
|
|
||||||
fprintf(fp, "#define WINDOW_G %d\n", window_g_199);
|
|
||||||
fprintf(fp, "#else\n");
|
|
||||||
fprintf(fp, " #error No known generator for the specified exhaustive test group order.\n");
|
|
||||||
fprintf(fp, "#endif\n");
|
|
||||||
fprintf(fp, "static secp256k1_ge_storage secp256k1_pre_g[ECMULT_TABLE_SIZE(WINDOW_G)];\n");
|
|
||||||
fprintf(fp, "static secp256k1_ge_storage secp256k1_pre_g_128[ECMULT_TABLE_SIZE(WINDOW_G)];\n");
|
|
||||||
fprintf(fp, "#else /* !defined(EXHAUSTIVE_TEST_ORDER) */\n");
|
|
||||||
fprintf(fp, "#define WINDOW_G ECMULT_WINDOW_SIZE\n");
|
fprintf(fp, "#define WINDOW_G ECMULT_WINDOW_SIZE\n");
|
||||||
|
|
||||||
print_two_tables(fp, ECMULT_WINDOW_SIZE);
|
print_two_tables(fp, ECMULT_WINDOW_SIZE);
|
||||||
|
|
||||||
fprintf(fp, "#endif /* defined(EXHAUSTIVE_TEST_ORDER) */\n");
|
|
||||||
fprintf(fp, "#undef S\n");
|
fprintf(fp, "#undef S\n");
|
||||||
fprintf(fp, "#endif /* SECP256K1_PRECOMPUTED_ECMULT_H */\n");
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
16459
src/precomputed_ecmult.c
generated
Normal file
16459
src/precomputed_ecmult.c
generated
Normal file
File diff suppressed because it is too large
Load Diff
16460
src/precomputed_ecmult.h
16460
src/precomputed_ecmult.h
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user