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:
@@ -7,7 +7,6 @@
|
||||
from typing import List, Optional, Tuple, NewType, NamedTuple
|
||||
import hashlib
|
||||
import secrets
|
||||
import time
|
||||
|
||||
#
|
||||
# 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,
|
||||
# otherwise use deterministic signing algorithm
|
||||
if i % 2 == 0:
|
||||
# Use a clock for extra_in
|
||||
t = time.clock_gettime_ns(time.CLOCK_MONOTONIC)
|
||||
secnonce_2, pubnonce_2 = nonce_gen(sk_2, pk_2, aggpk, msg, t.to_bytes(8, 'big'))
|
||||
# Use random extra_in of random length
|
||||
extra_in = secrets.token_bytes(secrets.randbelow(42))
|
||||
secnonce_2, pubnonce_2 = nonce_gen(sk_2, pk_2, aggpk, msg, extra_in)
|
||||
else:
|
||||
aggothernonce = nonce_agg([pubnonce_1])
|
||||
rand = secrets.token_bytes(32)
|
||||
|
||||
Reference in New Issue
Block a user