Skip to content

Commit e996d07

Browse files
committed
Merge commits '44916ae9 86e3b38 ddf2b29 6138d73 e40fd27 ' into temp-merge-1156
2 parents 64717a7 + e40fd27 commit e996d07

21 files changed

+1222
-339
lines changed

.cirrus.yml

+48-7
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ task:
7474
- env: {WIDEMUL: int64, RECOVERY: yes}
7575
- env: {WIDEMUL: int64, ECDH: yes, SCHNORRSIG: yes, EXPERIMENTAL: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes, BPPP: yes}
7676
- env: {WIDEMUL: int128}
77+
- env: {WIDEMUL: int128_struct}
7778
- env: {WIDEMUL: int128, RECOVERY: yes, SCHNORRSIG: yes}
7879
- env: {WIDEMUL: int128, ECDH: yes, SCHNORRSIG: yes, EXPERIMENTAL: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes, BPPP: yes}
7980
- env: {WIDEMUL: int128, ASM: x86_64}
@@ -268,20 +269,26 @@ task:
268269
ECDSAADAPTOR: yes
269270
BPPP: yes
270271
CTIMETEST: no
272+
# Use a MinGW-w64 host to tell ./configure we're building for Windows.
273+
# This will detect some MinGW-w64 tools but then make will need only
274+
# the MSVC tools CC, AR and NM as specified below.
275+
HOST: x86_64-w64-mingw32
276+
CC: /opt/msvc/bin/x64/cl
277+
AR: /opt/msvc/bin/x64/lib
278+
NM: /opt/msvc/bin/x64/dumpbin -symbols -headers
271279
# Set non-essential options that affect the CLI messages here.
272280
# (They depend on the user's taste, so we don't want to set them automatically in configure.ac.)
273281
CFLAGS: -nologo -diagnostics:caret
274282
LDFLAGS: -XCClinker -nologo -XCClinker -diagnostics:caret
275-
# Use a MinGW-w64 host to tell ./configure we're building for Windows.
276-
# This will detect some MinGW-w64 tools but then make will need only
277-
# the MSVC tools CC, AR and NM as specified below.
278283
matrix:
279284
- name: "x86_64 (MSVC): Windows (Debian stable, Wine)"
285+
- name: "x86_64 (MSVC): Windows (Debian stable, Wine, int128_struct)"
280286
env:
281-
HOST: x86_64-w64-mingw32
282-
CC: /opt/msvc/bin/x64/cl
283-
AR: /opt/msvc/bin/x64/lib
284-
NM: /opt/msvc/bin/x64/dumpbin -symbols -headers
287+
WIDEMUL: int128_struct
288+
- name: "x86_64 (MSVC): Windows (Debian stable, Wine, int128_struct with __(u)mulh)"
289+
env:
290+
WIDEMUL: int128_struct
291+
CPPFLAGS: -DSECP256K1_MSVC_MULH_TEST_OVERRIDE
285292
- name: "i686 (MSVC): Windows (Debian stable, Wine)"
286293
env:
287294
HOST: i686-w64-mingw32
@@ -346,6 +353,40 @@ task:
346353
- ./ci/cirrus.sh
347354
<< : *CAT_LOGS
348355

356+
# Memory sanitizers
357+
task:
358+
<< : *LINUX_CONTAINER
359+
name: "MSan"
360+
env:
361+
ECDH: yes
362+
RECOVERY: yes
363+
SCHNORRSIG: yes
364+
EXPERIMENTAL: yes
365+
ECDSA_S2C: yes
366+
GENERATOR: yes
367+
RANGEPROOF: yes
368+
WHITELIST: yes
369+
MUSIG: yes
370+
ECDSAADAPTOR: yes
371+
BPPP: yes
372+
CTIMETEST: no
373+
CC: clang
374+
SECP256K1_TEST_ITERS: 32
375+
ASM: no
376+
container:
377+
memory: 2G
378+
matrix:
379+
- env:
380+
CFLAGS: "-fsanitize=memory -g"
381+
- env:
382+
ECMULTGENPRECISION: 2
383+
ECMULTWINDOW: 2
384+
CFLAGS: "-fsanitize=memory -g -O3"
385+
<< : *MERGE_BASE
386+
test_script:
387+
- ./ci/cirrus.sh
388+
<< : *CAT_LOGS
389+
349390
task:
350391
name: "C++ -fpermissive (entire project)"
351392
<< : *LINUX_CONTAINER

Makefile.am

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ noinst_HEADERS += src/precomputed_ecmult.h
5050
noinst_HEADERS += src/precomputed_ecmult_gen.h
5151
noinst_HEADERS += src/assumptions.h
5252
noinst_HEADERS += src/util.h
53+
noinst_HEADERS += src/int128.h
54+
noinst_HEADERS += src/int128_impl.h
55+
noinst_HEADERS += src/int128_native.h
56+
noinst_HEADERS += src/int128_native_impl.h
57+
noinst_HEADERS += src/int128_struct.h
58+
noinst_HEADERS += src/int128_struct_impl.h
5359
noinst_HEADERS += src/scratch.h
5460
noinst_HEADERS += src/scratch_impl.h
5561
noinst_HEADERS += src/selftest.h

ci/cirrus.sh

+21
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ set -x
55

66
export LC_ALL=C
77

8+
# Print relevant CI environment to allow reproducing the job outside of CI.
9+
print_environment() {
10+
# Turn off -x because it messes up the output
11+
set +x
12+
# There are many ways to print variable names and their content. This one
13+
# does not rely on bash.
14+
for i in WERROR_CFLAGS MAKEFLAGS BUILD \
15+
ECMULTWINDOW ECMULTGENPRECISION ASM WIDEMUL WITH_VALGRIND EXTRAFLAGS \
16+
EXPERIMENTAL ECDH RECOVERY SCHNORRSIG \
17+
ECDSA_S2C GENERATOR RANGEPROOF WHITELIST MUSIG ECDSAADAPTOR BPPP \
18+
SECP256K1_TEST_ITERS BENCH SECP256K1_BENCH_ITERS CTIMETEST\
19+
EXAMPLES \
20+
WRAPPER_CMD CC AR NM HOST
21+
do
22+
eval 'printf "%s %s " "$i=\"${'"$i"'}\""'
23+
done
24+
echo "$0"
25+
set -x
26+
}
27+
print_environment
28+
829
# Start persistent wineserver if necessary.
930
# This speeds up jobs with many invocations of wine (e.g., ./configure with MSVC) tremendously.
1031
case "$WRAPPER_CMD" in

configure.ac

+8-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ AC_ARG_ENABLE(reduced_surjection_proof_size,
220220
[SECP_SET_DEFAULT([use_reduced_surjection_proof_size], [no], [no])])
221221

222222
# Test-only override of the (autodetected by the C code) "widemul" setting.
223-
# Legal values are int64 (for [u]int64_t), int128 (for [unsigned] __int128), and auto (the default).
223+
# Legal values are:
224+
# * int64 (for [u]int64_t),
225+
# * int128 (for [unsigned] __int128),
226+
# * int128_struct (for int128 implemented as a structure),
227+
# * and auto (the default).
224228
AC_ARG_WITH([test-override-wide-multiply], [] ,[set_widemul=$withval], [set_widemul=auto])
225229

226230
AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm|no|auto],
@@ -342,6 +346,9 @@ fi
342346

343347
# Select wide multiplication implementation
344348
case $set_widemul in
349+
int128_struct)
350+
AC_DEFINE(USE_FORCE_WIDEMUL_INT128_STRUCT, 1, [Define this symbol to force the use of the structure for simulating (unsigned) int128 based wide multiplication])
351+
;;
345352
int128)
346353
AC_DEFINE(USE_FORCE_WIDEMUL_INT128, 1, [Define this symbol to force the use of the (unsigned) __int128 based wide multiplication implementation])
347354
;;

src/assumptions.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include <limits.h>
1111

1212
#include "util.h"
13+
#if defined(SECP256K1_INT128_NATIVE)
14+
#include "int128_native.h"
15+
#endif
1316

1417
/* This library, like most software, relies on a number of compiler implementation defined (but not undefined)
1518
behaviours. Although the behaviours we require are essentially universal we test them specifically here to
@@ -55,7 +58,7 @@ struct secp256k1_assumption_checker {
5558

5659
/* To int64_t. */
5760
((int64_t)(uint64_t)0xB123C456D789E012ULL == (int64_t)-(int64_t)0x4EDC3BA928761FEEULL) &&
58-
#if defined(SECP256K1_WIDEMUL_INT128)
61+
#if defined(SECP256K1_INT128_NATIVE)
5962
((int64_t)(((uint128_t)0xA1234567B8901234ULL << 64) + 0xC5678901D2345678ULL) == (int64_t)-(int64_t)0x3A9876FE2DCBA988ULL) &&
6063
(((int64_t)(int128_t)(((uint128_t)0xB1C2D3E4F5A6B7C8ULL << 64) + 0xD9E0F1A2B3C4D5E6ULL)) == (int64_t)(uint64_t)0xD9E0F1A2B3C4D5E6ULL) &&
6164
(((int64_t)(int128_t)(((uint128_t)0xABCDEF0123456789ULL << 64) + 0x0123456789ABCDEFULL)) == (int64_t)(uint64_t)0x0123456789ABCDEFULL) &&
@@ -71,7 +74,7 @@ struct secp256k1_assumption_checker {
7174
((((int16_t)0xE9AC) >> 4) == (int16_t)(uint16_t)0xFE9A) &&
7275
((((int32_t)0x937C918A) >> 9) == (int32_t)(uint32_t)0xFFC9BE48) &&
7376
((((int64_t)0xA8B72231DF9CF4B9ULL) >> 19) == (int64_t)(uint64_t)0xFFFFF516E4463BF3ULL) &&
74-
#if defined(SECP256K1_WIDEMUL_INT128)
77+
#if defined(SECP256K1_INT128_NATIVE)
7578
((((int128_t)(((uint128_t)0xCD833A65684A0DBCULL << 64) + 0xB349312F71EA7637ULL)) >> 39) == (int128_t)(((uint128_t)0xFFFFFFFFFF9B0674ULL << 64) + 0xCAD0941B79669262ULL)) &&
7679
#endif
7780
1) * 2 - 1];

src/bench_whitelist.c

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "util.h"
1212
#include "bench.h"
1313
#include "hash_impl.h"
14+
#include "int128_impl.h"
1415
#include "scalar_impl.h"
1516
#include "testrand_impl.h"
1617

src/ecmult_impl.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,15 @@ static int secp256k1_ecmult_wnaf(int *wnaf, int len, const secp256k1_scalar *a,
200200
bit += now;
201201
}
202202
#ifdef VERIFY
203-
CHECK(carry == 0);
204-
while (bit < 256) {
205-
CHECK(secp256k1_scalar_get_bits(&s, bit++, 1) == 0);
203+
{
204+
int verify_bit = bit;
205+
206+
VERIFY_CHECK(carry == 0);
207+
208+
while (verify_bit < 256) {
209+
VERIFY_CHECK(secp256k1_scalar_get_bits(&s, verify_bit, 1) == 0);
210+
verify_bit++;
211+
}
206212
}
207213
#endif
208214
return last_set_bit + 1;

0 commit comments

Comments
 (0)