Bitcoin Core  24.99.0
P2P Digital Currency
ecmult_compute_table_impl.h
Go to the documentation of this file.
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  int 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 */
#define ECMULT_TABLE_SIZE(w)
The number of entries a table with precomputed multiples needs to have.
Definition: ecmult.h:30
static void secp256k1_ecmult_compute_table(secp256k1_ge_storage *table, int window_g, const secp256k1_gej *gen)
static void secp256k1_ecmult_compute_two_tables(secp256k1_ge_storage *table, secp256k1_ge_storage *table_128, int window_g, const secp256k1_ge *gen)
static void secp256k1_gej_double_var(secp256k1_gej *r, const secp256k1_gej *a, secp256k1_fe *rzr)
Set r equal to the double of a.
static void secp256k1_gej_add_ge_var(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b, secp256k1_fe *rzr)
Set r equal to the sum of a and b (with b given in affine coordinates).
static void secp256k1_gej_set_ge(secp256k1_gej *r, const secp256k1_ge *a)
Set a group element (jacobian) equal to another which is given in affine coordinates.
static void secp256k1_ge_to_storage(secp256k1_ge_storage *r, const secp256k1_ge *a)
Convert a group element to the storage type.
static void secp256k1_ge_set_gej_var(secp256k1_ge *r, secp256k1_gej *a)
Set a group element equal to another which is given in jacobian coordinates.
A group element in affine coordinates on the secp256k1 curve, or occasionally on an isomorphic curve ...
Definition: group.h:16
A group element of the secp256k1 curve, in jacobian coordinates.
Definition: group.h:28