2022-03-08 19:45:41 +00:00
|
|
|
/*****************************************************************************************************
|
|
|
|
* Copyright (c) 2013, 2014, 2017, 2021 Pieter Wuille, Andrew Poelstra, Jonas Nick, Russell O'Connor *
|
|
|
|
* Distributed under the MIT software license, see the accompanying *
|
|
|
|
* file COPYING or https://www.opensource.org/licenses/mit-license.php. *
|
|
|
|
*****************************************************************************************************/
|
|
|
|
|
|
|
|
#ifndef SECP256K1_ECMULT_COMPUTE_TABLE_IMPL_H
|
|
|
|
#define SECP256K1_ECMULT_COMPUTE_TABLE_IMPL_H
|
|
|
|
|
|
|
|
#include "ecmult_compute_table.h"
|
|
|
|
#include "group_impl.h"
|
|
|
|
#include "field_impl.h"
|
|
|
|
#include "ecmult.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2023-03-17 05:22:01 +00:00
|
|
|
static void rustsecp256k1_v0_8_1_ecmult_compute_table(rustsecp256k1_v0_8_1_ge_storage* table, int window_g, const rustsecp256k1_v0_8_1_gej* gen) {
|
|
|
|
rustsecp256k1_v0_8_1_gej gj;
|
|
|
|
rustsecp256k1_v0_8_1_ge ge, dgen;
|
2022-03-08 19:45:41 +00:00
|
|
|
int j;
|
|
|
|
|
|
|
|
gj = *gen;
|
2023-03-17 05:22:01 +00:00
|
|
|
rustsecp256k1_v0_8_1_ge_set_gej_var(&ge, &gj);
|
|
|
|
rustsecp256k1_v0_8_1_ge_to_storage(&table[0], &ge);
|
2022-03-08 19:45:41 +00:00
|
|
|
|
2023-03-17 05:22:01 +00:00
|
|
|
rustsecp256k1_v0_8_1_gej_double_var(&gj, gen, NULL);
|
|
|
|
rustsecp256k1_v0_8_1_ge_set_gej_var(&dgen, &gj);
|
2022-03-08 19:45:41 +00:00
|
|
|
|
|
|
|
for (j = 1; j < ECMULT_TABLE_SIZE(window_g); ++j) {
|
2023-03-17 05:22:01 +00:00
|
|
|
rustsecp256k1_v0_8_1_gej_set_ge(&gj, &ge);
|
|
|
|
rustsecp256k1_v0_8_1_gej_add_ge_var(&gj, &gj, &dgen, NULL);
|
|
|
|
rustsecp256k1_v0_8_1_ge_set_gej_var(&ge, &gj);
|
|
|
|
rustsecp256k1_v0_8_1_ge_to_storage(&table[j], &ge);
|
2022-03-08 19:45:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-17 05:22:01 +00:00
|
|
|
/* Like rustsecp256k1_v0_8_1_ecmult_compute_table, but one for both gen and gen*2^128. */
|
|
|
|
static void rustsecp256k1_v0_8_1_ecmult_compute_two_tables(rustsecp256k1_v0_8_1_ge_storage* table, rustsecp256k1_v0_8_1_ge_storage* table_128, int window_g, const rustsecp256k1_v0_8_1_ge* gen) {
|
|
|
|
rustsecp256k1_v0_8_1_gej gj;
|
2022-03-08 19:45:41 +00:00
|
|
|
int i;
|
|
|
|
|
2023-03-17 05:22:01 +00:00
|
|
|
rustsecp256k1_v0_8_1_gej_set_ge(&gj, gen);
|
|
|
|
rustsecp256k1_v0_8_1_ecmult_compute_table(table, window_g, &gj);
|
2022-03-08 19:45:41 +00:00
|
|
|
for (i = 0; i < 128; ++i) {
|
2023-03-17 05:22:01 +00:00
|
|
|
rustsecp256k1_v0_8_1_gej_double_var(&gj, &gj, NULL);
|
2022-03-08 19:45:41 +00:00
|
|
|
}
|
2023-03-17 05:22:01 +00:00
|
|
|
rustsecp256k1_v0_8_1_ecmult_compute_table(table_128, window_g, &gj);
|
2022-03-08 19:45:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* SECP256K1_ECMULT_COMPUTE_TABLE_IMPL_H */
|