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

bip-0327: derive extra_in from secrets in the reference self-test

The self-test reads time.clock_gettime_ns(time.CLOCK_MONOTONIC) for
extra_in on even iterations. CPython documents both symbols
"Availability: Unix", so the attribute lookup raises AttributeError on
Windows and python3 reference.py does not run there.

Take extra_in from secrets instead, at a random length, so the self-test
also exercises extra_in of varying length. time has no other use in the
file, so its import goes too.
This commit is contained in:
Ferdinando Ametrano
2026-09-07 20:42:48 +02:00
parent 2120121c40
commit 4f9567fd60

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)