Skip to content

Commit 7265727

Browse files
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.
1 parent 07d938a commit 7265727

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

bip-0340/reference.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def schnorr_sign(msg, seckey, aux_rand):
122122
sig = bytes_from_point(R) + bytes_from_int((k + e * d) % n)
123123
debug_print_vars()
124124
if not schnorr_verify(msg, bytes_from_point(P), sig):
125-
raise RuntimeError('The signature does not pass verification.')
125+
raise RuntimeError('The created signature does not pass verification.')
126126
return sig
127127

128128
def schnorr_verify(msg, pubkey, sig):
@@ -173,13 +173,17 @@ def test_vectors():
173173
print(' Expected key:', pubkey.hex().upper())
174174
print(' Actual key:', pubkey_actual.hex().upper())
175175
aux_rand = bytes.fromhex(aux_rand)
176-
sig_actual = schnorr_sign(msg, seckey, aux_rand)
177-
if sig == sig_actual:
178-
print(' * Passed signing test.')
179-
else:
180-
print(' * Failed signing test.')
181-
print(' Expected signature:', sig.hex().upper())
182-
print(' Actual signature:', sig_actual.hex().upper())
176+
try:
177+
sig_actual = schnorr_sign(msg, seckey, aux_rand)
178+
if sig == sig_actual:
179+
print(' * Passed signing test.')
180+
else:
181+
print(' * Failed signing test.')
182+
print(' Expected signature:', sig.hex().upper())
183+
print(' Actual signature:', sig_actual.hex().upper())
184+
all_passed = False
185+
except RuntimeError as e:
186+
print(' * Signing test raised exception:', e)
183187
all_passed = False
184188
result_actual = schnorr_verify(msg, pubkey, sig)
185189
if result == result_actual:

0 commit comments

Comments
 (0)