diff --git a/src/ecmult_gen_prec.h b/src/ecmult_gen_prec.h index 3c0958e20a5c3..cb8831af53e67 100644 --- a/src/ecmult_gen_prec.h +++ b/src/ecmult_gen_prec.h @@ -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 */ diff --git a/src/ecmult_gen_prec_impl.h b/src/ecmult_gen_prec_impl.h index dc028ba13ee87..fec7fb48ba6bf 100644 --- a/src/ecmult_gen_prec_impl.h +++ b/src/ecmult_gen_prec_impl.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]); } } } diff --git a/src/gen_context.c b/src/gen_context.c index 0e9df3682a12a..85652aec99bd9 100644 --- a/src/gen_context.c +++ b/src/gen_context.c @@ -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");