csecp256k1

Haskell FFI bindings to bitcoin-core/secp256k1 (docs.ppad.tech/csecp256k1).
git clone git://git.ppad.tech/csecp256k1.git
Log | Files | Refs | README | LICENSE

ecmult_compute_table_impl.h (2235B)


      1 /*****************************************************************************************************
      2  * Copyright (c) 2013, 2014, 2017, 2021 Pieter Wuille, Andrew Poelstra, Jonas Nick, Russell O'Connor *
      3  * Distributed under the MIT software license, see the accompanying                                  *
      4  * file COPYING or https://www.opensource.org/licenses/mit-license.php.                              *
      5  *****************************************************************************************************/
      6 
      7 #ifndef SECP256K1_ECMULT_COMPUTE_TABLE_IMPL_H
      8 #define SECP256K1_ECMULT_COMPUTE_TABLE_IMPL_H
      9 
     10 #include "ecmult_compute_table.h"
     11 #include "group_impl.h"
     12 #include "field_impl.h"
     13 #include "ecmult.h"
     14 #include "util.h"
     15 
     16 static void haskellsecp256k1_v0_1_0_ecmult_compute_table(haskellsecp256k1_v0_1_0_ge_storage* table, int window_g, const haskellsecp256k1_v0_1_0_gej* gen) {
     17     haskellsecp256k1_v0_1_0_gej gj;
     18     haskellsecp256k1_v0_1_0_ge ge, dgen;
     19     int j;
     20 
     21     gj = *gen;
     22     haskellsecp256k1_v0_1_0_ge_set_gej_var(&ge, &gj);
     23     haskellsecp256k1_v0_1_0_ge_to_storage(&table[0], &ge);
     24 
     25     haskellsecp256k1_v0_1_0_gej_double_var(&gj, gen, NULL);
     26     haskellsecp256k1_v0_1_0_ge_set_gej_var(&dgen, &gj);
     27 
     28     for (j = 1; j < ECMULT_TABLE_SIZE(window_g); ++j) {
     29         haskellsecp256k1_v0_1_0_gej_set_ge(&gj, &ge);
     30         haskellsecp256k1_v0_1_0_gej_add_ge_var(&gj, &gj, &dgen, NULL);
     31         haskellsecp256k1_v0_1_0_ge_set_gej_var(&ge, &gj);
     32         haskellsecp256k1_v0_1_0_ge_to_storage(&table[j], &ge);
     33     }
     34 }
     35 
     36 /* Like haskellsecp256k1_v0_1_0_ecmult_compute_table, but one for both gen and gen*2^128. */
     37 static void haskellsecp256k1_v0_1_0_ecmult_compute_two_tables(haskellsecp256k1_v0_1_0_ge_storage* table, haskellsecp256k1_v0_1_0_ge_storage* table_128, int window_g, const haskellsecp256k1_v0_1_0_ge* gen) {
     38     haskellsecp256k1_v0_1_0_gej gj;
     39     int i;
     40 
     41     haskellsecp256k1_v0_1_0_gej_set_ge(&gj, gen);
     42     haskellsecp256k1_v0_1_0_ecmult_compute_table(table, window_g, &gj);
     43     for (i = 0; i < 128; ++i) {
     44         haskellsecp256k1_v0_1_0_gej_double_var(&gj, &gj, NULL);
     45     }
     46     haskellsecp256k1_v0_1_0_ecmult_compute_table(table_128, window_g, &gj);
     47 }
     48 
     49 #endif /* SECP256K1_ECMULT_COMPUTE_TABLE_IMPL_H */