Skip to content

Commit d057eae

Browse files
committed
Squashed 'src/secp256k1/' changes from be8d9c2..fecf436
fecf436 Merge bitcoin-core/secp256k1#1019: build: don't append valgrind CPPFLAGS if not installed (macOS) 2e5e4b6 Merge bitcoin-core/secp256k1#1020: doc: remove use of <0xa0> "no break space" 812ff5c doc: remove use of 0xa0 "no break space" 214042a build: don't append valgrind CPPFLAGS if not installed 793ad90 Merge bitcoin-core/secp256k1#1010: doc: Minor fixes in safegcd_implementation.md dc9b685 doc: Minor fixes in safegcd_implementation.md ea5e8a9 Merge bitcoin-core/secp256k1#1012: Fix typos 2332975 Fix typos 7006f1b Merge bitcoin-core/secp256k1#1011: ci: Enable -g if we set CFLAGS manually 72de135 ci: Enable -g if we set CFLAGS manually 74c34e7 Merge bitcoin-core/secp256k1#1009: refactor: Use (int)&(int) in boolean context to avoid compiler warning 16d1322 refactor: Use (int)&(int) in boolean context to avoid compiler warning c74a7b7 Merge bitcoin-core/secp256k1#1007: doc: Replace apoelstra's GPG key by jonasnick's GPG key 3b157c4 doc: Suggest keys.openpgp.org as keyserver in SECURITY.md 73a7472 doc: Replace apoelstra's GPG key by jonasnick's GPG key 515a5db Merge bitcoin-core/secp256k1#991: Merge all "external" benchmarks into a single bench binary af6abcb Make bench support selecting which benchmarks to run 9f56bdf Merge bench_schnorrsig into bench 3208557 Merge bench_recover into bench 855e18d Merge bench_ecdh into bench 2a7be67 Combine bench_sign and bench_verify into single bench 8fa4120 Merge bitcoin-core/secp256k1#1002: Make aux_rnd32==NULL behave identical to 0x0000..00. 5324f89 Make aux_rnd32==NULL behave identical to 0x0000..00. 21c188b Merge bitcoin-core/secp256k1#943: VERIFY_CHECK precondition for secp256k1_fe_set_int. 3e7b2ea Merge bitcoin-core/secp256k1#999: bench_ecmult: improve clarity of output 23e2f66 bench: don't return 1 in have_flag() if argc = 1 96b1ad2 bench_ecmult: improve clarity of output 20d791e Merge bitcoin-core/secp256k1#989: Shared benchmark format for command line and CSV outputs aa1b889 Merge bitcoin-core/secp256k1#996: Fix G.y parity in sage code 044d956 Fix G.y parity in sage code b4b1306 create csv file from the benchmark output 26a255b Shared benchmark format for command line and CSV outputs 9526874 Merge bitcoin-core/secp256k1#810: Avoid overly-wide multiplications in 5x52 field mul/sqr 920a0e5 Merge bitcoin-core/secp256k1#952: Avoid computing out-of-bounds pointer. f34b5ca Merge bitcoin-core/secp256k1#983: [RFC] Remove OpenSSL testing support 297ce82 Merge bitcoin-core/secp256k1#966: Make aux_rand32 arg to secp256k1_schnorrsig_sign const 2888640 VERIFY_CHECK precondition for secp256k1_fe_set_int. d49011f Make _set_fe_int( . , 0 ) set magnitude to 0 bc08599 Remove OpenSSL testing support 10f9bd8 Merge bitcoin-core/secp256k1#987: Fix unused parameter warnings when building without VERIFY 189f6bc Fix unused parameter warnings when building without VERIFY da0092b Merge bitcoin-core/secp256k1#986: tests: remove `secp256k1_fe_verify` from tests.c and modify `_fe_from_storage` to call `_fe_verify` d439937 tests: remove `secp256k1_fe_verify` from tests.c and modify `secp256k1_fe_from_storage` to call `secp256k1_fe_verify` 2a3a97c Merge bitcoin-core/secp256k1#976: `secp256k1_schnorrsig_sign_internal` should be static aa5d34a Merge bitcoin-core/secp256k1#783: Make the public API docs more consistent and explicit 7271387 Add missing static to secp256k1_schnorrsig_sign_internal db4667d Make aux_rand32 arg to secp256k1_schnorrsig_sign const 9a5a87e Merge bitcoin-core/secp256k1#956: Replace ecmult_context with a generated static array. 20abd52 Add tests for pre_g tables. 6815761 Remove ecmult_context. f20dcbb Correct typo. 16a3cc0 Generate ecmult_static_pre_g.h 8de2d86 Bump memory limits in advance of making the ecmult context static. d7ec49a Merge bitcoin-core/secp256k1#969: ci: Fixes after Debian release 5d5c74a tests: Rewrite code to circument potential bug in clang 3d2f492 ci: Install libasan6 (instead of 5) after Debian upgrade adec5a1 Add missing null check for ctx and input keys in the public API f4edfc7 Improve consistency for NULL arguments in the public interface 9be7b0f Avoid computing out-of-bounds pointer. b53e0cd Avoid overly-wide multiplications git-subtree-dir: src/secp256k1 git-subtree-split: fecf436
1 parent c020cba commit d057eae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+17466
-1112
lines changed

.cirrus.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,13 @@ task:
278278
container:
279279
dockerfile: ci/linux-debian.Dockerfile
280280
cpu: 1
281-
memory: 1G
281+
memory: 2G
282282
env:
283283
ECDH: yes
284284
RECOVERY: yes
285285
EXPERIMENTAL: yes
286286
SCHNORRSIG: yes
287287
CTIMETEST: no
288-
EXTRAFLAGS: "--disable-openssl-tests"
289288
matrix:
290289
- name: "Valgrind (memcheck)"
291290
env:
@@ -294,8 +293,8 @@ task:
294293
TEST_ITERS: 16
295294
- name: "UBSan, ASan, LSan"
296295
env:
297-
CFLAGS: "-fsanitize=undefined,address"
298-
CFLAGS_FOR_BUILD: "-fsanitize=undefined,address"
296+
CFLAGS: "-fsanitize=undefined,address -g"
297+
CFLAGS_FOR_BUILD: "-fsanitize=undefined,address -g"
299298
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
300299
ASAN_OPTIONS: "strict_string_checks=1:detect_stack_use_after_return=1:detect_leaks=1"
301300
LSAN_OPTIONS: "use_unaligned=1"
@@ -330,7 +329,7 @@ task:
330329
# ./configure correctly errors out when given CC=g++.
331330
# We hack around this by passing CC=g++ only to make.
332331
CC: gcc
333-
MAKEFLAGS: -j2 CC=g++ CFLAGS=-fpermissive
332+
MAKEFLAGS: -j2 CC=g++ CFLAGS=-fpermissive\ -g
334333
WERROR_CFLAGS:
335334
EXPERIMENTAL: yes
336335
ECDH: yes

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/ecmult_static_pre_g.h linguist-generated

.gitignore

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
bench_inv
2-
bench_ecdh
1+
bench
32
bench_ecmult
4-
bench_schnorrsig
5-
bench_sign
6-
bench_verify
7-
bench_recover
83
bench_internal
94
tests
105
exhaustive_tests
116
gen_context
7+
gen_ecmult_static_pre_g
128
valgrind_ctime_test
139
*.exe
1410
*.so
1511
*.a
12+
*.csv
1613
!.gitignore
1714

1815
Makefile

Makefile.am

+12-9
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,9 @@ endif
8181

8282
noinst_PROGRAMS =
8383
if USE_BENCHMARK
84-
noinst_PROGRAMS += bench_verify bench_sign bench_internal bench_ecmult
85-
bench_verify_SOURCES = src/bench_verify.c
86-
bench_verify_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
87-
# SECP_TEST_INCLUDES are only used here for CRYPTO_CPPFLAGS
88-
bench_verify_CPPFLAGS = $(SECP_TEST_INCLUDES)
89-
bench_sign_SOURCES = src/bench_sign.c
90-
bench_sign_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
84+
noinst_PROGRAMS += bench bench_internal bench_ecmult
85+
bench_SOURCES = src/bench.c
86+
bench_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
9187
bench_internal_SOURCES = src/bench_internal.c
9288
bench_internal_LDADD = $(SECP_LIBS) $(COMMON_LIB)
9389
bench_internal_CPPFLAGS = $(SECP_INCLUDES)
@@ -127,12 +123,19 @@ exhaustive_tests_LDFLAGS = -static
127123
TESTS += exhaustive_tests
128124
endif
129125

126+
EXTRA_PROGRAMS = gen_ecmult_static_pre_g
127+
gen_ecmult_static_pre_g_SOURCES = src/gen_ecmult_static_pre_g.c
128+
# See Automake manual, Section "Errors with distclean"
129+
src/ecmult_static_pre_g.h:
130+
$(MAKE) $(AM_MAKEFLAGS) gen_ecmult_static_pre_g$(EXEEXT)
131+
./gen_ecmult_static_pre_g$(EXEEXT)
132+
130133
if USE_ECMULT_STATIC_PRECOMPUTATION
131134
CPPFLAGS_FOR_BUILD +=-I$(top_srcdir) -I$(builddir)/src
132135

133136
gen_context_OBJECTS = gen_context.o
134137
gen_context_BIN = gen_context$(BUILD_EXEEXT)
135-
gen_%.o: src/gen_%.c src/libsecp256k1-config.h
138+
$(gen_context_OBJECTS): src/gen_context.c src/libsecp256k1-config.h
136139
$(CC_FOR_BUILD) $(DEFS) $(CPPFLAGS_FOR_BUILD) $(SECP_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -c $< -o $@
137140

138141
$(gen_context_BIN): $(gen_context_OBJECTS)
@@ -149,7 +152,7 @@ src/ecmult_static_context.h: $(gen_context_BIN)
149152
CLEANFILES = $(gen_context_BIN) src/ecmult_static_context.h
150153
endif
151154

152-
EXTRA_DIST = autogen.sh src/gen_context.c src/basic-config.h
155+
EXTRA_DIST = autogen.sh src/gen_context.c src/ecmult_static_pre_g.h src/basic-config.h
153156

154157
if ENABLE_MODULE_ECDH
155158
include src/modules/ecdh/Makefile.am.include

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ To create a HTML report with coloured and annotated source code:
100100
$ mkdir -p coverage
101101
$ gcovr --exclude 'src/bench*' --html --html-details -o coverage/coverage.html
102102

103+
Benchmark
104+
------------
105+
If configured with `--enable-benchmark` (which is the default), binaries for benchmarking the libsecp256k1 functions will be present in the root directory after the build.
106+
107+
To print the benchmark result to the command line:
108+
109+
$ ./bench_name
110+
111+
To create a CSV file for the benchmark result :
112+
113+
$ ./bench_name | sed '2d;s/ \{1,\}//g' > bench_name.csv
114+
103115
Reporting a vulnerability
104116
------------
105117

SECURITY.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The following keys may be used to communicate sensitive information to developer
99
| Name | Fingerprint |
1010
|------|-------------|
1111
| Pieter Wuille | 133E AC17 9436 F14A 5CF1 B794 860F EB80 4E66 9320 |
12-
| Andrew Poelstra | 699A 63EF C17A D3A9 A34C FFC0 7AD0 A91C 40BD 0091 |
12+
| Jonas Nick | 36C7 1A37 C9D9 88BD E825 08D9 B1A7 0E4F 8DCD 0366 |
1313
| Tim Ruffing | 09E0 3F87 1092 E40E 106E 902B 33BC 86AB 80FF 5516 |
1414

15-
You can import a key by running the following command with that individual’s fingerprint: `gpg --recv-keys "<fingerprint>"` Ensure that you put quotes around fingerprints containing spaces.
15+
You can import a key by running the following command with that individual’s fingerprint: `gpg --keyserver hkps://keys.openpgp.org --recv-keys "<fingerprint>"` Ensure that you put quotes around fingerprints containing spaces.

build-aux/m4/bitcoin_secp.m4

-66
Original file line numberDiff line numberDiff line change
@@ -9,72 +9,6 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
99
AC_MSG_RESULT([$has_64bit_asm])
1010
])
1111

12-
dnl
13-
AC_DEFUN([SECP_OPENSSL_CHECK],[
14-
has_libcrypto=no
15-
m4_ifdef([PKG_CHECK_MODULES],[
16-
PKG_CHECK_MODULES([CRYPTO], [libcrypto], [has_libcrypto=yes],[has_libcrypto=no])
17-
if test x"$has_libcrypto" = x"yes"; then
18-
TEMP_LIBS="$LIBS"
19-
LIBS="$LIBS $CRYPTO_LIBS"
20-
AC_CHECK_LIB(crypto, main,[AC_DEFINE(HAVE_LIBCRYPTO,1,[Define this symbol if libcrypto is installed])],[has_libcrypto=no])
21-
LIBS="$TEMP_LIBS"
22-
fi
23-
])
24-
if test x$has_libcrypto = xno; then
25-
AC_CHECK_HEADER(openssl/crypto.h,[
26-
AC_CHECK_LIB(crypto, main,[
27-
has_libcrypto=yes
28-
CRYPTO_LIBS=-lcrypto
29-
AC_DEFINE(HAVE_LIBCRYPTO,1,[Define this symbol if libcrypto is installed])
30-
])
31-
])
32-
LIBS=
33-
fi
34-
if test x"$has_libcrypto" = x"yes" && test x"$has_openssl_ec" = x; then
35-
AC_MSG_CHECKING(for EC functions in libcrypto)
36-
CPPFLAGS_TEMP="$CPPFLAGS"
37-
CPPFLAGS="$CRYPTO_CPPFLAGS $CPPFLAGS"
38-
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
39-
#include <openssl/bn.h>
40-
#include <openssl/ec.h>
41-
#include <openssl/ecdsa.h>
42-
#include <openssl/obj_mac.h>]],[[
43-
# if OPENSSL_VERSION_NUMBER < 0x10100000L
44-
void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps) {(void)sig->r; (void)sig->s;}
45-
# endif
46-
47-
unsigned int zero = 0;
48-
const unsigned char *zero_ptr = (unsigned char*)&zero;
49-
EC_KEY_free(EC_KEY_new_by_curve_name(NID_secp256k1));
50-
EC_KEY *eckey = EC_KEY_new();
51-
EC_GROUP *group = EC_GROUP_new_by_curve_name(NID_secp256k1);
52-
EC_KEY_set_group(eckey, group);
53-
ECDSA_sign(0, NULL, 0, NULL, &zero, eckey);
54-
ECDSA_verify(0, NULL, 0, NULL, 0, eckey);
55-
o2i_ECPublicKey(&eckey, &zero_ptr, 0);
56-
d2i_ECPrivateKey(&eckey, &zero_ptr, 0);
57-
EC_KEY_check_key(eckey);
58-
EC_KEY_free(eckey);
59-
EC_GROUP_free(group);
60-
ECDSA_SIG *sig_openssl;
61-
sig_openssl = ECDSA_SIG_new();
62-
d2i_ECDSA_SIG(&sig_openssl, &zero_ptr, 0);
63-
i2d_ECDSA_SIG(sig_openssl, NULL);
64-
ECDSA_SIG_get0(sig_openssl, NULL, NULL);
65-
ECDSA_SIG_free(sig_openssl);
66-
const BIGNUM *bignum = BN_value_one();
67-
BN_is_negative(bignum);
68-
BN_num_bits(bignum);
69-
if (sizeof(zero) >= BN_num_bytes(bignum)) {
70-
BN_bn2bin(bignum, (unsigned char*)&zero);
71-
}
72-
]])],[has_openssl_ec=yes],[has_openssl_ec=no])
73-
AC_MSG_RESULT([$has_openssl_ec])
74-
CPPFLAGS="$CPPFLAGS_TEMP"
75-
fi
76-
])
77-
7812
AC_DEFUN([SECP_VALGRIND_CHECK],[
7913
if test x"$has_valgrind" != x"yes"; then
8014
CPPFLAGS_TEMP="$CPPFLAGS"

ci/cirrus.sh

+2-15
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ make
2626

2727
# Print information about binaries so that we can see that the architecture is correct
2828
file *tests* || true
29-
file bench_* || true
29+
file bench* || true
3030
file .libs/* || true
3131

3232
# This tells `make check` to wrap test invocations.
@@ -49,21 +49,8 @@ then
4949
{
5050
$EXEC ./bench_ecmult
5151
$EXEC ./bench_internal
52-
$EXEC ./bench_sign
53-
$EXEC ./bench_verify
52+
$EXEC ./bench
5453
} >> bench.log 2>&1
55-
if [ "$RECOVERY" = "yes" ]
56-
then
57-
$EXEC ./bench_recover >> bench.log 2>&1
58-
fi
59-
if [ "$ECDH" = "yes" ]
60-
then
61-
$EXEC ./bench_ecdh >> bench.log 2>&1
62-
fi
63-
if [ "$SCHNORRSIG" = "yes" ]
64-
then
65-
$EXEC ./bench_schnorrsig >> bench.log 2>&1
66-
fi
6754
fi
6855
if [ "$CTIMETEST" = "yes" ]
6956
then

ci/linux-debian.Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ RUN apt-get install --no-install-recommends --no-upgrade -y \
1414
make automake libtool pkg-config dpkg-dev valgrind qemu-user \
1515
gcc clang llvm libc6-dbg \
1616
g++ \
17-
gcc-i686-linux-gnu libc6-dev-i386-cross libc6-dbg:i386 libubsan1:i386 libasan5:i386 \
17+
gcc-i686-linux-gnu libc6-dev-i386-cross libc6-dbg:i386 libubsan1:i386 libasan6:i386 \
1818
gcc-s390x-linux-gnu libc6-dev-s390x-cross libc6-dbg:s390x \
1919
gcc-arm-linux-gnueabihf libc6-dev-armhf-cross libc6-dbg:armhf \
2020
gcc-aarch64-linux-gnu libc6-dev-arm64-cross libc6-dbg:arm64 \

configure.ac

+6-42
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ AC_PATH_TOOL(STRIP, strip)
2121

2222
# Save definition of AC_PROG_CC because AM_PROG_CC_C_O in automake<=1.13 will
2323
# redefine AC_PROG_CC to exit with an error, which avoids the user calling it
24-
# accidently and screwing up the effect of AM_PROG_CC_C_O. However, we'll need
24+
# accidentally and screwing up the effect of AM_PROG_CC_C_O. However, we'll need
2525
# AC_PROG_CC later on in AX_PROG_CC_FOR_BUILD, where its usage is fine, and
2626
# we'll carefully make sure not to call AC_PROG_CC anywhere else.
2727
m4_copy([AC_PROG_CC], [saved_AC_PROG_CC])
@@ -43,14 +43,8 @@ case $host_os in
4343
# These Homebrew packages may be keg-only, meaning that they won't be found
4444
# in expected paths because they may conflict with system files. Ask
4545
# Homebrew where each one is located, then adjust paths accordingly.
46-
openssl_prefix=`$BREW --prefix openssl 2>/dev/null`
47-
valgrind_prefix=`$BREW --prefix valgrind 2>/dev/null`
48-
if test x$openssl_prefix != x; then
49-
PKG_CONFIG_PATH="$openssl_prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
50-
export PKG_CONFIG_PATH
51-
CRYPTO_CPPFLAGS="-I$openssl_prefix/include"
52-
fi
53-
if test x$valgrind_prefix != x; then
46+
if $BREW list --versions valgrind >/dev/null; then
47+
valgrind_prefix=`$BREW --prefix valgrind 2>/dev/null`
5448
VALGRIND_CPPFLAGS="-I$valgrind_prefix/include"
5549
fi
5650
else
@@ -121,11 +115,6 @@ AC_ARG_ENABLE(tests,
121115
[use_tests=$enableval],
122116
[use_tests=yes])
123117

124-
AC_ARG_ENABLE(openssl_tests,
125-
AS_HELP_STRING([--enable-openssl-tests],[enable OpenSSL tests [default=auto]]),
126-
[enable_openssl_tests=$enableval],
127-
[enable_openssl_tests=auto])
128-
129118
AC_ARG_ENABLE(experimental,
130119
AS_HELP_STRING([--enable-experimental],[allow experimental configure options [default=no]]),
131120
[use_experimental=$enableval],
@@ -171,12 +160,14 @@ AC_ARG_ENABLE(external_default_callbacks,
171160
AC_ARG_WITH([test-override-wide-multiply], [] ,[set_widemul=$withval], [set_widemul=auto])
172161

173162
AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm|no|auto],
174-
[assembly optimizations to use (experimental: arm) [default=auto]])],[req_asm=$withval], [req_asm=auto])
163+
[assembly optimizations to use (experimental: arm) [default=auto]])],[req_asm=$withval], [req_asm=auto])
175164

176165
AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE|auto],
177166
[window size for ecmult precomputation for verification, specified as integer in range [2..24].]
178167
[Larger values result in possibly better performance at the cost of an exponentially larger precomputed table.]
179168
[The table will store 2^(SIZE-1) * 64 bytes of data but can be larger in memory due to platform-specific padding and alignment.]
169+
[A window size larger than 15 will require you delete the prebuilt ecmult_static_pre_g.h file so that it can be rebuilt.]
170+
[For very large window sizes, use "make -j 1" to reduce memory use during compilation.]
180171
["auto" is a reasonable setting for desktop machines (currently 15). [default=auto]]
181172
)],
182173
[req_ecmult_window=$withval], [req_ecmult_window=auto])
@@ -327,32 +318,6 @@ case $set_ecmult_gen_precision in
327318
;;
328319
esac
329320

330-
if test x"$use_tests" = x"yes"; then
331-
SECP_OPENSSL_CHECK
332-
if test x"$enable_openssl_tests" != x"no" && test x"$has_openssl_ec" = x"yes"; then
333-
enable_openssl_tests=yes
334-
AC_DEFINE(ENABLE_OPENSSL_TESTS, 1, [Define this symbol if OpenSSL EC functions are available])
335-
SECP_TEST_INCLUDES="$SSL_CFLAGS $CRYPTO_CFLAGS $CRYPTO_CPPFLAGS"
336-
SECP_TEST_LIBS="$CRYPTO_LIBS"
337-
338-
case $host in
339-
*mingw*)
340-
SECP_TEST_LIBS="$SECP_TEST_LIBS -lgdi32"
341-
;;
342-
esac
343-
else
344-
if test x"$enable_openssl_tests" = x"yes"; then
345-
AC_MSG_ERROR([OpenSSL tests requested but OpenSSL with EC support is not available])
346-
fi
347-
enable_openssl_tests=no
348-
fi
349-
else
350-
if test x"$enable_openssl_tests" = x"yes"; then
351-
AC_MSG_ERROR([OpenSSL tests requested but tests are not enabled])
352-
fi
353-
enable_openssl_tests=no
354-
fi
355-
356321
if test x"$enable_valgrind" = x"yes"; then
357322
SECP_INCLUDES="$SECP_INCLUDES $VALGRIND_CPPFLAGS"
358323
fi
@@ -517,7 +482,6 @@ echo " with ecmult precomp = $set_precomp"
517482
echo " with external callbacks = $use_external_default_callbacks"
518483
echo " with benchmarks = $use_benchmark"
519484
echo " with tests = $use_tests"
520-
echo " with openssl tests = $enable_openssl_tests"
521485
echo " with coverage = $enable_coverage"
522486
echo " module ecdh = $enable_module_ecdh"
523487
echo " module recovery = $enable_module_recovery"

doc/safegcd_implementation.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,14 @@ bits efficiently, which is possible on most platforms; it is abstracted here as
569569

570570
```python
571571
def count_trailing_zeros(v):
572-
"""For a non-zero value v, find z such that v=(d<<z) for some odd d."""
573-
return (v & -v).bit_length() - 1
572+
"""
573+
When v is zero, consider all N zero bits as "trailing".
574+
For a non-zero value v, find z such that v=(d<<z) for some odd d.
575+
"""
576+
if v == 0:
577+
return N
578+
else:
579+
return (v & -v).bit_length() - 1
574580

575581
i = N # divsteps left to do
576582
while True:
@@ -601,7 +607,7 @@ becomes negative, or when *i* reaches *0*. Combined, this is equivalent to addin
601607
It is easy to find what that multiple is: we want a number *w* such that *g+w&thinsp;f* has a few bottom
602608
zero bits. If that number of bits is *L*, we want *g+w&thinsp;f mod 2<sup>L</sup> = 0*, or *w = -g/f mod 2<sup>L</sup>*. Since *f*
603609
is odd, such a *w* exists for any *L*. *L* cannot be more than *i* steps (as we'd finish the loop before
604-
doing more) or more than *&eta;+1* steps (as we'd run `eta, f, g = -eta, g, f` at that point), but
610+
doing more) or more than *&eta;+1* steps (as we'd run `eta, f, g = -eta, g, -f` at that point), but
605611
apart from that, we're only limited by the complexity of computing *w*.
606612

607613
This code demonstrates how to cancel up to 4 bits per step:
@@ -618,7 +624,7 @@ while True:
618624
break
619625
# We know g is odd now
620626
if eta < 0:
621-
eta, f, g = -eta, g, f
627+
eta, f, g = -eta, g, -f
622628
# Compute limit on number of bits to cancel
623629
limit = min(min(eta + 1, i), 4)
624630
# Compute w = -g/f mod 2**limit, using the table value for -1/f mod 2**4. Note that f is

0 commit comments

Comments
 (0)