@@ -78,7 +78,7 @@ def lift_x_even_y(b):
78
78
if P is None :
79
79
return None
80
80
else :
81
- return [ x (P ), y (P ) if y (P ) % 2 == 0 else p - y (P )]
81
+ return ( x (P ), y (P ) if y (P ) % 2 == 0 else p - y (P ))
82
82
83
83
def int_from_bytes (b ):
84
84
return int .from_bytes (b , byteorder = "big" )
@@ -90,22 +90,20 @@ def is_square(x):
90
90
return pow (x , (p - 1 ) // 2 , p ) == 1
91
91
92
92
def has_square_y (P ):
93
- return (not is_infinity (P )) and ( is_square (y (P ) ))
93
+ return (not is_infinity (P )) and is_square (y (P ))
94
94
95
95
def has_even_y (P ):
96
96
return y (P ) % 2 == 0
97
97
98
98
def pubkey_gen (seckey ):
99
99
d0 = int_from_bytes (seckey )
100
100
if not (1 <= d0 <= n - 1 ):
101
- debug_print_vars ()
102
101
raise ValueError ('The secret key must be an integer in the range 1..n-1.' )
103
102
P = point_mul (G , d0 )
104
103
return bytes_from_point (P )
105
104
106
105
def schnorr_sign (msg , seckey , aux_rand ):
107
106
if len (msg ) != 32 :
108
- debug_print_vars ()
109
107
raise ValueError ('The message must be a 32-byte array.' )
110
108
d0 = int_from_bytes (seckey )
111
109
if not (1 <= d0 <= n - 1 ):
@@ -117,16 +115,14 @@ def schnorr_sign(msg, seckey, aux_rand):
117
115
t = xor_bytes (bytes_from_int (d ), tagged_hash ("BIP340/aux" , aux_rand ))
118
116
k0 = int_from_bytes (tagged_hash ("BIP340/nonce" , t + bytes_from_point (P ) + msg )) % n
119
117
if k0 == 0 :
120
- debug_print_vars ()
121
118
raise RuntimeError ('Failure. This happens only with negligible probability.' )
122
119
R = point_mul (G , k0 )
123
120
k = n - k0 if not has_square_y (R ) else k0
124
121
e = int_from_bytes (tagged_hash ("BIP340/challenge" , bytes_from_point (R ) + bytes_from_point (P ) + msg )) % n
125
122
sig = bytes_from_point (R ) + bytes_from_int ((k + e * d ) % n )
123
+ debug_print_vars ()
126
124
if not schnorr_verify (msg , bytes_from_point (P ), sig ):
127
- debug_print_vars ()
128
125
raise RuntimeError ('The signature does not pass verification.' )
129
- debug_print_vars ()
130
126
return sig
131
127
132
128
def schnorr_verify (msg , pubkey , sig ):
0 commit comments