mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-16 02:10:55 +00:00
ed25519: remove py2/py3 handling in ed25519 funcs as well
This commit is contained in:
parent
a9291e89c5
commit
c1b1bedb8c
@ -21,9 +21,6 @@ def combine_sig(R, sigs):
|
|||||||
def get_nonce(sk, data, ctr):
|
def get_nonce(sk, data, ctr):
|
||||||
h = ed25519raw.H(sk)
|
h = ed25519raw.H(sk)
|
||||||
b = ed25519raw.b
|
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)
|
R = ed25519raw.scalarmult(ed25519raw.B, r)
|
||||||
return r, ed25519raw.encodepoint(R)
|
return r, ed25519raw.encodepoint(R)
|
||||||
|
@ -69,9 +69,6 @@ def scalarmult(P, e):
|
|||||||
|
|
||||||
def encodeint(y):
|
def encodeint(y):
|
||||||
bits = [(y >> i) & 1 for i in range(b)]
|
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)])
|
||||||
|
|
||||||
|
|
||||||
@ -79,16 +76,10 @@ def encodepoint(P):
|
|||||||
x = P[0]
|
x = P[0]
|
||||||
y = P[1]
|
y = P[1]
|
||||||
bits = [(y >> i) & 1 for i in range(b - 1)] + [x & 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):
|
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
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user