refactor: Decouple table generation and ecmult_gen context
This commit is contained in:
parent
22dc2c0a0d
commit
e43ba02cfc
|
@ -9,8 +9,8 @@
|
|||
|
||||
#include "ecmult_gen.h"
|
||||
|
||||
static const size_t ECMULT_GEN_PREC_TABLE_SIZE = ROUND_TO_ALIGN(sizeof(*((secp256k1_ecmult_gen_context*) NULL)->prec));
|
||||
static const size_t ECMULT_GEN_PREC_TABLE_SIZE = ECMULT_GEN_PREC_N * ECMULT_GEN_PREC_G * sizeof(secp256k1_ge_storage);
|
||||
|
||||
static void secp256k1_ecmult_gen_create_prec_table(secp256k1_ecmult_gen_context *ctx, void **prealloc);
|
||||
static void secp256k1_ecmult_gen_create_prec_table(secp256k1_ge_storage* table);
|
||||
|
||||
#endif /* SECP256K1_ECMULT_GEN_PREC_H */
|
||||
|
|
|
@ -12,14 +12,11 @@
|
|||
#include "field_impl.h"
|
||||
#include "ecmult_gen.h"
|
||||
|
||||
static void secp256k1_ecmult_gen_create_prec_table(secp256k1_ecmult_gen_context *ctx, void **prealloc) {
|
||||
static void secp256k1_ecmult_gen_create_prec_table(secp256k1_ge_storage* table) {
|
||||
secp256k1_ge prec[ECMULT_GEN_PREC_N * ECMULT_GEN_PREC_G];
|
||||
secp256k1_gej gj;
|
||||
secp256k1_gej nums_gej;
|
||||
int i, j;
|
||||
size_t const prealloc_size = ECMULT_GEN_PREC_TABLE_SIZE;
|
||||
void* const base = *prealloc;
|
||||
ctx->prec = (secp256k1_ge_storage (*)[ECMULT_GEN_PREC_N][ECMULT_GEN_PREC_G])manual_alloc(prealloc, prealloc_size, base, prealloc_size);
|
||||
|
||||
/* get the generator */
|
||||
secp256k1_gej_set_ge(&gj, &secp256k1_ge_const_g);
|
||||
|
@ -70,7 +67,7 @@ static void secp256k1_ecmult_gen_create_prec_table(secp256k1_ecmult_gen_context
|
|||
}
|
||||
for (j = 0; j < ECMULT_GEN_PREC_N; j++) {
|
||||
for (i = 0; i < ECMULT_GEN_PREC_G; i++) {
|
||||
secp256k1_ge_to_storage(&(*ctx->prec)[j][i], &prec[j*ECMULT_GEN_PREC_G + i]);
|
||||
secp256k1_ge_to_storage(&table[j*ECMULT_GEN_PREC_G + i], &prec[j*ECMULT_GEN_PREC_G + i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,7 @@ static const secp256k1_callback default_error_callback = {
|
|||
};
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
secp256k1_ecmult_gen_context ctx;
|
||||
void *prealloc, *base;
|
||||
secp256k1_ge_storage* table;
|
||||
int inner;
|
||||
int outer;
|
||||
FILE* fp;
|
||||
|
@ -59,13 +58,12 @@ int main(int argc, char **argv) {
|
|||
fprintf(fp, "#endif\n");
|
||||
fprintf(fp, "static const secp256k1_ge_storage secp256k1_ecmult_static_context[ECMULT_GEN_PREC_N][ECMULT_GEN_PREC_G] = {\n");
|
||||
|
||||
base = checked_malloc(&default_error_callback, ECMULT_GEN_PREC_TABLE_SIZE);
|
||||
prealloc = base;
|
||||
secp256k1_ecmult_gen_create_prec_table(&ctx, &prealloc);
|
||||
table = checked_malloc(&default_error_callback, ECMULT_GEN_PREC_TABLE_SIZE);
|
||||
secp256k1_ecmult_gen_create_prec_table(table);
|
||||
for(outer = 0; outer != ECMULT_GEN_PREC_N; outer++) {
|
||||
fprintf(fp,"{\n");
|
||||
for(inner = 0; inner != ECMULT_GEN_PREC_G; inner++) {
|
||||
fprintf(fp," SC(%uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu)", SECP256K1_GE_STORAGE_CONST_GET((*ctx.prec)[outer][inner]));
|
||||
fprintf(fp," SC(%uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu)", SECP256K1_GE_STORAGE_CONST_GET(table[outer * ECMULT_GEN_PREC_G + inner]));
|
||||
if (inner != ECMULT_GEN_PREC_G - 1) {
|
||||
fprintf(fp,",\n");
|
||||
} else {
|
||||
|
@ -79,7 +77,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
}
|
||||
fprintf(fp,"};\n");
|
||||
free(base);
|
||||
free(table);
|
||||
|
||||
fprintf(fp, "#undef SC\n");
|
||||
fprintf(fp, "#endif\n");
|
||||
|
|
Loading…
Reference in New Issue