Skip to content

Commit afa1324

Browse files
committed
Update test vectors and generation script
1 parent 8a3db73 commit afa1324

File tree

3 files changed

+63
-59
lines changed

3 files changed

+63
-59
lines changed

bip-0340/reference.py

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,38 +66,22 @@ def bytes_from_point(P: Point) -> bytes:
6666
def xor_bytes(b0: bytes, b1: bytes) -> bytes:
6767
return bytes(x ^ y for (x, y) in zip(b0, b1))
6868

69-
def lift_x_square_y(b: bytes) -> Optional[Point]:
69+
def lift_x(b: bytes) -> Optional[Point]:
7070
x = int_from_bytes(b)
7171
if x >= p:
7272
return None
7373
y_sq = (pow(x, 3, p) + 7) % p
7474
y = pow(y_sq, (p + 1) // 4, p)
7575
if pow(y, 2, p) != y_sq:
7676
return None
77-
return (x, y)
78-
79-
def lift_x_even_y(b: bytes) -> Optional[Point]:
80-
P = lift_x_square_y(b)
81-
if P is None:
82-
return None
83-
else:
84-
return (x(P), y(P) if y(P) % 2 == 0 else p - y(P))
77+
return (x, y if y & 1 == 0 else p-y)
8578

8679
def int_from_bytes(b: bytes) -> int:
8780
return int.from_bytes(b, byteorder="big")
8881

8982
def hash_sha256(b: bytes) -> bytes:
9083
return hashlib.sha256(b).digest()
9184

92-
def is_square(x: int) -> bool:
93-
return int(pow(x, (p - 1) // 2, p)) == 1
94-
95-
def has_square_y(P: Optional[Point]) -> bool:
96-
infinity = is_infinity(P)
97-
if infinity: return False
98-
assert P is not None
99-
return is_square(y(P))
100-
10185
def has_even_y(P: Point) -> bool:
10286
return y(P) % 2 == 0
10387

@@ -120,14 +104,14 @@ def schnorr_sign(msg: bytes, seckey: bytes, aux_rand: bytes) -> bytes:
120104
P = point_mul(G, d0)
121105
assert P is not None
122106
d = d0 if has_even_y(P) else n - d0
123-
t = xor_bytes(bytes_from_int(d), tagged_hash("BIP340/aux", aux_rand))
124-
k0 = int_from_bytes(tagged_hash("BIP340/nonce", t + bytes_from_point(P) + msg)) % n
107+
t = xor_bytes(bytes_from_int(d), tagged_hash("BIP0340/aux", aux_rand))
108+
k0 = int_from_bytes(tagged_hash("BIP0340/nonce", t + bytes_from_point(P) + msg)) % n
125109
if k0 == 0:
126110
raise RuntimeError('Failure. This happens only with negligible probability.')
127111
R = point_mul(G, k0)
128112
assert R is not None
129-
k = n - k0 if not has_square_y(R) else k0
130-
e = int_from_bytes(tagged_hash("BIP340/challenge", bytes_from_point(R) + bytes_from_point(P) + msg)) % n
113+
k = n - k0 if not has_even_y(R) else k0
114+
e = int_from_bytes(tagged_hash("BIP0340/challenge", bytes_from_point(R) + bytes_from_point(P) + msg)) % n
131115
sig = bytes_from_point(R) + bytes_from_int((k + e * d) % n)
132116
debug_print_vars()
133117
if not schnorr_verify(msg, bytes_from_point(P), sig):
@@ -141,15 +125,15 @@ def schnorr_verify(msg: bytes, pubkey: bytes, sig: bytes) -> bool:
141125
raise ValueError('The public key must be a 32-byte array.')
142126
if len(sig) != 64:
143127
raise ValueError('The signature must be a 64-byte array.')
144-
P = lift_x_even_y(pubkey)
128+
P = lift_x(pubkey)
145129
r = int_from_bytes(sig[0:32])
146130
s = int_from_bytes(sig[32:64])
147131
if (P is None) or (r >= p) or (s >= n):
148132
debug_print_vars()
149133
return False
150-
e = int_from_bytes(tagged_hash("BIP340/challenge", sig[0:32] + pubkey + msg)) % n
134+
e = int_from_bytes(tagged_hash("BIP0340/challenge", sig[0:32] + pubkey + msg)) % n
151135
R = point_add(point_mul(G, s), point_mul(P, n - e))
152-
if (R is None) or (not has_square_y(R)) or (x(R) != r):
136+
if (R is None) or (not has_even_y(R)) or (x(R) != r):
153137
debug_print_vars()
154138
return False
155139
debug_print_vars()

bip-0340/test-vectors.csv

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
index,secret key,public key,aux_rand,message,signature,verification result,comment
2-
0,0000000000000000000000000000000000000000000000000000000000000003,F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9,0000000000000000000000000000000000000000000000000000000000000000,0000000000000000000000000000000000000000000000000000000000000000,067E337AD551B2276EC705E43F0920926A9CE08AC68159F9D258C9BBA412781C9F059FCDF4824F13B3D7C1305316F956704BB3FEA2C26142E18ACD90A90C947E,TRUE,
3-
1,B7E151628AED2A6ABF7158809CF4F3C762E7160F38B4DA56A784D9045190CFEF,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,0000000000000000000000000000000000000000000000000000000000000001,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,0E12B8C520948A776753A96F21ABD7FDC2D7D0C0DDC90851BE17B04E75EF86A47EF0DA46C4DC4D0D1BCB8668C2CE16C54C7C23A6716EDE303AF86774917CF928,TRUE,
4-
2,C90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B14E5C9,DD308AFEC5777E13121FA72B9CC1B7CC0139715309B086C960E18FD969774EB8,C87AA53824B4D7AE2EB035A2B5BBBCCC080E76CDC6D1692C4B0B62D798E6D906,7E2D58D8B3BCDF1ABADEC7829054F90DDA9805AAB56C77333024B9D0A508B75C,FC012F9FB8FE00A358F51EF93DCE0DC0C895F6E9A87C6C4905BC820B0C3677616B8737D14E703AF8E16E22E5B8F26227D41E5128F82D86F747244CC289C74D1D,TRUE,
5-
3,0B432B2677937381AEF05BB02A66ECD012773062CF3FA2549E44F58ED2401710,25D1DFF95105F5253C4022F628A996AD3A0D95FBF21D468A1B33F8C160D8F517,FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,FC132D4E426DFF535AEC0FA7083AC5118BC1D5FFFD848ABD8290C23F271CA0DD11AEDCEA3F55DA9BD677FE29C9DDA0CF878BCE43FDE0E313D69D1AF7A5AE8369,TRUE,test fails if msg is reduced modulo p or n
6-
4,,D69C3509BB99E412E68B0FE8544E72837DFA30746D8BE2AA65975F29D22DC7B9,,4DF3C3F68FCC83B27E9D42C90431A72499F17875C81A599B566C9889B9696703,00000000000000000000003B78CE563F89A0ED9414F5AA28AD0D96D6795F9C630EC50E5363E227ACAC6F542CE1C0B186657E0E0D1A6FFE283A33438DE4738419,TRUE,
7-
5,,EEFDEA4CDB677750A420FEE807EACF21EB9898AE79B9768766E4FAA04A2D4A34,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,7036D6BFE1837AE919631039A2CF652A295DFAC9A8BBB0806014B2F48DD7C807941607B563ABBA414287F374A332BA3636DE009EE1EF551A17796B72B68B8A24,FALSE,public key not on the curve
8-
6,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F995A579DA959FA739FCE39E8BD16FECB5CDCF97060B2C73CDE60E87ABCA1AA5D9,FALSE,has_square_y(R) is false
9-
7,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,F8704654F4687B7365ED32E796DE92761390A3BCC495179BFE073817B7ED32824E76B987F7C1F9A751EF5C343F7645D3CFFC7D570B9A7192EBF1898E1344E3BF,FALSE,negated message
10-
8,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,7036D6BFE1837AE919631039A2CF652A295DFAC9A8BBB0806014B2F48DD7C8076BE9F84A9C5445BEBD780C8B5CCD45C883D0DC47CD594B21A858F31A19AAB71D,FALSE,negated s value
11-
9,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,00000000000000000000000000000000000000000000000000000000000000009915EE59F07F9DBBAEDC31BFCC9B34AD49DE669CD24773BCED77DDA36D073EC8,FALSE,sG - eP is infinite. Test fails in single verification if has_square_y(inf) is defined as true and x(inf) as 0
12-
10,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,0000000000000000000000000000000000000000000000000000000000000001C7EC918B2B9CF34071BB54BED7EB4BB6BAB148E9A7E36E6B228F95DFA08B43EC,FALSE,sG - eP is infinite. Test fails in single verification if has_square_y(inf) is defined as true and x(inf) as 1
13-
11,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,4A298DACAE57395A15D0795DDBFD1DCB564DA82B0F269BC70A74F8220429BA1D941607B563ABBA414287F374A332BA3636DE009EE1EF551A17796B72B68B8A24,FALSE,sig[0:32] is not an X coordinate on the curve
14-
12,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F941607B563ABBA414287F374A332BA3636DE009EE1EF551A17796B72B68B8A24,FALSE,sig[0:32] is equal to field size
15-
13,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,7036D6BFE1837AE919631039A2CF652A295DFAC9A8BBB0806014B2F48DD7C807FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141,FALSE,sig[32:64] is equal to curve order
16-
14,,FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC30,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,7036D6BFE1837AE919631039A2CF652A295DFAC9A8BBB0806014B2F48DD7C807941607B563ABBA414287F374A332BA3636DE009EE1EF551A17796B72B68B8A24,FALSE,public key is not a valid X coordinate because it exceeds the field size
2+
0,0000000000000000000000000000000000000000000000000000000000000003,F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9,0000000000000000000000000000000000000000000000000000000000000000,0000000000000000000000000000000000000000000000000000000000000000,E907831F80848D1069A5371B402410364BDF1C5F8307B0084C55F1CE2DCA821525F66A4A85EA8B71E482A74F382D2CE5EBEEE8FDB2172F477DF4900D310536C0,TRUE,
3+
1,B7E151628AED2A6ABF7158809CF4F3C762E7160F38B4DA56A784D9045190CFEF,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,0000000000000000000000000000000000000000000000000000000000000001,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,6896BD60EEAE296DB48A229FF71DFE071BDE413E6D43F917DC8DCF8C78DE33418906D11AC976ABCCB20B091292BFF4EA897EFCB639EA871CFA95F6DE339E4B0A,TRUE,
4+
2,C90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B14E5C9,DD308AFEC5777E13121FA72B9CC1B7CC0139715309B086C960E18FD969774EB8,C87AA53824B4D7AE2EB035A2B5BBBCCC080E76CDC6D1692C4B0B62D798E6D906,7E2D58D8B3BCDF1ABADEC7829054F90DDA9805AAB56C77333024B9D0A508B75C,5831AAEED7B44BB74E5EAB94BA9D4294C49BCF2A60728D8B4C200F50DD313C1BAB745879A5AD954A72C45A91C3A51D3C7ADEA98D82F8481E0E1E03674A6F3FB7,TRUE,
5+
3,0B432B2677937381AEF05BB02A66ECD012773062CF3FA2549E44F58ED2401710,25D1DFF95105F5253C4022F628A996AD3A0D95FBF21D468A1B33F8C160D8F517,FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,7EB0509757E246F19449885651611CB965ECC1A187DD51B64FDA1EDC9637D5EC97582B9CB13DB3933705B32BA982AF5AF25FD78881EBB32771FC5922EFC66EA3,TRUE,test fails if msg is reduced modulo p or n
6+
4,,D69C3509BB99E412E68B0FE8544E72837DFA30746D8BE2AA65975F29D22DC7B9,,4DF3C3F68FCC83B27E9D42C90431A72499F17875C81A599B566C9889B9696703,00000000000000000000003B78CE563F89A0ED9414F5AA28AD0D96D6795F9C6376AFB1548AF603B3EB45C9F8207DEE1060CB71C04E80F593060B07D28308D7F4,TRUE,
7+
5,,EEFDEA4CDB677750A420FEE807EACF21EB9898AE79B9768766E4FAA04A2D4A34,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,6CFF5C3BA86C69EA4B7376F31A9BCB4F74C1976089B2D9963DA2E5543E17776969E89B4C5564D00349106B8497785DD7D1D713A8AE82B32FA79D5F7FC407D39B,FALSE,public key not on the curve
8+
6,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,FFF97BD5755EEEA420453A14355235D382F6472F8568A18B2F057A14602975563CC27944640AC607CD107AE10923D9EF7A73C643E166BE5EBEAFA34B1AC553E2,FALSE,has_even_y(R) is false
9+
7,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,1FA62E331EDBC21C394792D2AB1100A7B432B013DF3F6FF4F99FCB33E0E1515F28890B3EDB6E7189B630448B515CE4F8622A954CFE545735AAEA5134FCCDB2BD,FALSE,negated message
10+
8,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,6CFF5C3BA86C69EA4B7376F31A9BCB4F74C1976089B2D9963DA2E5543E177769961764B3AA9B2FFCB6EF947B6887A226E8D7C93E00C5ED0C1834FF0D0C2E6DA6,FALSE,negated s value
11+
9,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,0000000000000000000000000000000000000000000000000000000000000000123DDA8328AF9C23A94C1FEECFD123BA4FB73476F0D594DCB65C6425BD186051,FALSE,sG - eP is infinite. Test fails in single verification if has_even_y(inf) is defined as true and x(inf) as 0
12+
10,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,00000000000000000000000000000000000000000000000000000000000000017615FBAF5AE28864013C099742DEADB4DBA87F11AC6754F93780D5A1837CF197,FALSE,sG - eP is infinite. Test fails in single verification if has_even_y(inf) is defined as true and x(inf) as 1
13+
11,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,4A298DACAE57395A15D0795DDBFD1DCB564DA82B0F269BC70A74F8220429BA1D69E89B4C5564D00349106B8497785DD7D1D713A8AE82B32FA79D5F7FC407D39B,FALSE,sig[0:32] is not an X coordinate on the curve
14+
12,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F69E89B4C5564D00349106B8497785DD7D1D713A8AE82B32FA79D5F7FC407D39B,FALSE,sig[0:32] is equal to field size
15+
13,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,6CFF5C3BA86C69EA4B7376F31A9BCB4F74C1976089B2D9963DA2E5543E177769FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141,FALSE,sig[32:64] is equal to curve order
16+
14,,FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC30,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,6CFF5C3BA86C69EA4B7376F31A9BCB4F74C1976089B2D9963DA2E5543E17776969E89B4C5564D00349106B8497785DD7D1D713A8AE82B32FA79D5F7FC407D39B,FALSE,public key is not a valid X coordinate because it exceeds the field size

bip-0340/test-vectors.py

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import sys
22
from reference import *
33

4+
def is_square(x):
5+
return int(pow(x, (p - 1) // 2, p)) == 1
6+
7+
def has_square_y(P):
8+
"""Determine if P has a square Y coordinate. Used in an earlier draft of BIP340."""
9+
assert not is_infinity(P)
10+
return is_square(P[1])
11+
412
def vector0():
513
seckey = bytes_from_int(3)
614
msg = bytes_from_int(0)
@@ -19,9 +27,16 @@ def vector0():
1927
# we should have at least one test vector where the the point reconstructed
2028
# from the public key has a square and one where it has a non-square Y
2129
# coordinate. In this one Y is non-square.
22-
pubkey_point = lift_x_even_y(pubkey)
30+
pubkey_point = lift_x(pubkey)
2331
assert(not has_square_y(pubkey_point))
2432

33+
# For historical reasons (R tiebreaker was squareness and not evenness)
34+
# we should have at least one test vector where the the point reconstructed
35+
# from the R.x coordinate has a square and one where it has a non-square Y
36+
# coordinate. In this one Y is non-square.
37+
R = lift_x(sig[0:32])
38+
assert(not has_square_y(R))
39+
2540
return (seckey, pubkey, aux_rand, msg, sig, "TRUE", None)
2641

2742
def vector1():
@@ -30,6 +45,11 @@ def vector1():
3045
aux_rand = bytes_from_int(1)
3146

3247
sig = schnorr_sign(msg, seckey, aux_rand)
48+
49+
# The point reconstructed from the R.x coordinate has a square Y coordinate.
50+
R = lift_x(sig[0:32])
51+
assert(has_square_y(R))
52+
3353
return (seckey, pubkey_gen(seckey), aux_rand, msg, sig, "TRUE", None)
3454

3555
def vector2():
@@ -40,13 +60,13 @@ def vector2():
4060

4161
# The point reconstructed from the public key has a square Y coordinate.
4262
pubkey = pubkey_gen(seckey)
43-
pubkey_point = lift_x_even_y(pubkey)
63+
pubkey_point = lift_x(pubkey)
4464
assert(has_square_y(pubkey_point))
4565

4666
# This signature vector would not verify if the implementer checked the
47-
# squareness of the X coordinate of R instead of the Y coordinate.
48-
R = lift_x_square_y(sig[0:32])
49-
assert(not is_square(R[0]))
67+
# evenness of the X coordinate of R instead of the Y coordinate.
68+
R = lift_x(sig[0:32])
69+
assert(R[0] % 2 == 1)
5070

5171
return (seckey, pubkey, aux_rand, msg, sig, "TRUE", None)
5272

@@ -66,7 +86,7 @@ def vector3():
6686

6787
# Signs with a given nonce. This can be INSECURE and is only INTENDED FOR
6888
# GENERATING TEST VECTORS. Results in an invalid signature if y(kG) is not
69-
# square.
89+
# even.
7090
def insecure_schnorr_sign_fixed_nonce(msg, seckey0, k):
7191
if len(msg) != 32:
7292
raise ValueError('The message must be a 32-byte array.')
@@ -76,12 +96,12 @@ def insecure_schnorr_sign_fixed_nonce(msg, seckey0, k):
7696
P = point_mul(G, seckey0)
7797
seckey = seckey0 if has_even_y(P) else n - seckey0
7898
R = point_mul(G, k)
79-
e = int_from_bytes(tagged_hash("BIP340/challenge", bytes_from_point(R) + bytes_from_point(P) + msg)) % n
99+
e = int_from_bytes(tagged_hash("BIP0340/challenge", bytes_from_point(R) + bytes_from_point(P) + msg)) % n
80100
return bytes_from_point(R) + bytes_from_int((k + e * seckey) % n)
81101

82-
# Creates a singature with a small x(R) by using k = 1/2
102+
# Creates a singature with a small x(R) by using k = -1/2
83103
def vector4():
84-
one_half = 0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0
104+
one_half = n - 0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0
85105
seckey = bytes_from_int(0x763758E5CBEEDEE4F7D3FC86F531C36578933228998226672F13C4F0EBE855EB)
86106
msg = bytes_from_int(0x4DF3C3F68FCC83B27E9D42C90431A72499F17875C81A599B566C9889B9696703)
87107
sig = insecure_schnorr_sign_fixed_nonce(msg, seckey, one_half)
@@ -100,21 +120,21 @@ def vector5():
100120
sig = schnorr_sign(msg, seckey, default_aux_rand)
101121

102122
pubkey = bytes_from_int(0xEEFDEA4CDB677750A420FEE807EACF21EB9898AE79B9768766E4FAA04A2D4A34)
103-
assert(lift_x_even_y(pubkey) is None)
123+
assert(lift_x(pubkey) is None)
104124

105125
return (None, pubkey, None, msg, sig, "FALSE", "public key not on the curve")
106126

107127
def vector6():
108128
seckey = default_seckey
109129
msg = default_msg
110-
k = 3
130+
k = 6
111131
sig = insecure_schnorr_sign_fixed_nonce(msg, seckey, k)
112132

113-
# Y coordinate of R is not a square
133+
# Y coordinate of R is not even
114134
R = point_mul(G, k)
115-
assert(not has_square_y(R))
135+
assert(not has_even_y(R))
116136

117-
return (None, pubkey_gen(seckey), None, msg, sig, "FALSE", "has_square_y(R) is false")
137+
return (None, pubkey_gen(seckey), None, msg, sig, "FALSE", "has_even_y(R) is false")
118138

119139
def vector7():
120140
seckey = default_seckey
@@ -147,7 +167,7 @@ def vector9():
147167
sig = insecure_schnorr_sign_fixed_nonce(msg, seckey, k)
148168
bytes_from_point.__code__ = bytes_from_point_tmp
149169

150-
return (None, pubkey_gen(seckey), None, msg, sig, "FALSE", "sG - eP is infinite. Test fails in single verification if has_square_y(inf) is defined as true and x(inf) as 0")
170+
return (None, pubkey_gen(seckey), None, msg, sig, "FALSE", "sG - eP is infinite. Test fails in single verification if has_even_y(inf) is defined as true and x(inf) as 0")
151171

152172
def bytes_from_point_inf1(P):
153173
if P == None:
@@ -166,7 +186,7 @@ def vector10():
166186
sig = insecure_schnorr_sign_fixed_nonce(msg, seckey, k)
167187
bytes_from_point.__code__ = bytes_from_point_tmp
168188

169-
return (None, pubkey_gen(seckey), None, msg, sig, "FALSE", "sG - eP is infinite. Test fails in single verification if has_square_y(inf) is defined as true and x(inf) as 1")
189+
return (None, pubkey_gen(seckey), None, msg, sig, "FALSE", "sG - eP is infinite. Test fails in single verification if has_even_y(inf) is defined as true and x(inf) as 1")
170190

171191
# It's cryptographically impossible to create a test vector that fails if run
172192
# in an implementation which merely misses the check that sig[0:32] is an X
@@ -178,7 +198,7 @@ def vector11():
178198

179199
# Replace R's X coordinate with an X coordinate that's not on the curve
180200
x_not_on_curve = bytes_from_int(0x4A298DACAE57395A15D0795DDBFD1DCB564DA82B0F269BC70A74F8220429BA1D)
181-
assert(lift_x_square_y(x_not_on_curve) is None)
201+
assert(lift_x(x_not_on_curve) is None)
182202
sig = x_not_on_curve + sig[32:64]
183203

184204
return (None, pubkey_gen(seckey), None, msg, sig, "FALSE", "sig[0:32] is not an X coordinate on the curve")
@@ -222,10 +242,10 @@ def vector14():
222242
sig = schnorr_sign(msg, seckey, default_aux_rand)
223243
pubkey_int = p + 1
224244
pubkey = bytes_from_int(pubkey_int)
225-
assert(lift_x_even_y(pubkey) is None)
245+
assert(lift_x(pubkey) is None)
226246
# If an implementation would reduce a given public key modulo p then the
227247
# pubkey would be valid
228-
assert(lift_x_even_y(bytes_from_int(pubkey_int % p)) is not None)
248+
assert(lift_x(bytes_from_int(pubkey_int % p)) is not None)
229249

230250
return (None, pubkey, None, msg, sig, "FALSE", "public key is not a valid X coordinate because it exceeds the field size")
231251

0 commit comments

Comments
 (0)