1
0
mirror of https://github.com/bitcoin/bips.git synced 2026-09-14 19:01:38 +00:00

Merge pull request #2278 from fametrano/bip327-portable-monotonic-clock

bip-0327: derive extra_in from secrets in the reference self-test
This commit is contained in:
Murch
2026-09-10 08:25:02 -07:00
committed by GitHub

View File

@@ -7,7 +7,6 @@
from typing import List, Optional, Tuple, NewType, NamedTuple from typing import List, Optional, Tuple, NewType, NamedTuple
import hashlib import hashlib
import secrets import secrets
import time
# #
# The following helper functions were copied from the BIP-340 reference implementation: # The following helper functions were copied from the BIP-340 reference implementation:
@@ -838,9 +837,9 @@ def test_sign_and_verify_random(iters: int) -> None:
# On even iterations use regular signing algorithm for signer 2, # On even iterations use regular signing algorithm for signer 2,
# otherwise use deterministic signing algorithm # otherwise use deterministic signing algorithm
if i % 2 == 0: if i % 2 == 0:
# Use a clock for extra_in # Use random extra_in of random length
t = time.clock_gettime_ns(time.CLOCK_MONOTONIC) extra_in = secrets.token_bytes(secrets.randbelow(42))
secnonce_2, pubnonce_2 = nonce_gen(sk_2, pk_2, aggpk, msg, t.to_bytes(8, 'big')) secnonce_2, pubnonce_2 = nonce_gen(sk_2, pk_2, aggpk, msg, extra_in)
else: else:
aggothernonce = nonce_agg([pubnonce_1]) aggothernonce = nonce_agg([pubnonce_1])
rand = secrets.token_bytes(32) rand = secrets.token_bytes(32)