Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream PRs 1056, 1104, 1105, 1084, 1114, 1115, 1116, 1120, 1122, 1121, 1128, 1131, 1144, 1150, 1146 #238

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
40a3473
build: Fix #include "..." paths to get rid of further -I arguments
real-or-random Jun 30, 2022
af65d30
Merge bitcoin-core/secp256k1#1116: build: Fix #include "..." paths to…
real-or-random Jul 1, 2022
4cc0b1b
ecmult_gen: Skip RNG when creating blinding if no seed is available
real-or-random Jul 5, 2022
7a86955
ecmult_gen: Simplify code (no observable change)
real-or-random Jul 5, 2022
55f8bc9
ecmult_gen: Improve comments about projective blinding
real-or-random Jul 5, 2022
d0cf55e
config: Set preprocessor defaults for ECMULT_* config values
real-or-random Jul 6, 2022
63a3565
Merge bitcoin-core/secp256k1#1120: ecmult_gen: Skip RNG when creating…
real-or-random Jul 7, 2022
da6514a
config: Introduce DEBUG_CONFIG macro for debug output of config
real-or-random Jul 6, 2022
c27ae45
config: Remove basic-config.h
real-or-random Jul 6, 2022
17065f4
tests: Randomize the context with probability 15/16 instead of 1/4
real-or-random Jul 7, 2022
6a873cc
Merge bitcoin-core/secp256k1#1122: tests: Randomize the context with …
jonasnick Jul 11, 2022
3efeb9d
Merge bitcoin-core/secp256k1#1121: config: Set preprocessor defaults …
jonasnick Jul 11, 2022
cabe085
configure: Remove pkgconfig macros again (reintroduced by mismerge)
real-or-random Jul 21, 2022
9f8a13d
Merge bitcoin-core/secp256k1#1128: configure: Remove pkgconfig macros…
real-or-random Jul 21, 2022
ef48f08
readme: Add IRC channel
real-or-random Aug 2, 2022
78f5296
readme: Sell "no runtime dependencies"
real-or-random Aug 2, 2022
88b0089
readme: Fix line break
real-or-random Aug 2, 2022
694ce8f
Merge bitcoin-core/secp256k1#1131: readme: Misc improvements
real-or-random Aug 2, 2022
798727a
Revert "Add test logs to gitignore"
hebasto Oct 28, 2022
f5039cb
Cleanup `.gitignore` file
hebasto Oct 28, 2022
a43e982
Merge bitcoin-core/secp256k1#1144: Cleanup `.gitignore` file
jonasnick Nov 1, 2022
49ae843
ci: mostly prevent "-v/--version: not found" irrelevant error
jonasnick Nov 2, 2022
5c9f1a5
ci: always cat all logs_snippets
jonasnick Nov 7, 2022
e13fae4
Merge bitcoin-core/secp256k1#1150: ci: always cat test_env.log
jonasnick Nov 8, 2022
c2ee917
Merge bitcoin-core/secp256k1#1146: ci: prevent "-v/--version: not fou…
jonasnick Nov 8, 2022
64717a7
Merge commits '8b013fce 485f608f 44c2452f cd470333 accadc94 43756da8 …
jonasnick Jul 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ cat_logs_snippet: &CAT_LOGS
- cat valgrind_ctime_test.log || true
cat_bench_log_script:
- cat bench.log || true
on_failure:
cat_config_log_script:
- cat config.log || true
cat_test_env_script:
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ schnorr_example
*.so
*.a
*.csv
!.gitignore
*.log
*.trs

Expand All @@ -39,8 +38,6 @@ libtool
*.lo
*.o
*~
*.log
*.trs

coverage/
coverage.html
Expand Down
5 changes: 2 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ noinst_HEADERS += src/hash_impl.h
noinst_HEADERS += src/field.h
noinst_HEADERS += src/field_impl.h
noinst_HEADERS += src/bench.h
noinst_HEADERS += src/basic-config.h
noinst_HEADERS += contrib/lax_der_parsing.h
noinst_HEADERS += contrib/lax_der_parsing.c
noinst_HEADERS += contrib/lax_der_privatekey_parsing.h
Expand Down Expand Up @@ -89,7 +88,7 @@ endif
endif

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

Expand All @@ -114,7 +113,7 @@ TESTS =
if USE_TESTS
noinst_PROGRAMS += tests
tests_SOURCES = src/tests.c
tests_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
tests_CPPFLAGS = $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
if VALGRIND_ENABLED
tests_CPPFLAGS += -DVALGRIND
noinst_PROGRAMS += valgrind_ctime_test
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ libsecp256k1-zkp
================

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

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

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

Usage examples
-----------
Usage examples can be found in the [examples](examples) directory. To compile them you need to configure with `--enable-examples`.

Usage examples can be found in the [examples](examples) directory. To compile them you need to configure with `--enable-examples`.
* [ECDSA example](examples/ecdsa.c)
* [Schnorr signatures example](examples/schnorr.c)
* [Deriving a shared secret (ECDH) example](examples/ecdh.c)
* [MuSig example](examples/musig.c)

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`.

Test coverage
-----------
Expand Down
13 changes: 10 additions & 3 deletions ci/cirrus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ esac

env >> test_env.log

$CC -v || true
valgrind --version || true
$WRAPPER_CMD --version || true
if [ -n "$CC" ]; then
# The MSVC compiler "cl" doesn't understand "-v"
$CC -v || true
fi
if [ "$WITH_VALGRIND" = "yes" ]; then
valgrind --version
fi
if [ -n "$WRAPPER_CMD" ]; then
$WRAPPER_CMD --version
fi

./autogen.sh

Expand Down
2 changes: 0 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ AS_UNSET(ac_cv_prog_AR)
AS_UNSET(ac_cv_prog_ac_ct_AR)
LT_INIT([win32-dll])

PKG_PROG_PKG_CONFIG

build_windows=no

case $host_os in
Expand Down
17 changes: 0 additions & 17 deletions src/basic-config.h

This file was deleted.

11 changes: 11 additions & 0 deletions src/ecmult.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
#include "scalar.h"
#include "scratch.h"

#ifndef ECMULT_WINDOW_SIZE
# define ECMULT_WINDOW_SIZE 15
# ifdef DEBUG_CONFIG
# pragma message DEBUG_CONFIG_MSG("ECMULT_WINDOW_SIZE undefined, assuming default value")
# endif
#endif

#ifdef DEBUG_CONFIG
# pragma message DEBUG_CONFIG_DEF(ECMULT_WINDOW_SIZE)
#endif

/* Noone will ever need more than a window size of 24. The code might
* be correct for larger values of ECMULT_WINDOW_SIZE but this is not
* tested.
Expand Down
12 changes: 12 additions & 0 deletions src/ecmult_gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,21 @@
#include "scalar.h"
#include "group.h"

#ifndef ECMULT_GEN_PREC_BITS
# define ECMULT_GEN_PREC_BITS 4
# ifdef DEBUG_CONFIG
# pragma message DEBUG_CONFIG_MSG("ECMULT_GEN_PREC_BITS undefined, assuming default value")
# endif
#endif

#ifdef DEBUG_CONFIG
# pragma message DEBUG_CONFIG_DEF(ECMULT_GEN_PREC_BITS)
#endif

#if ECMULT_GEN_PREC_BITS != 2 && ECMULT_GEN_PREC_BITS != 4 && ECMULT_GEN_PREC_BITS != 8
# error "Set ECMULT_GEN_PREC_BITS to 2, 4 or 8."
#endif

#define ECMULT_GEN_PREC_G(bits) (1 << bits)
#define ECMULT_GEN_PREC_N(bits) (256 / bits)

Expand Down
17 changes: 9 additions & 8 deletions src/ecmult_gen_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,31 @@ static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const
unsigned char nonce32[32];
secp256k1_rfc6979_hmac_sha256 rng;
int overflow;
unsigned char keydata[64] = {0};
unsigned char keydata[64];
if (seed32 == NULL) {
/* When seed is NULL, reset the initial point and blinding value. */
secp256k1_gej_set_ge(&ctx->initial, &secp256k1_ge_const_g);
secp256k1_gej_neg(&ctx->initial, &ctx->initial);
secp256k1_scalar_set_int(&ctx->blind, 1);
return;
}
/* The prior blinding value (if not reset) is chained forward by including it in the hash. */
secp256k1_scalar_get_b32(nonce32, &ctx->blind);
secp256k1_scalar_get_b32(keydata, &ctx->blind);
/** Using a CSPRNG allows a failure free interface, avoids needing large amounts of random data,
* and guards against weak or adversarial seeds. This is a simpler and safer interface than
* asking the caller for blinding values directly and expecting them to retry on failure.
*/
memcpy(keydata, nonce32, 32);
if (seed32 != NULL) {
memcpy(keydata + 32, seed32, 32);
}
secp256k1_rfc6979_hmac_sha256_initialize(&rng, keydata, seed32 ? 64 : 32);
VERIFY_CHECK(seed32 != NULL);
memcpy(keydata + 32, seed32, 32);
secp256k1_rfc6979_hmac_sha256_initialize(&rng, keydata, 64);
memset(keydata, 0, sizeof(keydata));
/* Accept unobservably small non-uniformity. */
secp256k1_rfc6979_hmac_sha256_generate(&rng, nonce32, 32);
overflow = !secp256k1_fe_set_b32(&s, nonce32);
overflow |= secp256k1_fe_is_zero(&s);
secp256k1_fe_cmov(&s, &secp256k1_fe_one, overflow);
/* Randomize the projection to defend against multiplier sidechannels. */
/* Randomize the projection to defend against multiplier sidechannels.
Do this before our own call to secp256k1_ecmult_gen below. */
secp256k1_gej_rescale(&ctx->initial, &s);
secp256k1_fe_clear(&s);
secp256k1_rfc6979_hmac_sha256_generate(&rng, nonce32, 32);
Expand All @@ -121,6 +121,7 @@ static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const
secp256k1_scalar_cmov(&b, &secp256k1_scalar_one, secp256k1_scalar_is_zero(&b));
secp256k1_rfc6979_hmac_sha256_finalize(&rng);
memset(nonce32, 0, 32);
/* The random projection in ctx->initial ensures that gb will have a random projection. */
secp256k1_ecmult_gen(ctx, &gb, &b);
secp256k1_scalar_negate(&b, &b);
ctx->blind = b;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/ecdh/bench_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef SECP256K1_MODULE_ECDH_BENCH_H
#define SECP256K1_MODULE_ECDH_BENCH_H

#include "../include/secp256k1_ecdh.h"
#include "../../../include/secp256k1_ecdh.h"

typedef struct {
secp256k1_context *ctx;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/recovery/bench_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef SECP256K1_MODULE_RECOVERY_BENCH_H
#define SECP256K1_MODULE_RECOVERY_BENCH_H

#include "../include/secp256k1_recovery.h"
#include "../../../include/secp256k1_recovery.h"

typedef struct {
secp256k1_context *ctx;
Expand Down
8 changes: 6 additions & 2 deletions src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -7394,11 +7394,15 @@ int main(int argc, char **argv) {
run_context_tests(0);
run_context_tests(1);
run_scratch_tests();

ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
if (secp256k1_testrand_bits(1)) {
/* Randomize the context only with probability 15/16
to make sure we test without context randomization from time to time.
TODO Reconsider this when recalibrating the tests. */
if (secp256k1_testrand_bits(4)) {
unsigned char rand32[32];
secp256k1_testrand256(rand32);
CHECK(secp256k1_context_randomize(ctx, secp256k1_testrand_bits(1) ? rand32 : NULL));
CHECK(secp256k1_context_randomize(ctx, rand32));
}

run_rand_bits();
Expand Down
5 changes: 5 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#include <stdio.h>
#include <limits.h>

#define STR_(x) #x
#define STR(x) STR_(x)
#define DEBUG_CONFIG_MSG(x) "DEBUG_CONFIG: " x
#define DEBUG_CONFIG_DEF(x) DEBUG_CONFIG_MSG(#x "=" STR(x))

typedef struct {
void (*fn)(const char *text, void* data);
const void* data;
Expand Down