From c1b1bedb8c51f20d9d7b415217a29ea0e5336fa6 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 18 Dec 2017 22:33:55 +0100 Subject: [PATCH] ed25519: remove py2/py3 handling in ed25519 funcs as well --- trezorlib/ed25519cosi.py | 5 +---- trezorlib/ed25519raw.py | 15 +++------------ 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/trezorlib/ed25519cosi.py b/trezorlib/ed25519cosi.py index 01316e5d61..530718a109 100644 --- a/trezorlib/ed25519cosi.py +++ b/trezorlib/ed25519cosi.py @@ -21,10 +21,7 @@ def combine_sig(R, sigs): def get_nonce(sk, data, ctr): h = ed25519raw.H(sk) b = ed25519raw.b - if sys.version_info.major < 3: - r = ed25519raw.Hint(''.join([h[i] for i in range(b >> 3, b >> 2)]) + data + binascii.unhexlify('%08x' % ctr)) - else: - r = ed25519raw.Hint(bytes([h[i] for i in range(b >> 3, b >> 2)]) + data + binascii.unhexlify('%08x' % ctr)) + r = ed25519raw.Hint(bytes([h[i] for i in range(b >> 3, b >> 2)]) + data + binascii.unhexlify('%08x' % ctr)) R = ed25519raw.scalarmult(ed25519raw.B, r) return r, ed25519raw.encodepoint(R) diff --git a/trezorlib/ed25519raw.py b/trezorlib/ed25519raw.py index 2dcee91663..81476396e9 100644 --- a/trezorlib/ed25519raw.py +++ b/trezorlib/ed25519raw.py @@ -69,27 +69,18 @@ def scalarmult(P, e): def encodeint(y): bits = [(y >> i) & 1 for i in range(b)] - if sys.version_info.major < 3: - return ''.join([chr(sum([bits[i * 8 + j] << j for j in range(8)])) for i in range(b >> 3)]) - else: - return bytes([sum([bits[i * 8 + j] << j for j in range(8)]) for i in range(b >> 3)]) + return bytes([sum([bits[i * 8 + j] << j for j in range(8)]) for i in range(b >> 3)]) def encodepoint(P): x = P[0] y = P[1] bits = [(y >> i) & 1 for i in range(b - 1)] + [x & 1] - if sys.version_info.major < 3: - return ''.join([chr(sum([bits[i * 8 + j] << j for j in range(8)])) for i in range(b >> 3)]) - else: - return bytes([sum([bits[i * 8 + j] << j for j in range(8)]) for i in range(b >> 3)]) + return bytes([sum([bits[i * 8 + j] << j for j in range(8)]) for i in range(b >> 3)]) def bit(h, i): - if sys.version_info.major < 3: - return (ord(h[i >> 3]) >> (i & 7)) & 1 - else: - return (h[i >> 3] >> (i & 7)) & 1 + return (h[i >> 3] >> (i & 7)) & 1 def publickey(sk):