summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark "Murch" Erhardt <murch@murch.one>2024-12-23 16:09:41 -0500
committerGitHub <noreply@github.com>2024-12-23 16:09:41 -0500
commit665712c727ee898f0e6a31eee6f1a0ecab8bae4e (patch)
treeecd1ae65479883dd04f0ec125382e3aaa4ec719c
parenta0d4fb16f1466abba3b19e8539b6504447fa3b40 (diff)
parent7d921e33148bac865ef84860f61a3a2eba233c7d (diff)
Merge pull request #1729 from theStack/fix-bip0340-test-vector-gen_lift_xHEADmaster
BIP-340: fix `lift_x` calls in test vector generation script
-rw-r--r--bip-0340/test-vectors.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/bip-0340/test-vectors.py b/bip-0340/test-vectors.py
index 5a131c4..8442a71 100644
--- a/bip-0340/test-vectors.py
+++ b/bip-0340/test-vectors.py
@@ -27,14 +27,14 @@ def vector0():
# we should have at least one test vector where the point reconstructed
# from the public key has a square and one where it has a non-square Y
# coordinate. In this one Y is non-square.
- pubkey_point = lift_x(pubkey)
+ pubkey_point = lift_x(int_from_bytes(pubkey))
assert(not has_square_y(pubkey_point))
# For historical reasons (R tiebreaker was squareness and not evenness)
# we should have at least one test vector where the point reconstructed
# from the R.x coordinate has a square and one where it has a non-square Y
# coordinate. In this one Y is non-square.
- R = lift_x(sig[0:32])
+ R = lift_x(int_from_bytes(sig[0:32]))
assert(not has_square_y(R))
return (seckey, pubkey, aux_rand, msg, sig, "TRUE", None)
@@ -47,7 +47,7 @@ def vector1():
sig = schnorr_sign(msg, seckey, aux_rand)
# The point reconstructed from the R.x coordinate has a square Y coordinate.
- R = lift_x(sig[0:32])
+ R = lift_x(int_from_bytes(sig[0:32]))
assert(has_square_y(R))
return (seckey, pubkey_gen(seckey), aux_rand, msg, sig, "TRUE", None)
@@ -60,12 +60,12 @@ def vector2():
# The point reconstructed from the public key has a square Y coordinate.
pubkey = pubkey_gen(seckey)
- pubkey_point = lift_x(pubkey)
+ pubkey_point = lift_x(int_from_bytes(pubkey))
assert(has_square_y(pubkey_point))
# This signature vector would not verify if the implementer checked the
# evenness of the X coordinate of R instead of the Y coordinate.
- R = lift_x(sig[0:32])
+ R = lift_x(int_from_bytes(sig[0:32]))
assert(R[0] % 2 == 1)
return (seckey, pubkey, aux_rand, msg, sig, "TRUE", None)
@@ -119,8 +119,9 @@ def vector5():
msg = default_msg
sig = schnorr_sign(msg, seckey, default_aux_rand)
- pubkey = bytes_from_int(0xEEFDEA4CDB677750A420FEE807EACF21EB9898AE79B9768766E4FAA04A2D4A34)
- assert(lift_x(pubkey) is None)
+ pubkey_int = 0xEEFDEA4CDB677750A420FEE807EACF21EB9898AE79B9768766E4FAA04A2D4A34
+ pubkey = bytes_from_int(pubkey_int)
+ assert(lift_x(pubkey_int) is None)
return (None, pubkey, None, msg, sig, "FALSE", "public key not on the curve")
@@ -197,9 +198,9 @@ def vector11():
sig = schnorr_sign(msg, seckey, default_aux_rand)
# Replace R's X coordinate with an X coordinate that's not on the curve
- x_not_on_curve = bytes_from_int(0x4A298DACAE57395A15D0795DDBFD1DCB564DA82B0F269BC70A74F8220429BA1D)
+ x_not_on_curve = 0x4A298DACAE57395A15D0795DDBFD1DCB564DA82B0F269BC70A74F8220429BA1D
assert(lift_x(x_not_on_curve) is None)
- sig = x_not_on_curve + sig[32:64]
+ sig = bytes_from_int(x_not_on_curve) + sig[32:64]
return (None, pubkey_gen(seckey), None, msg, sig, "FALSE", "sig[0:32] is not an X coordinate on the curve")
@@ -242,10 +243,10 @@ def vector14():
sig = schnorr_sign(msg, seckey, default_aux_rand)
pubkey_int = p + 1
pubkey = bytes_from_int(pubkey_int)
- assert(lift_x(pubkey) is None)
+ assert(lift_x(pubkey_int) is None)
# If an implementation would reduce a given public key modulo p then the
# pubkey would be valid
- assert(lift_x(bytes_from_int(pubkey_int % p)) is not None)
+ assert(lift_x(pubkey_int % p) is not None)
return (None, pubkey, None, msg, sig, "FALSE", "public key is not a valid X coordinate because it exceeds the field size")