Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/gen_context.c
/********************************************************************** | /********************************************************************** | ||||
* Copyright (c) 2013, 2014, 2015 Thomas Daede, Cory Fields * | * Copyright (c) 2013, 2014, 2015 Thomas Daede, Cory Fields * | ||||
* Distributed under the MIT software license, see the accompanying * | * Distributed under the MIT software license, see the accompanying * | ||||
* file COPYING or http://www.opensource.org/licenses/mit-license.php.* | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* | ||||
**********************************************************************/ | **********************************************************************/ | ||||
#define USE_BASIC_CONFIG 1 | #define USE_BASIC_CONFIG 1 | ||||
#include "basic-config.h" | #include "basic-config.h" | ||||
#include "include/secp256k1.h" | #include "include/secp256k1.h" | ||||
#include "util.h" | |||||
#include "field_impl.h" | #include "field_impl.h" | ||||
#include "scalar_impl.h" | #include "scalar_impl.h" | ||||
#include "group_impl.h" | #include "group_impl.h" | ||||
#include "ecmult_gen_impl.h" | #include "ecmult_gen_impl.h" | ||||
static void default_error_callback_fn(const char* str, void* data) { | static void default_error_callback_fn(const char* str, void* data) { | ||||
(void)data; | (void)data; | ||||
fprintf(stderr, "[libsecp256k1] internal consistency check failed: %s\n", str); | fprintf(stderr, "[libsecp256k1] internal consistency check failed: %s\n", str); | ||||
abort(); | abort(); | ||||
} | } | ||||
static const secp256k1_callback default_error_callback = { | static const secp256k1_callback default_error_callback = { | ||||
default_error_callback_fn, | default_error_callback_fn, | ||||
NULL | NULL | ||||
}; | }; | ||||
int main(int argc, char **argv) { | int main(int argc, char **argv) { | ||||
secp256k1_ecmult_gen_context ctx; | secp256k1_ecmult_gen_context ctx; | ||||
void *prealloc, *base; | |||||
int inner; | int inner; | ||||
int outer; | int outer; | ||||
FILE* fp; | FILE* fp; | ||||
(void)argc; | (void)argc; | ||||
(void)argv; | (void)argv; | ||||
fp = fopen("src/ecmult_static_context.h","w"); | fp = fopen("src/ecmult_static_context.h","w"); | ||||
if (fp == NULL) { | if (fp == NULL) { | ||||
fprintf(stderr, "Could not open src/ecmult_static_context.h for writing!\n"); | fprintf(stderr, "Could not open src/ecmult_static_context.h for writing!\n"); | ||||
return -1; | return -1; | ||||
} | } | ||||
fprintf(fp, "#ifndef _SECP256K1_ECMULT_STATIC_CONTEXT_\n"); | fprintf(fp, "#ifndef _SECP256K1_ECMULT_STATIC_CONTEXT_\n"); | ||||
fprintf(fp, "#define _SECP256K1_ECMULT_STATIC_CONTEXT_\n"); | fprintf(fp, "#define _SECP256K1_ECMULT_STATIC_CONTEXT_\n"); | ||||
fprintf(fp, "#include \"src/group.h\"\n"); | fprintf(fp, "#include \"src/group.h\"\n"); | ||||
fprintf(fp, "#define SC SECP256K1_GE_STORAGE_CONST\n"); | fprintf(fp, "#define SC SECP256K1_GE_STORAGE_CONST\n"); | ||||
fprintf(fp, "static const secp256k1_ge_storage secp256k1_ecmult_static_context[64][16] = {\n"); | fprintf(fp, "static const secp256k1_ge_storage secp256k1_ecmult_static_context[64][16] = {\n"); | ||||
base = checked_malloc(&default_error_callback, SECP256K1_ECMULT_GEN_CONTEXT_PREALLOCATED_SIZE); | |||||
prealloc = base; | |||||
secp256k1_ecmult_gen_context_init(&ctx); | secp256k1_ecmult_gen_context_init(&ctx); | ||||
secp256k1_ecmult_gen_context_build(&ctx, &default_error_callback); | secp256k1_ecmult_gen_context_build(&ctx, &prealloc); | ||||
for(outer = 0; outer != 64; outer++) { | for(outer = 0; outer != 64; outer++) { | ||||
fprintf(fp,"{\n"); | fprintf(fp,"{\n"); | ||||
for(inner = 0; inner != 16; inner++) { | for(inner = 0; inner != 16; 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((*ctx.prec)[outer][inner])); | ||||
if (inner != 15) { | if (inner != 15) { | ||||
fprintf(fp,",\n"); | fprintf(fp,",\n"); | ||||
} else { | } else { | ||||
fprintf(fp,"\n"); | fprintf(fp,"\n"); | ||||
} | } | ||||
} | } | ||||
if (outer != 63) { | if (outer != 63) { | ||||
fprintf(fp,"},\n"); | fprintf(fp,"},\n"); | ||||
} else { | } else { | ||||
fprintf(fp,"}\n"); | fprintf(fp,"}\n"); | ||||
} | } | ||||
} | } | ||||
fprintf(fp,"};\n"); | fprintf(fp,"};\n"); | ||||
secp256k1_ecmult_gen_context_clear(&ctx); | secp256k1_ecmult_gen_context_clear(&ctx); | ||||
free(base); | |||||
fprintf(fp, "#undef SC\n"); | fprintf(fp, "#undef SC\n"); | ||||
fprintf(fp, "#endif\n"); | fprintf(fp, "#endif\n"); | ||||
fclose(fp); | fclose(fp); | ||||
return 0; | return 0; | ||||
} | } |