tests: create tests.support module

for things that should not be part of trezorlib but tests use them
pull/25/head
matejcik 7 years ago
parent a289d16838
commit 603b201ad0

@ -27,8 +27,8 @@ from ecdsa.util import string_to_number, number_to_string
from ecdsa.curves import SECP256k1 from ecdsa.curves import SECP256k1
from ecdsa.ellipticcurve import Point, INFINITY from ecdsa.ellipticcurve import Point, INFINITY
from . import tools from trezorlib import tools
from . import messages as proto from trezorlib import messages
PRIME_DERIVATION_FLAG = 0x80000000 PRIME_DERIVATION_FLAG = 0x80000000
@ -76,7 +76,7 @@ def public_ckd(public_node, n):
if not isinstance(n, list): if not isinstance(n, list):
raise ValueError('Parameter must be a list') raise ValueError('Parameter must be a list')
node = proto.HDNodeType() node = messages.HDNodeType()
node.CopyFrom(public_node) node.CopyFrom(public_node)
for i in n: for i in n:
@ -98,7 +98,7 @@ def get_subnode(node, i):
I64 = hmac.HMAC(key=node.chain_code, msg=data, digestmod=hashlib.sha512).digest() I64 = hmac.HMAC(key=node.chain_code, msg=data, digestmod=hashlib.sha512).digest()
I_left_as_exponent = string_to_number(I64[:32]) I_left_as_exponent = string_to_number(I64[:32])
node_out = proto.HDNodeType() node_out = messages.HDNodeType()
node_out.depth = node.depth + 1 node_out.depth = node.depth + 1
node_out.child_num = i node_out.child_num = i
node_out.chain_code = I64[32:] node_out.chain_code = I64[32:]
@ -138,7 +138,7 @@ def deserialize(xpub):
if tools.Hash(data[:-4])[:4] != data[-4:]: if tools.Hash(data[:-4])[:4] != data[-4:]:
raise ValueError("Checksum failed") raise ValueError("Checksum failed")
node = proto.HDNodeType() node = messages.HDNodeType()
node.depth = struct.unpack('>B', data[4:5])[0] node.depth = struct.unpack('>B', data[4:5])[0]
node.fingerprint = struct.unpack('>I', data[5:9])[0] node.fingerprint = struct.unpack('>I', data[5:9])[0]
node.child_num = struct.unpack('>I', data[9:13])[0] node.child_num = struct.unpack('>I', data[9:13])[0]

@ -70,7 +70,7 @@ def self_test(digest):
R = commits[i] R = commits[i]
h = ed25519raw.H(seckey) h = ed25519raw.H(seckey)
b = ed25519raw.b b = ed25519raw.b
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))
S = (r + ed25519raw.Hint(global_R + global_pk + digest) * a) % ed25519raw.l S = (r + ed25519raw.Hint(global_R + global_pk + digest) * a) % ed25519raw.l
print('Local sig %d: %s' % (i + 1, to_hex(ed25519raw.encodeint(S)))) print('Local sig %d: %s' % (i + 1, to_hex(ed25519raw.encodeint(S))))
sigs.append(ed25519raw.encodeint(S)) sigs.append(ed25519raw.encodeint(S))

@ -1,7 +1,6 @@
# orignal version downloaded from https://ed25519.cr.yp.to/python/ed25519.py # orignal version downloaded from https://ed25519.cr.yp.to/python/ed25519.py
# modified for Python 3 by Jochen Hoenicke <hoenicke@gmail.com> # modified for Python 3 by Jochen Hoenicke <hoenicke@gmail.com>
import sys
import hashlib import hashlib
b = 256 b = 256
Loading…
Cancel
Save