/ src / secp256k1 / src / ecmult_compute_table_impl.h
ecmult_compute_table_impl.h
 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 secp256k1_ecmult_compute_table(secp256k1_ge_storage* table, int window_g, const secp256k1_gej* gen) {
17      secp256k1_gej gj;
18      secp256k1_ge ge, dgen;
19      size_t j;
20  
21      gj = *gen;
22      secp256k1_ge_set_gej_var(&ge, &gj);
23      secp256k1_ge_to_storage(&table[0], &ge);
24  
25      secp256k1_gej_double_var(&gj, gen, NULL);
26      secp256k1_ge_set_gej_var(&dgen, &gj);
27  
28      for (j = 1; j < ECMULT_TABLE_SIZE(window_g); ++j) {
29          secp256k1_gej_set_ge(&gj, &ge);
30          secp256k1_gej_add_ge_var(&gj, &gj, &dgen, NULL);
31          secp256k1_ge_set_gej_var(&ge, &gj);
32          secp256k1_ge_to_storage(&table[j], &ge);
33      }
34  }
35  
36  /* Like secp256k1_ecmult_compute_table, but one for both gen and gen*2^128. */
37  static void secp256k1_ecmult_compute_two_tables(secp256k1_ge_storage* table, secp256k1_ge_storage* table_128, int window_g, const secp256k1_ge* gen) {
38      secp256k1_gej gj;
39      int i;
40  
41      secp256k1_gej_set_ge(&gj, gen);
42      secp256k1_ecmult_compute_table(table, window_g, &gj);
43      for (i = 0; i < 128; ++i) {
44          secp256k1_gej_double_var(&gj, &gj, NULL);
45      }
46      secp256k1_ecmult_compute_table(table_128, window_g, &gj);
47  }
48  
49  #endif /* SECP256K1_ECMULT_COMPUTE_TABLE_IMPL_H */