Skip to content

Commit 64717a7

Browse files
committed
2 parents 9a98106 + c2ee917 commit 64717a7

14 files changed

+66
-42
lines changed

.cirrus.yml

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ cat_logs_snippet: &CAT_LOGS
4242
- cat valgrind_ctime_test.log || true
4343
cat_bench_log_script:
4444
- cat bench.log || true
45-
on_failure:
4645
cat_config_log_script:
4746
- cat config.log || true
4847
cat_test_env_script:

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ schnorr_example
1818
*.so
1919
*.a
2020
*.csv
21-
!.gitignore
2221
*.log
2322
*.trs
2423

@@ -39,8 +38,6 @@ libtool
3938
*.lo
4039
*.o
4140
*~
42-
*.log
43-
*.trs
4441

4542
coverage/
4643
coverage.html

Makefile.am

+2-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ noinst_HEADERS += src/hash_impl.h
6060
noinst_HEADERS += src/field.h
6161
noinst_HEADERS += src/field_impl.h
6262
noinst_HEADERS += src/bench.h
63-
noinst_HEADERS += src/basic-config.h
6463
noinst_HEADERS += contrib/lax_der_parsing.h
6564
noinst_HEADERS += contrib/lax_der_parsing.c
6665
noinst_HEADERS += contrib/lax_der_privatekey_parsing.h
@@ -89,7 +88,7 @@ endif
8988
endif
9089

9190
libsecp256k1_la_SOURCES = src/secp256k1.c
92-
libsecp256k1_la_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src $(SECP_INCLUDES)
91+
libsecp256k1_la_CPPFLAGS = $(SECP_INCLUDES)
9392
libsecp256k1_la_LIBADD = $(SECP_LIBS) $(COMMON_LIB) $(PRECOMPUTED_LIB)
9493
libsecp256k1_la_LDFLAGS = -no-undefined -version-info $(LIB_VERSION_CURRENT):$(LIB_VERSION_REVISION):$(LIB_VERSION_AGE)
9594

@@ -114,7 +113,7 @@ TESTS =
114113
if USE_TESTS
115114
noinst_PROGRAMS += tests
116115
tests_SOURCES = src/tests.c
117-
tests_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
116+
tests_CPPFLAGS = $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
118117
if VALGRIND_ENABLED
119118
tests_CPPFLAGS += -DVALGRIND
120119
noinst_PROGRAMS += valgrind_ctime_test

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ libsecp256k1-zkp
22
================
33

44
[![Build Status](https://api.cirrus-ci.com/github/BlockstreamResearch/secp256k1-zkp.svg?branch=master)](https://cirrus-ci.com/github/BlockstreamResearch/secp256k1-zkp)
5+
![Dependencies: None](https://img.shields.io/badge/dependencies-none-success)
56

67
A fork of [libsecp256k1](https://github.com/bitcoin-core/secp256k1) with support for advanced and experimental features such as Confidential Assets and MuSig2
78

@@ -30,7 +31,14 @@ To compile optional modules (such as Schnorr signatures), you need to run `./con
3031

3132
Usage examples
3233
-----------
33-
Usage examples can be found in the [examples](examples) directory. To compile them you need to configure with `--enable-examples`.
34+
35+
Usage examples can be found in the [examples](examples) directory. To compile them you need to configure with `--enable-examples`.
36+
* [ECDSA example](examples/ecdsa.c)
37+
* [Schnorr signatures example](examples/schnorr.c)
38+
* [Deriving a shared secret (ECDH) example](examples/ecdh.c)
39+
* [MuSig example](examples/musig.c)
40+
41+
To compile the Schnorr signature, ECDH and MuSig examples, you need to enable the corresponding module by providing a flag to the `configure` script, for example `--enable-module-schnorrsig`.
3442

3543
Test coverage
3644
-----------

ci/cirrus.sh

+10-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@ esac
1616

1717
env >> test_env.log
1818

19-
$CC -v || true
20-
valgrind --version || true
21-
$WRAPPER_CMD --version || true
19+
if [ -n "$CC" ]; then
20+
# The MSVC compiler "cl" doesn't understand "-v"
21+
$CC -v || true
22+
fi
23+
if [ "$WITH_VALGRIND" = "yes" ]; then
24+
valgrind --version
25+
fi
26+
if [ -n "$WRAPPER_CMD" ]; then
27+
$WRAPPER_CMD --version
28+
fi
2229

2330
./autogen.sh
2431

configure.ac

-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ AS_UNSET(ac_cv_prog_AR)
4343
AS_UNSET(ac_cv_prog_ac_ct_AR)
4444
LT_INIT([win32-dll])
4545

46-
PKG_PROG_PKG_CONFIG
47-
4846
build_windows=no
4947

5048
case $host_os in

src/basic-config.h

-17
This file was deleted.

src/ecmult.h

+11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111
#include "scalar.h"
1212
#include "scratch.h"
1313

14+
#ifndef ECMULT_WINDOW_SIZE
15+
# define ECMULT_WINDOW_SIZE 15
16+
# ifdef DEBUG_CONFIG
17+
# pragma message DEBUG_CONFIG_MSG("ECMULT_WINDOW_SIZE undefined, assuming default value")
18+
# endif
19+
#endif
20+
21+
#ifdef DEBUG_CONFIG
22+
# pragma message DEBUG_CONFIG_DEF(ECMULT_WINDOW_SIZE)
23+
#endif
24+
1425
/* Noone will ever need more than a window size of 24. The code might
1526
* be correct for larger values of ECMULT_WINDOW_SIZE but this is not
1627
* tested.

src/ecmult_gen.h

+12
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,21 @@
1010
#include "scalar.h"
1111
#include "group.h"
1212

13+
#ifndef ECMULT_GEN_PREC_BITS
14+
# define ECMULT_GEN_PREC_BITS 4
15+
# ifdef DEBUG_CONFIG
16+
# pragma message DEBUG_CONFIG_MSG("ECMULT_GEN_PREC_BITS undefined, assuming default value")
17+
# endif
18+
#endif
19+
20+
#ifdef DEBUG_CONFIG
21+
# pragma message DEBUG_CONFIG_DEF(ECMULT_GEN_PREC_BITS)
22+
#endif
23+
1324
#if ECMULT_GEN_PREC_BITS != 2 && ECMULT_GEN_PREC_BITS != 4 && ECMULT_GEN_PREC_BITS != 8
1425
# error "Set ECMULT_GEN_PREC_BITS to 2, 4 or 8."
1526
#endif
27+
1628
#define ECMULT_GEN_PREC_G(bits) (1 << bits)
1729
#define ECMULT_GEN_PREC_N(bits) (256 / bits)
1830

src/ecmult_gen_impl.h

+9-8
Original file line numberDiff line numberDiff line change
@@ -88,31 +88,31 @@ static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const
8888
unsigned char nonce32[32];
8989
secp256k1_rfc6979_hmac_sha256 rng;
9090
int overflow;
91-
unsigned char keydata[64] = {0};
91+
unsigned char keydata[64];
9292
if (seed32 == NULL) {
9393
/* When seed is NULL, reset the initial point and blinding value. */
9494
secp256k1_gej_set_ge(&ctx->initial, &secp256k1_ge_const_g);
9595
secp256k1_gej_neg(&ctx->initial, &ctx->initial);
9696
secp256k1_scalar_set_int(&ctx->blind, 1);
97+
return;
9798
}
9899
/* The prior blinding value (if not reset) is chained forward by including it in the hash. */
99-
secp256k1_scalar_get_b32(nonce32, &ctx->blind);
100+
secp256k1_scalar_get_b32(keydata, &ctx->blind);
100101
/** Using a CSPRNG allows a failure free interface, avoids needing large amounts of random data,
101102
* and guards against weak or adversarial seeds. This is a simpler and safer interface than
102103
* asking the caller for blinding values directly and expecting them to retry on failure.
103104
*/
104-
memcpy(keydata, nonce32, 32);
105-
if (seed32 != NULL) {
106-
memcpy(keydata + 32, seed32, 32);
107-
}
108-
secp256k1_rfc6979_hmac_sha256_initialize(&rng, keydata, seed32 ? 64 : 32);
105+
VERIFY_CHECK(seed32 != NULL);
106+
memcpy(keydata + 32, seed32, 32);
107+
secp256k1_rfc6979_hmac_sha256_initialize(&rng, keydata, 64);
109108
memset(keydata, 0, sizeof(keydata));
110109
/* Accept unobservably small non-uniformity. */
111110
secp256k1_rfc6979_hmac_sha256_generate(&rng, nonce32, 32);
112111
overflow = !secp256k1_fe_set_b32(&s, nonce32);
113112
overflow |= secp256k1_fe_is_zero(&s);
114113
secp256k1_fe_cmov(&s, &secp256k1_fe_one, overflow);
115-
/* Randomize the projection to defend against multiplier sidechannels. */
114+
/* Randomize the projection to defend against multiplier sidechannels.
115+
Do this before our own call to secp256k1_ecmult_gen below. */
116116
secp256k1_gej_rescale(&ctx->initial, &s);
117117
secp256k1_fe_clear(&s);
118118
secp256k1_rfc6979_hmac_sha256_generate(&rng, nonce32, 32);
@@ -121,6 +121,7 @@ static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const
121121
secp256k1_scalar_cmov(&b, &secp256k1_scalar_one, secp256k1_scalar_is_zero(&b));
122122
secp256k1_rfc6979_hmac_sha256_finalize(&rng);
123123
memset(nonce32, 0, 32);
124+
/* The random projection in ctx->initial ensures that gb will have a random projection. */
124125
secp256k1_ecmult_gen(ctx, &gb, &b);
125126
secp256k1_scalar_negate(&b, &b);
126127
ctx->blind = b;

src/modules/ecdh/bench_impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#ifndef SECP256K1_MODULE_ECDH_BENCH_H
88
#define SECP256K1_MODULE_ECDH_BENCH_H
99

10-
#include "../include/secp256k1_ecdh.h"
10+
#include "../../../include/secp256k1_ecdh.h"
1111

1212
typedef struct {
1313
secp256k1_context *ctx;

src/modules/recovery/bench_impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#ifndef SECP256K1_MODULE_RECOVERY_BENCH_H
88
#define SECP256K1_MODULE_RECOVERY_BENCH_H
99

10-
#include "../include/secp256k1_recovery.h"
10+
#include "../../../include/secp256k1_recovery.h"
1111

1212
typedef struct {
1313
secp256k1_context *ctx;

src/tests.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -7394,11 +7394,15 @@ int main(int argc, char **argv) {
73947394
run_context_tests(0);
73957395
run_context_tests(1);
73967396
run_scratch_tests();
7397+
73977398
ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
7398-
if (secp256k1_testrand_bits(1)) {
7399+
/* Randomize the context only with probability 15/16
7400+
to make sure we test without context randomization from time to time.
7401+
TODO Reconsider this when recalibrating the tests. */
7402+
if (secp256k1_testrand_bits(4)) {
73997403
unsigned char rand32[32];
74007404
secp256k1_testrand256(rand32);
7401-
CHECK(secp256k1_context_randomize(ctx, secp256k1_testrand_bits(1) ? rand32 : NULL));
7405+
CHECK(secp256k1_context_randomize(ctx, rand32));
74027406
}
74037407

74047408
run_rand_bits();

src/util.h

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
#include <stdio.h>
1717
#include <limits.h>
1818

19+
#define STR_(x) #x
20+
#define STR(x) STR_(x)
21+
#define DEBUG_CONFIG_MSG(x) "DEBUG_CONFIG: " x
22+
#define DEBUG_CONFIG_DEF(x) DEBUG_CONFIG_MSG(#x "=" STR(x))
23+
1924
typedef struct {
2025
void (*fn)(const char *text, void* data);
2126
const void* data;

0 commit comments

Comments
 (0)