1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-12 18:49:07 +00:00

extmod: use lowercase names

This commit is contained in:
Jan Pochyla 2017-06-14 18:47:38 +02:00
parent 2ca60fc59a
commit 803c47dca8
38 changed files with 616 additions and 617 deletions

View File

@ -27,7 +27,7 @@ typedef struct _mp_obj_Config_t {
/// '''
/// Initializes the storage.
/// '''
STATIC mp_obj_t mod_TrezorConfig_Config_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezorconfig_Config_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
mp_obj_Config_t *o = m_new_obj(mp_obj_Config_t);
o->base.type = type;
@ -42,7 +42,7 @@ STATIC mp_obj_t mod_TrezorConfig_Config_make_new(const mp_obj_type_t *type, size
/// '''
/// Gets a value of given key for given app (or empty bytes if not set).
/// '''
STATIC mp_obj_t mod_TrezorConfig_Config_get(mp_obj_t self, mp_obj_t app, mp_obj_t key) {
STATIC mp_obj_t mod_trezorconfig_Config_get(mp_obj_t self, mp_obj_t app, mp_obj_t key) {
uint8_t a = mp_obj_get_int(app);
uint8_t k = mp_obj_get_int(key);
uint16_t appkey = a << 8 | k, len;
@ -56,14 +56,14 @@ STATIC mp_obj_t mod_TrezorConfig_Config_get(mp_obj_t self, mp_obj_t app, mp_obj_
memcpy(vstr.buf, val, len);
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorConfig_Config_get_obj, mod_TrezorConfig_Config_get);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorconfig_Config_get_obj, mod_trezorconfig_Config_get);
/// def set(self, app: int, key: int, value: bytes) -> None:
/// '''
/// Sets a value of given key for given app.
/// Returns True on success.
/// '''
STATIC mp_obj_t mod_TrezorConfig_Config_set(size_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezorconfig_Config_set(size_t n_args, const mp_obj_t *args) {
uint8_t a = mp_obj_get_int(args[1]);
uint8_t k = mp_obj_get_int(args[2]);
uint16_t appkey = a << 8 | k;
@ -75,45 +75,45 @@ STATIC mp_obj_t mod_TrezorConfig_Config_set(size_t n_args, const mp_obj_t *args)
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorConfig_Config_set_obj, 4, 4, mod_TrezorConfig_Config_set);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_Config_set_obj, 4, 4, mod_trezorconfig_Config_set);
/// def wipe(self) -> None:
/// '''
/// Erases the whole config. Use with caution!
/// '''
STATIC mp_obj_t mod_TrezorConfig_Config_wipe(mp_obj_t self) {
STATIC mp_obj_t mod_trezorconfig_Config_wipe(mp_obj_t self) {
bool r = norcow_wipe();
if (!r) {
mp_raise_msg(&mp_type_RuntimeError, "Could not wipe storage");
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorConfig_Config_wipe_obj, mod_TrezorConfig_Config_wipe);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorconfig_Config_wipe_obj, mod_trezorconfig_Config_wipe);
STATIC const mp_rom_map_elem_t mod_TrezorConfig_Config_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&mod_TrezorConfig_Config_get_obj) },
{ MP_ROM_QSTR(MP_QSTR_set), MP_ROM_PTR(&mod_TrezorConfig_Config_set_obj) },
{ MP_ROM_QSTR(MP_QSTR_wipe), MP_ROM_PTR(&mod_TrezorConfig_Config_wipe_obj) },
STATIC const mp_rom_map_elem_t mod_trezorconfig_Config_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&mod_trezorconfig_Config_get_obj) },
{ MP_ROM_QSTR(MP_QSTR_set), MP_ROM_PTR(&mod_trezorconfig_Config_set_obj) },
{ MP_ROM_QSTR(MP_QSTR_wipe), MP_ROM_PTR(&mod_trezorconfig_Config_wipe_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorConfig_Config_locals_dict, mod_TrezorConfig_Config_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorconfig_Config_locals_dict, mod_trezorconfig_Config_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorConfig_Config_type = {
STATIC const mp_obj_type_t mod_trezorconfig_Config_type = {
{ &mp_type_type },
.name = MP_QSTR_Config,
.make_new = mod_TrezorConfig_Config_make_new,
.locals_dict = (void*)&mod_TrezorConfig_Config_locals_dict,
.make_new = mod_trezorconfig_Config_make_new,
.locals_dict = (void*)&mod_trezorconfig_Config_locals_dict,
};
STATIC const mp_rom_map_elem_t mp_module_TrezorConfig_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_TrezorConfig) },
{ MP_ROM_QSTR(MP_QSTR_Config), MP_ROM_PTR(&mod_TrezorConfig_Config_type) },
STATIC const mp_rom_map_elem_t mp_module_trezorconfig_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorconfig) },
{ MP_ROM_QSTR(MP_QSTR_Config), MP_ROM_PTR(&mod_trezorconfig_Config_type) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_TrezorConfig_globals, mp_module_TrezorConfig_globals_table);
STATIC MP_DEFINE_CONST_DICT(mp_module_trezorconfig_globals, mp_module_trezorconfig_globals_table);
const mp_obj_module_t mp_module_TrezorConfig = {
const mp_obj_module_t mp_module_trezorconfig = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&mp_module_TrezorConfig_globals,
.globals = (mp_obj_dict_t*)&mp_module_trezorconfig_globals,
};
#endif // MICROPY_PY_TREZORCONFIG

View File

@ -41,7 +41,7 @@ enum {
/// '''
/// 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) {
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) {
mp_arg_check_num(n_args, n_kw, 2, 3, false);
mp_obj_AES_t *o = m_new_obj(mp_obj_AES_t);
o->base.type = type;
@ -95,7 +95,7 @@ STATIC mp_obj_t mod_TrezorCrypto_AES_make_new(const mp_obj_type_t *type, size_t
/// '''
/// Update AES context with data.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_AES_update(mp_obj_t self, mp_obj_t data) {
STATIC mp_obj_t mod_trezorcrypto_AES_update(mp_obj_t self, mp_obj_t data) {
mp_buffer_info_t buf;
mp_get_buffer_raise(data, &buf, MP_BUFFER_READ);
vstr_t vstr;
@ -141,18 +141,18 @@ STATIC mp_obj_t mod_TrezorCrypto_AES_update(mp_obj_t self, mp_obj_t data) {
}
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_AES_update_obj, mod_TrezorCrypto_AES_update);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AES_update_obj, mod_trezorcrypto_AES_update);
STATIC mp_obj_t mod_TrezorCrypto_AES___del__(mp_obj_t self) {
STATIC mp_obj_t mod_trezorcrypto_AES___del__(mp_obj_t self) {
mp_obj_AES_t *o = MP_OBJ_TO_PTR(self);
memset(&(o->ctx), 0, sizeof(aes_encrypt_ctx));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_AES___del___obj, mod_TrezorCrypto_AES___del__);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_AES___del___obj, mod_trezorcrypto_AES___del__);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_AES_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_TrezorCrypto_AES_update_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_TrezorCrypto_AES___del___obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_AES_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_AES_update_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_trezorcrypto_AES___del___obj) },
{ MP_ROM_QSTR(MP_QSTR_ECB), MP_OBJ_NEW_SMALL_INT(ECB) },
{ MP_ROM_QSTR(MP_QSTR_CBC), MP_OBJ_NEW_SMALL_INT(CBC) },
{ MP_ROM_QSTR(MP_QSTR_CFB), MP_OBJ_NEW_SMALL_INT(CFB) },
@ -161,11 +161,11 @@ STATIC const mp_rom_map_elem_t mod_TrezorCrypto_AES_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_Encrypt), MP_OBJ_NEW_SMALL_INT(Encrypt) },
{ MP_ROM_QSTR(MP_QSTR_Decrypt), MP_OBJ_NEW_SMALL_INT(Decrypt) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_AES_locals_dict, mod_TrezorCrypto_AES_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_AES_locals_dict, mod_trezorcrypto_AES_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_AES_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_AES_type = {
{ &mp_type_type },
.name = MP_QSTR_AES,
.make_new = mod_TrezorCrypto_AES_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_AES_locals_dict,
.make_new = mod_trezorcrypto_AES_make_new,
.locals_dict = (void*)&mod_trezorcrypto_AES_locals_dict,
};

View File

@ -19,7 +19,7 @@ typedef struct _mp_obj_HDNode_t {
HDNode hdnode;
} mp_obj_HDNode_t;
STATIC const mp_obj_type_t mod_TrezorCrypto_HDNode_type;
STATIC const mp_obj_type_t mod_trezorcrypto_HDNode_type;
#define XPUB_MAXLEN 128
#define ADDRESS_MAXLEN 36
@ -28,7 +28,7 @@ STATIC const mp_obj_type_t mod_TrezorCrypto_HDNode_type;
/// '''
/// Derive a BIP0032 child node in place.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_HDNode_derive(mp_obj_t self, mp_obj_t index) {
STATIC mp_obj_t mod_trezorcrypto_HDNode_derive(mp_obj_t self, mp_obj_t index) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
uint32_t i = mp_obj_get_int_truncated(index);
uint32_t fp = hdnode_fingerprint(&o->hdnode);
@ -41,13 +41,13 @@ STATIC mp_obj_t mod_TrezorCrypto_HDNode_derive(mp_obj_t self, mp_obj_t index) {
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_HDNode_derive_obj, mod_TrezorCrypto_HDNode_derive);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_derive_obj, mod_trezorcrypto_HDNode_derive);
/// 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) {
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);
// get path objects and length
@ -77,7 +77,7 @@ STATIC mp_obj_t mod_TrezorCrypto_HDNode_derive_path(mp_obj_t self, mp_obj_t path
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_HDNode_derive_path_obj, mod_TrezorCrypto_HDNode_derive_path);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_derive_path_obj, mod_trezorcrypto_HDNode_derive_path);
STATIC mp_obj_t serialize_public_private(mp_obj_t self, bool use_public, uint32_t version) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
@ -104,102 +104,102 @@ STATIC mp_obj_t serialize_public_private(mp_obj_t self, bool use_public, uint32_
/// '''
/// 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) {
STATIC mp_obj_t mod_trezorcrypto_HDNode_serialize_public(mp_obj_t self, mp_obj_t version) {
uint32_t ver = mp_obj_get_int_truncated(version);
return serialize_public_private(self, true, ver);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_HDNode_serialize_public_obj, mod_TrezorCrypto_HDNode_serialize_public);
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) {
STATIC mp_obj_t mod_trezorcrypto_HDNode_serialize_private(mp_obj_t self, mp_obj_t version) {
uint32_t ver = mp_obj_get_int_truncated(version);
return serialize_public_private(self, false, ver);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_HDNode_serialize_private_obj, mod_TrezorCrypto_HDNode_serialize_private);
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) {
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);
copy->base.type = &mod_TrezorCrypto_HDNode_type;
copy->base.type = &mod_trezorcrypto_HDNode_type;
copy->hdnode = o->hdnode;
copy->fingerprint = o->fingerprint;
return MP_OBJ_FROM_PTR(copy);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_HDNode_clone_obj, mod_TrezorCrypto_HDNode_clone);
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) {
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);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_HDNode_depth_obj, mod_TrezorCrypto_HDNode_depth);
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) {
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);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_HDNode_fingerprint_obj, mod_TrezorCrypto_HDNode_fingerprint);
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) {
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);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_HDNode_child_num_obj, mod_TrezorCrypto_HDNode_child_num);
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) {
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_str_of_type(&mp_type_bytes, o->hdnode.chain_code, sizeof(o->hdnode.chain_code));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_HDNode_chain_code_obj, mod_TrezorCrypto_HDNode_chain_code);
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) {
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_str_of_type(&mp_type_bytes, o->hdnode.private_key, sizeof(o->hdnode.private_key));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_HDNode_private_key_obj, mod_TrezorCrypto_HDNode_private_key);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_private_key_obj, mod_trezorcrypto_HDNode_private_key);
/// 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) {
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);
return mp_obj_new_str_of_type(&mp_type_bytes, o->hdnode.public_key, sizeof(o->hdnode.public_key));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_HDNode_public_key_obj, mod_TrezorCrypto_HDNode_public_key);
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) {
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);
uint32_t v = mp_obj_get_int_truncated(version);
@ -210,29 +210,29 @@ STATIC mp_obj_t mod_TrezorCrypto_HDNode_address(mp_obj_t self, mp_obj_t version)
vstr.len = strlen(vstr.buf);
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_HDNode_address_obj, mod_TrezorCrypto_HDNode_address);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_address_obj, mod_trezorcrypto_HDNode_address);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_HDNode_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_derive), MP_ROM_PTR(&mod_TrezorCrypto_HDNode_derive_obj) },
{ MP_ROM_QSTR(MP_QSTR_derive_path), MP_ROM_PTR(&mod_TrezorCrypto_HDNode_derive_path_obj) },
{ MP_ROM_QSTR(MP_QSTR_serialize_private), MP_ROM_PTR(&mod_TrezorCrypto_HDNode_serialize_private_obj) },
{ MP_ROM_QSTR(MP_QSTR_serialize_public), MP_ROM_PTR(&mod_TrezorCrypto_HDNode_serialize_public_obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_HDNode_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_derive), MP_ROM_PTR(&mod_trezorcrypto_HDNode_derive_obj) },
{ MP_ROM_QSTR(MP_QSTR_derive_path), MP_ROM_PTR(&mod_trezorcrypto_HDNode_derive_path_obj) },
{ MP_ROM_QSTR(MP_QSTR_serialize_private), MP_ROM_PTR(&mod_trezorcrypto_HDNode_serialize_private_obj) },
{ MP_ROM_QSTR(MP_QSTR_serialize_public), MP_ROM_PTR(&mod_trezorcrypto_HDNode_serialize_public_obj) },
{ MP_ROM_QSTR(MP_QSTR_clone), MP_ROM_PTR(&mod_TrezorCrypto_HDNode_clone_obj) },
{ MP_ROM_QSTR(MP_QSTR_depth), MP_ROM_PTR(&mod_TrezorCrypto_HDNode_depth_obj) },
{ MP_ROM_QSTR(MP_QSTR_fingerprint), MP_ROM_PTR(&mod_TrezorCrypto_HDNode_fingerprint_obj) },
{ MP_ROM_QSTR(MP_QSTR_child_num), MP_ROM_PTR(&mod_TrezorCrypto_HDNode_child_num_obj) },
{ MP_ROM_QSTR(MP_QSTR_chain_code), MP_ROM_PTR(&mod_TrezorCrypto_HDNode_chain_code_obj) },
{ MP_ROM_QSTR(MP_QSTR_private_key), MP_ROM_PTR(&mod_TrezorCrypto_HDNode_private_key_obj) },
{ MP_ROM_QSTR(MP_QSTR_public_key), MP_ROM_PTR(&mod_TrezorCrypto_HDNode_public_key_obj) },
{ MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&mod_TrezorCrypto_HDNode_address_obj) },
{ MP_ROM_QSTR(MP_QSTR_clone), MP_ROM_PTR(&mod_trezorcrypto_HDNode_clone_obj) },
{ MP_ROM_QSTR(MP_QSTR_depth), MP_ROM_PTR(&mod_trezorcrypto_HDNode_depth_obj) },
{ MP_ROM_QSTR(MP_QSTR_fingerprint), MP_ROM_PTR(&mod_trezorcrypto_HDNode_fingerprint_obj) },
{ MP_ROM_QSTR(MP_QSTR_child_num), MP_ROM_PTR(&mod_trezorcrypto_HDNode_child_num_obj) },
{ MP_ROM_QSTR(MP_QSTR_chain_code), MP_ROM_PTR(&mod_trezorcrypto_HDNode_chain_code_obj) },
{ MP_ROM_QSTR(MP_QSTR_private_key), MP_ROM_PTR(&mod_trezorcrypto_HDNode_private_key_obj) },
{ MP_ROM_QSTR(MP_QSTR_public_key), MP_ROM_PTR(&mod_trezorcrypto_HDNode_public_key_obj) },
{ MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&mod_trezorcrypto_HDNode_address_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_HDNode_locals_dict, mod_TrezorCrypto_HDNode_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_HDNode_locals_dict, mod_trezorcrypto_HDNode_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_HDNode_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_HDNode_type = {
{ &mp_type_type },
.name = MP_QSTR_HDNode,
.locals_dict = (void*)&mod_TrezorCrypto_HDNode_locals_dict,
.locals_dict = (void*)&mod_trezorcrypto_HDNode_locals_dict,
};
/// class Bip32:
@ -245,7 +245,7 @@ typedef struct _mp_obj_Bip32_t {
/// def __init__(self):
/// '''
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Bip32_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezorcrypto_Bip32_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
mp_obj_Bip32_t *o = m_new_obj(mp_obj_Bip32_t);
o->base.type = type;
@ -256,7 +256,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip32_make_new(const mp_obj_type_t *type, size_
/// '''
/// Construct a BIP0032 HD node from a base58-serialized value.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Bip32_deserialize(size_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezorcrypto_Bip32_deserialize(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t value;
mp_get_buffer_raise(args[1], &value, MP_BUFFER_READ);
if (value.len == 0) {
@ -271,18 +271,18 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip32_deserialize(size_t n_args, const mp_obj_t
}
mp_obj_HDNode_t *o = m_new_obj(mp_obj_HDNode_t);
o->base.type = &mod_TrezorCrypto_HDNode_type;
o->base.type = &mod_trezorcrypto_HDNode_type;
o->hdnode = hdnode;
o->fingerprint = fingerprint;
return MP_OBJ_FROM_PTR(o);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Bip32_deserialize_obj, 4, 4, mod_TrezorCrypto_Bip32_deserialize);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_Bip32_deserialize_obj, 4, 4, mod_trezorcrypto_Bip32_deserialize);
/// def from_seed(self, 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 self, mp_obj_t seed, mp_obj_t curve_name) {
STATIC mp_obj_t mod_trezorcrypto_Bip32_from_seed(mp_obj_t self, mp_obj_t seed, mp_obj_t curve_name) {
mp_buffer_info_t seedb;
mp_get_buffer_raise(seed, &seedb, MP_BUFFER_READ);
if (seedb.len == 0) {
@ -298,21 +298,21 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip32_from_seed(mp_obj_t self, mp_obj_t seed, m
mp_raise_ValueError("Failed to derive the root node");
}
mp_obj_HDNode_t *o = m_new_obj(mp_obj_HDNode_t);
o->base.type = &mod_TrezorCrypto_HDNode_type;
o->base.type = &mod_trezorcrypto_HDNode_type;
o->hdnode = hdnode;
return MP_OBJ_FROM_PTR(o);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Bip32_from_seed_obj, mod_TrezorCrypto_Bip32_from_seed);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_Bip32_from_seed_obj, mod_trezorcrypto_Bip32_from_seed);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_Bip32_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_deserialize), MP_ROM_PTR(&mod_TrezorCrypto_Bip32_deserialize_obj) },
{ MP_ROM_QSTR(MP_QSTR_from_seed), MP_ROM_PTR(&mod_TrezorCrypto_Bip32_from_seed_obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_Bip32_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_deserialize), MP_ROM_PTR(&mod_trezorcrypto_Bip32_deserialize_obj) },
{ MP_ROM_QSTR(MP_QSTR_from_seed), MP_ROM_PTR(&mod_trezorcrypto_Bip32_from_seed_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_Bip32_locals_dict, mod_TrezorCrypto_Bip32_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Bip32_locals_dict, mod_trezorcrypto_Bip32_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_Bip32_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_Bip32_type = {
{ &mp_type_type },
.name = MP_QSTR_Bip32,
.make_new = mod_TrezorCrypto_Bip32_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_Bip32_locals_dict,
.make_new = mod_trezorcrypto_Bip32_make_new,
.locals_dict = (void*)&mod_trezorcrypto_Bip32_locals_dict,
};

View File

@ -19,7 +19,7 @@ typedef struct _mp_obj_Bip39_t {
/// def __init__(self):
/// '''
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Bip39_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezorcrypto_Bip39_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
mp_obj_Bip39_t *o = m_new_obj(mp_obj_Bip39_t);
o->base.type = type;
@ -30,7 +30,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip39_make_new(const mp_obj_type_t *type, size_
/// '''
/// Return the first word from the wordlist starting with prefix.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Bip39_find_word(mp_obj_t self, mp_obj_t prefix)
STATIC mp_obj_t mod_trezorcrypto_Bip39_find_word(mp_obj_t self, mp_obj_t prefix)
{
mp_buffer_info_t pfx;
mp_get_buffer_raise(prefix, &pfx, MP_BUFFER_READ);
@ -44,14 +44,14 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip39_find_word(mp_obj_t self, mp_obj_t prefix)
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Bip39_find_word_obj, mod_TrezorCrypto_Bip39_find_word);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Bip39_find_word_obj, mod_trezorcrypto_Bip39_find_word);
/// def complete_word(self, 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 self, mp_obj_t prefix)
STATIC mp_obj_t mod_trezorcrypto_Bip39_complete_word(mp_obj_t self, mp_obj_t prefix)
{
mp_buffer_info_t pfx;
mp_get_buffer_raise(prefix, &pfx, MP_BUFFER_READ);
@ -71,13 +71,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip39_complete_word(mp_obj_t self, mp_obj_t pre
}
return mp_obj_new_int(res);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Bip39_complete_word_obj, mod_TrezorCrypto_Bip39_complete_word);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Bip39_complete_word_obj, mod_trezorcrypto_Bip39_complete_word);
/// def generate(self, 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 self, mp_obj_t strength) {
STATIC mp_obj_t mod_trezorcrypto_Bip39_generate(mp_obj_t self, mp_obj_t strength) {
int bits = mp_obj_get_int(strength);
if (bits % 32 || bits < 128 || bits > 256) {
mp_raise_ValueError("Invalid bit strength (only 128, 160, 192, 224 and 256 values are allowed)");
@ -85,13 +85,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip39_generate(mp_obj_t self, mp_obj_t strength
const char *mnemo = mnemonic_generate(bits);
return mp_obj_new_str_of_type(&mp_type_str, (uint8_t *)mnemo, strlen(mnemo));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Bip39_generate_obj, mod_TrezorCrypto_Bip39_generate);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Bip39_generate_obj, mod_trezorcrypto_Bip39_generate);
/// def from_data(self, 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 self, mp_obj_t data) {
STATIC mp_obj_t mod_trezorcrypto_Bip39_from_data(mp_obj_t self, mp_obj_t data) {
mp_buffer_info_t bin;
mp_get_buffer_raise(data, &bin, MP_BUFFER_READ);
if (bin.len % 4 || bin.len < 16 || bin.len > 32) {
@ -100,24 +100,24 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip39_from_data(mp_obj_t self, mp_obj_t data) {
const char *mnemo = mnemonic_from_data(bin.buf, bin.len);
return mp_obj_new_str_of_type(&mp_type_str, (uint8_t *)mnemo, strlen(mnemo));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Bip39_from_data_obj, mod_TrezorCrypto_Bip39_from_data);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Bip39_from_data_obj, mod_trezorcrypto_Bip39_from_data);
/// def check(self, mnemonic: str) -> bool:
/// '''
/// Check whether given mnemonic is valid.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Bip39_check(mp_obj_t self, mp_obj_t mnemonic) {
STATIC mp_obj_t mod_trezorcrypto_Bip39_check(mp_obj_t self, mp_obj_t mnemonic) {
mp_buffer_info_t text;
mp_get_buffer_raise(mnemonic, &text, MP_BUFFER_READ);
return (text.len > 0 && mnemonic_check(text.buf)) ? mp_const_true : mp_const_false;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Bip39_check_obj, mod_TrezorCrypto_Bip39_check);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Bip39_check_obj, mod_trezorcrypto_Bip39_check);
/// def seed(self, mnemonic: str, passphrase: str) -> bytes:
/// '''
/// Generate seed from mnemonic and passphrase.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Bip39_seed(mp_obj_t self, mp_obj_t mnemonic, mp_obj_t passphrase) {
STATIC mp_obj_t mod_trezorcrypto_Bip39_seed(mp_obj_t self, mp_obj_t mnemonic, mp_obj_t passphrase) {
mp_buffer_info_t mnemo;
mp_buffer_info_t phrase;
mp_get_buffer_raise(mnemonic, &mnemo, MP_BUFFER_READ);
@ -129,21 +129,21 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip39_seed(mp_obj_t self, mp_obj_t mnemonic, mp
mnemonic_to_seed(pmnemonic, ppassphrase, (uint8_t *)vstr.buf, NULL); // no callback for now
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Bip39_seed_obj, mod_TrezorCrypto_Bip39_seed);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_Bip39_seed_obj, mod_trezorcrypto_Bip39_seed);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_Bip39_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_find_word), MP_ROM_PTR(&mod_TrezorCrypto_Bip39_find_word_obj) },
{ MP_ROM_QSTR(MP_QSTR_complete_word), MP_ROM_PTR(&mod_TrezorCrypto_Bip39_complete_word_obj) },
{ MP_ROM_QSTR(MP_QSTR_generate), MP_ROM_PTR(&mod_TrezorCrypto_Bip39_generate_obj) },
{ MP_ROM_QSTR(MP_QSTR_from_data), MP_ROM_PTR(&mod_TrezorCrypto_Bip39_from_data_obj) },
{ MP_ROM_QSTR(MP_QSTR_check), MP_ROM_PTR(&mod_TrezorCrypto_Bip39_check_obj) },
{ MP_ROM_QSTR(MP_QSTR_seed), MP_ROM_PTR(&mod_TrezorCrypto_Bip39_seed_obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_Bip39_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_find_word), MP_ROM_PTR(&mod_trezorcrypto_Bip39_find_word_obj) },
{ MP_ROM_QSTR(MP_QSTR_complete_word), MP_ROM_PTR(&mod_trezorcrypto_Bip39_complete_word_obj) },
{ MP_ROM_QSTR(MP_QSTR_generate), MP_ROM_PTR(&mod_trezorcrypto_Bip39_generate_obj) },
{ MP_ROM_QSTR(MP_QSTR_from_data), MP_ROM_PTR(&mod_trezorcrypto_Bip39_from_data_obj) },
{ MP_ROM_QSTR(MP_QSTR_check), MP_ROM_PTR(&mod_trezorcrypto_Bip39_check_obj) },
{ MP_ROM_QSTR(MP_QSTR_seed), MP_ROM_PTR(&mod_trezorcrypto_Bip39_seed_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_Bip39_locals_dict, mod_TrezorCrypto_Bip39_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Bip39_locals_dict, mod_trezorcrypto_Bip39_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_Bip39_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_Bip39_type = {
{ &mp_type_type },
.name = MP_QSTR_Bip39,
.make_new = mod_TrezorCrypto_Bip39_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_Bip39_locals_dict,
.make_new = mod_trezorcrypto_Bip39_make_new,
.locals_dict = (void*)&mod_trezorcrypto_Bip39_locals_dict,
};

View File

@ -18,13 +18,13 @@ typedef struct _mp_obj_Blake2b_t {
BLAKE2B_CTX ctx;
} mp_obj_Blake2b_t;
STATIC mp_obj_t mod_TrezorCrypto_Blake2b_update(mp_obj_t self, mp_obj_t data);
STATIC mp_obj_t mod_trezorcrypto_Blake2b_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None, key: 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) {
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) {
mp_arg_check_num(n_args, n_kw, 0, 2, false);
mp_obj_Blake2b_t *o = m_new_obj(mp_obj_Blake2b_t);
o->base.type = type;
@ -38,7 +38,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Blake2b_make_new(const mp_obj_type_t *type, siz
}
// constructor called with data argument set
if (n_args >= 1) {
mod_TrezorCrypto_Blake2b_update(MP_OBJ_FROM_PTR(o), args[0]);
mod_trezorcrypto_Blake2b_update(MP_OBJ_FROM_PTR(o), args[0]);
}
return MP_OBJ_FROM_PTR(o);
}
@ -47,7 +47,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Blake2b_make_new(const mp_obj_type_t *type, siz
/// '''
/// Update the hash context with hashed data.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Blake2b_update(mp_obj_t self, mp_obj_t data) {
STATIC mp_obj_t mod_trezorcrypto_Blake2b_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Blake2b_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t msg;
mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
@ -56,13 +56,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Blake2b_update(mp_obj_t self, mp_obj_t data) {
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Blake2b_update_obj, mod_TrezorCrypto_Blake2b_update);
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) {
STATIC mp_obj_t mod_trezorcrypto_Blake2b_digest(mp_obj_t self) {
mp_obj_Blake2b_t *o = MP_OBJ_TO_PTR(self);
vstr_t vstr;
vstr_init_len(&vstr, BLAKE2B_DIGEST_LENGTH);
@ -72,27 +72,27 @@ STATIC mp_obj_t mod_TrezorCrypto_Blake2b_digest(mp_obj_t self) {
memset(&ctx, 0, sizeof(BLAKE2B_CTX));
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Blake2b_digest_obj, mod_TrezorCrypto_Blake2b_digest);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake2b_digest_obj, mod_trezorcrypto_Blake2b_digest);
STATIC mp_obj_t mod_TrezorCrypto_Blake2b___del__(mp_obj_t self) {
STATIC mp_obj_t mod_trezorcrypto_Blake2b___del__(mp_obj_t self) {
mp_obj_Blake2b_t *o = MP_OBJ_TO_PTR(self);
memset(&(o->ctx), 0, sizeof(BLAKE2B_CTX));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Blake2b___del___obj, mod_TrezorCrypto_Blake2b___del__);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake2b___del___obj, mod_trezorcrypto_Blake2b___del__);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_Blake2b_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_TrezorCrypto_Blake2b_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&mod_TrezorCrypto_Blake2b_digest_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_TrezorCrypto_Blake2b___del___obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_Blake2b_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Blake2b_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&mod_trezorcrypto_Blake2b_digest_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_trezorcrypto_Blake2b___del___obj) },
{ MP_ROM_QSTR(MP_QSTR_block_size), MP_OBJ_NEW_SMALL_INT(BLAKE2B_BLOCK_LENGTH) },
{ MP_ROM_QSTR(MP_QSTR_digest_size), MP_OBJ_NEW_SMALL_INT(BLAKE2B_DIGEST_LENGTH) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_Blake2b_locals_dict, mod_TrezorCrypto_Blake2b_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Blake2b_locals_dict, mod_trezorcrypto_Blake2b_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_Blake2b_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_Blake2b_type = {
{ &mp_type_type },
.name = MP_QSTR_Blake2b,
.make_new = mod_TrezorCrypto_Blake2b_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_Blake2b_locals_dict,
.make_new = mod_trezorcrypto_Blake2b_make_new,
.locals_dict = (void*)&mod_trezorcrypto_Blake2b_locals_dict,
};

View File

@ -18,13 +18,13 @@ typedef struct _mp_obj_Blake2s_t {
BLAKE2S_CTX ctx;
} mp_obj_Blake2s_t;
STATIC mp_obj_t mod_TrezorCrypto_Blake2s_update(mp_obj_t self, mp_obj_t data);
STATIC mp_obj_t mod_trezorcrypto_Blake2s_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None, key: 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) {
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) {
mp_arg_check_num(n_args, n_kw, 0, 2, false);
mp_obj_Blake2s_t *o = m_new_obj(mp_obj_Blake2s_t);
o->base.type = type;
@ -38,7 +38,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Blake2s_make_new(const mp_obj_type_t *type, siz
}
// constructor called with data argument set
if (n_args >= 1) {
mod_TrezorCrypto_Blake2s_update(MP_OBJ_FROM_PTR(o), args[0]);
mod_trezorcrypto_Blake2s_update(MP_OBJ_FROM_PTR(o), args[0]);
}
return MP_OBJ_FROM_PTR(o);
}
@ -47,7 +47,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Blake2s_make_new(const mp_obj_type_t *type, siz
/// '''
/// Update the hash context with hashed data.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Blake2s_update(mp_obj_t self, mp_obj_t data) {
STATIC mp_obj_t mod_trezorcrypto_Blake2s_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Blake2s_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t msg;
mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
@ -56,13 +56,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Blake2s_update(mp_obj_t self, mp_obj_t data) {
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Blake2s_update_obj, mod_TrezorCrypto_Blake2s_update);
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) {
STATIC mp_obj_t mod_trezorcrypto_Blake2s_digest(mp_obj_t self) {
mp_obj_Blake2s_t *o = MP_OBJ_TO_PTR(self);
vstr_t vstr;
vstr_init_len(&vstr, BLAKE2S_DIGEST_LENGTH);
@ -72,27 +72,27 @@ STATIC mp_obj_t mod_TrezorCrypto_Blake2s_digest(mp_obj_t self) {
memset(&ctx, 0, sizeof(BLAKE2S_CTX));
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Blake2s_digest_obj, mod_TrezorCrypto_Blake2s_digest);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake2s_digest_obj, mod_trezorcrypto_Blake2s_digest);
STATIC mp_obj_t mod_TrezorCrypto_Blake2s___del__(mp_obj_t self) {
STATIC mp_obj_t mod_trezorcrypto_Blake2s___del__(mp_obj_t self) {
mp_obj_Blake2s_t *o = MP_OBJ_TO_PTR(self);
memset(&(o->ctx), 0, sizeof(BLAKE2S_CTX));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Blake2s___del___obj, mod_TrezorCrypto_Blake2s___del__);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake2s___del___obj, mod_trezorcrypto_Blake2s___del__);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_Blake2s_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_TrezorCrypto_Blake2s_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&mod_TrezorCrypto_Blake2s_digest_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_TrezorCrypto_Blake2s___del___obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_Blake2s_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Blake2s_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&mod_trezorcrypto_Blake2s_digest_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_trezorcrypto_Blake2s___del___obj) },
{ MP_ROM_QSTR(MP_QSTR_block_size), MP_OBJ_NEW_SMALL_INT(BLAKE2S_BLOCK_LENGTH) },
{ MP_ROM_QSTR(MP_QSTR_digest_size), MP_OBJ_NEW_SMALL_INT(BLAKE2S_DIGEST_LENGTH) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_Blake2s_locals_dict, mod_TrezorCrypto_Blake2s_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Blake2s_locals_dict, mod_trezorcrypto_Blake2s_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_Blake2s_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_Blake2s_type = {
{ &mp_type_type },
.name = MP_QSTR_Blake2s,
.make_new = mod_TrezorCrypto_Blake2s_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_Blake2s_locals_dict,
.make_new = mod_trezorcrypto_Blake2s_make_new,
.locals_dict = (void*)&mod_trezorcrypto_Blake2s_locals_dict,
};

View File

@ -21,7 +21,7 @@ typedef struct _mp_obj_Curve25519_t {
/// def __init__(self) -> None:
/// '''
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Curve25519_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezorcrypto_Curve25519_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
mp_obj_Curve25519_t *o = m_new_obj(mp_obj_Curve25519_t);
o->base.type = type;
@ -32,7 +32,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Curve25519_make_new(const mp_obj_type_t *type,
/// '''
/// Generate secret key.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Curve25519_generate_secret(mp_obj_t self) {
STATIC mp_obj_t mod_trezorcrypto_Curve25519_generate_secret(mp_obj_t self) {
vstr_t vstr;
vstr_init_len(&vstr, 32);
random_buffer((uint8_t *)vstr.buf, 32);
@ -42,13 +42,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Curve25519_generate_secret(mp_obj_t self) {
vstr.buf[31] |= 64;
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Curve25519_generate_secret_obj, mod_TrezorCrypto_Curve25519_generate_secret);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Curve25519_generate_secret_obj, mod_trezorcrypto_Curve25519_generate_secret);
/// def publickey(self, secret_key: bytes) -> bytes:
/// '''
/// Computes public key from secret key.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Curve25519_publickey(mp_obj_t self, mp_obj_t secret_key) {
STATIC mp_obj_t mod_trezorcrypto_Curve25519_publickey(mp_obj_t self, mp_obj_t secret_key) {
mp_buffer_info_t sk;
mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
if (sk.len != 32) {
@ -59,14 +59,14 @@ STATIC mp_obj_t mod_TrezorCrypto_Curve25519_publickey(mp_obj_t self, mp_obj_t se
curve25519_scalarmult_basepoint((uint8_t *)vstr.buf, (const uint8_t *)sk.buf);
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Curve25519_publickey_obj, mod_TrezorCrypto_Curve25519_publickey);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Curve25519_publickey_obj, mod_trezorcrypto_Curve25519_publickey);
/// def multiply(self, 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 self, mp_obj_t secret_key, mp_obj_t public_key) {
STATIC mp_obj_t mod_trezorcrypto_Curve25519_multiply(mp_obj_t self, mp_obj_t secret_key, mp_obj_t public_key) {
mp_buffer_info_t sk, pk;
mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
mp_get_buffer_raise(public_key, &pk, MP_BUFFER_READ);
@ -81,18 +81,18 @@ STATIC mp_obj_t mod_TrezorCrypto_Curve25519_multiply(mp_obj_t self, mp_obj_t sec
curve25519_scalarmult((uint8_t *)vstr.buf, (const uint8_t *)sk.buf, (const uint8_t *)pk.buf);
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Curve25519_multiply_obj, mod_TrezorCrypto_Curve25519_multiply);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_Curve25519_multiply_obj, mod_trezorcrypto_Curve25519_multiply);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_Curve25519_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_generate_secret), MP_ROM_PTR(&mod_TrezorCrypto_Curve25519_generate_secret_obj) },
{ MP_ROM_QSTR(MP_QSTR_publickey), MP_ROM_PTR(&mod_TrezorCrypto_Curve25519_publickey_obj) },
{ MP_ROM_QSTR(MP_QSTR_multiply), MP_ROM_PTR(&mod_TrezorCrypto_Curve25519_multiply_obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_Curve25519_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_generate_secret), MP_ROM_PTR(&mod_trezorcrypto_Curve25519_generate_secret_obj) },
{ MP_ROM_QSTR(MP_QSTR_publickey), MP_ROM_PTR(&mod_trezorcrypto_Curve25519_publickey_obj) },
{ MP_ROM_QSTR(MP_QSTR_multiply), MP_ROM_PTR(&mod_trezorcrypto_Curve25519_multiply_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_Curve25519_locals_dict, mod_TrezorCrypto_Curve25519_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Curve25519_locals_dict, mod_trezorcrypto_Curve25519_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_Curve25519_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_Curve25519_type = {
{ &mp_type_type },
.name = MP_QSTR_Curve25519,
.make_new = mod_TrezorCrypto_Curve25519_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_Curve25519_locals_dict,
.make_new = mod_trezorcrypto_Curve25519_make_new,
.locals_dict = (void*)&mod_trezorcrypto_Curve25519_locals_dict,
};

View File

@ -21,7 +21,7 @@ typedef struct _mp_obj_Ed25519_t {
/// def __init__(self) -> None:
/// '''
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Ed25519_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezorcrypto_Ed25519_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
mp_obj_Ed25519_t *o = m_new_obj(mp_obj_Ed25519_t);
o->base.type = type;
@ -32,7 +32,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_make_new(const mp_obj_type_t *type, siz
/// '''
/// Generate secret key.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Ed25519_generate_secret(mp_obj_t self) {
STATIC mp_obj_t mod_trezorcrypto_Ed25519_generate_secret(mp_obj_t self) {
vstr_t vstr;
vstr_init_len(&vstr, 32);
random_buffer((uint8_t *)vstr.buf, 32);
@ -42,13 +42,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_generate_secret(mp_obj_t self) {
vstr.buf[31] |= 64;
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Ed25519_generate_secret_obj, mod_TrezorCrypto_Ed25519_generate_secret);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Ed25519_generate_secret_obj, mod_trezorcrypto_Ed25519_generate_secret);
/// def publickey(self, secret_key: bytes) -> bytes:
/// '''
/// Computes public key from secret key.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Ed25519_publickey(mp_obj_t self, mp_obj_t secret_key) {
STATIC mp_obj_t mod_trezorcrypto_Ed25519_publickey(mp_obj_t self, mp_obj_t secret_key) {
mp_buffer_info_t sk;
mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
if (sk.len != 32) {
@ -59,13 +59,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_publickey(mp_obj_t self, mp_obj_t secre
ed25519_publickey(*(const ed25519_secret_key *)sk.buf, *(ed25519_public_key *)vstr.buf);
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Ed25519_publickey_obj, mod_TrezorCrypto_Ed25519_publickey);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Ed25519_publickey_obj, mod_trezorcrypto_Ed25519_publickey);
/// def sign(self, secret_key: bytes, message: bytes) -> bytes:
/// '''
/// Uses secret key to produce the signature of message.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Ed25519_sign(mp_obj_t self, mp_obj_t secret_key, mp_obj_t message) {
STATIC mp_obj_t mod_trezorcrypto_Ed25519_sign(mp_obj_t self, mp_obj_t secret_key, mp_obj_t message) {
mp_buffer_info_t sk, msg;
mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
mp_get_buffer_raise(message, &msg, MP_BUFFER_READ);
@ -82,14 +82,14 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_sign(mp_obj_t self, mp_obj_t secret_key
ed25519_sign(msg.buf, msg.len, *(const ed25519_secret_key *)sk.buf, pk, *(ed25519_signature *)vstr.buf);
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Ed25519_sign_obj, mod_TrezorCrypto_Ed25519_sign);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_Ed25519_sign_obj, mod_trezorcrypto_Ed25519_sign);
/// def verify(self, 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(size_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezorcrypto_Ed25519_verify(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t pk, sig, msg;
mp_get_buffer_raise(args[1], &pk, MP_BUFFER_READ);
mp_get_buffer_raise(args[2], &sig, MP_BUFFER_READ);
@ -105,13 +105,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_verify(size_t n_args, const mp_obj_t *a
}
return (0 == ed25519_sign_open(msg.buf, msg.len, *(const ed25519_public_key *)pk.buf, *(const ed25519_signature *)sig.buf)) ? mp_const_true : mp_const_false;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Ed25519_verify_obj, 4, 4, mod_TrezorCrypto_Ed25519_verify);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_Ed25519_verify_obj, 4, 4, mod_trezorcrypto_Ed25519_verify);
/// def cosi_combine_publickeys(self, 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 self, mp_obj_t public_keys) {
STATIC mp_obj_t mod_trezorcrypto_Ed25519_cosi_combine_publickeys(mp_obj_t self, mp_obj_t public_keys) {
size_t pklen;
mp_obj_t *pkitems;
mp_obj_get_array(public_keys, &pklen, &pkitems);
@ -134,13 +134,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_cosi_combine_publickeys(mp_obj_t self,
}
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Ed25519_cosi_combine_publickeys_obj, mod_TrezorCrypto_Ed25519_cosi_combine_publickeys);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Ed25519_cosi_combine_publickeys_obj, mod_trezorcrypto_Ed25519_cosi_combine_publickeys);
/// def cosi_combine_signatures(self, 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 self, mp_obj_t R, mp_obj_t signatures) {
STATIC mp_obj_t mod_trezorcrypto_Ed25519_cosi_combine_signatures(mp_obj_t self, mp_obj_t R, mp_obj_t signatures) {
mp_buffer_info_t sigR;
mp_get_buffer_raise(R, &sigR, MP_BUFFER_READ);
if (sigR.len != 32) {
@ -166,13 +166,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_cosi_combine_signatures(mp_obj_t self,
ed25519_cosi_combine_signatures(*(ed25519_signature *)vstr.buf, *(const ed25519_public_key *)sigR.buf, sigs, siglen);
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Ed25519_cosi_combine_signatures_obj, mod_TrezorCrypto_Ed25519_cosi_combine_signatures);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_Ed25519_cosi_combine_signatures_obj, mod_trezorcrypto_Ed25519_cosi_combine_signatures);
/// def cosi_sign(self, 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) {
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;
mp_get_buffer_raise(args[1], &sk, MP_BUFFER_READ);
mp_get_buffer_raise(args[2], &msg, MP_BUFFER_READ);
@ -196,22 +196,22 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_cosi_sign(size_t n_args, const mp_obj_t
ed25519_cosi_sign(msg.buf, msg.len, *(const ed25519_secret_key *)sk.buf, *(const ed25519_secret_key *)nonce.buf, *(const ed25519_public_key *)sigR.buf, *(const ed25519_secret_key *)pk.buf, *(ed25519_cosi_signature *)vstr.buf);
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Ed25519_cosi_sign_obj, 6, 6, mod_TrezorCrypto_Ed25519_cosi_sign);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_Ed25519_cosi_sign_obj, 6, 6, mod_trezorcrypto_Ed25519_cosi_sign);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_Ed25519_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_generate_secret), MP_ROM_PTR(&mod_TrezorCrypto_Ed25519_generate_secret_obj) },
{ MP_ROM_QSTR(MP_QSTR_publickey), MP_ROM_PTR(&mod_TrezorCrypto_Ed25519_publickey_obj) },
{ MP_ROM_QSTR(MP_QSTR_sign), MP_ROM_PTR(&mod_TrezorCrypto_Ed25519_sign_obj) },
{ MP_ROM_QSTR(MP_QSTR_verify), MP_ROM_PTR(&mod_TrezorCrypto_Ed25519_verify_obj) },
{ MP_ROM_QSTR(MP_QSTR_cosi_combine_publickeys), MP_ROM_PTR(&mod_TrezorCrypto_Ed25519_cosi_combine_publickeys_obj) },
{ MP_ROM_QSTR(MP_QSTR_cosi_combine_signatures), MP_ROM_PTR(&mod_TrezorCrypto_Ed25519_cosi_combine_signatures_obj) },
{ MP_ROM_QSTR(MP_QSTR_cosi_sign), MP_ROM_PTR(&mod_TrezorCrypto_Ed25519_cosi_sign_obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_Ed25519_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_generate_secret), MP_ROM_PTR(&mod_trezorcrypto_Ed25519_generate_secret_obj) },
{ MP_ROM_QSTR(MP_QSTR_publickey), MP_ROM_PTR(&mod_trezorcrypto_Ed25519_publickey_obj) },
{ MP_ROM_QSTR(MP_QSTR_sign), MP_ROM_PTR(&mod_trezorcrypto_Ed25519_sign_obj) },
{ MP_ROM_QSTR(MP_QSTR_verify), MP_ROM_PTR(&mod_trezorcrypto_Ed25519_verify_obj) },
{ MP_ROM_QSTR(MP_QSTR_cosi_combine_publickeys), MP_ROM_PTR(&mod_trezorcrypto_Ed25519_cosi_combine_publickeys_obj) },
{ MP_ROM_QSTR(MP_QSTR_cosi_combine_signatures), MP_ROM_PTR(&mod_trezorcrypto_Ed25519_cosi_combine_signatures_obj) },
{ MP_ROM_QSTR(MP_QSTR_cosi_sign), MP_ROM_PTR(&mod_trezorcrypto_Ed25519_cosi_sign_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_Ed25519_locals_dict, mod_TrezorCrypto_Ed25519_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Ed25519_locals_dict, mod_trezorcrypto_Ed25519_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_Ed25519_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_Ed25519_type = {
{ &mp_type_type },
.name = MP_QSTR_Ed25519,
.make_new = mod_TrezorCrypto_Ed25519_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_Ed25519_locals_dict,
.make_new = mod_trezorcrypto_Ed25519_make_new,
.locals_dict = (void*)&mod_trezorcrypto_Ed25519_locals_dict,
};

View File

@ -20,7 +20,7 @@ typedef struct _mp_obj_Nist256p1_t {
/// def __init__(self) -> None:
/// '''
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezorcrypto_Nist256p1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
mp_obj_Nist256p1_t *o = m_new_obj(mp_obj_Nist256p1_t);
o->base.type = type;
@ -31,7 +31,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_make_new(const mp_obj_type_t *type, s
/// '''
/// Generate secret key.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_generate_secret(mp_obj_t self) {
STATIC mp_obj_t mod_trezorcrypto_Nist256p1_generate_secret(mp_obj_t self) {
vstr_t vstr;
vstr_init_len(&vstr, 32);
for (;;) {
@ -43,13 +43,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_generate_secret(mp_obj_t self) {
}
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Nist256p1_generate_secret_obj, mod_TrezorCrypto_Nist256p1_generate_secret);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Nist256p1_generate_secret_obj, mod_trezorcrypto_Nist256p1_generate_secret);
/// def publickey(self, 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) {
STATIC mp_obj_t mod_trezorcrypto_Nist256p1_publickey(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t sk;
mp_get_buffer_raise(args[1], &sk, MP_BUFFER_READ);
if (sk.len != 32) {
@ -66,13 +66,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_publickey(size_t n_args, const mp_obj
}
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Nist256p1_publickey_obj, 2, 3, mod_TrezorCrypto_Nist256p1_publickey);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_Nist256p1_publickey_obj, 2, 3, mod_trezorcrypto_Nist256p1_publickey);
/// def sign(self, 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) {
STATIC mp_obj_t mod_trezorcrypto_Nist256p1_sign(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t sk, dig;
mp_get_buffer_raise(args[1], &sk, MP_BUFFER_READ);
mp_get_buffer_raise(args[2], &dig, MP_BUFFER_READ);
@ -92,14 +92,14 @@ STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_sign(size_t n_args, const mp_obj_t *a
vstr.buf[0] = 27 + pby + compressed * 4;
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Nist256p1_sign_obj, 3, 4, mod_TrezorCrypto_Nist256p1_sign);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_Nist256p1_sign_obj, 3, 4, mod_trezorcrypto_Nist256p1_sign);
/// def verify(self, 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(size_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezorcrypto_Nist256p1_verify(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t pk, sig, dig;
mp_get_buffer_raise(args[1], &pk, MP_BUFFER_READ);
mp_get_buffer_raise(args[2], &sig, MP_BUFFER_READ);
@ -116,14 +116,14 @@ STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_verify(size_t n_args, const mp_obj_t
}
return mp_obj_new_bool(0 == ecdsa_verify_digest(&nist256p1, (const uint8_t *)pk.buf, (const uint8_t *)sig.buf + offset, (const uint8_t *)dig.buf));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Nist256p1_verify_obj, 4, 4, mod_TrezorCrypto_Nist256p1_verify);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_Nist256p1_verify_obj, 4, 4, mod_trezorcrypto_Nist256p1_verify);
/// def verify_recover(self, 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.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_verify_recover(mp_obj_t self, mp_obj_t signature, mp_obj_t digest) {
STATIC mp_obj_t mod_trezorcrypto_Nist256p1_verify_recover(mp_obj_t self, mp_obj_t signature, mp_obj_t digest) {
mp_buffer_info_t sig, dig;
mp_get_buffer_raise(signature, &sig, MP_BUFFER_READ);
mp_get_buffer_raise(digest, &dig, MP_BUFFER_READ);
@ -151,14 +151,14 @@ STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_verify_recover(mp_obj_t self, mp_obj_
return mp_const_none;
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Nist256p1_verify_recover_obj, mod_TrezorCrypto_Nist256p1_verify_recover);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_Nist256p1_verify_recover_obj, mod_trezorcrypto_Nist256p1_verify_recover);
/// def multiply(self, 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 self, mp_obj_t secret_key, mp_obj_t public_key) {
STATIC mp_obj_t mod_trezorcrypto_Nist256p1_multiply(mp_obj_t self, mp_obj_t secret_key, mp_obj_t public_key) {
mp_buffer_info_t sk, pk;
mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
mp_get_buffer_raise(public_key, &pk, MP_BUFFER_READ);
@ -175,21 +175,21 @@ STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_multiply(mp_obj_t self, mp_obj_t secr
}
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Nist256p1_multiply_obj, mod_TrezorCrypto_Nist256p1_multiply);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_Nist256p1_multiply_obj, mod_trezorcrypto_Nist256p1_multiply);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_Nist256p1_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_generate_secret), MP_ROM_PTR(&mod_TrezorCrypto_Nist256p1_generate_secret_obj) },
{ MP_ROM_QSTR(MP_QSTR_publickey), MP_ROM_PTR(&mod_TrezorCrypto_Nist256p1_publickey_obj) },
{ MP_ROM_QSTR(MP_QSTR_sign), MP_ROM_PTR(&mod_TrezorCrypto_Nist256p1_sign_obj) },
{ MP_ROM_QSTR(MP_QSTR_verify), MP_ROM_PTR(&mod_TrezorCrypto_Nist256p1_verify_obj) },
{ MP_ROM_QSTR(MP_QSTR_verify_recover), MP_ROM_PTR(&mod_TrezorCrypto_Nist256p1_verify_recover_obj) },
{ MP_ROM_QSTR(MP_QSTR_multiply), MP_ROM_PTR(&mod_TrezorCrypto_Nist256p1_multiply_obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_Nist256p1_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_generate_secret), MP_ROM_PTR(&mod_trezorcrypto_Nist256p1_generate_secret_obj) },
{ MP_ROM_QSTR(MP_QSTR_publickey), MP_ROM_PTR(&mod_trezorcrypto_Nist256p1_publickey_obj) },
{ MP_ROM_QSTR(MP_QSTR_sign), MP_ROM_PTR(&mod_trezorcrypto_Nist256p1_sign_obj) },
{ MP_ROM_QSTR(MP_QSTR_verify), MP_ROM_PTR(&mod_trezorcrypto_Nist256p1_verify_obj) },
{ MP_ROM_QSTR(MP_QSTR_verify_recover), MP_ROM_PTR(&mod_trezorcrypto_Nist256p1_verify_recover_obj) },
{ MP_ROM_QSTR(MP_QSTR_multiply), MP_ROM_PTR(&mod_trezorcrypto_Nist256p1_multiply_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_Nist256p1_locals_dict, mod_TrezorCrypto_Nist256p1_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Nist256p1_locals_dict, mod_trezorcrypto_Nist256p1_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_Nist256p1_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_Nist256p1_type = {
{ &mp_type_type },
.name = MP_QSTR_Nist256p1,
.make_new = mod_TrezorCrypto_Nist256p1_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_Nist256p1_locals_dict,
.make_new = mod_trezorcrypto_Nist256p1_make_new,
.locals_dict = (void*)&mod_trezorcrypto_Nist256p1_locals_dict,
};

View File

@ -22,13 +22,13 @@ typedef struct _mp_obj_Pbkdf2_t {
int prf;
} mp_obj_Pbkdf2_t;
STATIC mp_obj_t mod_TrezorCrypto_Pbkdf2_update(mp_obj_t self, mp_obj_t data);
STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, prf: str, password: bytes, salt: bytes, iterations: int = None) -> 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) {
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) {
mp_arg_check_num(n_args, n_kw, 3, 4, false);
mp_obj_Pbkdf2_t *o = m_new_obj(mp_obj_Pbkdf2_t);
o->base.type = type;
@ -61,7 +61,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Pbkdf2_make_new(const mp_obj_type_t *type, size
}
// constructor called with iterations as fourth parameter
if (n_args > 3) {
mod_TrezorCrypto_Pbkdf2_update(MP_OBJ_FROM_PTR(o), args[3]);
mod_trezorcrypto_Pbkdf2_update(MP_OBJ_FROM_PTR(o), args[3]);
}
return MP_OBJ_FROM_PTR(o);
}
@ -70,7 +70,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Pbkdf2_make_new(const mp_obj_type_t *type, size
/// '''
/// Update a PBKDF2 context.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Pbkdf2_update(mp_obj_t self, mp_obj_t iterations) {
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);
uint32_t iter = mp_obj_get_int(iterations);
if (o->prf == 256) {
@ -81,13 +81,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Pbkdf2_update(mp_obj_t self, mp_obj_t iteration
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Pbkdf2_update_obj, mod_TrezorCrypto_Pbkdf2_update);
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) {
STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_key(mp_obj_t self) {
mp_obj_Pbkdf2_t *o = MP_OBJ_TO_PTR(self);
vstr_t vstr;
if (o->prf == 256) {
@ -106,26 +106,26 @@ STATIC mp_obj_t mod_TrezorCrypto_Pbkdf2_key(mp_obj_t self) {
}
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Pbkdf2_key_obj, mod_TrezorCrypto_Pbkdf2_key);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Pbkdf2_key_obj, mod_trezorcrypto_Pbkdf2_key);
STATIC mp_obj_t mod_TrezorCrypto_Pbkdf2___del__(mp_obj_t self) {
STATIC mp_obj_t mod_trezorcrypto_Pbkdf2___del__(mp_obj_t self) {
mp_obj_Pbkdf2_t *o = MP_OBJ_TO_PTR(self);
memset(&(o->ctx256), 0, sizeof(PBKDF2_HMAC_SHA256_CTX));
memset(&(o->ctx512), 0, sizeof(PBKDF2_HMAC_SHA512_CTX));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Pbkdf2___del___obj, mod_TrezorCrypto_Pbkdf2___del__);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Pbkdf2___del___obj, mod_trezorcrypto_Pbkdf2___del__);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_Pbkdf2_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_TrezorCrypto_Pbkdf2_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_key), MP_ROM_PTR(&mod_TrezorCrypto_Pbkdf2_key_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_TrezorCrypto_Pbkdf2___del___obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_Pbkdf2_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Pbkdf2_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_key), MP_ROM_PTR(&mod_trezorcrypto_Pbkdf2_key_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_trezorcrypto_Pbkdf2___del___obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_Pbkdf2_locals_dict, mod_TrezorCrypto_Pbkdf2_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Pbkdf2_locals_dict, mod_trezorcrypto_Pbkdf2_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_Pbkdf2_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_Pbkdf2_type = {
{ &mp_type_type },
.name = MP_QSTR_Pbkdf2,
.make_new = mod_TrezorCrypto_Pbkdf2_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_Pbkdf2_locals_dict,
.make_new = mod_trezorcrypto_Pbkdf2_make_new,
.locals_dict = (void*)&mod_trezorcrypto_Pbkdf2_locals_dict,
};

View File

@ -19,7 +19,7 @@ typedef struct _mp_obj_Random_t {
/// def __init__(self) -> None:
/// '''
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Random_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezorcrypto_Random_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
mp_obj_Random_t *o = m_new_obj(mp_obj_Random_t);
o->base.type = type;
@ -30,20 +30,20 @@ STATIC mp_obj_t mod_TrezorCrypto_Random_make_new(const mp_obj_type_t *type, size
/// '''
/// Compute uniform random number from interval 0 ... n - 1
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Random_uniform(mp_obj_t self, mp_obj_t n) {
STATIC mp_obj_t mod_trezorcrypto_Random_uniform(mp_obj_t self, mp_obj_t n) {
uint32_t nn = mp_obj_get_int_truncated(n);
if (nn == 0) {
mp_raise_ValueError("Maximum can't be zero");
}
return mp_obj_new_int_from_uint(random_uniform(nn));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Random_uniform_obj, mod_TrezorCrypto_Random_uniform);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Random_uniform_obj, mod_trezorcrypto_Random_uniform);
/// def bytes(self, len: int) -> bytes:
/// '''
/// Generate random bytes sequence of length len
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Random_bytes(mp_obj_t self, mp_obj_t len) {
STATIC mp_obj_t mod_trezorcrypto_Random_bytes(mp_obj_t self, mp_obj_t len) {
uint32_t l = mp_obj_get_int(len);
if (l > 8192) {
mp_raise_ValueError("Maximum requested size is 8192");
@ -53,13 +53,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Random_bytes(mp_obj_t self, mp_obj_t len) {
random_buffer((uint8_t *)vstr.buf, l);
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Random_bytes_obj, mod_TrezorCrypto_Random_bytes);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Random_bytes_obj, mod_trezorcrypto_Random_bytes);
/// def shuffle(self, data: list) -> None:
/// '''
/// Shuffles items of given list (in-place)
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Random_shuffle(mp_obj_t self, mp_obj_t data) {
STATIC mp_obj_t mod_trezorcrypto_Random_shuffle(mp_obj_t self, mp_obj_t data) {
size_t item_cnt;
mp_obj_t *items;
mp_obj_get_array(data, &item_cnt, &items);
@ -69,18 +69,18 @@ STATIC mp_obj_t mod_TrezorCrypto_Random_shuffle(mp_obj_t self, mp_obj_t data) {
random_permute(items, sizeof(mp_obj_t *), item_cnt);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Random_shuffle_obj, mod_TrezorCrypto_Random_shuffle);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Random_shuffle_obj, mod_trezorcrypto_Random_shuffle);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_Random_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_uniform), MP_ROM_PTR(&mod_TrezorCrypto_Random_uniform_obj) },
{ MP_ROM_QSTR(MP_QSTR_bytes), MP_ROM_PTR(&mod_TrezorCrypto_Random_bytes_obj) },
{ MP_ROM_QSTR(MP_QSTR_shuffle), MP_ROM_PTR(&mod_TrezorCrypto_Random_shuffle_obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_Random_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_uniform), MP_ROM_PTR(&mod_trezorcrypto_Random_uniform_obj) },
{ MP_ROM_QSTR(MP_QSTR_bytes), MP_ROM_PTR(&mod_trezorcrypto_Random_bytes_obj) },
{ MP_ROM_QSTR(MP_QSTR_shuffle), MP_ROM_PTR(&mod_trezorcrypto_Random_shuffle_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_Random_locals_dict, mod_TrezorCrypto_Random_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Random_locals_dict, mod_trezorcrypto_Random_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_Random_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_Random_type = {
{ &mp_type_type },
.name = MP_QSTR_Random,
.make_new = mod_TrezorCrypto_Random_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_Random_locals_dict,
.make_new = mod_trezorcrypto_Random_make_new,
.locals_dict = (void*)&mod_trezorcrypto_Random_locals_dict,
};

View File

@ -22,7 +22,7 @@ typedef struct _mp_obj_Rfc6979_t {
/// '''
/// 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) {
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) {
mp_arg_check_num(n_args, n_kw, 2, 2, false);
mp_obj_Rfc6979_t *o = m_new_obj(mp_obj_Rfc6979_t);
o->base.type = type;
@ -43,23 +43,23 @@ STATIC mp_obj_t mod_TrezorCrypto_Rfc6979_make_new(const mp_obj_type_t *type, siz
/// '''
/// Compute next 32-bytes of pseudorandom data.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Rfc6979_next(mp_obj_t self) {
STATIC mp_obj_t mod_trezorcrypto_Rfc6979_next(mp_obj_t self) {
mp_obj_Rfc6979_t *o = MP_OBJ_TO_PTR(self);
vstr_t vstr;
vstr_init_len(&vstr, 32);
generate_rfc6979((uint8_t *)vstr.buf, &(o->rng));
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Rfc6979_next_obj, mod_TrezorCrypto_Rfc6979_next);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Rfc6979_next_obj, mod_trezorcrypto_Rfc6979_next);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_Rfc6979_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_next), MP_ROM_PTR(&mod_TrezorCrypto_Rfc6979_next_obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_Rfc6979_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_next), MP_ROM_PTR(&mod_trezorcrypto_Rfc6979_next_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_Rfc6979_locals_dict, mod_TrezorCrypto_Rfc6979_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Rfc6979_locals_dict, mod_trezorcrypto_Rfc6979_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_Rfc6979_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_Rfc6979_type = {
{ &mp_type_type },
.name = MP_QSTR_Rfc6979,
.make_new = mod_TrezorCrypto_Rfc6979_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_Rfc6979_locals_dict,
.make_new = mod_trezorcrypto_Rfc6979_make_new,
.locals_dict = (void*)&mod_trezorcrypto_Rfc6979_locals_dict,
};

View File

@ -18,20 +18,20 @@ typedef struct _mp_obj_Ripemd160_t {
RIPEMD160_CTX ctx;
} mp_obj_Ripemd160_t;
STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data);
STATIC mp_obj_t mod_trezorcrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None) -> None:
/// '''
/// 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) {
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) {
mp_arg_check_num(n_args, n_kw, 0, 1, false);
mp_obj_Ripemd160_t *o = m_new_obj(mp_obj_Ripemd160_t);
o->base.type = type;
ripemd160_Init(&(o->ctx));
// constructor called with bytes/str as first parameter
if (n_args == 1) {
mod_TrezorCrypto_Ripemd160_update(MP_OBJ_FROM_PTR(o), args[0]);
mod_trezorcrypto_Ripemd160_update(MP_OBJ_FROM_PTR(o), args[0]);
}
return MP_OBJ_FROM_PTR(o);
}
@ -40,7 +40,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_make_new(const mp_obj_type_t *type, s
/// '''
/// Update the hash context with hashed data.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data) {
STATIC mp_obj_t mod_trezorcrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t msg;
mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
@ -49,13 +49,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data)
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Ripemd160_update_obj, mod_TrezorCrypto_Ripemd160_update);
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) {
STATIC mp_obj_t mod_trezorcrypto_Ripemd160_digest(mp_obj_t self) {
mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self);
vstr_t vstr;
vstr_init_len(&vstr, RIPEMD160_DIGEST_LENGTH);
@ -65,27 +65,27 @@ STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_digest(mp_obj_t self) {
memset(&ctx, 0, sizeof(RIPEMD160_CTX));
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Ripemd160_digest_obj, mod_TrezorCrypto_Ripemd160_digest);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Ripemd160_digest_obj, mod_trezorcrypto_Ripemd160_digest);
STATIC mp_obj_t mod_TrezorCrypto_Ripemd160___del__(mp_obj_t self) {
STATIC mp_obj_t mod_trezorcrypto_Ripemd160___del__(mp_obj_t self) {
mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self);
memset(&(o->ctx), 0, sizeof(RIPEMD160_CTX));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Ripemd160___del___obj, mod_TrezorCrypto_Ripemd160___del__);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Ripemd160___del___obj, mod_trezorcrypto_Ripemd160___del__);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_Ripemd160_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_TrezorCrypto_Ripemd160_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&mod_TrezorCrypto_Ripemd160_digest_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_TrezorCrypto_Ripemd160___del___obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_Ripemd160_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Ripemd160_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&mod_trezorcrypto_Ripemd160_digest_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_trezorcrypto_Ripemd160___del___obj) },
{ MP_ROM_QSTR(MP_QSTR_block_size), MP_OBJ_NEW_SMALL_INT(RIPEMD160_BLOCK_LENGTH) },
{ MP_ROM_QSTR(MP_QSTR_digest_size), MP_OBJ_NEW_SMALL_INT(RIPEMD160_DIGEST_LENGTH) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_Ripemd160_locals_dict, mod_TrezorCrypto_Ripemd160_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Ripemd160_locals_dict, mod_trezorcrypto_Ripemd160_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_Ripemd160_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_Ripemd160_type = {
{ &mp_type_type },
.name = MP_QSTR_Ripemd160,
.make_new = mod_TrezorCrypto_Ripemd160_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_Ripemd160_locals_dict,
.make_new = mod_trezorcrypto_Ripemd160_make_new,
.locals_dict = (void*)&mod_trezorcrypto_Ripemd160_locals_dict,
};

View File

@ -20,7 +20,7 @@ typedef struct _mp_obj_Secp256k1_t {
/// def __init__(self) -> None:
/// '''
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezorcrypto_Secp256k1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
mp_obj_Secp256k1_t *o = m_new_obj(mp_obj_Secp256k1_t);
o->base.type = type;
@ -31,7 +31,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_make_new(const mp_obj_type_t *type, s
/// '''
/// Generate secret key.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_generate_secret(mp_obj_t self) {
STATIC mp_obj_t mod_trezorcrypto_Secp256k1_generate_secret(mp_obj_t self) {
vstr_t vstr;
vstr_init_len(&vstr, 32);
for (;;) {
@ -43,13 +43,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_generate_secret(mp_obj_t self) {
}
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Secp256k1_generate_secret_obj, mod_TrezorCrypto_Secp256k1_generate_secret);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Secp256k1_generate_secret_obj, mod_trezorcrypto_Secp256k1_generate_secret);
/// def publickey(self, 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) {
STATIC mp_obj_t mod_trezorcrypto_Secp256k1_publickey(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t sk;
mp_get_buffer_raise(args[1], &sk, MP_BUFFER_READ);
if (sk.len != 32) {
@ -66,13 +66,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_publickey(size_t n_args, const mp_obj
}
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Secp256k1_publickey_obj, 2, 3, mod_TrezorCrypto_Secp256k1_publickey);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_Secp256k1_publickey_obj, 2, 3, mod_trezorcrypto_Secp256k1_publickey);
/// def sign(self, 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_sign(size_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezorcrypto_Secp256k1_sign(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t sk, dig;
mp_get_buffer_raise(args[1], &sk, MP_BUFFER_READ);
mp_get_buffer_raise(args[2], &dig, MP_BUFFER_READ);
@ -92,14 +92,14 @@ STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_sign(size_t n_args, const mp_obj_t *a
vstr.buf[0] = 27 + pby + compressed * 4;
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Secp256k1_sign_obj, 3, 4, mod_TrezorCrypto_Secp256k1_sign);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_Secp256k1_sign_obj, 3, 4, mod_trezorcrypto_Secp256k1_sign);
/// def verify(self, 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(size_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezorcrypto_Secp256k1_verify(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t pk, sig, dig;
mp_get_buffer_raise(args[1], &pk, MP_BUFFER_READ);
mp_get_buffer_raise(args[2], &sig, MP_BUFFER_READ);
@ -116,14 +116,14 @@ STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_verify(size_t n_args, const mp_obj_t
}
return mp_obj_new_bool(0 == ecdsa_verify_digest(&secp256k1, (const uint8_t *)pk.buf, (const uint8_t *)sig.buf + offset, (const uint8_t *)dig.buf));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Secp256k1_verify_obj, 4, 4, mod_TrezorCrypto_Secp256k1_verify);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_Secp256k1_verify_obj, 4, 4, mod_trezorcrypto_Secp256k1_verify);
/// def verify_recover(self, 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.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_verify_recover(mp_obj_t self, mp_obj_t signature, mp_obj_t digest) {
STATIC mp_obj_t mod_trezorcrypto_Secp256k1_verify_recover(mp_obj_t self, mp_obj_t signature, mp_obj_t digest) {
mp_buffer_info_t sig, dig;
mp_get_buffer_raise(signature, &sig, MP_BUFFER_READ);
mp_get_buffer_raise(digest, &dig, MP_BUFFER_READ);
@ -151,14 +151,14 @@ STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_verify_recover(mp_obj_t self, mp_obj_
return mp_const_none;
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Secp256k1_verify_recover_obj, mod_TrezorCrypto_Secp256k1_verify_recover);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_Secp256k1_verify_recover_obj, mod_trezorcrypto_Secp256k1_verify_recover);
/// def multiply(self, 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 self, mp_obj_t secret_key, mp_obj_t public_key) {
STATIC mp_obj_t mod_trezorcrypto_Secp256k1_multiply(mp_obj_t self, mp_obj_t secret_key, mp_obj_t public_key) {
mp_buffer_info_t sk, pk;
mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
mp_get_buffer_raise(public_key, &pk, MP_BUFFER_READ);
@ -175,21 +175,21 @@ STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_multiply(mp_obj_t self, mp_obj_t secr
}
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Secp256k1_multiply_obj, mod_TrezorCrypto_Secp256k1_multiply);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_Secp256k1_multiply_obj, mod_trezorcrypto_Secp256k1_multiply);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_Secp256k1_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_generate_secret), MP_ROM_PTR(&mod_TrezorCrypto_Secp256k1_generate_secret_obj) },
{ MP_ROM_QSTR(MP_QSTR_publickey), MP_ROM_PTR(&mod_TrezorCrypto_Secp256k1_publickey_obj) },
{ MP_ROM_QSTR(MP_QSTR_sign), MP_ROM_PTR(&mod_TrezorCrypto_Secp256k1_sign_obj) },
{ MP_ROM_QSTR(MP_QSTR_verify), MP_ROM_PTR(&mod_TrezorCrypto_Secp256k1_verify_obj) },
{ MP_ROM_QSTR(MP_QSTR_verify_recover), MP_ROM_PTR(&mod_TrezorCrypto_Secp256k1_verify_recover_obj) },
{ MP_ROM_QSTR(MP_QSTR_multiply), MP_ROM_PTR(&mod_TrezorCrypto_Secp256k1_multiply_obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_Secp256k1_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_generate_secret), MP_ROM_PTR(&mod_trezorcrypto_Secp256k1_generate_secret_obj) },
{ MP_ROM_QSTR(MP_QSTR_publickey), MP_ROM_PTR(&mod_trezorcrypto_Secp256k1_publickey_obj) },
{ MP_ROM_QSTR(MP_QSTR_sign), MP_ROM_PTR(&mod_trezorcrypto_Secp256k1_sign_obj) },
{ MP_ROM_QSTR(MP_QSTR_verify), MP_ROM_PTR(&mod_trezorcrypto_Secp256k1_verify_obj) },
{ MP_ROM_QSTR(MP_QSTR_verify_recover), MP_ROM_PTR(&mod_trezorcrypto_Secp256k1_verify_recover_obj) },
{ MP_ROM_QSTR(MP_QSTR_multiply), MP_ROM_PTR(&mod_trezorcrypto_Secp256k1_multiply_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_Secp256k1_locals_dict, mod_TrezorCrypto_Secp256k1_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Secp256k1_locals_dict, mod_trezorcrypto_Secp256k1_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_Secp256k1_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_Secp256k1_type = {
{ &mp_type_type },
.name = MP_QSTR_Secp256k1,
.make_new = mod_TrezorCrypto_Secp256k1_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_Secp256k1_locals_dict,
.make_new = mod_trezorcrypto_Secp256k1_make_new,
.locals_dict = (void*)&mod_trezorcrypto_Secp256k1_locals_dict,
};

View File

@ -18,20 +18,20 @@ typedef struct _mp_obj_Sha1_t {
SHA1_CTX ctx;
} mp_obj_Sha1_t;
STATIC mp_obj_t mod_TrezorCrypto_Sha1_update(mp_obj_t self, mp_obj_t data);
STATIC mp_obj_t mod_trezorcrypto_Sha1_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None) -> None:
/// '''
/// 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) {
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) {
mp_arg_check_num(n_args, n_kw, 0, 1, false);
mp_obj_Sha1_t *o = m_new_obj(mp_obj_Sha1_t);
o->base.type = type;
sha1_Init(&(o->ctx));
// constructor called with bytes/str as first parameter
if (n_args == 1) {
mod_TrezorCrypto_Sha1_update(MP_OBJ_FROM_PTR(o), args[0]);
mod_trezorcrypto_Sha1_update(MP_OBJ_FROM_PTR(o), args[0]);
}
return MP_OBJ_FROM_PTR(o);
}
@ -40,7 +40,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha1_make_new(const mp_obj_type_t *type, size_t
/// '''
/// Update the hash context with hashed data.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Sha1_update(mp_obj_t self, mp_obj_t data) {
STATIC mp_obj_t mod_trezorcrypto_Sha1_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Sha1_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t msg;
mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
@ -49,13 +49,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha1_update(mp_obj_t self, mp_obj_t data) {
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha1_update_obj, mod_TrezorCrypto_Sha1_update);
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) {
STATIC mp_obj_t mod_trezorcrypto_Sha1_digest(mp_obj_t self) {
mp_obj_Sha1_t *o = MP_OBJ_TO_PTR(self);
vstr_t vstr;
vstr_init_len(&vstr, SHA1_DIGEST_LENGTH);
@ -65,27 +65,27 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha1_digest(mp_obj_t self) {
memset(&ctx, 0, sizeof(SHA1_CTX));
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha1_digest_obj, mod_TrezorCrypto_Sha1_digest);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha1_digest_obj, mod_trezorcrypto_Sha1_digest);
STATIC mp_obj_t mod_TrezorCrypto_Sha1___del__(mp_obj_t self) {
STATIC mp_obj_t mod_trezorcrypto_Sha1___del__(mp_obj_t self) {
mp_obj_Sha1_t *o = MP_OBJ_TO_PTR(self);
memset(&(o->ctx), 0, sizeof(SHA1_CTX));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha1___del___obj, mod_TrezorCrypto_Sha1___del__);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha1___del___obj, mod_trezorcrypto_Sha1___del__);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_Sha1_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_TrezorCrypto_Sha1_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&mod_TrezorCrypto_Sha1_digest_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_TrezorCrypto_Sha1___del___obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_Sha1_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Sha1_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&mod_trezorcrypto_Sha1_digest_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_trezorcrypto_Sha1___del___obj) },
{ MP_ROM_QSTR(MP_QSTR_block_size), MP_OBJ_NEW_SMALL_INT(SHA1_BLOCK_LENGTH) },
{ MP_ROM_QSTR(MP_QSTR_digest_size), MP_OBJ_NEW_SMALL_INT(SHA1_DIGEST_LENGTH) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_Sha1_locals_dict, mod_TrezorCrypto_Sha1_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Sha1_locals_dict, mod_trezorcrypto_Sha1_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_Sha1_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_Sha1_type = {
{ &mp_type_type },
.name = MP_QSTR_Sha1,
.make_new = mod_TrezorCrypto_Sha1_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_Sha1_locals_dict,
.make_new = mod_trezorcrypto_Sha1_make_new,
.locals_dict = (void*)&mod_trezorcrypto_Sha1_locals_dict,
};

View File

@ -18,20 +18,20 @@ typedef struct _mp_obj_Sha256_t {
SHA256_CTX ctx;
} mp_obj_Sha256_t;
STATIC mp_obj_t mod_TrezorCrypto_Sha256_update(mp_obj_t self, mp_obj_t data);
STATIC mp_obj_t mod_trezorcrypto_Sha256_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None) -> None:
/// '''
/// 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) {
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) {
mp_arg_check_num(n_args, n_kw, 0, 1, false);
mp_obj_Sha256_t *o = m_new_obj(mp_obj_Sha256_t);
o->base.type = type;
sha256_Init(&(o->ctx));
// constructor called with bytes/str as first parameter
if (n_args == 1) {
mod_TrezorCrypto_Sha256_update(MP_OBJ_FROM_PTR(o), args[0]);
mod_trezorcrypto_Sha256_update(MP_OBJ_FROM_PTR(o), args[0]);
}
return MP_OBJ_FROM_PTR(o);
}
@ -40,7 +40,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha256_make_new(const mp_obj_type_t *type, size
/// '''
/// Update the hash context with hashed data.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Sha256_update(mp_obj_t self, mp_obj_t data) {
STATIC mp_obj_t mod_trezorcrypto_Sha256_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t msg;
mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
@ -49,13 +49,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha256_update(mp_obj_t self, mp_obj_t data) {
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha256_update_obj, mod_TrezorCrypto_Sha256_update);
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) {
STATIC mp_obj_t mod_trezorcrypto_Sha256_digest(mp_obj_t self) {
mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self);
vstr_t vstr;
vstr_init_len(&vstr, SHA256_DIGEST_LENGTH);
@ -65,27 +65,27 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha256_digest(mp_obj_t self) {
memset(&ctx, 0, sizeof(SHA256_CTX));
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha256_digest_obj, mod_TrezorCrypto_Sha256_digest);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha256_digest_obj, mod_trezorcrypto_Sha256_digest);
STATIC mp_obj_t mod_TrezorCrypto_Sha256___del__(mp_obj_t self) {
STATIC mp_obj_t mod_trezorcrypto_Sha256___del__(mp_obj_t self) {
mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self);
memset(&(o->ctx), 0, sizeof(SHA256_CTX));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha256___del___obj, mod_TrezorCrypto_Sha256___del__);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha256___del___obj, mod_trezorcrypto_Sha256___del__);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_Sha256_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_TrezorCrypto_Sha256_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&mod_TrezorCrypto_Sha256_digest_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_TrezorCrypto_Sha256___del___obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_Sha256_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Sha256_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&mod_trezorcrypto_Sha256_digest_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_trezorcrypto_Sha256___del___obj) },
{ MP_ROM_QSTR(MP_QSTR_block_size), MP_OBJ_NEW_SMALL_INT(SHA256_BLOCK_LENGTH) },
{ MP_ROM_QSTR(MP_QSTR_digest_size), MP_OBJ_NEW_SMALL_INT(SHA256_DIGEST_LENGTH) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_Sha256_locals_dict, mod_TrezorCrypto_Sha256_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Sha256_locals_dict, mod_trezorcrypto_Sha256_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_Sha256_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_Sha256_type = {
{ &mp_type_type },
.name = MP_QSTR_Sha256,
.make_new = mod_TrezorCrypto_Sha256_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_Sha256_locals_dict,
.make_new = mod_trezorcrypto_Sha256_make_new,
.locals_dict = (void*)&mod_trezorcrypto_Sha256_locals_dict,
};

View File

@ -18,20 +18,20 @@ typedef struct _mp_obj_Sha3_256_t {
SHA3_CTX ctx;
} mp_obj_Sha3_256_t;
STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data);
STATIC mp_obj_t mod_trezorcrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None) -> 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) {
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) {
mp_arg_check_num(n_args, n_kw, 0, 1, false);
mp_obj_Sha3_256_t *o = m_new_obj(mp_obj_Sha3_256_t);
o->base.type = type;
sha3_256_Init(&(o->ctx));
// constructor called with bytes/str as first parameter
if (n_args == 1) {
mod_TrezorCrypto_Sha3_256_update(MP_OBJ_FROM_PTR(o), args[0]);
mod_trezorcrypto_Sha3_256_update(MP_OBJ_FROM_PTR(o), args[0]);
}
return MP_OBJ_FROM_PTR(o);
}
@ -40,7 +40,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_make_new(const mp_obj_type_t *type, si
/// '''
/// Update the hash context with hashed data.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data) {
STATIC mp_obj_t mod_trezorcrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t msg;
mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
@ -49,13 +49,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data) {
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha3_256_update_obj, mod_TrezorCrypto_Sha3_256_update);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha3_256_update_obj, mod_trezorcrypto_Sha3_256_update);
/// def digest(self, keccak: bool = False) -> bytes:
/// '''
/// Returns the digest of hashed data.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_digest(size_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezorcrypto_Sha3_256_digest(size_t n_args, const mp_obj_t *args) {
mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(args[0]);
vstr_t vstr;
vstr_init_len(&vstr, SHA3_256_DIGEST_LENGTH);
@ -69,27 +69,27 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_digest(size_t n_args, const mp_obj_t *
memset(&ctx, 0, sizeof(SHA3_CTX));
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Sha3_256_digest_obj, 1, 2, mod_TrezorCrypto_Sha3_256_digest);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_Sha3_256_digest_obj, 1, 2, mod_trezorcrypto_Sha3_256_digest);
STATIC mp_obj_t mod_TrezorCrypto_Sha3_256___del__(mp_obj_t self) {
STATIC mp_obj_t mod_trezorcrypto_Sha3_256___del__(mp_obj_t self) {
mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(self);
memset(&(o->ctx), 0, sizeof(SHA3_CTX));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha3_256___del___obj, mod_TrezorCrypto_Sha3_256___del__);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha3_256___del___obj, mod_trezorcrypto_Sha3_256___del__);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_Sha3_256_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_TrezorCrypto_Sha3_256_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&mod_TrezorCrypto_Sha3_256_digest_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_TrezorCrypto_Sha3_256___del___obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_Sha3_256_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Sha3_256_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&mod_trezorcrypto_Sha3_256_digest_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_trezorcrypto_Sha3_256___del___obj) },
{ MP_ROM_QSTR(MP_QSTR_block_size), MP_OBJ_NEW_SMALL_INT(SHA3_256_BLOCK_LENGTH) },
{ MP_ROM_QSTR(MP_QSTR_digest_size), MP_OBJ_NEW_SMALL_INT(SHA3_256_DIGEST_LENGTH) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_Sha3_256_locals_dict, mod_TrezorCrypto_Sha3_256_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Sha3_256_locals_dict, mod_trezorcrypto_Sha3_256_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_Sha3_256_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_Sha3_256_type = {
{ &mp_type_type },
.name = MP_QSTR_Sha3_256,
.make_new = mod_TrezorCrypto_Sha3_256_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_Sha3_256_locals_dict,
.make_new = mod_trezorcrypto_Sha3_256_make_new,
.locals_dict = (void*)&mod_trezorcrypto_Sha3_256_locals_dict,
};

View File

@ -18,20 +18,20 @@ typedef struct _mp_obj_Sha3_512_t {
SHA3_CTX ctx;
} mp_obj_Sha3_512_t;
STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data);
STATIC mp_obj_t mod_trezorcrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None) -> 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) {
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) {
mp_arg_check_num(n_args, n_kw, 0, 1, false);
mp_obj_Sha3_512_t *o = m_new_obj(mp_obj_Sha3_512_t);
o->base.type = type;
sha3_512_Init(&(o->ctx));
// constructor called with bytes/str as first parameter
if (n_args == 1) {
mod_TrezorCrypto_Sha3_512_update(MP_OBJ_FROM_PTR(o), args[0]);
mod_trezorcrypto_Sha3_512_update(MP_OBJ_FROM_PTR(o), args[0]);
}
return MP_OBJ_FROM_PTR(o);
}
@ -40,7 +40,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_make_new(const mp_obj_type_t *type, si
/// '''
/// Update the hash context with hashed data.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data) {
STATIC mp_obj_t mod_trezorcrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t msg;
mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
@ -49,13 +49,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data) {
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha3_512_update_obj, mod_TrezorCrypto_Sha3_512_update);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha3_512_update_obj, mod_trezorcrypto_Sha3_512_update);
/// def digest(self, keccak: bool = False) -> bytes:
/// '''
/// Returns the digest of hashed data.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_digest(size_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezorcrypto_Sha3_512_digest(size_t n_args, const mp_obj_t *args) {
mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(args[0]);
vstr_t vstr;
vstr_init_len(&vstr, SHA3_512_DIGEST_LENGTH);
@ -69,27 +69,27 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_digest(size_t n_args, const mp_obj_t *
memset(&ctx, 0, sizeof(SHA3_CTX));
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Sha3_512_digest_obj, 1, 2, mod_TrezorCrypto_Sha3_512_digest);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_Sha3_512_digest_obj, 1, 2, mod_trezorcrypto_Sha3_512_digest);
STATIC mp_obj_t mod_TrezorCrypto_Sha3_512___del__(mp_obj_t self) {
STATIC mp_obj_t mod_trezorcrypto_Sha3_512___del__(mp_obj_t self) {
mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(self);
memset(&(o->ctx), 0, sizeof(SHA3_CTX));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha3_512___del___obj, mod_TrezorCrypto_Sha3_512___del__);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha3_512___del___obj, mod_trezorcrypto_Sha3_512___del__);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_Sha3_512_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_TrezorCrypto_Sha3_512_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&mod_TrezorCrypto_Sha3_512_digest_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_TrezorCrypto_Sha3_512___del___obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_Sha3_512_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Sha3_512_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&mod_trezorcrypto_Sha3_512_digest_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_trezorcrypto_Sha3_512___del___obj) },
{ MP_ROM_QSTR(MP_QSTR_block_size), MP_OBJ_NEW_SMALL_INT(SHA3_512_BLOCK_LENGTH) },
{ MP_ROM_QSTR(MP_QSTR_digest_size), MP_OBJ_NEW_SMALL_INT(SHA3_512_DIGEST_LENGTH) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_Sha3_512_locals_dict, mod_TrezorCrypto_Sha3_512_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Sha3_512_locals_dict, mod_trezorcrypto_Sha3_512_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_Sha3_512_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_Sha3_512_type = {
{ &mp_type_type },
.name = MP_QSTR_Sha3_512,
.make_new = mod_TrezorCrypto_Sha3_512_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_Sha3_512_locals_dict,
.make_new = mod_trezorcrypto_Sha3_512_make_new,
.locals_dict = (void*)&mod_trezorcrypto_Sha3_512_locals_dict,
};

View File

@ -18,19 +18,19 @@ typedef struct _mp_obj_Sha512_t {
SHA512_CTX ctx;
} mp_obj_Sha512_t;
STATIC mp_obj_t mod_TrezorCrypto_Sha512_update(mp_obj_t self, mp_obj_t data);
STATIC mp_obj_t mod_trezorcrypto_Sha512_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None) -> None:
/// '''
/// 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) {
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) {
mp_arg_check_num(n_args, n_kw, 0, 1, false);
mp_obj_Sha512_t *o = m_new_obj(mp_obj_Sha512_t);
o->base.type = type;
sha512_Init(&(o->ctx));
if (n_args == 1) {
mod_TrezorCrypto_Sha512_update(MP_OBJ_FROM_PTR(o), args[0]);
mod_trezorcrypto_Sha512_update(MP_OBJ_FROM_PTR(o), args[0]);
}
return MP_OBJ_FROM_PTR(o);
}
@ -39,7 +39,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha512_make_new(const mp_obj_type_t *type, size
/// '''
/// Update the hash context with hashed data.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Sha512_update(mp_obj_t self, mp_obj_t data) {
STATIC mp_obj_t mod_trezorcrypto_Sha512_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t msg;
mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
@ -48,13 +48,13 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha512_update(mp_obj_t self, mp_obj_t data) {
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha512_update_obj, mod_TrezorCrypto_Sha512_update);
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) {
STATIC mp_obj_t mod_trezorcrypto_Sha512_digest(mp_obj_t self) {
mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self);
vstr_t vstr;
vstr_init_len(&vstr, SHA512_DIGEST_LENGTH);
@ -64,27 +64,27 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha512_digest(mp_obj_t self) {
memset(&ctx, 0, sizeof(SHA512_CTX));
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha512_digest_obj, mod_TrezorCrypto_Sha512_digest);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha512_digest_obj, mod_trezorcrypto_Sha512_digest);
STATIC mp_obj_t mod_TrezorCrypto_Sha512___del__(mp_obj_t self) {
STATIC mp_obj_t mod_trezorcrypto_Sha512___del__(mp_obj_t self) {
mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self);
memset(&(o->ctx), 0, sizeof(SHA512_CTX));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha512___del___obj, mod_TrezorCrypto_Sha512___del__);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha512___del___obj, mod_trezorcrypto_Sha512___del__);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_Sha512_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_TrezorCrypto_Sha512_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&mod_TrezorCrypto_Sha512_digest_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_TrezorCrypto_Sha512___del___obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_Sha512_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Sha512_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&mod_trezorcrypto_Sha512_digest_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_trezorcrypto_Sha512___del___obj) },
{ MP_ROM_QSTR(MP_QSTR_block_size), MP_OBJ_NEW_SMALL_INT(SHA512_BLOCK_LENGTH) },
{ MP_ROM_QSTR(MP_QSTR_digest_size), MP_OBJ_NEW_SMALL_INT(SHA512_DIGEST_LENGTH) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_Sha512_locals_dict, mod_TrezorCrypto_Sha512_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Sha512_locals_dict, mod_trezorcrypto_Sha512_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_Sha512_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_Sha512_type = {
{ &mp_type_type },
.name = MP_QSTR_Sha512,
.make_new = mod_TrezorCrypto_Sha512_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_Sha512_locals_dict,
.make_new = mod_trezorcrypto_Sha512_make_new,
.locals_dict = (void*)&mod_trezorcrypto_Sha512_locals_dict,
};

View File

@ -20,7 +20,7 @@ typedef struct _mp_obj_SSSS_t {
/// def __init__(self) -> None:
/// '''
/// '''
STATIC mp_obj_t mod_TrezorCrypto_SSSS_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezorcrypto_SSSS_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
mp_obj_SSSS_t *o = m_new_obj(mp_obj_SSSS_t);
o->base.type = type;
@ -31,7 +31,7 @@ STATIC mp_obj_t mod_TrezorCrypto_SSSS_make_new(const mp_obj_type_t *type, size_t
/// '''
/// Split secret to (M of N) shares using Shamir's Secret Sharing Scheme.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_SSSS_split(size_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezorcrypto_SSSS_split(size_t n_args, const mp_obj_t *args) {
mp_int_t m = mp_obj_get_int(args[1]);
mp_int_t n = mp_obj_get_int(args[2]);
mp_buffer_info_t secret;
@ -57,13 +57,13 @@ STATIC mp_obj_t mod_TrezorCrypto_SSSS_split(size_t n_args, const mp_obj_t *args)
}
return MP_OBJ_FROM_PTR(tuple);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_SSSS_split_obj, 4, 4, mod_TrezorCrypto_SSSS_split);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_SSSS_split_obj, 4, 4, mod_trezorcrypto_SSSS_split);
/// def combine(self, shares: tuple) -> bytes:
/// '''
/// Combine M shares of Shamir's Secret Sharing Scheme into secret.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_SSSS_combine(mp_obj_t self, mp_obj_t shares) {
STATIC mp_obj_t mod_trezorcrypto_SSSS_combine(mp_obj_t self, mp_obj_t shares) {
size_t n;
mp_obj_t *share;
mp_obj_get_array(shares, &n, &share);
@ -92,17 +92,17 @@ STATIC mp_obj_t mod_TrezorCrypto_SSSS_combine(mp_obj_t self, mp_obj_t shares) {
bn_write_be(&sk, (uint8_t *)vstr.buf);
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_SSSS_combine_obj, mod_TrezorCrypto_SSSS_combine);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_SSSS_combine_obj, mod_trezorcrypto_SSSS_combine);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_SSSS_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_split), MP_ROM_PTR(&mod_TrezorCrypto_SSSS_split_obj) },
{ MP_ROM_QSTR(MP_QSTR_combine), MP_ROM_PTR(&mod_TrezorCrypto_SSSS_combine_obj) },
STATIC const mp_rom_map_elem_t mod_trezorcrypto_SSSS_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_split), MP_ROM_PTR(&mod_trezorcrypto_SSSS_split_obj) },
{ MP_ROM_QSTR(MP_QSTR_combine), MP_ROM_PTR(&mod_trezorcrypto_SSSS_combine_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_SSSS_locals_dict, mod_TrezorCrypto_SSSS_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_SSSS_locals_dict, mod_trezorcrypto_SSSS_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_SSSS_type = {
STATIC const mp_obj_type_t mod_trezorcrypto_SSSS_type = {
{ &mp_type_type },
.name = MP_QSTR_SSSS,
.make_new = mod_TrezorCrypto_SSSS_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_SSSS_locals_dict,
.make_new = mod_trezorcrypto_SSSS_make_new,
.locals_dict = (void*)&mod_trezorcrypto_SSSS_locals_dict,
};

View File

@ -33,33 +33,33 @@
#include "modtrezorcrypto-sha3-512.h"
#include "modtrezorcrypto-ssss.h"
STATIC const mp_rom_map_elem_t mp_module_TrezorCrypto_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_TrezorCrypto) },
{ MP_ROM_QSTR(MP_QSTR_AES), MP_ROM_PTR(&mod_TrezorCrypto_AES_type) },
{ MP_ROM_QSTR(MP_QSTR_Bip32), MP_ROM_PTR(&mod_TrezorCrypto_Bip32_type) },
{ MP_ROM_QSTR(MP_QSTR_Bip39), MP_ROM_PTR(&mod_TrezorCrypto_Bip39_type) },
{ MP_ROM_QSTR(MP_QSTR_Blake2b), MP_ROM_PTR(&mod_TrezorCrypto_Blake2b_type) },
{ MP_ROM_QSTR(MP_QSTR_Blake2s), MP_ROM_PTR(&mod_TrezorCrypto_Blake2s_type) },
{ MP_ROM_QSTR(MP_QSTR_Curve25519), MP_ROM_PTR(&mod_TrezorCrypto_Curve25519_type) },
{ MP_ROM_QSTR(MP_QSTR_Ed25519), MP_ROM_PTR(&mod_TrezorCrypto_Ed25519_type) },
{ MP_ROM_QSTR(MP_QSTR_Nist256p1), MP_ROM_PTR(&mod_TrezorCrypto_Nist256p1_type) },
{ MP_ROM_QSTR(MP_QSTR_Pbkdf2), MP_ROM_PTR(&mod_TrezorCrypto_Pbkdf2_type) },
{ MP_ROM_QSTR(MP_QSTR_Random), MP_ROM_PTR(&mod_TrezorCrypto_Random_type) },
{ MP_ROM_QSTR(MP_QSTR_Rfc6979), MP_ROM_PTR(&mod_TrezorCrypto_Rfc6979_type) },
{ MP_ROM_QSTR(MP_QSTR_Ripemd160), MP_ROM_PTR(&mod_TrezorCrypto_Ripemd160_type) },
{ MP_ROM_QSTR(MP_QSTR_Secp256k1), MP_ROM_PTR(&mod_TrezorCrypto_Secp256k1_type) },
{ MP_ROM_QSTR(MP_QSTR_Sha1), MP_ROM_PTR(&mod_TrezorCrypto_Sha1_type) },
{ MP_ROM_QSTR(MP_QSTR_Sha256), MP_ROM_PTR(&mod_TrezorCrypto_Sha256_type) },
{ MP_ROM_QSTR(MP_QSTR_Sha512), MP_ROM_PTR(&mod_TrezorCrypto_Sha512_type) },
{ MP_ROM_QSTR(MP_QSTR_Sha3_256), MP_ROM_PTR(&mod_TrezorCrypto_Sha3_256_type) },
{ MP_ROM_QSTR(MP_QSTR_Sha3_512), MP_ROM_PTR(&mod_TrezorCrypto_Sha3_512_type) },
{ MP_ROM_QSTR(MP_QSTR_SSSS), MP_ROM_PTR(&mod_TrezorCrypto_SSSS_type) },
STATIC const mp_rom_map_elem_t mp_module_trezorcrypto_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorcrypto) },
{ MP_ROM_QSTR(MP_QSTR_AES), MP_ROM_PTR(&mod_trezorcrypto_AES_type) },
{ MP_ROM_QSTR(MP_QSTR_Bip32), MP_ROM_PTR(&mod_trezorcrypto_Bip32_type) },
{ MP_ROM_QSTR(MP_QSTR_Bip39), MP_ROM_PTR(&mod_trezorcrypto_Bip39_type) },
{ MP_ROM_QSTR(MP_QSTR_Blake2b), MP_ROM_PTR(&mod_trezorcrypto_Blake2b_type) },
{ MP_ROM_QSTR(MP_QSTR_Blake2s), MP_ROM_PTR(&mod_trezorcrypto_Blake2s_type) },
{ MP_ROM_QSTR(MP_QSTR_Curve25519), MP_ROM_PTR(&mod_trezorcrypto_Curve25519_type) },
{ MP_ROM_QSTR(MP_QSTR_Ed25519), MP_ROM_PTR(&mod_trezorcrypto_Ed25519_type) },
{ MP_ROM_QSTR(MP_QSTR_Nist256p1), MP_ROM_PTR(&mod_trezorcrypto_Nist256p1_type) },
{ MP_ROM_QSTR(MP_QSTR_Pbkdf2), MP_ROM_PTR(&mod_trezorcrypto_Pbkdf2_type) },
{ MP_ROM_QSTR(MP_QSTR_Random), MP_ROM_PTR(&mod_trezorcrypto_Random_type) },
{ MP_ROM_QSTR(MP_QSTR_Rfc6979), MP_ROM_PTR(&mod_trezorcrypto_Rfc6979_type) },
{ MP_ROM_QSTR(MP_QSTR_Ripemd160), MP_ROM_PTR(&mod_trezorcrypto_Ripemd160_type) },
{ MP_ROM_QSTR(MP_QSTR_Secp256k1), MP_ROM_PTR(&mod_trezorcrypto_Secp256k1_type) },
{ MP_ROM_QSTR(MP_QSTR_Sha1), MP_ROM_PTR(&mod_trezorcrypto_Sha1_type) },
{ MP_ROM_QSTR(MP_QSTR_Sha256), MP_ROM_PTR(&mod_trezorcrypto_Sha256_type) },
{ MP_ROM_QSTR(MP_QSTR_Sha512), MP_ROM_PTR(&mod_trezorcrypto_Sha512_type) },
{ MP_ROM_QSTR(MP_QSTR_Sha3_256), MP_ROM_PTR(&mod_trezorcrypto_Sha3_256_type) },
{ MP_ROM_QSTR(MP_QSTR_Sha3_512), MP_ROM_PTR(&mod_trezorcrypto_Sha3_512_type) },
{ MP_ROM_QSTR(MP_QSTR_SSSS), MP_ROM_PTR(&mod_trezorcrypto_SSSS_type) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_TrezorCrypto_globals, mp_module_TrezorCrypto_globals_table);
STATIC MP_DEFINE_CONST_DICT(mp_module_trezorcrypto_globals, mp_module_trezorcrypto_globals_table);
const mp_obj_module_t mp_module_TrezorCrypto = {
const mp_obj_module_t mp_module_trezorcrypto = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&mp_module_TrezorCrypto_globals,
.globals = (mp_obj_dict_t*)&mp_module_trezorcrypto_globals,
};
#endif // MICROPY_PY_TREZORCRYPTO

View File

@ -23,7 +23,7 @@ typedef struct _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) {
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) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
mp_obj_SDCard_t *o = m_new_obj(mp_obj_SDCard_t);
o->base.type = type;
@ -34,73 +34,73 @@ STATIC mp_obj_t mod_TrezorIO_SDCard_make_new(const mp_obj_type_t *type, size_t n
/// '''
/// Returns True if SD card is detected, False otherwise.
/// '''
STATIC mp_obj_t mod_TrezorIO_SDCard_present(mp_obj_t self) {
STATIC mp_obj_t mod_trezorio_SDCard_present(mp_obj_t self) {
return mp_obj_new_bool(sdcard_is_present());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorIO_SDCard_present_obj, mod_TrezorIO_SDCard_present);
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) {
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());
} else {
return mp_obj_new_bool(sdcard_power_off());
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorIO_SDCard_power_obj, mod_TrezorIO_SDCard_power);
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) {
STATIC mp_obj_t mod_trezorio_SDCard_capacity(mp_obj_t self) {
return mp_obj_new_int_from_ull(sdcard_get_capacity_in_bytes());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorIO_SDCard_capacity_obj, mod_TrezorIO_SDCard_capacity);
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 block_num block from the SD card into buf.
/// 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) {
STATIC mp_obj_t mod_trezorio_SDCard_read(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE);
mp_uint_t ret = sdcard_read_blocks(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SDCARD_BLOCK_SIZE);
return mp_obj_new_bool(ret == 0);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorIO_SDCard_read_obj, mod_TrezorIO_SDCard_read);
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 block_num block from buf to the SD card.
/// 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) {
STATIC mp_obj_t mod_trezorio_SDCard_write(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
mp_uint_t ret = sdcard_write_blocks(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SDCARD_BLOCK_SIZE);
return mp_obj_new_bool(ret == 0);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorIO_SDCard_write_obj, mod_TrezorIO_SDCard_write);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorio_SDCard_write_obj, mod_trezorio_SDCard_write);
STATIC const mp_rom_map_elem_t mod_TrezorIO_SDCard_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_present), MP_ROM_PTR(&mod_TrezorIO_SDCard_present_obj) },
{ MP_ROM_QSTR(MP_QSTR_power), MP_ROM_PTR(&mod_TrezorIO_SDCard_power_obj) },
{ MP_ROM_QSTR(MP_QSTR_capacity), MP_ROM_PTR(&mod_TrezorIO_SDCard_capacity_obj) },
STATIC const mp_rom_map_elem_t mod_trezorio_SDCard_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_present), MP_ROM_PTR(&mod_trezorio_SDCard_present_obj) },
{ MP_ROM_QSTR(MP_QSTR_power), MP_ROM_PTR(&mod_trezorio_SDCard_power_obj) },
{ MP_ROM_QSTR(MP_QSTR_capacity), MP_ROM_PTR(&mod_trezorio_SDCard_capacity_obj) },
{ MP_ROM_QSTR(MP_QSTR_block_size), MP_OBJ_NEW_SMALL_INT(SDCARD_BLOCK_SIZE) },
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mod_TrezorIO_SDCard_read_obj) },
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mod_TrezorIO_SDCard_write_obj) },
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mod_trezorio_SDCard_read_obj) },
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mod_trezorio_SDCard_write_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorIO_SDCard_locals_dict, mod_TrezorIO_SDCard_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorio_SDCard_locals_dict, mod_trezorio_SDCard_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorIO_SDCard_type = {
STATIC const mp_obj_type_t mod_trezorio_SDCard_type = {
{ &mp_type_type },
.name = MP_QSTR_SDCard,
.make_new = mod_TrezorIO_SDCard_make_new,
.locals_dict = (void*)&mod_TrezorIO_SDCard_locals_dict,
.make_new = mod_trezorio_SDCard_make_new,
.locals_dict = (void*)&mod_trezorio_SDCard_locals_dict,
};

View File

@ -11,16 +11,16 @@
#include "modtrezorio-sdcard.h"
STATIC const mp_rom_map_elem_t mp_module_TrezorIO_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_TrezorIO) },
{ MP_ROM_QSTR(MP_QSTR_SDCard), MP_ROM_PTR(&mod_TrezorIO_SDCard_type) },
STATIC const mp_rom_map_elem_t mp_module_trezorio_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorio) },
{ MP_ROM_QSTR(MP_QSTR_SDCard), MP_ROM_PTR(&mod_trezorio_SDCard_type) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_TrezorIO_globals, mp_module_TrezorIO_globals_table);
STATIC MP_DEFINE_CONST_DICT(mp_module_trezorio_globals, mp_module_trezorio_globals_table);
const mp_obj_module_t mp_module_TrezorIO = {
const mp_obj_module_t mp_module_trezorio = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&mp_module_TrezorIO_globals,
.globals = (mp_obj_dict_t*)&mp_module_trezorio_globals,
};
#endif // MICROPY_PY_TREZORIO

View File

@ -44,7 +44,7 @@ typedef struct _mp_obj_HID_t {
/// max_packet_len: int = 64) -> None:
/// '''
/// '''
STATIC mp_obj_t mod_TrezorMsg_HID_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezormsg_HID_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
STATIC const mp_arg_t allowed_args[] = {
{ MP_QSTR_iface_num, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
@ -111,14 +111,14 @@ STATIC mp_obj_t mod_TrezorMsg_HID_make_new(const mp_obj_type_t *type, size_t n_a
return MP_OBJ_FROM_PTR(o);
}
STATIC const mp_rom_map_elem_t mod_TrezorMsg_HID_locals_dict_table[] = {};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorMsg_HID_locals_dict, mod_TrezorMsg_HID_locals_dict_table);
STATIC const mp_rom_map_elem_t mod_trezormsg_HID_locals_dict_table[] = {};
STATIC MP_DEFINE_CONST_DICT(mod_trezormsg_HID_locals_dict, mod_trezormsg_HID_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorMsg_HID_type = {
STATIC const mp_obj_type_t mod_trezormsg_HID_type = {
{ &mp_type_type },
.name = MP_QSTR_HID,
.make_new = mod_TrezorMsg_HID_make_new,
.locals_dict = (void*)&mod_TrezorMsg_HID_locals_dict,
.make_new = mod_trezormsg_HID_make_new,
.locals_dict = (void*)&mod_trezormsg_HID_locals_dict,
};
/// class VCP:
@ -138,7 +138,7 @@ typedef struct _mp_obj_VCP_t {
/// ep_cmd: int) -> None:
/// '''
/// '''
STATIC mp_obj_t mod_TrezorMsg_VCP_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezormsg_VCP_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
STATIC const mp_arg_t allowed_args[] = {
{ MP_QSTR_iface_num, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
@ -197,14 +197,14 @@ STATIC mp_obj_t mod_TrezorMsg_VCP_make_new(const mp_obj_type_t *type, size_t n_a
return MP_OBJ_FROM_PTR(o);
}
STATIC const mp_rom_map_elem_t mod_TrezorMsg_VCP_locals_dict_table[] = {};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorMsg_VCP_locals_dict, mod_TrezorMsg_VCP_locals_dict_table);
STATIC const mp_rom_map_elem_t mod_trezormsg_VCP_locals_dict_table[] = {};
STATIC MP_DEFINE_CONST_DICT(mod_trezormsg_VCP_locals_dict, mod_trezormsg_VCP_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorMsg_VCP_type = {
STATIC const mp_obj_type_t mod_trezormsg_VCP_type = {
{ &mp_type_type },
.name = MP_QSTR_VCP,
.make_new = mod_TrezorMsg_VCP_make_new,
.locals_dict = (void*)&mod_TrezorMsg_VCP_locals_dict,
.make_new = mod_trezormsg_VCP_make_new,
.locals_dict = (void*)&mod_trezormsg_VCP_locals_dict,
};
/// class USB:
@ -241,7 +241,7 @@ static const char *get_0str(mp_obj_t o, size_t min_len, size_t max_len) {
/// interface_str: str = '') -> None:
/// '''
/// '''
STATIC mp_obj_t mod_TrezorMsg_USB_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezormsg_USB_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
STATIC const mp_arg_t allowed_args[] = {
{ MP_QSTR_vendor_id, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
@ -302,14 +302,14 @@ STATIC mp_obj_t mod_TrezorMsg_USB_make_new(const mp_obj_type_t *type, size_t n_a
return MP_OBJ_FROM_PTR(o);
}
STATIC const mp_rom_map_elem_t mod_TrezorMsg_USB_locals_dict_table[] = {};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorMsg_USB_locals_dict, mod_TrezorMsg_USB_locals_dict_table);
STATIC const mp_rom_map_elem_t mod_trezormsg_USB_locals_dict_table[] = {};
STATIC MP_DEFINE_CONST_DICT(mod_trezormsg_USB_locals_dict, mod_trezormsg_USB_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorMsg_USB_type = {
STATIC const mp_obj_type_t mod_trezormsg_USB_type = {
{ &mp_type_type },
.name = MP_QSTR_USB,
.make_new = mod_TrezorMsg_USB_make_new,
.locals_dict = (void*)&mod_TrezorMsg_USB_locals_dict,
.make_new = mod_trezormsg_USB_make_new,
.locals_dict = (void*)&mod_trezormsg_USB_locals_dict,
};
/// class Msg:
@ -325,7 +325,7 @@ typedef struct _mp_obj_Msg_t {
/// def __init__(self) -> None:
/// '''
/// '''
STATIC mp_obj_t mod_TrezorMsg_Msg_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezormsg_Msg_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
msg_init();
mp_obj_Msg_t *o = m_new_obj(mp_obj_Msg_t);
@ -339,7 +339,7 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_make_new(const mp_obj_type_t *type, size_t n_a
/// '''
/// Registers passed interfaces and initializes the USB stack.
/// '''
STATIC mp_obj_t mod_TrezorMsg_Msg_init_usb(mp_obj_t self, mp_obj_t usb_info, mp_obj_t usb_ifaces) {
STATIC mp_obj_t mod_trezormsg_Msg_init_usb(mp_obj_t self, mp_obj_t usb_info, mp_obj_t usb_ifaces) {
mp_obj_Msg_t *o = MP_OBJ_TO_PTR(self);
if (o->usb_info != mp_const_none || o->usb_ifaces != mp_const_none) {
@ -351,7 +351,7 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_init_usb(mp_obj_t self, mp_obj_t usb_info, mp_
mp_obj_get_array(usb_ifaces, &iface_cnt, &iface_objs);
// Initialize the USB stack
if (MP_OBJ_IS_TYPE(usb_info, &mod_TrezorMsg_USB_type)) {
if (MP_OBJ_IS_TYPE(usb_info, &mod_trezormsg_USB_type)) {
mp_obj_USB_t *usb = MP_OBJ_TO_PTR(usb_info);
if (usb_init(&usb->info) != 0) {
mp_raise_msg(&mp_type_RuntimeError, "failed to initialize USB");
@ -366,13 +366,13 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_init_usb(mp_obj_t self, mp_obj_t usb_info, mp_
for (size_t i = 0; i < iface_cnt; i++) {
mp_obj_t iface = iface_objs[i];
if (MP_OBJ_IS_TYPE(iface, &mod_TrezorMsg_HID_type)) {
if (MP_OBJ_IS_TYPE(iface, &mod_trezormsg_HID_type)) {
mp_obj_HID_t *hid = MP_OBJ_TO_PTR(iface);
if (usb_hid_add(&hid->info) != 0) {
usb_deinit();
mp_raise_msg(&mp_type_RuntimeError, "failed to add HID interface");
}
} else if (MP_OBJ_IS_TYPE(iface, &mod_TrezorMsg_VCP_type)) {
} else if (MP_OBJ_IS_TYPE(iface, &mod_trezormsg_VCP_type)) {
mp_obj_VCP_t *vcp = MP_OBJ_TO_PTR(iface);
if (usb_vcp_add(&vcp->info) != 0) {
usb_deinit();
@ -400,13 +400,13 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_init_usb(mp_obj_t self, mp_obj_t usb_info, mp_
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorMsg_Msg_init_usb_obj, mod_TrezorMsg_Msg_init_usb);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezormsg_Msg_init_usb_obj, mod_trezormsg_Msg_init_usb);
/// def deinit_usb(self) -> None:
/// '''
/// Cleans up the USB stack
/// '''
STATIC mp_obj_t mod_TrezorMsg_Msg_deinit_usb(mp_obj_t self) {
STATIC mp_obj_t mod_trezormsg_Msg_deinit_usb(mp_obj_t self) {
usb_stop();
usb_deinit();
@ -417,13 +417,13 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_deinit_usb(mp_obj_t self) {
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorMsg_Msg_deinit_usb_obj, mod_TrezorMsg_Msg_deinit_usb);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezormsg_Msg_deinit_usb_obj, mod_trezormsg_Msg_deinit_usb);
/// def send(self, iface: int, message: bytes) -> int:
/// '''
/// Sends message using USB HID (device) or UDP (emulator).
/// '''
STATIC mp_obj_t mod_TrezorMsg_Msg_send(mp_obj_t self, mp_obj_t iface, mp_obj_t message) {
STATIC mp_obj_t mod_trezormsg_Msg_send(mp_obj_t self, mp_obj_t iface, mp_obj_t message) {
// mp_obj_Msg_t *o = MP_OBJ_TO_PTR(self);
uint8_t i = mp_obj_get_int(iface);
mp_buffer_info_t msg;
@ -431,7 +431,7 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_send(mp_obj_t self, mp_obj_t iface, mp_obj_t m
ssize_t r = msg_send(i, msg.buf, msg.len);
return MP_OBJ_NEW_SMALL_INT(r);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorMsg_Msg_send_obj, mod_TrezorMsg_Msg_send);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezormsg_Msg_send_obj, mod_trezormsg_Msg_send);
#define TICK_RESOLUTION 1000
#define TOUCH_IFACE 255
@ -442,7 +442,7 @@ extern uint32_t touch_read(void); // defined in HAL
/// Polls the event queue and returns the event object.
/// Function returns None if timeout specified in microseconds is reached.
/// '''
STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_us) {
STATIC mp_obj_t mod_trezormsg_Msg_select(mp_obj_t self, mp_obj_t timeout_us) {
// mp_obj_Msg_t *o = MP_OBJ_TO_PTR(self);
int timeout = mp_obj_get_int(timeout_us);
if (timeout < 0) {
@ -475,9 +475,9 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_us) {
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorMsg_Msg_select_obj, mod_TrezorMsg_Msg_select);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezormsg_Msg_select_obj, mod_trezormsg_Msg_select);
STATIC mp_obj_t mod_TrezorMsg_Msg___del__(mp_obj_t self) {
STATIC mp_obj_t mod_trezormsg_Msg___del__(mp_obj_t self) {
mp_obj_Msg_t *o = MP_OBJ_TO_PTR(self);
if (o->usb_info != mp_const_none || o->usb_ifaces != mp_const_none) {
usb_stop();
@ -485,36 +485,36 @@ STATIC mp_obj_t mod_TrezorMsg_Msg___del__(mp_obj_t self) {
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorMsg_Msg___del___obj, mod_TrezorMsg_Msg___del__);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezormsg_Msg___del___obj, mod_trezormsg_Msg___del__);
STATIC const mp_rom_map_elem_t mod_TrezorMsg_Msg_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_TrezorMsg_Msg___del___obj) },
{ MP_ROM_QSTR(MP_QSTR_init_usb), MP_ROM_PTR(&mod_TrezorMsg_Msg_init_usb_obj) },
{ MP_ROM_QSTR(MP_QSTR_deinit_usb), MP_ROM_PTR(&mod_TrezorMsg_Msg_deinit_usb_obj) },
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&mod_TrezorMsg_Msg_send_obj) },
{ MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&mod_TrezorMsg_Msg_select_obj) },
STATIC const mp_rom_map_elem_t mod_trezormsg_Msg_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_trezormsg_Msg___del___obj) },
{ MP_ROM_QSTR(MP_QSTR_init_usb), MP_ROM_PTR(&mod_trezormsg_Msg_init_usb_obj) },
{ MP_ROM_QSTR(MP_QSTR_deinit_usb), MP_ROM_PTR(&mod_trezormsg_Msg_deinit_usb_obj) },
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&mod_trezormsg_Msg_send_obj) },
{ MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&mod_trezormsg_Msg_select_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorMsg_Msg_locals_dict, mod_TrezorMsg_Msg_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezormsg_Msg_locals_dict, mod_trezormsg_Msg_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorMsg_Msg_type = {
STATIC const mp_obj_type_t mod_trezormsg_Msg_type = {
{ &mp_type_type },
.name = MP_QSTR_Msg,
.make_new = mod_TrezorMsg_Msg_make_new,
.locals_dict = (void*)&mod_TrezorMsg_Msg_locals_dict,
.make_new = mod_trezormsg_Msg_make_new,
.locals_dict = (void*)&mod_trezormsg_Msg_locals_dict,
};
STATIC const mp_rom_map_elem_t mp_module_TrezorMsg_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_TrezorMsg) },
{ MP_ROM_QSTR(MP_QSTR_USB), MP_ROM_PTR(&mod_TrezorMsg_USB_type) },
{ MP_ROM_QSTR(MP_QSTR_HID), MP_ROM_PTR(&mod_TrezorMsg_HID_type) },
{ MP_ROM_QSTR(MP_QSTR_VCP), MP_ROM_PTR(&mod_TrezorMsg_VCP_type) },
{ MP_ROM_QSTR(MP_QSTR_Msg), MP_ROM_PTR(&mod_TrezorMsg_Msg_type) },
STATIC const mp_rom_map_elem_t mp_module_trezormsg_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezormsg) },
{ MP_ROM_QSTR(MP_QSTR_USB), MP_ROM_PTR(&mod_trezormsg_USB_type) },
{ MP_ROM_QSTR(MP_QSTR_HID), MP_ROM_PTR(&mod_trezormsg_HID_type) },
{ MP_ROM_QSTR(MP_QSTR_VCP), MP_ROM_PTR(&mod_trezormsg_VCP_type) },
{ MP_ROM_QSTR(MP_QSTR_Msg), MP_ROM_PTR(&mod_trezormsg_Msg_type) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_TrezorMsg_globals, mp_module_TrezorMsg_globals_table);
STATIC MP_DEFINE_CONST_DICT(mp_module_trezormsg_globals, mp_module_trezormsg_globals_table);
const mp_obj_module_t mp_module_TrezorMsg = {
const mp_obj_module_t mp_module_trezormsg = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&mp_module_TrezorMsg_globals,
.globals = (mp_obj_dict_t*)&mp_module_trezormsg_globals,
};
#endif // MICROPY_PY_TREZORMSG

View File

@ -21,7 +21,7 @@ typedef struct _mp_obj_Display_t {
/// '''
/// 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) {
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) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
display_init();
mp_obj_Display_t *o = m_new_obj(mp_obj_Display_t);
@ -33,27 +33,27 @@ STATIC mp_obj_t mod_TrezorUI_Display_make_new(const mp_obj_type_t *type, size_t
/// '''
/// Clear display with black color.
/// '''
STATIC mp_obj_t mod_TrezorUI_Display_clear(mp_obj_t self) {
STATIC mp_obj_t mod_trezorui_Display_clear(mp_obj_t self) {
display_clear();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorUI_Display_clear_obj, mod_TrezorUI_Display_clear);
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) {
STATIC mp_obj_t mod_trezorui_Display_refresh(mp_obj_t self) {
display_refresh();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorUI_Display_refresh_obj, mod_TrezorUI_Display_refresh);
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) {
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]);
mp_int_t w = mp_obj_get_int(args[3]);
@ -62,14 +62,14 @@ STATIC mp_obj_t mod_TrezorUI_Display_bar(size_t n_args, const mp_obj_t *args) {
display_bar(x, y, w, h, c);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_bar_obj, 6, 6, mod_TrezorUI_Display_bar);
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:
/// '''
/// 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) {
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]);
mp_int_t y = mp_obj_get_int(args[2]);
mp_int_t w = mp_obj_get_int(args[3]);
@ -80,14 +80,14 @@ STATIC mp_obj_t mod_TrezorUI_Display_bar_radius(size_t n_args, const mp_obj_t *a
display_bar_radius(x, y, w, h, c, b, r);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_bar_radius_obj, 8, 8, mod_TrezorUI_Display_bar_radius);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_bar_radius_obj, 8, 8, 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) {
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]);
mp_int_t y = mp_obj_get_int(args[2]);
mp_buffer_info_t image;
@ -105,14 +105,14 @@ STATIC mp_obj_t mod_TrezorUI_Display_image(size_t n_args, const mp_obj_t *args)
display_image(x, y, w, h, data + 12, datalen);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_image_obj, 4, 4, mod_TrezorUI_Display_image);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_image_obj, 4, 4, mod_trezorui_Display_image);
/// 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 image 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) {
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]);
mp_buffer_info_t icon;
@ -132,13 +132,13 @@ STATIC mp_obj_t mod_TrezorUI_Display_icon(size_t n_args, const mp_obj_t *args) {
display_icon(x, y, w, h, data + 12, icon.len - 12, fgcolor, bgcolor);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_icon_obj, 6, 6, mod_TrezorUI_Display_icon);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_icon_obj, 6, 6, mod_trezorui_Display_icon);
/// 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) {
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);
if (buf.len > 0) {
@ -146,14 +146,14 @@ STATIC mp_obj_t mod_TrezorUI_Display_print(mp_obj_t self, mp_obj_t text) {
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUI_Display_print_obj, mod_TrezorUI_Display_print);
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) -> None:
/// '''
/// Renders left-aligned text at position (x,y) where x is left position and y is baseline.
/// Font font is used for rendering, fgcolor is used as foreground color, bgcolor as background.
/// '''
STATIC mp_obj_t mod_TrezorUI_Display_text(size_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t mod_trezorui_Display_text(size_t n_args, const mp_obj_t *args) {
mp_int_t x = mp_obj_get_int(args[1]);
mp_int_t y = mp_obj_get_int(args[2]);
mp_buffer_info_t text;
@ -166,14 +166,14 @@ STATIC mp_obj_t mod_TrezorUI_Display_text(size_t n_args, const mp_obj_t *args) {
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_text_obj, 7, 7, mod_TrezorUI_Display_text);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_obj, 7, 7, mod_trezorui_Display_text);
/// def text_center(self, x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int) -> None:
/// '''
/// Renders text centered at position (x,y) where x is text center and y is baseline.
/// Font font is used for rendering, fgcolor is used as foreground color, bgcolor as background.
/// '''
STATIC mp_obj_t mod_TrezorUI_Display_text_center(size_t n_args, const mp_obj_t *args) {
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]);
mp_int_t y = mp_obj_get_int(args[2]);
mp_buffer_info_t text;
@ -186,14 +186,14 @@ STATIC mp_obj_t mod_TrezorUI_Display_text_center(size_t n_args, const mp_obj_t *
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_text_center_obj, 7, 7, mod_TrezorUI_Display_text_center);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_center_obj, 7, 7, mod_trezorui_Display_text_center);
/// def text_right(self, x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int) -> None:
/// '''
/// Renders right-aligned text at position (x,y) where x is right position and y is baseline.
/// Font font is used for rendering, fgcolor is used as foreground color, bgcolor as background.
/// '''
STATIC mp_obj_t mod_TrezorUI_Display_text_right(size_t n_args, const mp_obj_t *args) {
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]);
mp_int_t y = mp_obj_get_int(args[2]);
mp_buffer_info_t text;
@ -206,13 +206,13 @@ STATIC mp_obj_t mod_TrezorUI_Display_text_right(size_t n_args, const mp_obj_t *a
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_text_right_obj, 7, 7, mod_TrezorUI_Display_text_right);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_right_obj, 7, 7, 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) {
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;
mp_get_buffer_raise(text, &txt, MP_BUFFER_READ);
mp_int_t f = mp_obj_get_int(font);
@ -222,14 +222,14 @@ STATIC mp_obj_t mod_TrezorUI_Display_text_width(mp_obj_t self, mp_obj_t text, mp
}
return MP_OBJ_NEW_SMALL_INT(w);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorUI_Display_text_width_obj, mod_TrezorUI_Display_text_width);
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) {
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]);
mp_int_t y = mp_obj_get_int(args[2]);
mp_int_t scale = mp_obj_get_int(args[4]);
@ -243,7 +243,7 @@ STATIC mp_obj_t mod_TrezorUI_Display_qrcode(size_t n_args, const mp_obj_t *args)
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_qrcode_obj, 5, 5, mod_TrezorUI_Display_qrcode);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_qrcode_obj, 5, 5, mod_trezorui_Display_qrcode);
/// def loader(self, progress: int, yoffset: int, fgcolor: int, bgcolor: int, icon: bytes = None, iconfgcolor: int = None) -> None:
/// '''
@ -252,7 +252,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_qrcode_obj, 5, 5
/// 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) {
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]);
mp_int_t yoffset = mp_obj_get_int(args[2]);
mp_int_t fgcolor = mp_obj_get_int(args[3]);
@ -285,7 +285,7 @@ STATIC mp_obj_t mod_TrezorUI_Display_loader(size_t n_args, const mp_obj_t *args)
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_loader_obj, 5, 7, mod_TrezorUI_Display_loader);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_loader_obj, 5, 7, mod_trezorui_Display_loader);
/// def orientation(self, degrees: int = None) -> int:
/// '''
@ -293,7 +293,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_loader_obj, 5, 7
/// 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) {
STATIC mp_obj_t mod_trezorui_Display_orientation(size_t n_args, const mp_obj_t *args) {
mp_int_t deg;
if (n_args > 1) {
deg = mp_obj_get_int(args[1]);
@ -306,14 +306,14 @@ STATIC mp_obj_t mod_TrezorUI_Display_orientation(size_t n_args, const mp_obj_t *
}
return MP_OBJ_NEW_SMALL_INT(deg);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_orientation_obj, 1, 2, mod_TrezorUI_Display_orientation);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_orientation_obj, 1, 2, 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) {
STATIC mp_obj_t mod_trezorui_Display_backlight(size_t n_args, const mp_obj_t *args) {
mp_int_t val;
if (n_args > 1) {
val = mp_obj_get_int(args[1]);
@ -326,14 +326,14 @@ STATIC mp_obj_t mod_TrezorUI_Display_backlight(size_t n_args, const mp_obj_t *ar
}
return MP_OBJ_NEW_SMALL_INT(val);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_backlight_obj, 1, 2, mod_TrezorUI_Display_backlight);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_backlight_obj, 1, 2, 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) {
STATIC mp_obj_t mod_trezorui_Display_offset(size_t n_args, const mp_obj_t *args) {
int xy[2], *ret;
if (n_args > 1) {
size_t xy_cnt;
@ -358,13 +358,13 @@ STATIC mp_obj_t mod_TrezorUI_Display_offset(size_t n_args, const mp_obj_t *args)
return MP_OBJ_FROM_PTR(tuple);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_offset_obj, 1, 2, mod_TrezorUI_Display_offset);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_offset_obj, 1, 2, mod_trezorui_Display_offset);
/// def save(self, filename: str) -> None:
/// '''
/// Saves current display contents to file filename.
/// '''
STATIC mp_obj_t mod_TrezorUI_Display_save(mp_obj_t self, mp_obj_t filename) {
STATIC mp_obj_t mod_trezorui_Display_save(mp_obj_t self, mp_obj_t filename) {
mp_buffer_info_t fn;
mp_get_buffer_raise(filename, &fn, MP_BUFFER_READ);
if (fn.len > 0) {
@ -372,35 +372,35 @@ STATIC mp_obj_t mod_TrezorUI_Display_save(mp_obj_t self, mp_obj_t filename) {
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUI_Display_save_obj, mod_TrezorUI_Display_save);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorui_Display_save_obj, mod_trezorui_Display_save);
STATIC const mp_rom_map_elem_t mod_TrezorUI_Display_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&mod_TrezorUI_Display_clear_obj) },
{ MP_ROM_QSTR(MP_QSTR_refresh), MP_ROM_PTR(&mod_TrezorUI_Display_refresh_obj) },
{ MP_ROM_QSTR(MP_QSTR_bar), MP_ROM_PTR(&mod_TrezorUI_Display_bar_obj) },
{ MP_ROM_QSTR(MP_QSTR_bar_radius), MP_ROM_PTR(&mod_TrezorUI_Display_bar_radius_obj) },
{ MP_ROM_QSTR(MP_QSTR_image), MP_ROM_PTR(&mod_TrezorUI_Display_image_obj) },
{ MP_ROM_QSTR(MP_QSTR_icon), MP_ROM_PTR(&mod_TrezorUI_Display_icon_obj) },
{ MP_ROM_QSTR(MP_QSTR_print), MP_ROM_PTR(&mod_TrezorUI_Display_print_obj) },
{ MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&mod_TrezorUI_Display_text_obj) },
{ MP_ROM_QSTR(MP_QSTR_text_center), MP_ROM_PTR(&mod_TrezorUI_Display_text_center_obj) },
{ MP_ROM_QSTR(MP_QSTR_text_right), MP_ROM_PTR(&mod_TrezorUI_Display_text_right_obj) },
{ MP_ROM_QSTR(MP_QSTR_text_width), MP_ROM_PTR(&mod_TrezorUI_Display_text_width_obj) },
{ MP_ROM_QSTR(MP_QSTR_qrcode), MP_ROM_PTR(&mod_TrezorUI_Display_qrcode_obj) },
{ MP_ROM_QSTR(MP_QSTR_loader), MP_ROM_PTR(&mod_TrezorUI_Display_loader_obj) },
{ MP_ROM_QSTR(MP_QSTR_orientation), MP_ROM_PTR(&mod_TrezorUI_Display_orientation_obj) },
{ MP_ROM_QSTR(MP_QSTR_backlight), MP_ROM_PTR(&mod_TrezorUI_Display_backlight_obj) },
{ MP_ROM_QSTR(MP_QSTR_offset), MP_ROM_PTR(&mod_TrezorUI_Display_offset_obj) },
{ MP_ROM_QSTR(MP_QSTR_save), MP_ROM_PTR(&mod_TrezorUI_Display_save_obj) },
STATIC const mp_rom_map_elem_t mod_trezorui_Display_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&mod_trezorui_Display_clear_obj) },
{ MP_ROM_QSTR(MP_QSTR_refresh), MP_ROM_PTR(&mod_trezorui_Display_refresh_obj) },
{ MP_ROM_QSTR(MP_QSTR_bar), MP_ROM_PTR(&mod_trezorui_Display_bar_obj) },
{ MP_ROM_QSTR(MP_QSTR_bar_radius), MP_ROM_PTR(&mod_trezorui_Display_bar_radius_obj) },
{ MP_ROM_QSTR(MP_QSTR_image), MP_ROM_PTR(&mod_trezorui_Display_image_obj) },
{ MP_ROM_QSTR(MP_QSTR_icon), MP_ROM_PTR(&mod_trezorui_Display_icon_obj) },
{ MP_ROM_QSTR(MP_QSTR_print), MP_ROM_PTR(&mod_trezorui_Display_print_obj) },
{ MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&mod_trezorui_Display_text_obj) },
{ MP_ROM_QSTR(MP_QSTR_text_center), MP_ROM_PTR(&mod_trezorui_Display_text_center_obj) },
{ MP_ROM_QSTR(MP_QSTR_text_right), MP_ROM_PTR(&mod_trezorui_Display_text_right_obj) },
{ MP_ROM_QSTR(MP_QSTR_text_width), MP_ROM_PTR(&mod_trezorui_Display_text_width_obj) },
{ MP_ROM_QSTR(MP_QSTR_qrcode), MP_ROM_PTR(&mod_trezorui_Display_qrcode_obj) },
{ MP_ROM_QSTR(MP_QSTR_loader), MP_ROM_PTR(&mod_trezorui_Display_loader_obj) },
{ MP_ROM_QSTR(MP_QSTR_orientation), MP_ROM_PTR(&mod_trezorui_Display_orientation_obj) },
{ MP_ROM_QSTR(MP_QSTR_backlight), MP_ROM_PTR(&mod_trezorui_Display_backlight_obj) },
{ MP_ROM_QSTR(MP_QSTR_offset), MP_ROM_PTR(&mod_trezorui_Display_offset_obj) },
{ MP_ROM_QSTR(MP_QSTR_save), MP_ROM_PTR(&mod_trezorui_Display_save_obj) },
{ MP_ROM_QSTR(MP_QSTR_FONT_MONO), MP_OBJ_NEW_SMALL_INT(FONT_MONO) },
{ MP_ROM_QSTR(MP_QSTR_FONT_NORMAL), MP_OBJ_NEW_SMALL_INT(FONT_NORMAL) },
{ MP_ROM_QSTR(MP_QSTR_FONT_BOLD), MP_OBJ_NEW_SMALL_INT(FONT_BOLD) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorUI_Display_locals_dict, mod_TrezorUI_Display_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(mod_trezorui_Display_locals_dict, mod_trezorui_Display_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorUI_Display_type = {
STATIC const mp_obj_type_t mod_trezorui_Display_type = {
{ &mp_type_type },
.name = MP_QSTR_Display,
.make_new = mod_TrezorUI_Display_make_new,
.locals_dict = (void*)&mod_TrezorUI_Display_locals_dict,
.make_new = mod_trezorui_Display_make_new,
.locals_dict = (void*)&mod_trezorui_Display_locals_dict,
};

View File

@ -15,16 +15,16 @@
#include "modtrezorui-display.h"
STATIC const mp_rom_map_elem_t mp_module_TrezorUI_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_TrezorUI) },
{ MP_ROM_QSTR(MP_QSTR_Display), MP_ROM_PTR(&mod_TrezorUI_Display_type) },
STATIC const mp_rom_map_elem_t mp_module_trezorui_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorui) },
{ MP_ROM_QSTR(MP_QSTR_Display), MP_ROM_PTR(&mod_trezorui_Display_type) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_TrezorUI_globals, mp_module_TrezorUI_globals_table);
STATIC MP_DEFINE_CONST_DICT(mp_module_trezorui_globals, mp_module_trezorui_globals_table);
const mp_obj_module_t mp_module_TrezorUI = {
const mp_obj_module_t mp_module_trezorui = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&mp_module_TrezorUI_globals,
.globals = (mp_obj_dict_t*)&mp_module_trezorui_globals,
};
#endif // MICROPY_PY_TREZORUI

View File

@ -20,7 +20,7 @@
/// `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) {
STATIC mp_obj_t mod_trezorutils_memcpy(size_t n_args, const mp_obj_t *args) {
mp_arg_check_num(n_args, 0, 5, 5, false);
mp_buffer_info_t dst;
@ -49,13 +49,13 @@ STATIC mp_obj_t mod_TrezorUtils_memcpy(size_t n_args, const mp_obj_t *args) {
return mp_obj_new_int(ncpy);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUtils_memcpy_obj, 5, 5, mod_TrezorUtils_memcpy);
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) {
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)) {
__fatal_error(msg.buf, __FILE__, __LINE__, __FUNCTION__);
@ -64,19 +64,19 @@ STATIC mp_obj_t mod_TrezorUtils_halt(size_t n_args, const mp_obj_t *args) {
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUtils_halt_obj, 0, 1, mod_TrezorUtils_halt);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorutils_halt_obj, 0, 1, mod_trezorutils_halt);
STATIC const mp_rom_map_elem_t mp_module_TrezorUtils_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_TrezorUtils) },
{ MP_ROM_QSTR(MP_QSTR_memcpy), MP_ROM_PTR(&mod_TrezorUtils_memcpy_obj) },
{ MP_ROM_QSTR(MP_QSTR_halt), MP_ROM_PTR(&mod_TrezorUtils_halt_obj) },
STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorutils) },
{ MP_ROM_QSTR(MP_QSTR_memcpy), MP_ROM_PTR(&mod_trezorutils_memcpy_obj) },
{ MP_ROM_QSTR(MP_QSTR_halt), MP_ROM_PTR(&mod_trezorutils_halt_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_TrezorUtils_globals, mp_module_TrezorUtils_globals_table);
STATIC MP_DEFINE_CONST_DICT(mp_module_trezorutils_globals, mp_module_trezorutils_globals_table);
const mp_obj_module_t mp_module_TrezorUtils = {
const mp_obj_module_t mp_module_trezorutils = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&mp_module_TrezorUtils_globals,
.globals = (mp_obj_dict_t*)&mp_module_trezorutils_globals,
};
#endif // MICROPY_PY_TREZORUTILS

View File

@ -123,21 +123,21 @@
// extra built in modules to add to the list of known ones
extern const struct _mp_obj_module_t mp_module_utime;
extern const struct _mp_obj_module_t mp_module_TrezorConfig;
extern const struct _mp_obj_module_t mp_module_TrezorCrypto;
extern const struct _mp_obj_module_t mp_module_TrezorIO;
extern const struct _mp_obj_module_t mp_module_TrezorMsg;
extern const struct _mp_obj_module_t mp_module_TrezorUI;
extern const struct _mp_obj_module_t mp_module_TrezorUtils;
extern const struct _mp_obj_module_t mp_module_trezorconfig;
extern const struct _mp_obj_module_t mp_module_trezorcrypto;
extern const struct _mp_obj_module_t mp_module_trezorio;
extern const struct _mp_obj_module_t mp_module_trezormsg;
extern const struct _mp_obj_module_t mp_module_trezorui;
extern const struct _mp_obj_module_t mp_module_trezorutils;
#define MICROPY_PORT_BUILTIN_MODULES \
{ MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&mp_module_utime }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_TrezorConfig), (mp_obj_t)&mp_module_TrezorConfig }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_TrezorCrypto), (mp_obj_t)&mp_module_TrezorCrypto }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_TrezorIO), (mp_obj_t)&mp_module_TrezorIO }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_TrezorMsg), (mp_obj_t)&mp_module_TrezorMsg }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_TrezorUI), (mp_obj_t)&mp_module_TrezorUI }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_TrezorUtils), (mp_obj_t)&mp_module_TrezorUtils },
{ MP_OBJ_NEW_QSTR(MP_QSTR_trezorconfig), (mp_obj_t)&mp_module_trezorconfig }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_trezorcrypto), (mp_obj_t)&mp_module_trezorcrypto }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_trezorio), (mp_obj_t)&mp_module_trezorio }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_trezormsg), (mp_obj_t)&mp_module_trezormsg }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_trezorui), (mp_obj_t)&mp_module_trezorui }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_trezorutils), (mp_obj_t)&mp_module_trezorutils },
#define MP_STATE_PORT MP_STATE_VM

View File

@ -178,12 +178,12 @@ extern const struct _mp_obj_module_t mp_module_socket;
extern const struct _mp_obj_module_t mp_module_ffi;
extern const struct _mp_obj_module_t mp_module_jni;
extern const struct _mp_obj_module_t mp_module_TrezorConfig;
extern const struct _mp_obj_module_t mp_module_TrezorCrypto;
extern const struct _mp_obj_module_t mp_module_TrezorIO;
extern const struct _mp_obj_module_t mp_module_TrezorMsg;
extern const struct _mp_obj_module_t mp_module_TrezorUI;
extern const struct _mp_obj_module_t mp_module_TrezorUtils;
extern const struct _mp_obj_module_t mp_module_trezorconfig;
extern const struct _mp_obj_module_t mp_module_trezorcrypto;
extern const struct _mp_obj_module_t mp_module_trezorio;
extern const struct _mp_obj_module_t mp_module_trezormsg;
extern const struct _mp_obj_module_t mp_module_trezorui;
extern const struct _mp_obj_module_t mp_module_trezorutils;
#if MICROPY_PY_UOS_VFS
#define MICROPY_PY_UOS_VFS_DEF { MP_ROM_QSTR(MP_QSTR_uos_vfs), MP_ROM_PTR(&mp_module_uos_vfs) },
@ -222,32 +222,32 @@ extern const struct _mp_obj_module_t mp_module_TrezorUtils;
#endif
#if MICROPY_PY_TREZORCONFIG
#define MICROPY_PY_TREZORCONFIG_DEF { MP_ROM_QSTR(MP_QSTR_TrezorConfig), MP_ROM_PTR(&mp_module_TrezorConfig) },
#define MICROPY_PY_TREZORCONFIG_DEF { MP_ROM_QSTR(MP_QSTR_trezorconfig), MP_ROM_PTR(&mp_module_trezorconfig) },
#else
#define MICROPY_PY_TREZORCONFIG_DEF
#endif
#if MICROPY_PY_TREZORCRYPTO
#define MICROPY_PY_TREZORCRYPTO_DEF { MP_ROM_QSTR(MP_QSTR_TrezorCrypto), MP_ROM_PTR(&mp_module_TrezorCrypto) },
#define MICROPY_PY_TREZORCRYPTO_DEF { MP_ROM_QSTR(MP_QSTR_trezorcrypto), MP_ROM_PTR(&mp_module_trezorcrypto) },
#else
#define MICROPY_PY_TREZORCRYPTO_DEF
#endif
#if MICROPY_PY_TREZORIO
#define MICROPY_PY_TREZORIO_DEF { MP_ROM_QSTR(MP_QSTR_TrezorIO), MP_ROM_PTR(&mp_module_TrezorIO) },
#define MICROPY_PY_TREZORIO_DEF { MP_ROM_QSTR(MP_QSTR_trezorio), MP_ROM_PTR(&mp_module_trezorio) },
#else
#define MICROPY_PY_TREZORIO_DEF
#endif
#if MICROPY_PY_TREZORMSG
#define MICROPY_PY_TREZORMSG_DEF { MP_ROM_QSTR(MP_QSTR_TrezorMsg), MP_ROM_PTR(&mp_module_TrezorMsg) },
#define MICROPY_PY_TREZORMSG_DEF { MP_ROM_QSTR(MP_QSTR_trezormsg), MP_ROM_PTR(&mp_module_trezormsg) },
#else
#define MICROPY_PY_TREZORMSG_DEF
#endif
#if MICROPY_PY_TREZORUI
#define MICROPY_PY_TREZORUI_DEF { MP_ROM_QSTR(MP_QSTR_TrezorUI), MP_ROM_PTR(&mp_module_TrezorUI) },
#define MICROPY_PY_TREZORUI_DEF { MP_ROM_QSTR(MP_QSTR_trezorui), MP_ROM_PTR(&mp_module_trezorui) },
#else
#define MICROPY_PY_TREZORUI_DEF
#endif
#if MICROPY_PY_TREZORUTILS
#define MICROPY_PY_TREZORUTILS_DEF { MP_ROM_QSTR(MP_QSTR_TrezorUtils), MP_ROM_PTR(&mp_module_TrezorUtils) },
#define MICROPY_PY_TREZORUTILS_DEF { MP_ROM_QSTR(MP_QSTR_trezorutils), MP_ROM_PTR(&mp_module_trezorutils) },
#else
#define MICROPY_PY_TREZORUTILS_DEF
#endif

View File

@ -1,4 +1,4 @@
from TrezorConfig import Config
from trezorconfig import Config
_config = Config()

View File

@ -1,9 +1,9 @@
from TrezorCrypto import Bip32
from TrezorCrypto import Bip39
from TrezorCrypto import Pbkdf2 as pbkdf2
from TrezorCrypto import Rfc6979 as rfc6979
from TrezorCrypto import Random
from TrezorCrypto import SSSS
from trezorcrypto import Bip32
from trezorcrypto import Bip39
from trezorcrypto import Pbkdf2 as pbkdf2
from trezorcrypto import Rfc6979 as rfc6979
from trezorcrypto import Random
from trezorcrypto import SSSS
bip32 = Bip32()
bip39 = Bip39()

View File

@ -1,4 +1,4 @@
from TrezorCrypto import AES
from trezorcrypto import AES
def AES_ECB_Encrypt(key: bytes) -> AES:

View File

@ -1,7 +1,7 @@
from TrezorCrypto import Curve25519
from TrezorCrypto import Ed25519
from TrezorCrypto import Nist256p1
from TrezorCrypto import Secp256k1
from trezorcrypto import Curve25519
from trezorcrypto import Ed25519
from trezorcrypto import Nist256p1
from trezorcrypto import Secp256k1
curve25519 = Curve25519()
ed25519 = Ed25519()

View File

@ -1,8 +1,8 @@
from TrezorCrypto import Blake2b as blake2b
from TrezorCrypto import Blake2s as blake2s
from TrezorCrypto import Ripemd160 as ripemd160
from TrezorCrypto import Sha1 as sha1
from TrezorCrypto import Sha256 as sha256
from TrezorCrypto import Sha512 as sha512
from TrezorCrypto import Sha3_256 as sha3_256
from TrezorCrypto import Sha3_512 as sha3_512
from trezorcrypto import Blake2b as blake2b
from trezorcrypto import Blake2s as blake2s
from trezorcrypto import Ripemd160 as ripemd160
from trezorcrypto import Sha1 as sha1
from trezorcrypto import Sha256 as sha256
from trezorcrypto import Sha512 as sha512
from trezorcrypto import Sha3_256 as sha3_256
from trezorcrypto import Sha3_512 as sha3_512

View File

@ -1 +1 @@
from TrezorIO import SDCard
from trezorio import SDCard

View File

@ -1,4 +1,4 @@
from TrezorMsg import Msg, USB, HID, VCP
from trezormsg import Msg, USB, HID, VCP
_msg = Msg()

View File

@ -4,7 +4,7 @@ import sys
import math
import utime
from TrezorUI import Display
from trezorui import Display
from trezor import loop, res
display = Display()

View File

@ -1,8 +1,7 @@
import sys
import gc
from TrezorUtils import halt, memcpy
from trezor import log
from trezorutils import halt, memcpy
type_gen = type((lambda: (yield))())
type_genfunc = type((lambda: (yield)))