Skip to content

Commit 2e76c5d

Browse files
committed
f don't allow counter != 0 in nonce function
1 parent 639a859 commit 2e76c5d

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

include/secp256k1.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,8 @@ SECP256K1_API extern const secp256k1_nonce_function secp256k1_nonce_function_rfc
525525

526526
/** An implementation of the nonce generation function as defined in BIP-schnorr.
527527
* If a data pointer is passed, it is assumed to be a pointer to 32 bytes of
528-
* extra entropy.
528+
* extra entropy. The attempt argument must be 0 or the function will fail and
529+
* return 0.
529530
*/
530531
SECP256K1_API extern const secp256k1_nonce_function secp256k1_nonce_function_bipschnorr;
531532

src/secp256k1.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,10 @@ static void secp256k1_nonce_function_bipschnorr_sha256_tagged(secp256k1_sha256 *
432432
* (https://github.com/sipa/bips/blob/bip-schnorr/bip-schnorr.mediawiki) */
433433
static int nonce_function_bipschnorr(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int counter) {
434434
secp256k1_sha256 sha;
435-
(void) counter;
436-
VERIFY_CHECK(counter == 0);
437435

436+
if (counter != 0) {
437+
return 0;
438+
}
438439
/* Tag the hash with algo16 which is important to avoid nonce reuse across
439440
* algorithms. If the this nonce function is used in BIP-schnorr signing as
440441
* defined in the spec, an optimized tagging implementation is used. */

src/tests.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ void run_nonce_function_bipschnorr_tests(void) {
491491
CHECK(nonce_function_bipschnorr(nonces[2], msg, key, (unsigned char *) "something16chars", NULL, 0));
492492
CHECK(memcmp(nonces[2], nonces[0], sizeof(nonces[2])) != 0);
493493
CHECK(memcmp(nonces[2], nonces[1], sizeof(nonces[2])) != 0);
494+
495+
/* Check that counter != 0 makes nonce function fail. */
496+
CHECK(nonce_function_bipschnorr(nonces[0], msg, key, NULL, NULL, 0) == 1);
497+
CHECK(nonce_function_bipschnorr(nonces[0], msg, key, NULL, NULL, 1) == 0);
494498
}
495499

496500
void run_hmac_sha256_tests(void) {

0 commit comments

Comments
 (0)