Skip to content

Commit 9bfa53e

Browse files
committed
BIP 340: Verify sig before returning it
1 parent b6b5f58 commit 9bfa53e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

bip-0340/reference.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ def schnorr_sign(msg, seckey0, aux_rand):
110110
R = point_mul(G, k0)
111111
k = n - k0 if not has_square_y(R) else k0
112112
e = int_from_bytes(tagged_hash("BIP340/challenge", bytes_from_point(R) + bytes_from_point(P) + msg)) % n
113-
return bytes_from_point(R) + bytes_from_int((k + e * seckey) % n)
113+
sig = bytes_from_point(R) + bytes_from_int((k + e * seckey) % n)
114+
if not schnorr_verify(msg, bytes_from_point(P), sig):
115+
raise RuntimeError('The signature does not pass verification.')
116+
return sig
114117

115118
def schnorr_verify(msg, pubkey, sig):
116119
if len(msg) != 32:

0 commit comments

Comments
 (0)