Skip to content

Commit 64717a7

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

File tree

14 files changed

+66
-42
lines changed

14 files changed

+66
-42
lines changed

.cirrus.yml

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 9 additions & 1 deletion
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

Lines changed: 10 additions & 3 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/ecmult.h

Lines changed: 11 additions & 0 deletions
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

Lines changed: 12 additions & 0 deletions
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

Lines changed: 9 additions & 8 deletions
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;

0 commit comments

Comments
 (0)