github.com/SmartMeshFoundation/Spectrum@v0.0.0-20220621030607-452a266fee1e/crypto/secp256k1/libsecp256k1/src/gen_context.c (about)

     1  /**********************************************************************
     2   * Copyright (c) 2013, 2014, 2015 Thomas Daede, Cory Fields           *
     3   * Distributed under the MIT software license, see the accompanying   *
     4   * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
     5   **********************************************************************/
     6  
     7  #define USE_BASIC_CONFIG 1
     8  
     9  #include "basic-config.h"
    10  #include "include/secp256k1.h"
    11  #include "field_impl.h"
    12  #include "scalar_impl.h"
    13  #include "group_impl.h"
    14  #include "ecmult_gen_impl.h"
    15  
    16  static void default_error_callback_fn(const char* str, void* data) {
    17      (void)data;
    18      fprintf(stderr, "[libsecp256k1] internal consistency check failed: %s\n", str);
    19      abort();
    20  }
    21  
    22  static const secp256k1_callback default_error_callback = {
    23      default_error_callback_fn,
    24      NULL
    25  };
    26  
    27  int main(int argc, char **argv) {
    28      secp256k1_ecmult_gen_context ctx;
    29      int inner;
    30      int outer;
    31      FILE* fp;
    32  
    33      (void)argc;
    34      (void)argv;
    35  
    36      fp = fopen("src/ecmult_static_context.h","w");
    37      if (fp == NULL) {
    38          fprintf(stderr, "Could not open src/ecmult_static_context.h for writing!\n");
    39          return -1;
    40      }
    41      
    42      fprintf(fp, "#ifndef _SECP256K1_ECMULT_STATIC_CONTEXT_\n");
    43      fprintf(fp, "#define _SECP256K1_ECMULT_STATIC_CONTEXT_\n");
    44      fprintf(fp, "#include \"group.h\"\n");
    45      fprintf(fp, "#define SC SECP256K1_GE_STORAGE_CONST\n");
    46      fprintf(fp, "static const secp256k1_ge_storage secp256k1_ecmult_static_context[64][16] = {\n");
    47  
    48      secp256k1_ecmult_gen_context_init(&ctx);
    49      secp256k1_ecmult_gen_context_build(&ctx, &default_error_callback);
    50      for(outer = 0; outer != 64; outer++) {
    51          fprintf(fp,"{\n");
    52          for(inner = 0; inner != 16; inner++) {
    53              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]));
    54              if (inner != 15) {
    55                  fprintf(fp,",\n");
    56              } else {
    57                  fprintf(fp,"\n");
    58              }
    59          }
    60          if (outer != 63) {
    61              fprintf(fp,"},\n");
    62          } else {
    63              fprintf(fp,"}\n");
    64          }
    65      }
    66      fprintf(fp,"};\n");
    67      secp256k1_ecmult_gen_context_clear(&ctx);
    68      
    69      fprintf(fp, "#undef SC\n");
    70      fprintf(fp, "#endif\n");
    71      fclose(fp);
    72      
    73      return 0;
    74  }