Skip to content

Commit 7502d8b

Browse files
committed
Move ecmult precomputation code to separate file
1 parent 6b18128 commit 7502d8b

File tree

4 files changed

+66
-32
lines changed

4 files changed

+66
-32
lines changed

Makefile.am

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ noinst_HEADERS += src/ecmult_gen.h
3232
noinst_HEADERS += src/ecmult_gen_impl.h
3333
noinst_HEADERS += src/ecmult_gen_prec.h
3434
noinst_HEADERS += src/ecmult_gen_prec_impl.h
35+
noinst_HEADERS += src/ecmult_prec.h
36+
noinst_HEADERS += src/ecmult_prec_impl.h
3537
noinst_HEADERS += src/field_10x26.h
3638
noinst_HEADERS += src/field_10x26_impl.h
3739
noinst_HEADERS += src/field_5x52.h

src/ecmult_prec.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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_PREC_H
8+
#define SECP256K1_ECMULT_PREC_H
9+
10+
#include "ecmult.h"
11+
12+
static void secp256k1_ecmult_create_prec_table(secp256k1_ge_storage* table, int window_g, const secp256k1_gej* gen);
13+
static void secp256k1_ecmult_create_prec_two_tables(secp256k1_ge_storage* table, secp256k1_ge_storage* table_128, int window_g, const secp256k1_ge* gen);
14+
15+
#endif /* SECP256K1_ECMULT_PREC_H */

src/ecmult_prec_impl.h

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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_PREC_IMPL_H
8+
#define SECP256K1_ECMULT_PREC_IMPL_H
9+
10+
#include "ecmult_prec.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_create_prec_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+
static void secp256k1_ecmult_create_prec_two_tables(secp256k1_ge_storage* table, secp256k1_ge_storage* table_128, int window_g, const secp256k1_ge* gen) {
37+
secp256k1_gej gj;
38+
int i;
39+
40+
secp256k1_gej_set_ge(&gj, gen);
41+
secp256k1_ecmult_create_prec_table(table, window_g, &gj);
42+
for (i = 0; i < 128; ++i) {
43+
secp256k1_gej_double_var(&gj, &gj, NULL);
44+
}
45+
secp256k1_ecmult_create_prec_table(table_128, window_g, &gj);
46+
}
47+
48+
#endif /* SECP256K1_ECMULT_PREC_IMPL_H */

src/precompute.c

+1-32
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,7 @@
2222
#include "ecmult.h"
2323
#include "ecmult_gen.h"
2424
#include "ecmult_gen_prec_impl.h"
25-
26-
static void secp256k1_ecmult_create_prec_table(secp256k1_ge_storage* table, int window_g, const secp256k1_gej* gen) {
27-
secp256k1_gej gj;
28-
secp256k1_ge ge, dgen;
29-
int j;
30-
31-
gj = *gen;
32-
secp256k1_ge_set_gej_var(&ge, &gj);
33-
secp256k1_ge_to_storage(&table[0], &ge);
34-
35-
secp256k1_gej_double_var(&gj, gen, NULL);
36-
secp256k1_ge_set_gej_var(&dgen, &gj);
37-
38-
for (j = 1; j < ECMULT_TABLE_SIZE(window_g); ++j) {
39-
secp256k1_gej_set_ge(&gj, &ge);
40-
secp256k1_gej_add_ge_var(&gj, &gj, &dgen, NULL);
41-
secp256k1_ge_set_gej_var(&ge, &gj);
42-
secp256k1_ge_to_storage(&table[j], &ge);
43-
}
44-
}
45-
46-
static void secp256k1_ecmult_create_prec_two_tables(secp256k1_ge_storage* table, secp256k1_ge_storage* table_128, int window_g, const secp256k1_ge* gen) {
47-
secp256k1_gej gj;
48-
int i;
49-
50-
secp256k1_gej_set_ge(&gj, gen);
51-
secp256k1_ecmult_create_prec_table(table, window_g, &gj);
52-
for (i = 0; i < 128; ++i) {
53-
secp256k1_gej_double_var(&gj, &gj, NULL);
54-
}
55-
secp256k1_ecmult_create_prec_table(table_128, window_g, &gj);
56-
}
25+
#include "ecmult_prec_impl.h"
5726

5827
static void precompute_ecmult_print_table(FILE *fp, const char *name, int window_g, const secp256k1_ge_storage* table, int with_conditionals) {
5928
int j;

0 commit comments

Comments
 (0)