mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 22:38:08 +00:00
tools: fix small issues with keytool
This commit is contained in:
parent
e85ce3aea4
commit
4f11f46d07
@ -6,7 +6,7 @@ import pyblake2
|
|||||||
|
|
||||||
|
|
||||||
def hex(by):
|
def hex(by):
|
||||||
return str(binascii.hexlify(by), 'ascii')
|
return binascii.hexlify(by).decode()
|
||||||
|
|
||||||
|
|
||||||
def combine_keys(pks):
|
def combine_keys(pks):
|
||||||
@ -55,7 +55,7 @@ def compute_mask(combination, m, n):
|
|||||||
|
|
||||||
def createPubkey():
|
def createPubkey():
|
||||||
print('Enter randomness: ', end='')
|
print('Enter randomness: ', end='')
|
||||||
seckey = ed25519raw.H(input().encode('utf-8'))[0:32]
|
seckey = ed25519raw.H(input().encode())[0:32]
|
||||||
pubkey = ed25519raw.publickey(seckey)
|
pubkey = ed25519raw.publickey(seckey)
|
||||||
print('Secret Key: %s' % hex(seckey))
|
print('Secret Key: %s' % hex(seckey))
|
||||||
print('Public Key: %s' % hex(pubkey))
|
print('Public Key: %s' % hex(pubkey))
|
||||||
@ -63,7 +63,7 @@ def createPubkey():
|
|||||||
|
|
||||||
def combinePubkeys(m, n):
|
def combinePubkeys(m, n):
|
||||||
if binom(n, m) > 100:
|
if binom(n, m) > 100:
|
||||||
raise Exception("Too many keys")
|
raise Exception('Too many keys')
|
||||||
pks = []
|
pks = []
|
||||||
for i in range(0, n):
|
for i in range(0, n):
|
||||||
print('Enter pubkey %d: ' % i, end='')
|
print('Enter pubkey %d: ' % i, end='')
|
||||||
@ -91,7 +91,7 @@ def get_nonce(sk, data, ctr):
|
|||||||
a = 2 ** (b - 2) + sum(2 ** i * ed25519raw.bit(h, i) for i in range(3, b - 2))
|
a = 2 ** (b - 2) + sum(2 ** i * ed25519raw.bit(h, i) for i in range(3, b - 2))
|
||||||
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)
|
||||||
|
|
||||||
|
|
||||||
def phase1(data):
|
def phase1(data):
|
||||||
@ -101,7 +101,7 @@ def phase1(data):
|
|||||||
ctr = int(input())
|
ctr = int(input())
|
||||||
print('Enter privkey: ', end='')
|
print('Enter privkey: ', end='')
|
||||||
seckey = binascii.unhexlify(input())
|
seckey = binascii.unhexlify(input())
|
||||||
(_, R) = get_nonce(seckey, digest, ctr)
|
_, R = get_nonce(seckey, digest, ctr)
|
||||||
print('Local commit: %s' % hex(R))
|
print('Local commit: %s' % hex(R))
|
||||||
|
|
||||||
|
|
||||||
@ -202,9 +202,9 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
data = sys.argv[1].encode('utf-8')
|
data = sys.argv[1].encode()
|
||||||
N = 5
|
N = 3
|
||||||
keyset = [1, 3, 4]
|
keyset = [0, 2]
|
||||||
|
|
||||||
digest = pyblake2.blake2s(data).digest()
|
digest = pyblake2.blake2s(data).digest()
|
||||||
print('Digest: %s' % hex(digest))
|
print('Digest: %s' % hex(digest))
|
||||||
@ -215,7 +215,7 @@ def test():
|
|||||||
sigs = []
|
sigs = []
|
||||||
for i in range(0, N):
|
for i in range(0, N):
|
||||||
print('----- Key %d ------' % (i + 1))
|
print('----- Key %d ------' % (i + 1))
|
||||||
seckey = ed25519raw.H(("key%d" % (i + 1)).encode('utf-8'))[0:32]
|
seckey = bytes([0x41 + i]) * 32
|
||||||
pubkey = ed25519raw.publickey(seckey)
|
pubkey = ed25519raw.publickey(seckey)
|
||||||
print('Secret Key: %s' % hex(seckey))
|
print('Secret Key: %s' % hex(seckey))
|
||||||
print('Public Key: %s' % hex(pubkey))
|
print('Public Key: %s' % hex(pubkey))
|
||||||
@ -235,7 +235,7 @@ def test():
|
|||||||
print('Global commit: %s' % hex(globalR))
|
print('Global commit: %s' % hex(globalR))
|
||||||
print('-----------------')
|
print('-----------------')
|
||||||
|
|
||||||
for i in range(0, 5):
|
for i in range(0, N):
|
||||||
seckey = sks[i]
|
seckey = sks[i]
|
||||||
pubkey = pks[i]
|
pubkey = pks[i]
|
||||||
r = nonces[i]
|
r = nonces[i]
|
||||||
@ -250,7 +250,7 @@ def test():
|
|||||||
sigs.append(ed25519raw.encodeint(S))
|
sigs.append(ed25519raw.encodeint(S))
|
||||||
|
|
||||||
print('-----------------')
|
print('-----------------')
|
||||||
sig = combine_sig(globalR, [sigs[i] for i in [1, 3, 4]])
|
sig = combine_sig(globalR, [sigs[i] for i in keyset])
|
||||||
print('Global sig: %s' % hex(sig))
|
print('Global sig: %s' % hex(sig))
|
||||||
ed25519raw.checkvalid(sig, digest, globalPk)
|
ed25519raw.checkvalid(sig, digest, globalPk)
|
||||||
print('Valid Signature!')
|
print('Valid Signature!')
|
||||||
|
Loading…
Reference in New Issue
Block a user