mirror of
https://github.com/bitcoin/bips.git
synced 2025-05-12 12:03:29 +00:00
When checking test vectors, handle RuntimeException in signing
This is better for playing around with the code. Now these these exceptions can really be raised when the verification during signing fails.
This commit is contained in:
parent
07d938a214
commit
72657270d8
@ -122,7 +122,7 @@ def schnorr_sign(msg, seckey, aux_rand):
|
|||||||
sig = bytes_from_point(R) + bytes_from_int((k + e * d) % n)
|
sig = bytes_from_point(R) + bytes_from_int((k + e * d) % n)
|
||||||
debug_print_vars()
|
debug_print_vars()
|
||||||
if not schnorr_verify(msg, bytes_from_point(P), sig):
|
if not schnorr_verify(msg, bytes_from_point(P), sig):
|
||||||
raise RuntimeError('The signature does not pass verification.')
|
raise RuntimeError('The created signature does not pass verification.')
|
||||||
return sig
|
return sig
|
||||||
|
|
||||||
def schnorr_verify(msg, pubkey, sig):
|
def schnorr_verify(msg, pubkey, sig):
|
||||||
@ -173,6 +173,7 @@ def test_vectors():
|
|||||||
print(' Expected key:', pubkey.hex().upper())
|
print(' Expected key:', pubkey.hex().upper())
|
||||||
print(' Actual key:', pubkey_actual.hex().upper())
|
print(' Actual key:', pubkey_actual.hex().upper())
|
||||||
aux_rand = bytes.fromhex(aux_rand)
|
aux_rand = bytes.fromhex(aux_rand)
|
||||||
|
try:
|
||||||
sig_actual = schnorr_sign(msg, seckey, aux_rand)
|
sig_actual = schnorr_sign(msg, seckey, aux_rand)
|
||||||
if sig == sig_actual:
|
if sig == sig_actual:
|
||||||
print(' * Passed signing test.')
|
print(' * Passed signing test.')
|
||||||
@ -181,6 +182,9 @@ def test_vectors():
|
|||||||
print(' Expected signature:', sig.hex().upper())
|
print(' Expected signature:', sig.hex().upper())
|
||||||
print(' Actual signature:', sig_actual.hex().upper())
|
print(' Actual signature:', sig_actual.hex().upper())
|
||||||
all_passed = False
|
all_passed = False
|
||||||
|
except RuntimeError as e:
|
||||||
|
print(' * Signing test raised exception:', e)
|
||||||
|
all_passed = False
|
||||||
result_actual = schnorr_verify(msg, pubkey, sig)
|
result_actual = schnorr_verify(msg, pubkey, sig)
|
||||||
if result == result_actual:
|
if result == result_actual:
|
||||||
print(' * Passed verification test.')
|
print(' * Passed verification test.')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user