mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-09 20:56:05 +00:00
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
This commit is contained in:
parent
ffcb5e99cc
commit
482b4569f5
@ -47,11 +47,11 @@ STATIC secbool wrapped_ui_wait_callback(uint32_t wait, uint32_t progress,
|
||||
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
|
||||
/// called from this module!
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorconfig_init(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_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);
|
||||
|
||||
/// def unlock(pin: int) -> bool:
|
||||
/// '''
|
||||
/// """
|
||||
/// Attempts to unlock the storage with given PIN. Returns True on
|
||||
/// success, False on failure.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorconfig_unlock(mp_obj_t pin) {
|
||||
uint32_t pin_i = trezor_obj_get_uint(pin);
|
||||
if (sectrue != storage_unlock(pin_i)) {
|
||||
@ -81,9 +81,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorconfig_unlock_obj,
|
||||
mod_trezorconfig_unlock);
|
||||
|
||||
/// def check_pin(pin: int) -> bool:
|
||||
/// '''
|
||||
/// """
|
||||
/// Check the given PIN. Returns True on success, False on failure.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorconfig_check_pin(mp_obj_t 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);
|
||||
|
||||
/// def lock() -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Locks the storage.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorconfig_lock(void) {
|
||||
storage_lock();
|
||||
return mp_const_none;
|
||||
@ -102,9 +102,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_lock_obj,
|
||||
mod_trezorconfig_lock);
|
||||
|
||||
/// def has_pin() -> bool:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns True if storage has a configured PIN, False otherwise.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorconfig_has_pin(void) {
|
||||
if (sectrue != storage_has_pin()) {
|
||||
return mp_const_false;
|
||||
@ -115,9 +115,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_has_pin_obj,
|
||||
mod_trezorconfig_has_pin);
|
||||
|
||||
/// def get_pin_rem() -> int:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns the number of remaining PIN entry attempts.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorconfig_get_pin_rem(void) {
|
||||
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);
|
||||
|
||||
/// def change_pin(pin: int, newpin: int) -> bool:
|
||||
/// '''
|
||||
/// """
|
||||
/// 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) {
|
||||
uint32_t pin_i = trezor_obj_get_uint(pin);
|
||||
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,
|
||||
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).
|
||||
/// Raises a RuntimeError if decryption or authentication of the stored
|
||||
/// value fails.
|
||||
/// '''
|
||||
/// """
|
||||
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 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,
|
||||
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.
|
||||
/// '''
|
||||
/// """
|
||||
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 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,
|
||||
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.
|
||||
/// '''
|
||||
/// """
|
||||
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 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,
|
||||
mod_trezorconfig_delete);
|
||||
|
||||
/// 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.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorconfig_set_counter(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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,
|
||||
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
|
||||
/// returns the new value.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorconfig_next_counter(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// def wipe() -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Erases the whole config. Use with caution!
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorconfig_wipe(void) {
|
||||
storage_wipe();
|
||||
return mp_const_none;
|
||||
|
@ -33,9 +33,9 @@ enum AESMode {
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class AES:
|
||||
/// '''
|
||||
/// """
|
||||
/// AES context.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_AES_t {
|
||||
mp_obj_base_t base;
|
||||
aes_encrypt_ctx encrypt_ctx;
|
||||
@ -45,9 +45,9 @@ typedef struct _mp_obj_AES_t {
|
||||
} mp_obj_AES_t;
|
||||
|
||||
/// def __init__(self, mode: int, key: bytes, iv: bytes = None) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Initialize AES context.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_AES_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Encrypt data and update AES context.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_AES_encrypt(mp_obj_t self, mp_obj_t data) {
|
||||
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);
|
||||
|
||||
/// def decrypt(self, data: bytes) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Decrypt data and update AES context.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_AES_decrypt(mp_obj_t self, mp_obj_t data) {
|
||||
return aes_update(self, data, false);
|
||||
}
|
||||
|
@ -30,9 +30,9 @@
|
||||
/// package: trezorcrypto.bip32
|
||||
|
||||
/// class HDNode:
|
||||
/// '''
|
||||
/// """
|
||||
/// BIP0032 HD node structure.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_HDNode_t {
|
||||
mp_obj_base_t base;
|
||||
uint32_t fingerprint;
|
||||
@ -44,16 +44,18 @@ STATIC const mp_obj_type_t mod_trezorcrypto_HDNode_type;
|
||||
#define XPUB_MAXLEN 128
|
||||
#define ADDRESS_MAXLEN 36
|
||||
|
||||
/// def __init__(self,
|
||||
/// depth: int,
|
||||
/// fingerprint: int,
|
||||
/// child_num: int,
|
||||
/// chain_code: bytes,
|
||||
/// private_key: bytes = None,
|
||||
/// public_key: bytes = None,
|
||||
/// curve_name: str = None) -> None:
|
||||
/// '''
|
||||
/// '''
|
||||
/// def __init__(
|
||||
/// self,
|
||||
/// depth: int,
|
||||
/// fingerprint: int,
|
||||
/// child_num: int,
|
||||
/// chain_code: bytes,
|
||||
/// private_key: bytes = 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,
|
||||
size_t n_args, size_t n_kw,
|
||||
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);
|
||||
}
|
||||
|
||||
/// 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.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_HDNode_derive(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// def derive_cardano(self, index: int) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Derive a BIP0032 child node in place using Cardano algorithm.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_HDNode_derive_cardano(mp_obj_t self,
|
||||
mp_obj_t index) {
|
||||
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);
|
||||
|
||||
/// def derive_path(self, path: List[int]) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Go through a list of indexes and iteratively derive a child node in
|
||||
/// place.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_HDNode_derive_path(mp_obj_t self,
|
||||
mp_obj_t path) {
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Serialize the public info from HD node to base58 string.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_HDNode_serialize_public(mp_obj_t self,
|
||||
mp_obj_t 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);
|
||||
|
||||
/// def serialize_private(self, version: int) -> str:
|
||||
/// '''
|
||||
/// """
|
||||
/// Serialize the private info HD node to base58 string.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_HDNode_serialize_private(mp_obj_t self,
|
||||
mp_obj_t 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);
|
||||
|
||||
/// def clone(self) -> HDNode:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns a copy of the HD node.
|
||||
/// '''
|
||||
/// """
|
||||
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 *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);
|
||||
|
||||
/// def depth(self) -> int:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns a depth of the HD node.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_HDNode_depth(mp_obj_t self) {
|
||||
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
|
||||
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);
|
||||
|
||||
/// def fingerprint(self) -> int:
|
||||
/// '''
|
||||
/// """
|
||||
/// 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) {
|
||||
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
|
||||
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);
|
||||
|
||||
/// def child_num(self) -> int:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns a child index of the HD node.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_HDNode_child_num(mp_obj_t self) {
|
||||
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
|
||||
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);
|
||||
|
||||
/// def chain_code(self) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns a chain code of the HD node.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_HDNode_chain_code(mp_obj_t 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));
|
||||
@ -355,9 +357,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_chain_code_obj,
|
||||
mod_trezorcrypto_HDNode_chain_code);
|
||||
|
||||
/// def private_key(self) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns a private key of the HD node.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_HDNode_private_key(mp_obj_t 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));
|
||||
@ -366,9 +368,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_private_key_obj,
|
||||
mod_trezorcrypto_HDNode_private_key);
|
||||
|
||||
/// def private_key_ext(self) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns a private key extension of the HD node.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_HDNode_private_key_ext(mp_obj_t self) {
|
||||
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
|
||||
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);
|
||||
|
||||
/// def public_key(self) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns a public key of the HD node.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_HDNode_public_key(mp_obj_t self) {
|
||||
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
|
||||
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);
|
||||
|
||||
/// def address(self, version: int) -> str:
|
||||
/// '''
|
||||
/// """
|
||||
/// Compute a base58-encoded address string from the HD node.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_HDNode_address(mp_obj_t self,
|
||||
mp_obj_t version) {
|
||||
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);
|
||||
|
||||
/// def nem_address(self, network: int) -> str:
|
||||
/// '''
|
||||
/// """
|
||||
/// Compute a NEM address string from the HD node.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_HDNode_nem_address(mp_obj_t self,
|
||||
mp_obj_t network) {
|
||||
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,
|
||||
mod_trezorcrypto_HDNode_nem_address);
|
||||
|
||||
/// 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
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_HDNode_nem_encrypt(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// def ethereum_pubkeyhash(self) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Compute an Ethereum pubkeyhash (aka address) from the HD node.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_HDNode_ethereum_pubkeyhash(mp_obj_t 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,
|
||||
};
|
||||
|
||||
/// 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.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_bip32_deserialize(mp_obj_t value,
|
||||
mp_obj_t version_public,
|
||||
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);
|
||||
|
||||
/// def from_seed(seed: bytes, curve_name: str) -> HDNode:
|
||||
/// '''
|
||||
/// """
|
||||
/// Construct a BIP0032 HD node from a BIP0039 seed value.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_bip32_from_seed(mp_obj_t seed,
|
||||
mp_obj_t curve_name) {
|
||||
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);
|
||||
|
||||
/// def from_mnemonic_cardano(mnemonic: str, passphrase: str) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Convert mnemonic to hdnode
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_bip32_from_mnemonic_cardano(
|
||||
mp_obj_t mnemonic, mp_obj_t passphrase) {
|
||||
mp_buffer_info_t mnemo, phrase;
|
||||
|
@ -25,9 +25,9 @@
|
||||
/// package: trezorcrypto.bip39
|
||||
|
||||
/// def find_word(prefix: str) -> Optional[str]:
|
||||
/// '''
|
||||
/// """
|
||||
/// Return the first word from the wordlist starting with prefix.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_bip39_find_word(mp_obj_t prefix) {
|
||||
mp_buffer_info_t pfx;
|
||||
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);
|
||||
|
||||
/// def complete_word(prefix: str) -> int:
|
||||
/// '''
|
||||
/// """
|
||||
/// Return possible 1-letter suffixes for given word prefix.
|
||||
/// Result is a bitmask, with 'a' on the lowest bit, 'b' on the second
|
||||
/// lowest, etc.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_bip39_complete_word(mp_obj_t prefix) {
|
||||
mp_buffer_info_t pfx;
|
||||
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);
|
||||
|
||||
/// def generate(strength: int) -> str:
|
||||
/// '''
|
||||
/// """
|
||||
/// 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) {
|
||||
int bits = mp_obj_get_int(strength);
|
||||
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);
|
||||
|
||||
/// def from_data(data: bytes) -> str:
|
||||
/// '''
|
||||
/// """
|
||||
/// 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) {
|
||||
mp_buffer_info_t bin;
|
||||
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);
|
||||
|
||||
/// def check(mnemonic: str) -> bool:
|
||||
/// '''
|
||||
/// """
|
||||
/// Check whether given mnemonic is valid.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_bip39_check(mp_obj_t mnemonic) {
|
||||
mp_buffer_info_t text;
|
||||
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)
|
||||
/// -> bytes:
|
||||
/// '''
|
||||
/// def seed(
|
||||
/// mnemonic: str, passphrase: str, callback: Tuple[int, int, None] = None
|
||||
/// ) -> bytes:
|
||||
/// """
|
||||
/// Generate seed from mnemonic and passphrase.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_bip39_seed(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_buffer_info_t mnemo;
|
||||
|
@ -25,9 +25,9 @@
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Blake256:
|
||||
/// '''
|
||||
/// """
|
||||
/// Blake256 context.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_Blake256_t {
|
||||
mp_obj_base_t base;
|
||||
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);
|
||||
|
||||
/// def __init__(self, data: bytes = None) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Creates a hash context object.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Blake256_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Update the hash context with hashed 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_buffer_info_t msg;
|
||||
@ -70,9 +70,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Blake256_update_obj,
|
||||
mod_trezorcrypto_Blake256_update);
|
||||
|
||||
/// def digest(self) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns the digest of hashed data.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Blake256_digest(mp_obj_t self) {
|
||||
mp_obj_Blake256_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t hash[BLAKE256_DIGEST_LENGTH];
|
||||
|
@ -27,9 +27,9 @@
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Blake2b:
|
||||
/// '''
|
||||
/// """
|
||||
/// Blake2b context.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_Blake2b_t {
|
||||
mp_obj_base_t base;
|
||||
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);
|
||||
|
||||
/// 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.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Blake2b_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Update the hash context with hashed 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_buffer_info_t msg;
|
||||
@ -119,9 +123,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Blake2b_update_obj,
|
||||
mod_trezorcrypto_Blake2b_update);
|
||||
|
||||
/// def digest(self) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns the digest of hashed data.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Blake2b_digest(mp_obj_t self) {
|
||||
mp_obj_Blake2b_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t out[BLAKE2B_DIGEST_LENGTH];
|
||||
|
@ -27,9 +27,9 @@
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Blake2s:
|
||||
/// '''
|
||||
/// """
|
||||
/// Blake2s context.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_Blake2s_t {
|
||||
mp_obj_base_t base;
|
||||
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);
|
||||
|
||||
/// 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.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Blake2s_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Update the hash context with hashed 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_buffer_info_t msg;
|
||||
@ -119,9 +124,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Blake2s_update_obj,
|
||||
mod_trezorcrypto_Blake2s_update);
|
||||
|
||||
/// def digest(self) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns the digest of hashed data.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Blake2s_digest(mp_obj_t self) {
|
||||
mp_obj_Blake2s_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t out[BLAKE2S_DIGEST_LENGTH];
|
||||
|
@ -25,9 +25,9 @@
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class ChaCha20Poly1305:
|
||||
/// '''
|
||||
/// """
|
||||
/// ChaCha20Poly1305 context.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_ChaCha20Poly1305_t {
|
||||
mp_obj_base_t base;
|
||||
chacha20poly1305_ctx ctx;
|
||||
@ -35,10 +35,10 @@ typedef struct _mp_obj_ChaCha20Poly1305_t {
|
||||
} mp_obj_ChaCha20Poly1305_t;
|
||||
|
||||
/// def __init__(self, key: bytes, nonce: bytes) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Initialize the ChaCha20 + Poly1305 context for encryption or decryption
|
||||
/// using a 32 byte key and 12 byte nonce as in the RFC 7539 style.
|
||||
/// '''
|
||||
/// """
|
||||
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_t *args) {
|
||||
@ -61,10 +61,10 @@ STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_make_new(
|
||||
}
|
||||
|
||||
/// def encrypt(self, data: bytes) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Encrypt data (length of data must be divisible by 64 except for the
|
||||
/// final value).
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_encrypt(mp_obj_t self,
|
||||
mp_obj_t data) {
|
||||
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);
|
||||
|
||||
/// def decrypt(self, data: bytes) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Decrypt data (length of data must be divisible by 64 except for the
|
||||
/// final value).
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_decrypt(mp_obj_t self,
|
||||
mp_obj_t data) {
|
||||
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);
|
||||
|
||||
/// def auth(self, data: bytes) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Include authenticated data in the Poly1305 MAC using the RFC 7539
|
||||
/// style with 16 byte padding. This must only be called once and prior
|
||||
/// to encryption or decryption.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_auth(mp_obj_t self,
|
||||
mp_obj_t data) {
|
||||
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);
|
||||
|
||||
/// def finish(self) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Compute RFC 7539-style Poly1305 MAC.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_finish(mp_obj_t self) {
|
||||
mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t out[16];
|
||||
|
@ -26,9 +26,9 @@
|
||||
/// package: trezorcrypto.curve25519
|
||||
|
||||
/// def generate_secret() -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Generate secret key.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_curve25519_generate_secret() {
|
||||
uint8_t out[32];
|
||||
random_buffer(out, 32);
|
||||
@ -43,9 +43,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(
|
||||
mod_trezorcrypto_curve25519_generate_secret);
|
||||
|
||||
/// def publickey(secret_key: bytes) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Computes public key from secret key.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_curve25519_publickey(mp_obj_t secret_key) {
|
||||
mp_buffer_info_t sk;
|
||||
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);
|
||||
|
||||
/// def multiply(secret_key: bytes, public_key: bytes) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Multiplies point defined by public_key with scalar defined by
|
||||
/// secret_key. Useful for ECDH.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_curve25519_multiply(mp_obj_t secret_key,
|
||||
mp_obj_t public_key) {
|
||||
mp_buffer_info_t sk, pk;
|
||||
|
@ -27,9 +27,9 @@
|
||||
/// package: trezorcrypto.ed25519
|
||||
|
||||
/// def generate_secret() -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Generate secret key.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_ed25519_generate_secret() {
|
||||
uint8_t 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);
|
||||
|
||||
/// def publickey(secret_key: bytes) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Computes public key from secret key.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_ed25519_publickey(mp_obj_t secret_key) {
|
||||
mp_buffer_info_t sk;
|
||||
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,
|
||||
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.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_ed25519_sign(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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,
|
||||
3, mod_trezorcrypto_ed25519_sign);
|
||||
|
||||
/// 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.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_ed25519_sign_ext(mp_obj_t secret_key,
|
||||
mp_obj_t secret_extension,
|
||||
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);
|
||||
|
||||
/// def verify(public_key: bytes, signature: bytes, message: bytes) -> bool:
|
||||
/// '''
|
||||
/// """
|
||||
/// Uses public key to verify the signature of the message.
|
||||
/// Returns True on success.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_ed25519_verify(mp_obj_t public_key,
|
||||
mp_obj_t signature,
|
||||
mp_obj_t message) {
|
||||
@ -165,9 +166,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_ed25519_verify_obj,
|
||||
mod_trezorcrypto_ed25519_verify);
|
||||
|
||||
/// def cosi_combine_publickeys(public_keys: List[bytes]) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Combines a list of public keys used in COSI cosigning scheme.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t
|
||||
mod_trezorcrypto_ed25519_cosi_combine_publickeys(mp_obj_t public_keys) {
|
||||
size_t pklen;
|
||||
@ -197,9 +198,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(
|
||||
mod_trezorcrypto_ed25519_cosi_combine_publickeys);
|
||||
|
||||
/// def cosi_combine_signatures(R: bytes, signatures: List[bytes]) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Combines a list of signatures used in COSI cosigning scheme.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_ed25519_cosi_combine_signatures(
|
||||
mp_obj_t R, mp_obj_t signatures) {
|
||||
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);
|
||||
|
||||
/// 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.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_ed25519_cosi_sign(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_buffer_info_t sk, msg, nonce, sigR, pk;
|
||||
|
@ -28,9 +28,9 @@
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Groestl512:
|
||||
/// '''
|
||||
/// """
|
||||
/// GROESTL512 context.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_Groestl512_t {
|
||||
mp_obj_base_t base;
|
||||
GROESTL512_CTX ctx;
|
||||
@ -40,9 +40,9 @@ STATIC mp_obj_t mod_trezorcrypto_Groestl512_update(mp_obj_t self,
|
||||
mp_obj_t data);
|
||||
|
||||
/// def __init__(self, data: bytes = None) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Creates a hash context object.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Groestl512_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Update the hash context with hashed data.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Groestl512_update(mp_obj_t self,
|
||||
mp_obj_t data) {
|
||||
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);
|
||||
|
||||
/// def digest(self) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns the digest of hashed data.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Groestl512_digest(mp_obj_t self) {
|
||||
mp_obj_Groestl512_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t out[GROESTL512_DIGEST_LENGTH];
|
||||
|
@ -176,14 +176,14 @@ STATIC void mp_unpack_scalar(bignum256modm r, const mp_obj_t arg,
|
||||
//
|
||||
|
||||
/// class Ge25519:
|
||||
/// '''
|
||||
/// """
|
||||
/// EC point on ED25519
|
||||
/// '''
|
||||
/// """
|
||||
///
|
||||
/// def __init__(x: Optional[Union[Ge25519, bytes]] = None):
|
||||
/// '''
|
||||
/// """
|
||||
/// Constructor
|
||||
/// '''
|
||||
/// """
|
||||
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_make_new(
|
||||
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__);
|
||||
|
||||
/// class Sc25519:
|
||||
/// '''
|
||||
/// """
|
||||
/// EC scalar on SC25519
|
||||
/// '''
|
||||
/// """
|
||||
///
|
||||
/// def __init__(x: Optional[Union[Sc25519, bytes, int]] = None):
|
||||
/// '''
|
||||
/// """
|
||||
/// Constructor
|
||||
/// '''
|
||||
/// """
|
||||
///
|
||||
///
|
||||
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__);
|
||||
|
||||
/// class Hasher:
|
||||
/// '''
|
||||
/// """
|
||||
/// XMR hasher
|
||||
/// '''
|
||||
/// """
|
||||
///
|
||||
/// def __init__(x: Optional[bytes] = None):
|
||||
/// '''
|
||||
/// """
|
||||
/// Constructor
|
||||
/// '''
|
||||
/// """
|
||||
///
|
||||
/// def update(buffer: bytes):
|
||||
/// '''
|
||||
/// def update(buffer: bytes):
|
||||
/// """
|
||||
/// Update hasher
|
||||
/// '''
|
||||
/// """
|
||||
///
|
||||
/// def digest() -> bytes:
|
||||
/// '''
|
||||
/// def digest() -> bytes:
|
||||
/// """
|
||||
/// Computes digest
|
||||
/// '''
|
||||
/// """
|
||||
///
|
||||
/// def copy() -> Hasher:
|
||||
/// '''
|
||||
/// def copy() -> Hasher:
|
||||
/// """
|
||||
/// Creates copy of the hasher, preserving the state
|
||||
/// '''
|
||||
/// """
|
||||
///
|
||||
///
|
||||
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
|
||||
|
||||
/// 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
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_init256_modm(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
const bool res_arg = n_args == 2;
|
||||
@ -343,9 +344,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
mod_trezorcrypto_monero_init256_modm);
|
||||
|
||||
/// def check256_modm(val: Sc25519):
|
||||
/// '''
|
||||
/// """
|
||||
/// Throws exception if scalar is invalid
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_check256_modm(const mp_obj_t arg) {
|
||||
assert_scalar(arg);
|
||||
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);
|
||||
|
||||
/// def iszero256_modm(val: Sc25519) -> bool:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns False if the scalar is zero
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_iszero256_modm(const mp_obj_t arg) {
|
||||
assert_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);
|
||||
|
||||
/// def eq256_modm(a: Sc25519, b: Sc25519) -> int:
|
||||
/// '''
|
||||
/// """
|
||||
/// Compares scalars, returns 1 on the same value
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_eq256_modm(const mp_obj_t a,
|
||||
const mp_obj_t b) {
|
||||
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);
|
||||
|
||||
/// def get256_modm(a: Sc25519) -> int:
|
||||
/// '''
|
||||
/// """
|
||||
/// Extracts 64bit integer from the scalar. Raises exception if scalar is
|
||||
/// bigger than 2^64
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_get256_modm(const mp_obj_t arg) {
|
||||
assert_scalar(arg);
|
||||
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);
|
||||
|
||||
/// def add256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519:
|
||||
/// '''
|
||||
/// """
|
||||
/// Scalar addition
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_add256_modm(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
const bool res_arg = n_args == 3;
|
||||
@ -419,9 +420,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
mod_trezorcrypto_monero_add256_modm);
|
||||
|
||||
/// def sub256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519:
|
||||
/// '''
|
||||
/// """
|
||||
/// Scalar subtraction
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_sub256_modm(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
const bool res_arg = n_args == 3;
|
||||
@ -439,9 +440,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
mod_trezorcrypto_monero_sub256_modm);
|
||||
|
||||
/// def mul256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519:
|
||||
/// '''
|
||||
/// """
|
||||
/// Scalar multiplication
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_mul256_modm(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_mulsub256_modm(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_muladd256_modm(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
const bool res_arg = n_args == 4;
|
||||
@ -505,9 +508,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
mod_trezorcrypto_monero_muladd256_modm);
|
||||
|
||||
/// def inv256_modm(r: Optional[Sc25519], a: Sc25519) -> Sc25519:
|
||||
/// '''
|
||||
/// """
|
||||
/// Scalar modular inversion
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_inv256_modm(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_pack256_modm(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_unpack256_modm(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_unpack256_modm_noreduce(
|
||||
size_t n_args, const mp_obj_t *args) {
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Sets neutral point
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_set_neutral(
|
||||
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);
|
||||
@ -621,9 +627,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
mod_trezorcrypto_monero_ge25519_set_neutral);
|
||||
|
||||
/// def ge25519_set_xmr_h(r: Optional[Ge25519]) -> Ge25519:
|
||||
/// '''
|
||||
/// """
|
||||
/// Sets H point
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t
|
||||
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);
|
||||
@ -635,9 +641,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
mod_trezorcrypto_monero_ge25519_set_xmr_h);
|
||||
|
||||
/// def ge25519_check(r: Ge25519):
|
||||
/// '''
|
||||
/// """
|
||||
/// Checks point, throws if not on curve
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_check(const mp_obj_t arg) {
|
||||
assert_ge25519(arg);
|
||||
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);
|
||||
|
||||
/// def ge25519_eq(a: Ge25519, b: Ge25519) -> bool:
|
||||
/// '''
|
||||
/// """
|
||||
/// Compares EC points
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_eq(const mp_obj_t a,
|
||||
const mp_obj_t b) {
|
||||
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);
|
||||
|
||||
/// def ge25519_add(r: Optional[Ge25519], a: Ge25519, b: Ge25519) -> Ge25519:
|
||||
/// '''
|
||||
/// """
|
||||
/// Adds EC points
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_add(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
const bool res_arg = n_args == 3;
|
||||
@ -683,9 +689,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
mod_trezorcrypto_monero_ge25519_add);
|
||||
|
||||
/// def ge25519_sub(r: Optional[Ge25519], a: Ge25519, b: Ge25519) -> Ge25519:
|
||||
/// '''
|
||||
/// """
|
||||
/// Subtracts EC points
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_sub(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
const bool res_arg = n_args == 3;
|
||||
@ -703,9 +709,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
mod_trezorcrypto_monero_ge25519_sub);
|
||||
|
||||
/// def ge25519_double(r: Optional[Ge25519], p: Ge25519) -> Ge25519:
|
||||
/// '''
|
||||
/// """
|
||||
/// EC point doubling
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_double(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
const bool res_arg = n_args == 2;
|
||||
@ -720,9 +726,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
mod_trezorcrypto_monero_ge25519_double);
|
||||
|
||||
/// def ge25519_mul8(r: Optional[Ge25519], p: Ge25519) -> Ge25519:
|
||||
/// '''
|
||||
/// """
|
||||
/// EC point * 8
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_mul8(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_double_scalarmult_vartime(
|
||||
size_t n_args, const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_double_scalarmult_vartime2(
|
||||
size_t n_args, const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_scalarmult_base(
|
||||
size_t n_args, const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_scalarmult(
|
||||
size_t n_args, const mp_obj_t *args) {
|
||||
const bool res_arg = n_args == 3;
|
||||
@ -844,9 +858,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
mod_trezorcrypto_monero_ge25519_scalarmult);
|
||||
|
||||
/// def ge25519_pack(r: bytes, p: Ge25519, offset: int = 0) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Point compression
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_pack(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_unpack_vartime(
|
||||
size_t n_args, const mp_obj_t *args) {
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Monero block base 58 encoding
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_base58_addr_encode_check(
|
||||
size_t n_args, const mp_obj_t *args) {
|
||||
uint8_t out[128];
|
||||
@ -916,10 +931,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
mod_trezorcrypto_monero_xmr_base58_addr_encode_check);
|
||||
|
||||
/// def base58_addr_decode_check(buff: bytes) -> Tuple[bytes, int]:
|
||||
/// '''
|
||||
/// """
|
||||
/// Monero block base 58 decoding, returning (decoded, tag) or raising on
|
||||
/// error.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_base58_addr_decode_check(
|
||||
size_t n_args, const mp_obj_t *args) {
|
||||
uint8_t out[128];
|
||||
@ -944,9 +959,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
mod_trezorcrypto_monero_xmr_base58_addr_decode_check);
|
||||
|
||||
/// def xmr_random_scalar(r: Optional[Sc25519] = None) -> Sc25519:
|
||||
/// '''
|
||||
/// """
|
||||
/// Generates a random scalar
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t
|
||||
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);
|
||||
@ -958,9 +973,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
mod_trezorcrypto_monero_xmr_random_scalar);
|
||||
|
||||
/// def xmr_fast_hash(r: Optional[bytes], buff: bytes) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// XMR fast hash
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_fast_hash(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// def xmr_hash_to_ec(r: Optional[Ge25519], buff: bytes) -> Ge25519:
|
||||
/// '''
|
||||
/// """
|
||||
/// XMR hashing to EC point
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_hash_to_ec(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// def xmr_hash_to_scalar(r: Optional[Sc25519], buff: bytes) -> Sc25519:
|
||||
/// '''
|
||||
/// """
|
||||
/// XMR hashing to EC scalar
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_hash_to_scalar(
|
||||
size_t n_args, const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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))
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_derivation_to_scalar(
|
||||
size_t n_args, const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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)
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_generate_key_derivation(
|
||||
size_t n_args, const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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))
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_derive_private_key(
|
||||
size_t n_args, const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_derive_public_key(
|
||||
size_t n_args, const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_add_keys2(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_add_keys2_vartime(
|
||||
size_t n_args, const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_add_keys3(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_add_keys3_vartime(
|
||||
size_t n_args, const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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)
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_get_subaddress_secret_key(
|
||||
size_t n_args, const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// def xmr_gen_c(r: Optional[Ge25519], a: Sc25519, amount: int) -> Ge25519:
|
||||
/// '''
|
||||
/// """
|
||||
/// aG + amount * H
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_gen_c(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// def ct_equals(a: bytes, b: bytes) -> bool:
|
||||
/// '''
|
||||
/// """
|
||||
/// Constant time buffer comparison
|
||||
/// '''
|
||||
/// """
|
||||
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_get_buffer_raise(a, &buff_a, MP_BUFFER_READ);
|
||||
|
@ -26,9 +26,9 @@
|
||||
/// package: trezorcrypto.nem
|
||||
|
||||
/// def validate_address(address: str, network: int) -> bool:
|
||||
/// '''
|
||||
/// """
|
||||
/// Validate a NEM address
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_nem_validate_address(mp_obj_t address,
|
||||
mp_obj_t network) {
|
||||
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);
|
||||
|
||||
/// def compute_address(public_key: bytes, network: int) -> str:
|
||||
/// '''
|
||||
/// """
|
||||
/// Compute a NEM address from a public key
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_nem_compute_address(mp_obj_t public_key,
|
||||
mp_obj_t network) {
|
||||
mp_buffer_info_t p;
|
||||
|
@ -25,9 +25,9 @@
|
||||
/// package: trezorcrypto.nist256p1
|
||||
|
||||
/// def generate_secret() -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Generate secret key.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_nist256p1_generate_secret() {
|
||||
uint8_t out[32];
|
||||
for (;;) {
|
||||
@ -55,9 +55,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_nist256p1_generate_secret_obj,
|
||||
mod_trezorcrypto_nist256p1_generate_secret);
|
||||
|
||||
/// def publickey(secret_key: bytes, compressed: bool = True) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Computes public key from secret key.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_nist256p1_publickey(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_nist256p1_sign(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// def verify(public_key: bytes, signature: bytes, digest: bytes) -> bool:
|
||||
/// '''
|
||||
/// """
|
||||
/// Uses public key to verify the signature of the digest.
|
||||
/// Returns True on success.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_nist256p1_verify(mp_obj_t public_key,
|
||||
mp_obj_t signature,
|
||||
mp_obj_t digest) {
|
||||
@ -140,10 +141,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_nist256p1_verify_obj,
|
||||
mod_trezorcrypto_nist256p1_verify);
|
||||
|
||||
/// 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.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_nist256p1_verify_recover(mp_obj_t signature,
|
||||
mp_obj_t digest) {
|
||||
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);
|
||||
|
||||
/// def multiply(secret_key: bytes, public_key: bytes) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Multiplies point defined by public_key with scalar defined by
|
||||
/// secret_key. Useful for ECDH.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_nist256p1_multiply(mp_obj_t secret_key,
|
||||
mp_obj_t public_key) {
|
||||
mp_buffer_info_t sk, pk;
|
||||
|
@ -28,9 +28,9 @@
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Pbkdf2:
|
||||
/// '''
|
||||
/// """
|
||||
/// PBKDF2 context.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_Pbkdf2_t {
|
||||
mp_obj_base_t base;
|
||||
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);
|
||||
|
||||
/// 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.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Update a PBKDF2 context.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_update(mp_obj_t self,
|
||||
mp_obj_t iterations) {
|
||||
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);
|
||||
|
||||
/// def key(self) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Retrieve derived key.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_key(mp_obj_t self) {
|
||||
mp_obj_Pbkdf2_t *o = MP_OBJ_TO_PTR(self);
|
||||
if (o->prf == PRF_HMAC_SHA256) {
|
||||
|
@ -26,9 +26,9 @@
|
||||
/// package: trezorcrypto.random
|
||||
|
||||
/// def uniform(n: int) -> int:
|
||||
/// '''
|
||||
/// """
|
||||
/// Compute uniform random number from interval 0 ... n - 1.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_random_uniform(mp_obj_t n) {
|
||||
uint32_t nn = trezor_obj_get_uint(n);
|
||||
if (nn == 0) {
|
||||
@ -40,9 +40,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_random_uniform_obj,
|
||||
mod_trezorcrypto_random_uniform);
|
||||
|
||||
/// def bytes(len: int) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Generate random bytes sequence of length len.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_random_bytes(mp_obj_t len) {
|
||||
uint32_t l = trezor_obj_get_uint(len);
|
||||
if (l > 1024) {
|
||||
@ -57,9 +57,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_random_bytes_obj,
|
||||
mod_trezorcrypto_random_bytes);
|
||||
|
||||
/// def shuffle(data: list) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Shuffles items of given list (in-place).
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_random_shuffle(mp_obj_t data) {
|
||||
size_t count;
|
||||
mp_obj_t *items;
|
||||
|
@ -24,18 +24,18 @@
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Rfc6979:
|
||||
/// '''
|
||||
/// """
|
||||
/// RFC6979 context.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_Rfc6979_t {
|
||||
mp_obj_base_t base;
|
||||
rfc6979_state rng;
|
||||
} mp_obj_Rfc6979_t;
|
||||
|
||||
/// def __init__(self, secret_key: bytes, hash: bytes) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Initialize RFC6979 context from secret key and a hash.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Rfc6979_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Compute next 32-bytes of pseudorandom data.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Rfc6979_next(mp_obj_t self) {
|
||||
mp_obj_Rfc6979_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t out[32];
|
||||
|
@ -25,9 +25,9 @@
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Ripemd160:
|
||||
/// '''
|
||||
/// """
|
||||
/// RIPEMD160 context.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_Ripemd160_t {
|
||||
mp_obj_base_t base;
|
||||
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);
|
||||
|
||||
/// def __init__(self, data: bytes = None) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Creates a hash context object.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Ripemd160_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Update the hash context with hashed data.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Ripemd160_update(mp_obj_t self,
|
||||
mp_obj_t data) {
|
||||
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);
|
||||
|
||||
/// def digest(self) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns the digest of hashed data.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Ripemd160_digest(mp_obj_t self) {
|
||||
mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t out[RIPEMD160_DIGEST_LENGTH];
|
||||
|
@ -25,9 +25,9 @@
|
||||
/// package: trezorcrypto.secp256k1
|
||||
|
||||
/// def generate_secret() -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Generate secret key.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_generate_secret() {
|
||||
uint8_t out[32];
|
||||
for (;;) {
|
||||
@ -55,9 +55,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_secp256k1_generate_secret_obj,
|
||||
mod_trezorcrypto_secp256k1_generate_secret);
|
||||
|
||||
/// def publickey(secret_key: bytes, compressed: bool = True) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Computes public key from secret key.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_publickey(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_buffer_info_t sk;
|
||||
@ -98,11 +98,15 @@ enum {
|
||||
CANONICAL_SIG_EOS = 2,
|
||||
};
|
||||
|
||||
/// 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.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_sign(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// def verify(public_key: bytes, signature: bytes, digest: bytes) -> bool:
|
||||
/// '''
|
||||
/// """
|
||||
/// Uses public key to verify the signature of the digest.
|
||||
/// Returns True on success.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_verify(mp_obj_t public_key,
|
||||
mp_obj_t signature,
|
||||
mp_obj_t digest) {
|
||||
@ -169,10 +173,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_secp256k1_verify_obj,
|
||||
mod_trezorcrypto_secp256k1_verify);
|
||||
|
||||
/// 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.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_verify_recover(mp_obj_t signature,
|
||||
mp_obj_t digest) {
|
||||
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);
|
||||
|
||||
/// def multiply(secret_key: bytes, public_key: bytes) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Multiplies point defined by public_key with scalar defined by
|
||||
/// secret_key. Useful for ECDH.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_multiply(mp_obj_t secret_key,
|
||||
mp_obj_t public_key) {
|
||||
mp_buffer_info_t sk, pk;
|
||||
|
@ -64,10 +64,13 @@ STATIC const secp256k1_context *mod_trezorcrypto_secp256k1_context(void) {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
/// package: trezorcrypto.secp256k1_zkp
|
||||
|
||||
/// def generate_secret() -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Generate secret key.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_zkp_generate_secret() {
|
||||
uint8_t out[32];
|
||||
for (;;) {
|
||||
@ -94,9 +97,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(
|
||||
mod_trezorcrypto_secp256k1_zkp_generate_secret);
|
||||
|
||||
/// def publickey(secret_key: bytes, compressed: bool = True) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Computes public key from secret key.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_zkp_publickey(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// 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.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_zkp_sign(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// def verify(public_key: bytes, signature: bytes, digest: bytes) -> bool:
|
||||
/// '''
|
||||
/// """
|
||||
/// Uses public key to verify the signature of the digest.
|
||||
/// Returns True on success.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_zkp_verify(mp_obj_t public_key,
|
||||
mp_obj_t signature,
|
||||
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);
|
||||
|
||||
/// 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.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_zkp_verify_recover(
|
||||
mp_obj_t signature, mp_obj_t digest) {
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Multiplies point defined by public_key with scalar defined by
|
||||
/// secret_key. Useful for ECDH.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_zkp_multiply(mp_obj_t secret_key,
|
||||
mp_obj_t public_key) {
|
||||
const secp256k1_context *ctx = mod_trezorcrypto_secp256k1_context();
|
||||
|
@ -25,9 +25,9 @@
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Sha1:
|
||||
/// '''
|
||||
/// """
|
||||
/// SHA1 context.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_Sha1_t {
|
||||
mp_obj_base_t base;
|
||||
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);
|
||||
|
||||
/// def __init__(self, data: bytes = None) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Creates a hash context object.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Sha1_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Update the hash context with hashed 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_buffer_info_t msg;
|
||||
@ -70,9 +70,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha1_update_obj,
|
||||
mod_trezorcrypto_Sha1_update);
|
||||
|
||||
/// def digest(self) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns the digest of hashed data.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Sha1_digest(mp_obj_t self) {
|
||||
mp_obj_Sha1_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t out[SHA1_DIGEST_LENGTH];
|
||||
|
@ -25,9 +25,9 @@
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Sha256:
|
||||
/// '''
|
||||
/// """
|
||||
/// SHA256 context.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_Sha256_t {
|
||||
mp_obj_base_t base;
|
||||
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);
|
||||
|
||||
/// def __init__(self, data: bytes = None) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Creates a hash context object.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Sha256_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Update the hash context with hashed 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_buffer_info_t msg;
|
||||
@ -70,9 +70,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha256_update_obj,
|
||||
mod_trezorcrypto_Sha256_update);
|
||||
|
||||
/// def digest(self) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns the digest of hashed data.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Sha256_digest(mp_obj_t self) {
|
||||
mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t out[SHA256_DIGEST_LENGTH];
|
||||
|
@ -25,9 +25,9 @@
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Sha3_256:
|
||||
/// '''
|
||||
/// """
|
||||
/// SHA3_256 context.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_Sha3_256_t {
|
||||
mp_obj_base_t base;
|
||||
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);
|
||||
|
||||
/// def __init__(self, data: bytes = None, keccak = False) -> None:
|
||||
/// '''
|
||||
/// def __init__(self, data: bytes = None, keccak: bool = False) -> None:
|
||||
/// """
|
||||
/// Creates a hash context object.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Sha3_256_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Update the hash context with hashed 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_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);
|
||||
|
||||
/// def digest(self) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns the digest of hashed data.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Sha3_256_digest(mp_obj_t self) {
|
||||
mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(self);
|
||||
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);
|
||||
|
||||
/// def copy(self) -> sha3:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns the copy of the digest object with the current state
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Sha3_256_copy(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(args[0]);
|
||||
|
@ -25,9 +25,9 @@
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Sha3_512:
|
||||
/// '''
|
||||
/// """
|
||||
/// SHA3_512 context.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_Sha3_512_t {
|
||||
mp_obj_base_t base;
|
||||
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);
|
||||
|
||||
/// def __init__(self, data: bytes = None, keccak = False) -> None:
|
||||
/// '''
|
||||
/// def __init__(self, data: bytes = None, keccak: bool = False) -> None:
|
||||
/// """
|
||||
/// Creates a hash context object.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Sha3_512_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Update the hash context with hashed 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_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);
|
||||
|
||||
/// def digest(self) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns the digest of hashed data.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Sha3_512_digest(mp_obj_t self) {
|
||||
mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(self);
|
||||
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);
|
||||
|
||||
/// def copy(self) -> sha3:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns the copy of the digest object with the current state
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Sha3_512_copy(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(args[0]);
|
||||
|
@ -25,9 +25,9 @@
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Sha512:
|
||||
/// '''
|
||||
/// """
|
||||
/// SHA512 context.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_Sha512_t {
|
||||
mp_obj_base_t base;
|
||||
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);
|
||||
|
||||
/// def __init__(self, data: bytes = None) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Creates a hash context object.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Sha512_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Update the hash context with hashed 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_buffer_info_t msg;
|
||||
@ -69,9 +69,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha512_update_obj,
|
||||
mod_trezorcrypto_Sha512_update);
|
||||
|
||||
/// def digest(self) -> bytes:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns the digest of hashed data.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Sha512_digest(mp_obj_t self) {
|
||||
mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t out[SHA512_DIGEST_LENGTH];
|
||||
|
@ -22,15 +22,15 @@
|
||||
#include "embed/extmod/trezorobj.h"
|
||||
|
||||
/// class FlashOTP:
|
||||
/// '''
|
||||
/// '''
|
||||
/// """
|
||||
/// """
|
||||
typedef struct _mp_obj_FlashOTP_t {
|
||||
mp_obj_base_t base;
|
||||
} mp_obj_FlashOTP_t;
|
||||
|
||||
/// def __init__(self) -> None:
|
||||
/// '''
|
||||
/// '''
|
||||
/// """
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_FlashOTP_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw,
|
||||
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);
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_FlashOTP_write(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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,
|
||||
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
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_FlashOTP_read(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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,
|
||||
mod_trezorio_FlashOTP_read);
|
||||
|
||||
/// def FlashOTP.lock(self, block: int) -> None:
|
||||
/// '''
|
||||
/// def lock(self, block: int) -> None:
|
||||
/// """
|
||||
/// Lock OTP flash 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);
|
||||
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,
|
||||
mod_trezorio_FlashOTP_lock);
|
||||
|
||||
/// def FlashOTP.is_locked(self, block: int) -> bool:
|
||||
/// '''
|
||||
/// def is_locked(self, block: int) -> bool:
|
||||
/// """
|
||||
/// Is OTP flash block locked?
|
||||
/// '''
|
||||
/// """
|
||||
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);
|
||||
return (sectrue == flash_otp_is_locked(b)) ? mp_const_true : mp_const_false;
|
||||
|
@ -18,25 +18,27 @@
|
||||
*/
|
||||
|
||||
/// class HID:
|
||||
/// '''
|
||||
/// """
|
||||
/// USB HID interface configuration.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_HID_t {
|
||||
mp_obj_base_t base;
|
||||
usb_hid_info_t info;
|
||||
} mp_obj_HID_t;
|
||||
|
||||
/// def __init__(self,
|
||||
/// iface_num: int,
|
||||
/// ep_in: int,
|
||||
/// ep_out: int,
|
||||
/// report_desc: bytes,
|
||||
/// subclass: int = 0,
|
||||
/// protocol: int = 0,
|
||||
/// polling_interval: int = 1,
|
||||
/// max_packet_len: int = 64) -> None:
|
||||
/// '''
|
||||
/// '''
|
||||
/// def __init__(
|
||||
/// self,
|
||||
/// iface_num: int,
|
||||
/// ep_in: int,
|
||||
/// ep_out: int,
|
||||
/// report_desc: bytes,
|
||||
/// subclass: int = 0,
|
||||
/// protocol: int = 0,
|
||||
/// 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,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns the configured number of this interface.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_HID_iface_num(mp_obj_t self) {
|
||||
mp_obj_HID_t *o = MP_OBJ_TO_PTR(self);
|
||||
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);
|
||||
|
||||
/// def write(self, msg: bytes) -> int:
|
||||
/// '''
|
||||
/// """
|
||||
/// 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) {
|
||||
mp_obj_HID_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t buf;
|
||||
|
@ -26,18 +26,18 @@
|
||||
#define POLL_WRITE (0x0100)
|
||||
|
||||
/// 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
|
||||
// `io.POLL_READ` and `io.POLL_WRITE`) and assign the result into
|
||||
/// `list_ref`:
|
||||
///
|
||||
/// `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
|
||||
///
|
||||
/// If timeout occurs, False is returned, True otherwise.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
|
||||
mp_obj_t timeout_us) {
|
||||
mp_obj_list_t *ret = MP_OBJ_TO_PTR(list_ref);
|
||||
|
@ -20,15 +20,15 @@
|
||||
#include "sbu.h"
|
||||
|
||||
/// class SBU:
|
||||
/// '''
|
||||
/// '''
|
||||
/// """
|
||||
/// """
|
||||
typedef struct _mp_obj_SBU_t {
|
||||
mp_obj_base_t base;
|
||||
} mp_obj_SBU_t;
|
||||
|
||||
/// def __init__(self) -> None:
|
||||
/// '''
|
||||
/// '''
|
||||
/// """
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_SBU_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// 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,
|
||||
mp_obj_t sbu2) {
|
||||
sbu_set(sectrue * mp_obj_is_true(sbu1), sectrue * mp_obj_is_true(sbu2));
|
||||
|
@ -22,15 +22,15 @@
|
||||
#include "embed/extmod/trezorobj.h"
|
||||
|
||||
/// class SDCard:
|
||||
/// '''
|
||||
/// '''
|
||||
/// """
|
||||
/// """
|
||||
typedef struct _mp_obj_SDCard_t {
|
||||
mp_obj_base_t base;
|
||||
} mp_obj_SDCard_t;
|
||||
|
||||
/// def __init__(self) -> None:
|
||||
/// '''
|
||||
/// '''
|
||||
/// """
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_SDCard_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns True if SD card is detected, False otherwise.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_SDCard_present(mp_obj_t self) {
|
||||
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);
|
||||
|
||||
/// def power(self, state: bool) -> bool:
|
||||
/// '''
|
||||
/// """
|
||||
/// Power on or power off the SD card interface.
|
||||
/// 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) {
|
||||
if (mp_obj_is_true(state)) {
|
||||
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);
|
||||
|
||||
/// def capacity(self) -> int:
|
||||
/// '''
|
||||
/// """
|
||||
/// 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) {
|
||||
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);
|
||||
|
||||
/// def read(self, block_num: int, buf: bytearray) -> bool:
|
||||
/// '''
|
||||
/// """
|
||||
/// 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. 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,
|
||||
mp_obj_t buf) {
|
||||
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);
|
||||
|
||||
/// def write(self, block_num: int, buf: bytes) -> bool:
|
||||
/// '''
|
||||
/// """
|
||||
/// 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. 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,
|
||||
mp_obj_t buf) {
|
||||
uint32_t block = trezor_obj_get_uint(block_num);
|
||||
|
@ -25,9 +25,9 @@ enum {
|
||||
};
|
||||
|
||||
/// class USB:
|
||||
/// '''
|
||||
/// """
|
||||
/// USB device configuration.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_USB_t {
|
||||
mp_obj_base_t base;
|
||||
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,
|
||||
/// device_class: int=0,
|
||||
/// device_subclass: int=0,
|
||||
/// device_protocol: int=0,
|
||||
/// vendor_id: int,
|
||||
/// product_id: int,
|
||||
/// release_num: int,
|
||||
/// manufacturer: str='',
|
||||
/// product: str='',
|
||||
/// serial_number: str='',
|
||||
/// interface: str='',
|
||||
/// usb21_enabled: bool=True,
|
||||
/// usb21_landing: bool=True) -> None:
|
||||
/// '''
|
||||
/// '''
|
||||
/// def __init__(
|
||||
/// self,
|
||||
/// vendor_id: int,
|
||||
/// product_id: int,
|
||||
/// release_num: int,
|
||||
/// device_class: int = 0,
|
||||
/// device_subclass: int = 0,
|
||||
/// device_protocol: int = 0,
|
||||
/// manufacturer: str = "",
|
||||
/// product: str = "",
|
||||
/// serial_number: str = "",
|
||||
/// interface: str = "",
|
||||
/// usb21_enabled: bool = True,
|
||||
/// usb21_landing: bool = True,
|
||||
/// ) -> None:
|
||||
/// """
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_USB_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Registers passed interface into the USB stack.
|
||||
/// '''
|
||||
/// """
|
||||
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);
|
||||
|
||||
@ -172,9 +174,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_USB_add_obj,
|
||||
mod_trezorio_USB_add);
|
||||
|
||||
/// def open(self) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Initializes the USB stack.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_USB_open(mp_obj_t 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);
|
||||
|
||||
/// def close(self) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Cleans up the USB stack.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_USB_close(mp_obj_t self) {
|
||||
mp_obj_USB_t *o = MP_OBJ_TO_PTR(self);
|
||||
|
||||
|
@ -20,22 +20,24 @@
|
||||
void pendsv_kbd_intr(void);
|
||||
|
||||
/// class VCP:
|
||||
/// '''
|
||||
/// """
|
||||
/// USB VCP interface configuration.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_VCP_t {
|
||||
mp_obj_base_t base;
|
||||
usb_vcp_info_t info;
|
||||
} mp_obj_VCP_t;
|
||||
|
||||
/// def __init__(self,
|
||||
/// iface_num: int,
|
||||
/// data_iface_num: int,
|
||||
/// ep_in: int,
|
||||
/// ep_out: int,
|
||||
/// ep_cmd: int) -> None:
|
||||
/// '''
|
||||
/// '''
|
||||
/// def __init__(
|
||||
/// self,
|
||||
/// iface_num: int,
|
||||
/// data_iface_num: int,
|
||||
/// ep_in: int,
|
||||
/// ep_out: int,
|
||||
/// ep_cmd: int,
|
||||
/// ) -> None:
|
||||
/// """
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_VCP_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns the configured number of this interface.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_VCP_iface_num(mp_obj_t self) {
|
||||
mp_obj_VCP_t *o = MP_OBJ_TO_PTR(self);
|
||||
return MP_OBJ_NEW_SMALL_INT(o->info.iface_num);
|
||||
|
@ -18,24 +18,26 @@
|
||||
*/
|
||||
|
||||
/// class WebUSB:
|
||||
/// '''
|
||||
/// """
|
||||
/// USB WebUSB interface configuration.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_WebUSB_t {
|
||||
mp_obj_base_t base;
|
||||
usb_webusb_info_t info;
|
||||
} mp_obj_WebUSB_t;
|
||||
|
||||
/// def __init__(self,
|
||||
/// iface_num: int,
|
||||
/// ep_in: int,
|
||||
/// ep_out: int,
|
||||
/// subclass: int = 0,
|
||||
/// protocol: int = 0,
|
||||
/// polling_interval: int = 1,
|
||||
/// max_packet_len: int = 64) -> None:
|
||||
/// '''
|
||||
/// '''
|
||||
/// def __init__(
|
||||
/// self,
|
||||
/// iface_num: int,
|
||||
/// ep_in: int,
|
||||
/// ep_out: int,
|
||||
/// subclass: int = 0,
|
||||
/// protocol: int = 0,
|
||||
/// 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,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Returns the configured number of this interface.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_WebUSB_iface_num(mp_obj_t self) {
|
||||
mp_obj_WebUSB_t *o = MP_OBJ_TO_PTR(self);
|
||||
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);
|
||||
|
||||
/// def write(self, msg: bytes) -> int:
|
||||
/// '''
|
||||
/// """
|
||||
/// 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) {
|
||||
mp_obj_WebUSB_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t buf;
|
||||
|
@ -22,17 +22,17 @@
|
||||
#include "display.h"
|
||||
|
||||
/// class Display:
|
||||
/// '''
|
||||
/// """
|
||||
/// Provide access to device display.
|
||||
/// '''
|
||||
/// """
|
||||
typedef struct _mp_obj_Display_t {
|
||||
mp_obj_base_t base;
|
||||
} mp_obj_Display_t;
|
||||
|
||||
/// def __init__(self) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Initialize the display.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw,
|
||||
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:
|
||||
/// '''
|
||||
/// """
|
||||
/// Clear display with black color.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_clear(mp_obj_t self) {
|
||||
display_clear();
|
||||
return mp_const_none;
|
||||
@ -54,9 +54,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorui_Display_clear_obj,
|
||||
mod_trezorui_Display_clear);
|
||||
|
||||
/// def refresh(self) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Refresh display (update screen).
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_refresh(mp_obj_t self) {
|
||||
display_refresh();
|
||||
return mp_const_none;
|
||||
@ -65,10 +65,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorui_Display_refresh_obj,
|
||||
mod_trezorui_Display_refresh);
|
||||
|
||||
/// 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.
|
||||
/// '''
|
||||
/// """
|
||||
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 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,
|
||||
mod_trezorui_Display_bar);
|
||||
|
||||
/// def bar_radius(self, x: int, y: int, w: int, h: int, fgcolor: int, bgcolor:
|
||||
/// int = None, radius: int = None) -> None:
|
||||
/// '''
|
||||
/// def bar_radius(
|
||||
/// 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
|
||||
/// and height h of color fgcolor. Background is set to bgcolor and corners
|
||||
/// are drawn with radius radius.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_bar_radius(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// def image(self, x: int, y: int, image: bytes) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Renders an image at position (x,y).
|
||||
/// The image needs to be in TREZOR Optimized Image Format (TOIF) -
|
||||
/// full-color mode.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_image(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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,
|
||||
mod_trezorui_Display_image);
|
||||
|
||||
/// 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).
|
||||
/// The image needs to be in TREZOR Optimized Image Format (TOIF) -
|
||||
/// full-color mode. Image needs to be of exactly AVATAR_IMAGE_SIZE x
|
||||
/// AVATAR_IMAGE_SIZE pixels size.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_avatar(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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,
|
||||
6, mod_trezorui_Display_avatar);
|
||||
|
||||
/// def icon(self, x: int, y: int, icon: bytes, fgcolor: int, bgcolor: int) ->
|
||||
/// None:
|
||||
/// '''
|
||||
/// def icon(
|
||||
/// 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,
|
||||
/// bgcolor as background. The icon needs to be in TREZOR Optimized Image
|
||||
/// Format (TOIF) - gray-scale mode.
|
||||
/// '''
|
||||
/// """
|
||||
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 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,
|
||||
mod_trezorui_Display_icon);
|
||||
/// def loader(self, progress: int, indeterminate: bool, yoffset: int, fgcolor:
|
||||
/// int, bgcolor: int, icon: bytes = None, iconfgcolor: int = None) -> None:
|
||||
/// '''
|
||||
/// 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.
|
||||
/// Progress determines its position (0-1000), fgcolor is used as foreground
|
||||
/// color, bgcolor as background. When icon and iconfgcolor are provided, an
|
||||
/// 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.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_loader(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// def print(self, text: str) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// 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) {
|
||||
mp_buffer_info_t buf;
|
||||
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,
|
||||
mod_trezorui_Display_print);
|
||||
|
||||
/// def text(self, x: int, y: int, text: str, font: int, fgcolor: int, bgcolor:
|
||||
/// int, minwidth: int=None) -> int:
|
||||
/// '''
|
||||
/// def text(
|
||||
/// 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
|
||||
/// 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.
|
||||
/// '''
|
||||
/// """
|
||||
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 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,
|
||||
mod_trezorui_Display_text);
|
||||
|
||||
/// def text_center(self, x: int, y: int, text: str, font: int, fgcolor: int,
|
||||
/// bgcolor: int, minwidth: int=None) -> int:
|
||||
/// '''
|
||||
/// def text_center(
|
||||
/// 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
|
||||
/// 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.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_text_center(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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,
|
||||
mod_trezorui_Display_text_center);
|
||||
|
||||
/// def text_right(self, x: int, y: int, text: str, font: int, fgcolor: int,
|
||||
/// bgcolor: int, minwidth: int=None) -> int:
|
||||
/// '''
|
||||
/// 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.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_text_right(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// def text_width(self, text: str, font: int) -> int:
|
||||
/// '''
|
||||
/// """
|
||||
/// 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,
|
||||
mp_obj_t font) {
|
||||
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);
|
||||
|
||||
/// def qrcode(self, x: int, y: int, data: bytes, scale: int) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Renders data encoded as a QR code centered at position (x,y).
|
||||
/// Scale determines a zoom factor.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_qrcode(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// def orientation(self, degrees: int = None) -> int:
|
||||
/// '''
|
||||
/// """
|
||||
/// Sets display orientation to 0, 90, 180 or 270 degrees.
|
||||
/// Everything needs to be redrawn again when this function is used.
|
||||
/// Call without the degrees parameter to just perform the read of the
|
||||
/// value.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_orientation(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// def backlight(self, val: int = None) -> int:
|
||||
/// '''
|
||||
/// """
|
||||
/// Sets backlight intensity to the value specified in val.
|
||||
/// Call without the val parameter to just perform the read of the value.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_backlight(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// def offset(self, xy: Tuple[int, int] = None) -> Tuple[int, int]:
|
||||
/// '''
|
||||
/// """
|
||||
/// Sets offset (x, y) for all subsequent drawing calls.
|
||||
/// 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,
|
||||
const mp_obj_t *args) {
|
||||
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);
|
||||
|
||||
/// def save(self, prefix: str) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// 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) {
|
||||
mp_buffer_info_t pfx;
|
||||
mp_get_buffer_raise(prefix, &pfx, MP_BUFFER_READ);
|
||||
|
@ -29,12 +29,12 @@
|
||||
#include "common.h"
|
||||
|
||||
/// def consteq(sec: bytes, pub: bytes) -> bool:
|
||||
/// '''
|
||||
/// """
|
||||
/// Compares the private information in `sec` with public, user-provided
|
||||
/// information in `pub`. Runs in constant time, corresponding to a length
|
||||
/// of `pub`. Can access memory behind valid length of `sec`, caller is
|
||||
/// expected to avoid any invalid memory access.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorutils_consteq(mp_obj_t sec, mp_obj_t pub) {
|
||||
mp_buffer_info_t secbuf;
|
||||
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,
|
||||
mod_trezorutils_consteq);
|
||||
|
||||
/// def memcpy(dst: bytearray, dst_ofs: int,
|
||||
/// src: bytearray, src_ofs: int,
|
||||
/// n: int) -> int:
|
||||
/// '''
|
||||
/// def memcpy(
|
||||
/// dst: bytearray, dst_ofs: int, src: bytearray, src_ofs: int, n: int
|
||||
/// ) -> int:
|
||||
/// """
|
||||
/// Copies at most `n` bytes from `src` at offset `src_ofs` to
|
||||
/// `dst` at offset `dst_ofs`. Returns the number of actually
|
||||
/// copied bytes.
|
||||
/// '''
|
||||
/// """
|
||||
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);
|
||||
|
||||
@ -90,9 +90,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorutils_memcpy_obj, 5, 5,
|
||||
mod_trezorutils_memcpy);
|
||||
|
||||
/// def halt(msg: str = None) -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Halts execution.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorutils_halt(size_t n_args, const mp_obj_t *args) {
|
||||
mp_buffer_info_t msg;
|
||||
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);
|
||||
|
||||
/// def set_mode_unprivileged() -> None:
|
||||
/// '''
|
||||
/// """
|
||||
/// Set unprivileged mode.
|
||||
/// '''
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorutils_set_mode_unprivileged(void) {
|
||||
#ifndef TREZOR_EMULATOR
|
||||
__asm__ volatile("msr control, %0" ::"r"(0x1));
|
||||
|
@ -1,82 +1,99 @@
|
||||
from typing import *
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def init(ui_wait_callback: (int, int -> None)=None) -> None:
|
||||
'''
|
||||
Initializes the storage. Must be called before any other method is
|
||||
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.
|
||||
'''
|
||||
def init(ui_wait_callback: Tuple[int, Callable[int, None]] = None) -> None:
|
||||
"""
|
||||
Initializes the storage. Must be called before any other method is
|
||||
called from this module!
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def unlock(pin: int) -> bool:
|
||||
'''
|
||||
"""
|
||||
Attempts to unlock the storage with given PIN. Returns True on
|
||||
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
|
||||
def lock() -> None:
|
||||
'''
|
||||
"""
|
||||
Locks the storage.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def has_pin() -> bool:
|
||||
'''
|
||||
"""
|
||||
Returns True if storage has a configured PIN, False otherwise.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def get_pin_rem() -> int:
|
||||
'''
|
||||
"""
|
||||
Returns the number of remaining PIN entry attempts.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def change_pin(pin: int, newpin: int) -> bool:
|
||||
'''
|
||||
"""
|
||||
Change PIN. Returns True on success, False on failure.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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).
|
||||
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
|
||||
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.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
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.
|
||||
'''
|
||||
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.
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def wipe() -> None:
|
||||
'''
|
||||
"""
|
||||
Erases the whole config. Use with caution!
|
||||
'''
|
||||
"""
|
||||
|
@ -1,312 +1,347 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-aes.h
|
||||
class AES:
|
||||
'''
|
||||
"""
|
||||
AES context.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, mode: int, key: bytes, iv: bytes = None) -> None:
|
||||
'''
|
||||
"""
|
||||
Initialize AES context.
|
||||
'''
|
||||
"""
|
||||
|
||||
def encrypt(self, data: bytes) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Encrypt data and update AES context.
|
||||
'''
|
||||
"""
|
||||
|
||||
def decrypt(self, data: bytes) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Decrypt data and update AES context.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-blake256.h
|
||||
class Blake256:
|
||||
'''
|
||||
"""
|
||||
Blake256 context.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, data: bytes = None) -> None:
|
||||
'''
|
||||
"""
|
||||
Creates a hash context object.
|
||||
'''
|
||||
"""
|
||||
|
||||
def update(self, data: bytes) -> None:
|
||||
'''
|
||||
"""
|
||||
Update the hash context with hashed data.
|
||||
'''
|
||||
"""
|
||||
|
||||
def digest(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Returns the digest of hashed data.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h
|
||||
class Blake2b:
|
||||
'''
|
||||
"""
|
||||
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.
|
||||
'''
|
||||
"""
|
||||
|
||||
def update(self, data: bytes) -> None:
|
||||
'''
|
||||
"""
|
||||
Update the hash context with hashed data.
|
||||
'''
|
||||
"""
|
||||
|
||||
def digest(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Returns the digest of hashed data.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h
|
||||
class Blake2s:
|
||||
'''
|
||||
"""
|
||||
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.
|
||||
'''
|
||||
"""
|
||||
|
||||
def update(self, data: bytes) -> None:
|
||||
'''
|
||||
"""
|
||||
Update the hash context with hashed data.
|
||||
'''
|
||||
"""
|
||||
|
||||
def digest(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Returns the digest of hashed data.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-chacha20poly1305.h
|
||||
class ChaCha20Poly1305:
|
||||
'''
|
||||
"""
|
||||
ChaCha20Poly1305 context.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, key: bytes, nonce: bytes) -> None:
|
||||
'''
|
||||
"""
|
||||
Initialize the ChaCha20 + Poly1305 context for encryption or decryption
|
||||
using a 32 byte key and 12 byte nonce as in the RFC 7539 style.
|
||||
'''
|
||||
"""
|
||||
|
||||
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:
|
||||
'''
|
||||
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:
|
||||
'''
|
||||
"""
|
||||
Include authenticated data in the Poly1305 MAC using the RFC 7539
|
||||
style with 16 byte padding. This must only be called once and prior
|
||||
to encryption or decryption.
|
||||
'''
|
||||
"""
|
||||
|
||||
def finish(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Compute RFC 7539-style Poly1305 MAC.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-groestl.h
|
||||
class Groestl512:
|
||||
'''
|
||||
"""
|
||||
GROESTL512 context.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, data: bytes = None) -> None:
|
||||
'''
|
||||
"""
|
||||
Creates a hash context object.
|
||||
'''
|
||||
"""
|
||||
|
||||
def update(self, data: bytes) -> None:
|
||||
'''
|
||||
"""
|
||||
Update the hash context with hashed data.
|
||||
'''
|
||||
"""
|
||||
|
||||
def digest(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Returns the digest of hashed data.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h
|
||||
class Pbkdf2:
|
||||
'''
|
||||
"""
|
||||
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.
|
||||
'''
|
||||
"""
|
||||
|
||||
def update(self, iterations: int) -> None:
|
||||
'''
|
||||
"""
|
||||
Update a PBKDF2 context.
|
||||
'''
|
||||
"""
|
||||
|
||||
def key(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Retrieve derived key.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-rfc6979.h
|
||||
class Rfc6979:
|
||||
'''
|
||||
"""
|
||||
RFC6979 context.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, secret_key: bytes, hash: bytes) -> None:
|
||||
'''
|
||||
"""
|
||||
Initialize RFC6979 context from secret key and a hash.
|
||||
'''
|
||||
"""
|
||||
|
||||
def next(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Compute next 32-bytes of pseudorandom data.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h
|
||||
class Ripemd160:
|
||||
'''
|
||||
"""
|
||||
RIPEMD160 context.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, data: bytes = None) -> None:
|
||||
'''
|
||||
"""
|
||||
Creates a hash context object.
|
||||
'''
|
||||
"""
|
||||
|
||||
def update(self, data: bytes) -> None:
|
||||
'''
|
||||
"""
|
||||
Update the hash context with hashed data.
|
||||
'''
|
||||
"""
|
||||
|
||||
def digest(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Returns the digest of hashed data.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha1.h
|
||||
class Sha1:
|
||||
'''
|
||||
"""
|
||||
SHA1 context.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, data: bytes = None) -> None:
|
||||
'''
|
||||
"""
|
||||
Creates a hash context object.
|
||||
'''
|
||||
"""
|
||||
|
||||
def update(self, data: bytes) -> None:
|
||||
'''
|
||||
"""
|
||||
Update the hash context with hashed data.
|
||||
'''
|
||||
"""
|
||||
|
||||
def digest(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Returns the digest of hashed data.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha256.h
|
||||
class Sha256:
|
||||
'''
|
||||
"""
|
||||
SHA256 context.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, data: bytes = None) -> None:
|
||||
'''
|
||||
"""
|
||||
Creates a hash context object.
|
||||
'''
|
||||
"""
|
||||
|
||||
def update(self, data: bytes) -> None:
|
||||
'''
|
||||
"""
|
||||
Update the hash context with hashed data.
|
||||
'''
|
||||
"""
|
||||
|
||||
def digest(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Returns the digest of hashed data.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h
|
||||
class Sha3_256:
|
||||
'''
|
||||
"""
|
||||
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.
|
||||
'''
|
||||
"""
|
||||
|
||||
def update(self, data: bytes) -> None:
|
||||
'''
|
||||
"""
|
||||
Update the hash context with hashed data.
|
||||
'''
|
||||
"""
|
||||
|
||||
def digest(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Returns the digest of hashed data.
|
||||
'''
|
||||
"""
|
||||
|
||||
def copy(self) -> sha3:
|
||||
'''
|
||||
"""
|
||||
Returns the copy of the digest object with the current state
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h
|
||||
class Sha3_512:
|
||||
'''
|
||||
"""
|
||||
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.
|
||||
'''
|
||||
"""
|
||||
|
||||
def update(self, data: bytes) -> None:
|
||||
'''
|
||||
"""
|
||||
Update the hash context with hashed data.
|
||||
'''
|
||||
"""
|
||||
|
||||
def digest(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Returns the digest of hashed data.
|
||||
'''
|
||||
"""
|
||||
|
||||
def copy(self) -> sha3:
|
||||
'''
|
||||
"""
|
||||
Returns the copy of the digest object with the current state
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha512.h
|
||||
class Sha512:
|
||||
'''
|
||||
"""
|
||||
SHA512 context.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, data: bytes = None) -> None:
|
||||
'''
|
||||
"""
|
||||
Creates a hash context object.
|
||||
'''
|
||||
"""
|
||||
|
||||
def hash(self, data: bytes) -> None:
|
||||
'''
|
||||
"""
|
||||
Update the hash context with hashed data.
|
||||
'''
|
||||
"""
|
||||
|
||||
def digest(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Returns the digest of hashed data.
|
||||
'''
|
||||
"""
|
||||
|
@ -1,118 +1,126 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
class HDNode:
|
||||
'''
|
||||
"""
|
||||
BIP0032 HD node structure.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
depth: int,
|
||||
fingerprint: int,
|
||||
child_num: int,
|
||||
chain_code: bytes,
|
||||
private_key: bytes = None,
|
||||
public_key: bytes = None,
|
||||
curve_name: str = None) -> None:
|
||||
'''
|
||||
'''
|
||||
def __init__(
|
||||
self,
|
||||
depth: int,
|
||||
fingerprint: int,
|
||||
child_num: int,
|
||||
chain_code: bytes,
|
||||
private_key: bytes = 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.
|
||||
'''
|
||||
"""
|
||||
|
||||
def derive_cardano(self, index: int) -> None:
|
||||
'''
|
||||
"""
|
||||
Derive a BIP0032 child node in place using Cardano algorithm.
|
||||
'''
|
||||
"""
|
||||
|
||||
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:
|
||||
'''
|
||||
"""
|
||||
Serialize the public info from HD node to base58 string.
|
||||
'''
|
||||
"""
|
||||
|
||||
def serialize_private(self, version: int) -> str:
|
||||
'''
|
||||
"""
|
||||
Serialize the private info HD node to base58 string.
|
||||
'''
|
||||
"""
|
||||
|
||||
def clone(self) -> HDNode:
|
||||
'''
|
||||
"""
|
||||
Returns a copy of the HD node.
|
||||
'''
|
||||
"""
|
||||
|
||||
def depth(self) -> int:
|
||||
'''
|
||||
"""
|
||||
Returns a depth of the HD node.
|
||||
'''
|
||||
"""
|
||||
|
||||
def fingerprint(self) -> int:
|
||||
'''
|
||||
"""
|
||||
Returns a fingerprint of the HD node (hash of the parent public key).
|
||||
'''
|
||||
"""
|
||||
|
||||
def child_num(self) -> int:
|
||||
'''
|
||||
"""
|
||||
Returns a child index of the HD node.
|
||||
'''
|
||||
"""
|
||||
|
||||
def chain_code(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Returns a chain code of the HD node.
|
||||
'''
|
||||
"""
|
||||
|
||||
def private_key(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Returns a private key of the HD node.
|
||||
'''
|
||||
"""
|
||||
|
||||
def private_key_ext(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Returns a private key extension of the HD node.
|
||||
'''
|
||||
"""
|
||||
|
||||
def public_key(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Returns a public key of the HD node.
|
||||
'''
|
||||
"""
|
||||
|
||||
def address(self, version: int) -> str:
|
||||
'''
|
||||
"""
|
||||
Compute a base58-encoded address string from the HD node.
|
||||
'''
|
||||
"""
|
||||
|
||||
def nem_address(self, network: int) -> str:
|
||||
'''
|
||||
"""
|
||||
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
|
||||
'''
|
||||
"""
|
||||
|
||||
def ethereum_pubkeyhash(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
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.
|
||||
'''
|
||||
"""
|
||||
|
||||
def from_seed(seed: bytes, curve_name: str) -> HDNode:
|
||||
'''
|
||||
"""
|
||||
Construct a BIP0032 HD node from a BIP0039 seed value.
|
||||
'''
|
||||
"""
|
||||
|
||||
def from_mnemonic_cardano(mnemonic: str, passphrase: str) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Convert mnemonic to hdnode
|
||||
'''
|
||||
"""
|
||||
|
@ -1,38 +1,47 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
|
||||
def find_word(prefix: str) -> Optional[str]:
|
||||
'''
|
||||
"""
|
||||
Return the first word from the wordlist starting with prefix.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
|
||||
def complete_word(prefix: str) -> int:
|
||||
'''
|
||||
"""
|
||||
Return possible 1-letter suffixes for given word prefix.
|
||||
Result is a bitmask, with 'a' on the lowest bit, 'b' on the second lowest, etc.
|
||||
'''
|
||||
Result is a bitmask, with 'a' on the lowest bit, 'b' on the second
|
||||
lowest, etc.
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
|
||||
def generate(strength: int) -> str:
|
||||
'''
|
||||
"""
|
||||
Generate a mnemonic of given strength (128, 160, 192, 224 and 256 bits).
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
|
||||
def from_data(data: bytes) -> str:
|
||||
'''
|
||||
"""
|
||||
Generate a mnemonic from given data (of 16, 20, 24, 28 and 32 bytes).
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
|
||||
def check(mnemonic: str) -> bool:
|
||||
'''
|
||||
"""
|
||||
Check whether given mnemonic is valid.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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.
|
||||
'''
|
||||
"""
|
||||
|
@ -1,20 +1,23 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h
|
||||
def generate_secret() -> bytes:
|
||||
'''
|
||||
"""
|
||||
Generate secret key.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h
|
||||
def publickey(secret_key: bytes) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Computes public key from secret key.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h
|
||||
def multiply(secret_key: bytes, public_key: bytes) -> bytes:
|
||||
'''
|
||||
Multiplies point defined by public_key with scalar defined by secret_key.
|
||||
Useful for ECDH.
|
||||
'''
|
||||
"""
|
||||
Multiplies point defined by public_key with scalar defined by
|
||||
secret_key. Useful for ECDH.
|
||||
"""
|
||||
|
@ -1,50 +1,66 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
def generate_secret() -> bytes:
|
||||
'''
|
||||
"""
|
||||
Generate secret key.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
def publickey(secret_key: bytes) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Computes public key from secret key.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
def verify(public_key: bytes, signature: bytes, message: bytes) -> bool:
|
||||
'''
|
||||
"""
|
||||
Uses public key to verify the signature of the message.
|
||||
Returns True on success.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
def cosi_combine_publickeys(public_keys: List[bytes]) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Combines a list of public keys used in COSI cosigning scheme.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
def cosi_combine_signatures(R: bytes, signatures: List[bytes]) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Combines a list of signatures used in COSI cosigning scheme.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
def cosi_sign(secret_key: bytes, message: bytes, nonce: bytes, sigR: bytes, combined_pubkey: bytes) -> bytes:
|
||||
'''
|
||||
def cosi_sign(
|
||||
secret_key: bytes,
|
||||
message: bytes,
|
||||
nonce: bytes,
|
||||
sigR: bytes,
|
||||
combined_pubkey: bytes,
|
||||
) -> bytes:
|
||||
"""
|
||||
Produce signature of message using COSI cosigning scheme.
|
||||
'''
|
||||
"""
|
||||
|
@ -1,313 +1,407 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
class Ge25519:
|
||||
'''
|
||||
"""
|
||||
EC point on ED25519
|
||||
'''
|
||||
"""
|
||||
def __init__(x: Optional[Union[Ge25519, bytes]] = None):
|
||||
'''
|
||||
"""
|
||||
Constructor
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
class Sc25519:
|
||||
'''
|
||||
"""
|
||||
EC scalar on SC25519
|
||||
'''
|
||||
"""
|
||||
def __init__(x: Optional[Union[Sc25519, bytes, int]] = None):
|
||||
'''
|
||||
"""
|
||||
Constructor
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
class Hasher:
|
||||
'''
|
||||
"""
|
||||
XMR hasher
|
||||
'''
|
||||
"""
|
||||
def __init__(x: Optional[bytes] = None):
|
||||
'''
|
||||
"""
|
||||
Constructor
|
||||
'''
|
||||
def update(buffer: bytes):
|
||||
'''
|
||||
"""
|
||||
def update(buffer: bytes):
|
||||
"""
|
||||
Update hasher
|
||||
'''
|
||||
def digest() -> bytes:
|
||||
'''
|
||||
"""
|
||||
def digest() -> bytes:
|
||||
"""
|
||||
Computes digest
|
||||
'''
|
||||
def copy() -> Hasher:
|
||||
'''
|
||||
"""
|
||||
def copy() -> Hasher:
|
||||
"""
|
||||
Creates copy of the hasher, preserving the state
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def check256_modm(val: Sc25519):
|
||||
'''
|
||||
"""
|
||||
Throws exception if scalar is invalid
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def iszero256_modm(val: Sc25519) -> bool:
|
||||
'''
|
||||
"""
|
||||
Returns False if the scalar is zero
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def eq256_modm(a: Sc25519, b: Sc25519) -> int:
|
||||
'''
|
||||
"""
|
||||
Compares scalars, returns 1 on the same value
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
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
|
||||
def add256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519:
|
||||
'''
|
||||
"""
|
||||
Scalar addition
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def sub256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519:
|
||||
'''
|
||||
"""
|
||||
Scalar subtraction
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def mul256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519:
|
||||
'''
|
||||
"""
|
||||
Scalar multiplication
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def inv256_modm(r: Optional[Sc25519], a: Sc25519) -> Sc25519:
|
||||
'''
|
||||
"""
|
||||
Scalar modular inversion
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_set_neutral(r: Optional[Ge25519]) -> Ge25519:
|
||||
'''
|
||||
"""
|
||||
Sets neutral point
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_set_xmr_h(r: Optional[Ge25519]) -> Ge25519:
|
||||
'''
|
||||
"""
|
||||
Sets H point
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_check(r: Ge25519):
|
||||
'''
|
||||
"""
|
||||
Checks point, throws if not on curve
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_eq(a: Ge25519, b: Ge25519) -> bool:
|
||||
'''
|
||||
"""
|
||||
Compares EC points
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_add(r: Optional[Ge25519], a: Ge25519, b: Ge25519) -> Ge25519:
|
||||
'''
|
||||
"""
|
||||
Adds EC points
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_sub(r: Optional[Ge25519], a: Ge25519, b: Ge25519) -> Ge25519:
|
||||
'''
|
||||
"""
|
||||
Subtracts EC points
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_double(r: Optional[Ge25519], p: Ge25519) -> Ge25519:
|
||||
'''
|
||||
"""
|
||||
EC point doubling
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_mul8(r: Optional[Ge25519], p: Ge25519) -> Ge25519:
|
||||
'''
|
||||
"""
|
||||
EC point * 8
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_pack(r: bytes, p: Ge25519, offset: int = 0) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Point compression
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def base58_addr_encode_check(tag: int, buff: bytes) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Monero block base 58 encoding
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
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
|
||||
def xmr_random_scalar(r: Optional[Sc25519] = None) -> Sc25519:
|
||||
'''
|
||||
"""
|
||||
Generates a random scalar
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def xmr_fast_hash(r: Optional[bytes], buff: bytes) -> bytes:
|
||||
'''
|
||||
"""
|
||||
XMR fast hash
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def xmr_hash_to_ec(r: Optional[Ge25519], buff: bytes) -> Ge25519:
|
||||
'''
|
||||
"""
|
||||
XMR hashing to EC point
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def xmr_hash_to_scalar(r: Optional[Sc25519], buff: bytes) -> Sc25519:
|
||||
'''
|
||||
"""
|
||||
XMR hashing to EC scalar
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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))
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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)
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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))
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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)
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def xmr_gen_c(r: Optional[Ge25519], a: Sc25519, amount: int) -> Ge25519:
|
||||
'''
|
||||
"""
|
||||
aG + amount * H
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ct_equals(a: bytes, b: bytes) -> bool:
|
||||
'''
|
||||
"""
|
||||
Constant time buffer comparison
|
||||
'''
|
||||
"""
|
||||
|
@ -1,13 +1,15 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-nem.h
|
||||
def validate_address(address: str, network: int) -> bool:
|
||||
'''
|
||||
"""
|
||||
Validate a NEM address
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-nem.h
|
||||
def compute_address(public_key: bytes, network: int) -> str:
|
||||
'''
|
||||
"""
|
||||
Compute a NEM address from a public key
|
||||
'''
|
||||
"""
|
||||
|
@ -1,40 +1,48 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
||||
def generate_secret() -> bytes:
|
||||
'''
|
||||
"""
|
||||
Generate secret key.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
||||
def publickey(secret_key: bytes, compressed: bool = True) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Computes public key from secret key.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
||||
def sign(secret_key: bytes, digest: bytes, 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.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
||||
def verify(public_key: bytes, signature: bytes, digest: bytes) -> bool:
|
||||
'''
|
||||
"""
|
||||
Uses public key to verify the signature of the digest.
|
||||
Returns True on success.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
||||
def verify_recover(signature: bytes, digest: bytes) -> bytes:
|
||||
'''
|
||||
Uses signature of the digest to verify the digest and recover the public key.
|
||||
Returns public key on success, None on failure.
|
||||
'''
|
||||
"""
|
||||
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-nist256p1.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.
|
||||
'''
|
||||
"""
|
||||
Multiplies point defined by public_key with scalar defined by
|
||||
secret_key. Useful for ECDH.
|
||||
"""
|
||||
|
@ -1,19 +1,22 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-random.h
|
||||
def uniform(n: int) -> int:
|
||||
'''
|
||||
"""
|
||||
Compute uniform random number from interval 0 ... n - 1.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-random.h
|
||||
def bytes(len: int) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Generate random bytes sequence of length len.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-random.h
|
||||
def shuffle(data: list) -> None:
|
||||
'''
|
||||
"""
|
||||
Shuffles items of given list (in-place).
|
||||
'''
|
||||
"""
|
||||
|
@ -1,40 +1,51 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
|
||||
def generate_secret() -> bytes:
|
||||
'''
|
||||
"""
|
||||
Generate secret key.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
|
||||
def publickey(secret_key: bytes, compressed: bool = True) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Computes public key from secret key.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
|
||||
def sign(secret_key: bytes, digest: bytes, 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.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
|
||||
def verify(public_key: bytes, signature: bytes, digest: bytes) -> bool:
|
||||
'''
|
||||
"""
|
||||
Uses public key to verify the signature of the digest.
|
||||
Returns True on success.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
|
||||
def verify_recover(signature: bytes, digest: bytes) -> bytes:
|
||||
'''
|
||||
Uses signature of the digest to verify the digest and recover the public key.
|
||||
Returns public key on success, None on failure.
|
||||
'''
|
||||
"""
|
||||
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.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.
|
||||
'''
|
||||
"""
|
||||
Multiplies point defined by public_key with scalar defined by
|
||||
secret_key. Useful for ECDH.
|
||||
"""
|
||||
|
48
core/mocks/generated/trezorcrypto/secp256k1_zkp.py
Normal file
48
core/mocks/generated/trezorcrypto/secp256k1_zkp.py
Normal file
@ -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
|
||||
|
@ -1,206 +1,223 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorio/modtrezorio-flash.h
|
||||
class FlashOTP:
|
||||
'''
|
||||
'''
|
||||
"""
|
||||
"""
|
||||
|
||||
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
|
||||
'''
|
||||
"""
|
||||
|
||||
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
|
||||
'''
|
||||
"""
|
||||
|
||||
def FlashOTP.lock(self, block: int) -> None:
|
||||
'''
|
||||
def lock(self, block: int) -> None:
|
||||
"""
|
||||
Lock OTP flash block
|
||||
'''
|
||||
"""
|
||||
|
||||
def FlashOTP.is_locked(self, block: int) -> bool:
|
||||
'''
|
||||
def is_locked(self, block: int) -> bool:
|
||||
"""
|
||||
Is OTP flash block locked?
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorio/modtrezorio-hid.h
|
||||
class HID:
|
||||
'''
|
||||
"""
|
||||
USB HID interface configuration.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
iface_num: int,
|
||||
ep_in: int,
|
||||
ep_out: int,
|
||||
report_desc: bytes,
|
||||
subclass: int = 0,
|
||||
protocol: int = 0,
|
||||
polling_interval: int = 1,
|
||||
max_packet_len: int = 64) -> None:
|
||||
'''
|
||||
'''
|
||||
def __init__(
|
||||
self,
|
||||
iface_num: int,
|
||||
ep_in: int,
|
||||
ep_out: int,
|
||||
report_desc: bytes,
|
||||
subclass: int = 0,
|
||||
protocol: int = 0,
|
||||
polling_interval: int = 1,
|
||||
max_packet_len: int = 64,
|
||||
) -> None:
|
||||
"""
|
||||
"""
|
||||
|
||||
def iface_num(self) -> int:
|
||||
'''
|
||||
"""
|
||||
Returns the configured number of this interface.
|
||||
'''
|
||||
"""
|
||||
|
||||
def write(self, msg: bytes) -> int:
|
||||
'''
|
||||
"""
|
||||
Sends message using USB HID (device) or UDP (emulator).
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorio/modtrezorio-poll.h
|
||||
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
|
||||
`list_ref`:
|
||||
`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
|
||||
If timeout occurs, False is returned, True otherwise.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorio/modtrezorio-sbu.h
|
||||
class SBU:
|
||||
'''
|
||||
'''
|
||||
"""
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
'''
|
||||
'''
|
||||
"""
|
||||
"""
|
||||
|
||||
def set(self, sbu1: bool, sbu2: bool) -> None:
|
||||
'''
|
||||
"""
|
||||
Sets SBU wires to sbu1 and sbu2 values respectively
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorio/modtrezorio-sdcard.h
|
||||
class SDCard:
|
||||
'''
|
||||
'''
|
||||
"""
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
'''
|
||||
'''
|
||||
"""
|
||||
"""
|
||||
|
||||
def present(self) -> bool:
|
||||
'''
|
||||
"""
|
||||
Returns True if SD card is detected, False otherwise.
|
||||
'''
|
||||
"""
|
||||
|
||||
def power(self, state: bool) -> bool:
|
||||
'''
|
||||
"""
|
||||
Power on or power off the SD card interface.
|
||||
Returns True if in case of success, False otherwise.
|
||||
'''
|
||||
"""
|
||||
|
||||
def capacity(self) -> int:
|
||||
'''
|
||||
"""
|
||||
Returns capacity of the SD card in bytes, or zero if not present.
|
||||
'''
|
||||
"""
|
||||
|
||||
def read(self, block_num: int, buf: bytearray) -> bool:
|
||||
'''
|
||||
"""
|
||||
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.
|
||||
Returns True if in case of success, False otherwise.
|
||||
'''
|
||||
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.
|
||||
"""
|
||||
|
||||
def write(self, block_num: int, buf: bytes) -> bool:
|
||||
'''
|
||||
"""
|
||||
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.
|
||||
Returns True if in case of success, False otherwise.
|
||||
'''
|
||||
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.
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorio/modtrezorio-usb.h
|
||||
class USB:
|
||||
'''
|
||||
"""
|
||||
USB device configuration.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
device_class: int=0,
|
||||
device_subclass: int=0,
|
||||
device_protocol: int=0,
|
||||
vendor_id: int,
|
||||
product_id: int,
|
||||
release_num: int,
|
||||
manufacturer: str='',
|
||||
product: str='',
|
||||
serial_number: str='',
|
||||
interface: str='',
|
||||
usb21_enabled: bool=True,
|
||||
usb21_landing: bool=True) -> None:
|
||||
'''
|
||||
'''
|
||||
def __init__(
|
||||
self,
|
||||
vendor_id: int,
|
||||
product_id: int,
|
||||
release_num: int,
|
||||
device_class: int = 0,
|
||||
device_subclass: int = 0,
|
||||
device_protocol: int = 0,
|
||||
manufacturer: str = "",
|
||||
product: str = "",
|
||||
serial_number: str = "",
|
||||
interface: str = "",
|
||||
usb21_enabled: bool = True,
|
||||
usb21_landing: bool = True,
|
||||
) -> None:
|
||||
"""
|
||||
"""
|
||||
|
||||
def add(self, iface: Union[HID, VCP, WebUSB]) -> None:
|
||||
'''
|
||||
"""
|
||||
Registers passed interface into the USB stack.
|
||||
'''
|
||||
"""
|
||||
|
||||
def open(self) -> None:
|
||||
'''
|
||||
"""
|
||||
Initializes the USB stack.
|
||||
'''
|
||||
"""
|
||||
|
||||
def close(self) -> None:
|
||||
'''
|
||||
"""
|
||||
Cleans up the USB stack.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorio/modtrezorio-vcp.h
|
||||
class VCP:
|
||||
'''
|
||||
"""
|
||||
USB VCP interface configuration.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
iface_num: int,
|
||||
data_iface_num: int,
|
||||
ep_in: int,
|
||||
ep_out: int,
|
||||
ep_cmd: int) -> None:
|
||||
'''
|
||||
'''
|
||||
def __init__(
|
||||
self,
|
||||
iface_num: int,
|
||||
data_iface_num: int,
|
||||
ep_in: int,
|
||||
ep_out: int,
|
||||
ep_cmd: int,
|
||||
) -> None:
|
||||
"""
|
||||
"""
|
||||
|
||||
def iface_num(self) -> int:
|
||||
'''
|
||||
"""
|
||||
Returns the configured number of this interface.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorio/modtrezorio-webusb.h
|
||||
class WebUSB:
|
||||
'''
|
||||
"""
|
||||
USB WebUSB interface configuration.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
iface_num: int,
|
||||
ep_in: int,
|
||||
ep_out: int,
|
||||
subclass: int = 0,
|
||||
protocol: int = 0,
|
||||
polling_interval: int = 1,
|
||||
max_packet_len: int = 64) -> None:
|
||||
'''
|
||||
'''
|
||||
def __init__(
|
||||
self,
|
||||
iface_num: int,
|
||||
ep_in: int,
|
||||
ep_out: int,
|
||||
subclass: int = 0,
|
||||
protocol: int = 0,
|
||||
polling_interval: int = 1,
|
||||
max_packet_len: int = 64,
|
||||
) -> None:
|
||||
"""
|
||||
"""
|
||||
|
||||
def iface_num(self) -> int:
|
||||
'''
|
||||
"""
|
||||
Returns the configured number of this interface.
|
||||
'''
|
||||
"""
|
||||
|
||||
def write(self, msg: bytes) -> int:
|
||||
'''
|
||||
"""
|
||||
Sends message using USB WebUSB (device) or UDP (emulator).
|
||||
'''
|
||||
"""
|
||||
|
@ -1,124 +1,182 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorui/modtrezorui-display.h
|
||||
class Display:
|
||||
'''
|
||||
"""
|
||||
Provide access to device display.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
'''
|
||||
"""
|
||||
Initialize the display.
|
||||
'''
|
||||
"""
|
||||
|
||||
def clear(self) -> None:
|
||||
'''
|
||||
"""
|
||||
Clear display with black color.
|
||||
'''
|
||||
"""
|
||||
|
||||
def refresh(self) -> None:
|
||||
'''
|
||||
"""
|
||||
Refresh display (update screen).
|
||||
'''
|
||||
"""
|
||||
|
||||
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:
|
||||
'''
|
||||
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 bar_radius(
|
||||
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
|
||||
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:
|
||||
'''
|
||||
"""
|
||||
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).
|
||||
The image needs to be in TREZOR Optimized Image Format (TOIF) - full-color mode.
|
||||
Image needs to be of exactly AVATAR_IMAGE_SIZE x AVATAR_IMAGE_SIZE pixels size.
|
||||
'''
|
||||
The image needs to be in TREZOR Optimized Image Format (TOIF) -
|
||||
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:
|
||||
'''
|
||||
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 Format (TOIF) - gray-scale mode.
|
||||
'''
|
||||
def icon(
|
||||
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,
|
||||
bgcolor as background. The icon needs to be in TREZOR Optimized Image
|
||||
Format (TOIF) - gray-scale mode.
|
||||
"""
|
||||
|
||||
def loader(self, progress: int, yoffset: int, fgcolor: int, bgcolor: int, icon: bytes = None, iconfgcolor: int = None) -> None:
|
||||
'''
|
||||
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.
|
||||
Progress determines its position (0-1000), fgcolor is used as foreground color, bgcolor as background.
|
||||
When icon and iconfgcolor are provided, an 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.
|
||||
'''
|
||||
Progress determines its position (0-1000), fgcolor is used as foreground
|
||||
color, bgcolor as background. When icon and iconfgcolor are provided, an
|
||||
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:
|
||||
'''
|
||||
"""
|
||||
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:
|
||||
'''
|
||||
Renders left-aligned text at position (x,y) where x is left position and y is baseline.
|
||||
Font font is used for rendering, fgcolor is used as foreground color, bgcolor as background.
|
||||
Fills at least minwidth pixels with bgcolor.
|
||||
Returns width of rendered text in pixels.
|
||||
'''
|
||||
def text(
|
||||
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
|
||||
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_center(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 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_center(
|
||||
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
|
||||
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_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:
|
||||
'''
|
||||
"""
|
||||
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:
|
||||
'''
|
||||
"""
|
||||
Renders data encoded as a QR code centered at position (x,y).
|
||||
Scale determines a zoom factor.
|
||||
'''
|
||||
"""
|
||||
|
||||
def orientation(self, degrees: int = None) -> int:
|
||||
'''
|
||||
"""
|
||||
Sets display orientation to 0, 90, 180 or 270 degrees.
|
||||
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:
|
||||
'''
|
||||
"""
|
||||
Sets backlight intensity to the value specified in val.
|
||||
Call without the val parameter to just perform the read of the value.
|
||||
'''
|
||||
"""
|
||||
|
||||
def offset(self, xy: Tuple[int, int] = None) -> Tuple[int, int]:
|
||||
'''
|
||||
"""
|
||||
Sets offset (x, y) for all subsequent drawing calls.
|
||||
Call without the xy parameter to just perform the read of the value.
|
||||
'''
|
||||
"""
|
||||
|
||||
def save(self, prefix: str) -> None:
|
||||
'''
|
||||
"""
|
||||
Saves current display contents to PNG file with given prefix.
|
||||
'''
|
||||
"""
|
||||
|
@ -1,32 +1,36 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorutils/modtrezorutils.c
|
||||
def consteq(sec: bytes, pub: bytes) -> bool:
|
||||
'''
|
||||
"""
|
||||
Compares the private information in `sec` with public, user-provided
|
||||
information in `pub`. Runs in constant time, corresponding to a length
|
||||
of `pub`. Can access memory behind valid length of `sec`, caller is
|
||||
expected to avoid any invalid memory access.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorutils/modtrezorutils.c
|
||||
def memcpy(dst: bytearray, dst_ofs: int,
|
||||
src: bytearray, src_ofs: int,
|
||||
n: int) -> int:
|
||||
'''
|
||||
def memcpy(
|
||||
dst: bytearray, dst_ofs: int, src: bytearray, src_ofs: int, n: int
|
||||
) -> int:
|
||||
"""
|
||||
Copies at most `n` bytes from `src` at offset `src_ofs` to
|
||||
`dst` at offset `dst_ofs`. Returns the number of actually
|
||||
copied bytes.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorutils/modtrezorutils.c
|
||||
def halt(msg: str = None) -> None:
|
||||
'''
|
||||
"""
|
||||
Halts execution.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorutils/modtrezorutils.c
|
||||
def set_mode_unprivileged() -> None:
|
||||
'''
|
||||
"""
|
||||
Set unprivileged mode.
|
||||
'''
|
||||
"""
|
||||
|
@ -1,5 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
import glob
|
||||
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 = "/// "
|
||||
|
||||
@ -28,17 +38,17 @@ def split_to_parts(line, mod_desc=None):
|
||||
current_class = line[6:].split("(")[0].strip(":")
|
||||
current_indent = 0
|
||||
|
||||
yield (current_package, "\n")
|
||||
yield (current_package, "\n\n")
|
||||
yield (current_package, "# " + mod_desc + "\n")
|
||||
|
||||
elif line.startswith("def "):
|
||||
current_method = line[4:].split("(")[0]
|
||||
|
||||
yield (current_package, "\n")
|
||||
|
||||
if current_class is None:
|
||||
yield (current_package, "\n\n")
|
||||
yield (current_package, "# " + mod_desc + "\n")
|
||||
else:
|
||||
yield (current_package, "\n")
|
||||
current_indent = 4
|
||||
|
||||
line = current_indent * " " + line
|
||||
@ -49,16 +59,20 @@ def split_to_parts(line, mod_desc=None):
|
||||
def store_to_file(dest, parts):
|
||||
for package, line in parts:
|
||||
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"
|
||||
|
||||
if not os.path.exists(dirpath):
|
||||
os.makedirs(dirpath)
|
||||
open(os.path.join(dirpath, "__init__.py"), "w").close()
|
||||
open(os.path.join(dirpath, ".mock-generated"), "w").close()
|
||||
|
||||
filepath = os.path.join(dirpath, filename)
|
||||
|
||||
os.makedirs(dirpath, exist_ok=True)
|
||||
|
||||
if os.path.isdir(os.path.join(dest, package)):
|
||||
if not line.strip():
|
||||
continue
|
||||
print("Package exists: {}".format(package))
|
||||
print("You should set 'package:' in {}".format(line.strip()))
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if not os.path.exists(filepath):
|
||||
with open(filepath, "a") as f:
|
||||
f.write("from typing import *\n")
|
||||
@ -72,17 +86,16 @@ def build_module(mod_file, dest):
|
||||
global current_class
|
||||
global current_package
|
||||
|
||||
if not (mod_file.endswith(".h") or mod_file.endswith(".c")):
|
||||
return
|
||||
if not os.path.basename(mod_file).startswith("mod"):
|
||||
return
|
||||
filename = os.path.basename(mod_file)
|
||||
assert filename.startswith("mod")
|
||||
assert filename.endswith(".c") or filename.endswith(".h")
|
||||
# modfoobar-xyz.h -> foobar-xyz
|
||||
name = filename[3:-2]
|
||||
|
||||
current_indent = 0
|
||||
current_class = None
|
||||
current_package = (
|
||||
os.path.basename(mod_file).split(".")[0].split("-")[0].replace("mod", "")
|
||||
)
|
||||
mod_desc = mod_file.replace("../embed/extmod", "extmod")
|
||||
current_package = name.split("-")[0]
|
||||
mod_desc = re.sub(r"^.*/embed/", "", mod_file)
|
||||
|
||||
for l in open(mod_file):
|
||||
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))
|
||||
|
||||
|
||||
def build_directory(dir, dest):
|
||||
print("Building mocks for", dir, "to", dest)
|
||||
for pkg in sorted(
|
||||
[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 build_directory(src, dest):
|
||||
for modfile in sorted(glob.glob(os.path.join(src, "**", "mod*.[ch]"))):
|
||||
build_module(modfile, dest)
|
||||
|
||||
|
||||
def clear_directory(top_dir):
|
||||
print("Clearing up directory", top_dir)
|
||||
for root, dirs, files in os.walk(top_dir, topdown=False):
|
||||
if ".mock-generated" not in files:
|
||||
# print("Not a mock directory", root)
|
||||
continue
|
||||
for name in files:
|
||||
# print('Deleting file', os.path.join(root, name))
|
||||
os.remove(os.path.join(root, name))
|
||||
for name in dirs:
|
||||
# print('Deleting directory', os.path.join(root, name))
|
||||
try:
|
||||
os.rmdir(os.path.join(root, name))
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
def do_check():
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
build_directory(EXTMOD_PATH, tmpdir)
|
||||
diff_out = subprocess.run(
|
||||
["diff", "-ur", MOCKS_PATH, tmpdir],
|
||||
stdout=subprocess.PIPE,
|
||||
universal_newlines=True,
|
||||
).stdout
|
||||
if diff_out.strip():
|
||||
print(diff_out, end="")
|
||||
sys.exit(1)
|
||||
|
||||
os.rmdir(root)
|
||||
|
||||
def do_generate():
|
||||
shutil.rmtree(MOCKS_PATH)
|
||||
build_directory(EXTMOD_PATH, MOCKS_PATH)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
clear_directory("../mocks/generated")
|
||||
build_directory("../embed/extmod", "../mocks/generated")
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "--check":
|
||||
do_check()
|
||||
else:
|
||||
do_generate()
|
||||
|
Loading…
Reference in New Issue
Block a user