Skip to content

Commit da51507

Browse files
committed
Merge #1058: Signed-digit multi-comb ecmult_gen algorithm
4c341f8 Add changelog entry for SDMC (Pieter Wuille) a043940 Permit COMB_BITS < 256 for exhaustive tests (Pieter Wuille) 39b2f2a Add test case for ecmult_gen recoded = {-1,0,1} (Pieter Wuille) 644e86d Reintroduce projective blinding (Pieter Wuille) 07810d9 Reduce side channels from single-bit reads (Peter Dettman) a0d32b5 Optimization: use Nx32 representation for recoded bits (Peter Dettman) e03dcc4 Make secp256k1_scalar_get_bits support 32-bit reads (Pieter Wuille) 5005abe Rename scalar_get_bits -> scalar_get_bits_limb32; return uint32_t (Pieter Wuille) 6247f48 Optimization: avoid unnecessary doublings in precomputation (Peter Dettman) 15d0cca Optimization: first table lookup needs no point addition (Pieter Wuille) 7a33db3 Optimization: move (2^COMB_BITS-1)/2 term into ctx->scalar_offset (Pieter Wuille) ed2a056 Provide 3 configurations accessible through ./configure (Pieter Wuille) 5f7be9f Always generate tables for current (blocks,teeth) config (Pieter Wuille) fde1dfc Signed-digit multi-comb ecmult_gen algorithm (Peter Dettman) 486518b Make exhaustive tests's scalar_inverse(&x,&x) work (Pieter Wuille) ab45c3e Initial gej blinding -> final ge blinding (Pieter Wuille) aa00a6b Introduce CEIL_DIV macro and use it (Tim Ruffing) Pull request description: ACKs for top commit: real-or-random: reACK 4c341f8 jonasnick: ACK 4c341f8 stratospher: ACK 4c341f8. Did [these benchmarks](#1058 (comment)) and saw a 12.4% on gcc 13.2.0 and 11.5% on clang 15.0.0. Also summarised how the precomputed table generation works [here](https://github.com/stratospher/blogosphere/blob/main/sdmc.md) for future me :) Tree-SHA512: 9a11138e4fb98b98e85c82cd46ed78b29fbe63d6efe61654ef519a64b1e175d63395a8a931c1646f9df8c7daacd796d5fe2384899d5a13a2c7ed2ded696ceed5
2 parents d831168 + 4c341f8 commit da51507

22 files changed

+2418
-9970
lines changed

.cirrus.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ env:
1111
BUILD: check
1212
### secp256k1 config
1313
ECMULTWINDOW: auto
14-
ECMULTGENPRECISION: auto
14+
ECMULTGENKB: auto
1515
ASM: no
1616
WIDEMUL: auto
1717
WITH_VALGRIND: yes

.github/workflows/ci.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ env:
2222
BUILD: 'check'
2323
### secp256k1 config
2424
ECMULTWINDOW: 'auto'
25-
ECMULTGENPRECISION: 'auto'
25+
ECMULTGENKB: 'auto'
2626
ASM: 'no'
2727
WIDEMUL: 'auto'
2828
WITH_VALGRIND: 'yes'
@@ -83,8 +83,8 @@ jobs:
8383
- env_vars: { CPPFLAGS: '-DDETERMINISTIC' }
8484
- env_vars: { CFLAGS: '-O0', CTIMETESTS: 'no' }
8585
- env_vars: { CFLAGS: '-O1', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' }
86-
- env_vars: { ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 }
87-
- env_vars: { ECMULTGENPRECISION: 8, ECMULTWINDOW: 4 }
86+
- env_vars: { ECMULTGENKB: 2, ECMULTWINDOW: 2 }
87+
- env_vars: { ECMULTGENKB: 86, ECMULTWINDOW: 4 }
8888
cc:
8989
- 'gcc'
9090
- 'clang'
@@ -377,8 +377,8 @@ jobs:
377377
configuration:
378378
- env_vars: { CC: 'clang', ASM: 'auto' }
379379
- env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'auto' }
380-
- env_vars: { CC: 'clang', ASM: 'no', ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 }
381-
- env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'no', ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 }
380+
- env_vars: { CC: 'clang', ASM: 'no', ECMULTGENKB: 2, ECMULTWINDOW: 2 }
381+
- env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'no', ECMULTGENKB: 2, ECMULTWINDOW: 2 }
382382

383383
env:
384384
# The `--error-exitcode` is required to make the test fail if valgrind found errors,
@@ -431,8 +431,8 @@ jobs:
431431
configuration:
432432
- env_vars: { CC: 'clang', ASM: 'auto' }
433433
- env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'auto' }
434-
- env_vars: { CC: 'clang', ASM: 'no', ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 }
435-
- env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'no', ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 }
434+
- env_vars: { CC: 'clang', ASM: 'no', ECMULTGENKB: 2, ECMULTWINDOW: 2 }
435+
- env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'no', ECMULTGENKB: 2, ECMULTWINDOW: 2 }
436436

437437
env:
438438
ECDH: 'yes'
@@ -487,7 +487,7 @@ jobs:
487487
- env_vars:
488488
CFLAGS: '-fsanitize=memory -fsanitize-recover=memory -g'
489489
- env_vars:
490-
ECMULTGENPRECISION: 2
490+
ECMULTGENKB: 2
491491
ECMULTWINDOW: 2
492492
CFLAGS: '-fsanitize=memory -fsanitize-recover=memory -g -O3'
493493

@@ -600,7 +600,7 @@ jobs:
600600
matrix:
601601
env_vars:
602602
- { WIDEMUL: 'int64', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' }
603-
- { WIDEMUL: 'int128_struct', ECMULTGENPRECISION: 2, ECMULTWINDOW: 4 }
603+
- { WIDEMUL: 'int128_struct', ECMULTGENKB: 2, ECMULTWINDOW: 4 }
604604
- { WIDEMUL: 'int128', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' }
605605
- { WIDEMUL: 'int128', RECOVERY: 'yes' }
606606
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' }

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
#### Changed
11+
- The implementation of the point multiplication algorithm used for signing and public key generation was changed, resulting in improved performance for those operations.
12+
- The related configure option `--ecmult-gen-precision` was replaced with `--ecmult-gen-kb` (`ECMULT_GEN_KB` for CMake).
13+
- This changes the supported precomputed table sizes for these operations. The new supported sizes are 2 KiB, 22 KiB, or 86 KiB (while the old supported sizes were 32 KiB, 64 KiB, or 512 KiB).
14+
1015
## [0.4.1] - 2023-12-21
1116

1217
#### Changed

CMakeLists.txt

+16-7
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,22 @@ if(SECP256K1_ECMULT_WINDOW_SIZE STREQUAL "AUTO")
101101
endif()
102102
add_compile_definitions(ECMULT_WINDOW_SIZE=${SECP256K1_ECMULT_WINDOW_SIZE})
103103

104-
set(SECP256K1_ECMULT_GEN_PREC_BITS "AUTO" CACHE STRING "Precision bits to tune the precomputed table size for signing, specified as integer 2, 4 or 8. \"AUTO\" is a reasonable setting for desktop machines (currently 4). [default=AUTO]")
105-
set_property(CACHE SECP256K1_ECMULT_GEN_PREC_BITS PROPERTY STRINGS "AUTO" 2 4 8)
106-
check_string_option_value(SECP256K1_ECMULT_GEN_PREC_BITS)
107-
if(SECP256K1_ECMULT_GEN_PREC_BITS STREQUAL "AUTO")
108-
set(SECP256K1_ECMULT_GEN_PREC_BITS 4)
104+
set(SECP256K1_ECMULT_GEN_KB "AUTO" CACHE STRING "The size of the precomputed table for signing in multiples of 1024 bytes (on typical platforms). Larger values result in possibly better signing or key generation performance at the cost of a larger table. Valid choices are 2, 22, 86. \"AUTO\" is a reasonable setting for desktop machines (currently 22). [default=AUTO]")
105+
set_property(CACHE SECP256K1_ECMULT_GEN_KB PROPERTY STRINGS "AUTO" 2 22 86)
106+
check_string_option_value(SECP256K1_ECMULT_GEN_KB)
107+
if(SECP256K1_ECMULT_GEN_KB STREQUAL "AUTO")
108+
set(SECP256K1_ECMULT_GEN_KB 22)
109+
endif()
110+
if(SECP256K1_ECMULT_GEN_KB EQUAL 2)
111+
add_compile_definitions(COMB_BLOCKS=2)
112+
add_compile_definitions(COMB_TEETH=5)
113+
elseif(SECP256K1_ECMULT_GEN_KB EQUAL 22)
114+
add_compile_definitions(COMB_BLOCKS=11)
115+
add_compile_definitions(COMB_TEETH=6)
116+
elseif(SECP256K1_ECMULT_GEN_KB EQUAL 86)
117+
add_compile_definitions(COMB_BLOCKS=43)
118+
add_compile_definitions(COMB_TEETH=6)
109119
endif()
110-
add_compile_definitions(ECMULT_GEN_PREC_BITS=${SECP256K1_ECMULT_GEN_PREC_BITS})
111120

112121
set(SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY "OFF" CACHE STRING "Test-only override of the (autodetected by the C code) \"widemul\" setting. Legal values are: \"OFF\", \"int128_struct\", \"int128\" or \"int64\". [default=OFF]")
113122
set_property(CACHE SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY PROPERTY STRINGS "OFF" "int128_struct" "int128" "int64")
@@ -294,7 +303,7 @@ message(" schnorrsig .......................... ${SECP256K1_ENABLE_MODULE_SCHNO
294303
message(" ElligatorSwift ...................... ${SECP256K1_ENABLE_MODULE_ELLSWIFT}")
295304
message("Parameters:")
296305
message(" ecmult window size .................. ${SECP256K1_ECMULT_WINDOW_SIZE}")
297-
message(" ecmult gen precision bits ........... ${SECP256K1_ECMULT_GEN_PREC_BITS}")
306+
message(" ecmult gen table size ............... ${SECP256K1_ECMULT_GEN_KB} KiB")
298307
message("Optional features:")
299308
message(" assembly ............................ ${SECP256K1_ASM}")
300309
message(" external callbacks .................. ${SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS}")

ci/ci.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ print_environment() {
1212
# There are many ways to print variable names and their content. This one
1313
# does not rely on bash.
1414
for var in WERROR_CFLAGS MAKEFLAGS BUILD \
15-
ECMULTWINDOW ECMULTGENPRECISION ASM WIDEMUL WITH_VALGRIND EXTRAFLAGS \
15+
ECMULTWINDOW ECMULTGENKB ASM WIDEMUL WITH_VALGRIND EXTRAFLAGS \
1616
EXPERIMENTAL ECDH RECOVERY SCHNORRSIG ELLSWIFT \
1717
SECP256K1_TEST_ITERS BENCH SECP256K1_BENCH_ITERS CTIMETESTS\
1818
EXAMPLES \
@@ -74,7 +74,7 @@ esac
7474
--enable-experimental="$EXPERIMENTAL" \
7575
--with-test-override-wide-multiply="$WIDEMUL" --with-asm="$ASM" \
7676
--with-ecmult-window="$ECMULTWINDOW" \
77-
--with-ecmult-gen-precision="$ECMULTGENPRECISION" \
77+
--with-ecmult-gen-kb="$ECMULTGENKB" \
7878
--enable-module-ecdh="$ECDH" --enable-module-recovery="$RECOVERY" \
7979
--enable-module-ellswift="$ELLSWIFT" \
8080
--enable-module-schnorrsig="$SCHNORRSIG" \

configure.ac

+20-15
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,12 @@ AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE|auto],
213213
)],
214214
[req_ecmult_window=$withval], [req_ecmult_window=auto])
215215

216-
AC_ARG_WITH([ecmult-gen-precision], [AS_HELP_STRING([--with-ecmult-gen-precision=2|4|8|auto],
217-
[Precision bits to tune the precomputed table size for signing.]
218-
[The size of the table is 32kB for 2 bits, 64kB for 4 bits, 512kB for 8 bits of precision.]
219-
[A larger table size usually results in possible faster signing.]
220-
["auto" is a reasonable setting for desktop machines (currently 4). [default=auto]]
216+
AC_ARG_WITH([ecmult-gen-kb], [AS_HELP_STRING([--with-ecmult-gen-kb=2|22|86|auto],
217+
[The size of the precomputed table for signing in multiples of 1024 bytes (on typical platforms).]
218+
[Larger values result in possibly better signing/keygeneration performance at the cost of a larger table.]
219+
["auto" is a reasonable setting for desktop machines (currently 22). [default=auto]]
221220
)],
222-
[req_ecmult_gen_precision=$withval], [req_ecmult_gen_precision=auto])
221+
[req_ecmult_gen_kb=$withval], [req_ecmult_gen_kb=auto])
223222

224223
AC_ARG_WITH([valgrind], [AS_HELP_STRING([--with-valgrind=yes|no|auto],
225224
[Build with extra checks for running inside Valgrind [default=auto]]
@@ -358,19 +357,25 @@ case $set_ecmult_window in
358357
;;
359358
esac
360359

361-
# Set ecmult gen precision
362-
if test x"$req_ecmult_gen_precision" = x"auto"; then
363-
set_ecmult_gen_precision=4
360+
# Set ecmult gen kb
361+
if test x"$req_ecmult_gen_kb" = x"auto"; then
362+
set_ecmult_gen_kb=22
364363
else
365-
set_ecmult_gen_precision=$req_ecmult_gen_precision
364+
set_ecmult_gen_kb=$req_ecmult_gen_kb
366365
fi
367366

368-
case $set_ecmult_gen_precision in
369-
2|4|8)
370-
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DECMULT_GEN_PREC_BITS=$set_ecmult_gen_precision"
367+
case $set_ecmult_gen_kb in
368+
2)
369+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DCOMB_BLOCKS=2 -DCOMB_TEETH=5"
370+
;;
371+
22)
372+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DCOMB_BLOCKS=11 -DCOMB_TEETH=6"
373+
;;
374+
86)
375+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DCOMB_BLOCKS=43 -DCOMB_TEETH=6"
371376
;;
372377
*)
373-
AC_MSG_ERROR(['ecmult gen precision not 2, 4, 8 or "auto"'])
378+
AC_MSG_ERROR(['ecmult gen table size not 2, 22, 86 or "auto"'])
374379
;;
375380
esac
376381

@@ -475,7 +480,7 @@ echo " module ellswift = $enable_module_ellswift"
475480
echo
476481
echo " asm = $set_asm"
477482
echo " ecmult window size = $set_ecmult_window"
478-
echo " ecmult gen prec. bits = $set_ecmult_gen_precision"
483+
echo " ecmult gen table size = $set_ecmult_gen_kb KiB"
479484
# Hide test-only options unless they're used.
480485
if test x"$set_widemul" != xauto; then
481486
echo " wide multiplication = $set_widemul"

src/ecmult_const_impl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, cons
214214
#ifdef VERIFY
215215
/* Verify that v1 and v2 are in range [0, 2^129-1]. */
216216
for (i = 129; i < 256; ++i) {
217-
VERIFY_CHECK(secp256k1_scalar_get_bits(&v1, i, 1) == 0);
218-
VERIFY_CHECK(secp256k1_scalar_get_bits(&v2, i, 1) == 0);
217+
VERIFY_CHECK(secp256k1_scalar_get_bits_limb32(&v1, i, 1) == 0);
218+
VERIFY_CHECK(secp256k1_scalar_get_bits_limb32(&v2, i, 1) == 0);
219219
}
220220
#endif
221221

src/ecmult_gen.h

+108-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/***********************************************************************
2-
* Copyright (c) 2013, 2014 Pieter Wuille *
2+
* Copyright (c) Pieter Wuille, Peter Dettman *
33
* Distributed under the MIT software license, see the accompanying *
44
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
55
***********************************************************************/
@@ -10,31 +10,126 @@
1010
#include "scalar.h"
1111
#include "group.h"
1212

13-
#ifndef ECMULT_GEN_PREC_BITS
14-
# define ECMULT_GEN_PREC_BITS 4
13+
14+
/* Configuration parameters for the signed-digit multi-comb algorithm:
15+
*
16+
* - COMB_BLOCKS is the number of blocks the input is split into. Each
17+
* has a corresponding table.
18+
* - COMB_TEETH is the number of bits simultaneously covered by one table.
19+
* - COMB_RANGE is the number of bits in supported scalars. For production
20+
* purposes, only 256 is reasonable, but smaller numbers are supported for
21+
* exhaustive test mode.
22+
*
23+
* The comb's spacing (COMB_SPACING), or the distance between the teeth,
24+
* is defined as ceil(COMB_RANGE / (COMB_BLOCKS * COMB_TEETH)). Each block covers
25+
* COMB_SPACING * COMB_TEETH consecutive bits in the input.
26+
*
27+
* The size of the precomputed table is COMB_BLOCKS * (1 << (COMB_TEETH - 1))
28+
* secp256k1_ge_storages.
29+
*
30+
* The number of point additions equals COMB_BLOCKS * COMB_SPACING. Each point
31+
* addition involves a cmov from (1 << (COMB_TEETH - 1)) table entries and a
32+
* conditional negation.
33+
*
34+
* The number of point doublings is COMB_SPACING - 1. */
35+
36+
#if defined(EXHAUSTIVE_TEST_ORDER)
37+
/* We need to control these values for exhaustive tests because
38+
* the table cannot have infinities in them (secp256k1_ge_storage
39+
* doesn't support infinities) */
40+
# undef COMB_BLOCKS
41+
# undef COMB_TEETH
42+
# if EXHAUSTIVE_TEST_ORDER == 7
43+
# define COMB_RANGE 3
44+
# define COMB_BLOCKS 1
45+
# define COMB_TEETH 2
46+
# elif EXHAUSTIVE_TEST_ORDER == 13
47+
# define COMB_RANGE 4
48+
# define COMB_BLOCKS 1
49+
# define COMB_TEETH 2
50+
# elif EXHAUSTIVE_TEST_ORDER == 199
51+
# define COMB_RANGE 8
52+
# define COMB_BLOCKS 2
53+
# define COMB_TEETH 3
54+
# else
55+
# error "Unknown exhaustive test order"
56+
# endif
57+
# if (COMB_RANGE >= 32) || ((EXHAUSTIVE_TEST_ORDER >> (COMB_RANGE - 1)) != 1)
58+
# error "COMB_RANGE != ceil(log2(EXHAUSTIVE_TEST_ORDER+1))"
59+
# endif
60+
#else /* !defined(EXHAUSTIVE_TEST_ORDER) */
61+
# define COMB_RANGE 256
62+
#endif /* defined(EXHAUSTIVE_TEST_ORDER) */
63+
64+
/* Use (11, 6) as default configuration, which results in a 22 kB table. */
65+
#ifndef COMB_BLOCKS
66+
# define COMB_BLOCKS 11
1567
# ifdef DEBUG_CONFIG
16-
# pragma message DEBUG_CONFIG_MSG("ECMULT_GEN_PREC_BITS undefined, assuming default value")
68+
# pragma message DEBUG_CONFIG_MSG("COMB_BLOCKS undefined, assuming default value")
1769
# endif
1870
#endif
71+
#ifndef COMB_TEETH
72+
# define COMB_TEETH 6
73+
# ifdef DEBUG_CONFIG
74+
# pragma message DEBUG_CONFIG_MSG("COMB_TEETH undefined, assuming default value")
75+
# endif
76+
#endif
77+
/* Use ceil(COMB_RANGE / (COMB_BLOCKS * COMB_TEETH)) as COMB_SPACING. */
78+
#define COMB_SPACING CEIL_DIV(COMB_RANGE, COMB_BLOCKS * COMB_TEETH)
1979

20-
#ifdef DEBUG_CONFIG
21-
# pragma message DEBUG_CONFIG_DEF(ECMULT_GEN_PREC_BITS)
80+
/* Range checks on the parameters. */
81+
82+
/* The remaining COMB_* parameters are derived values, don't modify these. */
83+
/* - The number of bits covered by all the blocks; must be at least COMB_RANGE. */
84+
#define COMB_BITS (COMB_BLOCKS * COMB_TEETH * COMB_SPACING)
85+
/* - The number of entries per table. */
86+
#define COMB_POINTS (1 << (COMB_TEETH - 1))
87+
88+
/* Sanity checks. */
89+
#if !(1 <= COMB_BLOCKS && COMB_BLOCKS <= 256)
90+
# error "COMB_BLOCKS must be in the range [1, 256]"
91+
#endif
92+
#if !(1 <= COMB_TEETH && COMB_TEETH <= 8)
93+
# error "COMB_TEETH must be in the range [1, 8]"
94+
#endif
95+
#if COMB_BITS < COMB_RANGE
96+
# error "COMB_BLOCKS * COMB_TEETH * COMB_SPACING is too low"
2297
#endif
2398

24-
#if ECMULT_GEN_PREC_BITS != 2 && ECMULT_GEN_PREC_BITS != 4 && ECMULT_GEN_PREC_BITS != 8
25-
# error "Set ECMULT_GEN_PREC_BITS to 2, 4 or 8."
99+
/* These last 2 checks are not strictly required, but prevent gratuitously inefficient
100+
* configurations. Note that they compare with 256 rather than COMB_RANGE, so they do
101+
* permit somewhat excessive values for the exhaustive test case, where testing with
102+
* suboptimal parameters may be desirable. */
103+
#if (COMB_BLOCKS - 1) * COMB_TEETH * COMB_SPACING >= 256
104+
# error "COMB_BLOCKS can be reduced"
105+
#endif
106+
#if COMB_BLOCKS * (COMB_TEETH - 1) * COMB_SPACING >= 256
107+
# error "COMB_TEETH can be reduced"
26108
#endif
27109

28-
#define ECMULT_GEN_PREC_G(bits) (1 << bits)
29-
#define ECMULT_GEN_PREC_N(bits) (256 / bits)
110+
#ifdef DEBUG_CONFIG
111+
# pragma message DEBUG_CONFIG_DEF(COMB_RANGE)
112+
# pragma message DEBUG_CONFIG_DEF(COMB_BLOCKS)
113+
# pragma message DEBUG_CONFIG_DEF(COMB_TEETH)
114+
# pragma message DEBUG_CONFIG_DEF(COMB_SPACING)
115+
#endif
30116

31117
typedef struct {
32118
/* Whether the context has been built. */
33119
int built;
34120

35-
/* Blinding values used when computing (n-b)G + bG. */
36-
secp256k1_scalar blind; /* -b */
37-
secp256k1_gej initial; /* bG */
121+
/* Values chosen such that
122+
*
123+
* n*G == comb(n + scalar_offset, G/2) + ge_offset.
124+
*
125+
* This expression lets us use scalar blinding and optimize the comb precomputation. See
126+
* ecmult_gen_impl.h for more details. */
127+
secp256k1_scalar scalar_offset;
128+
secp256k1_ge ge_offset;
129+
130+
/* Factor used for projective blinding. This value is used to rescale the Z
131+
* coordinate of the first table lookup. */
132+
secp256k1_fe proj_blind;
38133
} secp256k1_ecmult_gen_context;
39134

40135
static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context* ctx);

src/ecmult_gen_compute_table.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/***********************************************************************
2-
* Copyright (c) 2013, 2014, 2015 Pieter Wuille, Gregory Maxwell *
2+
* Copyright (c) Pieter Wuille, Gregory Maxwell *
33
* Distributed under the MIT software license, see the accompanying *
44
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
55
***********************************************************************/
@@ -9,6 +9,6 @@
99

1010
#include "ecmult_gen.h"
1111

12-
static void secp256k1_ecmult_gen_compute_table(secp256k1_ge_storage* table, const secp256k1_ge* gen, int bits);
12+
static void secp256k1_ecmult_gen_compute_table(secp256k1_ge_storage* table, const secp256k1_ge* gen, int blocks, int teeth, int spacing);
1313

1414
#endif /* SECP256K1_ECMULT_GEN_COMPUTE_TABLE_H */

0 commit comments

Comments
 (0)