build: fix and auto-generate mock files

Squashed commit of the following:

commit 84d3486f59bda063f06521c8b695ea4b07781ec6
Author: matejcik <ja@matejcik.cz>
Date:   Fri May 17 14:17:15 2019 +0200

    mocks: complete

commit d538133a6d0fb4af06c7c81f80b8675869fb5908
Author: matejcik <ja@matejcik.cz>
Date:   Fri May 17 14:12:26 2019 +0200

    mocks part 3

commit 9f0b868d41dafaf487df6fc844db7f3368eabe1b
Author: matejcik <ja@matejcik.cz>
Date:   Fri May 17 14:09:20 2019 +0200

    mocks: update generated mocks

commit 5d80c18a7824ed16fc11cde4cdb8ebca7ed33400
Author: matejcik <ja@matejcik.cz>
Date:   Thu May 16 15:49:40 2019 +0200

    mocks wip 2

commit 4b576eb796136a61eb88cb0d281fa4e21eadada8
Author: matejcik <ja@matejcik.cz>
Date:   Tue May 7 17:02:51 2019 +0200

    WIP mocks part 1

commit cf3f0d4471ab74b478d2970b0bb178feae7c86a3
Author: matejcik <ja@matejcik.cz>
Date:   Fri May 3 17:07:53 2019 +0200

    core: add package to secp256k1_zkp for mocking

commit 8a12f26c8c0d99363c8df96012426abbbb3ff6cb
Author: matejcik <ja@matejcik.cz>
Date:   Fri May 3 17:04:05 2019 +0200

    core: blackify extmod docstring quotes

commit b6f239676dde8b60b001fcae4e5de80a71dbacf2
Author: matejcik <ja@matejcik.cz>
Date:   Fri May 3 16:52:27 2019 +0200

    core: make build_mocks directory agnostic

mocks: detect bad packages

mocks: revert noqa in favor of setup.cfg

mocks: fix broken comment formatting
pull/160/head
matejcik 5 years ago
parent ffcb5e99cc
commit 482b4569f5

@ -47,11 +47,11 @@ STATIC secbool wrapped_ui_wait_callback(uint32_t wait, uint32_t progress,
return secfalse; return secfalse;
} }
/// def init(ui_wait_callback: (int, int -> None)=None) -> None: /// def init(ui_wait_callback: Tuple[int, Callable[int, None]] = None) -> None:
/// ''' /// """
/// Initializes the storage. Must be called before any other method is /// Initializes the storage. Must be called before any other method is
/// called from this module! /// called from this module!
/// ''' /// """
STATIC mp_obj_t mod_trezorconfig_init(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_trezorconfig_init(size_t n_args, const mp_obj_t *args) {
if (n_args > 0) { if (n_args > 0) {
ui_wait_callback = args[0]; ui_wait_callback = args[0];
@ -66,10 +66,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_init_obj, 0, 1,
mod_trezorconfig_init); mod_trezorconfig_init);
/// def unlock(pin: int) -> bool: /// def unlock(pin: int) -> bool:
/// ''' /// """
/// Attempts to unlock the storage with given PIN. Returns True on /// Attempts to unlock the storage with given PIN. Returns True on
/// success, False on failure. /// success, False on failure.
/// ''' /// """
STATIC mp_obj_t mod_trezorconfig_unlock(mp_obj_t pin) { STATIC mp_obj_t mod_trezorconfig_unlock(mp_obj_t pin) {
uint32_t pin_i = trezor_obj_get_uint(pin); uint32_t pin_i = trezor_obj_get_uint(pin);
if (sectrue != storage_unlock(pin_i)) { if (sectrue != storage_unlock(pin_i)) {
@ -81,9 +81,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorconfig_unlock_obj,
mod_trezorconfig_unlock); mod_trezorconfig_unlock);
/// def check_pin(pin: int) -> bool: /// def check_pin(pin: int) -> bool:
/// ''' /// """
/// Check the given PIN. Returns True on success, False on failure. /// Check the given PIN. Returns True on success, False on failure.
/// ''' /// """
STATIC mp_obj_t mod_trezorconfig_check_pin(mp_obj_t pin) { STATIC mp_obj_t mod_trezorconfig_check_pin(mp_obj_t pin) {
return mod_trezorconfig_unlock(pin); return mod_trezorconfig_unlock(pin);
} }
@ -91,9 +91,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorconfig_check_pin_obj,
mod_trezorconfig_check_pin); mod_trezorconfig_check_pin);
/// def lock() -> None: /// def lock() -> None:
/// ''' /// """
/// Locks the storage. /// Locks the storage.
/// ''' /// """
STATIC mp_obj_t mod_trezorconfig_lock(void) { STATIC mp_obj_t mod_trezorconfig_lock(void) {
storage_lock(); storage_lock();
return mp_const_none; return mp_const_none;
@ -102,9 +102,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_lock_obj,
mod_trezorconfig_lock); mod_trezorconfig_lock);
/// def has_pin() -> bool: /// def has_pin() -> bool:
/// ''' /// """
/// Returns True if storage has a configured PIN, False otherwise. /// Returns True if storage has a configured PIN, False otherwise.
/// ''' /// """
STATIC mp_obj_t mod_trezorconfig_has_pin(void) { STATIC mp_obj_t mod_trezorconfig_has_pin(void) {
if (sectrue != storage_has_pin()) { if (sectrue != storage_has_pin()) {
return mp_const_false; return mp_const_false;
@ -115,9 +115,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_has_pin_obj,
mod_trezorconfig_has_pin); mod_trezorconfig_has_pin);
/// def get_pin_rem() -> int: /// def get_pin_rem() -> int:
/// ''' /// """
/// Returns the number of remaining PIN entry attempts. /// Returns the number of remaining PIN entry attempts.
/// ''' /// """
STATIC mp_obj_t mod_trezorconfig_get_pin_rem(void) { STATIC mp_obj_t mod_trezorconfig_get_pin_rem(void) {
return mp_obj_new_int_from_uint(storage_get_pin_rem()); return mp_obj_new_int_from_uint(storage_get_pin_rem());
} }
@ -125,9 +125,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_get_pin_rem_obj,
mod_trezorconfig_get_pin_rem); mod_trezorconfig_get_pin_rem);
/// def change_pin(pin: int, newpin: int) -> bool: /// def change_pin(pin: int, newpin: int) -> bool:
/// ''' /// """
/// Change PIN. Returns True on success, False on failure. /// Change PIN. Returns True on success, False on failure.
/// ''' /// """
STATIC mp_obj_t mod_trezorconfig_change_pin(mp_obj_t pin, mp_obj_t newpin) { STATIC mp_obj_t mod_trezorconfig_change_pin(mp_obj_t pin, mp_obj_t newpin) {
uint32_t pin_i = trezor_obj_get_uint(pin); uint32_t pin_i = trezor_obj_get_uint(pin);
uint32_t newpin_i = trezor_obj_get_uint(newpin); uint32_t newpin_i = trezor_obj_get_uint(newpin);
@ -139,12 +139,12 @@ STATIC mp_obj_t mod_trezorconfig_change_pin(mp_obj_t pin, mp_obj_t newpin) {
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorconfig_change_pin_obj, STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorconfig_change_pin_obj,
mod_trezorconfig_change_pin); mod_trezorconfig_change_pin);
/// def get(app: int, key: int, public: bool=False) -> bytes: /// def get(app: int, key: int, public: bool = False) -> bytes:
/// ''' /// """
/// Gets the value of the given key for the given app (or None if not set). /// Gets the value of the given key for the given app (or None if not set).
/// Raises a RuntimeError if decryption or authentication of the stored /// Raises a RuntimeError if decryption or authentication of the stored
/// value fails. /// value fails.
/// ''' /// """
STATIC mp_obj_t mod_trezorconfig_get(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_trezorconfig_get(size_t n_args, const mp_obj_t *args) {
uint8_t app = trezor_obj_get_uint8(args[0]) & 0x3F; uint8_t app = trezor_obj_get_uint8(args[0]) & 0x3F;
uint8_t key = trezor_obj_get_uint8(args[1]); uint8_t key = trezor_obj_get_uint8(args[1]);
@ -170,10 +170,10 @@ STATIC mp_obj_t mod_trezorconfig_get(size_t n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_get_obj, 2, 3, STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_get_obj, 2, 3,
mod_trezorconfig_get); mod_trezorconfig_get);
/// def set(app: int, key: int, value: bytes, public: bool=False) -> None: /// def set(app: int, key: int, value: bytes, public: bool = False) -> None:
/// ''' /// """
/// Sets a value of given key for given app. /// Sets a value of given key for given app.
/// ''' /// """
STATIC mp_obj_t mod_trezorconfig_set(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_trezorconfig_set(size_t n_args, const mp_obj_t *args) {
uint8_t app = trezor_obj_get_uint8(args[0]) & 0x3F; uint8_t app = trezor_obj_get_uint8(args[0]) & 0x3F;
uint8_t key = trezor_obj_get_uint8(args[1]); uint8_t key = trezor_obj_get_uint8(args[1]);
@ -191,10 +191,10 @@ STATIC mp_obj_t mod_trezorconfig_set(size_t n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_set_obj, 3, 4, STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_set_obj, 3, 4,
mod_trezorconfig_set); mod_trezorconfig_set);
/// def delete(app: int, key: int, public: bool=False) -> bool: /// def delete(app: int, key: int, public: bool = False) -> bool:
/// ''' /// """
/// Deletes the given key of the given app. /// Deletes the given key of the given app.
/// ''' /// """
STATIC mp_obj_t mod_trezorconfig_delete(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_trezorconfig_delete(size_t n_args, const mp_obj_t *args) {
uint8_t app = trezor_obj_get_uint8(args[0]) & 0x3F; uint8_t app = trezor_obj_get_uint8(args[0]) & 0x3F;
uint8_t key = trezor_obj_get_uint8(args[1]); uint8_t key = trezor_obj_get_uint8(args[1]);
@ -210,11 +210,12 @@ STATIC mp_obj_t mod_trezorconfig_delete(size_t n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_delete_obj, 2, 3, STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_delete_obj, 2, 3,
mod_trezorconfig_delete); mod_trezorconfig_delete);
/// def set_counter(app: int, key: int, count: int, writable_locked: bool=False) /// def set_counter(
/// -> bool: /// app: int, key: int, count: int, writable_locked: bool = False
/// ''' /// ) -> bool:
/// """
/// Sets the given key of the given app as a counter with the given value. /// Sets the given key of the given app as a counter with the given value.
/// ''' /// """
STATIC mp_obj_t mod_trezorconfig_set_counter(size_t n_args, STATIC mp_obj_t mod_trezorconfig_set_counter(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
uint8_t app = trezor_obj_get_uint8(args[0]) & 0x3F; uint8_t app = trezor_obj_get_uint8(args[0]) & 0x3F;
@ -240,11 +241,11 @@ STATIC mp_obj_t mod_trezorconfig_set_counter(size_t n_args,
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_set_counter_obj, 3, STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_set_counter_obj, 3,
4, mod_trezorconfig_set_counter); 4, mod_trezorconfig_set_counter);
/// def next_counter(app: int, key: int, writable_locked: bool=False) -> bool: /// def next_counter(app: int, key: int, writable_locked: bool = False) -> bool:
/// ''' /// """
/// Increments the counter stored under the given key of the given app and /// Increments the counter stored under the given key of the given app and
/// returns the new value. /// returns the new value.
/// ''' /// """
STATIC mp_obj_t mod_trezorconfig_next_counter(size_t n_args, STATIC mp_obj_t mod_trezorconfig_next_counter(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
uint8_t app = trezor_obj_get_uint8(args[0]) & 0x3F; uint8_t app = trezor_obj_get_uint8(args[0]) & 0x3F;
@ -265,9 +266,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_next_counter_obj, 2,
3, mod_trezorconfig_next_counter); 3, mod_trezorconfig_next_counter);
/// def wipe() -> None: /// def wipe() -> None:
/// ''' /// """
/// Erases the whole config. Use with caution! /// Erases the whole config. Use with caution!
/// ''' /// """
STATIC mp_obj_t mod_trezorconfig_wipe(void) { STATIC mp_obj_t mod_trezorconfig_wipe(void) {
storage_wipe(); storage_wipe();
return mp_const_none; return mp_const_none;

@ -33,9 +33,9 @@ enum AESMode {
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class AES: /// class AES:
/// ''' /// """
/// AES context. /// AES context.
/// ''' /// """
typedef struct _mp_obj_AES_t { typedef struct _mp_obj_AES_t {
mp_obj_base_t base; mp_obj_base_t base;
aes_encrypt_ctx encrypt_ctx; aes_encrypt_ctx encrypt_ctx;
@ -45,9 +45,9 @@ typedef struct _mp_obj_AES_t {
} mp_obj_AES_t; } mp_obj_AES_t;
/// def __init__(self, mode: int, key: bytes, iv: bytes = None) -> None: /// def __init__(self, mode: int, key: bytes, iv: bytes = None) -> None:
/// ''' /// """
/// Initialize AES context. /// Initialize AES context.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_AES_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorcrypto_AES_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -148,9 +148,9 @@ static mp_obj_t aes_update(mp_obj_t self, mp_obj_t data, bool encrypt) {
} }
/// def encrypt(self, data: bytes) -> bytes: /// def encrypt(self, data: bytes) -> bytes:
/// ''' /// """
/// Encrypt data and update AES context. /// Encrypt data and update AES context.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_AES_encrypt(mp_obj_t self, mp_obj_t data) { STATIC mp_obj_t mod_trezorcrypto_AES_encrypt(mp_obj_t self, mp_obj_t data) {
return aes_update(self, data, true); return aes_update(self, data, true);
} }
@ -158,9 +158,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AES_encrypt_obj,
mod_trezorcrypto_AES_encrypt); mod_trezorcrypto_AES_encrypt);
/// def decrypt(self, data: bytes) -> bytes: /// def decrypt(self, data: bytes) -> bytes:
/// ''' /// """
/// Decrypt data and update AES context. /// Decrypt data and update AES context.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_AES_decrypt(mp_obj_t self, mp_obj_t data) { STATIC mp_obj_t mod_trezorcrypto_AES_decrypt(mp_obj_t self, mp_obj_t data) {
return aes_update(self, data, false); return aes_update(self, data, false);
} }

@ -30,9 +30,9 @@
/// package: trezorcrypto.bip32 /// package: trezorcrypto.bip32
/// class HDNode: /// class HDNode:
/// ''' /// """
/// BIP0032 HD node structure. /// BIP0032 HD node structure.
/// ''' /// """
typedef struct _mp_obj_HDNode_t { typedef struct _mp_obj_HDNode_t {
mp_obj_base_t base; mp_obj_base_t base;
uint32_t fingerprint; uint32_t fingerprint;
@ -44,16 +44,18 @@ STATIC const mp_obj_type_t mod_trezorcrypto_HDNode_type;
#define XPUB_MAXLEN 128 #define XPUB_MAXLEN 128
#define ADDRESS_MAXLEN 36 #define ADDRESS_MAXLEN 36
/// def __init__(self, /// def __init__(
/// depth: int, /// self,
/// fingerprint: int, /// depth: int,
/// child_num: int, /// fingerprint: int,
/// chain_code: bytes, /// child_num: int,
/// private_key: bytes = None, /// chain_code: bytes,
/// public_key: bytes = None, /// private_key: bytes = None,
/// curve_name: str = None) -> None: /// public_key: bytes = None,
/// ''' /// curve_name: str = None,
/// ''' /// ) -> None:
/// """
/// """
STATIC mp_obj_t mod_trezorcrypto_HDNode_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorcrypto_HDNode_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -144,10 +146,10 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_make_new(const mp_obj_type_t *type,
return MP_OBJ_FROM_PTR(o); return MP_OBJ_FROM_PTR(o);
} }
/// def derive(self, index: int, public: bool=False) -> None: /// def derive(self, index: int, public: bool = False) -> None:
/// ''' /// """
/// Derive a BIP0032 child node in place. /// Derive a BIP0032 child node in place.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_HDNode_derive(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_HDNode_derive(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(args[0]); mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(args[0]);
@ -183,9 +185,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_HDNode_derive_obj,
mod_trezorcrypto_HDNode_derive); mod_trezorcrypto_HDNode_derive);
/// def derive_cardano(self, index: int) -> None: /// def derive_cardano(self, index: int) -> None:
/// ''' /// """
/// Derive a BIP0032 child node in place using Cardano algorithm. /// Derive a BIP0032 child node in place using Cardano algorithm.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_HDNode_derive_cardano(mp_obj_t self, STATIC mp_obj_t mod_trezorcrypto_HDNode_derive_cardano(mp_obj_t self,
mp_obj_t index) { mp_obj_t index) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
@ -216,10 +218,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_derive_cardano_obj,
mod_trezorcrypto_HDNode_derive_cardano); mod_trezorcrypto_HDNode_derive_cardano);
/// def derive_path(self, path: List[int]) -> None: /// def derive_path(self, path: List[int]) -> None:
/// ''' /// """
/// Go through a list of indexes and iteratively derive a child node in /// Go through a list of indexes and iteratively derive a child node in
/// place. /// place.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_HDNode_derive_path(mp_obj_t self, STATIC mp_obj_t mod_trezorcrypto_HDNode_derive_path(mp_obj_t self,
mp_obj_t path) { mp_obj_t path) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
@ -272,9 +274,9 @@ STATIC mp_obj_t serialize_public_private(mp_obj_t self, bool use_public,
} }
/// def serialize_public(self, version: int) -> str: /// def serialize_public(self, version: int) -> str:
/// ''' /// """
/// Serialize the public info from HD node to base58 string. /// Serialize the public info from HD node to base58 string.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_HDNode_serialize_public(mp_obj_t self, STATIC mp_obj_t mod_trezorcrypto_HDNode_serialize_public(mp_obj_t self,
mp_obj_t version) { mp_obj_t version) {
uint32_t ver = trezor_obj_get_uint(version); uint32_t ver = trezor_obj_get_uint(version);
@ -284,9 +286,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_serialize_public_obj,
mod_trezorcrypto_HDNode_serialize_public); mod_trezorcrypto_HDNode_serialize_public);
/// def serialize_private(self, version: int) -> str: /// def serialize_private(self, version: int) -> str:
/// ''' /// """
/// Serialize the private info HD node to base58 string. /// Serialize the private info HD node to base58 string.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_HDNode_serialize_private(mp_obj_t self, STATIC mp_obj_t mod_trezorcrypto_HDNode_serialize_private(mp_obj_t self,
mp_obj_t version) { mp_obj_t version) {
uint32_t ver = trezor_obj_get_uint(version); uint32_t ver = trezor_obj_get_uint(version);
@ -296,9 +298,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_serialize_private_obj,
mod_trezorcrypto_HDNode_serialize_private); mod_trezorcrypto_HDNode_serialize_private);
/// def clone(self) -> HDNode: /// def clone(self) -> HDNode:
/// ''' /// """
/// Returns a copy of the HD node. /// Returns a copy of the HD node.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_HDNode_clone(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_HDNode_clone(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
mp_obj_HDNode_t *copy = m_new_obj(mp_obj_HDNode_t); mp_obj_HDNode_t *copy = m_new_obj(mp_obj_HDNode_t);
@ -311,9 +313,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_clone_obj,
mod_trezorcrypto_HDNode_clone); mod_trezorcrypto_HDNode_clone);
/// def depth(self) -> int: /// def depth(self) -> int:
/// ''' /// """
/// Returns a depth of the HD node. /// Returns a depth of the HD node.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_HDNode_depth(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_HDNode_depth(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
return mp_obj_new_int_from_uint(o->hdnode.depth); return mp_obj_new_int_from_uint(o->hdnode.depth);
@ -322,9 +324,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_depth_obj,
mod_trezorcrypto_HDNode_depth); mod_trezorcrypto_HDNode_depth);
/// def fingerprint(self) -> int: /// def fingerprint(self) -> int:
/// ''' /// """
/// Returns a fingerprint of the HD node (hash of the parent public key). /// Returns a fingerprint of the HD node (hash of the parent public key).
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_HDNode_fingerprint(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_HDNode_fingerprint(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
return mp_obj_new_int_from_uint(o->fingerprint); return mp_obj_new_int_from_uint(o->fingerprint);
@ -333,9 +335,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_fingerprint_obj,
mod_trezorcrypto_HDNode_fingerprint); mod_trezorcrypto_HDNode_fingerprint);
/// def child_num(self) -> int: /// def child_num(self) -> int:
/// ''' /// """
/// Returns a child index of the HD node. /// Returns a child index of the HD node.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_HDNode_child_num(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_HDNode_child_num(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
return mp_obj_new_int_from_uint(o->hdnode.child_num); return mp_obj_new_int_from_uint(o->hdnode.child_num);
@ -344,9 +346,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_child_num_obj,
mod_trezorcrypto_HDNode_child_num); mod_trezorcrypto_HDNode_child_num);
/// def chain_code(self) -> bytes: /// def chain_code(self) -> bytes:
/// ''' /// """
/// Returns a chain code of the HD node. /// Returns a chain code of the HD node.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_HDNode_chain_code(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_HDNode_chain_code(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
return mp_obj_new_bytes(o->hdnode.chain_code, sizeof(o->hdnode.chain_code)); return mp_obj_new_bytes(o->hdnode.chain_code, sizeof(o->hdnode.chain_code));
@ -355,9 +357,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_chain_code_obj,
mod_trezorcrypto_HDNode_chain_code); mod_trezorcrypto_HDNode_chain_code);
/// def private_key(self) -> bytes: /// def private_key(self) -> bytes:
/// ''' /// """
/// Returns a private key of the HD node. /// Returns a private key of the HD node.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_HDNode_private_key(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_HDNode_private_key(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
return mp_obj_new_bytes(o->hdnode.private_key, sizeof(o->hdnode.private_key)); return mp_obj_new_bytes(o->hdnode.private_key, sizeof(o->hdnode.private_key));
@ -366,9 +368,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_private_key_obj,
mod_trezorcrypto_HDNode_private_key); mod_trezorcrypto_HDNode_private_key);
/// def private_key_ext(self) -> bytes: /// def private_key_ext(self) -> bytes:
/// ''' /// """
/// Returns a private key extension of the HD node. /// Returns a private key extension of the HD node.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_HDNode_private_key_ext(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_HDNode_private_key_ext(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
return mp_obj_new_bytes(o->hdnode.private_key_extension, return mp_obj_new_bytes(o->hdnode.private_key_extension,
@ -378,9 +380,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_private_key_ext_obj,
mod_trezorcrypto_HDNode_private_key_ext); mod_trezorcrypto_HDNode_private_key_ext);
/// def public_key(self) -> bytes: /// def public_key(self) -> bytes:
/// ''' /// """
/// Returns a public key of the HD node. /// Returns a public key of the HD node.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_HDNode_public_key(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_HDNode_public_key(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
hdnode_fill_public_key(&o->hdnode); hdnode_fill_public_key(&o->hdnode);
@ -390,9 +392,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_public_key_obj,
mod_trezorcrypto_HDNode_public_key); mod_trezorcrypto_HDNode_public_key);
/// def address(self, version: int) -> str: /// def address(self, version: int) -> str:
/// ''' /// """
/// Compute a base58-encoded address string from the HD node. /// Compute a base58-encoded address string from the HD node.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_HDNode_address(mp_obj_t self, STATIC mp_obj_t mod_trezorcrypto_HDNode_address(mp_obj_t self,
mp_obj_t version) { mp_obj_t version) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
@ -408,9 +410,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_address_obj,
mod_trezorcrypto_HDNode_address); mod_trezorcrypto_HDNode_address);
/// def nem_address(self, network: int) -> str: /// def nem_address(self, network: int) -> str:
/// ''' /// """
/// Compute a NEM address string from the HD node. /// Compute a NEM address string from the HD node.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_HDNode_nem_address(mp_obj_t self, STATIC mp_obj_t mod_trezorcrypto_HDNode_nem_address(mp_obj_t self,
mp_obj_t network) { mp_obj_t network) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
@ -427,11 +429,12 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_nem_address(mp_obj_t self,
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_nem_address_obj, STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_nem_address_obj,
mod_trezorcrypto_HDNode_nem_address); mod_trezorcrypto_HDNode_nem_address);
/// def nem_encrypt(self, transfer_public_key: bytes, iv: bytes, salt: bytes, /// def nem_encrypt(
/// payload: bytes) -> bytes: /// self, transfer_public_key: bytes, iv: bytes, salt: bytes, payload: bytes
/// ''' /// ) -> bytes:
/// """
/// Encrypts payload using the transfer's public key /// Encrypts payload using the transfer's public key
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_HDNode_nem_encrypt(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_HDNode_nem_encrypt(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(args[0]); mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(args[0]);
@ -472,9 +475,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_HDNode_nem_encrypt); mod_trezorcrypto_HDNode_nem_encrypt);
/// def ethereum_pubkeyhash(self) -> bytes: /// def ethereum_pubkeyhash(self) -> bytes:
/// ''' /// """
/// Compute an Ethereum pubkeyhash (aka address) from the HD node. /// Compute an Ethereum pubkeyhash (aka address) from the HD node.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_HDNode_ethereum_pubkeyhash(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_HDNode_ethereum_pubkeyhash(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
@ -544,11 +547,12 @@ STATIC const mp_obj_type_t mod_trezorcrypto_HDNode_type = {
.locals_dict = (void *)&mod_trezorcrypto_HDNode_locals_dict, .locals_dict = (void *)&mod_trezorcrypto_HDNode_locals_dict,
}; };
/// def deserialize(self, value: str, version_public: int, version_private: int) /// def deserialize(
/// -> HDNode: /// self, value: str, version_public: int, version_private: int
/// ''' /// ) -> HDNode:
/// """
/// Construct a BIP0032 HD node from a base58-serialized value. /// Construct a BIP0032 HD node from a base58-serialized value.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_bip32_deserialize(mp_obj_t value, STATIC mp_obj_t mod_trezorcrypto_bip32_deserialize(mp_obj_t value,
mp_obj_t version_public, mp_obj_t version_public,
mp_obj_t version_private) { mp_obj_t version_private) {
@ -576,9 +580,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_bip32_deserialize_obj,
mod_trezorcrypto_bip32_deserialize); mod_trezorcrypto_bip32_deserialize);
/// def from_seed(seed: bytes, curve_name: str) -> HDNode: /// def from_seed(seed: bytes, curve_name: str) -> HDNode:
/// ''' /// """
/// Construct a BIP0032 HD node from a BIP0039 seed value. /// Construct a BIP0032 HD node from a BIP0039 seed value.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_bip32_from_seed(mp_obj_t seed, STATIC mp_obj_t mod_trezorcrypto_bip32_from_seed(mp_obj_t seed,
mp_obj_t curve_name) { mp_obj_t curve_name) {
mp_buffer_info_t seedb; mp_buffer_info_t seedb;
@ -605,9 +609,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_bip32_from_seed_obj,
mod_trezorcrypto_bip32_from_seed); mod_trezorcrypto_bip32_from_seed);
/// def from_mnemonic_cardano(mnemonic: str, passphrase: str) -> bytes: /// def from_mnemonic_cardano(mnemonic: str, passphrase: str) -> bytes:
/// ''' /// """
/// Convert mnemonic to hdnode /// Convert mnemonic to hdnode
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_bip32_from_mnemonic_cardano( STATIC mp_obj_t mod_trezorcrypto_bip32_from_mnemonic_cardano(
mp_obj_t mnemonic, mp_obj_t passphrase) { mp_obj_t mnemonic, mp_obj_t passphrase) {
mp_buffer_info_t mnemo, phrase; mp_buffer_info_t mnemo, phrase;

@ -25,9 +25,9 @@
/// package: trezorcrypto.bip39 /// package: trezorcrypto.bip39
/// def find_word(prefix: str) -> Optional[str]: /// def find_word(prefix: str) -> Optional[str]:
/// ''' /// """
/// Return the first word from the wordlist starting with prefix. /// Return the first word from the wordlist starting with prefix.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_bip39_find_word(mp_obj_t prefix) { STATIC mp_obj_t mod_trezorcrypto_bip39_find_word(mp_obj_t prefix) {
mp_buffer_info_t pfx; mp_buffer_info_t pfx;
mp_get_buffer_raise(prefix, &pfx, MP_BUFFER_READ); mp_get_buffer_raise(prefix, &pfx, MP_BUFFER_READ);
@ -45,11 +45,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip39_find_word_obj,
mod_trezorcrypto_bip39_find_word); mod_trezorcrypto_bip39_find_word);
/// def complete_word(prefix: str) -> int: /// def complete_word(prefix: str) -> int:
/// ''' /// """
/// Return possible 1-letter suffixes for given word prefix. /// Return possible 1-letter suffixes for given word prefix.
/// Result is a bitmask, with 'a' on the lowest bit, 'b' on the second /// Result is a bitmask, with 'a' on the lowest bit, 'b' on the second
/// lowest, etc. /// lowest, etc.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_bip39_complete_word(mp_obj_t prefix) { STATIC mp_obj_t mod_trezorcrypto_bip39_complete_word(mp_obj_t prefix) {
mp_buffer_info_t pfx; mp_buffer_info_t pfx;
mp_get_buffer_raise(prefix, &pfx, MP_BUFFER_READ); mp_get_buffer_raise(prefix, &pfx, MP_BUFFER_READ);
@ -73,9 +73,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip39_complete_word_obj,
mod_trezorcrypto_bip39_complete_word); mod_trezorcrypto_bip39_complete_word);
/// def generate(strength: int) -> str: /// def generate(strength: int) -> str:
/// ''' /// """
/// Generate a mnemonic of given strength (128, 160, 192, 224 and 256 bits). /// Generate a mnemonic of given strength (128, 160, 192, 224 and 256 bits).
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_bip39_generate(mp_obj_t strength) { STATIC mp_obj_t mod_trezorcrypto_bip39_generate(mp_obj_t strength) {
int bits = mp_obj_get_int(strength); int bits = mp_obj_get_int(strength);
if (bits % 32 || bits < 128 || bits > 256) { if (bits % 32 || bits < 128 || bits > 256) {
@ -93,9 +93,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip39_generate_obj,
mod_trezorcrypto_bip39_generate); mod_trezorcrypto_bip39_generate);
/// def from_data(data: bytes) -> str: /// def from_data(data: bytes) -> str:
/// ''' /// """
/// Generate a mnemonic from given data (of 16, 20, 24, 28 and 32 bytes). /// Generate a mnemonic from given data (of 16, 20, 24, 28 and 32 bytes).
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_bip39_from_data(mp_obj_t data) { STATIC mp_obj_t mod_trezorcrypto_bip39_from_data(mp_obj_t data) {
mp_buffer_info_t bin; mp_buffer_info_t bin;
mp_get_buffer_raise(data, &bin, MP_BUFFER_READ); mp_get_buffer_raise(data, &bin, MP_BUFFER_READ);
@ -113,9 +113,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip39_from_data_obj,
mod_trezorcrypto_bip39_from_data); mod_trezorcrypto_bip39_from_data);
/// def check(mnemonic: str) -> bool: /// def check(mnemonic: str) -> bool:
/// ''' /// """
/// Check whether given mnemonic is valid. /// Check whether given mnemonic is valid.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_bip39_check(mp_obj_t mnemonic) { STATIC mp_obj_t mod_trezorcrypto_bip39_check(mp_obj_t mnemonic) {
mp_buffer_info_t text; mp_buffer_info_t text;
mp_get_buffer_raise(mnemonic, &text, MP_BUFFER_READ); mp_get_buffer_raise(mnemonic, &text, MP_BUFFER_READ);
@ -134,11 +134,12 @@ STATIC void wrapped_ui_wait_callback(uint32_t current, uint32_t total) {
} }
} }
/// def seed(mnemonic: str, passphrase: str, callback: (int, int -> None)=None) /// def seed(
/// -> bytes: /// mnemonic: str, passphrase: str, callback: Tuple[int, int, None] = None
/// ''' /// ) -> bytes:
/// """
/// Generate seed from mnemonic and passphrase. /// Generate seed from mnemonic and passphrase.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_bip39_seed(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_bip39_seed(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_buffer_info_t mnemo; mp_buffer_info_t mnemo;

@ -25,9 +25,9 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Blake256: /// class Blake256:
/// ''' /// """
/// Blake256 context. /// Blake256 context.
/// ''' /// """
typedef struct _mp_obj_Blake256_t { typedef struct _mp_obj_Blake256_t {
mp_obj_base_t base; mp_obj_base_t base;
BLAKE256_CTX ctx; BLAKE256_CTX ctx;
@ -36,9 +36,9 @@ typedef struct _mp_obj_Blake256_t {
STATIC mp_obj_t mod_trezorcrypto_Blake256_update(mp_obj_t self, mp_obj_t data); STATIC mp_obj_t mod_trezorcrypto_Blake256_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None) -> None: /// def __init__(self, data: bytes = None) -> None:
/// ''' /// """
/// Creates a hash context object. /// Creates a hash context object.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Blake256_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorcrypto_Blake256_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -54,9 +54,9 @@ STATIC mp_obj_t mod_trezorcrypto_Blake256_make_new(const mp_obj_type_t *type,
} }
/// def update(self, data: bytes) -> None: /// def update(self, data: bytes) -> None:
/// ''' /// """
/// Update the hash context with hashed data. /// Update the hash context with hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Blake256_update(mp_obj_t self, mp_obj_t data) { STATIC mp_obj_t mod_trezorcrypto_Blake256_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Blake256_t *o = MP_OBJ_TO_PTR(self); mp_obj_Blake256_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t msg; mp_buffer_info_t msg;
@ -70,9 +70,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Blake256_update_obj,
mod_trezorcrypto_Blake256_update); mod_trezorcrypto_Blake256_update);
/// def digest(self) -> bytes: /// def digest(self) -> bytes:
/// ''' /// """
/// Returns the digest of hashed data. /// Returns the digest of hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Blake256_digest(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_Blake256_digest(mp_obj_t self) {
mp_obj_Blake256_t *o = MP_OBJ_TO_PTR(self); mp_obj_Blake256_t *o = MP_OBJ_TO_PTR(self);
uint8_t hash[BLAKE256_DIGEST_LENGTH]; uint8_t hash[BLAKE256_DIGEST_LENGTH];

@ -27,9 +27,9 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Blake2b: /// class Blake2b:
/// ''' /// """
/// Blake2b context. /// Blake2b context.
/// ''' /// """
typedef struct _mp_obj_Blake2b_t { typedef struct _mp_obj_Blake2b_t {
mp_obj_base_t base; mp_obj_base_t base;
BLAKE2B_CTX ctx; BLAKE2B_CTX ctx;
@ -37,11 +37,15 @@ typedef struct _mp_obj_Blake2b_t {
STATIC mp_obj_t mod_trezorcrypto_Blake2b_update(mp_obj_t self, mp_obj_t data); STATIC mp_obj_t mod_trezorcrypto_Blake2b_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None, outlen: int = Blake2b.digest_size, /// def __init__(
/// personal: bytes = None) -> None: /// self,
/// ''' /// data: bytes = None,
/// outlen: int = Blake2b.digest_size,
/// personal: bytes = None,
/// ) -> None:
/// """
/// Creates a hash context object. /// Creates a hash context object.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Blake2b_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorcrypto_Blake2b_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -103,9 +107,9 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2b_make_new(const mp_obj_type_t *type,
} }
/// def update(self, data: bytes) -> None: /// def update(self, data: bytes) -> None:
/// ''' /// """
/// Update the hash context with hashed data. /// Update the hash context with hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Blake2b_update(mp_obj_t self, mp_obj_t data) { STATIC mp_obj_t mod_trezorcrypto_Blake2b_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Blake2b_t *o = MP_OBJ_TO_PTR(self); mp_obj_Blake2b_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t msg; mp_buffer_info_t msg;
@ -119,9 +123,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Blake2b_update_obj,
mod_trezorcrypto_Blake2b_update); mod_trezorcrypto_Blake2b_update);
/// def digest(self) -> bytes: /// def digest(self) -> bytes:
/// ''' /// """
/// Returns the digest of hashed data. /// Returns the digest of hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Blake2b_digest(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_Blake2b_digest(mp_obj_t self) {
mp_obj_Blake2b_t *o = MP_OBJ_TO_PTR(self); mp_obj_Blake2b_t *o = MP_OBJ_TO_PTR(self);
uint8_t out[BLAKE2B_DIGEST_LENGTH]; uint8_t out[BLAKE2B_DIGEST_LENGTH];

@ -27,9 +27,9 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Blake2s: /// class Blake2s:
/// ''' /// """
/// Blake2s context. /// Blake2s context.
/// ''' /// """
typedef struct _mp_obj_Blake2s_t { typedef struct _mp_obj_Blake2s_t {
mp_obj_base_t base; mp_obj_base_t base;
BLAKE2S_CTX ctx; BLAKE2S_CTX ctx;
@ -37,11 +37,16 @@ typedef struct _mp_obj_Blake2s_t {
STATIC mp_obj_t mod_trezorcrypto_Blake2s_update(mp_obj_t self, mp_obj_t data); STATIC mp_obj_t mod_trezorcrypto_Blake2s_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None, outlen: int = Blake2s.digest_size, /// def __init__(
/// key: bytes = None, personal: bytes = None) -> None: /// self,
/// ''' /// data: bytes = None,
/// outlen: int = Blake2s.digest_size,
/// key: bytes = None,
/// personal: bytes = None,
/// ) -> None:
/// """
/// Creates a hash context object. /// Creates a hash context object.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Blake2s_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorcrypto_Blake2s_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -103,9 +108,9 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2s_make_new(const mp_obj_type_t *type,
} }
/// def update(self, data: bytes) -> None: /// def update(self, data: bytes) -> None:
/// ''' /// """
/// Update the hash context with hashed data. /// Update the hash context with hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Blake2s_update(mp_obj_t self, mp_obj_t data) { STATIC mp_obj_t mod_trezorcrypto_Blake2s_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Blake2s_t *o = MP_OBJ_TO_PTR(self); mp_obj_Blake2s_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t msg; mp_buffer_info_t msg;
@ -119,9 +124,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Blake2s_update_obj,
mod_trezorcrypto_Blake2s_update); mod_trezorcrypto_Blake2s_update);
/// def digest(self) -> bytes: /// def digest(self) -> bytes:
/// ''' /// """
/// Returns the digest of hashed data. /// Returns the digest of hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Blake2s_digest(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_Blake2s_digest(mp_obj_t self) {
mp_obj_Blake2s_t *o = MP_OBJ_TO_PTR(self); mp_obj_Blake2s_t *o = MP_OBJ_TO_PTR(self);
uint8_t out[BLAKE2S_DIGEST_LENGTH]; uint8_t out[BLAKE2S_DIGEST_LENGTH];

@ -25,9 +25,9 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class ChaCha20Poly1305: /// class ChaCha20Poly1305:
/// ''' /// """
/// ChaCha20Poly1305 context. /// ChaCha20Poly1305 context.
/// ''' /// """
typedef struct _mp_obj_ChaCha20Poly1305_t { typedef struct _mp_obj_ChaCha20Poly1305_t {
mp_obj_base_t base; mp_obj_base_t base;
chacha20poly1305_ctx ctx; chacha20poly1305_ctx ctx;
@ -35,10 +35,10 @@ typedef struct _mp_obj_ChaCha20Poly1305_t {
} mp_obj_ChaCha20Poly1305_t; } mp_obj_ChaCha20Poly1305_t;
/// def __init__(self, key: bytes, nonce: bytes) -> None: /// def __init__(self, key: bytes, nonce: bytes) -> None:
/// ''' /// """
/// Initialize the ChaCha20 + Poly1305 context for encryption or decryption /// Initialize the ChaCha20 + Poly1305 context for encryption or decryption
/// using a 32 byte key and 12 byte nonce as in the RFC 7539 style. /// using a 32 byte key and 12 byte nonce as in the RFC 7539 style.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_make_new( STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_make_new(
const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_type_t *type, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -61,10 +61,10 @@ STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_make_new(
} }
/// def encrypt(self, data: bytes) -> bytes: /// def encrypt(self, data: bytes) -> bytes:
/// ''' /// """
/// Encrypt data (length of data must be divisible by 64 except for the /// Encrypt data (length of data must be divisible by 64 except for the
/// final value). /// final value).
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_encrypt(mp_obj_t self, STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_encrypt(mp_obj_t self,
mp_obj_t data) { mp_obj_t data) {
mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self); mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self);
@ -80,10 +80,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_ChaCha20Poly1305_encrypt_obj,
mod_trezorcrypto_ChaCha20Poly1305_encrypt); mod_trezorcrypto_ChaCha20Poly1305_encrypt);
/// def decrypt(self, data: bytes) -> bytes: /// def decrypt(self, data: bytes) -> bytes:
/// ''' /// """
/// Decrypt data (length of data must be divisible by 64 except for the /// Decrypt data (length of data must be divisible by 64 except for the
/// final value). /// final value).
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_decrypt(mp_obj_t self, STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_decrypt(mp_obj_t self,
mp_obj_t data) { mp_obj_t data) {
mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self); mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self);
@ -99,11 +99,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_ChaCha20Poly1305_decrypt_obj,
mod_trezorcrypto_ChaCha20Poly1305_decrypt); mod_trezorcrypto_ChaCha20Poly1305_decrypt);
/// def auth(self, data: bytes) -> None: /// def auth(self, data: bytes) -> None:
/// ''' /// """
/// Include authenticated data in the Poly1305 MAC using the RFC 7539 /// Include authenticated data in the Poly1305 MAC using the RFC 7539
/// style with 16 byte padding. This must only be called once and prior /// style with 16 byte padding. This must only be called once and prior
/// to encryption or decryption. /// to encryption or decryption.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_auth(mp_obj_t self, STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_auth(mp_obj_t self,
mp_obj_t data) { mp_obj_t data) {
mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self); mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self);
@ -117,9 +117,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_ChaCha20Poly1305_auth_obj,
mod_trezorcrypto_ChaCha20Poly1305_auth); mod_trezorcrypto_ChaCha20Poly1305_auth);
/// def finish(self) -> bytes: /// def finish(self) -> bytes:
/// ''' /// """
/// Compute RFC 7539-style Poly1305 MAC. /// Compute RFC 7539-style Poly1305 MAC.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_finish(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_finish(mp_obj_t self) {
mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self); mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self);
uint8_t out[16]; uint8_t out[16];

@ -26,9 +26,9 @@
/// package: trezorcrypto.curve25519 /// package: trezorcrypto.curve25519
/// def generate_secret() -> bytes: /// def generate_secret() -> bytes:
/// ''' /// """
/// Generate secret key. /// Generate secret key.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_curve25519_generate_secret() { STATIC mp_obj_t mod_trezorcrypto_curve25519_generate_secret() {
uint8_t out[32]; uint8_t out[32];
random_buffer(out, 32); random_buffer(out, 32);
@ -43,9 +43,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(
mod_trezorcrypto_curve25519_generate_secret); mod_trezorcrypto_curve25519_generate_secret);
/// def publickey(secret_key: bytes) -> bytes: /// def publickey(secret_key: bytes) -> bytes:
/// ''' /// """
/// Computes public key from secret key. /// Computes public key from secret key.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_curve25519_publickey(mp_obj_t secret_key) { STATIC mp_obj_t mod_trezorcrypto_curve25519_publickey(mp_obj_t secret_key) {
mp_buffer_info_t sk; mp_buffer_info_t sk;
mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ); mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
@ -60,10 +60,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_curve25519_publickey_obj,
mod_trezorcrypto_curve25519_publickey); mod_trezorcrypto_curve25519_publickey);
/// def multiply(secret_key: bytes, public_key: bytes) -> bytes: /// def multiply(secret_key: bytes, public_key: bytes) -> bytes:
/// ''' /// """
/// Multiplies point defined by public_key with scalar defined by /// Multiplies point defined by public_key with scalar defined by
/// secret_key. Useful for ECDH. /// secret_key. Useful for ECDH.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_curve25519_multiply(mp_obj_t secret_key, STATIC mp_obj_t mod_trezorcrypto_curve25519_multiply(mp_obj_t secret_key,
mp_obj_t public_key) { mp_obj_t public_key) {
mp_buffer_info_t sk, pk; mp_buffer_info_t sk, pk;

@ -27,9 +27,9 @@
/// package: trezorcrypto.ed25519 /// package: trezorcrypto.ed25519
/// def generate_secret() -> bytes: /// def generate_secret() -> bytes:
/// ''' /// """
/// Generate secret key. /// Generate secret key.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_ed25519_generate_secret() { STATIC mp_obj_t mod_trezorcrypto_ed25519_generate_secret() {
uint8_t out[32]; uint8_t out[32];
random_buffer(out, 32); random_buffer(out, 32);
@ -43,9 +43,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_ed25519_generate_secret_obj,
mod_trezorcrypto_ed25519_generate_secret); mod_trezorcrypto_ed25519_generate_secret);
/// def publickey(secret_key: bytes) -> bytes: /// def publickey(secret_key: bytes) -> bytes:
/// ''' /// """
/// Computes public key from secret key. /// Computes public key from secret key.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_ed25519_publickey(mp_obj_t secret_key) { STATIC mp_obj_t mod_trezorcrypto_ed25519_publickey(mp_obj_t secret_key) {
mp_buffer_info_t sk; mp_buffer_info_t sk;
mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ); mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
@ -60,10 +60,10 @@ STATIC mp_obj_t mod_trezorcrypto_ed25519_publickey(mp_obj_t secret_key) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_ed25519_publickey_obj, STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_ed25519_publickey_obj,
mod_trezorcrypto_ed25519_publickey); mod_trezorcrypto_ed25519_publickey);
/// def sign(secret_key: bytes, message: bytes, hasher: str='') -> bytes: /// def sign(secret_key: bytes, message: bytes, hasher: str = "") -> bytes:
/// ''' /// """
/// Uses secret key to produce the signature of message. /// Uses secret key to produce the signature of message.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_ed25519_sign(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_ed25519_sign(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_buffer_info_t sk, msg; mp_buffer_info_t sk, msg;
@ -100,11 +100,12 @@ STATIC mp_obj_t mod_trezorcrypto_ed25519_sign(size_t n_args,
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_ed25519_sign_obj, 2, STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_ed25519_sign_obj, 2,
3, mod_trezorcrypto_ed25519_sign); 3, mod_trezorcrypto_ed25519_sign);
/// def sign_ext(secret_key: bytes, secret_extension: bytes, message: bytes) -> /// def sign_ext(
/// bytes: /// secret_key: bytes, secret_extension: bytes, message: bytes
/// ''' /// ) -> bytes:
/// """
/// Uses secret key to produce the cardano signature of message. /// Uses secret key to produce the cardano signature of message.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_ed25519_sign_ext(mp_obj_t secret_key, STATIC mp_obj_t mod_trezorcrypto_ed25519_sign_ext(mp_obj_t secret_key,
mp_obj_t secret_extension, mp_obj_t secret_extension,
mp_obj_t message) { mp_obj_t message) {
@ -135,10 +136,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_ed25519_sign_ext_obj,
mod_trezorcrypto_ed25519_sign_ext); mod_trezorcrypto_ed25519_sign_ext);
/// def verify(public_key: bytes, signature: bytes, message: bytes) -> bool: /// def verify(public_key: bytes, signature: bytes, message: bytes) -> bool:
/// ''' /// """
/// Uses public key to verify the signature of the message. /// Uses public key to verify the signature of the message.
/// Returns True on success. /// Returns True on success.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_ed25519_verify(mp_obj_t public_key, STATIC mp_obj_t mod_trezorcrypto_ed25519_verify(mp_obj_t public_key,
mp_obj_t signature, mp_obj_t signature,
mp_obj_t message) { mp_obj_t message) {
@ -165,9 +166,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_ed25519_verify_obj,
mod_trezorcrypto_ed25519_verify); mod_trezorcrypto_ed25519_verify);
/// def cosi_combine_publickeys(public_keys: List[bytes]) -> bytes: /// def cosi_combine_publickeys(public_keys: List[bytes]) -> bytes:
/// ''' /// """
/// Combines a list of public keys used in COSI cosigning scheme. /// Combines a list of public keys used in COSI cosigning scheme.
/// ''' /// """
STATIC mp_obj_t STATIC mp_obj_t
mod_trezorcrypto_ed25519_cosi_combine_publickeys(mp_obj_t public_keys) { mod_trezorcrypto_ed25519_cosi_combine_publickeys(mp_obj_t public_keys) {
size_t pklen; size_t pklen;
@ -197,9 +198,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(
mod_trezorcrypto_ed25519_cosi_combine_publickeys); mod_trezorcrypto_ed25519_cosi_combine_publickeys);
/// def cosi_combine_signatures(R: bytes, signatures: List[bytes]) -> bytes: /// def cosi_combine_signatures(R: bytes, signatures: List[bytes]) -> bytes:
/// ''' /// """
/// Combines a list of signatures used in COSI cosigning scheme. /// Combines a list of signatures used in COSI cosigning scheme.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_ed25519_cosi_combine_signatures( STATIC mp_obj_t mod_trezorcrypto_ed25519_cosi_combine_signatures(
mp_obj_t R, mp_obj_t signatures) { mp_obj_t R, mp_obj_t signatures) {
mp_buffer_info_t sigR; mp_buffer_info_t sigR;
@ -232,11 +233,16 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(
mod_trezorcrypto_ed25519_cosi_combine_signatures_obj, mod_trezorcrypto_ed25519_cosi_combine_signatures_obj,
mod_trezorcrypto_ed25519_cosi_combine_signatures); mod_trezorcrypto_ed25519_cosi_combine_signatures);
/// def cosi_sign(secret_key: bytes, message: bytes, nonce: bytes, sigR: bytes, /// def cosi_sign(
/// combined_pubkey: bytes) -> bytes: /// secret_key: bytes,
/// ''' /// message: bytes,
/// nonce: bytes,
/// sigR: bytes,
/// combined_pubkey: bytes,
/// ) -> bytes:
/// """
/// Produce signature of message using COSI cosigning scheme. /// Produce signature of message using COSI cosigning scheme.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_ed25519_cosi_sign(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_ed25519_cosi_sign(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_buffer_info_t sk, msg, nonce, sigR, pk; mp_buffer_info_t sk, msg, nonce, sigR, pk;

@ -28,9 +28,9 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Groestl512: /// class Groestl512:
/// ''' /// """
/// GROESTL512 context. /// GROESTL512 context.
/// ''' /// """
typedef struct _mp_obj_Groestl512_t { typedef struct _mp_obj_Groestl512_t {
mp_obj_base_t base; mp_obj_base_t base;
GROESTL512_CTX ctx; GROESTL512_CTX ctx;
@ -40,9 +40,9 @@ STATIC mp_obj_t mod_trezorcrypto_Groestl512_update(mp_obj_t self,
mp_obj_t data); mp_obj_t data);
/// def __init__(self, data: bytes = None) -> None: /// def __init__(self, data: bytes = None) -> None:
/// ''' /// """
/// Creates a hash context object. /// Creates a hash context object.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Groestl512_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorcrypto_Groestl512_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -57,9 +57,9 @@ STATIC mp_obj_t mod_trezorcrypto_Groestl512_make_new(const mp_obj_type_t *type,
} }
/// def update(self, data: bytes) -> None: /// def update(self, data: bytes) -> None:
/// ''' /// """
/// Update the hash context with hashed data. /// Update the hash context with hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Groestl512_update(mp_obj_t self, STATIC mp_obj_t mod_trezorcrypto_Groestl512_update(mp_obj_t self,
mp_obj_t data) { mp_obj_t data) {
mp_obj_Groestl512_t *o = MP_OBJ_TO_PTR(self); mp_obj_Groestl512_t *o = MP_OBJ_TO_PTR(self);
@ -74,9 +74,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Groestl512_update_obj,
mod_trezorcrypto_Groestl512_update); mod_trezorcrypto_Groestl512_update);
/// def digest(self) -> bytes: /// def digest(self) -> bytes:
/// ''' /// """
/// Returns the digest of hashed data. /// Returns the digest of hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Groestl512_digest(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_Groestl512_digest(mp_obj_t self) {
mp_obj_Groestl512_t *o = MP_OBJ_TO_PTR(self); mp_obj_Groestl512_t *o = MP_OBJ_TO_PTR(self);
uint8_t out[GROESTL512_DIGEST_LENGTH]; uint8_t out[GROESTL512_DIGEST_LENGTH];

@ -176,14 +176,14 @@ STATIC void mp_unpack_scalar(bignum256modm r, const mp_obj_t arg,
// //
/// class Ge25519: /// class Ge25519:
/// ''' /// """
/// EC point on ED25519 /// EC point on ED25519
/// ''' /// """
/// ///
/// def __init__(x: Optional[Union[Ge25519, bytes]] = None): /// def __init__(x: Optional[Union[Ge25519, bytes]] = None):
/// ''' /// """
/// Constructor /// Constructor
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_make_new( STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_make_new(
const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_type_t *type, size_t n_args, size_t n_kw,
@ -214,14 +214,14 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_ge25519___del___obj,
mod_trezorcrypto_monero_ge25519___del__); mod_trezorcrypto_monero_ge25519___del__);
/// class Sc25519: /// class Sc25519:
/// ''' /// """
/// EC scalar on SC25519 /// EC scalar on SC25519
/// ''' /// """
/// ///
/// def __init__(x: Optional[Union[Sc25519, bytes, int]] = None): /// def __init__(x: Optional[Union[Sc25519, bytes, int]] = None):
/// ''' /// """
/// Constructor /// Constructor
/// ''' /// """
/// ///
/// ///
STATIC mp_obj_t mod_trezorcrypto_monero_bignum256modm_make_new( STATIC mp_obj_t mod_trezorcrypto_monero_bignum256modm_make_new(
@ -257,29 +257,29 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(
mod_trezorcrypto_monero_bignum256modm___del__); mod_trezorcrypto_monero_bignum256modm___del__);
/// class Hasher: /// class Hasher:
/// ''' /// """
/// XMR hasher /// XMR hasher
/// ''' /// """
/// ///
/// def __init__(x: Optional[bytes] = None): /// def __init__(x: Optional[bytes] = None):
/// ''' /// """
/// Constructor /// Constructor
/// ''' /// """
/// ///
/// def update(buffer: bytes): /// def update(buffer: bytes):
/// ''' /// """
/// Update hasher /// Update hasher
/// ''' /// """
/// ///
/// def digest() -> bytes: /// def digest() -> bytes:
/// ''' /// """
/// Computes digest /// Computes digest
/// ''' /// """
/// ///
/// def copy() -> Hasher: /// def copy() -> Hasher:
/// ''' /// """
/// Creates copy of the hasher, preserving the state /// Creates copy of the hasher, preserving the state
/// ''' /// """
/// ///
/// ///
STATIC mp_obj_t mod_trezorcrypto_monero_hasher_make_new( STATIC mp_obj_t mod_trezorcrypto_monero_hasher_make_new(
@ -313,11 +313,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_hasher___del___obj,
/// mock:global /// mock:global
/// def init256_modm(dst: Optional[Sc25519], val: Union[int, bytes, Sc25519]) -> /// def init256_modm(
/// Sc25519: /// dst: Optional[Sc25519], val: Union[int, bytes, Sc25519]
/// ''' /// ) -> Sc25519:
/// """
/// Initializes Sc25519 scalar /// Initializes Sc25519 scalar
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_init256_modm(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_monero_init256_modm(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
const bool res_arg = n_args == 2; const bool res_arg = n_args == 2;
@ -343,9 +344,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_init256_modm); mod_trezorcrypto_monero_init256_modm);
/// def check256_modm(val: Sc25519): /// def check256_modm(val: Sc25519):
/// ''' /// """
/// Throws exception if scalar is invalid /// Throws exception if scalar is invalid
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_check256_modm(const mp_obj_t arg) { STATIC mp_obj_t mod_trezorcrypto_monero_check256_modm(const mp_obj_t arg) {
assert_scalar(arg); assert_scalar(arg);
if (check256_modm(MP_OBJ_C_SCALAR(arg)) != 1) { if (check256_modm(MP_OBJ_C_SCALAR(arg)) != 1) {
@ -357,9 +358,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_check256_modm_obj,
mod_trezorcrypto_monero_check256_modm); mod_trezorcrypto_monero_check256_modm);
/// def iszero256_modm(val: Sc25519) -> bool: /// def iszero256_modm(val: Sc25519) -> bool:
/// ''' /// """
/// Returns False if the scalar is zero /// Returns False if the scalar is zero
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_iszero256_modm(const mp_obj_t arg) { STATIC mp_obj_t mod_trezorcrypto_monero_iszero256_modm(const mp_obj_t arg) {
assert_scalar(arg); assert_scalar(arg);
const int r = iszero256_modm(MP_OBJ_C_SCALAR(arg)); const int r = iszero256_modm(MP_OBJ_C_SCALAR(arg));
@ -369,9 +370,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_iszero256_modm_obj,
mod_trezorcrypto_monero_iszero256_modm); mod_trezorcrypto_monero_iszero256_modm);
/// def eq256_modm(a: Sc25519, b: Sc25519) -> int: /// def eq256_modm(a: Sc25519, b: Sc25519) -> int:
/// ''' /// """
/// Compares scalars, returns 1 on the same value /// Compares scalars, returns 1 on the same value
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_eq256_modm(const mp_obj_t a, STATIC mp_obj_t mod_trezorcrypto_monero_eq256_modm(const mp_obj_t a,
const mp_obj_t b) { const mp_obj_t b) {
assert_scalar(a); assert_scalar(a);
@ -383,10 +384,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_monero_eq256_modm_obj,
mod_trezorcrypto_monero_eq256_modm); mod_trezorcrypto_monero_eq256_modm);
/// def get256_modm(a: Sc25519) -> int: /// def get256_modm(a: Sc25519) -> int:
/// ''' /// """
/// Extracts 64bit integer from the scalar. Raises exception if scalar is /// Extracts 64bit integer from the scalar. Raises exception if scalar is
/// bigger than 2^64 /// bigger than 2^64
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_get256_modm(const mp_obj_t arg) { STATIC mp_obj_t mod_trezorcrypto_monero_get256_modm(const mp_obj_t arg) {
assert_scalar(arg); assert_scalar(arg);
uint64_t v; uint64_t v;
@ -399,9 +400,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_get256_modm_obj,
mod_trezorcrypto_monero_get256_modm); mod_trezorcrypto_monero_get256_modm);
/// def add256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519: /// def add256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519:
/// ''' /// """
/// Scalar addition /// Scalar addition
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_add256_modm(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_monero_add256_modm(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
const bool res_arg = n_args == 3; const bool res_arg = n_args == 3;
@ -419,9 +420,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_add256_modm); mod_trezorcrypto_monero_add256_modm);
/// def sub256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519: /// def sub256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519:
/// ''' /// """
/// Scalar subtraction /// Scalar subtraction
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_sub256_modm(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_monero_sub256_modm(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
const bool res_arg = n_args == 3; const bool res_arg = n_args == 3;
@ -439,9 +440,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_sub256_modm); mod_trezorcrypto_monero_sub256_modm);
/// def mul256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519: /// def mul256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519:
/// ''' /// """
/// Scalar multiplication /// Scalar multiplication
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_mul256_modm(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_monero_mul256_modm(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
const bool res_arg = n_args == 3; const bool res_arg = n_args == 3;
@ -458,11 +459,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_mul256_modm_obj, 2, 3, mod_trezorcrypto_monero_mul256_modm_obj, 2, 3,
mod_trezorcrypto_monero_mul256_modm); mod_trezorcrypto_monero_mul256_modm);
/// def mulsub256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519, c: Sc25519) /// def mulsub256_modm(
/// -> Sc25519: /// r: Optional[Sc25519], a: Sc25519, b: Sc25519, c: Sc25519
/// ''' /// ) -> Sc25519:
/// """
/// c - a*b /// c - a*b
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_mulsub256_modm(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_monero_mulsub256_modm(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
const bool res_arg = n_args == 4; const bool res_arg = n_args == 4;
@ -481,11 +483,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_mulsub256_modm_obj, 3, 4, mod_trezorcrypto_monero_mulsub256_modm_obj, 3, 4,
mod_trezorcrypto_monero_mulsub256_modm); mod_trezorcrypto_monero_mulsub256_modm);
/// def muladd256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519, c: Sc25519) /// def muladd256_modm(
/// -> Sc25519: /// r: Optional[Sc25519], a: Sc25519, b: Sc25519, c: Sc25519
/// ''' /// ) -> Sc25519:
/// """
/// c + a*b /// c + a*b
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_muladd256_modm(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_monero_muladd256_modm(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
const bool res_arg = n_args == 4; const bool res_arg = n_args == 4;
@ -505,9 +508,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_muladd256_modm); mod_trezorcrypto_monero_muladd256_modm);
/// def inv256_modm(r: Optional[Sc25519], a: Sc25519) -> Sc25519: /// def inv256_modm(r: Optional[Sc25519], a: Sc25519) -> Sc25519:
/// ''' /// """
/// Scalar modular inversion /// Scalar modular inversion
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_inv256_modm(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_monero_inv256_modm(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
const bool res_arg = n_args == 2; const bool res_arg = n_args == 2;
@ -530,11 +533,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_inv256_modm_obj, 1, 2, mod_trezorcrypto_monero_inv256_modm_obj, 1, 2,
mod_trezorcrypto_monero_inv256_modm); mod_trezorcrypto_monero_inv256_modm);
/// def pack256_modm(r: Optional[bytes], a: Sc25519, offset: Optional[int] = 0) /// def pack256_modm(
/// -> bytes: /// r: Optional[bytes], a: Sc25519, offset: Optional[int] = 0
/// ''' /// ) -> bytes:
/// """
/// Scalar compression /// Scalar compression
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_pack256_modm(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_monero_pack256_modm(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
if (n_args == 1 || args[0] == mp_const_none) { if (n_args == 1 || args[0] == mp_const_none) {
@ -559,11 +563,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_pack256_modm_obj, 1, 3, mod_trezorcrypto_monero_pack256_modm_obj, 1, 3,
mod_trezorcrypto_monero_pack256_modm); mod_trezorcrypto_monero_pack256_modm);
/// def unpack256_modm(r: Optional[Sc25519], a: bytes, offset: int = 0) -> /// def unpack256_modm(
/// Sc25519: /// r: Optional[Sc25519], a: bytes, offset: int = 0
/// ''' /// ) -> Sc25519:
/// """
/// Scalar decompression /// Scalar decompression
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_unpack256_modm(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_monero_unpack256_modm(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
const bool res_arg = n_args >= 2; const bool res_arg = n_args >= 2;
@ -577,11 +582,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_unpack256_modm_obj, 1, 3, mod_trezorcrypto_monero_unpack256_modm_obj, 1, 3,
mod_trezorcrypto_monero_unpack256_modm); mod_trezorcrypto_monero_unpack256_modm);
/// def unpack256_modm_noreduce(r: Optional[Sc25519], a: bytes, offset: int = 0) /// def unpack256_modm_noreduce(
/// -> Sc25519: /// r: Optional[Sc25519], a: bytes, offset: int = 0
/// ''' /// ) -> Sc25519:
/// """
/// Scalar decompression, raw, without modular reduction /// Scalar decompression, raw, without modular reduction
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_unpack256_modm_noreduce( STATIC mp_obj_t mod_trezorcrypto_monero_unpack256_modm_noreduce(
size_t n_args, const mp_obj_t *args) { size_t n_args, const mp_obj_t *args) {
const bool res_arg = n_args >= 2; const bool res_arg = n_args >= 2;
@ -607,9 +613,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
// //
/// def ge25519_set_neutral(r: Optional[Ge25519]) -> Ge25519: /// def ge25519_set_neutral(r: Optional[Ge25519]) -> Ge25519:
/// ''' /// """
/// Sets neutral point /// Sets neutral point
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_set_neutral( STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_set_neutral(
size_t n_args, const mp_obj_t *args) { size_t n_args, const mp_obj_t *args) {
mp_obj_t res = mp_obj_new_ge25519_r(n_args == 1 ? args[0] : mp_const_none); mp_obj_t res = mp_obj_new_ge25519_r(n_args == 1 ? args[0] : mp_const_none);
@ -621,9 +627,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_ge25519_set_neutral); mod_trezorcrypto_monero_ge25519_set_neutral);
/// def ge25519_set_xmr_h(r: Optional[Ge25519]) -> Ge25519: /// def ge25519_set_xmr_h(r: Optional[Ge25519]) -> Ge25519:
/// ''' /// """
/// Sets H point /// Sets H point
/// ''' /// """
STATIC mp_obj_t STATIC mp_obj_t
mod_trezorcrypto_monero_ge25519_set_xmr_h(size_t n_args, const mp_obj_t *args) { mod_trezorcrypto_monero_ge25519_set_xmr_h(size_t n_args, const mp_obj_t *args) {
mp_obj_t res = mp_obj_new_ge25519_r(n_args == 1 ? args[0] : mp_const_none); mp_obj_t res = mp_obj_new_ge25519_r(n_args == 1 ? args[0] : mp_const_none);
@ -635,9 +641,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_ge25519_set_xmr_h); mod_trezorcrypto_monero_ge25519_set_xmr_h);
/// def ge25519_check(r: Ge25519): /// def ge25519_check(r: Ge25519):
/// ''' /// """
/// Checks point, throws if not on curve /// Checks point, throws if not on curve
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_check(const mp_obj_t arg) { STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_check(const mp_obj_t arg) {
assert_ge25519(arg); assert_ge25519(arg);
if (ge25519_check(&MP_OBJ_C_GE25519(arg)) != 1) { if (ge25519_check(&MP_OBJ_C_GE25519(arg)) != 1) {
@ -649,9 +655,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_ge25519_check_obj,
mod_trezorcrypto_monero_ge25519_check); mod_trezorcrypto_monero_ge25519_check);
/// def ge25519_eq(a: Ge25519, b: Ge25519) -> bool: /// def ge25519_eq(a: Ge25519, b: Ge25519) -> bool:
/// ''' /// """
/// Compares EC points /// Compares EC points
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_eq(const mp_obj_t a, STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_eq(const mp_obj_t a,
const mp_obj_t b) { const mp_obj_t b) {
assert_ge25519(a); assert_ge25519(a);
@ -663,9 +669,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_monero_ge25519_eq_obj,
mod_trezorcrypto_monero_ge25519_eq); mod_trezorcrypto_monero_ge25519_eq);
/// def ge25519_add(r: Optional[Ge25519], a: Ge25519, b: Ge25519) -> Ge25519: /// def ge25519_add(r: Optional[Ge25519], a: Ge25519, b: Ge25519) -> Ge25519:
/// ''' /// """
/// Adds EC points /// Adds EC points
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_add(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_add(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
const bool res_arg = n_args == 3; const bool res_arg = n_args == 3;
@ -683,9 +689,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_ge25519_add); mod_trezorcrypto_monero_ge25519_add);
/// def ge25519_sub(r: Optional[Ge25519], a: Ge25519, b: Ge25519) -> Ge25519: /// def ge25519_sub(r: Optional[Ge25519], a: Ge25519, b: Ge25519) -> Ge25519:
/// ''' /// """
/// Subtracts EC points /// Subtracts EC points
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_sub(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_sub(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
const bool res_arg = n_args == 3; const bool res_arg = n_args == 3;
@ -703,9 +709,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_ge25519_sub); mod_trezorcrypto_monero_ge25519_sub);
/// def ge25519_double(r: Optional[Ge25519], p: Ge25519) -> Ge25519: /// def ge25519_double(r: Optional[Ge25519], p: Ge25519) -> Ge25519:
/// ''' /// """
/// EC point doubling /// EC point doubling
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_double(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_double(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
const bool res_arg = n_args == 2; const bool res_arg = n_args == 2;
@ -720,9 +726,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_ge25519_double); mod_trezorcrypto_monero_ge25519_double);
/// def ge25519_mul8(r: Optional[Ge25519], p: Ge25519) -> Ge25519: /// def ge25519_mul8(r: Optional[Ge25519], p: Ge25519) -> Ge25519:
/// ''' /// """
/// EC point * 8 /// EC point * 8
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_mul8(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_mul8(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
const bool res_arg = n_args == 2; const bool res_arg = n_args == 2;
@ -736,11 +742,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_ge25519_mul8_obj, 1, 2, mod_trezorcrypto_monero_ge25519_mul8_obj, 1, 2,
mod_trezorcrypto_monero_ge25519_mul8); mod_trezorcrypto_monero_ge25519_mul8);
/// def ge25519_double_scalarmult_vartime(r: Optional[Ge25519], p1: Ge25519, s1: /// def ge25519_double_scalarmult_vartime(
/// Sc25519, s2: Sc25519) -> Ge25519: /// r: Optional[Ge25519], p1: Ge25519, s1: Sc25519, s2: Sc25519
/// ''' /// ) -> Ge25519:
/// """
/// s1 * G + s2 * p1 /// s1 * G + s2 * p1
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_double_scalarmult_vartime( STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_double_scalarmult_vartime(
size_t n_args, const mp_obj_t *args) { size_t n_args, const mp_obj_t *args) {
const bool res_arg = n_args == 4; const bool res_arg = n_args == 4;
@ -759,11 +766,16 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_ge25519_double_scalarmult_vartime_obj, 3, 4, mod_trezorcrypto_monero_ge25519_double_scalarmult_vartime_obj, 3, 4,
mod_trezorcrypto_monero_ge25519_double_scalarmult_vartime); mod_trezorcrypto_monero_ge25519_double_scalarmult_vartime);
/// def ge25519_double_scalarmult_vartime2(r: Optional[Ge25519], p1: Ge25519, /// def ge25519_double_scalarmult_vartime2(
/// s1: Sc25519, p2: Ge25519, s2: Sc25519) -> Ge25519: /// r: Optional[Ge25519],
/// ''' /// p1: Ge25519,
/// s1: Sc25519,
/// p2: Ge25519,
/// s2: Sc25519,
/// ) -> Ge25519:
/// """
/// s1 * p1 + s2 * p2 /// s1 * p1 + s2 * p2
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_double_scalarmult_vartime2( STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_double_scalarmult_vartime2(
size_t n_args, const mp_obj_t *args) { size_t n_args, const mp_obj_t *args) {
const bool res_arg = n_args == 5; const bool res_arg = n_args == 5;
@ -785,11 +797,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_ge25519_double_scalarmult_vartime2_obj, 4, 5, mod_trezorcrypto_monero_ge25519_double_scalarmult_vartime2_obj, 4, 5,
mod_trezorcrypto_monero_ge25519_double_scalarmult_vartime2); mod_trezorcrypto_monero_ge25519_double_scalarmult_vartime2);
/// def ge25519_scalarmult_base(r: Optional[Ge25519], s: Union[Sc25519, int]) -> /// def ge25519_scalarmult_base(
/// Ge25519: /// r: Optional[Ge25519], s: Union[Sc25519, int]
/// ''' /// ) -> Ge25519:
/// """
/// s * G /// s * G
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_scalarmult_base( STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_scalarmult_base(
size_t n_args, const mp_obj_t *args) { size_t n_args, const mp_obj_t *args) {
const bool res_arg = n_args == 2; const bool res_arg = n_args == 2;
@ -813,11 +826,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_ge25519_scalarmult_base_obj, 1, 2, mod_trezorcrypto_monero_ge25519_scalarmult_base_obj, 1, 2,
mod_trezorcrypto_monero_ge25519_scalarmult_base); mod_trezorcrypto_monero_ge25519_scalarmult_base);
/// def ge25519_scalarmult(r: Optional[Ge25519], p: Ge25519, s: Union[Sc25519, /// def ge25519_scalarmult(
/// int]) -> Ge25519: /// r: Optional[Ge25519], p: Ge25519, s: Union[Sc25519, int]
/// ''' /// ) -> Ge25519:
/// """
/// s * p /// s * p
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_scalarmult( STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_scalarmult(
size_t n_args, const mp_obj_t *args) { size_t n_args, const mp_obj_t *args) {
const bool res_arg = n_args == 3; const bool res_arg = n_args == 3;
@ -844,9 +858,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_ge25519_scalarmult); mod_trezorcrypto_monero_ge25519_scalarmult);
/// def ge25519_pack(r: bytes, p: Ge25519, offset: int = 0) -> bytes: /// def ge25519_pack(r: bytes, p: Ge25519, offset: int = 0) -> bytes:
/// ''' /// """
/// Point compression /// Point compression
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_pack(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_pack(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
if (n_args == 1 || args[0] == mp_const_none) { if (n_args == 1 || args[0] == mp_const_none) {
@ -871,11 +885,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_ge25519_pack_obj, 1, 3, mod_trezorcrypto_monero_ge25519_pack_obj, 1, 3,
mod_trezorcrypto_monero_ge25519_pack); mod_trezorcrypto_monero_ge25519_pack);
/// def ge25519_unpack_vartime(r: Optional[Ge25519], buff: bytes, offset: int = /// def ge25519_unpack_vartime(
/// 0) -> Ge25519: /// r: Optional[Ge25519], buff: bytes, offset: int = 0
/// ''' /// ) -> Ge25519:
/// """
/// Point decompression /// Point decompression
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_unpack_vartime( STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_unpack_vartime(
size_t n_args, const mp_obj_t *args) { size_t n_args, const mp_obj_t *args) {
const bool res_arg = n_args >= 2; const bool res_arg = n_args >= 2;
@ -894,9 +909,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
// //
/// def base58_addr_encode_check(tag: int, buff: bytes) -> bytes: /// def base58_addr_encode_check(tag: int, buff: bytes) -> bytes:
/// ''' /// """
/// Monero block base 58 encoding /// Monero block base 58 encoding
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_base58_addr_encode_check( STATIC mp_obj_t mod_trezorcrypto_monero_xmr_base58_addr_encode_check(
size_t n_args, const mp_obj_t *args) { size_t n_args, const mp_obj_t *args) {
uint8_t out[128]; uint8_t out[128];
@ -916,10 +931,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_xmr_base58_addr_encode_check); mod_trezorcrypto_monero_xmr_base58_addr_encode_check);
/// def base58_addr_decode_check(buff: bytes) -> Tuple[bytes, int]: /// def base58_addr_decode_check(buff: bytes) -> Tuple[bytes, int]:
/// ''' /// """
/// Monero block base 58 decoding, returning (decoded, tag) or raising on /// Monero block base 58 decoding, returning (decoded, tag) or raising on
/// error. /// error.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_base58_addr_decode_check( STATIC mp_obj_t mod_trezorcrypto_monero_xmr_base58_addr_decode_check(
size_t n_args, const mp_obj_t *args) { size_t n_args, const mp_obj_t *args) {
uint8_t out[128]; uint8_t out[128];
@ -944,9 +959,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_xmr_base58_addr_decode_check); mod_trezorcrypto_monero_xmr_base58_addr_decode_check);
/// def xmr_random_scalar(r: Optional[Sc25519] = None) -> Sc25519: /// def xmr_random_scalar(r: Optional[Sc25519] = None) -> Sc25519:
/// ''' /// """
/// Generates a random scalar /// Generates a random scalar
/// ''' /// """
STATIC mp_obj_t STATIC mp_obj_t
mod_trezorcrypto_monero_xmr_random_scalar(size_t n_args, const mp_obj_t *args) { mod_trezorcrypto_monero_xmr_random_scalar(size_t n_args, const mp_obj_t *args) {
mp_obj_t res = mp_obj_new_scalar_r(n_args == 1 ? args[0] : mp_const_none); mp_obj_t res = mp_obj_new_scalar_r(n_args == 1 ? args[0] : mp_const_none);
@ -958,9 +973,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_xmr_random_scalar); mod_trezorcrypto_monero_xmr_random_scalar);
/// def xmr_fast_hash(r: Optional[bytes], buff: bytes) -> bytes: /// def xmr_fast_hash(r: Optional[bytes], buff: bytes) -> bytes:
/// ''' /// """
/// XMR fast hash /// XMR fast hash
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_fast_hash(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_monero_xmr_fast_hash(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
const int off = n_args == 2 ? 0 : -1; const int off = n_args == 2 ? 0 : -1;
@ -985,9 +1000,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_xmr_fast_hash); mod_trezorcrypto_monero_xmr_fast_hash);
/// def xmr_hash_to_ec(r: Optional[Ge25519], buff: bytes) -> Ge25519: /// def xmr_hash_to_ec(r: Optional[Ge25519], buff: bytes) -> Ge25519:
/// ''' /// """
/// XMR hashing to EC point /// XMR hashing to EC point
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_hash_to_ec(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_monero_xmr_hash_to_ec(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
const bool res_arg = n_args == 2; const bool res_arg = n_args == 2;
@ -1003,9 +1018,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_xmr_hash_to_ec); mod_trezorcrypto_monero_xmr_hash_to_ec);
/// def xmr_hash_to_scalar(r: Optional[Sc25519], buff: bytes) -> Sc25519: /// def xmr_hash_to_scalar(r: Optional[Sc25519], buff: bytes) -> Sc25519:
/// ''' /// """
/// XMR hashing to EC scalar /// XMR hashing to EC scalar
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_hash_to_scalar( STATIC mp_obj_t mod_trezorcrypto_monero_xmr_hash_to_scalar(
size_t n_args, const mp_obj_t *args) { size_t n_args, const mp_obj_t *args) {
const bool res_arg = n_args == 2; const bool res_arg = n_args == 2;
@ -1020,11 +1035,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_xmr_hash_to_scalar_obj, 1, 2, mod_trezorcrypto_monero_xmr_hash_to_scalar_obj, 1, 2,
mod_trezorcrypto_monero_xmr_hash_to_scalar); mod_trezorcrypto_monero_xmr_hash_to_scalar);
/// def xmr_derivation_to_scalar(r: Optional[Sc25519], p: Ge25519, output_index: /// def xmr_derivation_to_scalar(
/// int) -> Sc25519: /// r: Optional[Sc25519], p: Ge25519, output_index: int
/// ''' /// ) -> Sc25519:
/// """
/// H_s(derivation || varint(output_index)) /// H_s(derivation || varint(output_index))
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_derivation_to_scalar( STATIC mp_obj_t mod_trezorcrypto_monero_xmr_derivation_to_scalar(
size_t n_args, const mp_obj_t *args) { size_t n_args, const mp_obj_t *args) {
const bool res_arg = n_args == 3; const bool res_arg = n_args == 3;
@ -1039,11 +1055,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_xmr_derivation_to_scalar_obj, 2, 3, mod_trezorcrypto_monero_xmr_derivation_to_scalar_obj, 2, 3,
mod_trezorcrypto_monero_xmr_derivation_to_scalar); mod_trezorcrypto_monero_xmr_derivation_to_scalar);
/// def xmr_generate_key_derivation(r: Optional[Ge25519], A: Ge25519, b: /// def xmr_generate_key_derivation(
/// Sc25519) -> Ge25519: /// r: Optional[Ge25519], A: Ge25519, b: Sc25519
/// ''' /// ) -> Ge25519:
/// """
/// 8*(key2*key1) /// 8*(key2*key1)
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_generate_key_derivation( STATIC mp_obj_t mod_trezorcrypto_monero_xmr_generate_key_derivation(
size_t n_args, const mp_obj_t *args) { size_t n_args, const mp_obj_t *args) {
const bool res_arg = n_args == 3; const bool res_arg = n_args == 3;
@ -1060,11 +1077,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_xmr_generate_key_derivation_obj, 2, 3, mod_trezorcrypto_monero_xmr_generate_key_derivation_obj, 2, 3,
mod_trezorcrypto_monero_xmr_generate_key_derivation); mod_trezorcrypto_monero_xmr_generate_key_derivation);
/// def xmr_derive_private_key(r: Optional[Sc25519], deriv: Ge25519, idx: int, /// def xmr_derive_private_key(
/// base: Sc25519) -> Sc25519: /// r: Optional[Sc25519], deriv: Ge25519, idx: int, base: Sc25519
/// ''' /// ) -> Sc25519:
/// """
/// base + H_s(derivation || varint(output_index)) /// base + H_s(derivation || varint(output_index))
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_derive_private_key( STATIC mp_obj_t mod_trezorcrypto_monero_xmr_derive_private_key(
size_t n_args, const mp_obj_t *args) { size_t n_args, const mp_obj_t *args) {
const bool res_arg = n_args == 4; const bool res_arg = n_args == 4;
@ -1081,11 +1099,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_xmr_derive_private_key_obj, 3, 4, mod_trezorcrypto_monero_xmr_derive_private_key_obj, 3, 4,
mod_trezorcrypto_monero_xmr_derive_private_key); mod_trezorcrypto_monero_xmr_derive_private_key);
/// def xmr_derive_public_key(r: Optional[Ge25519], deriv: Ge25519, idx: int, /// def xmr_derive_public_key(
/// base: Ge25519) -> Ge25519: /// r: Optional[Ge25519], deriv: Ge25519, idx: int, base: Ge25519
/// ''' /// ) -> Ge25519:
/// """
/// H_s(derivation || varint(output_index))G + base /// H_s(derivation || varint(output_index))G + base
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_derive_public_key( STATIC mp_obj_t mod_trezorcrypto_monero_xmr_derive_public_key(
size_t n_args, const mp_obj_t *args) { size_t n_args, const mp_obj_t *args) {
const bool res_arg = n_args == 4; const bool res_arg = n_args == 4;
@ -1102,11 +1121,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_xmr_derive_public_key_obj, 3, 4, mod_trezorcrypto_monero_xmr_derive_public_key_obj, 3, 4,
mod_trezorcrypto_monero_xmr_derive_public_key); mod_trezorcrypto_monero_xmr_derive_public_key);
/// def xmr_add_keys2(r: Optional[Ge25519], a: Sc25519, b: Sc25519, B: Ge25519) /// def xmr_add_keys2(
/// -> Ge25519: /// r: Optional[Ge25519], a: Sc25519, b: Sc25519, B: Ge25519
/// ''' /// ) -> Ge25519:
/// """
/// aG + bB, G is basepoint /// aG + bB, G is basepoint
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_add_keys2(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_monero_xmr_add_keys2(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
const bool res_arg = n_args == 4; const bool res_arg = n_args == 4;
@ -1123,11 +1143,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_xmr_add_keys2_obj, 3, 4, mod_trezorcrypto_monero_xmr_add_keys2_obj, 3, 4,
mod_trezorcrypto_monero_xmr_add_keys2); mod_trezorcrypto_monero_xmr_add_keys2);
/// def xmr_add_keys2_vartime(r: Optional[Ge25519], a: Sc25519, b: Sc25519, B: /// def xmr_add_keys2_vartime(
/// Ge25519) -> Ge25519: /// r: Optional[Ge25519], a: Sc25519, b: Sc25519, B: Ge25519
/// ''' /// ) -> Ge25519:
/// """
/// aG + bB, G is basepoint /// aG + bB, G is basepoint
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_add_keys2_vartime( STATIC mp_obj_t mod_trezorcrypto_monero_xmr_add_keys2_vartime(
size_t n_args, const mp_obj_t *args) { size_t n_args, const mp_obj_t *args) {
const bool res_arg = n_args == 4; const bool res_arg = n_args == 4;
@ -1145,11 +1166,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_xmr_add_keys2_vartime_obj, 3, 4, mod_trezorcrypto_monero_xmr_add_keys2_vartime_obj, 3, 4,
mod_trezorcrypto_monero_xmr_add_keys2_vartime); mod_trezorcrypto_monero_xmr_add_keys2_vartime);
/// def xmr_add_keys3(r: Optional[Ge25519], a: Sc25519, A: Ge25519, b: Sc25519, /// def xmr_add_keys3(
/// B: Ge25519) -> Ge25519: /// r: Optional[Ge25519], a: Sc25519, A: Ge25519, b: Sc25519, B: Ge25519
/// ''' /// ) -> Ge25519:
/// """
/// aA + bB /// aA + bB
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_add_keys3(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_monero_xmr_add_keys3(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
const bool res_arg = n_args == 5; const bool res_arg = n_args == 5;
@ -1168,11 +1190,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_xmr_add_keys3_obj, 4, 5, mod_trezorcrypto_monero_xmr_add_keys3_obj, 4, 5,
mod_trezorcrypto_monero_xmr_add_keys3); mod_trezorcrypto_monero_xmr_add_keys3);
/// def xmr_add_keys3_vartime(r: Optional[Ge25519], a: Sc25519, A: Ge25519, b: /// def xmr_add_keys3_vartime(
/// Sc25519, B: Ge25519) -> Ge25519: /// r: Optional[Ge25519], a: Sc25519, A: Ge25519, b: Sc25519, B: Ge25519
/// ''' /// ) -> Ge25519:
/// """
/// aA + bB /// aA + bB
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_add_keys3_vartime( STATIC mp_obj_t mod_trezorcrypto_monero_xmr_add_keys3_vartime(
size_t n_args, const mp_obj_t *args) { size_t n_args, const mp_obj_t *args) {
const bool res_arg = n_args == 5; const bool res_arg = n_args == 5;
@ -1192,11 +1215,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_xmr_add_keys3_vartime_obj, 4, 5, mod_trezorcrypto_monero_xmr_add_keys3_vartime_obj, 4, 5,
mod_trezorcrypto_monero_xmr_add_keys3_vartime); mod_trezorcrypto_monero_xmr_add_keys3_vartime);
/// def xmr_get_subaddress_secret_key(r: Optional[Sc25519], major: int, minor: /// def xmr_get_subaddress_secret_key(
/// int, m: Sc25519) -> Sc25519: /// r: Optional[Sc25519], major: int, minor: int, m: Sc25519
/// ''' /// ) -> Sc25519:
/// """
/// Hs(SubAddr || a || index_major || index_minor) /// Hs(SubAddr || a || index_major || index_minor)
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_get_subaddress_secret_key( STATIC mp_obj_t mod_trezorcrypto_monero_xmr_get_subaddress_secret_key(
size_t n_args, const mp_obj_t *args) { size_t n_args, const mp_obj_t *args) {
const bool res_arg = n_args == 4; const bool res_arg = n_args == 4;
@ -1213,9 +1237,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_xmr_get_subaddress_secret_key); mod_trezorcrypto_monero_xmr_get_subaddress_secret_key);
/// def xmr_gen_c(r: Optional[Ge25519], a: Sc25519, amount: int) -> Ge25519: /// def xmr_gen_c(r: Optional[Ge25519], a: Sc25519, amount: int) -> Ge25519:
/// ''' /// """
/// aG + amount * H /// aG + amount * H
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_gen_c(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_monero_xmr_gen_c(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
const bool res_arg = n_args == 3; const bool res_arg = n_args == 3;
@ -1231,9 +1255,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_xmr_gen_c); mod_trezorcrypto_monero_xmr_gen_c);
/// def ct_equals(a: bytes, b: bytes) -> bool: /// def ct_equals(a: bytes, b: bytes) -> bool:
/// ''' /// """
/// Constant time buffer comparison /// Constant time buffer comparison
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_ct_equals(const mp_obj_t a, const mp_obj_t b) { STATIC mp_obj_t mod_trezorcrypto_ct_equals(const mp_obj_t a, const mp_obj_t b) {
mp_buffer_info_t buff_a, buff_b; mp_buffer_info_t buff_a, buff_b;
mp_get_buffer_raise(a, &buff_a, MP_BUFFER_READ); mp_get_buffer_raise(a, &buff_a, MP_BUFFER_READ);

@ -26,9 +26,9 @@
/// package: trezorcrypto.nem /// package: trezorcrypto.nem
/// def validate_address(address: str, network: int) -> bool: /// def validate_address(address: str, network: int) -> bool:
/// ''' /// """
/// Validate a NEM address /// Validate a NEM address
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_nem_validate_address(mp_obj_t address, STATIC mp_obj_t mod_trezorcrypto_nem_validate_address(mp_obj_t address,
mp_obj_t network) { mp_obj_t network) {
mp_buffer_info_t addr; mp_buffer_info_t addr;
@ -41,9 +41,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_nem_validate_address_obj,
mod_trezorcrypto_nem_validate_address); mod_trezorcrypto_nem_validate_address);
/// def compute_address(public_key: bytes, network: int) -> str: /// def compute_address(public_key: bytes, network: int) -> str:
/// ''' /// """
/// Compute a NEM address from a public key /// Compute a NEM address from a public key
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_nem_compute_address(mp_obj_t public_key, STATIC mp_obj_t mod_trezorcrypto_nem_compute_address(mp_obj_t public_key,
mp_obj_t network) { mp_obj_t network) {
mp_buffer_info_t p; mp_buffer_info_t p;

@ -25,9 +25,9 @@
/// package: trezorcrypto.nist256p1 /// package: trezorcrypto.nist256p1
/// def generate_secret() -> bytes: /// def generate_secret() -> bytes:
/// ''' /// """
/// Generate secret key. /// Generate secret key.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_nist256p1_generate_secret() { STATIC mp_obj_t mod_trezorcrypto_nist256p1_generate_secret() {
uint8_t out[32]; uint8_t out[32];
for (;;) { for (;;) {
@ -55,9 +55,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_nist256p1_generate_secret_obj,
mod_trezorcrypto_nist256p1_generate_secret); mod_trezorcrypto_nist256p1_generate_secret);
/// def publickey(secret_key: bytes, compressed: bool = True) -> bytes: /// def publickey(secret_key: bytes, compressed: bool = True) -> bytes:
/// ''' /// """
/// Computes public key from secret key. /// Computes public key from secret key.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_nist256p1_publickey(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_nist256p1_publickey(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_buffer_info_t sk; mp_buffer_info_t sk;
@ -80,11 +80,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_nist256p1_publickey_obj, 1, 2, mod_trezorcrypto_nist256p1_publickey_obj, 1, 2,
mod_trezorcrypto_nist256p1_publickey); mod_trezorcrypto_nist256p1_publickey);
/// def sign(secret_key: bytes, digest: bytes, compressed: bool = True) -> /// def sign(
/// bytes: /// secret_key: bytes, digest: bytes, compressed: bool = True
/// ''' /// ) -> bytes:
/// """
/// Uses secret key to produce the signature of the digest. /// Uses secret key to produce the signature of the digest.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_nist256p1_sign(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_nist256p1_sign(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_buffer_info_t sk, dig; mp_buffer_info_t sk, dig;
@ -110,10 +111,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_nist256p1_sign_obj,
mod_trezorcrypto_nist256p1_sign); mod_trezorcrypto_nist256p1_sign);
/// def verify(public_key: bytes, signature: bytes, digest: bytes) -> bool: /// def verify(public_key: bytes, signature: bytes, digest: bytes) -> bool:
/// ''' /// """
/// Uses public key to verify the signature of the digest. /// Uses public key to verify the signature of the digest.
/// Returns True on success. /// Returns True on success.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_nist256p1_verify(mp_obj_t public_key, STATIC mp_obj_t mod_trezorcrypto_nist256p1_verify(mp_obj_t public_key,
mp_obj_t signature, mp_obj_t signature,
mp_obj_t digest) { mp_obj_t digest) {
@ -140,10 +141,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_nist256p1_verify_obj,
mod_trezorcrypto_nist256p1_verify); mod_trezorcrypto_nist256p1_verify);
/// def verify_recover(signature: bytes, digest: bytes) -> bytes: /// def verify_recover(signature: bytes, digest: bytes) -> bytes:
/// ''' /// """
/// Uses signature of the digest to verify the digest and recover the public /// Uses signature of the digest to verify the digest and recover the public
/// key. Returns public key on success, None if the signature is invalid. /// key. Returns public key on success, None if the signature is invalid.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_nist256p1_verify_recover(mp_obj_t signature, STATIC mp_obj_t mod_trezorcrypto_nist256p1_verify_recover(mp_obj_t signature,
mp_obj_t digest) { mp_obj_t digest) {
mp_buffer_info_t sig, dig; mp_buffer_info_t sig, dig;
@ -178,10 +179,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_nist256p1_verify_recover_obj,
mod_trezorcrypto_nist256p1_verify_recover); mod_trezorcrypto_nist256p1_verify_recover);
/// def multiply(secret_key: bytes, public_key: bytes) -> bytes: /// def multiply(secret_key: bytes, public_key: bytes) -> bytes:
/// ''' /// """
/// Multiplies point defined by public_key with scalar defined by /// Multiplies point defined by public_key with scalar defined by
/// secret_key. Useful for ECDH. /// secret_key. Useful for ECDH.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_nist256p1_multiply(mp_obj_t secret_key, STATIC mp_obj_t mod_trezorcrypto_nist256p1_multiply(mp_obj_t secret_key,
mp_obj_t public_key) { mp_obj_t public_key) {
mp_buffer_info_t sk, pk; mp_buffer_info_t sk, pk;

@ -28,9 +28,9 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Pbkdf2: /// class Pbkdf2:
/// ''' /// """
/// PBKDF2 context. /// PBKDF2 context.
/// ''' /// """
typedef struct _mp_obj_Pbkdf2_t { typedef struct _mp_obj_Pbkdf2_t {
mp_obj_base_t base; mp_obj_base_t base;
union { union {
@ -42,11 +42,18 @@ typedef struct _mp_obj_Pbkdf2_t {
STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_update(mp_obj_t self, mp_obj_t data); STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, prf: int, password: bytes, salt: bytes, iterations: int =
/// None, blocknr: int = 1) -> None: /// def __init__(
/// ''' /// self,
/// prf: int,
/// password: bytes,
/// salt: bytes,
/// iterations: int = None,
/// blocknr: int = 1,
/// ) -> None:
/// """
/// Create a PBKDF2 context. /// Create a PBKDF2 context.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -89,9 +96,9 @@ STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_make_new(const mp_obj_type_t *type,
} }
/// def update(self, iterations: int) -> None: /// def update(self, iterations: int) -> None:
/// ''' /// """
/// Update a PBKDF2 context. /// Update a PBKDF2 context.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_update(mp_obj_t self, STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_update(mp_obj_t self,
mp_obj_t iterations) { mp_obj_t iterations) {
mp_obj_Pbkdf2_t *o = MP_OBJ_TO_PTR(self); mp_obj_Pbkdf2_t *o = MP_OBJ_TO_PTR(self);
@ -108,9 +115,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Pbkdf2_update_obj,
mod_trezorcrypto_Pbkdf2_update); mod_trezorcrypto_Pbkdf2_update);
/// def key(self) -> bytes: /// def key(self) -> bytes:
/// ''' /// """
/// Retrieve derived key. /// Retrieve derived key.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_key(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_key(mp_obj_t self) {
mp_obj_Pbkdf2_t *o = MP_OBJ_TO_PTR(self); mp_obj_Pbkdf2_t *o = MP_OBJ_TO_PTR(self);
if (o->prf == PRF_HMAC_SHA256) { if (o->prf == PRF_HMAC_SHA256) {

@ -26,9 +26,9 @@
/// package: trezorcrypto.random /// package: trezorcrypto.random
/// def uniform(n: int) -> int: /// def uniform(n: int) -> int:
/// ''' /// """
/// Compute uniform random number from interval 0 ... n - 1. /// Compute uniform random number from interval 0 ... n - 1.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_random_uniform(mp_obj_t n) { STATIC mp_obj_t mod_trezorcrypto_random_uniform(mp_obj_t n) {
uint32_t nn = trezor_obj_get_uint(n); uint32_t nn = trezor_obj_get_uint(n);
if (nn == 0) { if (nn == 0) {
@ -40,9 +40,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_random_uniform_obj,
mod_trezorcrypto_random_uniform); mod_trezorcrypto_random_uniform);
/// def bytes(len: int) -> bytes: /// def bytes(len: int) -> bytes:
/// ''' /// """
/// Generate random bytes sequence of length len. /// Generate random bytes sequence of length len.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_random_bytes(mp_obj_t len) { STATIC mp_obj_t mod_trezorcrypto_random_bytes(mp_obj_t len) {
uint32_t l = trezor_obj_get_uint(len); uint32_t l = trezor_obj_get_uint(len);
if (l > 1024) { if (l > 1024) {
@ -57,9 +57,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_random_bytes_obj,
mod_trezorcrypto_random_bytes); mod_trezorcrypto_random_bytes);
/// def shuffle(data: list) -> None: /// def shuffle(data: list) -> None:
/// ''' /// """
/// Shuffles items of given list (in-place). /// Shuffles items of given list (in-place).
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_random_shuffle(mp_obj_t data) { STATIC mp_obj_t mod_trezorcrypto_random_shuffle(mp_obj_t data) {
size_t count; size_t count;
mp_obj_t *items; mp_obj_t *items;

@ -24,18 +24,18 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Rfc6979: /// class Rfc6979:
/// ''' /// """
/// RFC6979 context. /// RFC6979 context.
/// ''' /// """
typedef struct _mp_obj_Rfc6979_t { typedef struct _mp_obj_Rfc6979_t {
mp_obj_base_t base; mp_obj_base_t base;
rfc6979_state rng; rfc6979_state rng;
} mp_obj_Rfc6979_t; } mp_obj_Rfc6979_t;
/// def __init__(self, secret_key: bytes, hash: bytes) -> None: /// def __init__(self, secret_key: bytes, hash: bytes) -> None:
/// ''' /// """
/// Initialize RFC6979 context from secret key and a hash. /// Initialize RFC6979 context from secret key and a hash.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Rfc6979_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorcrypto_Rfc6979_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -56,9 +56,9 @@ STATIC mp_obj_t mod_trezorcrypto_Rfc6979_make_new(const mp_obj_type_t *type,
} }
/// def next(self) -> bytes: /// def next(self) -> bytes:
/// ''' /// """
/// Compute next 32-bytes of pseudorandom data. /// Compute next 32-bytes of pseudorandom data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Rfc6979_next(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_Rfc6979_next(mp_obj_t self) {
mp_obj_Rfc6979_t *o = MP_OBJ_TO_PTR(self); mp_obj_Rfc6979_t *o = MP_OBJ_TO_PTR(self);
uint8_t out[32]; uint8_t out[32];

@ -25,9 +25,9 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Ripemd160: /// class Ripemd160:
/// ''' /// """
/// RIPEMD160 context. /// RIPEMD160 context.
/// ''' /// """
typedef struct _mp_obj_Ripemd160_t { typedef struct _mp_obj_Ripemd160_t {
mp_obj_base_t base; mp_obj_base_t base;
RIPEMD160_CTX ctx; RIPEMD160_CTX ctx;
@ -36,9 +36,9 @@ typedef struct _mp_obj_Ripemd160_t {
STATIC mp_obj_t mod_trezorcrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data); STATIC mp_obj_t mod_trezorcrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None) -> None: /// def __init__(self, data: bytes = None) -> None:
/// ''' /// """
/// Creates a hash context object. /// Creates a hash context object.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Ripemd160_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorcrypto_Ripemd160_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -54,9 +54,9 @@ STATIC mp_obj_t mod_trezorcrypto_Ripemd160_make_new(const mp_obj_type_t *type,
} }
/// def update(self, data: bytes) -> None: /// def update(self, data: bytes) -> None:
/// ''' /// """
/// Update the hash context with hashed data. /// Update the hash context with hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Ripemd160_update(mp_obj_t self, STATIC mp_obj_t mod_trezorcrypto_Ripemd160_update(mp_obj_t self,
mp_obj_t data) { mp_obj_t data) {
mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self); mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self);
@ -71,9 +71,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Ripemd160_update_obj,
mod_trezorcrypto_Ripemd160_update); mod_trezorcrypto_Ripemd160_update);
/// def digest(self) -> bytes: /// def digest(self) -> bytes:
/// ''' /// """
/// Returns the digest of hashed data. /// Returns the digest of hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Ripemd160_digest(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_Ripemd160_digest(mp_obj_t self) {
mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self); mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self);
uint8_t out[RIPEMD160_DIGEST_LENGTH]; uint8_t out[RIPEMD160_DIGEST_LENGTH];

@ -25,9 +25,9 @@
/// package: trezorcrypto.secp256k1 /// package: trezorcrypto.secp256k1
/// def generate_secret() -> bytes: /// def generate_secret() -> bytes:
/// ''' /// """
/// Generate secret key. /// Generate secret key.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_secp256k1_generate_secret() { STATIC mp_obj_t mod_trezorcrypto_secp256k1_generate_secret() {
uint8_t out[32]; uint8_t out[32];
for (;;) { for (;;) {
@ -55,9 +55,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_secp256k1_generate_secret_obj,
mod_trezorcrypto_secp256k1_generate_secret); mod_trezorcrypto_secp256k1_generate_secret);
/// def publickey(secret_key: bytes, compressed: bool = True) -> bytes: /// def publickey(secret_key: bytes, compressed: bool = True) -> bytes:
/// ''' /// """
/// Computes public key from secret key. /// Computes public key from secret key.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_secp256k1_publickey(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_secp256k1_publickey(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_buffer_info_t sk; mp_buffer_info_t sk;
@ -98,11 +98,15 @@ enum {
CANONICAL_SIG_EOS = 2, CANONICAL_SIG_EOS = 2,
}; };
/// def sign(secret_key: bytes, digest: bytes, compressed: bool = True, /// def sign(
/// canonical: int = None) -> bytes: /// secret_key: bytes,
/// ''' /// digest: bytes,
/// compressed: bool = True,
/// canonical: int = None,
/// ) -> bytes:
/// """
/// Uses secret key to produce the signature of the digest. /// Uses secret key to produce the signature of the digest.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_secp256k1_sign(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_secp256k1_sign(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_buffer_info_t sk, dig; mp_buffer_info_t sk, dig;
@ -139,10 +143,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_secp256k1_sign_obj,
mod_trezorcrypto_secp256k1_sign); mod_trezorcrypto_secp256k1_sign);
/// def verify(public_key: bytes, signature: bytes, digest: bytes) -> bool: /// def verify(public_key: bytes, signature: bytes, digest: bytes) -> bool:
/// ''' /// """
/// Uses public key to verify the signature of the digest. /// Uses public key to verify the signature of the digest.
/// Returns True on success. /// Returns True on success.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_secp256k1_verify(mp_obj_t public_key, STATIC mp_obj_t mod_trezorcrypto_secp256k1_verify(mp_obj_t public_key,
mp_obj_t signature, mp_obj_t signature,
mp_obj_t digest) { mp_obj_t digest) {
@ -169,10 +173,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_secp256k1_verify_obj,
mod_trezorcrypto_secp256k1_verify); mod_trezorcrypto_secp256k1_verify);
/// def verify_recover(signature: bytes, digest: bytes) -> bytes: /// def verify_recover(signature: bytes, digest: bytes) -> bytes:
/// ''' /// """
/// Uses signature of the digest to verify the digest and recover the public /// Uses signature of the digest to verify the digest and recover the public
/// key. Returns public key on success, None if the signature is invalid. /// key. Returns public key on success, None if the signature is invalid.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_secp256k1_verify_recover(mp_obj_t signature, STATIC mp_obj_t mod_trezorcrypto_secp256k1_verify_recover(mp_obj_t signature,
mp_obj_t digest) { mp_obj_t digest) {
mp_buffer_info_t sig, dig; mp_buffer_info_t sig, dig;
@ -207,10 +211,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_secp256k1_verify_recover_obj,
mod_trezorcrypto_secp256k1_verify_recover); mod_trezorcrypto_secp256k1_verify_recover);
/// def multiply(secret_key: bytes, public_key: bytes) -> bytes: /// def multiply(secret_key: bytes, public_key: bytes) -> bytes:
/// ''' /// """
/// Multiplies point defined by public_key with scalar defined by /// Multiplies point defined by public_key with scalar defined by
/// secret_key. Useful for ECDH. /// secret_key. Useful for ECDH.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_secp256k1_multiply(mp_obj_t secret_key, STATIC mp_obj_t mod_trezorcrypto_secp256k1_multiply(mp_obj_t secret_key,
mp_obj_t public_key) { mp_obj_t public_key) {
mp_buffer_info_t sk, pk; mp_buffer_info_t sk, pk;

@ -64,10 +64,13 @@ STATIC const secp256k1_context *mod_trezorcrypto_secp256k1_context(void) {
return ctx; return ctx;
} }
/// package: trezorcrypto.secp256k1_zkp
/// def generate_secret() -> bytes: /// def generate_secret() -> bytes:
/// ''' /// """
/// Generate secret key. /// Generate secret key.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_secp256k1_zkp_generate_secret() { STATIC mp_obj_t mod_trezorcrypto_secp256k1_zkp_generate_secret() {
uint8_t out[32]; uint8_t out[32];
for (;;) { for (;;) {
@ -94,9 +97,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(
mod_trezorcrypto_secp256k1_zkp_generate_secret); mod_trezorcrypto_secp256k1_zkp_generate_secret);
/// def publickey(secret_key: bytes, compressed: bool = True) -> bytes: /// def publickey(secret_key: bytes, compressed: bool = True) -> bytes:
/// ''' /// """
/// Computes public key from secret key. /// Computes public key from secret key.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_secp256k1_zkp_publickey(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_secp256k1_zkp_publickey(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
const secp256k1_context *ctx = mod_trezorcrypto_secp256k1_context(); const secp256k1_context *ctx = mod_trezorcrypto_secp256k1_context();
@ -122,11 +125,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_secp256k1_zkp_publickey_obj, 1, 2, mod_trezorcrypto_secp256k1_zkp_publickey_obj, 1, 2,
mod_trezorcrypto_secp256k1_zkp_publickey); mod_trezorcrypto_secp256k1_zkp_publickey);
/// def sign(secret_key: bytes, digest: bytes, compressed: bool = True) -> /// def sign(
/// bytes: /// secret_key: bytes, digest: bytes, compressed: bool = True
/// ''' /// ) -> bytes:
/// """
/// Uses secret key to produce the signature of the digest. /// Uses secret key to produce the signature of the digest.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_secp256k1_zkp_sign(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_secp256k1_zkp_sign(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
const secp256k1_context *ctx = mod_trezorcrypto_secp256k1_context(); const secp256k1_context *ctx = mod_trezorcrypto_secp256k1_context();
@ -157,10 +161,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_secp256k1_zkp_sign); mod_trezorcrypto_secp256k1_zkp_sign);
/// def verify(public_key: bytes, signature: bytes, digest: bytes) -> bool: /// def verify(public_key: bytes, signature: bytes, digest: bytes) -> bool:
/// ''' /// """
/// Uses public key to verify the signature of the digest. /// Uses public key to verify the signature of the digest.
/// Returns True on success. /// Returns True on success.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_secp256k1_zkp_verify(mp_obj_t public_key, STATIC mp_obj_t mod_trezorcrypto_secp256k1_zkp_verify(mp_obj_t public_key,
mp_obj_t signature, mp_obj_t signature,
mp_obj_t digest) { mp_obj_t digest) {
@ -197,10 +201,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_secp256k1_zkp_verify_obj,
mod_trezorcrypto_secp256k1_zkp_verify); mod_trezorcrypto_secp256k1_zkp_verify);
/// def verify_recover(signature: bytes, digest: bytes) -> bytes: /// def verify_recover(signature: bytes, digest: bytes) -> bytes:
/// ''' /// """
/// Uses signature of the digest to verify the digest and recover the public /// Uses signature of the digest to verify the digest and recover the public
/// key. Returns public key on success, None if the signature is invalid. /// key. Returns public key on success, None if the signature is invalid.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_secp256k1_zkp_verify_recover( STATIC mp_obj_t mod_trezorcrypto_secp256k1_zkp_verify_recover(
mp_obj_t signature, mp_obj_t digest) { mp_obj_t signature, mp_obj_t digest) {
const secp256k1_context *ctx = mod_trezorcrypto_secp256k1_context(); const secp256k1_context *ctx = mod_trezorcrypto_secp256k1_context();
@ -250,10 +254,10 @@ static int secp256k1_ecdh_hash_passthrough(uint8_t *output, const uint8_t *x,
} }
/// def multiply(secret_key: bytes, public_key: bytes) -> bytes: /// def multiply(secret_key: bytes, public_key: bytes) -> bytes:
/// ''' /// """
/// Multiplies point defined by public_key with scalar defined by /// Multiplies point defined by public_key with scalar defined by
/// secret_key. Useful for ECDH. /// secret_key. Useful for ECDH.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_secp256k1_zkp_multiply(mp_obj_t secret_key, STATIC mp_obj_t mod_trezorcrypto_secp256k1_zkp_multiply(mp_obj_t secret_key,
mp_obj_t public_key) { mp_obj_t public_key) {
const secp256k1_context *ctx = mod_trezorcrypto_secp256k1_context(); const secp256k1_context *ctx = mod_trezorcrypto_secp256k1_context();

@ -25,9 +25,9 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Sha1: /// class Sha1:
/// ''' /// """
/// SHA1 context. /// SHA1 context.
/// ''' /// """
typedef struct _mp_obj_Sha1_t { typedef struct _mp_obj_Sha1_t {
mp_obj_base_t base; mp_obj_base_t base;
SHA1_CTX ctx; SHA1_CTX ctx;
@ -36,9 +36,9 @@ typedef struct _mp_obj_Sha1_t {
STATIC mp_obj_t mod_trezorcrypto_Sha1_update(mp_obj_t self, mp_obj_t data); STATIC mp_obj_t mod_trezorcrypto_Sha1_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None) -> None: /// def __init__(self, data: bytes = None) -> None:
/// ''' /// """
/// Creates a hash context object. /// Creates a hash context object.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Sha1_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorcrypto_Sha1_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -54,9 +54,9 @@ STATIC mp_obj_t mod_trezorcrypto_Sha1_make_new(const mp_obj_type_t *type,
} }
/// def update(self, data: bytes) -> None: /// def update(self, data: bytes) -> None:
/// ''' /// """
/// Update the hash context with hashed data. /// Update the hash context with hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Sha1_update(mp_obj_t self, mp_obj_t data) { STATIC mp_obj_t mod_trezorcrypto_Sha1_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Sha1_t *o = MP_OBJ_TO_PTR(self); mp_obj_Sha1_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t msg; mp_buffer_info_t msg;
@ -70,9 +70,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha1_update_obj,
mod_trezorcrypto_Sha1_update); mod_trezorcrypto_Sha1_update);
/// def digest(self) -> bytes: /// def digest(self) -> bytes:
/// ''' /// """
/// Returns the digest of hashed data. /// Returns the digest of hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Sha1_digest(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_Sha1_digest(mp_obj_t self) {
mp_obj_Sha1_t *o = MP_OBJ_TO_PTR(self); mp_obj_Sha1_t *o = MP_OBJ_TO_PTR(self);
uint8_t out[SHA1_DIGEST_LENGTH]; uint8_t out[SHA1_DIGEST_LENGTH];

@ -25,9 +25,9 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Sha256: /// class Sha256:
/// ''' /// """
/// SHA256 context. /// SHA256 context.
/// ''' /// """
typedef struct _mp_obj_Sha256_t { typedef struct _mp_obj_Sha256_t {
mp_obj_base_t base; mp_obj_base_t base;
SHA256_CTX ctx; SHA256_CTX ctx;
@ -36,9 +36,9 @@ typedef struct _mp_obj_Sha256_t {
STATIC mp_obj_t mod_trezorcrypto_Sha256_update(mp_obj_t self, mp_obj_t data); STATIC mp_obj_t mod_trezorcrypto_Sha256_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None) -> None: /// def __init__(self, data: bytes = None) -> None:
/// ''' /// """
/// Creates a hash context object. /// Creates a hash context object.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Sha256_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorcrypto_Sha256_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -54,9 +54,9 @@ STATIC mp_obj_t mod_trezorcrypto_Sha256_make_new(const mp_obj_type_t *type,
} }
/// def update(self, data: bytes) -> None: /// def update(self, data: bytes) -> None:
/// ''' /// """
/// Update the hash context with hashed data. /// Update the hash context with hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Sha256_update(mp_obj_t self, mp_obj_t data) { STATIC mp_obj_t mod_trezorcrypto_Sha256_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self); mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t msg; mp_buffer_info_t msg;
@ -70,9 +70,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha256_update_obj,
mod_trezorcrypto_Sha256_update); mod_trezorcrypto_Sha256_update);
/// def digest(self) -> bytes: /// def digest(self) -> bytes:
/// ''' /// """
/// Returns the digest of hashed data. /// Returns the digest of hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Sha256_digest(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_Sha256_digest(mp_obj_t self) {
mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self); mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self);
uint8_t out[SHA256_DIGEST_LENGTH]; uint8_t out[SHA256_DIGEST_LENGTH];

@ -25,9 +25,9 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Sha3_256: /// class Sha3_256:
/// ''' /// """
/// SHA3_256 context. /// SHA3_256 context.
/// ''' /// """
typedef struct _mp_obj_Sha3_256_t { typedef struct _mp_obj_Sha3_256_t {
mp_obj_base_t base; mp_obj_base_t base;
SHA3_CTX ctx; SHA3_CTX ctx;
@ -36,10 +36,10 @@ typedef struct _mp_obj_Sha3_256_t {
STATIC mp_obj_t mod_trezorcrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data); STATIC mp_obj_t mod_trezorcrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None, keccak = False) -> None: /// def __init__(self, data: bytes = None, keccak: bool = False) -> None:
/// ''' /// """
/// Creates a hash context object. /// Creates a hash context object.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Sha3_256_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorcrypto_Sha3_256_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -67,9 +67,9 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_256_make_new(const mp_obj_type_t *type,
} }
/// def update(self, data: bytes) -> None: /// def update(self, data: bytes) -> None:
/// ''' /// """
/// Update the hash context with hashed data. /// Update the hash context with hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data) { STATIC mp_obj_t mod_trezorcrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(self); mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t msg; mp_buffer_info_t msg;
@ -83,9 +83,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha3_256_update_obj,
mod_trezorcrypto_Sha3_256_update); mod_trezorcrypto_Sha3_256_update);
/// def digest(self) -> bytes: /// def digest(self) -> bytes:
/// ''' /// """
/// Returns the digest of hashed data. /// Returns the digest of hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Sha3_256_digest(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_Sha3_256_digest(mp_obj_t self) {
mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(self); mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(self);
uint8_t out[SHA3_256_DIGEST_LENGTH]; uint8_t out[SHA3_256_DIGEST_LENGTH];
@ -103,9 +103,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha3_256_digest_obj,
mod_trezorcrypto_Sha3_256_digest); mod_trezorcrypto_Sha3_256_digest);
/// def copy(self) -> sha3: /// def copy(self) -> sha3:
/// ''' /// """
/// Returns the copy of the digest object with the current state /// Returns the copy of the digest object with the current state
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Sha3_256_copy(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_Sha3_256_copy(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(args[0]); mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(args[0]);

@ -25,9 +25,9 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Sha3_512: /// class Sha3_512:
/// ''' /// """
/// SHA3_512 context. /// SHA3_512 context.
/// ''' /// """
typedef struct _mp_obj_Sha3_512_t { typedef struct _mp_obj_Sha3_512_t {
mp_obj_base_t base; mp_obj_base_t base;
SHA3_CTX ctx; SHA3_CTX ctx;
@ -36,10 +36,10 @@ typedef struct _mp_obj_Sha3_512_t {
STATIC mp_obj_t mod_trezorcrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data); STATIC mp_obj_t mod_trezorcrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None, keccak = False) -> None: /// def __init__(self, data: bytes = None, keccak: bool = False) -> None:
/// ''' /// """
/// Creates a hash context object. /// Creates a hash context object.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Sha3_512_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorcrypto_Sha3_512_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -67,9 +67,9 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_512_make_new(const mp_obj_type_t *type,
} }
/// def update(self, data: bytes) -> None: /// def update(self, data: bytes) -> None:
/// ''' /// """
/// Update the hash context with hashed data. /// Update the hash context with hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data) { STATIC mp_obj_t mod_trezorcrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(self); mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t msg; mp_buffer_info_t msg;
@ -83,9 +83,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha3_512_update_obj,
mod_trezorcrypto_Sha3_512_update); mod_trezorcrypto_Sha3_512_update);
/// def digest(self) -> bytes: /// def digest(self) -> bytes:
/// ''' /// """
/// Returns the digest of hashed data. /// Returns the digest of hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Sha3_512_digest(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_Sha3_512_digest(mp_obj_t self) {
mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(self); mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(self);
uint8_t out[SHA3_512_DIGEST_LENGTH]; uint8_t out[SHA3_512_DIGEST_LENGTH];
@ -103,9 +103,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha3_512_digest_obj,
mod_trezorcrypto_Sha3_512_digest); mod_trezorcrypto_Sha3_512_digest);
/// def copy(self) -> sha3: /// def copy(self) -> sha3:
/// ''' /// """
/// Returns the copy of the digest object with the current state /// Returns the copy of the digest object with the current state
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Sha3_512_copy(size_t n_args, STATIC mp_obj_t mod_trezorcrypto_Sha3_512_copy(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(args[0]); mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(args[0]);

@ -25,9 +25,9 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Sha512: /// class Sha512:
/// ''' /// """
/// SHA512 context. /// SHA512 context.
/// ''' /// """
typedef struct _mp_obj_Sha512_t { typedef struct _mp_obj_Sha512_t {
mp_obj_base_t base; mp_obj_base_t base;
SHA512_CTX ctx; SHA512_CTX ctx;
@ -36,9 +36,9 @@ typedef struct _mp_obj_Sha512_t {
STATIC mp_obj_t mod_trezorcrypto_Sha512_update(mp_obj_t self, mp_obj_t data); STATIC mp_obj_t mod_trezorcrypto_Sha512_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None) -> None: /// def __init__(self, data: bytes = None) -> None:
/// ''' /// """
/// Creates a hash context object. /// Creates a hash context object.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Sha512_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorcrypto_Sha512_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -53,9 +53,9 @@ STATIC mp_obj_t mod_trezorcrypto_Sha512_make_new(const mp_obj_type_t *type,
} }
/// def hash(self, data: bytes) -> None: /// def hash(self, data: bytes) -> None:
/// ''' /// """
/// Update the hash context with hashed data. /// Update the hash context with hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Sha512_update(mp_obj_t self, mp_obj_t data) { STATIC mp_obj_t mod_trezorcrypto_Sha512_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self); mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t msg; mp_buffer_info_t msg;
@ -69,9 +69,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha512_update_obj,
mod_trezorcrypto_Sha512_update); mod_trezorcrypto_Sha512_update);
/// def digest(self) -> bytes: /// def digest(self) -> bytes:
/// ''' /// """
/// Returns the digest of hashed data. /// Returns the digest of hashed data.
/// ''' /// """
STATIC mp_obj_t mod_trezorcrypto_Sha512_digest(mp_obj_t self) { STATIC mp_obj_t mod_trezorcrypto_Sha512_digest(mp_obj_t self) {
mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self); mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self);
uint8_t out[SHA512_DIGEST_LENGTH]; uint8_t out[SHA512_DIGEST_LENGTH];

@ -22,15 +22,15 @@
#include "embed/extmod/trezorobj.h" #include "embed/extmod/trezorobj.h"
/// class FlashOTP: /// class FlashOTP:
/// ''' /// """
/// ''' /// """
typedef struct _mp_obj_FlashOTP_t { typedef struct _mp_obj_FlashOTP_t {
mp_obj_base_t base; mp_obj_base_t base;
} mp_obj_FlashOTP_t; } mp_obj_FlashOTP_t;
/// def __init__(self) -> None: /// def __init__(self) -> None:
/// ''' /// """
/// ''' /// """
STATIC mp_obj_t mod_trezorio_FlashOTP_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorio_FlashOTP_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -40,10 +40,10 @@ STATIC mp_obj_t mod_trezorio_FlashOTP_make_new(const mp_obj_type_t *type,
return MP_OBJ_FROM_PTR(o); return MP_OBJ_FROM_PTR(o);
} }
/// def FlashOTP.write(self, block: int, offset: int, data: bytes) -> None: /// def write(self, block: int, offset: int, data: bytes) -> None:
/// ''' /// """
/// Writes data to OTP flash /// Writes data to OTP flash
/// ''' /// """
STATIC mp_obj_t mod_trezorio_FlashOTP_write(size_t n_args, STATIC mp_obj_t mod_trezorio_FlashOTP_write(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
uint8_t block = trezor_obj_get_uint8(args[1]); uint8_t block = trezor_obj_get_uint8(args[1]);
@ -58,10 +58,10 @@ STATIC mp_obj_t mod_trezorio_FlashOTP_write(size_t n_args,
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorio_FlashOTP_write_obj, 4, STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorio_FlashOTP_write_obj, 4,
4, mod_trezorio_FlashOTP_write); 4, mod_trezorio_FlashOTP_write);
/// def FlashOTP.read(self, block: int, offset: int, data: bytearray) -> None: /// def read(self, block: int, offset: int, data: bytearray) -> None:
/// ''' /// """
/// Reads data from OTP flash /// Reads data from OTP flash
/// ''' /// """
STATIC mp_obj_t mod_trezorio_FlashOTP_read(size_t n_args, STATIC mp_obj_t mod_trezorio_FlashOTP_read(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
uint8_t block = trezor_obj_get_uint8(args[1]); uint8_t block = trezor_obj_get_uint8(args[1]);
@ -76,10 +76,10 @@ STATIC mp_obj_t mod_trezorio_FlashOTP_read(size_t n_args,
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorio_FlashOTP_read_obj, 4, 4, STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorio_FlashOTP_read_obj, 4, 4,
mod_trezorio_FlashOTP_read); mod_trezorio_FlashOTP_read);
/// def FlashOTP.lock(self, block: int) -> None: /// def lock(self, block: int) -> None:
/// ''' /// """
/// Lock OTP flash block /// Lock OTP flash block
/// ''' /// """
STATIC mp_obj_t mod_trezorio_FlashOTP_lock(mp_obj_t self, mp_obj_t block) { STATIC mp_obj_t mod_trezorio_FlashOTP_lock(mp_obj_t self, mp_obj_t block) {
uint8_t b = trezor_obj_get_uint8(block); uint8_t b = trezor_obj_get_uint8(block);
if (sectrue != flash_otp_lock(b)) { if (sectrue != flash_otp_lock(b)) {
@ -90,10 +90,10 @@ STATIC mp_obj_t mod_trezorio_FlashOTP_lock(mp_obj_t self, mp_obj_t block) {
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_FlashOTP_lock_obj, STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_FlashOTP_lock_obj,
mod_trezorio_FlashOTP_lock); mod_trezorio_FlashOTP_lock);
/// def FlashOTP.is_locked(self, block: int) -> bool: /// def is_locked(self, block: int) -> bool:
/// ''' /// """
/// Is OTP flash block locked? /// Is OTP flash block locked?
/// ''' /// """
STATIC mp_obj_t mod_trezorio_FlashOTP_is_locked(mp_obj_t self, mp_obj_t block) { STATIC mp_obj_t mod_trezorio_FlashOTP_is_locked(mp_obj_t self, mp_obj_t block) {
uint8_t b = trezor_obj_get_uint8(block); uint8_t b = trezor_obj_get_uint8(block);
return (sectrue == flash_otp_is_locked(b)) ? mp_const_true : mp_const_false; return (sectrue == flash_otp_is_locked(b)) ? mp_const_true : mp_const_false;

@ -18,25 +18,27 @@
*/ */
/// class HID: /// class HID:
/// ''' /// """
/// USB HID interface configuration. /// USB HID interface configuration.
/// ''' /// """
typedef struct _mp_obj_HID_t { typedef struct _mp_obj_HID_t {
mp_obj_base_t base; mp_obj_base_t base;
usb_hid_info_t info; usb_hid_info_t info;
} mp_obj_HID_t; } mp_obj_HID_t;
/// def __init__(self, /// def __init__(
/// iface_num: int, /// self,
/// ep_in: int, /// iface_num: int,
/// ep_out: int, /// ep_in: int,
/// report_desc: bytes, /// ep_out: int,
/// subclass: int = 0, /// report_desc: bytes,
/// protocol: int = 0, /// subclass: int = 0,
/// polling_interval: int = 1, /// protocol: int = 0,
/// max_packet_len: int = 64) -> None: /// polling_interval: int = 1,
/// ''' /// max_packet_len: int = 64,
/// ''' /// ) -> None:
/// """
/// """
STATIC mp_obj_t mod_trezorio_HID_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorio_HID_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -102,9 +104,9 @@ STATIC mp_obj_t mod_trezorio_HID_make_new(const mp_obj_type_t *type,
} }
/// def iface_num(self) -> int: /// def iface_num(self) -> int:
/// ''' /// """
/// Returns the configured number of this interface. /// Returns the configured number of this interface.
/// ''' /// """
STATIC mp_obj_t mod_trezorio_HID_iface_num(mp_obj_t self) { STATIC mp_obj_t mod_trezorio_HID_iface_num(mp_obj_t self) {
mp_obj_HID_t *o = MP_OBJ_TO_PTR(self); mp_obj_HID_t *o = MP_OBJ_TO_PTR(self);
return MP_OBJ_NEW_SMALL_INT(o->info.iface_num); return MP_OBJ_NEW_SMALL_INT(o->info.iface_num);
@ -113,9 +115,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_HID_iface_num_obj,
mod_trezorio_HID_iface_num); mod_trezorio_HID_iface_num);
/// def write(self, msg: bytes) -> int: /// def write(self, msg: bytes) -> int:
/// ''' /// """
/// Sends message using USB HID (device) or UDP (emulator). /// Sends message using USB HID (device) or UDP (emulator).
/// ''' /// """
STATIC mp_obj_t mod_trezorio_HID_write(mp_obj_t self, mp_obj_t msg) { STATIC mp_obj_t mod_trezorio_HID_write(mp_obj_t self, mp_obj_t msg) {
mp_obj_HID_t *o = MP_OBJ_TO_PTR(self); mp_obj_HID_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t buf; mp_buffer_info_t buf;

@ -26,18 +26,18 @@
#define POLL_WRITE (0x0100) #define POLL_WRITE (0x0100)
/// def poll(ifaces: Iterable[int], list_ref: List, timeout_us: int) -> bool: /// def poll(ifaces: Iterable[int], list_ref: List, timeout_us: int) -> bool:
/// ''' /// """
/// Wait until one of `ifaces` is ready to read or write (using masks /// Wait until one of `ifaces` is ready to read or write (using masks
// `io.POLL_READ` and `io.POLL_WRITE`) and assign the result into // `io.POLL_READ` and `io.POLL_WRITE`) and assign the result into
/// `list_ref`: /// `list_ref`:
/// ///
/// `list_ref[0]` - the interface number, including the mask /// `list_ref[0]` - the interface number, including the mask
/// `list_ref[1]` - for touch event, tuple of (event_type, x_position, /// `list_ref[1]` - for touch event, tuple of:
/// y_position) /// (event_type, x_position, y_position)
/// - for USB read event, received bytes /// - for USB read event, received bytes
/// ///
/// If timeout occurs, False is returned, True otherwise. /// If timeout occurs, False is returned, True otherwise.
/// ''' /// """
STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref, STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
mp_obj_t timeout_us) { mp_obj_t timeout_us) {
mp_obj_list_t *ret = MP_OBJ_TO_PTR(list_ref); mp_obj_list_t *ret = MP_OBJ_TO_PTR(list_ref);

@ -20,15 +20,15 @@
#include "sbu.h" #include "sbu.h"
/// class SBU: /// class SBU:
/// ''' /// """
/// ''' /// """
typedef struct _mp_obj_SBU_t { typedef struct _mp_obj_SBU_t {
mp_obj_base_t base; mp_obj_base_t base;
} mp_obj_SBU_t; } mp_obj_SBU_t;
/// def __init__(self) -> None: /// def __init__(self) -> None:
/// ''' /// """
/// ''' /// """
STATIC mp_obj_t mod_trezorio_SBU_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorio_SBU_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -40,9 +40,9 @@ STATIC mp_obj_t mod_trezorio_SBU_make_new(const mp_obj_type_t *type,
} }
/// def set(self, sbu1: bool, sbu2: bool) -> None: /// def set(self, sbu1: bool, sbu2: bool) -> None:
/// ''' /// """
/// Sets SBU wires to sbu1 and sbu2 values respectively /// Sets SBU wires to sbu1 and sbu2 values respectively
/// ''' /// """
STATIC mp_obj_t mod_trezorio_SBU_set(mp_obj_t self, mp_obj_t sbu1, STATIC mp_obj_t mod_trezorio_SBU_set(mp_obj_t self, mp_obj_t sbu1,
mp_obj_t sbu2) { mp_obj_t sbu2) {
sbu_set(sectrue * mp_obj_is_true(sbu1), sectrue * mp_obj_is_true(sbu2)); sbu_set(sectrue * mp_obj_is_true(sbu1), sectrue * mp_obj_is_true(sbu2));

@ -22,15 +22,15 @@
#include "embed/extmod/trezorobj.h" #include "embed/extmod/trezorobj.h"
/// class SDCard: /// class SDCard:
/// ''' /// """
/// ''' /// """
typedef struct _mp_obj_SDCard_t { typedef struct _mp_obj_SDCard_t {
mp_obj_base_t base; mp_obj_base_t base;
} mp_obj_SDCard_t; } mp_obj_SDCard_t;
/// def __init__(self) -> None: /// def __init__(self) -> None:
/// ''' /// """
/// ''' /// """
STATIC mp_obj_t mod_trezorio_SDCard_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorio_SDCard_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -44,9 +44,9 @@ STATIC mp_obj_t mod_trezorio_SDCard_make_new(const mp_obj_type_t *type,
} }
/// def present(self) -> bool: /// def present(self) -> bool:
/// ''' /// """
/// Returns True if SD card is detected, False otherwise. /// Returns True if SD card is detected, False otherwise.
/// ''' /// """
STATIC mp_obj_t mod_trezorio_SDCard_present(mp_obj_t self) { STATIC mp_obj_t mod_trezorio_SDCard_present(mp_obj_t self) {
return mp_obj_new_bool(sdcard_is_present()); return mp_obj_new_bool(sdcard_is_present());
} }
@ -54,10 +54,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_SDCard_present_obj,
mod_trezorio_SDCard_present); mod_trezorio_SDCard_present);
/// def power(self, state: bool) -> bool: /// def power(self, state: bool) -> bool:
/// ''' /// """
/// Power on or power off the SD card interface. /// Power on or power off the SD card interface.
/// Returns True if in case of success, False otherwise. /// Returns True if in case of success, False otherwise.
/// ''' /// """
STATIC mp_obj_t mod_trezorio_SDCard_power(mp_obj_t self, mp_obj_t state) { STATIC mp_obj_t mod_trezorio_SDCard_power(mp_obj_t self, mp_obj_t state) {
if (mp_obj_is_true(state)) { if (mp_obj_is_true(state)) {
return mp_obj_new_bool(sdcard_power_on()); return mp_obj_new_bool(sdcard_power_on());
@ -70,9 +70,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_SDCard_power_obj,
mod_trezorio_SDCard_power); mod_trezorio_SDCard_power);
/// def capacity(self) -> int: /// def capacity(self) -> int:
/// ''' /// """
/// Returns capacity of the SD card in bytes, or zero if not present. /// Returns capacity of the SD card in bytes, or zero if not present.
/// ''' /// """
STATIC mp_obj_t mod_trezorio_SDCard_capacity(mp_obj_t self) { STATIC mp_obj_t mod_trezorio_SDCard_capacity(mp_obj_t self) {
return mp_obj_new_int_from_ull(sdcard_get_capacity_in_bytes()); return mp_obj_new_int_from_ull(sdcard_get_capacity_in_bytes());
} }
@ -80,11 +80,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_SDCard_capacity_obj,
mod_trezorio_SDCard_capacity); mod_trezorio_SDCard_capacity);
/// def read(self, block_num: int, buf: bytearray) -> bool: /// def read(self, block_num: int, buf: bytearray) -> bool:
/// ''' /// """
/// Reads blocks starting with block_num from the SD card into buf. /// Reads blocks starting with block_num from the SD card into buf.
/// Number of bytes read is length of buf rounded down to multiply of /// Number of bytes read is length of buf rounded down to multiply of
/// SDCARD_BLOCK_SIZE. Returns True if in case of success, False otherwise. /// SDCARD_BLOCK_SIZE. Returns True if in case of success, False otherwise.
/// ''' /// """
STATIC mp_obj_t mod_trezorio_SDCard_read(mp_obj_t self, mp_obj_t block_num, STATIC mp_obj_t mod_trezorio_SDCard_read(mp_obj_t self, mp_obj_t block_num,
mp_obj_t buf) { mp_obj_t buf) {
uint32_t block = trezor_obj_get_uint(block_num); uint32_t block = trezor_obj_get_uint(block_num);
@ -97,11 +97,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorio_SDCard_read_obj,
mod_trezorio_SDCard_read); mod_trezorio_SDCard_read);
/// def write(self, block_num: int, buf: bytes) -> bool: /// def write(self, block_num: int, buf: bytes) -> bool:
/// ''' /// """
/// Writes blocks starting with block_num from buf to the SD card. /// Writes blocks starting with block_num from buf to the SD card.
/// Number of bytes written is length of buf rounded down to multiply of /// Number of bytes written is length of buf rounded down to multiply of
/// SDCARD_BLOCK_SIZE. Returns True if in case of success, False otherwise. /// SDCARD_BLOCK_SIZE. Returns True if in case of success, False otherwise.
/// ''' /// """
STATIC mp_obj_t mod_trezorio_SDCard_write(mp_obj_t self, mp_obj_t block_num, STATIC mp_obj_t mod_trezorio_SDCard_write(mp_obj_t self, mp_obj_t block_num,
mp_obj_t buf) { mp_obj_t buf) {
uint32_t block = trezor_obj_get_uint(block_num); uint32_t block = trezor_obj_get_uint(block_num);

@ -25,9 +25,9 @@ enum {
}; };
/// class USB: /// class USB:
/// ''' /// """
/// USB device configuration. /// USB device configuration.
/// ''' /// """
typedef struct _mp_obj_USB_t { typedef struct _mp_obj_USB_t {
mp_obj_base_t base; mp_obj_base_t base;
mp_obj_list_t ifaces; mp_obj_list_t ifaces;
@ -49,21 +49,23 @@ static const char *get_0str(mp_obj_t o, size_t min_len, size_t max_len) {
} }
} }
/// def __init__(self, /// def __init__(
/// device_class: int=0, /// self,
/// device_subclass: int=0, /// vendor_id: int,
/// device_protocol: int=0, /// product_id: int,
/// vendor_id: int, /// release_num: int,
/// product_id: int, /// device_class: int = 0,
/// release_num: int, /// device_subclass: int = 0,
/// manufacturer: str='', /// device_protocol: int = 0,
/// product: str='', /// manufacturer: str = "",
/// serial_number: str='', /// product: str = "",
/// interface: str='', /// serial_number: str = "",
/// usb21_enabled: bool=True, /// interface: str = "",
/// usb21_landing: bool=True) -> None: /// usb21_enabled: bool = True,
/// ''' /// usb21_landing: bool = True,
/// ''' /// ) -> None:
/// """
/// """
STATIC mp_obj_t mod_trezorio_USB_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorio_USB_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -155,9 +157,9 @@ STATIC mp_obj_t mod_trezorio_USB_make_new(const mp_obj_type_t *type,
} }
/// def add(self, iface: Union[HID, VCP, WebUSB]) -> None: /// def add(self, iface: Union[HID, VCP, WebUSB]) -> None:
/// ''' /// """
/// Registers passed interface into the USB stack. /// Registers passed interface into the USB stack.
/// ''' /// """
STATIC mp_obj_t mod_trezorio_USB_add(mp_obj_t self, mp_obj_t iface) { STATIC mp_obj_t mod_trezorio_USB_add(mp_obj_t self, mp_obj_t iface) {
mp_obj_USB_t *o = MP_OBJ_TO_PTR(self); mp_obj_USB_t *o = MP_OBJ_TO_PTR(self);
@ -172,9 +174,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_USB_add_obj,
mod_trezorio_USB_add); mod_trezorio_USB_add);
/// def open(self) -> None: /// def open(self) -> None:
/// ''' /// """
/// Initializes the USB stack. /// Initializes the USB stack.
/// ''' /// """
STATIC mp_obj_t mod_trezorio_USB_open(mp_obj_t self) { STATIC mp_obj_t mod_trezorio_USB_open(mp_obj_t self) {
mp_obj_USB_t *o = MP_OBJ_TO_PTR(self); mp_obj_USB_t *o = MP_OBJ_TO_PTR(self);
@ -234,9 +236,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_USB_open_obj,
mod_trezorio_USB_open); mod_trezorio_USB_open);
/// def close(self) -> None: /// def close(self) -> None:
/// ''' /// """
/// Cleans up the USB stack. /// Cleans up the USB stack.
/// ''' /// """
STATIC mp_obj_t mod_trezorio_USB_close(mp_obj_t self) { STATIC mp_obj_t mod_trezorio_USB_close(mp_obj_t self) {
mp_obj_USB_t *o = MP_OBJ_TO_PTR(self); mp_obj_USB_t *o = MP_OBJ_TO_PTR(self);

@ -20,22 +20,24 @@
void pendsv_kbd_intr(void); void pendsv_kbd_intr(void);
/// class VCP: /// class VCP:
/// ''' /// """
/// USB VCP interface configuration. /// USB VCP interface configuration.
/// ''' /// """
typedef struct _mp_obj_VCP_t { typedef struct _mp_obj_VCP_t {
mp_obj_base_t base; mp_obj_base_t base;
usb_vcp_info_t info; usb_vcp_info_t info;
} mp_obj_VCP_t; } mp_obj_VCP_t;
/// def __init__(self, /// def __init__(
/// iface_num: int, /// self,
/// data_iface_num: int, /// iface_num: int,
/// ep_in: int, /// data_iface_num: int,
/// ep_out: int, /// ep_in: int,
/// ep_cmd: int) -> None: /// ep_out: int,
/// ''' /// ep_cmd: int,
/// ''' /// ) -> None:
/// """
/// """
STATIC mp_obj_t mod_trezorio_VCP_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorio_VCP_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -98,9 +100,9 @@ STATIC mp_obj_t mod_trezorio_VCP_make_new(const mp_obj_type_t *type,
} }
/// def iface_num(self) -> int: /// def iface_num(self) -> int:
/// ''' /// """
/// Returns the configured number of this interface. /// Returns the configured number of this interface.
/// ''' /// """
STATIC mp_obj_t mod_trezorio_VCP_iface_num(mp_obj_t self) { STATIC mp_obj_t mod_trezorio_VCP_iface_num(mp_obj_t self) {
mp_obj_VCP_t *o = MP_OBJ_TO_PTR(self); mp_obj_VCP_t *o = MP_OBJ_TO_PTR(self);
return MP_OBJ_NEW_SMALL_INT(o->info.iface_num); return MP_OBJ_NEW_SMALL_INT(o->info.iface_num);

@ -18,24 +18,26 @@
*/ */
/// class WebUSB: /// class WebUSB:
/// ''' /// """
/// USB WebUSB interface configuration. /// USB WebUSB interface configuration.
/// ''' /// """
typedef struct _mp_obj_WebUSB_t { typedef struct _mp_obj_WebUSB_t {
mp_obj_base_t base; mp_obj_base_t base;
usb_webusb_info_t info; usb_webusb_info_t info;
} mp_obj_WebUSB_t; } mp_obj_WebUSB_t;
/// def __init__(self, /// def __init__(
/// iface_num: int, /// self,
/// ep_in: int, /// iface_num: int,
/// ep_out: int, /// ep_in: int,
/// subclass: int = 0, /// ep_out: int,
/// protocol: int = 0, /// subclass: int = 0,
/// polling_interval: int = 1, /// protocol: int = 0,
/// max_packet_len: int = 64) -> None: /// polling_interval: int = 1,
/// ''' /// max_packet_len: int = 64,
/// ''' /// ) -> None:
/// """
/// """
STATIC mp_obj_t mod_trezorio_WebUSB_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorio_WebUSB_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -90,9 +92,9 @@ STATIC mp_obj_t mod_trezorio_WebUSB_make_new(const mp_obj_type_t *type,
} }
/// def iface_num(self) -> int: /// def iface_num(self) -> int:
/// ''' /// """
/// Returns the configured number of this interface. /// Returns the configured number of this interface.
/// ''' /// """
STATIC mp_obj_t mod_trezorio_WebUSB_iface_num(mp_obj_t self) { STATIC mp_obj_t mod_trezorio_WebUSB_iface_num(mp_obj_t self) {
mp_obj_WebUSB_t *o = MP_OBJ_TO_PTR(self); mp_obj_WebUSB_t *o = MP_OBJ_TO_PTR(self);
return MP_OBJ_NEW_SMALL_INT(o->info.iface_num); return MP_OBJ_NEW_SMALL_INT(o->info.iface_num);
@ -101,9 +103,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_WebUSB_iface_num_obj,
mod_trezorio_WebUSB_iface_num); mod_trezorio_WebUSB_iface_num);
/// def write(self, msg: bytes) -> int: /// def write(self, msg: bytes) -> int:
/// ''' /// """
/// Sends message using USB WebUSB (device) or UDP (emulator). /// Sends message using USB WebUSB (device) or UDP (emulator).
/// ''' /// """
STATIC mp_obj_t mod_trezorio_WebUSB_write(mp_obj_t self, mp_obj_t msg) { STATIC mp_obj_t mod_trezorio_WebUSB_write(mp_obj_t self, mp_obj_t msg) {
mp_obj_WebUSB_t *o = MP_OBJ_TO_PTR(self); mp_obj_WebUSB_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t buf; mp_buffer_info_t buf;

@ -22,17 +22,17 @@
#include "display.h" #include "display.h"
/// class Display: /// class Display:
/// ''' /// """
/// Provide access to device display. /// Provide access to device display.
/// ''' /// """
typedef struct _mp_obj_Display_t { typedef struct _mp_obj_Display_t {
mp_obj_base_t base; mp_obj_base_t base;
} mp_obj_Display_t; } mp_obj_Display_t;
/// def __init__(self) -> None: /// def __init__(self) -> None:
/// ''' /// """
/// Initialize the display. /// Initialize the display.
/// ''' /// """
STATIC mp_obj_t mod_trezorui_Display_make_new(const mp_obj_type_t *type, STATIC mp_obj_t mod_trezorui_Display_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
@ -43,9 +43,9 @@ STATIC mp_obj_t mod_trezorui_Display_make_new(const mp_obj_type_t *type,
} }
/// def clear(self) -> None: /// def clear(self) -> None:
/// ''' /// """
/// Clear display with black color. /// Clear display with black color.
/// ''' /// """
STATIC mp_obj_t mod_trezorui_Display_clear(mp_obj_t self) { STATIC mp_obj_t mod_trezorui_Display_clear(mp_obj_t self) {
display_clear(); display_clear();
return mp_const_none; return mp_const_none;
@ -54,9 +54,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorui_Display_clear_obj,
mod_trezorui_Display_clear); mod_trezorui_Display_clear);
/// def refresh(self) -> None: /// def refresh(self) -> None:
/// ''' /// """
/// Refresh display (update screen). /// Refresh display (update screen).
/// ''' /// """
STATIC mp_obj_t mod_trezorui_Display_refresh(mp_obj_t self) { STATIC mp_obj_t mod_trezorui_Display_refresh(mp_obj_t self) {
display_refresh(); display_refresh();
return mp_const_none; return mp_const_none;
@ -65,10 +65,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorui_Display_refresh_obj,
mod_trezorui_Display_refresh); mod_trezorui_Display_refresh);
/// def bar(self, x: int, y: int, w: int, h: int, color: int) -> None: /// def bar(self, 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 /// Renders a bar at position (x,y = upper left corner) with width w and
/// height h of color color. /// height h of color color.
/// ''' /// """
STATIC mp_obj_t mod_trezorui_Display_bar(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_trezorui_Display_bar(size_t n_args, const mp_obj_t *args) {
mp_int_t x = mp_obj_get_int(args[1]); mp_int_t x = mp_obj_get_int(args[1]);
mp_int_t y = mp_obj_get_int(args[2]); mp_int_t y = mp_obj_get_int(args[2]);
@ -81,13 +81,21 @@ STATIC mp_obj_t mod_trezorui_Display_bar(size_t n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_bar_obj, 6, 6, STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_bar_obj, 6, 6,
mod_trezorui_Display_bar); mod_trezorui_Display_bar);
/// def bar_radius(self, x: int, y: int, w: int, h: int, fgcolor: int, bgcolor: /// def bar_radius(
/// int = None, radius: int = None) -> None: /// self,
/// ''' /// 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 /// 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 /// and height h of color fgcolor. Background is set to bgcolor and corners
/// are drawn with radius radius. /// are drawn with radius radius.
/// ''' /// """
STATIC mp_obj_t mod_trezorui_Display_bar_radius(size_t n_args, STATIC mp_obj_t mod_trezorui_Display_bar_radius(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_int_t x = mp_obj_get_int(args[1]); mp_int_t x = mp_obj_get_int(args[1]);
@ -105,11 +113,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_bar_radius_obj,
mod_trezorui_Display_bar_radius); mod_trezorui_Display_bar_radius);
/// def image(self, x: int, y: int, image: bytes) -> None: /// def image(self, x: int, y: int, image: bytes) -> None:
/// ''' /// """
/// Renders an image at position (x,y). /// Renders an image at position (x,y).
/// The image needs to be in TREZOR Optimized Image Format (TOIF) - /// The image needs to be in TREZOR Optimized Image Format (TOIF) -
/// full-color mode. /// full-color mode.
/// ''' /// """
STATIC mp_obj_t mod_trezorui_Display_image(size_t n_args, STATIC mp_obj_t mod_trezorui_Display_image(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_int_t x = mp_obj_get_int(args[1]); mp_int_t x = mp_obj_get_int(args[1]);
@ -132,14 +140,15 @@ STATIC mp_obj_t mod_trezorui_Display_image(size_t n_args,
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_image_obj, 4, 4, STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_image_obj, 4, 4,
mod_trezorui_Display_image); mod_trezorui_Display_image);
/// def avatar(self, x: int, y: int, image: bytes, fgcolor: int, bgcolor: int) /// def avatar(
/// -> None: /// self, x: int, y: int, image: bytes, fgcolor: int, bgcolor: int
/// ''' /// ) -> None:
/// """
/// Renders an avatar at position (x,y). /// Renders an avatar at position (x,y).
/// The image needs to be in TREZOR Optimized Image Format (TOIF) - /// The image needs to be in TREZOR Optimized Image Format (TOIF) -
/// full-color mode. Image needs to be of exactly AVATAR_IMAGE_SIZE x /// full-color mode. Image needs to be of exactly AVATAR_IMAGE_SIZE x
/// AVATAR_IMAGE_SIZE pixels size. /// AVATAR_IMAGE_SIZE pixels size.
/// ''' /// """
STATIC mp_obj_t mod_trezorui_Display_avatar(size_t n_args, STATIC mp_obj_t mod_trezorui_Display_avatar(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_int_t x = mp_obj_get_int(args[1]); mp_int_t x = mp_obj_get_int(args[1]);
@ -167,13 +176,14 @@ STATIC mp_obj_t mod_trezorui_Display_avatar(size_t n_args,
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_avatar_obj, 6, STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_avatar_obj, 6,
6, mod_trezorui_Display_avatar); 6, mod_trezorui_Display_avatar);
/// def icon(self, x: int, y: int, icon: bytes, fgcolor: int, bgcolor: int) -> /// def icon(
/// None: /// self, x: int, y: int, icon: bytes, fgcolor: int, bgcolor: int
/// ''' /// ) -> None:
/// """
/// Renders an icon at position (x,y), fgcolor is used as foreground color, /// Renders an icon at position (x,y), fgcolor is used as foreground color,
/// bgcolor as background. The icon needs to be in TREZOR Optimized Image /// bgcolor as background. The icon needs to be in TREZOR Optimized Image
/// Format (TOIF) - gray-scale mode. /// Format (TOIF) - gray-scale mode.
/// ''' /// """
STATIC mp_obj_t mod_trezorui_Display_icon(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_trezorui_Display_icon(size_t n_args, const mp_obj_t *args) {
mp_int_t x = mp_obj_get_int(args[1]); mp_int_t x = mp_obj_get_int(args[1]);
mp_int_t y = mp_obj_get_int(args[2]); mp_int_t y = mp_obj_get_int(args[2]);
@ -197,16 +207,24 @@ STATIC mp_obj_t mod_trezorui_Display_icon(size_t n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_icon_obj, 6, 6, STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_icon_obj, 6, 6,
mod_trezorui_Display_icon); mod_trezorui_Display_icon);
/// def loader(self, progress: int, indeterminate: bool, yoffset: int, fgcolor: /// def loader(
/// int, bgcolor: int, icon: bytes = None, iconfgcolor: int = None) -> None: /// self,
/// ''' /// progress: int,
/// indeterminate: bool,
/// yoffset: int,
/// fgcolor: int,
/// bgcolor: int,
/// icon: bytes = None,
/// iconfgcolor: int = None,
/// ) -> None:
/// """
/// Renders a rotating loader graphic. /// Renders a rotating loader graphic.
/// Progress determines its position (0-1000), fgcolor is used as foreground /// Progress determines its position (0-1000), fgcolor is used as foreground
/// color, bgcolor as background. When icon and iconfgcolor are provided, an /// color, bgcolor as background. When icon and iconfgcolor are provided, an
/// icon is drawn in the middle using the color specified in iconfgcolor. /// icon is drawn in the middle using the color specified in iconfgcolor.
/// Icon needs to be of exactly LOADER_ICON_SIZE x LOADER_ICON_SIZE pixels /// Icon needs to be of exactly LOADER_ICON_SIZE x LOADER_ICON_SIZE pixels
/// size. /// size.
/// ''' /// """
STATIC mp_obj_t mod_trezorui_Display_loader(size_t n_args, STATIC mp_obj_t mod_trezorui_Display_loader(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_int_t progress = mp_obj_get_int(args[1]); mp_int_t progress = mp_obj_get_int(args[1]);
@ -248,9 +266,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_loader_obj, 6,
8, mod_trezorui_Display_loader); 8, mod_trezorui_Display_loader);
/// def print(self, text: str) -> None: /// def print(self, text: str) -> None:
/// ''' /// """
/// Renders text using 5x8 bitmap font (using special text mode). /// Renders text using 5x8 bitmap font (using special text mode).
/// ''' /// """
STATIC mp_obj_t mod_trezorui_Display_print(mp_obj_t self, mp_obj_t text) { STATIC mp_obj_t mod_trezorui_Display_print(mp_obj_t self, mp_obj_t text) {
mp_buffer_info_t buf; mp_buffer_info_t buf;
mp_get_buffer_raise(text, &buf, MP_BUFFER_READ); mp_get_buffer_raise(text, &buf, MP_BUFFER_READ);
@ -262,14 +280,22 @@ STATIC mp_obj_t mod_trezorui_Display_print(mp_obj_t self, mp_obj_t text) {
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorui_Display_print_obj, STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorui_Display_print_obj,
mod_trezorui_Display_print); mod_trezorui_Display_print);
/// def text(self, x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: /// def text(
/// int, minwidth: int=None) -> int: /// self,
/// ''' /// x: int,
/// y: int,
/// text: str,
/// font: int,
/// fgcolor: int,
/// bgcolor: int,
/// minwidth: int = None,
/// ) -> int:
/// """
/// Renders left-aligned text at position (x,y) where x is left position and /// 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 /// y is baseline. Font font is used for rendering, fgcolor is used as
/// foreground color, bgcolor as background. Fills at least minwidth pixels /// foreground color, bgcolor as background. Fills at least minwidth pixels
/// with bgcolor. Returns width of rendered text in pixels. /// with bgcolor. Returns width of rendered text in pixels.
/// ''' /// """
STATIC mp_obj_t mod_trezorui_Display_text(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_trezorui_Display_text(size_t n_args, const mp_obj_t *args) {
mp_int_t x = mp_obj_get_int(args[1]); mp_int_t x = mp_obj_get_int(args[1]);
mp_int_t y = mp_obj_get_int(args[2]); mp_int_t y = mp_obj_get_int(args[2]);
@ -290,14 +316,22 @@ STATIC mp_obj_t mod_trezorui_Display_text(size_t n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_obj, 7, 8, STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_obj, 7, 8,
mod_trezorui_Display_text); mod_trezorui_Display_text);
/// def text_center(self, x: int, y: int, text: str, font: int, fgcolor: int, /// def text_center(
/// bgcolor: int, minwidth: int=None) -> int: /// self,
/// ''' /// x: int,
/// y: int,
/// text: str,
/// font: int,
/// fgcolor: int,
/// bgcolor: int,
/// minwidth: int = None,
/// ) -> int:
/// """
/// Renders text centered at position (x,y) where x is text center and y is /// 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 /// baseline. Font font is used for rendering, fgcolor is used as foreground
/// color, bgcolor as background. Fills at least minwidth pixels with /// color, bgcolor as background. Fills at least minwidth pixels with
/// bgcolor. Returns width of rendered text in pixels. /// bgcolor. Returns width of rendered text in pixels.
/// ''' /// """
STATIC mp_obj_t mod_trezorui_Display_text_center(size_t n_args, STATIC mp_obj_t mod_trezorui_Display_text_center(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_int_t x = mp_obj_get_int(args[1]); mp_int_t x = mp_obj_get_int(args[1]);
@ -320,14 +354,22 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_center_obj,
7, 8, 7, 8,
mod_trezorui_Display_text_center); mod_trezorui_Display_text_center);
/// def text_right(self, x: int, y: int, text: str, font: int, fgcolor: int, /// def text_right(
/// bgcolor: int, minwidth: int=None) -> int: /// self,
/// ''' /// x: int,
/// y: int,
/// text: str,
/// font: int,
/// fgcolor: int,
/// bgcolor: int,
/// minwidth: int = None,
/// ) -> int:
/// """
/// Renders right-aligned text at position (x,y) where x is right position /// 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 /// and y is baseline. Font font is used for rendering, fgcolor is used as
/// foreground color, bgcolor as background. Fills at least minwidth pixels /// foreground color, bgcolor as background. Fills at least minwidth pixels
/// with bgcolor. Returns width of rendered text in pixels. /// with bgcolor. Returns width of rendered text in pixels.
/// ''' /// """
STATIC mp_obj_t mod_trezorui_Display_text_right(size_t n_args, STATIC mp_obj_t mod_trezorui_Display_text_right(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_int_t x = mp_obj_get_int(args[1]); mp_int_t x = mp_obj_get_int(args[1]);
@ -351,9 +393,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_right_obj,
mod_trezorui_Display_text_right); mod_trezorui_Display_text_right);
/// def text_width(self, text: str, font: int) -> int: /// def text_width(self, text: str, font: int) -> int:
/// ''' /// """
/// Returns a width of text in pixels. Font font is used for rendering. /// Returns a width of text in pixels. Font font is used for rendering.
/// ''' /// """
STATIC mp_obj_t mod_trezorui_Display_text_width(mp_obj_t self, mp_obj_t text, STATIC mp_obj_t mod_trezorui_Display_text_width(mp_obj_t self, mp_obj_t text,
mp_obj_t font) { mp_obj_t font) {
mp_buffer_info_t txt; mp_buffer_info_t txt;
@ -366,10 +408,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorui_Display_text_width_obj,
mod_trezorui_Display_text_width); mod_trezorui_Display_text_width);
/// def qrcode(self, x: int, y: int, data: bytes, scale: int) -> None: /// def qrcode(self, x: int, y: int, data: bytes, scale: int) -> None:
/// ''' /// """
/// Renders data encoded as a QR code centered at position (x,y). /// Renders data encoded as a QR code centered at position (x,y).
/// Scale determines a zoom factor. /// Scale determines a zoom factor.
/// ''' /// """
STATIC mp_obj_t mod_trezorui_Display_qrcode(size_t n_args, STATIC mp_obj_t mod_trezorui_Display_qrcode(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_int_t x = mp_obj_get_int(args[1]); mp_int_t x = mp_obj_get_int(args[1]);
@ -389,12 +431,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_qrcode_obj, 5,
5, mod_trezorui_Display_qrcode); 5, mod_trezorui_Display_qrcode);
/// def orientation(self, degrees: int = None) -> int: /// def orientation(self, degrees: int = None) -> int:
/// ''' /// """
/// Sets display orientation to 0, 90, 180 or 270 degrees. /// Sets display orientation to 0, 90, 180 or 270 degrees.
/// Everything needs to be redrawn again when this function is used. /// Everything needs to be redrawn again when this function is used.
/// Call without the degrees parameter to just perform the read of the /// Call without the degrees parameter to just perform the read of the
/// value. /// value.
/// ''' /// """
STATIC mp_obj_t mod_trezorui_Display_orientation(size_t n_args, STATIC mp_obj_t mod_trezorui_Display_orientation(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_int_t deg; mp_int_t deg;
@ -414,10 +456,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_orientation_obj,
mod_trezorui_Display_orientation); mod_trezorui_Display_orientation);
/// def backlight(self, val: int = None) -> int: /// def backlight(self, val: int = None) -> int:
/// ''' /// """
/// Sets backlight intensity to the value specified in val. /// Sets backlight intensity to the value specified in val.
/// Call without the val parameter to just perform the read of the value. /// Call without the val parameter to just perform the read of the value.
/// ''' /// """
STATIC mp_obj_t mod_trezorui_Display_backlight(size_t n_args, STATIC mp_obj_t mod_trezorui_Display_backlight(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_int_t val; mp_int_t val;
@ -437,10 +479,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_backlight_obj,
mod_trezorui_Display_backlight); mod_trezorui_Display_backlight);
/// def offset(self, xy: Tuple[int, int] = None) -> Tuple[int, int]: /// def offset(self, xy: Tuple[int, int] = None) -> Tuple[int, int]:
/// ''' /// """
/// Sets offset (x, y) for all subsequent drawing calls. /// Sets offset (x, y) for all subsequent drawing calls.
/// Call without the xy parameter to just perform the read of the value. /// Call without the xy parameter to just perform the read of the value.
/// ''' /// """
STATIC mp_obj_t mod_trezorui_Display_offset(size_t n_args, STATIC mp_obj_t mod_trezorui_Display_offset(size_t n_args,
const mp_obj_t *args) { const mp_obj_t *args) {
int xy[2], x, y; int xy[2], x, y;
@ -470,9 +512,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_offset_obj, 1,
2, mod_trezorui_Display_offset); 2, mod_trezorui_Display_offset);
/// def save(self, prefix: str) -> None: /// def save(self, prefix: str) -> None:
/// ''' /// """
/// Saves current display contents to PNG file with given prefix. /// Saves current display contents to PNG file with given prefix.
/// ''' /// """
STATIC mp_obj_t mod_trezorui_Display_save(mp_obj_t self, mp_obj_t prefix) { STATIC mp_obj_t mod_trezorui_Display_save(mp_obj_t self, mp_obj_t prefix) {
mp_buffer_info_t pfx; mp_buffer_info_t pfx;
mp_get_buffer_raise(prefix, &pfx, MP_BUFFER_READ); mp_get_buffer_raise(prefix, &pfx, MP_BUFFER_READ);

@ -29,12 +29,12 @@
#include "common.h" #include "common.h"
/// def consteq(sec: bytes, pub: bytes) -> bool: /// def consteq(sec: bytes, pub: bytes) -> bool:
/// ''' /// """
/// Compares the private information in `sec` with public, user-provided /// Compares the private information in `sec` with public, user-provided
/// information in `pub`. Runs in constant time, corresponding to a length /// information in `pub`. Runs in constant time, corresponding to a length
/// of `pub`. Can access memory behind valid length of `sec`, caller is /// of `pub`. Can access memory behind valid length of `sec`, caller is
/// expected to avoid any invalid memory access. /// expected to avoid any invalid memory access.
/// ''' /// """
STATIC mp_obj_t mod_trezorutils_consteq(mp_obj_t sec, mp_obj_t pub) { STATIC mp_obj_t mod_trezorutils_consteq(mp_obj_t sec, mp_obj_t pub) {
mp_buffer_info_t secbuf; mp_buffer_info_t secbuf;
mp_get_buffer_raise(sec, &secbuf, MP_BUFFER_READ); mp_get_buffer_raise(sec, &secbuf, MP_BUFFER_READ);
@ -57,14 +57,14 @@ STATIC mp_obj_t mod_trezorutils_consteq(mp_obj_t sec, mp_obj_t pub) {
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorutils_consteq_obj, STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorutils_consteq_obj,
mod_trezorutils_consteq); mod_trezorutils_consteq);
/// def memcpy(dst: bytearray, dst_ofs: int, /// def memcpy(
/// src: bytearray, src_ofs: int, /// dst: bytearray, dst_ofs: int, src: bytearray, src_ofs: int, n: int
/// n: int) -> int: /// ) -> int:
/// ''' /// """
/// Copies at most `n` bytes from `src` at offset `src_ofs` to /// Copies at most `n` bytes from `src` at offset `src_ofs` to
/// `dst` at offset `dst_ofs`. Returns the number of actually /// `dst` at offset `dst_ofs`. Returns the number of actually
/// copied bytes. /// copied bytes.
/// ''' /// """
STATIC mp_obj_t mod_trezorutils_memcpy(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_trezorutils_memcpy(size_t n_args, const mp_obj_t *args) {
mp_arg_check_num(n_args, 0, 5, 5, false); mp_arg_check_num(n_args, 0, 5, 5, false);
@ -90,9 +90,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorutils_memcpy_obj, 5, 5,
mod_trezorutils_memcpy); mod_trezorutils_memcpy);
/// def halt(msg: str = None) -> None: /// def halt(msg: str = None) -> None:
/// ''' /// """
/// Halts execution. /// Halts execution.
/// ''' /// """
STATIC mp_obj_t mod_trezorutils_halt(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_trezorutils_halt(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t msg; mp_buffer_info_t msg;
if (n_args > 0 && mp_get_buffer(args[0], &msg, MP_BUFFER_READ)) { if (n_args > 0 && mp_get_buffer(args[0], &msg, MP_BUFFER_READ)) {
@ -106,9 +106,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorutils_halt_obj, 0, 1,
mod_trezorutils_halt); mod_trezorutils_halt);
/// def set_mode_unprivileged() -> None: /// def set_mode_unprivileged() -> None:
/// ''' /// """
/// Set unprivileged mode. /// Set unprivileged mode.
/// ''' /// """
STATIC mp_obj_t mod_trezorutils_set_mode_unprivileged(void) { STATIC mp_obj_t mod_trezorutils_set_mode_unprivileged(void) {
#ifndef TREZOR_EMULATOR #ifndef TREZOR_EMULATOR
__asm__ volatile("msr control, %0" ::"r"(0x1)); __asm__ volatile("msr control, %0" ::"r"(0x1));

@ -1,82 +1,99 @@
from typing import * from typing import *
# extmod/modtrezorconfig/modtrezorconfig.c # extmod/modtrezorconfig/modtrezorconfig.c
def init(ui_wait_callback: (int, int -> None)=None) -> None: def init(ui_wait_callback: Tuple[int, Callable[int, None]] = None) -> None:
''' """
Initializes the storage. Must be called before any other method is Initializes the storage. Must be called before any other method is
called from this module! called from this module!
''' """
# extmod/modtrezorconfig/modtrezorconfig.c
def check_pin(pin: int) -> bool:
'''
Check the given PIN. Returns True on success, False on failure.
'''
# extmod/modtrezorconfig/modtrezorconfig.c # extmod/modtrezorconfig/modtrezorconfig.c
def unlock(pin: int) -> bool: def unlock(pin: int) -> bool:
''' """
Attempts to unlock the storage with given PIN. Returns True on Attempts to unlock the storage with given PIN. Returns True on
success, False on failure. success, False on failure.
''' """
# extmod/modtrezorconfig/modtrezorconfig.c
def check_pin(pin: int) -> bool:
"""
Check the given PIN. Returns True on success, False on failure.
"""
# extmod/modtrezorconfig/modtrezorconfig.c # extmod/modtrezorconfig/modtrezorconfig.c
def lock() -> None: def lock() -> None:
''' """
Locks the storage. Locks the storage.
''' """
# extmod/modtrezorconfig/modtrezorconfig.c # extmod/modtrezorconfig/modtrezorconfig.c
def has_pin() -> bool: def has_pin() -> bool:
''' """
Returns True if storage has a configured PIN, False otherwise. Returns True if storage has a configured PIN, False otherwise.
''' """
# extmod/modtrezorconfig/modtrezorconfig.c # extmod/modtrezorconfig/modtrezorconfig.c
def get_pin_rem() -> int: def get_pin_rem() -> int:
''' """
Returns the number of remaining PIN entry attempts. Returns the number of remaining PIN entry attempts.
''' """
# extmod/modtrezorconfig/modtrezorconfig.c # extmod/modtrezorconfig/modtrezorconfig.c
def change_pin(pin: int, newpin: int) -> bool: def change_pin(pin: int, newpin: int) -> bool:
''' """
Change PIN. Returns True on success, False on failure. Change PIN. Returns True on success, False on failure.
''' """
# extmod/modtrezorconfig/modtrezorconfig.c # extmod/modtrezorconfig/modtrezorconfig.c
def get(app: int, key: int, public: bool=False) -> bytes: def get(app: int, key: int, public: bool = False) -> bytes:
''' """
Gets the value of the given key for the given app (or None if not set). Gets the value of the given key for the given app (or None if not set).
Raises a RuntimeError if decryption or authentication of the stored value fails. Raises a RuntimeError if decryption or authentication of the stored
''' value fails.
"""
# extmod/modtrezorconfig/modtrezorconfig.c # extmod/modtrezorconfig/modtrezorconfig.c
def set(app: int, key: int, value: bytes, public: bool=False) -> None: def set(app: int, key: int, value: bytes, public: bool = False) -> None:
''' """
Sets a value of given key for given app. Sets a value of given key for given app.
''' """
# extmod/modtrezorconfig/modtrezorconfig.c # extmod/modtrezorconfig/modtrezorconfig.c
def delete(app: int, key: int, public: bool=False) -> bool: def delete(app: int, key: int, public: bool = False) -> bool:
''' """
Deletes the given key of the given app. Deletes the given key of the given app.
''' """
# extmod/modtrezorconfig/modtrezorconfig.c # extmod/modtrezorconfig/modtrezorconfig.c
def set_counter(app: int, key: int, count: int, writable_locked: bool=False) -> bool: def set_counter(
''' app: int, key: int, count: int, writable_locked: bool = False
) -> bool:
"""
Sets the given key of the given app as a counter with the given value. Sets the given key of the given app as a counter with the given value.
''' """
# extmod/modtrezorconfig/modtrezorconfig.c # extmod/modtrezorconfig/modtrezorconfig.c
def next_counter(app: int, key: int, writable_locked: bool=False) -> bool: def next_counter(app: int, key: int, writable_locked: bool = False) -> bool:
''' """
Increments the counter stored under the given key of the given app and returns the new value. Increments the counter stored under the given key of the given app and
''' returns the new value.
"""
# extmod/modtrezorconfig/modtrezorconfig.c # extmod/modtrezorconfig/modtrezorconfig.c
def wipe() -> None: def wipe() -> None:
''' """
Erases the whole config. Use with caution! Erases the whole config. Use with caution!
''' """

@ -1,312 +1,347 @@
from typing import *
# extmod/modtrezorcrypto/modtrezorcrypto-aes.h # extmod/modtrezorcrypto/modtrezorcrypto-aes.h
class AES: class AES:
''' """
AES context. AES context.
''' """
def __init__(self, mode: int, key: bytes, iv: bytes = None) -> None: def __init__(self, mode: int, key: bytes, iv: bytes = None) -> None:
''' """
Initialize AES context. Initialize AES context.
''' """
def encrypt(self, data: bytes) -> bytes: def encrypt(self, data: bytes) -> bytes:
''' """
Encrypt data and update AES context. Encrypt data and update AES context.
''' """
def decrypt(self, data: bytes) -> bytes: def decrypt(self, data: bytes) -> bytes:
''' """
Decrypt data and update AES context. Decrypt data and update AES context.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-blake256.h # extmod/modtrezorcrypto/modtrezorcrypto-blake256.h
class Blake256: class Blake256:
''' """
Blake256 context. Blake256 context.
''' """
def __init__(self, data: bytes = None) -> None: def __init__(self, data: bytes = None) -> None:
''' """
Creates a hash context object. Creates a hash context object.
''' """
def update(self, data: bytes) -> None: def update(self, data: bytes) -> None:
''' """
Update the hash context with hashed data. Update the hash context with hashed data.
''' """
def digest(self) -> bytes: def digest(self) -> bytes:
''' """
Returns the digest of hashed data. Returns the digest of hashed data.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h # extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h
class Blake2b: class Blake2b:
''' """
Blake2b context. Blake2b context.
''' """
def __init__(self, data: bytes = None, outlen: int = Blake2b.digest_size, personal: bytes = None) -> None: def __init__(
''' self,
data: bytes = None,
outlen: int = Blake2b.digest_size,
personal: bytes = None,
) -> None:
"""
Creates a hash context object. Creates a hash context object.
''' """
def update(self, data: bytes) -> None: def update(self, data: bytes) -> None:
''' """
Update the hash context with hashed data. Update the hash context with hashed data.
''' """
def digest(self) -> bytes: def digest(self) -> bytes:
''' """
Returns the digest of hashed data. Returns the digest of hashed data.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h # extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h
class Blake2s: class Blake2s:
''' """
Blake2s context. Blake2s context.
''' """
def __init__(self, data: bytes = None, outlen: int = Blake2s.digest_size, key: bytes = None, personal: bytes = None) -> None: def __init__(
''' self,
data: bytes = None,
outlen: int = Blake2s.digest_size,
key: bytes = None,
personal: bytes = None,
) -> None:
"""
Creates a hash context object. Creates a hash context object.
''' """
def update(self, data: bytes) -> None: def update(self, data: bytes) -> None:
''' """
Update the hash context with hashed data. Update the hash context with hashed data.
''' """
def digest(self) -> bytes: def digest(self) -> bytes:
''' """
Returns the digest of hashed data. Returns the digest of hashed data.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-chacha20poly1305.h # extmod/modtrezorcrypto/modtrezorcrypto-chacha20poly1305.h
class ChaCha20Poly1305: class ChaCha20Poly1305:
''' """
ChaCha20Poly1305 context. ChaCha20Poly1305 context.
''' """
def __init__(self, key: bytes, nonce: bytes) -> None: def __init__(self, key: bytes, nonce: bytes) -> None:
''' """
Initialize the ChaCha20 + Poly1305 context for encryption or decryption Initialize the ChaCha20 + Poly1305 context for encryption or decryption
using a 32 byte key and 12 byte nonce as in the RFC 7539 style. using a 32 byte key and 12 byte nonce as in the RFC 7539 style.
''' """
def encrypt(self, data: bytes) -> bytes: def encrypt(self, data: bytes) -> bytes:
''' """
Encrypt data (length of data must be divisible by 64 except for the final value). Encrypt data (length of data must be divisible by 64 except for the
''' final value).
"""
def decrypt(self, data: bytes) -> bytes: def decrypt(self, data: bytes) -> bytes:
''' """
Decrypt data (length of data must be divisible by 64 except for the final value). Decrypt data (length of data must be divisible by 64 except for the
''' final value).
"""
def auth(self, data: bytes) -> None: def auth(self, data: bytes) -> None:
''' """
Include authenticated data in the Poly1305 MAC using the RFC 7539 Include authenticated data in the Poly1305 MAC using the RFC 7539
style with 16 byte padding. This must only be called once and prior style with 16 byte padding. This must only be called once and prior
to encryption or decryption. to encryption or decryption.
''' """
def finish(self) -> bytes: def finish(self) -> bytes:
''' """
Compute RFC 7539-style Poly1305 MAC. Compute RFC 7539-style Poly1305 MAC.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-groestl.h # extmod/modtrezorcrypto/modtrezorcrypto-groestl.h
class Groestl512: class Groestl512:
''' """
GROESTL512 context. GROESTL512 context.
''' """
def __init__(self, data: bytes = None) -> None: def __init__(self, data: bytes = None) -> None:
''' """
Creates a hash context object. Creates a hash context object.
''' """
def update(self, data: bytes) -> None: def update(self, data: bytes) -> None:
''' """
Update the hash context with hashed data. Update the hash context with hashed data.
''' """
def digest(self) -> bytes: def digest(self) -> bytes:
''' """
Returns the digest of hashed data. Returns the digest of hashed data.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h # extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h
class Pbkdf2: class Pbkdf2:
''' """
PBKDF2 context. PBKDF2 context.
''' """
def __init__(self, prf: int, password: bytes, salt: bytes, iterations: int = None, blocknr: int = 1) -> None: def __init__(
''' self,
prf: int,
password: bytes,
salt: bytes,
iterations: int = None,
blocknr: int = 1,
) -> None:
"""
Create a PBKDF2 context. Create a PBKDF2 context.
''' """
def update(self, iterations: int) -> None: def update(self, iterations: int) -> None:
''' """
Update a PBKDF2 context. Update a PBKDF2 context.
''' """
def key(self) -> bytes: def key(self) -> bytes:
''' """
Retrieve derived key. Retrieve derived key.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-rfc6979.h # extmod/modtrezorcrypto/modtrezorcrypto-rfc6979.h
class Rfc6979: class Rfc6979:
''' """
RFC6979 context. RFC6979 context.
''' """
def __init__(self, secret_key: bytes, hash: bytes) -> None: def __init__(self, secret_key: bytes, hash: bytes) -> None:
''' """
Initialize RFC6979 context from secret key and a hash. Initialize RFC6979 context from secret key and a hash.
''' """
def next(self) -> bytes: def next(self) -> bytes:
''' """
Compute next 32-bytes of pseudorandom data. Compute next 32-bytes of pseudorandom data.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h # extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h
class Ripemd160: class Ripemd160:
''' """
RIPEMD160 context. RIPEMD160 context.
''' """
def __init__(self, data: bytes = None) -> None: def __init__(self, data: bytes = None) -> None:
''' """
Creates a hash context object. Creates a hash context object.
''' """
def update(self, data: bytes) -> None: def update(self, data: bytes) -> None:
''' """
Update the hash context with hashed data. Update the hash context with hashed data.
''' """
def digest(self) -> bytes: def digest(self) -> bytes:
''' """
Returns the digest of hashed data. Returns the digest of hashed data.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-sha1.h # extmod/modtrezorcrypto/modtrezorcrypto-sha1.h
class Sha1: class Sha1:
''' """
SHA1 context. SHA1 context.
''' """
def __init__(self, data: bytes = None) -> None: def __init__(self, data: bytes = None) -> None:
''' """
Creates a hash context object. Creates a hash context object.
''' """
def update(self, data: bytes) -> None: def update(self, data: bytes) -> None:
''' """
Update the hash context with hashed data. Update the hash context with hashed data.
''' """
def digest(self) -> bytes: def digest(self) -> bytes:
''' """
Returns the digest of hashed data. Returns the digest of hashed data.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-sha256.h # extmod/modtrezorcrypto/modtrezorcrypto-sha256.h
class Sha256: class Sha256:
''' """
SHA256 context. SHA256 context.
''' """
def __init__(self, data: bytes = None) -> None: def __init__(self, data: bytes = None) -> None:
''' """
Creates a hash context object. Creates a hash context object.
''' """
def update(self, data: bytes) -> None: def update(self, data: bytes) -> None:
''' """
Update the hash context with hashed data. Update the hash context with hashed data.
''' """
def digest(self) -> bytes: def digest(self) -> bytes:
''' """
Returns the digest of hashed data. Returns the digest of hashed data.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h # extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h
class Sha3_256: class Sha3_256:
''' """
SHA3_256 context. SHA3_256 context.
''' """
def __init__(self, data: bytes = None, keccak = False) -> None: def __init__(self, data: bytes = None, keccak: bool = False) -> None:
''' """
Creates a hash context object. Creates a hash context object.
''' """
def update(self, data: bytes) -> None: def update(self, data: bytes) -> None:
''' """
Update the hash context with hashed data. Update the hash context with hashed data.
''' """
def digest(self) -> bytes: def digest(self) -> bytes:
''' """
Returns the digest of hashed data. Returns the digest of hashed data.
''' """
def copy(self) -> sha3: def copy(self) -> sha3:
''' """
Returns the copy of the digest object with the current state Returns the copy of the digest object with the current state
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h # extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h
class Sha3_512: class Sha3_512:
''' """
SHA3_512 context. SHA3_512 context.
''' """
def __init__(self, data: bytes = None, keccak = False) -> None: def __init__(self, data: bytes = None, keccak: bool = False) -> None:
''' """
Creates a hash context object. Creates a hash context object.
''' """
def update(self, data: bytes) -> None: def update(self, data: bytes) -> None:
''' """
Update the hash context with hashed data. Update the hash context with hashed data.
''' """
def digest(self) -> bytes: def digest(self) -> bytes:
''' """
Returns the digest of hashed data. Returns the digest of hashed data.
''' """
def copy(self) -> sha3: def copy(self) -> sha3:
''' """
Returns the copy of the digest object with the current state Returns the copy of the digest object with the current state
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-sha512.h # extmod/modtrezorcrypto/modtrezorcrypto-sha512.h
class Sha512: class Sha512:
''' """
SHA512 context. SHA512 context.
''' """
def __init__(self, data: bytes = None) -> None: def __init__(self, data: bytes = None) -> None:
''' """
Creates a hash context object. Creates a hash context object.
''' """
def hash(self, data: bytes) -> None: def hash(self, data: bytes) -> None:
''' """
Update the hash context with hashed data. Update the hash context with hashed data.
''' """
def digest(self) -> bytes: def digest(self) -> bytes:
''' """
Returns the digest of hashed data. Returns the digest of hashed data.
''' """

@ -1,118 +1,126 @@
from typing import * from typing import *
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h # extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
class HDNode: class HDNode:
''' """
BIP0032 HD node structure. BIP0032 HD node structure.
''' """
def __init__(self, def __init__(
depth: int, self,
fingerprint: int, depth: int,
child_num: int, fingerprint: int,
chain_code: bytes, child_num: int,
private_key: bytes = None, chain_code: bytes,
public_key: bytes = None, private_key: bytes = None,
curve_name: str = None) -> None: public_key: bytes = None,
''' curve_name: str = None,
''' ) -> None:
"""
def derive(self, index: int, public: bool=False) -> None: """
'''
def derive(self, index: int, public: bool = False) -> None:
"""
Derive a BIP0032 child node in place. Derive a BIP0032 child node in place.
''' """
def derive_cardano(self, index: int) -> None: def derive_cardano(self, index: int) -> None:
''' """
Derive a BIP0032 child node in place using Cardano algorithm. Derive a BIP0032 child node in place using Cardano algorithm.
''' """
def derive_path(self, path: List[int]) -> None: def derive_path(self, path: List[int]) -> None:
''' """
Go through a list of indexes and iteratively derive a child node in place. Go through a list of indexes and iteratively derive a child node in
''' place.
"""
def serialize_public(self, version: int) -> str: def serialize_public(self, version: int) -> str:
''' """
Serialize the public info from HD node to base58 string. Serialize the public info from HD node to base58 string.
''' """
def serialize_private(self, version: int) -> str: def serialize_private(self, version: int) -> str:
''' """
Serialize the private info HD node to base58 string. Serialize the private info HD node to base58 string.
''' """
def clone(self) -> HDNode: def clone(self) -> HDNode:
''' """
Returns a copy of the HD node. Returns a copy of the HD node.
''' """
def depth(self) -> int: def depth(self) -> int:
''' """
Returns a depth of the HD node. Returns a depth of the HD node.
''' """
def fingerprint(self) -> int: def fingerprint(self) -> int:
''' """
Returns a fingerprint of the HD node (hash of the parent public key). Returns a fingerprint of the HD node (hash of the parent public key).
''' """
def child_num(self) -> int: def child_num(self) -> int:
''' """
Returns a child index of the HD node. Returns a child index of the HD node.
''' """
def chain_code(self) -> bytes: def chain_code(self) -> bytes:
''' """
Returns a chain code of the HD node. Returns a chain code of the HD node.
''' """
def private_key(self) -> bytes: def private_key(self) -> bytes:
''' """
Returns a private key of the HD node. Returns a private key of the HD node.
''' """
def private_key_ext(self) -> bytes: def private_key_ext(self) -> bytes:
''' """
Returns a private key extension of the HD node. Returns a private key extension of the HD node.
''' """
def public_key(self) -> bytes: def public_key(self) -> bytes:
''' """
Returns a public key of the HD node. Returns a public key of the HD node.
''' """
def address(self, version: int) -> str: def address(self, version: int) -> str:
''' """
Compute a base58-encoded address string from the HD node. Compute a base58-encoded address string from the HD node.
''' """
def nem_address(self, network: int) -> str: def nem_address(self, network: int) -> str:
''' """
Compute a NEM address string from the HD node. Compute a NEM address string from the HD node.
''' """
def nem_encrypt(self, transfer_public_key: bytes, iv: bytes, salt: bytes, payload: bytes) -> bytes: def nem_encrypt(
''' self, transfer_public_key: bytes, iv: bytes, salt: bytes, payload: bytes
) -> bytes:
"""
Encrypts payload using the transfer's public key Encrypts payload using the transfer's public key
''' """
def ethereum_pubkeyhash(self) -> bytes: def ethereum_pubkeyhash(self) -> bytes:
''' """
Compute an Ethereum pubkeyhash (aka address) from the HD node. Compute an Ethereum pubkeyhash (aka address) from the HD node.
''' """
def deserialize(self, value: str, version_public: int, version_private: int) -> HDNode: def deserialize(
''' self, value: str, version_public: int, version_private: int
) -> HDNode:
"""
Construct a BIP0032 HD node from a base58-serialized value. Construct a BIP0032 HD node from a base58-serialized value.
''' """
def from_seed(seed: bytes, curve_name: str) -> HDNode: def from_seed(seed: bytes, curve_name: str) -> HDNode:
''' """
Construct a BIP0032 HD node from a BIP0039 seed value. Construct a BIP0032 HD node from a BIP0039 seed value.
''' """
def from_mnemonic_cardano(mnemonic: str, passphrase: str) -> bytes: def from_mnemonic_cardano(mnemonic: str, passphrase: str) -> bytes:
''' """
Convert mnemonic to hdnode Convert mnemonic to hdnode
''' """

@ -1,38 +1,47 @@
from typing import * from typing import *
# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h # extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
def find_word(prefix: str) -> Optional[str]: def find_word(prefix: str) -> Optional[str]:
''' """
Return the first word from the wordlist starting with prefix. Return the first word from the wordlist starting with prefix.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h # extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
def complete_word(prefix: str) -> int: def complete_word(prefix: str) -> int:
''' """
Return possible 1-letter suffixes for given word prefix. 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. Result is a bitmask, with 'a' on the lowest bit, 'b' on the second
''' lowest, etc.
"""
# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h # extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
def generate(strength: int) -> str: def generate(strength: int) -> str:
''' """
Generate a mnemonic of given strength (128, 160, 192, 224 and 256 bits). 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: def from_data(data: bytes) -> str:
''' """
Generate a mnemonic from given data (of 16, 20, 24, 28 and 32 bytes). 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: def check(mnemonic: str) -> bool:
''' """
Check whether given mnemonic is valid. Check whether given mnemonic is valid.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h # extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
def seed(mnemonic: str, passphrase: str, callback: (int, int -> None)=None) -> bytes: def seed(
''' mnemonic: str, passphrase: str, callback: Tuple[int, int, None] = None
) -> bytes:
"""
Generate seed from mnemonic and passphrase. Generate seed from mnemonic and passphrase.
''' """

@ -1,20 +1,23 @@
from typing import * from typing import *
# extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h # extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h
def generate_secret() -> bytes: def generate_secret() -> bytes:
''' """
Generate secret key. Generate secret key.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h # extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h
def publickey(secret_key: bytes) -> bytes: def publickey(secret_key: bytes) -> bytes:
''' """
Computes public key from secret key. 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: def multiply(secret_key: bytes, public_key: bytes) -> bytes:
''' """
Multiplies point defined by public_key with scalar defined by secret_key. Multiplies point defined by public_key with scalar defined by
Useful for ECDH. secret_key. Useful for ECDH.
''' """

@ -1,50 +1,66 @@
from typing import * from typing import *
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h # extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
def generate_secret() -> bytes: def generate_secret() -> bytes:
''' """
Generate secret key. Generate secret key.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h # extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
def publickey(secret_key: bytes) -> bytes: def publickey(secret_key: bytes) -> bytes:
''' """
Computes public key from secret key. Computes public key from secret key.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h # extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
def sign(secret_key: bytes, message: bytes, hasher: str='') -> bytes: def sign(secret_key: bytes, message: bytes, hasher: str = "") -> bytes:
''' """
Uses secret key to produce the signature of message. Uses secret key to produce the signature of message.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h # extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
def sign_ext(secret_key: bytes, secret_extension: bytes, message: bytes) -> bytes: def sign_ext(
''' secret_key: bytes, secret_extension: bytes, message: bytes
) -> bytes:
"""
Uses secret key to produce the cardano signature of message. Uses secret key to produce the cardano signature of message.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h # extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
def verify(public_key: bytes, signature: bytes, message: bytes) -> bool: def verify(public_key: bytes, signature: bytes, message: bytes) -> bool:
''' """
Uses public key to verify the signature of the message. Uses public key to verify the signature of the message.
Returns True on success. Returns True on success.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h # extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
def cosi_combine_publickeys(public_keys: List[bytes]) -> bytes: def cosi_combine_publickeys(public_keys: List[bytes]) -> bytes:
''' """
Combines a list of public keys used in COSI cosigning scheme. Combines a list of public keys used in COSI cosigning scheme.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h # extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
def cosi_combine_signatures(R: bytes, signatures: List[bytes]) -> bytes: def cosi_combine_signatures(R: bytes, signatures: List[bytes]) -> bytes:
''' """
Combines a list of signatures used in COSI cosigning scheme. Combines a list of signatures used in COSI cosigning scheme.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h # extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
def cosi_sign(secret_key: bytes, message: bytes, nonce: bytes, sigR: bytes, combined_pubkey: bytes) -> bytes: def cosi_sign(
''' secret_key: bytes,
message: bytes,
nonce: bytes,
sigR: bytes,
combined_pubkey: bytes,
) -> bytes:
"""
Produce signature of message using COSI cosigning scheme. Produce signature of message using COSI cosigning scheme.
''' """

@ -1,313 +1,407 @@
from typing import * from typing import *
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
class Ge25519: class Ge25519:
''' """
EC point on ED25519 EC point on ED25519
''' """
def __init__(x: Optional[Union[Ge25519, bytes]] = None): def __init__(x: Optional[Union[Ge25519, bytes]] = None):
''' """
Constructor Constructor
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
class Sc25519: class Sc25519:
''' """
EC scalar on SC25519 EC scalar on SC25519
''' """
def __init__(x: Optional[Union[Sc25519, bytes, int]] = None): def __init__(x: Optional[Union[Sc25519, bytes, int]] = None):
''' """
Constructor Constructor
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
class Hasher: class Hasher:
''' """
XMR hasher XMR hasher
''' """
def __init__(x: Optional[bytes] = None): def __init__(x: Optional[bytes] = None):
''' """
Constructor Constructor
''' """
def update(buffer: bytes): def update(buffer: bytes):
''' """
Update hasher Update hasher
''' """
def digest() -> bytes: def digest() -> bytes:
''' """
Computes digest Computes digest
''' """
def copy() -> Hasher: def copy() -> Hasher:
''' """
Creates copy of the hasher, preserving the state Creates copy of the hasher, preserving the state
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def init256_modm(dst: Optional[Sc25519], val: Union[int, bytes, Sc25519]) -> Sc25519: def init256_modm(
''' dst: Optional[Sc25519], val: Union[int, bytes, Sc25519]
) -> Sc25519:
"""
Initializes Sc25519 scalar Initializes Sc25519 scalar
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def check256_modm(val: Sc25519): def check256_modm(val: Sc25519):
''' """
Throws exception if scalar is invalid Throws exception if scalar is invalid
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def iszero256_modm(val: Sc25519) -> bool: def iszero256_modm(val: Sc25519) -> bool:
''' """
Returns False if the scalar is zero Returns False if the scalar is zero
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def eq256_modm(a: Sc25519, b: Sc25519) -> int: def eq256_modm(a: Sc25519, b: Sc25519) -> int:
''' """
Compares scalars, returns 1 on the same value Compares scalars, returns 1 on the same value
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def get256_modm(a: Sc25519) -> int: def get256_modm(a: Sc25519) -> int:
''' """
Extracts 64bit integer from the scalar. Raises exception if scalar is bigger than 2^64 Extracts 64bit integer from the scalar. Raises exception if scalar is
''' bigger than 2^64
"""
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def add256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519: def add256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519:
''' """
Scalar addition Scalar addition
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def sub256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519: def sub256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519:
''' """
Scalar subtraction Scalar subtraction
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def mul256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519: def mul256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519:
''' """
Scalar multiplication Scalar multiplication
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def mulsub256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519, c: Sc25519) -> Sc25519: def mulsub256_modm(
''' r: Optional[Sc25519], a: Sc25519, b: Sc25519, c: Sc25519
) -> Sc25519:
"""
c - a*b c - a*b
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def muladd256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519, c: Sc25519) -> Sc25519: def muladd256_modm(
''' r: Optional[Sc25519], a: Sc25519, b: Sc25519, c: Sc25519
) -> Sc25519:
"""
c + a*b c + a*b
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def inv256_modm(r: Optional[Sc25519], a: Sc25519) -> Sc25519: def inv256_modm(r: Optional[Sc25519], a: Sc25519) -> Sc25519:
''' """
Scalar modular inversion Scalar modular inversion
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def pack256_modm(r: Optional[bytes], a: Sc25519, offset: Optional[int] = 0) -> bytes: def pack256_modm(
''' r: Optional[bytes], a: Sc25519, offset: Optional[int] = 0
) -> bytes:
"""
Scalar compression Scalar compression
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def unpack256_modm(r: Optional[Sc25519], a: bytes, offset: int = 0) -> Sc25519: def unpack256_modm(
''' r: Optional[Sc25519], a: bytes, offset: int = 0
) -> Sc25519:
"""
Scalar decompression Scalar decompression
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def unpack256_modm_noreduce(r: Optional[Sc25519], a: bytes, offset: int = 0) -> Sc25519: def unpack256_modm_noreduce(
''' r: Optional[Sc25519], a: bytes, offset: int = 0
) -> Sc25519:
"""
Scalar decompression, raw, without modular reduction Scalar decompression, raw, without modular reduction
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def ge25519_set_neutral(r: Optional[Ge25519]) -> Ge25519: def ge25519_set_neutral(r: Optional[Ge25519]) -> Ge25519:
''' """
Sets neutral point Sets neutral point
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def ge25519_set_xmr_h(r: Optional[Ge25519]) -> Ge25519: def ge25519_set_xmr_h(r: Optional[Ge25519]) -> Ge25519:
''' """
Sets H point Sets H point
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def ge25519_check(r: Ge25519): def ge25519_check(r: Ge25519):
''' """
Checks point, throws if not on curve Checks point, throws if not on curve
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def ge25519_eq(a: Ge25519, b: Ge25519) -> bool: def ge25519_eq(a: Ge25519, b: Ge25519) -> bool:
''' """
Compares EC points Compares EC points
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def ge25519_add(r: Optional[Ge25519], a: Ge25519, b: Ge25519) -> Ge25519: def ge25519_add(r: Optional[Ge25519], a: Ge25519, b: Ge25519) -> Ge25519:
''' """
Adds EC points Adds EC points
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def ge25519_sub(r: Optional[Ge25519], a: Ge25519, b: Ge25519) -> Ge25519: def ge25519_sub(r: Optional[Ge25519], a: Ge25519, b: Ge25519) -> Ge25519:
''' """
Subtracts EC points Subtracts EC points
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def ge25519_double(r: Optional[Ge25519], p: Ge25519) -> Ge25519: def ge25519_double(r: Optional[Ge25519], p: Ge25519) -> Ge25519:
''' """
EC point doubling EC point doubling
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def ge25519_mul8(r: Optional[Ge25519], p: Ge25519) -> Ge25519: def ge25519_mul8(r: Optional[Ge25519], p: Ge25519) -> Ge25519:
''' """
EC point * 8 EC point * 8
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def ge25519_double_scalarmult_vartime(r: Optional[Ge25519], p1: Ge25519, s1: Sc25519, s2: Sc25519) -> Ge25519: def ge25519_double_scalarmult_vartime(
''' r: Optional[Ge25519], p1: Ge25519, s1: Sc25519, s2: Sc25519
) -> Ge25519:
"""
s1 * G + s2 * p1 s1 * G + s2 * p1
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def ge25519_double_scalarmult_vartime2(r: Optional[Ge25519], p1: Ge25519, s1: Sc25519, p2: Ge25519, s2: Sc25519) -> Ge25519: def ge25519_double_scalarmult_vartime2(
''' r: Optional[Ge25519],
p1: Ge25519,
s1: Sc25519,
p2: Ge25519,
s2: Sc25519,
) -> Ge25519:
"""
s1 * p1 + s2 * p2 s1 * p1 + s2 * p2
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def ge25519_scalarmult_base(r: Optional[Ge25519], s: Union[Sc25519, int]) -> Ge25519: def ge25519_scalarmult_base(
''' r: Optional[Ge25519], s: Union[Sc25519, int]
) -> Ge25519:
"""
s * G s * G
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def ge25519_scalarmult(r: Optional[Ge25519], p: Ge25519, s: Union[Sc25519, int]) -> Ge25519: def ge25519_scalarmult(
''' r: Optional[Ge25519], p: Ge25519, s: Union[Sc25519, int]
) -> Ge25519:
"""
s * p s * p
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def ge25519_pack(r: bytes, p: Ge25519, offset: int = 0) -> bytes: def ge25519_pack(r: bytes, p: Ge25519, offset: int = 0) -> bytes:
''' """
Point compression Point compression
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def ge25519_unpack_vartime(r: Optional[Ge25519], buff: bytes, offset: int = 0) -> Ge25519: def ge25519_unpack_vartime(
''' r: Optional[Ge25519], buff: bytes, offset: int = 0
) -> Ge25519:
"""
Point decompression Point decompression
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def base58_addr_encode_check(tag: int, buff: bytes) -> bytes: def base58_addr_encode_check(tag: int, buff: bytes) -> bytes:
''' """
Monero block base 58 encoding Monero block base 58 encoding
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def base58_addr_decode_check(buff: bytes) -> Tuple[bytes, int]: def base58_addr_decode_check(buff: bytes) -> Tuple[bytes, int]:
''' """
Monero block base 58 decoding, returning (decoded, tag) or raising on error. Monero block base 58 decoding, returning (decoded, tag) or raising on
''' error.
"""
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def xmr_random_scalar(r: Optional[Sc25519] = None) -> Sc25519: def xmr_random_scalar(r: Optional[Sc25519] = None) -> Sc25519:
''' """
Generates a random scalar Generates a random scalar
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def xmr_fast_hash(r: Optional[bytes], buff: bytes) -> bytes: def xmr_fast_hash(r: Optional[bytes], buff: bytes) -> bytes:
''' """
XMR fast hash XMR fast hash
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def xmr_hash_to_ec(r: Optional[Ge25519], buff: bytes) -> Ge25519: def xmr_hash_to_ec(r: Optional[Ge25519], buff: bytes) -> Ge25519:
''' """
XMR hashing to EC point XMR hashing to EC point
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def xmr_hash_to_scalar(r: Optional[Sc25519], buff: bytes) -> Sc25519: def xmr_hash_to_scalar(r: Optional[Sc25519], buff: bytes) -> Sc25519:
''' """
XMR hashing to EC scalar XMR hashing to EC scalar
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def xmr_derivation_to_scalar(r: Optional[Sc25519], p: Ge25519, output_index: int) -> Sc25519: def xmr_derivation_to_scalar(
''' r: Optional[Sc25519], p: Ge25519, output_index: int
) -> Sc25519:
"""
H_s(derivation || varint(output_index)) H_s(derivation || varint(output_index))
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def xmr_generate_key_derivation(r: Optional[Ge25519], A: Ge25519, b: Sc25519) -> Ge25519: def xmr_generate_key_derivation(
''' r: Optional[Ge25519], A: Ge25519, b: Sc25519
) -> Ge25519:
"""
8*(key2*key1) 8*(key2*key1)
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def xmr_derive_private_key(r: Optional[Sc25519], deriv: Ge25519, idx: int, base: Sc25519) -> Sc25519: def xmr_derive_private_key(
''' r: Optional[Sc25519], deriv: Ge25519, idx: int, base: Sc25519
) -> Sc25519:
"""
base + H_s(derivation || varint(output_index)) base + H_s(derivation || varint(output_index))
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def xmr_derive_public_key(r: Optional[Ge25519], deriv: Ge25519, idx: int, base: Ge25519) -> Ge25519: def xmr_derive_public_key(
''' r: Optional[Ge25519], deriv: Ge25519, idx: int, base: Ge25519
) -> Ge25519:
"""
H_s(derivation || varint(output_index))G + base H_s(derivation || varint(output_index))G + base
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def xmr_add_keys2(r: Optional[Ge25519], a: Sc25519, b: Sc25519, B: Ge25519) -> Ge25519: def xmr_add_keys2(
''' r: Optional[Ge25519], a: Sc25519, b: Sc25519, B: Ge25519
) -> Ge25519:
"""
aG + bB, G is basepoint aG + bB, G is basepoint
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def xmr_add_keys2_vartime(r: Optional[Ge25519], a: Sc25519, b: Sc25519, B: Ge25519) -> Ge25519: def xmr_add_keys2_vartime(
''' r: Optional[Ge25519], a: Sc25519, b: Sc25519, B: Ge25519
) -> Ge25519:
"""
aG + bB, G is basepoint aG + bB, G is basepoint
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def xmr_add_keys3(r: Optional[Ge25519], a: Sc25519, A: Ge25519, b: Sc25519, B: Ge25519) -> Ge25519: def xmr_add_keys3(
''' r: Optional[Ge25519], a: Sc25519, A: Ge25519, b: Sc25519, B: Ge25519
) -> Ge25519:
"""
aA + bB aA + bB
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def xmr_add_keys3_vartime(r: Optional[Ge25519], a: Sc25519, A: Ge25519, b: Sc25519, B: Ge25519) -> Ge25519: def xmr_add_keys3_vartime(
''' r: Optional[Ge25519], a: Sc25519, A: Ge25519, b: Sc25519, B: Ge25519
) -> Ge25519:
"""
aA + bB aA + bB
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def xmr_get_subaddress_secret_key(r: Optional[Sc25519], major: int, minor: int, m: Sc25519) -> Sc25519: def xmr_get_subaddress_secret_key(
''' r: Optional[Sc25519], major: int, minor: int, m: Sc25519
) -> Sc25519:
"""
Hs(SubAddr || a || index_major || index_minor) Hs(SubAddr || a || index_major || index_minor)
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def xmr_gen_c(r: Optional[Ge25519], a: Sc25519, amount: int) -> Ge25519: def xmr_gen_c(r: Optional[Ge25519], a: Sc25519, amount: int) -> Ge25519:
''' """
aG + amount * H aG + amount * H
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def ct_equals(a: bytes, b: bytes) -> bool: def ct_equals(a: bytes, b: bytes) -> bool:
''' """
Constant time buffer comparison Constant time buffer comparison
''' """

@ -1,13 +1,15 @@
from typing import * from typing import *
# extmod/modtrezorcrypto/modtrezorcrypto-nem.h # extmod/modtrezorcrypto/modtrezorcrypto-nem.h
def validate_address(address: str, network: int) -> bool: def validate_address(address: str, network: int) -> bool:
''' """
Validate a NEM address Validate a NEM address
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-nem.h # extmod/modtrezorcrypto/modtrezorcrypto-nem.h
def compute_address(public_key: bytes, network: int) -> str: def compute_address(public_key: bytes, network: int) -> str:
''' """
Compute a NEM address from a public key Compute a NEM address from a public key
''' """

@ -1,40 +1,48 @@
from typing import * from typing import *
# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h # extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
def generate_secret() -> bytes: def generate_secret() -> bytes:
''' """
Generate secret key. Generate secret key.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h # extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
def publickey(secret_key: bytes, compressed: bool = True) -> bytes: def publickey(secret_key: bytes, compressed: bool = True) -> bytes:
''' """
Computes public key from secret key. Computes public key from secret key.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h # extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
def sign(secret_key: bytes, digest: bytes, compressed: bool = True) -> bytes: def sign(
''' secret_key: bytes, digest: bytes, compressed: bool = True
) -> bytes:
"""
Uses secret key to produce the signature of the digest. 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: def verify(public_key: bytes, signature: bytes, digest: bytes) -> bool:
''' """
Uses public key to verify the signature of the digest. Uses public key to verify the signature of the digest.
Returns True on success. Returns True on success.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h # extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
def verify_recover(signature: bytes, digest: bytes) -> bytes: def verify_recover(signature: bytes, digest: bytes) -> bytes:
''' """
Uses signature of the digest to verify the digest and recover the public key. Uses signature of the digest to verify the digest and recover the public
Returns public key on success, None on failure. key. Returns public key on success, None if the signature is invalid.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h # extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
def multiply(secret_key: bytes, public_key: bytes) -> bytes: def multiply(secret_key: bytes, public_key: bytes) -> bytes:
''' """
Multiplies point defined by public_key with scalar defined by secret_key. Multiplies point defined by public_key with scalar defined by
Useful for ECDH. secret_key. Useful for ECDH.
''' """

@ -1,19 +1,22 @@
from typing import * from typing import *
# extmod/modtrezorcrypto/modtrezorcrypto-random.h # extmod/modtrezorcrypto/modtrezorcrypto-random.h
def uniform(n: int) -> int: def uniform(n: int) -> int:
''' """
Compute uniform random number from interval 0 ... n - 1. Compute uniform random number from interval 0 ... n - 1.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-random.h # extmod/modtrezorcrypto/modtrezorcrypto-random.h
def bytes(len: int) -> bytes: def bytes(len: int) -> bytes:
''' """
Generate random bytes sequence of length len. Generate random bytes sequence of length len.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-random.h # extmod/modtrezorcrypto/modtrezorcrypto-random.h
def shuffle(data: list) -> None: def shuffle(data: list) -> None:
''' """
Shuffles items of given list (in-place). Shuffles items of given list (in-place).
''' """

@ -1,40 +1,51 @@
from typing import * from typing import *
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h # extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
def generate_secret() -> bytes: def generate_secret() -> bytes:
''' """
Generate secret key. Generate secret key.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h # extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
def publickey(secret_key: bytes, compressed: bool = True) -> bytes: def publickey(secret_key: bytes, compressed: bool = True) -> bytes:
''' """
Computes public key from secret key. Computes public key from secret key.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h # extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
def sign(secret_key: bytes, digest: bytes, compressed: bool = True, canonical: int = None) -> bytes: def sign(
''' secret_key: bytes,
digest: bytes,
compressed: bool = True,
canonical: int = None,
) -> bytes:
"""
Uses secret key to produce the signature of the digest. 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: def verify(public_key: bytes, signature: bytes, digest: bytes) -> bool:
''' """
Uses public key to verify the signature of the digest. Uses public key to verify the signature of the digest.
Returns True on success. Returns True on success.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h # extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
def verify_recover(signature: bytes, digest: bytes) -> bytes: def verify_recover(signature: bytes, digest: bytes) -> bytes:
''' """
Uses signature of the digest to verify the digest and recover the public key. Uses signature of the digest to verify the digest and recover the public
Returns public key on success, None on failure. key. Returns public key on success, None if the signature is invalid.
''' """
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h # extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
def multiply(secret_key: bytes, public_key: bytes) -> bytes: def multiply(secret_key: bytes, public_key: bytes) -> bytes:
''' """
Multiplies point defined by public_key with scalar defined by secret_key. Multiplies point defined by public_key with scalar defined by
Useful for ECDH. secret_key. Useful for ECDH.
''' """

@ -0,0 +1,48 @@
from typing import *
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1_zkp.h
def generate_secret() -> bytes:
"""
Generate secret key.
"""
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1_zkp.h
def publickey(secret_key: bytes, compressed: bool = True) -> bytes:
"""
Computes public key from secret key.
"""
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1_zkp.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_zkp.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_zkp.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 if the signature is invalid.
"""
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1_zkp.h
def multiply(secret_key: bytes, public_key: bytes) -> bytes:
"""
Multiplies point defined by public_key with scalar defined by
secret_key. Useful for ECDH.
"""

@ -1,4 +1,4 @@
from typing import * # noqa: F401 from typing import *
# extmod/modtrezorcrypto/modtrezorcrypto-shamir.h # extmod/modtrezorcrypto/modtrezorcrypto-shamir.h

@ -1,206 +1,223 @@
from typing import * from typing import *
# extmod/modtrezorio/modtrezorio-flash.h # extmod/modtrezorio/modtrezorio-flash.h
class FlashOTP: class FlashOTP:
''' """
''' """
def __init__(self) -> None: def __init__(self) -> None:
''' """
''' """
def FlashOTP.write(self, block: int, offset: int, data: bytes) -> None: def write(self, block: int, offset: int, data: bytes) -> None:
''' """
Writes data to OTP flash Writes data to OTP flash
''' """
def FlashOTP.read(self, block: int, offset: int, data: bytearray) -> None: def read(self, block: int, offset: int, data: bytearray) -> None:
''' """
Reads data from OTP flash Reads data from OTP flash
''' """
def FlashOTP.lock(self, block: int) -> None: def lock(self, block: int) -> None:
''' """
Lock OTP flash block Lock OTP flash block
''' """
def FlashOTP.is_locked(self, block: int) -> bool: def is_locked(self, block: int) -> bool:
''' """
Is OTP flash block locked? Is OTP flash block locked?
''' """
# extmod/modtrezorio/modtrezorio-hid.h # extmod/modtrezorio/modtrezorio-hid.h
class HID: class HID:
''' """
USB HID interface configuration. USB HID interface configuration.
''' """
def __init__(self, def __init__(
iface_num: int, self,
ep_in: int, iface_num: int,
ep_out: int, ep_in: int,
report_desc: bytes, ep_out: int,
subclass: int = 0, report_desc: bytes,
protocol: int = 0, subclass: int = 0,
polling_interval: int = 1, protocol: int = 0,
max_packet_len: int = 64) -> None: polling_interval: int = 1,
''' max_packet_len: int = 64,
''' ) -> None:
"""
"""
def iface_num(self) -> int: def iface_num(self) -> int:
''' """
Returns the configured number of this interface. Returns the configured number of this interface.
''' """
def write(self, msg: bytes) -> int: def write(self, msg: bytes) -> int:
''' """
Sends message using USB HID (device) or UDP (emulator). Sends message using USB HID (device) or UDP (emulator).
''' """
# extmod/modtrezorio/modtrezorio-poll.h # extmod/modtrezorio/modtrezorio-poll.h
def poll(ifaces: Iterable[int], list_ref: List, timeout_us: int) -> bool: def poll(ifaces: Iterable[int], list_ref: List, timeout_us: int) -> bool:
''' """
Wait until one of `ifaces` is ready to read or write (using masks Wait until one of `ifaces` is ready to read or write (using masks
`list_ref`: `list_ref`:
`list_ref[0]` - the interface number, including the mask `list_ref[0]` - the interface number, including the mask
`list_ref[1]` - for touch event, tuple of (event_type, x_position, y_position) `list_ref[1]` - for touch event, tuple of (event_type, x_position,
y_position)
- for USB read event, received bytes - for USB read event, received bytes
If timeout occurs, False is returned, True otherwise. If timeout occurs, False is returned, True otherwise.
''' """
# extmod/modtrezorio/modtrezorio-sbu.h # extmod/modtrezorio/modtrezorio-sbu.h
class SBU: class SBU:
''' """
''' """
def __init__(self) -> None: def __init__(self) -> None:
''' """
''' """
def set(self, sbu1: bool, sbu2: bool) -> None: def set(self, sbu1: bool, sbu2: bool) -> None:
''' """
Sets SBU wires to sbu1 and sbu2 values respectively Sets SBU wires to sbu1 and sbu2 values respectively
''' """
# extmod/modtrezorio/modtrezorio-sdcard.h # extmod/modtrezorio/modtrezorio-sdcard.h
class SDCard: class SDCard:
''' """
''' """
def __init__(self) -> None: def __init__(self) -> None:
''' """
''' """
def present(self) -> bool: def present(self) -> bool:
''' """
Returns True if SD card is detected, False otherwise. Returns True if SD card is detected, False otherwise.
''' """
def power(self, state: bool) -> bool: def power(self, state: bool) -> bool:
''' """
Power on or power off the SD card interface. Power on or power off the SD card interface.
Returns True if in case of success, False otherwise. Returns True if in case of success, False otherwise.
''' """
def capacity(self) -> int: def capacity(self) -> int:
''' """
Returns capacity of the SD card in bytes, or zero if not present. Returns capacity of the SD card in bytes, or zero if not present.
''' """
def read(self, block_num: int, buf: bytearray) -> bool: def read(self, block_num: int, buf: bytearray) -> bool:
''' """
Reads blocks starting with block_num from the SD card into buf. Reads blocks starting with block_num from the SD card into buf.
Number of bytes read is length of buf rounded down to multiply of SDCARD_BLOCK_SIZE. Number of bytes read is length of buf rounded down to multiply of
Returns True if in case of success, False otherwise. SDCARD_BLOCK_SIZE. Returns True if in case of success, False otherwise.
''' """
def write(self, block_num: int, buf: bytes) -> bool: def write(self, block_num: int, buf: bytes) -> bool:
''' """
Writes blocks starting with block_num from buf to the SD card. Writes blocks starting with block_num from buf to the SD card.
Number of bytes written is length of buf rounded down to multiply of SDCARD_BLOCK_SIZE. Number of bytes written is length of buf rounded down to multiply of
Returns True if in case of success, False otherwise. SDCARD_BLOCK_SIZE. Returns True if in case of success, False otherwise.
''' """
# extmod/modtrezorio/modtrezorio-usb.h # extmod/modtrezorio/modtrezorio-usb.h
class USB: class USB:
''' """
USB device configuration. USB device configuration.
''' """
def __init__(self, def __init__(
device_class: int=0, self,
device_subclass: int=0, vendor_id: int,
device_protocol: int=0, product_id: int,
vendor_id: int, release_num: int,
product_id: int, device_class: int = 0,
release_num: int, device_subclass: int = 0,
manufacturer: str='', device_protocol: int = 0,
product: str='', manufacturer: str = "",
serial_number: str='', product: str = "",
interface: str='', serial_number: str = "",
usb21_enabled: bool=True, interface: str = "",
usb21_landing: bool=True) -> None: usb21_enabled: bool = True,
''' usb21_landing: bool = True,
''' ) -> None:
"""
"""
def add(self, iface: Union[HID, VCP, WebUSB]) -> None: def add(self, iface: Union[HID, VCP, WebUSB]) -> None:
''' """
Registers passed interface into the USB stack. Registers passed interface into the USB stack.
''' """
def open(self) -> None: def open(self) -> None:
''' """
Initializes the USB stack. Initializes the USB stack.
''' """
def close(self) -> None: def close(self) -> None:
''' """
Cleans up the USB stack. Cleans up the USB stack.
''' """
# extmod/modtrezorio/modtrezorio-vcp.h # extmod/modtrezorio/modtrezorio-vcp.h
class VCP: class VCP:
''' """
USB VCP interface configuration. USB VCP interface configuration.
''' """
def __init__(self, def __init__(
iface_num: int, self,
data_iface_num: int, iface_num: int,
ep_in: int, data_iface_num: int,
ep_out: int, ep_in: int,
ep_cmd: int) -> None: ep_out: int,
''' ep_cmd: int,
''' ) -> None:
"""
"""
def iface_num(self) -> int: def iface_num(self) -> int:
''' """
Returns the configured number of this interface. Returns the configured number of this interface.
''' """
# extmod/modtrezorio/modtrezorio-webusb.h # extmod/modtrezorio/modtrezorio-webusb.h
class WebUSB: class WebUSB:
''' """
USB WebUSB interface configuration. USB WebUSB interface configuration.
''' """
def __init__(self, def __init__(
iface_num: int, self,
ep_in: int, iface_num: int,
ep_out: int, ep_in: int,
subclass: int = 0, ep_out: int,
protocol: int = 0, subclass: int = 0,
polling_interval: int = 1, protocol: int = 0,
max_packet_len: int = 64) -> None: polling_interval: int = 1,
''' max_packet_len: int = 64,
''' ) -> None:
"""
"""
def iface_num(self) -> int: def iface_num(self) -> int:
''' """
Returns the configured number of this interface. Returns the configured number of this interface.
''' """
def write(self, msg: bytes) -> int: def write(self, msg: bytes) -> int:
''' """
Sends message using USB WebUSB (device) or UDP (emulator). Sends message using USB WebUSB (device) or UDP (emulator).
''' """

@ -1,124 +1,182 @@
from typing import * from typing import *
# extmod/modtrezorui/modtrezorui-display.h # extmod/modtrezorui/modtrezorui-display.h
class Display: class Display:
''' """
Provide access to device display. Provide access to device display.
''' """
def __init__(self) -> None: def __init__(self) -> None:
''' """
Initialize the display. Initialize the display.
''' """
def clear(self) -> None: def clear(self) -> None:
''' """
Clear display with black color. Clear display with black color.
''' """
def refresh(self) -> None: def refresh(self) -> None:
''' """
Refresh display (update screen). Refresh display (update screen).
''' """
def bar(self, x: int, y: int, w: int, h: int, color: int) -> None: def bar(self, 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. Renders a bar at position (x,y = upper left corner) with width w and
''' height h of color color.
"""
def bar_radius(self, x: int, y: int, w: int, h: int, fgcolor: int, bgcolor: int = None, radius: int = None) -> None:
''' def bar_radius(
Renders a rounded bar at position (x,y = upper left corner) with width w and height h of color fgcolor. self,
Background is set to bgcolor and corners are drawn with radius 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.
"""
def image(self, x: int, y: int, image: bytes) -> None: def image(self, x: int, y: int, image: bytes) -> None:
''' """
Renders an image at position (x,y). Renders an image at position (x,y).
The image needs to be in TREZOR Optimized Image Format (TOIF) - full-color mode. The image needs to be in TREZOR Optimized Image Format (TOIF) -
''' full-color mode.
"""
def avatar(self, x: int, y: int, image: bytes, fgcolor: int, bgcolor: int) -> None:
''' def avatar(
self, x: int, y: int, image: bytes, fgcolor: int, bgcolor: int
) -> None:
"""
Renders an avatar at position (x,y). Renders an avatar at position (x,y).
The image needs to be in TREZOR Optimized Image Format (TOIF) - full-color mode. The image needs to be in TREZOR Optimized Image Format (TOIF) -
Image needs to be of exactly AVATAR_IMAGE_SIZE x AVATAR_IMAGE_SIZE pixels size. full-color mode. Image needs to be of exactly AVATAR_IMAGE_SIZE x
''' AVATAR_IMAGE_SIZE pixels size.
"""
def icon(self, x: int, y: int, icon: bytes, fgcolor: int, bgcolor: int) -> None:
''' def icon(
Renders an icon at position (x,y), fgcolor is used as foreground color, bgcolor as background. self, x: int, y: int, icon: bytes, fgcolor: int, bgcolor: int
The icon needs to be in TREZOR Optimized Image Format (TOIF) - gray-scale mode. ) -> None:
''' """
Renders an icon at position (x,y), fgcolor is used as foreground color,
def loader(self, progress: int, yoffset: int, fgcolor: int, bgcolor: int, icon: bytes = None, iconfgcolor: int = None) -> None: bgcolor as background. The icon needs to be in TREZOR Optimized Image
''' Format (TOIF) - gray-scale mode.
"""
def loader(
self,
progress: int,
indeterminate: bool,
yoffset: int,
fgcolor: int,
bgcolor: int,
icon: bytes = None,
iconfgcolor: int = None,
) -> None:
"""
Renders a rotating loader graphic. Renders a rotating loader graphic.
Progress determines its position (0-1000), fgcolor is used as foreground color, bgcolor as background. Progress determines its position (0-1000), fgcolor is used as foreground
When icon and iconfgcolor are provided, an icon is drawn in the middle using the color specified in iconfgcolor. color, bgcolor as background. When icon and iconfgcolor are provided, an
Icon needs to be of exactly LOADER_ICON_SIZE x LOADER_ICON_SIZE pixels size. icon is drawn in the middle using the color specified in iconfgcolor.
''' Icon needs to be of exactly LOADER_ICON_SIZE x LOADER_ICON_SIZE pixels
size.
"""
def print(self, text: str) -> None: def print(self, text: str) -> None:
''' """
Renders text using 5x8 bitmap font (using special text mode). Renders text using 5x8 bitmap font (using special text mode).
''' """
def text(self, x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int, minwidth: int=None) -> int: def text(
''' self,
Renders left-aligned text at position (x,y) where x is left position and y is baseline. x: int,
Font font is used for rendering, fgcolor is used as foreground color, bgcolor as background. y: int,
Fills at least minwidth pixels with bgcolor. text: str,
Returns width of rendered text in pixels. font: int,
''' fgcolor: int,
bgcolor: int,
def text_center(self, x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int, minwidth: int=None) -> int: minwidth: int = None,
''' ) -> int:
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. Renders left-aligned text at position (x,y) where x is left position and
Fills at least minwidth pixels with bgcolor. y is baseline. Font font is used for rendering, fgcolor is used as
Returns width of rendered text in pixels. foreground color, bgcolor as background. Fills at least minwidth pixels
''' with bgcolor. Returns width of rendered text in pixels.
"""
def text_right(self, x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int, minwidth: int=None) -> int:
''' def text_center(
Renders right-aligned text at position (x,y) where x is right position and y is baseline. self,
Font font is used for rendering, fgcolor is used as foreground color, bgcolor as background. x: int,
Fills at least minwidth pixels with bgcolor. y: int,
Returns width of rendered text in pixels. text: str,
''' font: int,
fgcolor: int,
bgcolor: int,
minwidth: int = None,
) -> int:
"""
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. Fills at least minwidth pixels with
bgcolor. Returns width of rendered text in pixels.
"""
def text_right(
self,
x: int,
y: int,
text: str,
font: int,
fgcolor: int,
bgcolor: int,
minwidth: int = None,
) -> int:
"""
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. Fills at least minwidth pixels
with bgcolor. Returns width of rendered text in pixels.
"""
def text_width(self, text: str, font: int) -> int: def text_width(self, text: str, font: int) -> int:
''' """
Returns a width of text in pixels. Font font is used for rendering. Returns a width of text in pixels. Font font is used for rendering.
''' """
def qrcode(self, x: int, y: int, data: bytes, scale: int) -> None: def qrcode(self, x: int, y: int, data: bytes, scale: int) -> None:
''' """
Renders data encoded as a QR code centered at position (x,y). Renders data encoded as a QR code centered at position (x,y).
Scale determines a zoom factor. Scale determines a zoom factor.
''' """
def orientation(self, degrees: int = None) -> int: def orientation(self, degrees: int = None) -> int:
''' """
Sets display orientation to 0, 90, 180 or 270 degrees. Sets display orientation to 0, 90, 180 or 270 degrees.
Everything needs to be redrawn again when this function is used. Everything needs to be redrawn again when this function is used.
Call without the degrees parameter to just perform the read of the value. Call without the degrees parameter to just perform the read of the
''' value.
"""
def backlight(self, val: int = None) -> int: def backlight(self, val: int = None) -> int:
''' """
Sets backlight intensity to the value specified in val. Sets backlight intensity to the value specified in val.
Call without the val parameter to just perform the read of the value. Call without the val parameter to just perform the read of the value.
''' """
def offset(self, xy: Tuple[int, int] = None) -> Tuple[int, int]: def offset(self, xy: Tuple[int, int] = None) -> Tuple[int, int]:
''' """
Sets offset (x, y) for all subsequent drawing calls. Sets offset (x, y) for all subsequent drawing calls.
Call without the xy parameter to just perform the read of the value. Call without the xy parameter to just perform the read of the value.
''' """
def save(self, prefix: str) -> None: def save(self, prefix: str) -> None:
''' """
Saves current display contents to PNG file with given prefix. Saves current display contents to PNG file with given prefix.
''' """

@ -1,32 +1,36 @@
from typing import * from typing import *
# extmod/modtrezorutils/modtrezorutils.c # extmod/modtrezorutils/modtrezorutils.c
def consteq(sec: bytes, pub: bytes) -> bool: def consteq(sec: bytes, pub: bytes) -> bool:
''' """
Compares the private information in `sec` with public, user-provided Compares the private information in `sec` with public, user-provided
information in `pub`. Runs in constant time, corresponding to a length information in `pub`. Runs in constant time, corresponding to a length
of `pub`. Can access memory behind valid length of `sec`, caller is of `pub`. Can access memory behind valid length of `sec`, caller is
expected to avoid any invalid memory access. expected to avoid any invalid memory access.
''' """
# extmod/modtrezorutils/modtrezorutils.c # extmod/modtrezorutils/modtrezorutils.c
def memcpy(dst: bytearray, dst_ofs: int, def memcpy(
src: bytearray, src_ofs: int, dst: bytearray, dst_ofs: int, src: bytearray, src_ofs: int, n: int
n: int) -> int: ) -> int:
''' """
Copies at most `n` bytes from `src` at offset `src_ofs` to Copies at most `n` bytes from `src` at offset `src_ofs` to
`dst` at offset `dst_ofs`. Returns the number of actually `dst` at offset `dst_ofs`. Returns the number of actually
copied bytes. copied bytes.
''' """
# extmod/modtrezorutils/modtrezorutils.c # extmod/modtrezorutils/modtrezorutils.c
def halt(msg: str = None) -> None: def halt(msg: str = None) -> None:
''' """
Halts execution. Halts execution.
''' """
# extmod/modtrezorutils/modtrezorutils.c # extmod/modtrezorutils/modtrezorutils.c
def set_mode_unprivileged() -> None: def set_mode_unprivileged() -> None:
''' """
Set unprivileged mode. Set unprivileged mode.
''' """

@ -1,5 +1,15 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import glob
import os import os
import re
import shutil
import subprocess
import sys
import tempfile
CORE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
EXTMOD_PATH = os.path.join(CORE_DIR, "embed", "extmod")
MOCKS_PATH = os.path.join(CORE_DIR, "mocks", "generated")
COMMENT_PREFIX = "/// " COMMENT_PREFIX = "/// "
@ -28,17 +38,17 @@ def split_to_parts(line, mod_desc=None):
current_class = line[6:].split("(")[0].strip(":") current_class = line[6:].split("(")[0].strip(":")
current_indent = 0 current_indent = 0
yield (current_package, "\n") yield (current_package, "\n\n")
yield (current_package, "# " + mod_desc + "\n") yield (current_package, "# " + mod_desc + "\n")
elif line.startswith("def "): elif line.startswith("def "):
current_method = line[4:].split("(")[0] current_method = line[4:].split("(")[0]
yield (current_package, "\n")
if current_class is None: if current_class is None:
yield (current_package, "\n\n")
yield (current_package, "# " + mod_desc + "\n") yield (current_package, "# " + mod_desc + "\n")
else: else:
yield (current_package, "\n")
current_indent = 4 current_indent = 4
line = current_indent * " " + line line = current_indent * " " + line
@ -49,15 +59,19 @@ def split_to_parts(line, mod_desc=None):
def store_to_file(dest, parts): def store_to_file(dest, parts):
for package, line in parts: for package, line in parts:
package = package.replace(".", "/") package = package.replace(".", "/")
dirpath = os.path.join(os.path.abspath(dest), os.path.dirname(package)) dirpath = os.path.join(dest, os.path.dirname(package))
filename = os.path.basename(package) + ".py" filename = os.path.basename(package) + ".py"
filepath = os.path.join(dirpath, filename)
if not os.path.exists(dirpath): os.makedirs(dirpath, exist_ok=True)
os.makedirs(dirpath)
open(os.path.join(dirpath, "__init__.py"), "w").close() if os.path.isdir(os.path.join(dest, package)):
open(os.path.join(dirpath, ".mock-generated"), "w").close() if not line.strip():
continue
print("Package exists: {}".format(package))
print("You should set 'package:' in {}".format(line.strip()))
sys.exit(1)
filepath = os.path.join(dirpath, filename)
if not os.path.exists(filepath): if not os.path.exists(filepath):
with open(filepath, "a") as f: with open(filepath, "a") as f:
@ -72,17 +86,16 @@ def build_module(mod_file, dest):
global current_class global current_class
global current_package global current_package
if not (mod_file.endswith(".h") or mod_file.endswith(".c")): filename = os.path.basename(mod_file)
return assert filename.startswith("mod")
if not os.path.basename(mod_file).startswith("mod"): assert filename.endswith(".c") or filename.endswith(".h")
return # modfoobar-xyz.h -> foobar-xyz
name = filename[3:-2]
current_indent = 0 current_indent = 0
current_class = None current_class = None
current_package = ( current_package = name.split("-")[0]
os.path.basename(mod_file).split(".")[0].split("-")[0].replace("mod", "") mod_desc = re.sub(r"^.*/embed/", "", mod_file)
)
mod_desc = mod_file.replace("../embed/extmod", "extmod")
for l in open(mod_file): for l in open(mod_file):
if not l.startswith(COMMENT_PREFIX): if not l.startswith(COMMENT_PREFIX):
@ -92,34 +105,31 @@ def build_module(mod_file, dest):
store_to_file(dest, split_to_parts(l, mod_desc)) store_to_file(dest, split_to_parts(l, mod_desc))
def build_directory(dir, dest): def build_directory(src, dest):
print("Building mocks for", dir, "to", dest) for modfile in sorted(glob.glob(os.path.join(src, "**", "mod*.[ch]"))):
for pkg in sorted( build_module(modfile, dest)
[x for x in os.listdir(dir) if os.path.isdir(os.path.join(dir, x))]
):
for mod in sorted(os.listdir(os.path.join(dir, pkg))):
build_module(os.path.join(dir, pkg, mod), dest)
def clear_directory(top_dir): def do_check():
print("Clearing up directory", top_dir) with tempfile.TemporaryDirectory() as tmpdir:
for root, dirs, files in os.walk(top_dir, topdown=False): build_directory(EXTMOD_PATH, tmpdir)
if ".mock-generated" not in files: diff_out = subprocess.run(
# print("Not a mock directory", root) ["diff", "-ur", MOCKS_PATH, tmpdir],
continue stdout=subprocess.PIPE,
for name in files: universal_newlines=True,
# print('Deleting file', os.path.join(root, name)) ).stdout
os.remove(os.path.join(root, name)) if diff_out.strip():
for name in dirs: print(diff_out, end="")
# print('Deleting directory', os.path.join(root, name)) sys.exit(1)
try:
os.rmdir(os.path.join(root, name))
except FileNotFoundError:
pass
os.rmdir(root) def do_generate():
shutil.rmtree(MOCKS_PATH)
build_directory(EXTMOD_PATH, MOCKS_PATH)
if __name__ == "__main__": if __name__ == "__main__":
clear_directory("../mocks/generated") if len(sys.argv) > 1 and sys.argv[1] == "--check":
build_directory("../embed/extmod", "../mocks/generated") do_check()
else:
do_generate()

@ -14,6 +14,8 @@ ignore =
E741, E741,
# W503: line break before binary operator # W503: line break before binary operator
W503 W503
per-file-ignores =
core/mocks/generated/*:F4
[isort] [isort]
multi_line_output = 3 multi_line_output = 3

Loading…
Cancel
Save