Skip to content

Commit 45f37b6

Browse files
committed
Modulo-reduce msg32 inside RFC6979 nonce fn to match spec. Fixes bitcoin#1063.
1 parent a1102b1 commit 45f37b6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/secp256k1.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -423,16 +423,20 @@ static int nonce_function_rfc6979(unsigned char *nonce32, const unsigned char *m
423423
unsigned int offset = 0;
424424
secp256k1_rfc6979_hmac_sha256 rng;
425425
unsigned int i;
426+
secp256k1_scalar msg;
427+
unsigned char msgmod32[32];
428+
secp256k1_scalar_set_b32(&msg, msg32, NULL);
429+
secp256k1_scalar_get_b32(msgmod32, &msg);
426430
/* We feed a byte array to the PRNG as input, consisting of:
427-
* - the private key (32 bytes) and message (32 bytes), see RFC 6979 3.2d.
431+
* - the private key (32 bytes) and reduced message (32 bytes), see RFC 6979 3.2d.
428432
* - optionally 32 extra bytes of data, see RFC 6979 3.6 Additional Data.
429433
* - optionally 16 extra bytes with the algorithm name.
430434
* Because the arguments have distinct fixed lengths it is not possible for
431435
* different argument mixtures to emulate each other and result in the same
432436
* nonces.
433437
*/
434438
buffer_append(keydata, &offset, key32, 32);
435-
buffer_append(keydata, &offset, msg32, 32);
439+
buffer_append(keydata, &offset, msgmod32, 32);
436440
if (data != NULL) {
437441
buffer_append(keydata, &offset, data, 32);
438442
}

0 commit comments

Comments
 (0)