From fd1718f8b6e2be3d80faa38860a803a20f453ced Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Sat, 8 Apr 2017 18:43:26 +0200 Subject: [PATCH] mocks: update build script, refresh --- mocks/trezor/config.py | 8 +-- mocks/trezor/crypto.py | 2 +- mocks/trezor/crypto/HDNode.py | 24 ++++----- mocks/trezor/crypto/aes/AES.py | 2 +- mocks/trezor/crypto/bip32.py | 4 +- mocks/trezor/crypto/bip39.py | 21 ++++++-- mocks/trezor/crypto/curve/curve25519.py | 6 +-- mocks/trezor/crypto/curve/ed25519.py | 26 ++++++++-- mocks/trezor/crypto/curve/nist256p1.py | 19 ++++--- mocks/trezor/crypto/curve/secp256k1.py | 19 ++++--- mocks/trezor/crypto/hashlib.py | 63 +++++++++++++----------- mocks/trezor/crypto/hashlib/blake2b.py | 12 +++++ mocks/trezor/crypto/hashlib/blake2s.py | 4 +- mocks/trezor/crypto/hashlib/ripemd160.py | 4 +- mocks/trezor/crypto/hashlib/sha1.py | 4 +- mocks/trezor/crypto/hashlib/sha256.py | 4 +- mocks/trezor/crypto/hashlib/sha3_256.py | 4 +- mocks/trezor/crypto/hashlib/sha3_512.py | 4 +- mocks/trezor/crypto/hashlib/sha512.py | 4 +- mocks/trezor/crypto/pbkdf2.py | 4 +- mocks/trezor/crypto/random.py | 6 +-- mocks/trezor/crypto/rfc6979.py | 6 +++ mocks/trezor/crypto/ssss.py | 4 +- mocks/trezor/debug.py | 2 +- mocks/trezor/msg.py | 8 +-- mocks/trezor/ui/display.py | 54 ++++++++++---------- mocks/trezor/utils.py | 8 ++- tools/build_mocks | 10 ++-- 28 files changed, 206 insertions(+), 130 deletions(-) create mode 100644 mocks/trezor/crypto/hashlib/blake2b.py create mode 100644 mocks/trezor/crypto/rfc6979.py diff --git a/mocks/trezor/config.py b/mocks/trezor/config.py index 6e1466de..717e96a1 100644 --- a/mocks/trezor/config.py +++ b/mocks/trezor/config.py @@ -1,18 +1,18 @@ -# ../extmod/modtrezorconfig/modtrezorconfig.c +# extmod/modtrezorconfig/modtrezorconfig.c def get(app: int, key: int) -> bytes: ''' - Gets a value of given key for given app (or None if not set). + Gets a value of given key for given app (or empty bytes if not set). ''' -# ../extmod/modtrezorconfig/modtrezorconfig.c +# extmod/modtrezorconfig/modtrezorconfig.c def set(app: int, key: int, value: bytes) -> None: ''' Sets a value of given key for given app. Returns True on success. ''' -# ../extmod/modtrezorconfig/modtrezorconfig.c +# extmod/modtrezorconfig/modtrezorconfig.c def wipe() -> None: ''' Erases the whole config (use with caution!) diff --git a/mocks/trezor/crypto.py b/mocks/trezor/crypto.py index 5b2854be..58672b8b 100644 --- a/mocks/trezor/crypto.py +++ b/mocks/trezor/crypto.py @@ -1,5 +1,5 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h +# extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h def pbkdf2(prf: str, password: bytes, salt: bytes, iterations: int=None) -> Pbkdf2: ''' Create a PBKDF2 context diff --git a/mocks/trezor/crypto/HDNode.py b/mocks/trezor/crypto/HDNode.py index 98f85396..72d517a4 100644 --- a/mocks/trezor/crypto/HDNode.py +++ b/mocks/trezor/crypto/HDNode.py @@ -1,71 +1,71 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h def derive(index: int) -> None: ''' Derive a BIP0032 child node in place. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h def derive_path(path: list) -> None: ''' Go through a list of indexes and iteratively derive a child node in place. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h def serialize_public() -> str: ''' Serialize the public info from HD node to base58 string. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h def serialize_private() -> str: ''' Serialize the private info HD node to base58 string. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h def clone() -> HDNode: ''' Returns a copy of the HD node. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h def depth() -> int: ''' Returns a depth of the HD node. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h def fingerprint() -> int: ''' Returns a fingerprint of the HD node (hash of the parent public key). ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h def child_num() -> int: ''' Returns a child index of the HD node. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h def chain_code() -> bytes: ''' Returns a chain code of the HD node. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h def private_key() -> bytes: ''' Returns a private key of the HD node. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h def public_key() -> bytes: ''' Returns a public key of the HD node. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h def address(version: int) -> str: ''' Compute a base58-encoded address string from the HD node. diff --git a/mocks/trezor/crypto/aes/AES.py b/mocks/trezor/crypto/aes/AES.py index 163c28d2..4372f654 100644 --- a/mocks/trezor/crypto/aes/AES.py +++ b/mocks/trezor/crypto/aes/AES.py @@ -1,5 +1,5 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-aes.h +# extmod/modtrezorcrypto/modtrezorcrypto-aes.h def update(self, data: bytes) -> bytes: ''' Update AES context diff --git a/mocks/trezor/crypto/bip32.py b/mocks/trezor/crypto/bip32.py index 9f09cad7..4eb2a5ca 100644 --- a/mocks/trezor/crypto/bip32.py +++ b/mocks/trezor/crypto/bip32.py @@ -1,11 +1,11 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h def deserialize(value: str) -> HDNode: ''' Construct a BIP0032 HD node from a base58-serialized value. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h def from_seed(seed: bytes, curve_name: str) -> HDNode: ''' Construct a BIP0032 HD node from a BIP0039 seed value. diff --git a/mocks/trezor/crypto/bip39.py b/mocks/trezor/crypto/bip39.py index 9a63bdb8..14bca3bc 100644 --- a/mocks/trezor/crypto/bip39.py +++ b/mocks/trezor/crypto/bip39.py @@ -1,23 +1,36 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-bip39.h +# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h +def find_word(prefix: str) -> str: + ''' + Return the first word from the wordlist starting with prefix + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h +def complete_word(prefix: str) -> int: + ''' + Return possible 1-letter suffixes for given word prefix + Result is a bitmask, with 'a' on the lowest bit, 'b' on the second lowest, etc. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h def generate(strength: int) -> str: ''' Generate a mnemonic of given strength (128, 160, 192, 224 and 256 bits) ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-bip39.h +# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h def from_data(data: bytes) -> str: ''' Generate a mnemonic from given data (of 16, 20, 24, 28 and 32 bytes) ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-bip39.h +# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h def check(mnemonic: str) -> bool: ''' Check whether given mnemonic is valid ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-bip39.h +# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h def seed(mnemonic: str, passphrase: str) -> bytes: ''' Generate seed from mnemonic and passphrase diff --git a/mocks/trezor/crypto/curve/curve25519.py b/mocks/trezor/crypto/curve/curve25519.py index 0c77b988..344089c9 100644 --- a/mocks/trezor/crypto/curve/curve25519.py +++ b/mocks/trezor/crypto/curve/curve25519.py @@ -1,17 +1,17 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h +# extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h def generate_secret() -> bytes: ''' Generate secret key. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h +# extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h def publickey(secret_key: bytes) -> bytes: ''' Computes public key from secret key. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h +# extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h def multiply(secret_key: bytes, public_key: bytes) -> bytes: ''' Multiplies point defined by public_key with scalar defined by secret_key diff --git a/mocks/trezor/crypto/curve/ed25519.py b/mocks/trezor/crypto/curve/ed25519.py index 4896ecf0..944a5e02 100644 --- a/mocks/trezor/crypto/curve/ed25519.py +++ b/mocks/trezor/crypto/curve/ed25519.py @@ -1,25 +1,43 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h +# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h def generate_secret() -> bytes: ''' Generate secret key. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h +# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h def publickey(secret_key: bytes) -> bytes: ''' Computes public key from secret key. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h +# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h def sign(secret_key: bytes, message: bytes) -> bytes: ''' Uses secret key to produce the signature of message. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h +# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h def verify(public_key: bytes, signature: bytes, message: bytes) -> bool: ''' Uses public key to verify the signature of the message. Returns True on success. ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h +def cosi_combine_publickeys(public_keys: list) -> bytes: + ''' + Combines a list of public keys used in COSI cosigning scheme + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h +def cosi_combine_signatures(R: bytes, signatures: list) -> bytes: + ''' + Combines a list of signatures used in COSI cosigning scheme + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h +def cosi_sign(secret_key: bytes, message: bytes, nonce: bytes, sigR: bytes, combined_pubkey: bytes) -> bytes: + ''' + Produce signature of message using COSI cosigning scheme + ''' diff --git a/mocks/trezor/crypto/curve/nist256p1.py b/mocks/trezor/crypto/curve/nist256p1.py index 0375e2c2..41d5bfae 100644 --- a/mocks/trezor/crypto/curve/nist256p1.py +++ b/mocks/trezor/crypto/curve/nist256p1.py @@ -1,30 +1,37 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h +# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h def generate_secret() -> bytes: ''' Generate secret key. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h +# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h def publickey(secret_key: bytes, compressed: bool=True) -> bytes: ''' Computes public key from secret key. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h -def sign(secret_key: bytes, digest: bytes) -> bytes: +# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h +def sign(secret_key: bytes, digest: bytes, compressed: bool=True) -> bytes: ''' Uses secret key to produce the signature of the digest. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h +# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h def verify(public_key: bytes, signature: bytes, digest: bytes) -> bool: ''' Uses public key to verify the signature of the digest. Returns True on success. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h +# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h +def verify_recover(signature: bytes, digest: bytes) -> bytes: + ''' + Uses signature of the digest to verify the digest and recover the public key. + Returns public key on success, None on failure. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h def multiply(secret_key: bytes, public_key: bytes) -> bytes: ''' Multiplies point defined by public_key with scalar defined by secret_key diff --git a/mocks/trezor/crypto/curve/secp256k1.py b/mocks/trezor/crypto/curve/secp256k1.py index 1b9681b6..2416392f 100644 --- a/mocks/trezor/crypto/curve/secp256k1.py +++ b/mocks/trezor/crypto/curve/secp256k1.py @@ -1,30 +1,37 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h +# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h def generate_secret() -> bytes: ''' Generate secret key. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h +# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h def publickey(secret_key: bytes, compressed: bool=True) -> bytes: ''' Computes public key from secret key. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h -def sign(secret_key: bytes, digest: bytes) -> bytes: +# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h +def sign(secret_key: bytes, digest: bytes, compressed: bool=True) -> bytes: ''' Uses secret key to produce the signature of the digest. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h +# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h def verify(public_key: bytes, signature: bytes, digest: bytes) -> bool: ''' Uses public key to verify the signature of the digest. Returns True on success. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h +# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h +def verify_recover(signature: bytes, digest: bytes) -> bytes: + ''' + Uses signature of the digest to verify the digest and recover the public key. + Returns public key on success, None on failure. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h def multiply(secret_key: bytes, public_key: bytes) -> bytes: ''' Multiplies point defined by public_key with scalar defined by secret_key diff --git a/mocks/trezor/crypto/hashlib.py b/mocks/trezor/crypto/hashlib.py index 11a6bc97..b86b6887 100644 --- a/mocks/trezor/crypto/hashlib.py +++ b/mocks/trezor/crypto/hashlib.py @@ -1,41 +1,48 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h -def blake2s(data: bytes=None, key: bytes=None) -> Blake2s: + +# extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h +def blake2b(data: bytes=None, key: bytes=None) -> Blake2b: ''' Creates a hash context object. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-sha1.h -def sha1(data: bytes=None) -> Sha1: - ''' - Creates a hash context object. - ''' - -# ../extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h -def ripemd160(data: bytes=None) -> Ripemd160: - ''' - Creates a hash context object. - ''' - -# ../extmod/modtrezorcrypto/modtrezorcrypto-sha256.h -def sha256(data: bytes=None) -> Sha256: - ''' - Creates a hash context object. - ''' - -# ../extmod/modtrezorcrypto/modtrezorcrypto-sha512.h -def sha512(data: bytes=None) -> Sha512: - ''' - Creates a hash context object. - ''' - -# ../extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h +# extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h def sha3_256(data: bytes=None) -> Sha3_256: ''' Creates a hash context object. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h +# extmod/modtrezorcrypto/modtrezorcrypto-sha512.h +def sha512(data: bytes=None) -> Sha512: + ''' + Creates a hash context object. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-sha256.h +def sha256(data: bytes=None) -> Sha256: + ''' + Creates a hash context object. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h +def ripemd160(data: bytes=None) -> Ripemd160: + ''' + Creates a hash context object. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h def sha3_512(data: bytes=None) -> Sha3_512: ''' Creates a hash context object. ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-sha1.h +def sha1(data: bytes=None) -> Sha1: + ''' + Creates a hash context object. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h +def blake2s(data: bytes=None, key: bytes=None) -> Blake2s: + ''' + Creates a hash context object. + ''' diff --git a/mocks/trezor/crypto/hashlib/blake2b.py b/mocks/trezor/crypto/hashlib/blake2b.py new file mode 100644 index 00000000..bbb0314c --- /dev/null +++ b/mocks/trezor/crypto/hashlib/blake2b.py @@ -0,0 +1,12 @@ + +# extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h +def update(self, data: bytes) -> None: + ''' + Update the hash context with hashed data. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h +def digest(self) -> bytes: + ''' + Returns the digest of hashed data. + ''' diff --git a/mocks/trezor/crypto/hashlib/blake2s.py b/mocks/trezor/crypto/hashlib/blake2s.py index 61ad7bdb..161c92cb 100644 --- a/mocks/trezor/crypto/hashlib/blake2s.py +++ b/mocks/trezor/crypto/hashlib/blake2s.py @@ -1,11 +1,11 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h +# extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h def update(self, data: bytes) -> None: ''' Update the hash context with hashed data. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h +# extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h def digest(self) -> bytes: ''' Returns the digest of hashed data. diff --git a/mocks/trezor/crypto/hashlib/ripemd160.py b/mocks/trezor/crypto/hashlib/ripemd160.py index 6c3b7a48..b7f4ebec 100644 --- a/mocks/trezor/crypto/hashlib/ripemd160.py +++ b/mocks/trezor/crypto/hashlib/ripemd160.py @@ -1,11 +1,11 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h +# extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h def update(self, data: bytes) -> None: ''' Update the hash context with hashed data. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h +# extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h def digest(self) -> bytes: ''' Returns the digest of hashed data. diff --git a/mocks/trezor/crypto/hashlib/sha1.py b/mocks/trezor/crypto/hashlib/sha1.py index a20e9043..fd9b0ab1 100644 --- a/mocks/trezor/crypto/hashlib/sha1.py +++ b/mocks/trezor/crypto/hashlib/sha1.py @@ -1,11 +1,11 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-sha1.h +# extmod/modtrezorcrypto/modtrezorcrypto-sha1.h def update(self, data: bytes) -> None: ''' Update the hash context with hashed data. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-sha1.h +# extmod/modtrezorcrypto/modtrezorcrypto-sha1.h def digest(self) -> bytes: ''' Returns the digest of hashed data. diff --git a/mocks/trezor/crypto/hashlib/sha256.py b/mocks/trezor/crypto/hashlib/sha256.py index af1cd862..a81545fc 100644 --- a/mocks/trezor/crypto/hashlib/sha256.py +++ b/mocks/trezor/crypto/hashlib/sha256.py @@ -1,11 +1,11 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-sha256.h +# extmod/modtrezorcrypto/modtrezorcrypto-sha256.h def update(self, data: bytes) -> None: ''' Update the hash context with hashed data. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-sha256.h +# extmod/modtrezorcrypto/modtrezorcrypto-sha256.h def digest(self) -> bytes: ''' Returns the digest of hashed data. diff --git a/mocks/trezor/crypto/hashlib/sha3_256.py b/mocks/trezor/crypto/hashlib/sha3_256.py index b09a5bd2..f9a579c9 100644 --- a/mocks/trezor/crypto/hashlib/sha3_256.py +++ b/mocks/trezor/crypto/hashlib/sha3_256.py @@ -1,11 +1,11 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h +# extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h def update(self, data: bytes) -> None: ''' Update the hash context with hashed data. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h +# extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h def digest(self, keccak: bool=False) -> bytes: ''' Returns the digest of hashed data. diff --git a/mocks/trezor/crypto/hashlib/sha3_512.py b/mocks/trezor/crypto/hashlib/sha3_512.py index aa6f048e..dcd41490 100644 --- a/mocks/trezor/crypto/hashlib/sha3_512.py +++ b/mocks/trezor/crypto/hashlib/sha3_512.py @@ -1,11 +1,11 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h +# extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h def update(self, data: bytes) -> None: ''' Update the hash context with hashed data. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h +# extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h def digest(self, keccak: bool=False) -> bytes: ''' Returns the digest of hashed data. diff --git a/mocks/trezor/crypto/hashlib/sha512.py b/mocks/trezor/crypto/hashlib/sha512.py index 2343620b..b54c99fc 100644 --- a/mocks/trezor/crypto/hashlib/sha512.py +++ b/mocks/trezor/crypto/hashlib/sha512.py @@ -1,11 +1,11 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-sha512.h +# extmod/modtrezorcrypto/modtrezorcrypto-sha512.h def hash(self, data: bytes) -> None: ''' Update the hash context with hashed data. ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-sha512.h +# extmod/modtrezorcrypto/modtrezorcrypto-sha512.h def digest(self) -> bytes: ''' Returns the digest of hashed data. diff --git a/mocks/trezor/crypto/pbkdf2.py b/mocks/trezor/crypto/pbkdf2.py index c110ec8f..23e9b014 100644 --- a/mocks/trezor/crypto/pbkdf2.py +++ b/mocks/trezor/crypto/pbkdf2.py @@ -1,11 +1,11 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h +# extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h def update(self, iterations: int) -> None: ''' Update a PBKDF2 context ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h +# extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h def key(self) -> bytes: ''' Retreive derived key diff --git a/mocks/trezor/crypto/random.py b/mocks/trezor/crypto/random.py index f6a05e08..0fc9ed05 100644 --- a/mocks/trezor/crypto/random.py +++ b/mocks/trezor/crypto/random.py @@ -1,17 +1,17 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-random.h +# extmod/modtrezorcrypto/modtrezorcrypto-random.h def uniform(n: int) -> int: ''' Compute uniform random number from interval 0 ... n - 1 ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-random.h +# extmod/modtrezorcrypto/modtrezorcrypto-random.h def bytes(len: int) -> bytes: ''' Generate random bytes sequence of length len ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-random.h +# extmod/modtrezorcrypto/modtrezorcrypto-random.h def shuffle(data: list) -> None: ''' Shuffles items of given list (in-place) diff --git a/mocks/trezor/crypto/rfc6979.py b/mocks/trezor/crypto/rfc6979.py new file mode 100644 index 00000000..baf6f8a5 --- /dev/null +++ b/mocks/trezor/crypto/rfc6979.py @@ -0,0 +1,6 @@ + +# extmod/modtrezorcrypto/modtrezorcrypto-rfc6979.h +def next() -> bytes: + ''' + Compute next 32-bytes of pseudorandom data + ''' diff --git a/mocks/trezor/crypto/ssss.py b/mocks/trezor/crypto/ssss.py index 8870e8a6..79912199 100644 --- a/mocks/trezor/crypto/ssss.py +++ b/mocks/trezor/crypto/ssss.py @@ -1,11 +1,11 @@ -# ../extmod/modtrezorcrypto/modtrezorcrypto-ssss.h +# extmod/modtrezorcrypto/modtrezorcrypto-ssss.h def split(m: int, n: int, secret: bytes) -> tuple: ''' Split secret to (M of N) shares using Shamir's Secret Sharing Scheme ''' -# ../extmod/modtrezorcrypto/modtrezorcrypto-ssss.h +# extmod/modtrezorcrypto/modtrezorcrypto-ssss.h def combine(shares: tuple) -> bytes: ''' Combine M shares of Shamir's Secret Sharing Scheme into secret diff --git a/mocks/trezor/debug.py b/mocks/trezor/debug.py index ef3ef38b..2898ed8b 100644 --- a/mocks/trezor/debug.py +++ b/mocks/trezor/debug.py @@ -1,5 +1,5 @@ -# ../extmod/modtrezordebug/modtrezordebug.c +# extmod/modtrezordebug/modtrezordebug.c def memaccess(address: int, length: int) -> bytes: ''' Creates a bytes object that can be used to access certain memory location. diff --git a/mocks/trezor/msg.py b/mocks/trezor/msg.py index 251fb33e..7e20f131 100644 --- a/mocks/trezor/msg.py +++ b/mocks/trezor/msg.py @@ -1,23 +1,23 @@ -# ../extmod/modtrezormsg/modtrezormsg.c +# extmod/modtrezormsg/modtrezormsg.c def set_interfaces(ifaces: list/tuple) -> None: ''' Configures USB interfaces with a list/tuple of (usage_page, ...) ''' -# ../extmod/modtrezormsg/modtrezormsg.c +# extmod/modtrezormsg/modtrezormsg.c def get_interfaces() -> tuple: ''' Reads a tuple (of usage pages) of configured USB interfaces ''' -# ../extmod/modtrezormsg/modtrezormsg.c +# extmod/modtrezormsg/modtrezormsg.c def send(usage_page: int, message: bytes) -> int: ''' Sends message using USB HID (device) or UDP (emulator). ''' -# ../extmod/modtrezormsg/modtrezormsg.c +# extmod/modtrezormsg/modtrezormsg.c def select(timeout_us: int) -> tuple: ''' Polls the event queue and returns the event object. diff --git a/mocks/trezor/ui/display.py b/mocks/trezor/ui/display.py index 3a18bd10..996c477d 100644 --- a/mocks/trezor/ui/display.py +++ b/mocks/trezor/ui/display.py @@ -1,78 +1,84 @@ -# ../extmod/modtrezorui/modtrezorui-display.h +# extmod/modtrezorui/modtrezorui-display.h def clear() -> None ''' Clear display (with black color) ''' -# ../extmod/modtrezorui/modtrezorui-display.h +# extmod/modtrezorui/modtrezorui-display.h def refresh() -> None ''' Refresh display (update screen) ''' -# ../extmod/modtrezorui/modtrezorui-display.h +# extmod/modtrezorui/modtrezorui-display.h def bar(x: int, y: int, w: int, h: int, color: int) -> None: ''' Renders a bar at position (x,y = upper left corner) with width w and height h of color color. ''' -# ../extmod/modtrezorui/modtrezorui-display.h +# extmod/modtrezorui/modtrezorui-display.h def bar_radius(x: int, y: int, w: int, h: int, fgcolor: int, bgcolor: int=None, radius: int=None) -> None: ''' Renders a rounded bar at position (x,y = upper left corner) with width w and height h of color fgcolor. Background is set to bgcolor and corners are drawn with radius radius. ''' -# ../extmod/modtrezorui/modtrezorui-display.h +# extmod/modtrezorui/modtrezorui-display.h def image(x: int, y: int, image: bytes) -> None: ''' Renders an image at position (x,y). The image needs to be in TREZOR Optimized Image Format (TOIF) - full-color mode. ''' -# ../extmod/modtrezorui/modtrezorui-display.h +# extmod/modtrezorui/modtrezorui-display.h def icon(x: int, y: int, icon: bytes, fgcolor: int, bgcolor: int) -> None: ''' Renders an icon at position (x,y), fgcolor is used as foreground color, bgcolor as background. The image needs to be in TREZOR Optimized Image Format (TOIF) - gray-scale mode. ''' -# ../extmod/modtrezorui/modtrezorui-display.h -def text(x: int, y: int, text: bytes, font: int, fgcolor: int, bgcolor: int) -> None: +# extmod/modtrezorui/modtrezorui-display.h +def print(text: str, fgcolor: int, bgcolor: int) -> None: + ''' + Renders text using 5x8 bitmap font (using special text mode) + ''' + +# extmod/modtrezorui/modtrezorui-display.h +def text(x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int) -> None: ''' Renders left-aligned text at position (x,y) where x is left position and y is baseline. Font font is used for rendering, fgcolor is used as foreground color, bgcolor as background. ''' -# ../extmod/modtrezorui/modtrezorui-display.h -def text_center(x: int, y: int, text: bytes, font: int, fgcolor: int, bgcolor: int) -> None: +# extmod/modtrezorui/modtrezorui-display.h +def text_center(x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int) -> None: ''' Renders text centered at position (x,y) where x is text center and y is baseline. Font font is used for rendering, fgcolor is used as foreground color, bgcolor as background. ''' -# ../extmod/modtrezorui/modtrezorui-display.h -def text_right(x: int, y: int, text: bytes, font: int, fgcolor: int, bgcolor: int) -> None: +# extmod/modtrezorui/modtrezorui-display.h +def text_right(x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int) -> None: ''' Renders right-aligned text at position (x,y) where x is right position and y is baseline. Font font is used for rendering, fgcolor is used as foreground color, bgcolor as background. ''' -# ../extmod/modtrezorui/modtrezorui-display.h -def text_width(text: bytes, font: int) -> int: +# extmod/modtrezorui/modtrezorui-display.h +def text_width(text: str, font: int) -> int: ''' Returns a width of text in pixels. Font font is used for rendering. ''' -# ../extmod/modtrezorui/modtrezorui-display.h +# extmod/modtrezorui/modtrezorui-display.h def qrcode(x: int, y: int, data: bytes, scale: int) -> None: ''' - Renders data encoded as a QR code at position (x,y). + Renders data encoded as a QR code centered at position (x,y). Scale determines a zoom factor. ''' -# ../extmod/modtrezorui/modtrezorui-display.h +# extmod/modtrezorui/modtrezorui-display.h def loader(progress: int, yoffset: int, fgcolor: int, bgcolor: int, icon: bytes=None, iconfgcolor: int=None) -> None: ''' Renders a rotating loader graphic. @@ -81,7 +87,7 @@ def loader(progress: int, yoffset: int, fgcolor: int, bgcolor: int, icon: bytes= Icon needs to be of exactly LOADER_ICON_SIZE x LOADER_ICON_SIZE pixels size. ''' -# ../extmod/modtrezorui/modtrezorui-display.h +# extmod/modtrezorui/modtrezorui-display.h def orientation(degrees: int=None) -> int: ''' Sets display orientation to 0, 90, 180 or 270 degrees. @@ -89,27 +95,21 @@ def orientation(degrees: int=None) -> int: Call without the degrees parameter to just perform the read of the value. ''' -# ../extmod/modtrezorui/modtrezorui-display.h +# extmod/modtrezorui/modtrezorui-display.h def backlight(val: int=None) -> int: ''' Sets backlight intensity to the value specified in val. Call without the val parameter to just perform the read of the value. ''' -# ../extmod/modtrezorui/modtrezorui-display.h +# extmod/modtrezorui/modtrezorui-display.h def offset(xy: tuple=None) -> tuple: ''' Sets offset (x, y) for all subsequent drawing calls. Call without the xy parameter to just perform the read of the value. ''' -# ../extmod/modtrezorui/modtrezorui-display.h -def raw(reg: int, data: bytes=None) -> None: - ''' - Performs a raw command on the display. Read the datasheet to learn more. - ''' - -# ../extmod/modtrezorui/modtrezorui-display.h +# extmod/modtrezorui/modtrezorui-display.h def save(filename: string) -> None: ''' Saves current display contents to file filename. diff --git a/mocks/trezor/utils.py b/mocks/trezor/utils.py index 211a3b36..f979751b 100644 --- a/mocks/trezor/utils.py +++ b/mocks/trezor/utils.py @@ -1,5 +1,5 @@ -# ../extmod/modtrezorutils/modtrezorutils.c +# extmod/modtrezorutils/modtrezorutils.c def memcpy(dst: bytearray, dst_ofs: int, src: bytearray, src_ofs: int, ''' @@ -7,3 +7,9 @@ def memcpy(dst: bytearray, dst_ofs: int, `dst` at offset `dst_ofs`. Returns the number of actually copied bytes. ''' + +# extmod/modtrezorutils/modtrezorutils.c +def halt(msg: str=None) -> None: + ''' + Halts execution + ''' diff --git a/tools/build_mocks b/tools/build_mocks index 15dd1c6b..f0c5ddf5 100755 --- a/tools/build_mocks +++ b/tools/build_mocks @@ -6,7 +6,7 @@ COMMENT_PREFIX = '/// ' current_method = None current_package = None -def split_to_parts(line, mod_file=None): +def split_to_parts(line, mod_desc=None): global current_method global current_package # Line is beginning of method @@ -18,7 +18,7 @@ def split_to_parts(line, mod_file=None): *current_package, method_name = current_method.split('.') yield (current_package, "\n") - yield (current_package, '# ' + mod_file + "\n") + yield (current_package, '# ' + mod_desc + "\n") line = line.replace(current_method, method_name) yield (current_package, line) @@ -46,13 +46,13 @@ def build_module(mod_file, dest): if not (mod_file.endswith('.h') or mod_file.endswith('.c')): return - #print(mod_file) + mod_desc = mod_file.replace('../micropython/extmod', 'extmod') for l in open(mod_file): if not l.startswith(COMMENT_PREFIX): continue l = l[len(COMMENT_PREFIX):]#.strip() - store_to_file(dest, split_to_parts(l, mod_file)) + store_to_file(dest, split_to_parts(l, mod_desc)) def build_directory(dir, dest): print("Building mocks for", dir, "to", dest) @@ -80,4 +80,4 @@ def clear_directory(top_dir): if __name__ == '__main__': clear_directory('../mocks') - build_directory('../extmod', '../mocks') + build_directory('../micropython/extmod', '../mocks')