From 769528f30714a1e5503a7abefad25fd89f0ef237 Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Sun, 4 Jul 2021 02:03:18 +0200 Subject: [PATCH] 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 d68bba62ccf49..74cbcac45ec03 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 e6de73b8a59a3..693b78f03444d 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;