diff options
author | Pieter Wuille <pieter@wuille.net> | 2020-09-02 14:20:42 -0700 |
---|---|---|
committer | Pieter Wuille <pieter@wuille.net> | 2020-09-03 14:38:22 -0700 |
commit | 3b1fb9600b938172dd98a63e4906a861af9c3ab0 (patch) | |
tree | e9bbf70fe3c22394512934eb294a96f80e286845 /bip-0340 | |
parent | d8531483f53adb39bf2265ea2148a8b05334d747 (diff) | |
download | bips-3b1fb9600b938172dd98a63e4906a861af9c3ab0.tar.xz |
Clarify that R=infinity is invalid in BIP340
Also rename is_infinity to is_infinite is reference implementation,
to match the wording in BIP340.
Diffstat (limited to 'bip-0340')
-rw-r--r-- | bip-0340/reference.py | 5 | ||||
-rw-r--r-- | bip-0340/test-vectors.py | 2 |
2 files changed, 5 insertions, 2 deletions
diff --git a/bip-0340/reference.py b/bip-0340/reference.py index 5d17db5..5b38c0a 100644 --- a/bip-0340/reference.py +++ b/bip-0340/reference.py @@ -26,13 +26,15 @@ def tagged_hash(tag: str, msg: bytes) -> bytes: tag_hash = hashlib.sha256(tag.encode()).digest() return hashlib.sha256(tag_hash + tag_hash + msg).digest() -def is_infinity(P: Optional[Point]) -> bool: +def is_infinite(P: Optional[Point]) -> bool: return P is None def x(P: Point) -> int: + assert not is_infinite(P) return P[0] def y(P: Point) -> int: + assert not is_infinite(P) return P[1] def point_add(P1: Optional[Point], P2: Optional[Point]) -> Optional[Point]: @@ -83,6 +85,7 @@ def hash_sha256(b: bytes) -> bytes: return hashlib.sha256(b).digest() def has_even_y(P: Point) -> bool: + assert not is_infinite(P) return y(P) % 2 == 0 def pubkey_gen(seckey: bytes) -> bytes: diff --git a/bip-0340/test-vectors.py b/bip-0340/test-vectors.py index e5b8847..d1bf6b2 100644 --- a/bip-0340/test-vectors.py +++ b/bip-0340/test-vectors.py @@ -6,7 +6,7 @@ def is_square(x): def has_square_y(P): """Determine if P has a square Y coordinate. Used in an earlier draft of BIP340.""" - assert not is_infinity(P) + assert not is_infinite(P) return is_square(P[1]) def vector0(): |