From 2cc3cfa58382582fc26eb91e3243153e1d06ce77 Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Sun, 4 Jul 2021 02:01:44 +0200 Subject: [PATCH 1/5] Fix -Wmissing-braces warning in clang --- src/modules/schnorrsig/tests_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/schnorrsig/tests_impl.h b/src/modules/schnorrsig/tests_impl.h index 0405d46f43..e804df5041 100644 --- a/src/modules/schnorrsig/tests_impl.h +++ b/src/modules/schnorrsig/tests_impl.h @@ -122,7 +122,7 @@ void test_schnorrsig_api(void) { secp256k1_xonly_pubkey zero_pk; unsigned char sig[64]; secp256k1_schnorrsig_extraparams extraparams = SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT; - secp256k1_schnorrsig_extraparams invalid_extraparams = { 0 }; + secp256k1_schnorrsig_extraparams invalid_extraparams = {{ 0 }, NULL, NULL}; /** setup **/ secp256k1_context *none = secp256k1_context_create(SECP256K1_CONTEXT_NONE); From 769528f30714a1e5503a7abefad25fd89f0ef237 Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Sun, 4 Jul 2021 02:03:18 +0200 Subject: [PATCH 2/5] Don't use string literals for char arrays without NUL termination unsigned char foo[4] = "abcd" is not valid C++ because the string literal "abcd" does not fit into foo due to the terminating NUL character. This is valid in C, it will just omit the NUL character. Fixes #962. --- include/secp256k1_schnorrsig.h | 2 +- src/modules/schnorrsig/main_impl.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/secp256k1_schnorrsig.h b/include/secp256k1_schnorrsig.h index d68bba62cc..74cbcac45e 100644 --- a/include/secp256k1_schnorrsig.h +++ b/include/secp256k1_schnorrsig.h @@ -85,7 +85,7 @@ typedef struct { void* ndata; } secp256k1_schnorrsig_extraparams; -#define SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC "\xda\x6f\xb3\x8c" +#define SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC { 0xda, 0x6f, 0xb3, 0x8c } #define SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT {\ SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC,\ NULL,\ diff --git a/src/modules/schnorrsig/main_impl.h b/src/modules/schnorrsig/main_impl.h index e6de73b8a5..693b78f034 100644 --- a/src/modules/schnorrsig/main_impl.h +++ b/src/modules/schnorrsig/main_impl.h @@ -47,6 +47,8 @@ static void secp256k1_nonce_function_bip340_sha256_tagged_aux(secp256k1_sha256 * * by using the correct tagged hash function. */ static const unsigned char bip340_algo[13] = "BIP0340/nonce"; +static const unsigned char schnorrsig_extraparams_magic[4] = SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC; + static int nonce_function_bip340(unsigned char *nonce32, const unsigned char *msg, size_t msglen, const unsigned char *key32, const unsigned char *xonly_pk32, const unsigned char *algo, size_t algolen, void *data) { secp256k1_sha256 sha; unsigned char masked_key[32]; @@ -194,7 +196,7 @@ int secp256k1_schnorrsig_sign_custom(const secp256k1_context* ctx, unsigned char if (extraparams != NULL) { ARG_CHECK(secp256k1_memcmp_var(extraparams->magic, - SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC, + schnorrsig_extraparams_magic, sizeof(extraparams->magic)) == 0); noncefp = extraparams->noncefp; ndata = extraparams->ndata; From b5b8e7b7190aed619a1fa83bf1794fddef90346d Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Sun, 4 Jul 2021 11:35:52 +0200 Subject: [PATCH 3/5] Don't declare constants twice This is forbidden in C++. --- src/ecmult.h | 1 - src/ecmult_gen.h | 1 - 2 files changed, 2 deletions(-) diff --git a/src/ecmult.h b/src/ecmult.h index 7ab617e20e..84537bbfed 100644 --- a/src/ecmult.h +++ b/src/ecmult.h @@ -17,7 +17,6 @@ typedef struct { secp256k1_ge_storage (*pre_g_128)[]; /* odd multiples of 2^128*generator */ } secp256k1_ecmult_context; -static const size_t SECP256K1_ECMULT_CONTEXT_PREALLOCATED_SIZE; static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx); static void secp256k1_ecmult_context_build(secp256k1_ecmult_context *ctx, void **prealloc); static void secp256k1_ecmult_context_finalize_memcpy(secp256k1_ecmult_context *dst, const secp256k1_ecmult_context *src); diff --git a/src/ecmult_gen.h b/src/ecmult_gen.h index 539618dcbb..05cf4d52cc 100644 --- a/src/ecmult_gen.h +++ b/src/ecmult_gen.h @@ -35,7 +35,6 @@ typedef struct { secp256k1_gej initial; } secp256k1_ecmult_gen_context; -static const size_t SECP256K1_ECMULT_GEN_CONTEXT_PREALLOCATED_SIZE; static void secp256k1_ecmult_gen_context_init(secp256k1_ecmult_gen_context* ctx); static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context* ctx, void **prealloc); static void secp256k1_ecmult_gen_context_finalize_memcpy(secp256k1_ecmult_gen_context *dst, const secp256k1_ecmult_gen_context* src); From f698caaff6a263390d7ded5be4751dbc1c862b1e Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Sun, 4 Jul 2021 11:37:06 +0200 Subject: [PATCH 4/5] Use unsigned char consistently for byte arrays C++ does not allow initialization with string literals but we do it in other places and -fpermissive will convince g++ to compile. --- src/modules/schnorrsig/tests_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/schnorrsig/tests_impl.h b/src/modules/schnorrsig/tests_impl.h index e804df5041..59357afa99 100644 --- a/src/modules/schnorrsig/tests_impl.h +++ b/src/modules/schnorrsig/tests_impl.h @@ -219,7 +219,7 @@ void test_schnorrsig_api(void) { /* Checks that hash initialized by secp256k1_schnorrsig_sha256_tagged has the * expected state. */ void test_schnorrsig_sha256_tagged(void) { - char tag[17] = "BIP0340/challenge"; + unsigned char tag[17] = "BIP0340/challenge"; secp256k1_sha256 sha; secp256k1_sha256 sha_optimized; From 90e83449b2c2e4046af755e35fdeee579a468f31 Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Mon, 5 Jul 2021 10:33:36 +0200 Subject: [PATCH 5/5] ci: Add C++ test --- .cirrus.yml | 20 ++++++++++++++++++++ ci/linux-debian.Dockerfile | 1 + 2 files changed, 21 insertions(+) diff --git a/.cirrus.yml b/.cirrus.yml index aca8e0b527..bf71a70839 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -320,3 +320,23 @@ task: - ./ci/cirrus.sh << : *CAT_LOGS +task: + name: "C++ -fpermissive" + container: + dockerfile: ci/linux-debian.Dockerfile + cpu: 1 + memory: 1G + env: + # ./configure correctly errors out when given CC=g++. + # We hack around this by passing CC=g++ only to make. + CC: gcc + MAKEFLAGS: -j2 CC=g++ CFLAGS=-fpermissive + WERROR_CFLAGS: + EXPERIMENTAL: yes + ECDH: yes + RECOVERY: yes + SCHNORRSIG: yes + << : *MERGE_BASE + test_script: + - ./ci/cirrus.sh + << : *CAT_LOGS diff --git a/ci/linux-debian.Dockerfile b/ci/linux-debian.Dockerfile index 6def91333d..2c02ed69d0 100644 --- a/ci/linux-debian.Dockerfile +++ b/ci/linux-debian.Dockerfile @@ -13,6 +13,7 @@ RUN apt-get install --no-install-recommends --no-upgrade -y \ git ca-certificates \ make automake libtool pkg-config dpkg-dev valgrind qemu-user \ gcc clang llvm libc6-dbg \ + g++ \ gcc-i686-linux-gnu libc6-dev-i386-cross libc6-dbg:i386 libubsan1:i386 libasan5:i386 \ gcc-s390x-linux-gnu libc6-dev-s390x-cross libc6-dbg:s390x \ gcc-arm-linux-gnueabihf libc6-dev-armhf-cross libc6-dbg:armhf \