mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-27 08:38:07 +00:00
core/extmod: explicitly initialize automatic variables
This commit is contained in:
parent
fb583cf0fa
commit
59002118c0
@ -36,7 +36,7 @@ STATIC mp_obj_t ui_wait_callback = mp_const_none;
|
||||
STATIC secbool wrapped_ui_wait_callback(uint32_t wait, uint32_t progress,
|
||||
const char *message) {
|
||||
if (mp_obj_is_callable(ui_wait_callback)) {
|
||||
mp_obj_t args[3];
|
||||
mp_obj_t args[3] = {0};
|
||||
args[0] = mp_obj_new_int(wait);
|
||||
args[1] = mp_obj_new_int(progress);
|
||||
args[2] = mp_obj_new_str(message, strlen(message));
|
||||
@ -74,7 +74,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_init_obj, 0, 1,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorconfig_unlock(mp_obj_t pin, mp_obj_t ext_salt) {
|
||||
uint32_t pin_i = trezor_obj_get_uint(pin);
|
||||
mp_buffer_info_t ext_salt_b;
|
||||
mp_buffer_info_t ext_salt_b = {0};
|
||||
ext_salt_b.buf = NULL;
|
||||
if (ext_salt != mp_const_none) {
|
||||
mp_get_buffer_raise(ext_salt, &ext_salt_b, MP_BUFFER_READ);
|
||||
@ -161,7 +161,7 @@ STATIC mp_obj_t mod_trezorconfig_change_pin(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
uint32_t oldpin = trezor_obj_get_uint(args[0]);
|
||||
uint32_t newpin = trezor_obj_get_uint(args[1]);
|
||||
mp_buffer_info_t ext_salt_b;
|
||||
mp_buffer_info_t ext_salt_b = {0};
|
||||
const uint8_t *old_ext_salt = NULL;
|
||||
if (args[2] != mp_const_none) {
|
||||
mp_get_buffer_raise(args[2], &ext_salt_b, MP_BUFFER_READ);
|
||||
@ -223,7 +223,7 @@ STATIC mp_obj_t mod_trezorconfig_change_wipe_code(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
uint32_t pin = trezor_obj_get_uint(args[0]);
|
||||
uint32_t wipe_code = trezor_obj_get_uint(args[2]);
|
||||
mp_buffer_info_t ext_salt_b;
|
||||
mp_buffer_info_t ext_salt_b = {0};
|
||||
const uint8_t *ext_salt = NULL;
|
||||
if (args[1] != mp_const_none) {
|
||||
mp_get_buffer_raise(args[1], &ext_salt_b, MP_BUFFER_READ);
|
||||
@ -261,7 +261,7 @@ STATIC mp_obj_t mod_trezorconfig_get(size_t n_args, const mp_obj_t *args) {
|
||||
if (len == 0) {
|
||||
return mp_const_empty_bytes;
|
||||
}
|
||||
vstr_t vstr;
|
||||
vstr_t vstr = {0};
|
||||
vstr_init_len(&vstr, len);
|
||||
if (sectrue != storage_get(appkey, vstr.buf, vstr.len, &len)) {
|
||||
vstr_clear(&vstr);
|
||||
|
@ -63,14 +63,14 @@ STATIC mp_obj_t mod_trezorcrypto_AES_make_new(const mp_obj_type_t *type,
|
||||
if (o->mode < ECB || o->mode > CTR) {
|
||||
mp_raise_ValueError("Invalid AES mode");
|
||||
}
|
||||
mp_buffer_info_t key;
|
||||
mp_buffer_info_t key = {0};
|
||||
mp_get_buffer_raise(args[1], &key, MP_BUFFER_READ);
|
||||
if (key.len != 16 && key.len != 24 && key.len != 32) {
|
||||
mp_raise_ValueError(
|
||||
"Invalid length of key (has to be 128, 192 or 256 bits)");
|
||||
}
|
||||
if (n_args > 2) {
|
||||
mp_buffer_info_t iv;
|
||||
mp_buffer_info_t iv = {0};
|
||||
mp_get_buffer_raise(args[2], &iv, MP_BUFFER_READ);
|
||||
if (iv.len != AES_BLOCK_SIZE) {
|
||||
mp_raise_ValueError(
|
||||
@ -98,12 +98,12 @@ STATIC mp_obj_t mod_trezorcrypto_AES_make_new(const mp_obj_type_t *type,
|
||||
}
|
||||
|
||||
static mp_obj_t aes_update(mp_obj_t self, mp_obj_t data, bool encrypt) {
|
||||
mp_buffer_info_t buf;
|
||||
mp_buffer_info_t buf = {0};
|
||||
mp_get_buffer_raise(data, &buf, MP_BUFFER_READ);
|
||||
if (buf.len == 0) {
|
||||
return mp_const_empty_bytes;
|
||||
}
|
||||
vstr_t vstr;
|
||||
vstr_t vstr = {0};
|
||||
vstr_init_len(&vstr, buf.len);
|
||||
mp_obj_AES_t *o = MP_OBJ_TO_PTR(self);
|
||||
switch (o->mode) {
|
||||
|
@ -84,14 +84,14 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_make_new(const mp_obj_type_t *type,
|
||||
MP_ARG_KW_ONLY | MP_ARG_OBJ,
|
||||
{.u_obj = mp_const_empty_bytes}},
|
||||
};
|
||||
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)] = {0};
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args),
|
||||
allowed_args, vals);
|
||||
|
||||
mp_buffer_info_t chain_code;
|
||||
mp_buffer_info_t private_key;
|
||||
mp_buffer_info_t public_key;
|
||||
mp_buffer_info_t curve_name;
|
||||
mp_buffer_info_t chain_code = {0};
|
||||
mp_buffer_info_t private_key = {0};
|
||||
mp_buffer_info_t public_key = {0};
|
||||
mp_buffer_info_t curve_name = {0};
|
||||
const uint32_t depth = trezor_obj_get_uint(vals[0].u_obj);
|
||||
const uint32_t fingerprint = trezor_obj_get_uint(vals[1].u_obj);
|
||||
const uint32_t child_num = trezor_obj_get_uint(vals[2].u_obj);
|
||||
@ -159,7 +159,7 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_derive(size_t n_args,
|
||||
uint32_t fp = hdnode_fingerprint(&o->hdnode);
|
||||
bool public = n_args > 2 && args[2] == mp_const_true;
|
||||
|
||||
int res;
|
||||
int res = 0;
|
||||
if (public) {
|
||||
res = hdnode_public_ckd(&o->hdnode, i);
|
||||
} else {
|
||||
@ -198,7 +198,7 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_derive_cardano(mp_obj_t self,
|
||||
uint32_t i = mp_obj_get_int_truncated(index);
|
||||
uint32_t fp = hdnode_fingerprint(&o->hdnode);
|
||||
|
||||
int res;
|
||||
int res = 0;
|
||||
// same as in derive
|
||||
if (0 ==
|
||||
memcmp(o->hdnode.private_key,
|
||||
@ -233,8 +233,8 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_derive_path(mp_obj_t self,
|
||||
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
|
||||
|
||||
// get path objects and length
|
||||
size_t plen;
|
||||
mp_obj_t *pitems;
|
||||
size_t plen = 0;
|
||||
mp_obj_t *pitems = NULL;
|
||||
mp_obj_get_array(path, &plen, &pitems);
|
||||
if (plen > 32) {
|
||||
mp_raise_ValueError("Path cannot be longer than 32 indexes");
|
||||
@ -423,29 +423,29 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_nem_encrypt(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(args[0]);
|
||||
|
||||
mp_buffer_info_t transfer_pk;
|
||||
mp_buffer_info_t transfer_pk = {0};
|
||||
mp_get_buffer_raise(args[1], &transfer_pk, MP_BUFFER_READ);
|
||||
if (transfer_pk.len != 32) {
|
||||
mp_raise_ValueError("transfer_public_key has invalid length");
|
||||
}
|
||||
|
||||
mp_buffer_info_t iv;
|
||||
mp_buffer_info_t iv = {0};
|
||||
mp_get_buffer_raise(args[2], &iv, MP_BUFFER_READ);
|
||||
if (iv.len != 16) {
|
||||
mp_raise_ValueError("iv has invalid length");
|
||||
}
|
||||
mp_buffer_info_t salt;
|
||||
mp_buffer_info_t salt = {0};
|
||||
mp_get_buffer_raise(args[3], &salt, MP_BUFFER_READ);
|
||||
if (salt.len != NEM_SALT_SIZE) {
|
||||
mp_raise_ValueError("salt has invalid length");
|
||||
}
|
||||
mp_buffer_info_t payload;
|
||||
mp_buffer_info_t payload = {0};
|
||||
mp_get_buffer_raise(args[4], &payload, MP_BUFFER_READ);
|
||||
if (payload.len == 0) {
|
||||
mp_raise_ValueError("payload is empty");
|
||||
}
|
||||
|
||||
vstr_t vstr;
|
||||
vstr_t vstr = {0};
|
||||
vstr_init_len(&vstr, NEM_ENCRYPTED_SIZE(payload.len));
|
||||
if (!hdnode_nem_encrypt(
|
||||
&o->hdnode, *(const ed25519_public_key *)transfer_pk.buf, iv.buf,
|
||||
@ -465,7 +465,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
STATIC mp_obj_t mod_trezorcrypto_HDNode_ethereum_pubkeyhash(mp_obj_t self) {
|
||||
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
|
||||
|
||||
uint8_t pkh[20];
|
||||
uint8_t pkh[20] = {0};
|
||||
hdnode_get_ethereum_pubkeyhash(&o->hdnode, pkh);
|
||||
return mp_obj_new_bytes(pkh, sizeof(pkh));
|
||||
}
|
||||
@ -546,18 +546,18 @@ STATIC const mp_obj_type_t mod_trezorcrypto_HDNode_type = {
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_bip32_from_seed(mp_obj_t seed,
|
||||
mp_obj_t curve_name) {
|
||||
mp_buffer_info_t seedb;
|
||||
mp_buffer_info_t seedb = {0};
|
||||
mp_get_buffer_raise(seed, &seedb, MP_BUFFER_READ);
|
||||
if (seedb.len == 0) {
|
||||
mp_raise_ValueError("Invalid seed");
|
||||
}
|
||||
mp_buffer_info_t curveb;
|
||||
mp_buffer_info_t curveb = {0};
|
||||
mp_get_buffer_raise(curve_name, &curveb, MP_BUFFER_READ);
|
||||
if (curveb.len == 0) {
|
||||
mp_raise_ValueError("Invalid curve name");
|
||||
}
|
||||
|
||||
HDNode hdnode;
|
||||
HDNode hdnode = {0};
|
||||
int res = 0;
|
||||
if (strcmp(curveb.buf, ED25519_CARDANO_NAME) != 0) {
|
||||
res = hdnode_from_seed(seedb.buf, seedb.len, curveb.buf, &hdnode);
|
||||
@ -589,14 +589,14 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_bip32_from_seed_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_bip32_from_mnemonic_cardano(
|
||||
mp_obj_t mnemonic, mp_obj_t passphrase) {
|
||||
mp_buffer_info_t mnemo, phrase;
|
||||
mp_buffer_info_t mnemo = {0}, phrase = {0};
|
||||
mp_get_buffer_raise(mnemonic, &mnemo, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(passphrase, &phrase, MP_BUFFER_READ);
|
||||
HDNode hdnode;
|
||||
HDNode hdnode = {0};
|
||||
const char *pmnemonic = mnemo.len > 0 ? mnemo.buf : "";
|
||||
const char *ppassphrase = phrase.len > 0 ? phrase.buf : "";
|
||||
|
||||
uint8_t entropy[64];
|
||||
uint8_t entropy[64] = {0};
|
||||
int entropy_len = mnemonic_to_entropy(pmnemonic, entropy);
|
||||
|
||||
if (entropy_len == 0) {
|
||||
|
@ -29,7 +29,7 @@
|
||||
/// Return the first word from the wordlist starting with prefix.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_bip39_complete_word(mp_obj_t prefix) {
|
||||
mp_buffer_info_t pfx;
|
||||
mp_buffer_info_t pfx = {0};
|
||||
mp_get_buffer_raise(prefix, &pfx, MP_BUFFER_READ);
|
||||
if (pfx.len == 0) {
|
||||
return mp_const_none;
|
||||
@ -51,7 +51,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip39_complete_word_obj,
|
||||
/// lowest, etc.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_bip39_word_completion_mask(mp_obj_t prefix) {
|
||||
mp_buffer_info_t pfx;
|
||||
mp_buffer_info_t pfx = {0};
|
||||
mp_get_buffer_raise(prefix, &pfx, MP_BUFFER_READ);
|
||||
return mp_obj_new_int(mnemonic_word_completion_mask(pfx.buf, pfx.len));
|
||||
}
|
||||
@ -84,7 +84,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip39_generate_obj,
|
||||
/// Generate a mnemonic from given data (of 16, 20, 24, 28 and 32 bytes).
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_bip39_from_data(mp_obj_t data) {
|
||||
mp_buffer_info_t bin;
|
||||
mp_buffer_info_t bin = {0};
|
||||
mp_get_buffer_raise(data, &bin, MP_BUFFER_READ);
|
||||
if (bin.len % 4 || bin.len < 16 || bin.len > 32) {
|
||||
mp_raise_ValueError(
|
||||
@ -104,7 +104,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip39_from_data_obj,
|
||||
/// Check whether given mnemonic is valid.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_bip39_check(mp_obj_t mnemonic) {
|
||||
mp_buffer_info_t text;
|
||||
mp_buffer_info_t text = {0};
|
||||
mp_get_buffer_raise(mnemonic, &text, MP_BUFFER_READ);
|
||||
return (text.len > 0 && mnemonic_check(text.buf)) ? mp_const_true
|
||||
: mp_const_false;
|
||||
@ -131,11 +131,11 @@ STATIC void wrapped_ui_wait_callback(uint32_t current, uint32_t total) {
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_bip39_seed(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_buffer_info_t mnemo;
|
||||
mp_buffer_info_t phrase;
|
||||
mp_buffer_info_t mnemo = {0};
|
||||
mp_buffer_info_t phrase = {0};
|
||||
mp_get_buffer_raise(args[0], &mnemo, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(args[1], &phrase, MP_BUFFER_READ);
|
||||
uint8_t seed[64];
|
||||
uint8_t seed[64] = {0};
|
||||
const char *pmnemonic = mnemo.len > 0 ? mnemo.buf : "";
|
||||
const char *ppassphrase = phrase.len > 0 ? phrase.buf : "";
|
||||
if (n_args > 2) {
|
||||
|
@ -61,7 +61,7 @@ STATIC mp_obj_t mod_trezorcrypto_Blake256_make_new(const mp_obj_type_t *type,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Blake256_update(mp_obj_t self, mp_obj_t data) {
|
||||
mp_obj_Blake256_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t msg;
|
||||
mp_buffer_info_t msg = {0};
|
||||
mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
|
||||
if (msg.len > 0) {
|
||||
blake256_Update(&(o->ctx), msg.buf, msg.len);
|
||||
@ -77,8 +77,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Blake256_update_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Blake256_digest(mp_obj_t self) {
|
||||
mp_obj_Blake256_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t hash[BLAKE256_DIGEST_LENGTH];
|
||||
BLAKE256_CTX ctx;
|
||||
uint8_t hash[BLAKE256_DIGEST_LENGTH] = {0};
|
||||
BLAKE256_CTX ctx = {0};
|
||||
memcpy(&ctx, &(o->ctx), sizeof(BLAKE256_CTX));
|
||||
blake256_Final(&ctx, hash);
|
||||
memzero(&ctx, sizeof(BLAKE256_CTX));
|
||||
|
@ -64,18 +64,18 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2b_make_new(const mp_obj_type_t *type,
|
||||
MP_ARG_KW_ONLY | MP_ARG_OBJ,
|
||||
{.u_obj = mp_const_empty_bytes}},
|
||||
};
|
||||
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)] = {0};
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args),
|
||||
allowed_args, vals);
|
||||
|
||||
size_t data_len;
|
||||
size_t data_len = 0;
|
||||
const uint8_t *data =
|
||||
(const uint8_t *)mp_obj_str_get_data(vals[0].u_obj, &data_len);
|
||||
const mp_int_t outlen = vals[1].u_int;
|
||||
size_t key_len;
|
||||
size_t key_len = 0;
|
||||
const uint8_t *key =
|
||||
(const uint8_t *)mp_obj_str_get_data(vals[2].u_obj, &key_len);
|
||||
size_t personal_len;
|
||||
size_t personal_len = 0;
|
||||
const uint8_t *personal =
|
||||
(const uint8_t *)mp_obj_str_get_data(vals[3].u_obj, &personal_len);
|
||||
|
||||
@ -115,7 +115,7 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2b_make_new(const mp_obj_type_t *type,
|
||||
/// """
|
||||
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_buffer_info_t msg = {0};
|
||||
mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
|
||||
if (msg.len > 0) {
|
||||
blake2b_Update(&(o->ctx), msg.buf, msg.len);
|
||||
@ -131,8 +131,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Blake2b_update_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Blake2b_digest(mp_obj_t self) {
|
||||
mp_obj_Blake2b_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t out[BLAKE2B_DIGEST_LENGTH];
|
||||
BLAKE2B_CTX ctx;
|
||||
uint8_t out[BLAKE2B_DIGEST_LENGTH] = {0};
|
||||
BLAKE2B_CTX ctx = {0};
|
||||
memcpy(&ctx, &(o->ctx), sizeof(BLAKE2B_CTX));
|
||||
blake2b_Final(&ctx, out, ctx.outlen);
|
||||
memzero(&ctx, sizeof(BLAKE2B_CTX));
|
||||
|
@ -64,18 +64,18 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2s_make_new(const mp_obj_type_t *type,
|
||||
MP_ARG_KW_ONLY | MP_ARG_OBJ,
|
||||
{.u_obj = mp_const_empty_bytes}},
|
||||
};
|
||||
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)] = {0};
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args),
|
||||
allowed_args, vals);
|
||||
|
||||
size_t data_len;
|
||||
size_t data_len = 0;
|
||||
const uint8_t *data =
|
||||
(const uint8_t *)mp_obj_str_get_data(vals[0].u_obj, &data_len);
|
||||
const mp_int_t outlen = vals[1].u_int;
|
||||
size_t key_len;
|
||||
size_t key_len = 0;
|
||||
const uint8_t *key =
|
||||
(const uint8_t *)mp_obj_str_get_data(vals[2].u_obj, &key_len);
|
||||
size_t personal_len;
|
||||
size_t personal_len = 0;
|
||||
const uint8_t *personal =
|
||||
(const uint8_t *)mp_obj_str_get_data(vals[3].u_obj, &personal_len);
|
||||
|
||||
@ -115,7 +115,7 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2s_make_new(const mp_obj_type_t *type,
|
||||
/// """
|
||||
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_buffer_info_t msg = {0};
|
||||
mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
|
||||
if (msg.len > 0) {
|
||||
blake2s_Update(&(o->ctx), msg.buf, msg.len);
|
||||
@ -131,8 +131,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Blake2s_update_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Blake2s_digest(mp_obj_t self) {
|
||||
mp_obj_Blake2s_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t out[BLAKE2S_DIGEST_LENGTH];
|
||||
BLAKE2S_CTX ctx;
|
||||
uint8_t out[BLAKE2S_DIGEST_LENGTH] = {0};
|
||||
BLAKE2S_CTX ctx = {0};
|
||||
memcpy(&ctx, &(o->ctx), sizeof(BLAKE2S_CTX));
|
||||
blake2s_Final(&ctx, out, ctx.outlen);
|
||||
memzero(&ctx, sizeof(BLAKE2S_CTX));
|
||||
|
@ -46,7 +46,7 @@ STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_make_new(
|
||||
mp_obj_ChaCha20Poly1305_t *o =
|
||||
m_new_obj_with_finaliser(mp_obj_ChaCha20Poly1305_t);
|
||||
o->base.type = type;
|
||||
mp_buffer_info_t key, nonce;
|
||||
mp_buffer_info_t key = {0}, nonce = {0};
|
||||
mp_get_buffer_raise(args[0], &key, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(args[1], &nonce, MP_BUFFER_READ);
|
||||
if (key.len != 32) {
|
||||
@ -69,9 +69,9 @@ STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_make_new(
|
||||
STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_encrypt(mp_obj_t self,
|
||||
mp_obj_t data) {
|
||||
mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t in;
|
||||
mp_buffer_info_t in = {0};
|
||||
mp_get_buffer_raise(data, &in, MP_BUFFER_READ);
|
||||
vstr_t vstr;
|
||||
vstr_t vstr = {0};
|
||||
vstr_init_len(&vstr, in.len);
|
||||
chacha20poly1305_encrypt(&(o->ctx), in.buf, (uint8_t *)vstr.buf, in.len);
|
||||
o->plen += in.len;
|
||||
@ -88,9 +88,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_ChaCha20Poly1305_encrypt_obj,
|
||||
STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_decrypt(mp_obj_t self,
|
||||
mp_obj_t data) {
|
||||
mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t in;
|
||||
mp_buffer_info_t in = {0};
|
||||
mp_get_buffer_raise(data, &in, MP_BUFFER_READ);
|
||||
vstr_t vstr;
|
||||
vstr_t vstr = {0};
|
||||
vstr_init_len(&vstr, in.len);
|
||||
chacha20poly1305_decrypt(&(o->ctx), in.buf, (uint8_t *)vstr.buf, in.len);
|
||||
o->plen += in.len;
|
||||
@ -108,7 +108,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_ChaCha20Poly1305_decrypt_obj,
|
||||
STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_auth(mp_obj_t self,
|
||||
mp_obj_t data) {
|
||||
mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t in;
|
||||
mp_buffer_info_t in = {0};
|
||||
mp_get_buffer_raise(data, &in, MP_BUFFER_READ);
|
||||
rfc7539_auth(&(o->ctx), in.buf, in.len);
|
||||
o->alen += in.len;
|
||||
@ -123,7 +123,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_ChaCha20Poly1305_auth_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_finish(mp_obj_t self) {
|
||||
mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t out[16];
|
||||
uint8_t out[16] = {0};
|
||||
rfc7539_finish(&(o->ctx), o->alen, o->plen, out);
|
||||
return mp_obj_new_bytes(out, sizeof(out));
|
||||
}
|
||||
|
@ -30,7 +30,7 @@
|
||||
/// Computes a CRC32 checksum of `data`.
|
||||
/// """
|
||||
mp_obj_t mod_trezorcrypto_crc_crc32(size_t n_args, const mp_obj_t *args) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_buffer_info_t bufinfo = {0};
|
||||
mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ);
|
||||
uint32_t crc = (n_args > 1) ? trezor_obj_get_uint(args[1]) : 0;
|
||||
crc = checksum_crc32(bufinfo.buf, bufinfo.len, crc ^ 0xffffffff);
|
||||
|
@ -30,7 +30,7 @@
|
||||
/// Generate secret key.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_curve25519_generate_secret() {
|
||||
uint8_t out[32];
|
||||
uint8_t out[32] = {0};
|
||||
random_buffer(out, 32);
|
||||
// taken from https://cr.yp.to/ecdh.html
|
||||
out[0] &= 248;
|
||||
@ -47,12 +47,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(
|
||||
/// Computes public key from secret key.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_curve25519_publickey(mp_obj_t secret_key) {
|
||||
mp_buffer_info_t sk;
|
||||
mp_buffer_info_t sk = {0};
|
||||
mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
|
||||
if (sk.len != 32) {
|
||||
mp_raise_ValueError("Invalid length of secret key");
|
||||
}
|
||||
uint8_t out[32];
|
||||
uint8_t out[32] = {0};
|
||||
curve25519_scalarmult_basepoint(out, (const uint8_t *)sk.buf);
|
||||
return mp_obj_new_bytes(out, sizeof(out));
|
||||
}
|
||||
@ -66,7 +66,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_curve25519_publickey_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_curve25519_multiply(mp_obj_t secret_key,
|
||||
mp_obj_t public_key) {
|
||||
mp_buffer_info_t sk, pk;
|
||||
mp_buffer_info_t sk = {0}, pk = {0};
|
||||
mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(public_key, &pk, MP_BUFFER_READ);
|
||||
if (sk.len != 32) {
|
||||
@ -75,7 +75,7 @@ STATIC mp_obj_t mod_trezorcrypto_curve25519_multiply(mp_obj_t secret_key,
|
||||
if (pk.len != 32) {
|
||||
mp_raise_ValueError("Invalid length of public key");
|
||||
}
|
||||
uint8_t out[32];
|
||||
uint8_t out[32] = {0};
|
||||
curve25519_scalarmult(out, (const uint8_t *)sk.buf, (const uint8_t *)pk.buf);
|
||||
return mp_obj_new_bytes(out, sizeof(out));
|
||||
}
|
||||
|
@ -31,7 +31,7 @@
|
||||
/// Generate secret key.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_ed25519_generate_secret() {
|
||||
uint8_t out[32];
|
||||
uint8_t out[32] = {0};
|
||||
random_buffer(out, 32);
|
||||
// taken from https://cr.yp.to/ecdh.html
|
||||
out[0] &= 248;
|
||||
@ -47,12 +47,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_ed25519_generate_secret_obj,
|
||||
/// Computes public key from secret key.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_ed25519_publickey(mp_obj_t secret_key) {
|
||||
mp_buffer_info_t sk;
|
||||
mp_buffer_info_t sk = {0};
|
||||
mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
|
||||
if (sk.len != 32) {
|
||||
mp_raise_ValueError("Invalid length of secret key");
|
||||
}
|
||||
uint8_t out[32];
|
||||
uint8_t out[32] = {0};
|
||||
ed25519_publickey(*(const ed25519_secret_key *)sk.buf,
|
||||
*(ed25519_public_key *)out);
|
||||
return mp_obj_new_bytes(out, sizeof(out));
|
||||
@ -66,7 +66,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_ed25519_publickey_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_ed25519_sign(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_buffer_info_t sk, msg;
|
||||
mp_buffer_info_t sk = {0}, msg = {0};
|
||||
mp_get_buffer_raise(args[0], &sk, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(args[1], &msg, MP_BUFFER_READ);
|
||||
if (sk.len != 32) {
|
||||
@ -75,9 +75,9 @@ STATIC mp_obj_t mod_trezorcrypto_ed25519_sign(size_t n_args,
|
||||
if (msg.len == 0) {
|
||||
mp_raise_ValueError("Empty data to sign");
|
||||
}
|
||||
ed25519_public_key pk;
|
||||
uint8_t out[64];
|
||||
mp_buffer_info_t hash_func;
|
||||
ed25519_public_key pk = {0};
|
||||
uint8_t out[64] = {0};
|
||||
mp_buffer_info_t hash_func = {0};
|
||||
|
||||
if (n_args == 3) {
|
||||
mp_get_buffer_raise(args[2], &hash_func, MP_BUFFER_READ);
|
||||
@ -111,7 +111,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_ed25519_sign_obj, 2,
|
||||
STATIC mp_obj_t mod_trezorcrypto_ed25519_sign_ext(mp_obj_t secret_key,
|
||||
mp_obj_t secret_extension,
|
||||
mp_obj_t message) {
|
||||
mp_buffer_info_t sk, skext, msg;
|
||||
mp_buffer_info_t sk = {0}, skext = {0}, msg = {0};
|
||||
mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(secret_extension, &skext, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(message, &msg, MP_BUFFER_READ);
|
||||
@ -124,11 +124,11 @@ STATIC mp_obj_t mod_trezorcrypto_ed25519_sign_ext(mp_obj_t secret_key,
|
||||
if (msg.len == 0) {
|
||||
mp_raise_ValueError("Empty data to sign");
|
||||
}
|
||||
ed25519_public_key pk;
|
||||
ed25519_public_key pk = {0};
|
||||
|
||||
ed25519_publickey_ext(*(const ed25519_secret_key *)sk.buf,
|
||||
*(const ed25519_secret_key *)skext.buf, pk);
|
||||
uint8_t out[64];
|
||||
uint8_t out[64] = {0};
|
||||
ed25519_sign_ext(msg.buf, msg.len, *(const ed25519_secret_key *)sk.buf,
|
||||
*(const ed25519_secret_key *)skext.buf, pk,
|
||||
*(ed25519_signature *)out);
|
||||
@ -147,7 +147,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_ed25519_sign_ext_obj,
|
||||
STATIC mp_obj_t mod_trezorcrypto_ed25519_verify(mp_obj_t public_key,
|
||||
mp_obj_t signature,
|
||||
mp_obj_t message) {
|
||||
mp_buffer_info_t pk, sig, msg;
|
||||
mp_buffer_info_t pk = {0}, sig = {0}, msg = {0};
|
||||
mp_get_buffer_raise(public_key, &pk, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(signature, &sig, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(message, &msg, MP_BUFFER_READ);
|
||||
@ -175,14 +175,15 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_ed25519_verify_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t
|
||||
mod_trezorcrypto_ed25519_cosi_combine_publickeys(mp_obj_t public_keys) {
|
||||
size_t pklen;
|
||||
mp_obj_t *pkitems;
|
||||
size_t pklen = 0;
|
||||
mp_obj_t *pkitems = NULL;
|
||||
mp_obj_get_array(public_keys, &pklen, &pkitems);
|
||||
if (pklen > 15) {
|
||||
mp_raise_ValueError("Can't combine more than 15 public keys");
|
||||
}
|
||||
mp_buffer_info_t buf;
|
||||
mp_buffer_info_t buf = {0};
|
||||
ed25519_public_key pks[pklen];
|
||||
memset(pks, 0, sizeof(pks));
|
||||
for (int i = 0; i < pklen; i++) {
|
||||
mp_get_buffer_raise(pkitems[i], &buf, MP_BUFFER_READ);
|
||||
if (buf.len != 32) {
|
||||
@ -190,7 +191,7 @@ mod_trezorcrypto_ed25519_cosi_combine_publickeys(mp_obj_t public_keys) {
|
||||
}
|
||||
memcpy(pks[i], buf.buf, buf.len);
|
||||
}
|
||||
uint8_t out[32];
|
||||
uint8_t out[32] = {0};
|
||||
if (0 !=
|
||||
ed25519_cosi_combine_publickeys(*(ed25519_public_key *)out, pks, pklen)) {
|
||||
mp_raise_ValueError("Error combining public keys");
|
||||
@ -207,19 +208,20 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_ed25519_cosi_combine_signatures(
|
||||
mp_obj_t R, mp_obj_t signatures) {
|
||||
mp_buffer_info_t sigR;
|
||||
mp_buffer_info_t sigR = {0};
|
||||
mp_get_buffer_raise(R, &sigR, MP_BUFFER_READ);
|
||||
if (sigR.len != 32) {
|
||||
mp_raise_ValueError("Invalid length of R");
|
||||
}
|
||||
size_t siglen;
|
||||
mp_obj_t *sigitems;
|
||||
size_t siglen = 0;
|
||||
mp_obj_t *sigitems = NULL;
|
||||
mp_obj_get_array(signatures, &siglen, &sigitems);
|
||||
if (siglen > 15) {
|
||||
mp_raise_ValueError("Can't combine more than 15 COSI signatures");
|
||||
}
|
||||
mp_buffer_info_t buf;
|
||||
mp_buffer_info_t buf = {0};
|
||||
ed25519_cosi_signature sigs[siglen];
|
||||
memset(sigs, 0, sizeof(sigs));
|
||||
for (int i = 0; i < siglen; i++) {
|
||||
mp_get_buffer_raise(sigitems[i], &buf, MP_BUFFER_READ);
|
||||
if (buf.len != 32) {
|
||||
@ -227,7 +229,7 @@ STATIC mp_obj_t mod_trezorcrypto_ed25519_cosi_combine_signatures(
|
||||
}
|
||||
memcpy(sigs[i], buf.buf, buf.len);
|
||||
}
|
||||
uint8_t out[64];
|
||||
uint8_t out[64] = {0};
|
||||
ed25519_cosi_combine_signatures(*(ed25519_signature *)out,
|
||||
*(const ed25519_public_key *)sigR.buf, sigs,
|
||||
siglen);
|
||||
@ -249,7 +251,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(
|
||||
/// """
|
||||
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_buffer_info_t sk = {0}, msg = {0}, nonce = {0}, sigR = {0}, pk = {0};
|
||||
mp_get_buffer_raise(args[0], &sk, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(args[1], &msg, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(args[2], &nonce, MP_BUFFER_READ);
|
||||
@ -267,7 +269,7 @@ STATIC mp_obj_t mod_trezorcrypto_ed25519_cosi_sign(size_t n_args,
|
||||
if (pk.len != 32) {
|
||||
mp_raise_ValueError("Invalid length of aggregated public key");
|
||||
}
|
||||
uint8_t out[32];
|
||||
uint8_t out[32] = {0};
|
||||
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,
|
||||
|
@ -65,7 +65,7 @@ STATIC mp_obj_t mod_trezorcrypto_Groestl512_make_new(const mp_obj_type_t *type,
|
||||
STATIC mp_obj_t mod_trezorcrypto_Groestl512_update(mp_obj_t self,
|
||||
mp_obj_t data) {
|
||||
mp_obj_Groestl512_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t msg;
|
||||
mp_buffer_info_t msg = {0};
|
||||
mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
|
||||
if (msg.len > 0) {
|
||||
groestl512_Update(&(o->ctx), msg.buf, msg.len);
|
||||
@ -81,8 +81,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Groestl512_update_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Groestl512_digest(mp_obj_t self) {
|
||||
mp_obj_Groestl512_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t out[GROESTL512_DIGEST_LENGTH];
|
||||
GROESTL512_CTX ctx;
|
||||
uint8_t out[GROESTL512_DIGEST_LENGTH] = {0};
|
||||
GROESTL512_CTX ctx = {0};
|
||||
memcpy(&ctx, &(o->ctx), sizeof(GROESTL512_CTX));
|
||||
groestl512_Final(&ctx, out);
|
||||
memzero(&ctx, sizeof(GROESTL512_CTX));
|
||||
|
@ -83,7 +83,7 @@ static uint64_t mp_obj_uint64_get_checked(mp_const_obj_t self_in) {
|
||||
if (MP_OBJ_IS_SMALL_INT(self_in)) {
|
||||
return MP_OBJ_SMALL_INT_VALUE(self_in);
|
||||
} else {
|
||||
byte buff[8];
|
||||
byte buff[8] = {0};
|
||||
uint64_t res = 0;
|
||||
mp_obj_t *o = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
@ -149,7 +149,7 @@ STATIC mp_obj_t mp_obj_new_ge25519_r(mp_obj_t r) {
|
||||
}
|
||||
|
||||
STATIC void mp_unpack_ge25519(ge25519 *r, const mp_obj_t arg, mp_int_t offset) {
|
||||
mp_buffer_info_t buff;
|
||||
mp_buffer_info_t buff = {0};
|
||||
mp_get_buffer_raise(arg, &buff, MP_BUFFER_READ);
|
||||
if (buff.len < 32 + offset) {
|
||||
mp_raise_ValueError("Invalid length of the EC point");
|
||||
@ -163,7 +163,7 @@ STATIC void mp_unpack_ge25519(ge25519 *r, const mp_obj_t arg, mp_int_t offset) {
|
||||
|
||||
STATIC void mp_unpack_scalar(bignum256modm r, const mp_obj_t arg,
|
||||
mp_int_t offset) {
|
||||
mp_buffer_info_t buff;
|
||||
mp_buffer_info_t buff = {0};
|
||||
mp_get_buffer_raise(arg, &buff, MP_BUFFER_READ);
|
||||
if (buff.len < 32 + offset) {
|
||||
mp_raise_ValueError("Invalid length of secret key");
|
||||
@ -291,7 +291,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_hasher_make_new(
|
||||
xmr_hasher_init(&(o->h));
|
||||
|
||||
if (n_args == 1 && MP_OBJ_IS_STR_OR_BYTES(args[0])) {
|
||||
mp_buffer_info_t buff;
|
||||
mp_buffer_info_t buff = {0};
|
||||
mp_get_buffer_raise(args[0], &buff, MP_BUFFER_READ);
|
||||
xmr_hasher_update(&o->h, buff.buf, buff.len);
|
||||
}
|
||||
@ -390,7 +390,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_monero_eq256_modm_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_get256_modm(const mp_obj_t arg) {
|
||||
assert_scalar(arg);
|
||||
uint64_t v;
|
||||
uint64_t v = 0;
|
||||
if (!get256_modm(&v, MP_OBJ_C_SCALAR(arg))) {
|
||||
mp_raise_ValueError("Ed25519 scalar too big");
|
||||
}
|
||||
@ -521,9 +521,9 @@ STATIC mp_obj_t mod_trezorcrypto_monero_inv256_modm(size_t n_args,
|
||||
// bn_prime = curve order, little endian encoded
|
||||
bignum256 bn_prime = {.val = {0x1cf5d3ed, 0x9318d2, 0x1de73596, 0x1df3bd45,
|
||||
0x14d, 0x0, 0x0, 0x0, 0x100000}};
|
||||
bignum256 bn_x;
|
||||
bignum256modm bm_x;
|
||||
uint8_t raw_x[32];
|
||||
bignum256 bn_x = {0};
|
||||
bignum256modm bm_x = {0};
|
||||
uint8_t raw_x[32] = {0};
|
||||
|
||||
memcpy(bm_x, MP_OBJ_C_SCALAR(args[1 + off]), sizeof(bignum256modm));
|
||||
contract256_modm(raw_x, bm_x);
|
||||
@ -551,12 +551,12 @@ STATIC mp_obj_t mod_trezorcrypto_monero_pack256_modm(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
if (n_args == 1 || args[0] == mp_const_none) {
|
||||
assert_scalar(args[0]);
|
||||
uint8_t buff[32];
|
||||
uint8_t buff[32] = {0};
|
||||
contract256_modm(buff, MP_OBJ_C_SCALAR(args[0]));
|
||||
return mp_obj_new_bytes(buff, 32);
|
||||
|
||||
} else {
|
||||
mp_buffer_info_t bufm;
|
||||
mp_buffer_info_t bufm = {0};
|
||||
mp_get_buffer_raise(args[0], &bufm, MP_BUFFER_WRITE);
|
||||
const mp_int_t offset = n_args >= 3 ? mp_obj_get_int(args[2]) : 0;
|
||||
if (bufm.len < 32 + offset) {
|
||||
@ -603,7 +603,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_unpack256_modm_noreduce(
|
||||
mp_obj_t res = mp_obj_new_scalar_r(res_arg ? args[0] : mp_const_none);
|
||||
const mp_int_t offset = n_args >= 3 ? mp_obj_get_int(args[2]) : 0;
|
||||
|
||||
mp_buffer_info_t buff;
|
||||
mp_buffer_info_t buff = {0};
|
||||
mp_get_buffer_raise(args[1 + off], &buff, MP_BUFFER_READ);
|
||||
if (buff.len != 32 + offset) {
|
||||
mp_raise_ValueError("Invalid length of secret key");
|
||||
@ -821,7 +821,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_scalarmult_base(
|
||||
ge25519_scalarmult_base_wrapper(&MP_OBJ_GE25519(res),
|
||||
MP_OBJ_C_SCALAR(args[1 + off]));
|
||||
} else if (mp_obj_is_integer(args[1 + off])) {
|
||||
bignum256modm mlt;
|
||||
bignum256modm mlt = {0};
|
||||
set256_modm(mlt, mp_obj_get_int(args[1 + off]));
|
||||
ge25519_scalarmult_base_wrapper(&MP_OBJ_GE25519(res), mlt);
|
||||
} else {
|
||||
@ -851,7 +851,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_scalarmult(
|
||||
ge25519_scalarmult(&MP_OBJ_GE25519(res), &MP_OBJ_C_GE25519(args[1 + off]),
|
||||
MP_OBJ_C_SCALAR(args[2 + off]));
|
||||
} else if (mp_obj_is_integer(args[2 + off])) {
|
||||
bignum256modm mlt;
|
||||
bignum256modm mlt = {0};
|
||||
set256_modm(mlt, mp_obj_get_int(args[2 + off]));
|
||||
ge25519_scalarmult(&MP_OBJ_GE25519(res), &MP_OBJ_C_GE25519(args[1 + off]),
|
||||
mlt);
|
||||
@ -873,12 +873,12 @@ STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_pack(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
if (n_args == 1 || args[0] == mp_const_none) {
|
||||
assert_ge25519(args[0]);
|
||||
uint8_t buff[32];
|
||||
uint8_t buff[32] = {0};
|
||||
ge25519_pack(buff, &MP_OBJ_C_GE25519(args[0]));
|
||||
return mp_obj_new_bytes(buff, 32);
|
||||
|
||||
} else {
|
||||
mp_buffer_info_t bufm;
|
||||
mp_buffer_info_t bufm = {0};
|
||||
mp_get_buffer_raise(args[0], &bufm, MP_BUFFER_WRITE);
|
||||
const mp_int_t offset = n_args >= 3 ? mp_obj_get_int(args[2]) : 0;
|
||||
if (bufm.len < 32 + offset) {
|
||||
@ -922,8 +922,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_base58_addr_encode_check(
|
||||
size_t n_args, const mp_obj_t *args) {
|
||||
uint8_t out[128];
|
||||
mp_buffer_info_t data;
|
||||
uint8_t out[128] = {0};
|
||||
mp_buffer_info_t data = {0};
|
||||
mp_get_buffer_raise(args[1], &data, MP_BUFFER_READ);
|
||||
|
||||
int sz = xmr_base58_addr_encode_check(mp_obj_get_int(args[0]), data.buf,
|
||||
@ -945,10 +945,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_base58_addr_decode_check(
|
||||
size_t n_args, const mp_obj_t *args) {
|
||||
uint8_t out[128];
|
||||
uint64_t tag;
|
||||
uint8_t out[128] = {0};
|
||||
uint64_t tag = 0;
|
||||
|
||||
mp_buffer_info_t data;
|
||||
mp_buffer_info_t data = {0};
|
||||
mp_get_buffer_raise(args[0], &data, MP_BUFFER_READ);
|
||||
|
||||
int sz =
|
||||
@ -989,10 +989,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_xmr_fast_hash(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
const int off = n_args >= 2 ? 0 : -1;
|
||||
uint8_t buff[32];
|
||||
uint8_t buff[32] = {0};
|
||||
uint8_t *buff_use = buff;
|
||||
if (n_args > 1) {
|
||||
mp_buffer_info_t odata;
|
||||
mp_buffer_info_t odata = {0};
|
||||
mp_get_buffer_raise(args[0], &odata, MP_BUFFER_WRITE);
|
||||
if (odata.len < 32) {
|
||||
mp_raise_ValueError("Output buffer too small");
|
||||
@ -1000,7 +1000,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_xmr_fast_hash(size_t n_args,
|
||||
buff_use = odata.buf;
|
||||
}
|
||||
|
||||
mp_buffer_info_t data;
|
||||
mp_buffer_info_t data = {0};
|
||||
mp_get_buffer_raise(args[1 + off], &data, MP_BUFFER_READ);
|
||||
mp_int_t length = n_args >= 3 ? mp_obj_get_int(args[2]) : data.len;
|
||||
mp_int_t offset = n_args >= 4 ? mp_obj_get_int(args[3]) : 0;
|
||||
@ -1028,7 +1028,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_xmr_hash_to_ec(size_t n_args,
|
||||
const bool res_arg = n_args >= 2;
|
||||
const int off = res_arg ? 0 : -1;
|
||||
mp_obj_t res = mp_obj_new_ge25519_r(res_arg ? args[0] : mp_const_none);
|
||||
mp_buffer_info_t data;
|
||||
mp_buffer_info_t data = {0};
|
||||
mp_get_buffer_raise(args[1 + off], &data, MP_BUFFER_READ);
|
||||
mp_int_t length = n_args >= 3 ? mp_obj_get_int(args[2]) : data.len;
|
||||
mp_int_t offset = n_args >= 4 ? mp_obj_get_int(args[3]) : 0;
|
||||
@ -1057,7 +1057,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_xmr_hash_to_scalar(
|
||||
const bool res_arg = n_args >= 2;
|
||||
const int off = res_arg ? 0 : -1;
|
||||
mp_obj_t res = mp_obj_new_scalar_r(res_arg ? args[0] : mp_const_none);
|
||||
mp_buffer_info_t data;
|
||||
mp_buffer_info_t data = {0};
|
||||
mp_get_buffer_raise(args[1 + off], &data, MP_BUFFER_READ);
|
||||
mp_int_t length = n_args >= 3 ? mp_obj_get_int(args[2]) : data.len;
|
||||
mp_int_t offset = n_args >= 4 ? mp_obj_get_int(args[3]) : 0;
|
||||
@ -1298,7 +1298,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
/// Constant time buffer comparison
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_ct_equals(const mp_obj_t a, const mp_obj_t b) {
|
||||
mp_buffer_info_t buff_a, buff_b;
|
||||
mp_buffer_info_t buff_a = {0}, buff_b = {0};
|
||||
mp_get_buffer_raise(a, &buff_a, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(b, &buff_b, MP_BUFFER_READ);
|
||||
|
||||
@ -1316,7 +1316,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_ct_equals_obj,
|
||||
STATIC mp_obj_t mod_trezorcrypto_monero_hasher_update(mp_obj_t self,
|
||||
const mp_obj_t arg) {
|
||||
mp_obj_hasher_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t buff;
|
||||
mp_buffer_info_t buff = {0};
|
||||
mp_get_buffer_raise(arg, &buff, MP_BUFFER_READ);
|
||||
if (buff.len > 0) {
|
||||
xmr_hasher_update(&o->h, buff.buf, buff.len);
|
||||
@ -1330,10 +1330,10 @@ STATIC mp_obj_t mod_trezorcrypto_monero_hasher_digest(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_obj_hasher_t *o = MP_OBJ_TO_PTR(args[0]);
|
||||
|
||||
Hasher ctx;
|
||||
Hasher ctx = {0};
|
||||
memcpy(&ctx, &(o->h), sizeof(Hasher));
|
||||
|
||||
uint8_t out[SHA3_256_DIGEST_LENGTH];
|
||||
uint8_t out[SHA3_256_DIGEST_LENGTH] = {0};
|
||||
xmr_hasher_final(&ctx, out);
|
||||
memzero(&ctx, sizeof(SHA3_CTX));
|
||||
|
||||
@ -1341,7 +1341,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_hasher_digest(size_t n_args,
|
||||
return mp_obj_new_bytes(out, sizeof(out));
|
||||
|
||||
} else {
|
||||
mp_buffer_info_t bufm;
|
||||
mp_buffer_info_t bufm = {0};
|
||||
mp_get_buffer_raise(args[1], &bufm, MP_BUFFER_WRITE);
|
||||
const mp_int_t offset = n_args >= 3 ? mp_obj_get_int(args[2]) : 0;
|
||||
if (bufm.len < 32 + offset) {
|
||||
|
@ -31,7 +31,7 @@
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_nem_validate_address(mp_obj_t address,
|
||||
mp_obj_t network) {
|
||||
mp_buffer_info_t addr;
|
||||
mp_buffer_info_t addr = {0};
|
||||
mp_get_buffer_raise(address, &addr, MP_BUFFER_READ);
|
||||
|
||||
uint32_t n = trezor_obj_get_uint(network);
|
||||
@ -46,7 +46,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_nem_validate_address_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_nem_compute_address(mp_obj_t public_key,
|
||||
mp_obj_t network) {
|
||||
mp_buffer_info_t p;
|
||||
mp_buffer_info_t p = {0};
|
||||
mp_get_buffer_raise(public_key, &p, MP_BUFFER_READ);
|
||||
|
||||
uint32_t n = trezor_obj_get_uint(network);
|
||||
|
@ -29,7 +29,7 @@
|
||||
/// Generate secret key.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_nist256p1_generate_secret() {
|
||||
uint8_t out[32];
|
||||
uint8_t out[32] = {0};
|
||||
for (;;) {
|
||||
random_buffer(out, 32);
|
||||
// check whether secret > 0 && secret < curve_order
|
||||
@ -60,18 +60,18 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_nist256p1_generate_secret_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_nist256p1_publickey(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_buffer_info_t sk;
|
||||
mp_buffer_info_t sk = {0};
|
||||
mp_get_buffer_raise(args[0], &sk, MP_BUFFER_READ);
|
||||
if (sk.len != 32) {
|
||||
mp_raise_ValueError("Invalid length of secret key");
|
||||
}
|
||||
bool compressed = n_args < 2 || args[1] == mp_const_true;
|
||||
if (compressed) {
|
||||
uint8_t out[33];
|
||||
uint8_t out[33] = {0};
|
||||
ecdsa_get_public_key33(&nist256p1, (const uint8_t *)sk.buf, out);
|
||||
return mp_obj_new_bytes(out, sizeof(out));
|
||||
} else {
|
||||
uint8_t out[65];
|
||||
uint8_t out[65] = {0};
|
||||
ecdsa_get_public_key65(&nist256p1, (const uint8_t *)sk.buf, out);
|
||||
return mp_obj_new_bytes(out, sizeof(out));
|
||||
}
|
||||
@ -88,7 +88,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_nist256p1_sign(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_buffer_info_t sk, dig;
|
||||
mp_buffer_info_t sk = {0}, dig = {0};
|
||||
mp_get_buffer_raise(args[0], &sk, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(args[1], &dig, MP_BUFFER_READ);
|
||||
bool compressed = n_args < 3 || args[2] == mp_const_true;
|
||||
@ -98,7 +98,7 @@ STATIC mp_obj_t mod_trezorcrypto_nist256p1_sign(size_t n_args,
|
||||
if (dig.len != 32) {
|
||||
mp_raise_ValueError("Invalid length of digest");
|
||||
}
|
||||
uint8_t out[65], pby;
|
||||
uint8_t out[65] = {0}, pby = 0;
|
||||
if (0 != ecdsa_sign_digest(&nist256p1, (const uint8_t *)sk.buf,
|
||||
(const uint8_t *)dig.buf, out + 1, &pby, NULL)) {
|
||||
mp_raise_ValueError("Signing failed");
|
||||
@ -118,7 +118,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_nist256p1_sign_obj,
|
||||
STATIC mp_obj_t mod_trezorcrypto_nist256p1_verify(mp_obj_t public_key,
|
||||
mp_obj_t signature,
|
||||
mp_obj_t digest) {
|
||||
mp_buffer_info_t pk, sig, dig;
|
||||
mp_buffer_info_t pk = {0}, sig = {0}, dig = {0};
|
||||
mp_get_buffer_raise(public_key, &pk, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(signature, &sig, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(digest, &dig, MP_BUFFER_READ);
|
||||
@ -147,7 +147,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_nist256p1_verify_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_nist256p1_verify_recover(mp_obj_t signature,
|
||||
mp_obj_t digest) {
|
||||
mp_buffer_info_t sig, dig;
|
||||
mp_buffer_info_t sig = {0}, dig = {0};
|
||||
mp_get_buffer_raise(signature, &sig, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(digest, &dig, MP_BUFFER_READ);
|
||||
if (sig.len != 65) {
|
||||
@ -162,7 +162,7 @@ STATIC mp_obj_t mod_trezorcrypto_nist256p1_verify_recover(mp_obj_t signature,
|
||||
}
|
||||
bool compressed = (recid >= 4);
|
||||
recid &= 3;
|
||||
uint8_t out[65];
|
||||
uint8_t out[65] = {0};
|
||||
if (0 == ecdsa_recover_pub_from_sig(&nist256p1, out,
|
||||
(const uint8_t *)sig.buf + 1,
|
||||
(const uint8_t *)dig.buf, recid)) {
|
||||
@ -185,7 +185,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_nist256p1_verify_recover_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_nist256p1_multiply(mp_obj_t secret_key,
|
||||
mp_obj_t public_key) {
|
||||
mp_buffer_info_t sk, pk;
|
||||
mp_buffer_info_t sk = {0}, pk = {0};
|
||||
mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(public_key, &pk, MP_BUFFER_READ);
|
||||
if (sk.len != 32) {
|
||||
@ -194,7 +194,7 @@ STATIC mp_obj_t mod_trezorcrypto_nist256p1_multiply(mp_obj_t secret_key,
|
||||
if (pk.len != 33 && pk.len != 65) {
|
||||
mp_raise_ValueError("Invalid length of public key");
|
||||
}
|
||||
uint8_t out[65];
|
||||
uint8_t out[65] = {0};
|
||||
if (0 != ecdh_multiply(&nist256p1, (const uint8_t *)sk.buf,
|
||||
(const uint8_t *)pk.buf, out)) {
|
||||
mp_raise_ValueError("Multiply failed");
|
||||
|
@ -62,9 +62,9 @@ STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_make_new(const mp_obj_type_t *type,
|
||||
mp_obj_Pbkdf2_t *o = m_new_obj_with_finaliser(mp_obj_Pbkdf2_t);
|
||||
o->base.type = type;
|
||||
|
||||
mp_buffer_info_t password;
|
||||
mp_buffer_info_t password = {0};
|
||||
mp_get_buffer_raise(args[1], &password, MP_BUFFER_READ);
|
||||
mp_buffer_info_t salt;
|
||||
mp_buffer_info_t salt = {0};
|
||||
mp_get_buffer_raise(args[2], &salt, MP_BUFFER_READ);
|
||||
|
||||
if (password.len == 0) {
|
||||
@ -122,17 +122,17 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Pbkdf2_update_obj,
|
||||
STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_key(mp_obj_t self) {
|
||||
mp_obj_Pbkdf2_t *o = MP_OBJ_TO_PTR(self);
|
||||
if (o->prf == PRF_HMAC_SHA256) {
|
||||
PBKDF2_HMAC_SHA256_CTX ctx;
|
||||
PBKDF2_HMAC_SHA256_CTX ctx = {0};
|
||||
memcpy(&ctx, &(o->ctx256), sizeof(PBKDF2_HMAC_SHA256_CTX));
|
||||
uint8_t out[SHA256_DIGEST_LENGTH];
|
||||
uint8_t out[SHA256_DIGEST_LENGTH] = {0};
|
||||
pbkdf2_hmac_sha256_Final(&ctx, out);
|
||||
memzero(&ctx, sizeof(PBKDF2_HMAC_SHA256_CTX));
|
||||
return mp_obj_new_bytes(out, sizeof(out));
|
||||
}
|
||||
if (o->prf == PRF_HMAC_SHA512) {
|
||||
PBKDF2_HMAC_SHA512_CTX ctx;
|
||||
PBKDF2_HMAC_SHA512_CTX ctx = {0};
|
||||
memcpy(&ctx, &(o->ctx512), sizeof(PBKDF2_HMAC_SHA512_CTX));
|
||||
uint8_t out[SHA512_DIGEST_LENGTH];
|
||||
uint8_t out[SHA512_DIGEST_LENGTH] = {0};
|
||||
pbkdf2_hmac_sha512_Final(&ctx, out);
|
||||
memzero(&ctx, sizeof(PBKDF2_HMAC_SHA512_CTX));
|
||||
return mp_obj_new_bytes(out, sizeof(out));
|
||||
|
@ -49,7 +49,7 @@ STATIC mp_obj_t mod_trezorcrypto_random_bytes(mp_obj_t len) {
|
||||
if (l > 1024) {
|
||||
mp_raise_ValueError("Maximum requested size is 1024");
|
||||
}
|
||||
vstr_t vstr;
|
||||
vstr_t vstr = {0};
|
||||
vstr_init_len(&vstr, l);
|
||||
random_buffer((uint8_t *)vstr.buf, l);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
@ -62,8 +62,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_random_bytes_obj,
|
||||
/// Shuffles items of given list (in-place).
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_random_shuffle(mp_obj_t data) {
|
||||
size_t count;
|
||||
mp_obj_t *items;
|
||||
size_t count = 0;
|
||||
mp_obj_t *items = NULL;
|
||||
mp_obj_get_array(data, &count, &items);
|
||||
if (count > 256) {
|
||||
mp_raise_ValueError("Maximum list size is 256 items");
|
||||
@ -72,7 +72,7 @@ STATIC mp_obj_t mod_trezorcrypto_random_shuffle(mp_obj_t data) {
|
||||
return mp_const_none;
|
||||
}
|
||||
// Fisher-Yates shuffle
|
||||
mp_obj_t t;
|
||||
mp_obj_t t = 0;
|
||||
for (size_t i = count - 1; i >= 1; i--) {
|
||||
size_t j = random_uniform(i + 1);
|
||||
t = items[i];
|
||||
|
@ -62,7 +62,7 @@ STATIC mp_obj_t mod_trezorcrypto_Ripemd160_make_new(const mp_obj_type_t *type,
|
||||
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_buffer_info_t msg = {0};
|
||||
mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
|
||||
if (msg.len > 0) {
|
||||
ripemd160_Update(&(o->ctx), msg.buf, msg.len);
|
||||
@ -78,8 +78,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Ripemd160_update_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Ripemd160_digest(mp_obj_t self) {
|
||||
mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t out[RIPEMD160_DIGEST_LENGTH];
|
||||
RIPEMD160_CTX ctx;
|
||||
uint8_t out[RIPEMD160_DIGEST_LENGTH] = {0};
|
||||
RIPEMD160_CTX ctx = {0};
|
||||
memcpy(&ctx, &(o->ctx), sizeof(RIPEMD160_CTX));
|
||||
ripemd160_Final(&ctx, out);
|
||||
memzero(&ctx, sizeof(RIPEMD160_CTX));
|
||||
|
@ -29,7 +29,7 @@
|
||||
/// Generate secret key.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_generate_secret() {
|
||||
uint8_t out[32];
|
||||
uint8_t out[32] = {0};
|
||||
for (;;) {
|
||||
random_buffer(out, 32);
|
||||
// check whether secret > 0 && secret < curve_order
|
||||
@ -60,18 +60,18 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_secp256k1_generate_secret_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_publickey(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_buffer_info_t sk;
|
||||
mp_buffer_info_t sk = {0};
|
||||
mp_get_buffer_raise(args[0], &sk, MP_BUFFER_READ);
|
||||
if (sk.len != 32) {
|
||||
mp_raise_ValueError("Invalid length of secret key");
|
||||
}
|
||||
bool compressed = n_args < 2 || args[1] == mp_const_true;
|
||||
if (compressed) {
|
||||
uint8_t out[33];
|
||||
uint8_t out[33] = {0};
|
||||
ecdsa_get_public_key33(&secp256k1, (const uint8_t *)sk.buf, out);
|
||||
return mp_obj_new_bytes(out, sizeof(out));
|
||||
} else {
|
||||
uint8_t out[65];
|
||||
uint8_t out[65] = {0};
|
||||
ecdsa_get_public_key65(&secp256k1, (const uint8_t *)sk.buf, out);
|
||||
return mp_obj_new_bytes(out, sizeof(out));
|
||||
}
|
||||
@ -117,7 +117,7 @@ enum {
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_sign(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_buffer_info_t sk, dig;
|
||||
mp_buffer_info_t sk = {0}, dig = {0};
|
||||
mp_get_buffer_raise(args[0], &sk, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(args[1], &dig, MP_BUFFER_READ);
|
||||
bool compressed = (n_args < 3) || (args[2] == mp_const_true);
|
||||
@ -139,7 +139,7 @@ STATIC mp_obj_t mod_trezorcrypto_secp256k1_sign(size_t n_args,
|
||||
if (dig.len != 32) {
|
||||
mp_raise_ValueError("Invalid length of digest");
|
||||
}
|
||||
uint8_t out[65], pby;
|
||||
uint8_t out[65] = {0}, pby = 0;
|
||||
if (0 != ecdsa_sign_digest(&secp256k1, (const uint8_t *)sk.buf,
|
||||
(const uint8_t *)dig.buf, out + 1, &pby,
|
||||
is_canonical)) {
|
||||
@ -160,7 +160,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_secp256k1_sign_obj,
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_verify(mp_obj_t public_key,
|
||||
mp_obj_t signature,
|
||||
mp_obj_t digest) {
|
||||
mp_buffer_info_t pk, sig, dig;
|
||||
mp_buffer_info_t pk = {0}, sig = {0}, dig = {0};
|
||||
mp_get_buffer_raise(public_key, &pk, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(signature, &sig, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(digest, &dig, MP_BUFFER_READ);
|
||||
@ -189,7 +189,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_secp256k1_verify_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_verify_recover(mp_obj_t signature,
|
||||
mp_obj_t digest) {
|
||||
mp_buffer_info_t sig, dig;
|
||||
mp_buffer_info_t sig = {0}, dig = {0};
|
||||
mp_get_buffer_raise(signature, &sig, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(digest, &dig, MP_BUFFER_READ);
|
||||
if (sig.len != 65) {
|
||||
@ -204,7 +204,7 @@ STATIC mp_obj_t mod_trezorcrypto_secp256k1_verify_recover(mp_obj_t signature,
|
||||
}
|
||||
bool compressed = (recid >= 4);
|
||||
recid &= 3;
|
||||
uint8_t out[65];
|
||||
uint8_t out[65] = {0};
|
||||
if (0 == ecdsa_recover_pub_from_sig(&secp256k1, out,
|
||||
(const uint8_t *)sig.buf + 1,
|
||||
(const uint8_t *)dig.buf, recid)) {
|
||||
@ -227,7 +227,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_secp256k1_verify_recover_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_multiply(mp_obj_t secret_key,
|
||||
mp_obj_t public_key) {
|
||||
mp_buffer_info_t sk, pk;
|
||||
mp_buffer_info_t sk = {0}, pk = {0};
|
||||
mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(public_key, &pk, MP_BUFFER_READ);
|
||||
if (sk.len != 32) {
|
||||
@ -236,7 +236,7 @@ STATIC mp_obj_t mod_trezorcrypto_secp256k1_multiply(mp_obj_t secret_key,
|
||||
if (pk.len != 33 && pk.len != 65) {
|
||||
mp_raise_ValueError("Invalid length of public key");
|
||||
}
|
||||
uint8_t out[65];
|
||||
uint8_t out[65] = {0};
|
||||
if (0 != ecdh_multiply(&secp256k1, (const uint8_t *)sk.buf,
|
||||
(const uint8_t *)pk.buf, out)) {
|
||||
mp_raise_ValueError("Multiply failed");
|
||||
|
@ -152,7 +152,7 @@ STATIC mp_obj_t mod_trezorcrypto_secp256k1_context_publickey(
|
||||
size_t n_args, const mp_obj_t *args) {
|
||||
const secp256k1_context *ctx =
|
||||
mod_trezorcrypto_get_secp256k1_context(args[0]);
|
||||
mp_buffer_info_t sk;
|
||||
mp_buffer_info_t sk = {0};
|
||||
mp_get_buffer_raise(args[1], &sk, MP_BUFFER_READ);
|
||||
secp256k1_pubkey pk;
|
||||
if (sk.len != 32) {
|
||||
@ -163,7 +163,7 @@ STATIC mp_obj_t mod_trezorcrypto_secp256k1_context_publickey(
|
||||
}
|
||||
|
||||
bool compressed = n_args < 3 || args[2] == mp_const_true;
|
||||
uint8_t out[65];
|
||||
uint8_t out[65] = {0};
|
||||
size_t outlen = sizeof(out);
|
||||
secp256k1_ec_pubkey_serialize(
|
||||
ctx, out, &outlen, &pk,
|
||||
@ -184,7 +184,7 @@ STATIC mp_obj_t mod_trezorcrypto_secp256k1_context_sign(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
const secp256k1_context *ctx =
|
||||
mod_trezorcrypto_get_secp256k1_context(args[0]);
|
||||
mp_buffer_info_t sk, dig;
|
||||
mp_buffer_info_t sk = {0}, dig = {0};
|
||||
mp_get_buffer_raise(args[1], &sk, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(args[2], &dig, MP_BUFFER_READ);
|
||||
bool compressed = n_args < 4 || args[3] == mp_const_true;
|
||||
@ -195,8 +195,8 @@ STATIC mp_obj_t mod_trezorcrypto_secp256k1_context_sign(size_t n_args,
|
||||
mp_raise_ValueError("Invalid length of digest");
|
||||
}
|
||||
secp256k1_ecdsa_recoverable_signature sig;
|
||||
uint8_t out[65];
|
||||
int pby;
|
||||
uint8_t out[65] = {0};
|
||||
int pby = 0;
|
||||
if (!secp256k1_ecdsa_sign_recoverable(ctx, &sig, (const uint8_t *)dig.buf,
|
||||
(const uint8_t *)sk.buf, NULL, NULL)) {
|
||||
mp_raise_ValueError("Signing failed");
|
||||
@ -221,7 +221,7 @@ STATIC mp_obj_t
|
||||
mod_trezorcrypto_secp256k1_context_verify(size_t n_args, const mp_obj_t *args) {
|
||||
const secp256k1_context *ctx =
|
||||
mod_trezorcrypto_get_secp256k1_context(args[0]);
|
||||
mp_buffer_info_t pk, sig, dig;
|
||||
mp_buffer_info_t pk = {0}, sig = {0}, dig = {0};
|
||||
mp_get_buffer_raise(args[1], &pk, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(args[2], &sig, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(args[3], &dig, MP_BUFFER_READ);
|
||||
@ -261,7 +261,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_context_verify_recover(
|
||||
mp_obj_t self, mp_obj_t signature, mp_obj_t digest) {
|
||||
const secp256k1_context *ctx = mod_trezorcrypto_get_secp256k1_context(self);
|
||||
mp_buffer_info_t sig, dig;
|
||||
mp_buffer_info_t sig = {0}, dig = {0};
|
||||
mp_get_buffer_raise(signature, &sig, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(digest, &dig, MP_BUFFER_READ);
|
||||
if (sig.len != 65) {
|
||||
@ -286,7 +286,7 @@ STATIC mp_obj_t mod_trezorcrypto_secp256k1_context_verify_recover(
|
||||
if (!secp256k1_ecdsa_recover(ctx, &pk, &ec_sig, (const uint8_t *)dig.buf)) {
|
||||
return mp_const_none;
|
||||
}
|
||||
uint8_t out[65];
|
||||
uint8_t out[65] = {0};
|
||||
size_t pklen = sizeof(out);
|
||||
secp256k1_ec_pubkey_serialize(
|
||||
ctx, out, &pklen, &pk,
|
||||
@ -314,7 +314,7 @@ static int secp256k1_ecdh_hash_passthrough(uint8_t *output, const uint8_t *x,
|
||||
STATIC mp_obj_t mod_trezorcrypto_secp256k1_context_multiply(
|
||||
mp_obj_t self, mp_obj_t secret_key, mp_obj_t public_key) {
|
||||
const secp256k1_context *ctx = mod_trezorcrypto_get_secp256k1_context(self);
|
||||
mp_buffer_info_t sk, pk;
|
||||
mp_buffer_info_t sk = {0}, pk = {0};
|
||||
mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(public_key, &pk, MP_BUFFER_READ);
|
||||
if (sk.len != 32) {
|
||||
@ -328,7 +328,7 @@ STATIC mp_obj_t mod_trezorcrypto_secp256k1_context_multiply(
|
||||
pk.len)) {
|
||||
mp_raise_ValueError("Invalid public key");
|
||||
}
|
||||
uint8_t out[65];
|
||||
uint8_t out[65] = {0};
|
||||
if (!secp256k1_ecdh(ctx, out, &ec_pk, (const uint8_t *)sk.buf,
|
||||
secp256k1_ecdh_hash_passthrough, NULL)) {
|
||||
mp_raise_ValueError("Multiply failed");
|
||||
|
@ -61,7 +61,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha1_make_new(const mp_obj_type_t *type,
|
||||
/// """
|
||||
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_buffer_info_t msg = {0};
|
||||
mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
|
||||
if (msg.len > 0) {
|
||||
sha1_Update(&(o->ctx), msg.buf, msg.len);
|
||||
@ -77,8 +77,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha1_update_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Sha1_digest(mp_obj_t self) {
|
||||
mp_obj_Sha1_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t out[SHA1_DIGEST_LENGTH];
|
||||
SHA1_CTX ctx;
|
||||
uint8_t out[SHA1_DIGEST_LENGTH] = {0};
|
||||
SHA1_CTX ctx = {0};
|
||||
memcpy(&ctx, &(o->ctx), sizeof(SHA1_CTX));
|
||||
sha1_Final(&ctx, out);
|
||||
memzero(&ctx, sizeof(SHA1_CTX));
|
||||
|
@ -61,7 +61,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha256_make_new(const mp_obj_type_t *type,
|
||||
/// """
|
||||
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_buffer_info_t msg = {0};
|
||||
mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
|
||||
if (msg.len > 0) {
|
||||
sha256_Update(&(o->ctx), msg.buf, msg.len);
|
||||
@ -77,8 +77,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha256_update_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Sha256_digest(mp_obj_t self) {
|
||||
mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t out[SHA256_DIGEST_LENGTH];
|
||||
SHA256_CTX ctx;
|
||||
uint8_t out[SHA256_DIGEST_LENGTH] = {0};
|
||||
SHA256_CTX ctx = {0};
|
||||
memcpy(&ctx, &(o->ctx), sizeof(SHA256_CTX));
|
||||
sha256_Final(&ctx, out);
|
||||
memzero(&ctx, sizeof(SHA256_CTX));
|
||||
|
@ -55,7 +55,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_256_make_new(const mp_obj_type_t *type,
|
||||
{MP_QSTR_data, MP_ARG_OBJ, {.u_obj = mp_const_none}},
|
||||
{MP_QSTR_keccak, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL}},
|
||||
};
|
||||
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)] = {0};
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args),
|
||||
allowed_args, vals);
|
||||
if (vals[1].u_obj != MP_OBJ_NULL) {
|
||||
@ -74,7 +74,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_256_make_new(const mp_obj_type_t *type,
|
||||
/// """
|
||||
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_buffer_info_t msg = {0};
|
||||
mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
|
||||
if (msg.len > 0) {
|
||||
sha3_Update(&(o->ctx), msg.buf, msg.len);
|
||||
@ -90,8 +90,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha3_256_update_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Sha3_256_digest(mp_obj_t self) {
|
||||
mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t out[SHA3_256_DIGEST_LENGTH];
|
||||
SHA3_CTX ctx;
|
||||
uint8_t out[SHA3_256_DIGEST_LENGTH] = {0};
|
||||
SHA3_CTX ctx = {0};
|
||||
memcpy(&ctx, &(o->ctx), sizeof(SHA3_CTX));
|
||||
if (o->keccak) {
|
||||
keccak_Final(&ctx, out);
|
||||
|
@ -55,7 +55,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_512_make_new(const mp_obj_type_t *type,
|
||||
{MP_QSTR_data, MP_ARG_OBJ, {.u_obj = mp_const_none}},
|
||||
{MP_QSTR_keccak, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL}},
|
||||
};
|
||||
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)] = {0};
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args),
|
||||
allowed_args, vals);
|
||||
if (vals[1].u_obj != MP_OBJ_NULL) {
|
||||
@ -74,7 +74,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_512_make_new(const mp_obj_type_t *type,
|
||||
/// """
|
||||
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_buffer_info_t msg = {0};
|
||||
mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
|
||||
if (msg.len > 0) {
|
||||
sha3_Update(&(o->ctx), msg.buf, msg.len);
|
||||
@ -90,8 +90,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha3_512_update_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Sha3_512_digest(mp_obj_t self) {
|
||||
mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t out[SHA3_512_DIGEST_LENGTH];
|
||||
SHA3_CTX ctx;
|
||||
uint8_t out[SHA3_512_DIGEST_LENGTH] = {0};
|
||||
SHA3_CTX ctx = {0};
|
||||
memcpy(&ctx, &(o->ctx), sizeof(SHA3_CTX));
|
||||
if (o->keccak) {
|
||||
keccak_Final(&ctx, out);
|
||||
|
@ -60,7 +60,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha512_make_new(const mp_obj_type_t *type,
|
||||
/// """
|
||||
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_buffer_info_t msg = {0};
|
||||
mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
|
||||
if (msg.len > 0) {
|
||||
sha512_Update(&(o->ctx), msg.buf, msg.len);
|
||||
@ -76,8 +76,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha512_update_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_Sha512_digest(mp_obj_t self) {
|
||||
mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t out[SHA512_DIGEST_LENGTH];
|
||||
SHA512_CTX ctx;
|
||||
uint8_t out[SHA512_DIGEST_LENGTH] = {0};
|
||||
SHA512_CTX ctx = {0};
|
||||
memcpy(&ctx, &(o->ctx), sizeof(SHA512_CTX));
|
||||
sha512_Final(&ctx, out);
|
||||
memzero(&ctx, sizeof(SHA512_CTX));
|
||||
|
@ -39,18 +39,18 @@
|
||||
/// :rtype: Array of bytes.
|
||||
/// """
|
||||
mp_obj_t mod_trezorcrypto_shamir_interpolate(mp_obj_t shares, mp_obj_t x) {
|
||||
size_t share_count;
|
||||
mp_obj_t *share_items;
|
||||
size_t share_count = 0;
|
||||
mp_obj_t *share_items = NULL;
|
||||
mp_obj_get_array(shares, &share_count, &share_items);
|
||||
if (share_count < 1 || share_count > SHAMIR_MAX_SHARE_COUNT) {
|
||||
mp_raise_ValueError("Invalid number of shares.");
|
||||
}
|
||||
uint8_t x_uint8 = trezor_obj_get_uint8(x);
|
||||
uint8_t share_indices[SHAMIR_MAX_SHARE_COUNT];
|
||||
const uint8_t *share_values[SHAMIR_MAX_SHARE_COUNT];
|
||||
uint8_t share_indices[SHAMIR_MAX_SHARE_COUNT] = {0};
|
||||
const uint8_t *share_values[SHAMIR_MAX_SHARE_COUNT] = {0};
|
||||
size_t value_len = 0;
|
||||
for (int i = 0; i < share_count; ++i) {
|
||||
mp_obj_t *share;
|
||||
mp_obj_t *share = NULL;
|
||||
mp_obj_get_array_fixed_n(share_items[i], 2, &share);
|
||||
share_indices[i] = trezor_obj_get_uint8(share[0]);
|
||||
mp_buffer_info_t value;
|
||||
@ -66,7 +66,7 @@ mp_obj_t mod_trezorcrypto_shamir_interpolate(mp_obj_t shares, mp_obj_t x) {
|
||||
}
|
||||
share_values[i] = value.buf;
|
||||
}
|
||||
vstr_t vstr;
|
||||
vstr_t vstr = {0};
|
||||
vstr_init_len(&vstr, value_len);
|
||||
if (shamir_interpolate((uint8_t *)vstr.buf, x_uint8, share_indices,
|
||||
share_values, share_count, value_len) != true) {
|
||||
|
@ -71,7 +71,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(
|
||||
/// Raises ValueError if not found.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorcrypto_slip39_word_index(mp_obj_t _word) {
|
||||
mp_buffer_info_t word;
|
||||
mp_buffer_info_t word = {0};
|
||||
|
||||
mp_get_buffer_raise(_word, &word, MP_BUFFER_READ);
|
||||
|
||||
|
@ -484,7 +484,7 @@ static const BYTE ExCvt[] = MKCVTBL(TBL_CT, FF_CODE_PAGE);
|
||||
|
||||
static WORD ld_word (const BYTE* ptr) /* Load a 2-byte little-endian word */
|
||||
{
|
||||
WORD rv;
|
||||
WORD rv = 0;
|
||||
|
||||
rv = ptr[1];
|
||||
rv = rv << 8 | ptr[0];
|
||||
@ -493,7 +493,7 @@ static WORD ld_word (const BYTE* ptr) /* Load a 2-byte little-endian word */
|
||||
|
||||
static DWORD ld_dword (const BYTE* ptr) /* Load a 4-byte little-endian word */
|
||||
{
|
||||
DWORD rv;
|
||||
DWORD rv = 0;
|
||||
|
||||
rv = ptr[3];
|
||||
rv = rv << 8 | ptr[2];
|
||||
@ -563,11 +563,11 @@ static DWORD tchar2uni ( /* Returns a character in UTF-16 encoding (>=0x10000 on
|
||||
const TCHAR** str /* Pointer to pointer to TCHAR string in configured encoding */
|
||||
)
|
||||
{
|
||||
DWORD uc;
|
||||
DWORD uc = 0;
|
||||
const TCHAR *p = *str;
|
||||
|
||||
BYTE b;
|
||||
int nf;
|
||||
BYTE b = 0;
|
||||
int nf = 0;
|
||||
|
||||
uc = (BYTE)*p++; /* Get an encoding unit */
|
||||
if (uc & 0x80) { /* Multiple byte code? */
|
||||
@ -605,7 +605,7 @@ static BYTE put_utf ( /* Returns number of encoding units written (0:buffer over
|
||||
UINT szb /* Size of the buffer */
|
||||
)
|
||||
{
|
||||
DWORD hc;
|
||||
DWORD hc = 0;
|
||||
|
||||
if (chr < 0x80) { /* Single byte code? */
|
||||
if (szb < 1) return 0; /* Buffer overflow? */
|
||||
@ -702,7 +702,7 @@ static FRESULT sync_fs ( /* Returns FR_OK or FR_DISK_ERR */
|
||||
FATFS* fs /* Filesystem object */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
FRESULT res = 0;
|
||||
|
||||
|
||||
res = sync_window(fs);
|
||||
@ -756,8 +756,8 @@ static DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x7FFFFFF
|
||||
DWORD clst /* Cluster number to get the value */
|
||||
)
|
||||
{
|
||||
UINT wc, bc;
|
||||
DWORD val;
|
||||
UINT wc = 0, bc = 0;
|
||||
DWORD val = 0;
|
||||
FATFS *fs = obj->fs;
|
||||
|
||||
|
||||
@ -807,8 +807,8 @@ static FRESULT put_fat ( /* FR_OK(0):succeeded, !=0:error */
|
||||
DWORD val /* New value to be set to the entry */
|
||||
)
|
||||
{
|
||||
UINT bc;
|
||||
BYTE *p;
|
||||
UINT bc = 0;
|
||||
BYTE *p = NULL;
|
||||
FRESULT res = FR_INT_ERR;
|
||||
|
||||
|
||||
@ -867,7 +867,7 @@ static FRESULT remove_chain ( /* FR_OK(0):succeeded, !=0:error */
|
||||
)
|
||||
{
|
||||
FRESULT res = FR_OK;
|
||||
DWORD nxt;
|
||||
DWORD nxt = 0;
|
||||
FATFS *fs = obj->fs;
|
||||
|
||||
if (clst < 2 || clst >= fs->n_fatent) return FR_INT_ERR; /* Check if in valid range */
|
||||
@ -910,8 +910,8 @@ static DWORD create_chain ( /* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:D
|
||||
DWORD clst /* Cluster# to stretch, 0:Create a new chain */
|
||||
)
|
||||
{
|
||||
DWORD cs, ncl, scl;
|
||||
FRESULT res;
|
||||
DWORD cs = 0, ncl = 0, scl = 0;
|
||||
FRESULT res = 0;
|
||||
FATFS *fs = obj->fs;
|
||||
|
||||
|
||||
@ -989,9 +989,9 @@ static FRESULT dir_clear ( /* Returns FR_OK or FR_DISK_ERR */
|
||||
DWORD clst /* Directory table to clear */
|
||||
)
|
||||
{
|
||||
LBA_t sect;
|
||||
UINT n, szb;
|
||||
BYTE *ibuf;
|
||||
LBA_t sect = 0;
|
||||
UINT n = 0, szb = 0;
|
||||
BYTE *ibuf = NULL;
|
||||
|
||||
|
||||
if (sync_window(fs) != FR_OK) return FR_DISK_ERR; /* Flush disk access window */
|
||||
@ -1017,7 +1017,7 @@ static FRESULT dir_sdi ( /* FR_OK(0):succeeded, !=0:error */
|
||||
DWORD ofs /* Offset of directory table */
|
||||
)
|
||||
{
|
||||
DWORD csz, clst;
|
||||
DWORD csz = 0, clst = 0;
|
||||
FATFS *fs = dp->obj.fs;
|
||||
|
||||
|
||||
@ -1065,7 +1065,7 @@ static FRESULT dir_next ( /* FR_OK(0):succeeded, FR_NO_FILE:End of table, FR_DEN
|
||||
int stretch /* 0: Do not stretch table, 1: Stretch table if needed */
|
||||
)
|
||||
{
|
||||
DWORD ofs, clst;
|
||||
DWORD ofs = 0, clst = 0;
|
||||
FATFS *fs = dp->obj.fs;
|
||||
|
||||
|
||||
@ -1120,8 +1120,8 @@ static FRESULT dir_alloc ( /* FR_OK(0):succeeded, !=0:error */
|
||||
UINT nent /* Number of contiguous entries to allocate */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
UINT n;
|
||||
FRESULT res = 0;
|
||||
UINT n = 0;
|
||||
FATFS *fs = dp->obj.fs;
|
||||
|
||||
|
||||
@ -1157,7 +1157,7 @@ static DWORD ld_clust ( /* Returns the top cluster value of the SFN entry */
|
||||
const BYTE* dir /* Pointer to the key entry */
|
||||
)
|
||||
{
|
||||
DWORD cl;
|
||||
DWORD cl = 0;
|
||||
|
||||
cl = ld_word(dir + DIR_FstClusLO);
|
||||
if (fs->fs_type == FS_FAT32) {
|
||||
@ -1191,8 +1191,8 @@ static int cmp_lfn ( /* 1:matched, 0:not matched */
|
||||
BYTE* dir /* Pointer to the directory entry containing the part of LFN */
|
||||
)
|
||||
{
|
||||
UINT i, s;
|
||||
WCHAR wc, uc;
|
||||
UINT i = 0, s = 0;
|
||||
WCHAR wc = 0, uc = 0;
|
||||
|
||||
|
||||
if (ld_word(dir + LDIR_FstClusLO) != 0) return 0; /* Check LDIR_FstClusLO */
|
||||
@ -1226,8 +1226,8 @@ static int pick_lfn ( /* 1:succeeded, 0:buffer overflow or invalid LFN entry */
|
||||
BYTE* dir /* Pointer to the LFN entry */
|
||||
)
|
||||
{
|
||||
UINT i, s;
|
||||
WCHAR wc, uc;
|
||||
UINT i = 0, s = 0;
|
||||
WCHAR wc = 0, uc = 0;
|
||||
|
||||
|
||||
if (ld_word(dir + LDIR_FstClusLO) != 0) return 0; /* Check LDIR_FstClusLO is 0 */
|
||||
@ -1264,8 +1264,8 @@ static void put_lfn (
|
||||
BYTE sum /* Checksum of the corresponding SFN */
|
||||
)
|
||||
{
|
||||
UINT i, s;
|
||||
WCHAR wc;
|
||||
UINT i = 0, s = 0;
|
||||
WCHAR wc = 0;
|
||||
|
||||
|
||||
dir[LDIR_Chksum] = sum; /* Set checksum */
|
||||
@ -1298,10 +1298,10 @@ static void gen_numname (
|
||||
UINT seq /* Sequence number */
|
||||
)
|
||||
{
|
||||
BYTE ns[8], c;
|
||||
UINT i, j;
|
||||
WCHAR wc;
|
||||
DWORD sreg;
|
||||
BYTE ns[8] = {0}, c = 0;
|
||||
UINT i = 0, j = 0;
|
||||
WCHAR wc = 0;
|
||||
DWORD sreg = 0;
|
||||
|
||||
|
||||
mem_cpy(dst, src, 11);
|
||||
@ -1380,7 +1380,7 @@ static FRESULT dir_read (
|
||||
{
|
||||
FRESULT res = FR_NO_FILE;
|
||||
FATFS *fs = dp->obj.fs;
|
||||
BYTE attr, b;
|
||||
BYTE attr = 0, b = 0;
|
||||
BYTE ord = 0xFF, sum = 0xFF;
|
||||
|
||||
while (dp->sect) {
|
||||
@ -1430,10 +1430,10 @@ static FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */
|
||||
DIR* dp /* Pointer to the directory object with the file name */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
FRESULT res = 0;
|
||||
FATFS *fs = dp->obj.fs;
|
||||
BYTE c;
|
||||
BYTE a, ord, sum;
|
||||
BYTE c = 0;
|
||||
BYTE a = 0, ord = 0, sum = 0;
|
||||
|
||||
res = dir_sdi(dp, 0); /* Rewind directory object */
|
||||
if (res != FR_OK) return res;
|
||||
@ -1481,10 +1481,10 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too
|
||||
DIR* dp /* Target directory with object name to be created */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
FRESULT res = 0;
|
||||
FATFS *fs = dp->obj.fs;
|
||||
UINT n, nlen, nent;
|
||||
BYTE sn[12], sum;
|
||||
UINT n = 0, nlen = 0, nent = 0;
|
||||
BYTE sn[12] = {0}, sum = 0;
|
||||
|
||||
|
||||
if (dp->fn[NSFLAG] & (NS_DOT | NS_NONAME)) return FR_INVALID_NAME; /* Check name validity */
|
||||
@ -1547,7 +1547,7 @@ static FRESULT dir_remove ( /* FR_OK:Succeeded, FR_DISK_ERR:A disk error */
|
||||
DIR* dp /* Directory object pointing the entry to be removed */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
FRESULT res = 0;
|
||||
FATFS *fs = dp->obj.fs;
|
||||
DWORD last = dp->dptr;
|
||||
|
||||
@ -1583,9 +1583,9 @@ static void get_fileinfo (
|
||||
FILINFO* fno /* Pointer to the file information to be filled */
|
||||
)
|
||||
{
|
||||
UINT si, di;
|
||||
BYTE lcf;
|
||||
WCHAR wc, hs;
|
||||
UINT si = 0, di = 0;
|
||||
BYTE lcf = 0;
|
||||
WCHAR wc = 0, hs = 0;
|
||||
FATFS *fs = dp->obj.fs;
|
||||
|
||||
|
||||
@ -1664,11 +1664,11 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr
|
||||
const TCHAR** path /* Pointer to pointer to the segment in the path string */
|
||||
)
|
||||
{
|
||||
BYTE b, cf;
|
||||
WCHAR wc, *lfn;
|
||||
DWORD uc;
|
||||
UINT i, ni, si, di;
|
||||
const TCHAR *p;
|
||||
BYTE b = 0, cf = 0;
|
||||
WCHAR wc = 0, *lfn = NULL;
|
||||
DWORD uc = 0;
|
||||
UINT i = 0, ni = 0, si = 0, di = 0;
|
||||
const TCHAR *p = NULL;
|
||||
|
||||
|
||||
/* Create LFN into LFN working buffer */
|
||||
@ -1780,8 +1780,8 @@ static FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */
|
||||
const TCHAR* path /* Full-path string to find a file or directory */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
BYTE ns;
|
||||
FRESULT res = 0;
|
||||
BYTE ns = 0;
|
||||
FATFS *fs = dp->obj.fs;
|
||||
|
||||
|
||||
@ -1837,9 +1837,9 @@ static int get_ldnumber ( /* Returns logical drive number (-1:invalid drive numb
|
||||
const TCHAR** path /* Pointer to pointer to the path name */
|
||||
)
|
||||
{
|
||||
const TCHAR *tp, *tt;
|
||||
TCHAR tc;
|
||||
int i, vol = -1;
|
||||
const TCHAR *tp = NULL, *tt = NULL;
|
||||
TCHAR tc = 0;
|
||||
int i = 0, vol = -1;
|
||||
|
||||
tt = tp = *path;
|
||||
if (!tp) return vol; /* Invalid path name? */
|
||||
@ -1905,8 +1905,8 @@ static UINT find_volume ( /* Returns BS status found in the hosting drive */
|
||||
UINT part /* Partition to fined = 0:auto, 1..:forced */
|
||||
)
|
||||
{
|
||||
UINT fmt, i;
|
||||
DWORD mbr_pt[4];
|
||||
UINT fmt = 0, i = 0;
|
||||
DWORD mbr_pt[4] = {0};
|
||||
|
||||
|
||||
fmt = check_fs(fs, 0); /* Load sector 0 and check if it is an FAT VBR as SFD */
|
||||
@ -1938,13 +1938,13 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */
|
||||
BYTE mode /* !=0: Check write protection for write access */
|
||||
)
|
||||
{
|
||||
int vol;
|
||||
DSTATUS stat;
|
||||
LBA_t bsect;
|
||||
DWORD tsect, sysect, fasize, nclst, szbfat;
|
||||
WORD nrsv;
|
||||
FATFS *fs;
|
||||
UINT fmt;
|
||||
int vol = 0;
|
||||
DSTATUS stat = 0;
|
||||
LBA_t bsect = 0;
|
||||
DWORD tsect = 0, sysect = 0, fasize = 0, nclst = 0, szbfat = 0;
|
||||
WORD nrsv = 0;
|
||||
FATFS *fs = NULL;
|
||||
UINT fmt = 0;
|
||||
|
||||
|
||||
/* Get logical drive number */
|
||||
@ -2120,9 +2120,9 @@ FRESULT f_mount (
|
||||
BYTE opt /* Mode option 0:Do not mount (delayed mount), 1:Mount immediately */
|
||||
)
|
||||
{
|
||||
FATFS *cfs;
|
||||
int vol;
|
||||
FRESULT res;
|
||||
FATFS *cfs = NULL;
|
||||
int vol = 0;
|
||||
FRESULT res = 0;
|
||||
const TCHAR *rp = path;
|
||||
|
||||
|
||||
@ -2159,12 +2159,12 @@ FRESULT f_open (
|
||||
BYTE mode /* Access mode and file open mode flags */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
DIR dj;
|
||||
FATFS *fs;
|
||||
DWORD cl, bcs, clst;
|
||||
LBA_t sc;
|
||||
FSIZE_t ofs;
|
||||
FRESULT res = 0;
|
||||
DIR dj = {0};
|
||||
FATFS *fs = NULL;
|
||||
DWORD cl = 0, bcs = 0, clst = 0;
|
||||
LBA_t sc = 0;
|
||||
FSIZE_t ofs = 0;
|
||||
DEF_NAMBUF
|
||||
|
||||
|
||||
@ -2290,12 +2290,12 @@ FRESULT f_read (
|
||||
UINT* br /* Pointer to number of bytes read */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
FATFS *fs;
|
||||
DWORD clst;
|
||||
LBA_t sect;
|
||||
FSIZE_t remain;
|
||||
UINT rcnt, cc, csect;
|
||||
FRESULT res = 0;
|
||||
FATFS *fs = NULL;
|
||||
DWORD clst = 0;
|
||||
LBA_t sect = 0;
|
||||
FSIZE_t remain = 0;
|
||||
UINT rcnt = 0, cc = 0, csect = 0;
|
||||
BYTE *rbuff = (BYTE*)buff;
|
||||
|
||||
|
||||
@ -2368,11 +2368,11 @@ FRESULT f_write (
|
||||
UINT* bw /* Pointer to number of bytes written */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
FATFS *fs;
|
||||
DWORD clst;
|
||||
LBA_t sect;
|
||||
UINT wcnt, cc, csect;
|
||||
FRESULT res = 0;
|
||||
FATFS *fs = NULL;
|
||||
DWORD clst = 0;
|
||||
LBA_t sect = 0;
|
||||
UINT wcnt = 0, cc = 0, csect = 0;
|
||||
const BYTE *wbuff = (const BYTE*)buff;
|
||||
|
||||
|
||||
@ -2456,10 +2456,10 @@ FRESULT f_sync (
|
||||
FIL* fp /* Pointer to the file object */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
FATFS *fs;
|
||||
DWORD tm;
|
||||
BYTE *dir;
|
||||
FRESULT res = 0;
|
||||
FATFS *fs = NULL;
|
||||
DWORD tm = 0;
|
||||
BYTE *dir = NULL;
|
||||
|
||||
|
||||
res = validate(&fp->obj, &fs); /* Check validity of the file object */
|
||||
@ -2503,8 +2503,8 @@ FRESULT f_close (
|
||||
FIL* fp /* Pointer to the file object to be closed */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
FATFS *fs;
|
||||
FRESULT res = 0;
|
||||
FATFS *fs = NULL;
|
||||
|
||||
res = f_sync(fp); /* Flush cached data */
|
||||
if (res == FR_OK)
|
||||
@ -2532,11 +2532,11 @@ FRESULT f_lseek (
|
||||
FSIZE_t ofs /* File pointer from top of file */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
FATFS *fs;
|
||||
DWORD clst, bcs;
|
||||
LBA_t nsect;
|
||||
FSIZE_t ifptr;
|
||||
FRESULT res = 0;
|
||||
FATFS *fs = NULL;
|
||||
DWORD clst = 0, bcs = 0;
|
||||
LBA_t nsect = 0;
|
||||
FSIZE_t ifptr = 0;
|
||||
|
||||
res = validate(&fp->obj, &fs); /* Check validity of the file object */
|
||||
if (res == FR_OK) res = (FRESULT)fp->err;
|
||||
@ -2623,8 +2623,8 @@ FRESULT f_opendir (
|
||||
const TCHAR* path /* Pointer to the directory path */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
FATFS *fs;
|
||||
FRESULT res = 0;
|
||||
FATFS *fs = NULL;
|
||||
DEF_NAMBUF
|
||||
|
||||
|
||||
@ -2670,8 +2670,8 @@ FRESULT f_closedir (
|
||||
DIR *dp /* Pointer to the directory object to be closed */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
FATFS *fs;
|
||||
FRESULT res = 0;
|
||||
FATFS *fs = NULL;
|
||||
|
||||
|
||||
res = validate(&dp->obj, &fs); /* Check validity of the file object */
|
||||
@ -2693,8 +2693,8 @@ FRESULT f_readdir (
|
||||
FILINFO* fno /* Pointer to file information to return */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
FATFS *fs;
|
||||
FRESULT res = 0;
|
||||
FATFS *fs = NULL;
|
||||
DEF_NAMBUF
|
||||
|
||||
|
||||
@ -2731,8 +2731,8 @@ FRESULT f_stat (
|
||||
FILINFO* fno /* Pointer to file information to return */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
DIR dj;
|
||||
FRESULT res = 0;
|
||||
DIR dj = {0};
|
||||
DEF_NAMBUF
|
||||
|
||||
|
||||
@ -2766,12 +2766,12 @@ FRESULT f_getfree (
|
||||
FATFS** fatfs /* Pointer to return pointer to corresponding filesystem object */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
FATFS *fs;
|
||||
DWORD nfree, clst, stat;
|
||||
LBA_t sect;
|
||||
UINT i;
|
||||
FFOBJID obj;
|
||||
FRESULT res = 0;
|
||||
FATFS *fs = NULL;
|
||||
DWORD nfree = 0, clst = 0, stat = 0;
|
||||
LBA_t sect = 0;
|
||||
UINT i = 0;
|
||||
FFOBJID obj = {0};
|
||||
|
||||
|
||||
/* Get logical drive */
|
||||
@ -2833,9 +2833,9 @@ FRESULT f_truncate (
|
||||
FIL* fp /* Pointer to the file object */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
FATFS *fs;
|
||||
DWORD ncl;
|
||||
FRESULT res = 0;
|
||||
FATFS *fs = NULL;
|
||||
DWORD ncl = 0;
|
||||
|
||||
|
||||
res = validate(&fp->obj, &fs); /* Check validity of the file object */
|
||||
@ -2881,10 +2881,10 @@ FRESULT f_unlink (
|
||||
const TCHAR* path /* Pointer to the file or directory path */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
DIR dj, sdj;
|
||||
FRESULT res = 0;
|
||||
DIR dj = {0}, sdj = {0};
|
||||
DWORD dclst = 0;
|
||||
FATFS *fs;
|
||||
FATFS *fs = NULL;
|
||||
DEF_NAMBUF
|
||||
|
||||
|
||||
@ -2947,11 +2947,11 @@ FRESULT f_mkdir (
|
||||
const TCHAR* path /* Pointer to the directory path */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
DIR dj;
|
||||
FFOBJID sobj;
|
||||
FATFS *fs;
|
||||
DWORD dcl, pcl, tm;
|
||||
FRESULT res = 0;
|
||||
DIR dj = {0};
|
||||
FFOBJID sobj = {0};
|
||||
FATFS *fs = NULL;
|
||||
DWORD dcl = 0, pcl = 0, tm = 0;
|
||||
DEF_NAMBUF
|
||||
|
||||
|
||||
@ -3021,11 +3021,11 @@ FRESULT f_rename (
|
||||
const TCHAR* path_new /* Pointer to the new name */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
DIR djo, djn;
|
||||
FATFS *fs;
|
||||
BYTE buf[FF_FS_EXFAT ? SZDIRE * 2 : SZDIRE], *dir;
|
||||
LBA_t sect;
|
||||
FRESULT res = 0;
|
||||
DIR djo = {0}, djn = {0};
|
||||
FATFS *fs = NULL;
|
||||
BYTE buf[(FF_FS_EXFAT) ? (SZDIRE * 2) : (SZDIRE)] = {0}, *dir = NULL;
|
||||
LBA_t sect = 0;
|
||||
DEF_NAMBUF
|
||||
|
||||
|
||||
@ -3099,11 +3099,11 @@ FRESULT f_getlabel (
|
||||
DWORD* vsn /* Variable to store the volume serial number */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
DIR dj;
|
||||
FATFS *fs;
|
||||
UINT si, di;
|
||||
WCHAR wc;
|
||||
FRESULT res = 0;
|
||||
DIR dj = {0};
|
||||
FATFS *fs = NULL;
|
||||
UINT si = 0, di = 0;
|
||||
WCHAR wc = 0;
|
||||
|
||||
/* Get logical drive */
|
||||
res = mount_volume(&path, &fs, 0);
|
||||
@ -3169,14 +3169,14 @@ FRESULT f_setlabel (
|
||||
const TCHAR* label /* Volume label to set with heading logical drive number */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
DIR dj;
|
||||
FATFS *fs;
|
||||
BYTE dirvn[22];
|
||||
UINT di;
|
||||
WCHAR wc;
|
||||
FRESULT res = 0;
|
||||
DIR dj = {0};
|
||||
FATFS *fs = NULL;
|
||||
BYTE dirvn[22] = {0};
|
||||
UINT di = 0;
|
||||
WCHAR wc = 0;
|
||||
static const char badchr[] = "+.,;=[]/\\\"*:<>\?|\x7F"; /* [0..] for FAT, [7..] for exFAT */
|
||||
DWORD dc;
|
||||
DWORD dc = 0;
|
||||
|
||||
/* Get logical drive */
|
||||
res = mount_volume(&label, &fs, FA_WRITE);
|
||||
@ -3270,10 +3270,10 @@ static FRESULT create_partition (
|
||||
BYTE* buf /* Working buffer for a sector */
|
||||
)
|
||||
{
|
||||
UINT i, cy;
|
||||
LBA_t sz_drv;
|
||||
DWORD sz_drv32, s_lba32, n_lba32;
|
||||
BYTE *pte, hd, n_hd, sc, n_sc;
|
||||
UINT i = 0, cy = 0;
|
||||
LBA_t sz_drv = 0;
|
||||
DWORD sz_drv32 = 0, s_lba32 = 0, n_lba32 = 0;
|
||||
BYTE *pte = NULL, hd = 0, n_hd = 0, sc = 0, n_sc = 0;
|
||||
|
||||
/* Get drive size */
|
||||
if (disk_ioctl(drv, GET_SECTOR_COUNT, &sz_drv) != RES_OK) return FR_DISK_ERR;
|
||||
@ -3332,16 +3332,16 @@ FRESULT f_mkfs (
|
||||
static const WORD cst[] = {1, 4, 16, 64, 256, 512, 0}; /* Cluster size boundary for FAT volume (4Ks unit) */
|
||||
static const WORD cst32[] = {1, 2, 4, 8, 16, 32, 0}; /* Cluster size boundary for FAT32 volume (128Ks unit) */
|
||||
static const MKFS_PARM defopt = {FM_ANY, 0, 0, 0, 0}; /* Default parameter */
|
||||
BYTE fsopt, fsty, sys, *buf, *pte, pdrv, ipart;
|
||||
BYTE fsopt = 0, fsty = 0, sys = 0, *buf = NULL, *pte = NULL, pdrv = 0, ipart = 0;
|
||||
WORD ss; /* Sector size */
|
||||
DWORD sz_buf, sz_blk, n_clst, pau, nsect, n;
|
||||
DWORD sz_buf = 0, sz_blk = 0, n_clst = 0, pau = 0, nsect = 0, n = 0;
|
||||
LBA_t sz_vol, b_vol, b_fat, b_data; /* Size of volume, Base LBA of volume, fat, data */
|
||||
LBA_t sect, lba[2];
|
||||
LBA_t sect = 0, lba[2] = {0};
|
||||
DWORD sz_rsv, sz_fat, sz_dir, sz_au; /* Size of reserved, fat, dir, data, cluster */
|
||||
UINT n_fat, n_root, i; /* Index, Number of FATs and Number of roor dir entries */
|
||||
int vol;
|
||||
DSTATUS ds;
|
||||
FRESULT fr;
|
||||
int vol = 0;
|
||||
DSTATUS ds = 0;
|
||||
FRESULT fr = 0;
|
||||
|
||||
|
||||
/* Check mounted drive and clear work area */
|
||||
|
@ -129,8 +129,8 @@ DWORD ff_wtoupper ( /* Returns up-converted code point */
|
||||
DWORD uni /* Unicode code point to be up-converted */
|
||||
)
|
||||
{
|
||||
const WORD *p;
|
||||
WORD uc, bc, nc, cmd;
|
||||
const WORD *p = (void*) 0;
|
||||
WORD uc = 0, bc = 0, nc = 0, cmd = 0;
|
||||
static const WORD cvt1[] = { /* Compressed up conversion table for U+0000 - U+0FFF */
|
||||
/* Basic Latin */
|
||||
0x0061,0x031A,
|
||||
|
@ -211,9 +211,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_FatFSFile_close_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_FatFSFile_read(mp_obj_t self, mp_obj_t data) {
|
||||
mp_obj_FatFSFile_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t buf;
|
||||
mp_buffer_info_t buf = {0};
|
||||
mp_get_buffer_raise(data, &buf, MP_BUFFER_WRITE);
|
||||
UINT read;
|
||||
UINT read = 0;
|
||||
FRESULT res = f_read(&(o->fp), buf.buf, buf.len, &read);
|
||||
if (res != FR_OK) {
|
||||
FATFS_RAISE(FatFSError, res);
|
||||
@ -229,9 +229,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_FatFSFile_read_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_FatFSFile_write(mp_obj_t self, mp_obj_t data) {
|
||||
mp_obj_FatFSFile_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t buf;
|
||||
mp_buffer_info_t buf = {0};
|
||||
mp_get_buffer_raise(data, &buf, MP_BUFFER_READ);
|
||||
UINT written;
|
||||
UINT written = 0;
|
||||
FRESULT res = f_write(&(o->fp), buf.buf, buf.len, &written);
|
||||
if (res != FR_OK) {
|
||||
FATFS_RAISE(FatFSError, res);
|
||||
@ -327,7 +327,7 @@ typedef struct _mp_obj_FatFSDir_t {
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_FatFSDir_iternext(mp_obj_t self) {
|
||||
mp_obj_FatFSDir_t *o = MP_OBJ_TO_PTR(self);
|
||||
FILINFO info;
|
||||
FILINFO info = {0};
|
||||
FRESULT res = f_readdir(&(o->dp), &info);
|
||||
if (res != FR_OK) {
|
||||
f_closedir(&(o->dp));
|
||||
@ -357,7 +357,7 @@ STATIC const mp_obj_type_t mod_trezorio_FatFSDir_type = {
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_fatfs_open(mp_obj_t path, mp_obj_t flags) {
|
||||
FATFS_ONLY_MOUNTED;
|
||||
mp_buffer_info_t _path, _flags;
|
||||
mp_buffer_info_t _path = {0}, _flags = {0};
|
||||
mp_get_buffer_raise(path, &_path, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(flags, &_flags, MP_BUFFER_READ);
|
||||
const char *mode_s = _flags.buf;
|
||||
@ -381,7 +381,7 @@ STATIC mp_obj_t mod_trezorio_fatfs_open(mp_obj_t path, mp_obj_t flags) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
FIL fp;
|
||||
FIL fp = {0};
|
||||
FRESULT res = f_open(&fp, _path.buf, mode);
|
||||
if (res != FR_OK) {
|
||||
FATFS_RAISE(FatFSError, res);
|
||||
@ -400,9 +400,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_fatfs_open_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_fatfs_listdir(mp_obj_t path) {
|
||||
FATFS_ONLY_MOUNTED;
|
||||
mp_buffer_info_t _path;
|
||||
mp_buffer_info_t _path = {0};
|
||||
mp_get_buffer_raise(path, &_path, MP_BUFFER_READ);
|
||||
DIR dp;
|
||||
DIR dp = {0};
|
||||
FRESULT res = f_opendir(&dp, _path.buf);
|
||||
if (res != FR_OK) {
|
||||
FATFS_RAISE(FatFSError, res);
|
||||
@ -421,7 +421,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_fatfs_listdir_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_fatfs_mkdir(size_t n_args, const mp_obj_t *args) {
|
||||
FATFS_ONLY_MOUNTED;
|
||||
mp_buffer_info_t path;
|
||||
mp_buffer_info_t path = {0};
|
||||
mp_get_buffer_raise(args[0], &path, MP_BUFFER_READ);
|
||||
FRESULT res = f_mkdir(path.buf);
|
||||
// directory exists and exist_ok is True, return without failure
|
||||
@ -442,7 +442,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorio_fatfs_mkdir_obj, 1, 2,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_fatfs_unlink(mp_obj_t path) {
|
||||
FATFS_ONLY_MOUNTED;
|
||||
mp_buffer_info_t _path;
|
||||
mp_buffer_info_t _path = {0};
|
||||
mp_get_buffer_raise(path, &_path, MP_BUFFER_READ);
|
||||
FRESULT res = f_unlink(_path.buf);
|
||||
if (res != FR_OK) {
|
||||
@ -459,9 +459,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_fatfs_unlink_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_fatfs_stat(mp_obj_t path) {
|
||||
FATFS_ONLY_MOUNTED;
|
||||
mp_buffer_info_t _path;
|
||||
mp_buffer_info_t _path = {0};
|
||||
mp_get_buffer_raise(path, &_path, MP_BUFFER_READ);
|
||||
FILINFO info;
|
||||
FILINFO info = {0};
|
||||
FRESULT res = f_stat(_path.buf, &info);
|
||||
if (res != FR_OK) {
|
||||
FATFS_RAISE(FatFSError, res);
|
||||
@ -477,7 +477,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_fatfs_stat_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_fatfs_rename(mp_obj_t oldpath, mp_obj_t newpath) {
|
||||
FATFS_ONLY_MOUNTED;
|
||||
mp_buffer_info_t _oldpath, _newpath;
|
||||
mp_buffer_info_t _oldpath = {0}, _newpath = {0};
|
||||
mp_get_buffer_raise(oldpath, &_oldpath, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(newpath, &_newpath, MP_BUFFER_READ);
|
||||
FRESULT res = f_rename(_oldpath.buf, _newpath.buf);
|
||||
@ -537,7 +537,7 @@ STATIC mp_obj_t mod_trezorio_fatfs_mkfs() {
|
||||
FATFS_RAISE(FatFSError, FR_LOCKED);
|
||||
}
|
||||
MKFS_PARM params = {FM_FAT32, 0, 0, 0, 0};
|
||||
uint8_t working_buf[FF_MAX_SS];
|
||||
uint8_t working_buf[FF_MAX_SS] = {0};
|
||||
FRESULT res = f_mkfs("", ¶ms, working_buf, sizeof(working_buf));
|
||||
if (res != FR_OK) {
|
||||
FATFS_RAISE(FatFSError, res);
|
||||
@ -556,7 +556,7 @@ STATIC mp_obj_t mod_trezorio_fatfs_setlabel(mp_obj_t label) {
|
||||
having parsed the FAT table, which is of course a prerequisite for setting
|
||||
label. */
|
||||
FATFS_ONLY_MOUNTED;
|
||||
mp_buffer_info_t _label;
|
||||
mp_buffer_info_t _label = {0};
|
||||
mp_get_buffer_raise(label, &_label, MP_BUFFER_READ);
|
||||
FRESULT res = f_setlabel(_label.buf);
|
||||
if (res != FR_OK) {
|
||||
|
@ -50,7 +50,7 @@ STATIC mp_obj_t mod_trezorio_FlashOTP_write(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
uint8_t block = trezor_obj_get_uint8(args[1]);
|
||||
uint8_t offset = trezor_obj_get_uint8(args[2]);
|
||||
mp_buffer_info_t data;
|
||||
mp_buffer_info_t data = {0};
|
||||
mp_get_buffer_raise(args[3], &data, MP_BUFFER_READ);
|
||||
if (sectrue != flash_otp_write(block, offset, data.buf, data.len)) {
|
||||
mp_raise_ValueError("write failed");
|
||||
@ -68,7 +68,7 @@ STATIC mp_obj_t mod_trezorio_FlashOTP_read(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
uint8_t block = trezor_obj_get_uint8(args[1]);
|
||||
uint8_t offset = trezor_obj_get_uint8(args[2]);
|
||||
mp_buffer_info_t data;
|
||||
mp_buffer_info_t data = {0};
|
||||
mp_get_buffer_raise(args[3], &data, MP_BUFFER_WRITE);
|
||||
if (sectrue != flash_otp_read(block, offset, data.buf, data.len)) {
|
||||
mp_raise_ValueError("read failed");
|
||||
|
@ -62,7 +62,7 @@ STATIC mp_obj_t mod_trezorio_HID_make_new(const mp_obj_type_t *type,
|
||||
MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_OBJ,
|
||||
{.u_obj = MP_OBJ_NULL}},
|
||||
};
|
||||
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)] = {0};
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args),
|
||||
allowed_args, vals);
|
||||
|
||||
@ -73,7 +73,7 @@ STATIC mp_obj_t mod_trezorio_HID_make_new(const mp_obj_type_t *type,
|
||||
const mp_int_t protocol = vals[4].u_int;
|
||||
const mp_int_t polling_interval = vals[5].u_int;
|
||||
const mp_int_t max_packet_len = vals[6].u_int;
|
||||
mp_buffer_info_t report_desc;
|
||||
mp_buffer_info_t report_desc = {0};
|
||||
mp_get_buffer_raise(vals[7].u_obj, &report_desc, MP_BUFFER_READ);
|
||||
|
||||
if (report_desc.buf == NULL || report_desc.len == 0 ||
|
||||
@ -122,7 +122,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_HID_iface_num_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_HID_write(mp_obj_t self, mp_obj_t msg) {
|
||||
mp_obj_HID_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t buf;
|
||||
mp_buffer_info_t buf = {0};
|
||||
mp_get_buffer_raise(msg, &buf, MP_BUFFER_READ);
|
||||
ssize_t r = usb_hid_write(o->info.iface_num, buf.buf, buf.len);
|
||||
return MP_OBJ_NEW_SMALL_INT(r);
|
||||
@ -137,7 +137,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_HID_write_obj,
|
||||
STATIC mp_obj_t mod_trezorio_HID_write_blocking(mp_obj_t self, mp_obj_t msg,
|
||||
mp_obj_t timeout_ms) {
|
||||
mp_obj_HID_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t buf;
|
||||
mp_buffer_info_t buf = {0};
|
||||
mp_get_buffer_raise(msg, &buf, MP_BUFFER_READ);
|
||||
uint32_t timeout = trezor_obj_get_uint(timeout_ms);
|
||||
ssize_t r =
|
||||
|
@ -50,11 +50,11 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
|
||||
|
||||
const mp_uint_t timeout = trezor_obj_get_uint(timeout_ms);
|
||||
const mp_uint_t deadline = mp_hal_ticks_ms() + timeout;
|
||||
mp_obj_iter_buf_t iterbuf;
|
||||
mp_obj_iter_buf_t iterbuf = {0};
|
||||
|
||||
for (;;) {
|
||||
mp_obj_t iter = mp_getiter(ifaces, &iterbuf);
|
||||
mp_obj_t item;
|
||||
mp_obj_t item = 0;
|
||||
while ((item = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) {
|
||||
const mp_uint_t i = trezor_obj_get_uint(item);
|
||||
const mp_uint_t iface = i & 0x00FF;
|
||||
@ -96,7 +96,7 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
|
||||
}
|
||||
} else if (mode == POLL_READ) {
|
||||
if (sectrue == usb_hid_can_read(iface)) {
|
||||
uint8_t buf[64];
|
||||
uint8_t buf[64] = {0};
|
||||
int len = usb_hid_read(iface, buf, sizeof(buf));
|
||||
if (len > 0) {
|
||||
ret->items[0] = MP_OBJ_NEW_SMALL_INT(i);
|
||||
@ -104,7 +104,7 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
|
||||
return mp_const_true;
|
||||
}
|
||||
} else if (sectrue == usb_webusb_can_read(iface)) {
|
||||
uint8_t buf[64];
|
||||
uint8_t buf[64] = {0};
|
||||
int len = usb_webusb_read(iface, buf, sizeof(buf));
|
||||
if (len > 0) {
|
||||
ret->items[0] = MP_OBJ_NEW_SMALL_INT(i);
|
||||
|
@ -82,7 +82,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_sdcard_capacity_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_sdcard_read(mp_obj_t block_num, mp_obj_t buf) {
|
||||
uint32_t block = trezor_obj_get_uint(block_num);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_buffer_info_t bufinfo = {0};
|
||||
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE);
|
||||
if (sectrue !=
|
||||
sdcard_read_blocks(bufinfo.buf, block, bufinfo.len / SDCARD_BLOCK_SIZE)) {
|
||||
@ -101,7 +101,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_sdcard_read_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_sdcard_write(mp_obj_t block_num, mp_obj_t buf) {
|
||||
uint32_t block = trezor_obj_get_uint(block_num);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_buffer_info_t bufinfo = {0};
|
||||
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
|
||||
if (sectrue != sdcard_write_blocks(bufinfo.buf, block,
|
||||
bufinfo.len / SDCARD_BLOCK_SIZE)) {
|
||||
|
@ -99,7 +99,7 @@ STATIC mp_obj_t mod_trezorio_USB_make_new(const mp_obj_type_t *type,
|
||||
{MP_QSTR_usb21_enabled, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true}},
|
||||
{MP_QSTR_usb21_landing, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true}},
|
||||
};
|
||||
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)] = {0};
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args),
|
||||
allowed_args, vals);
|
||||
|
||||
@ -186,8 +186,8 @@ STATIC mp_obj_t mod_trezorio_USB_open(mp_obj_t self) {
|
||||
mp_raise_msg(&mp_type_RuntimeError, "already initialized");
|
||||
}
|
||||
|
||||
size_t iface_cnt;
|
||||
mp_obj_t *iface_objs;
|
||||
size_t iface_cnt = 0;
|
||||
mp_obj_t *iface_objs = NULL;
|
||||
mp_obj_get_array(MP_OBJ_FROM_PTR(&o->ifaces), &iface_cnt, &iface_objs);
|
||||
|
||||
// Initialize the USB stack
|
||||
|
@ -60,7 +60,7 @@ STATIC mp_obj_t mod_trezorio_VCP_make_new(const mp_obj_type_t *type,
|
||||
MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_INT,
|
||||
{.u_int = 0}},
|
||||
};
|
||||
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)] = {0};
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args),
|
||||
allowed_args, vals);
|
||||
|
||||
|
@ -58,7 +58,7 @@ STATIC mp_obj_t mod_trezorio_WebUSB_make_new(const mp_obj_type_t *type,
|
||||
{MP_QSTR_polling_interval, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1}},
|
||||
{MP_QSTR_max_packet_len, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 64}},
|
||||
};
|
||||
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)] = {0};
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args),
|
||||
allowed_args, vals);
|
||||
|
||||
@ -110,7 +110,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_WebUSB_iface_num_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_WebUSB_write(mp_obj_t self, mp_obj_t msg) {
|
||||
mp_obj_WebUSB_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t buf;
|
||||
mp_buffer_info_t buf = {0};
|
||||
mp_get_buffer_raise(msg, &buf, MP_BUFFER_READ);
|
||||
ssize_t r = usb_webusb_write(o->info.iface_num, buf.buf, buf.len);
|
||||
return MP_OBJ_NEW_SMALL_INT(r);
|
||||
|
@ -44,7 +44,7 @@
|
||||
0x009341U // section "8.3.23 Read ID4 (D3h)" of ILI9341V datasheet
|
||||
|
||||
static uint32_t read_display_id(uint8_t command) {
|
||||
volatile uint8_t c;
|
||||
volatile uint8_t c = 0;
|
||||
uint32_t id = 0;
|
||||
CMD(command);
|
||||
c = ADDR; // first returned value is a dummy value and should be discarded
|
||||
|
@ -101,7 +101,7 @@ void display_init(void) {
|
||||
}
|
||||
atexit(SDL_Quit);
|
||||
|
||||
char *window_title;
|
||||
char *window_title = NULL;
|
||||
if (!asprintf(&window_title, "Trezor^emu: %s", profile_name())) {
|
||||
window_title = "Trezor^emu";
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ static struct { int x, y; } DISPLAY_OFFSET;
|
||||
|
||||
static inline uint16_t interpolate_color(uint16_t color0, uint16_t color1,
|
||||
uint8_t step) {
|
||||
uint8_t cr, cg, cb;
|
||||
uint8_t cr = 0, cg = 0, cb = 0;
|
||||
cr = (((color0 & 0xF800) >> 11) * step +
|
||||
((color1 & 0xF800) >> 11) * (15 - step)) /
|
||||
15;
|
||||
@ -133,7 +133,7 @@ void display_clear(void) {
|
||||
void display_bar(int x, int y, int w, int h, uint16_t c) {
|
||||
x += DISPLAY_OFFSET.x;
|
||||
y += DISPLAY_OFFSET.y;
|
||||
int x0, y0, x1, y1;
|
||||
int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
|
||||
clamp_coords(x, y, w, h, &x0, &y0, &x1, &y1);
|
||||
display_set_window(x0, y0, x1, y1);
|
||||
for (int i = 0; i < (x1 - x0 + 1) * (y1 - y0 + 1); i++) {
|
||||
@ -167,11 +167,11 @@ void display_bar_radius(int x, int y, int w, int h, uint16_t c, uint16_t b,
|
||||
} else {
|
||||
r = 16 / r;
|
||||
}
|
||||
uint16_t colortable[16];
|
||||
uint16_t colortable[16] = {0};
|
||||
set_color_table(colortable, c, b);
|
||||
x += DISPLAY_OFFSET.x;
|
||||
y += DISPLAY_OFFSET.y;
|
||||
int x0, y0, x1, y1;
|
||||
int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
|
||||
clamp_coords(x, y, w, h, &x0, &y0, &x1, &y1);
|
||||
display_set_window(x0, y0, x1, y1);
|
||||
for (int j = y0; j <= y1; j++) {
|
||||
@ -220,7 +220,7 @@ void display_image(int x, int y, int w, int h, const void *data,
|
||||
#if TREZOR_MODEL == T
|
||||
x += DISPLAY_OFFSET.x;
|
||||
y += DISPLAY_OFFSET.y;
|
||||
int x0, y0, x1, y1;
|
||||
int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
|
||||
clamp_coords(x, y, w, h, &x0, &y0, &x1, &y1);
|
||||
display_set_window(x0, y0, x1, y1);
|
||||
x0 -= x;
|
||||
@ -228,9 +228,9 @@ void display_image(int x, int y, int w, int h, const void *data,
|
||||
y0 -= y;
|
||||
y1 -= y;
|
||||
|
||||
struct uzlib_uncomp decomp;
|
||||
uint8_t decomp_window[UZLIB_WINDOW_SIZE];
|
||||
uint8_t decomp_out[2];
|
||||
struct uzlib_uncomp decomp = {0};
|
||||
uint8_t decomp_window[UZLIB_WINDOW_SIZE] = {0};
|
||||
uint8_t decomp_out[2] = {0};
|
||||
uzlib_prepare(&decomp, decomp_window, data, datalen, decomp_out,
|
||||
sizeof(decomp_out));
|
||||
|
||||
@ -260,7 +260,7 @@ void display_avatar(int x, int y, const void *data, uint32_t datalen,
|
||||
#if TREZOR_MODEL == T
|
||||
x += DISPLAY_OFFSET.x;
|
||||
y += DISPLAY_OFFSET.y;
|
||||
int x0, y0, x1, y1;
|
||||
int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
|
||||
clamp_coords(x, y, AVATAR_IMAGE_SIZE, AVATAR_IMAGE_SIZE, &x0, &y0, &x1, &y1);
|
||||
display_set_window(x0, y0, x1, y1);
|
||||
x0 -= x;
|
||||
@ -268,9 +268,9 @@ void display_avatar(int x, int y, const void *data, uint32_t datalen,
|
||||
y0 -= y;
|
||||
y1 -= y;
|
||||
|
||||
struct uzlib_uncomp decomp;
|
||||
uint8_t decomp_window[UZLIB_WINDOW_SIZE];
|
||||
uint8_t decomp_out[2];
|
||||
struct uzlib_uncomp decomp = {0};
|
||||
uint8_t decomp_window[UZLIB_WINDOW_SIZE] = {0};
|
||||
uint8_t decomp_out[2] = {0};
|
||||
uzlib_prepare(&decomp, decomp_window, data, datalen, decomp_out,
|
||||
sizeof(decomp_out));
|
||||
|
||||
@ -295,7 +295,7 @@ void display_avatar(int x, int y, const void *data, uint32_t datalen,
|
||||
#if AVATAR_ANTIALIAS
|
||||
d = 31 * (d - AVATAR_BORDER_LOW) /
|
||||
(AVATAR_BORDER_HIGH - AVATAR_BORDER_LOW);
|
||||
uint16_t c;
|
||||
uint16_t c = 0;
|
||||
if (d >= 16) {
|
||||
c = interpolate_color(bgcolor, fgcolor, d - 16);
|
||||
} else {
|
||||
@ -318,7 +318,7 @@ void display_icon(int x, int y, int w, int h, const void *data,
|
||||
x += DISPLAY_OFFSET.x;
|
||||
y += DISPLAY_OFFSET.y;
|
||||
x &= ~1; // cannot draw at odd coordinate
|
||||
int x0, y0, x1, y1;
|
||||
int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
|
||||
clamp_coords(x, y, w, h, &x0, &y0, &x1, &y1);
|
||||
display_set_window(x0, y0, x1, y1);
|
||||
x0 -= x;
|
||||
@ -326,12 +326,12 @@ void display_icon(int x, int y, int w, int h, const void *data,
|
||||
y0 -= y;
|
||||
y1 -= y;
|
||||
|
||||
uint16_t colortable[16];
|
||||
uint16_t colortable[16] = {0};
|
||||
set_color_table(colortable, fgcolor, bgcolor);
|
||||
|
||||
struct uzlib_uncomp decomp;
|
||||
uint8_t decomp_window[UZLIB_WINDOW_SIZE];
|
||||
uint8_t decomp_out;
|
||||
struct uzlib_uncomp decomp = {0};
|
||||
uint8_t decomp_window[UZLIB_WINDOW_SIZE] = {0};
|
||||
uint8_t decomp_out = 0;
|
||||
uzlib_prepare(&decomp, decomp_window, data, datalen, &decomp_out,
|
||||
sizeof(decomp_out));
|
||||
|
||||
@ -357,7 +357,7 @@ void display_loader(uint16_t progress, bool indeterminate, int yoffset,
|
||||
uint16_t fgcolor, uint16_t bgcolor, const uint8_t *icon,
|
||||
uint32_t iconlen, uint16_t iconfgcolor) {
|
||||
#if TREZOR_MODEL == T
|
||||
uint16_t colortable[16], iconcolortable[16];
|
||||
uint16_t colortable[16] = {0}, iconcolortable[16] = {0};
|
||||
set_color_table(colortable, fgcolor, bgcolor);
|
||||
if (icon) {
|
||||
set_color_table(iconcolortable, iconfgcolor, bgcolor);
|
||||
@ -374,9 +374,9 @@ void display_loader(uint16_t progress, bool indeterminate, int yoffset,
|
||||
LOADER_ICON_SIZE == *(uint16_t *)(icon + 4) &&
|
||||
LOADER_ICON_SIZE == *(uint16_t *)(icon + 6) &&
|
||||
iconlen == 12 + *(uint32_t *)(icon + 8)) {
|
||||
uint8_t icondata[LOADER_ICON_SIZE * LOADER_ICON_SIZE / 2];
|
||||
uint8_t icondata[(LOADER_ICON_SIZE * LOADER_ICON_SIZE) / 2] = {0};
|
||||
memzero(&icondata, sizeof(icondata));
|
||||
struct uzlib_uncomp decomp;
|
||||
struct uzlib_uncomp decomp = {0};
|
||||
uzlib_prepare(&decomp, NULL, icon + 12, iconlen - 12, icondata,
|
||||
sizeof(icondata));
|
||||
uzlib_uncompress(&decomp);
|
||||
@ -387,7 +387,7 @@ void display_loader(uint16_t progress, bool indeterminate, int yoffset,
|
||||
for (int y = 0; y < img_loader_size * 2; y++) {
|
||||
for (int x = 0; x < img_loader_size * 2; x++) {
|
||||
int mx = x, my = y;
|
||||
uint16_t a;
|
||||
uint16_t a = 0;
|
||||
if ((mx >= img_loader_size) && (my >= img_loader_size)) {
|
||||
mx = img_loader_size * 2 - 1 - x;
|
||||
my = img_loader_size * 2 - 1 - y;
|
||||
@ -411,7 +411,7 @@ void display_loader(uint16_t progress, bool indeterminate, int yoffset,
|
||||
int i =
|
||||
(x - (img_loader_size - (LOADER_ICON_SIZE / 2))) +
|
||||
(y - (img_loader_size - (LOADER_ICON_SIZE / 2))) * LOADER_ICON_SIZE;
|
||||
uint8_t c;
|
||||
uint8_t c = 0;
|
||||
if (i % 2) {
|
||||
c = icon[i / 2] & 0x0F;
|
||||
} else {
|
||||
@ -419,7 +419,7 @@ void display_loader(uint16_t progress, bool indeterminate, int yoffset,
|
||||
}
|
||||
PIXELDATA(iconcolortable[c]);
|
||||
} else {
|
||||
uint8_t c;
|
||||
uint8_t c = 0;
|
||||
if (indeterminate) {
|
||||
uint16_t diff =
|
||||
(progress > a) ? (progress - a) : (1000 + progress - a);
|
||||
@ -505,7 +505,7 @@ void display_print(const char *text, int textlen) {
|
||||
y /= 8;
|
||||
const int k = x % 6;
|
||||
x /= 6;
|
||||
char c;
|
||||
char c = 0;
|
||||
if (x < DISPLAY_PRINT_COLS && y < DISPLAY_PRINT_ROWS) {
|
||||
c = display_print_buf[y][x] & 0x7F;
|
||||
// char invert = display_print_buf[y][x] & 0x80;
|
||||
@ -539,7 +539,7 @@ void display_printf(const char *fmt, ...) {
|
||||
} else {
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
char buf[256];
|
||||
char buf[256] = {0};
|
||||
int len = mini_vsnprintf(buf, sizeof(buf), fmt, va);
|
||||
display_print(buf, len);
|
||||
va_end(va);
|
||||
@ -633,7 +633,7 @@ static void display_text_render(int x, int y, const char *text, int textlen,
|
||||
textlen = strlen(text);
|
||||
}
|
||||
|
||||
uint16_t colortable[16];
|
||||
uint16_t colortable[16] = {0};
|
||||
set_color_table(colortable, fgcolor, bgcolor);
|
||||
|
||||
// render glyphs
|
||||
@ -648,7 +648,7 @@ static void display_text_render(int x, int y, const char *text, int textlen,
|
||||
if (w && h) {
|
||||
const int sx = x + bearX;
|
||||
const int sy = y - bearY;
|
||||
int x0, y0, x1, y1;
|
||||
int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
|
||||
clamp_coords(sx, sy, w, h, &x0, &y0, &x1, &y1);
|
||||
display_set_window(x0, y0, x1, y1);
|
||||
for (int j = y0; j <= y1; j++) {
|
||||
@ -759,8 +759,8 @@ void display_qrcode(int x, int y, const char *data, uint32_t datalen,
|
||||
uint8_t scale) {
|
||||
if (scale < 1 || scale > 10) return;
|
||||
|
||||
uint8_t codedata[qrcodegen_BUFFER_LEN_FOR_VERSION(QR_MAX_VERSION)];
|
||||
uint8_t tempdata[qrcodegen_BUFFER_LEN_FOR_VERSION(QR_MAX_VERSION)];
|
||||
uint8_t codedata[qrcodegen_BUFFER_LEN_FOR_VERSION(QR_MAX_VERSION)] = {0};
|
||||
uint8_t tempdata[qrcodegen_BUFFER_LEN_FOR_VERSION(QR_MAX_VERSION)] = {0};
|
||||
|
||||
int side = 0;
|
||||
if (qrcodegen_encodeText(data, tempdata, codedata, qrcodegen_Ecc_MEDIUM,
|
||||
@ -771,7 +771,7 @@ void display_qrcode(int x, int y, const char *data, uint32_t datalen,
|
||||
|
||||
x += DISPLAY_OFFSET.x - (side + 2) * scale / 2;
|
||||
y += DISPLAY_OFFSET.y - (side + 2) * scale / 2;
|
||||
int x0, y0, x1, y1;
|
||||
int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
|
||||
clamp_coords(x, y, (side + 2) * scale, (side + 2) * scale, &x0, &y0, &x1,
|
||||
&y1);
|
||||
display_set_window(x0, y0, x1, y1);
|
||||
|
@ -128,7 +128,7 @@ 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;
|
||||
mp_buffer_info_t image = {0};
|
||||
mp_get_buffer_raise(args[3], &image, MP_BUFFER_READ);
|
||||
const uint8_t *data = image.buf;
|
||||
if (image.len < 8 || memcmp(data, "TOIf", 4) != 0) {
|
||||
@ -159,7 +159,7 @@ STATIC mp_obj_t mod_trezorui_Display_avatar(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
mp_buffer_info_t image;
|
||||
mp_buffer_info_t image = {0};
|
||||
mp_get_buffer_raise(args[3], &image, MP_BUFFER_READ);
|
||||
const uint8_t *data = image.buf;
|
||||
if (image.len < 8 || memcmp(data, "TOIf", 4) != 0) {
|
||||
@ -193,7 +193,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_avatar_obj, 6,
|
||||
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;
|
||||
mp_buffer_info_t icon = {0};
|
||||
mp_get_buffer_raise(args[3], &icon, MP_BUFFER_READ);
|
||||
const uint8_t *data = icon.buf;
|
||||
if (icon.len < 8 || memcmp(data, "TOIg", 4) != 0) {
|
||||
@ -239,7 +239,7 @@ STATIC mp_obj_t mod_trezorui_Display_loader(size_t n_args,
|
||||
mp_int_t fgcolor = mp_obj_get_int(args[4]);
|
||||
mp_int_t bgcolor = mp_obj_get_int(args[5]);
|
||||
if (n_args > 6) { // icon provided
|
||||
mp_buffer_info_t icon;
|
||||
mp_buffer_info_t icon = {0};
|
||||
mp_get_buffer_raise(args[6], &icon, MP_BUFFER_READ);
|
||||
const uint8_t *data = icon.buf;
|
||||
if (icon.len < 8 || memcmp(data, "TOIg", 4) != 0) {
|
||||
@ -254,7 +254,7 @@ STATIC mp_obj_t mod_trezorui_Display_loader(size_t n_args,
|
||||
if (datalen != icon.len - 12) {
|
||||
mp_raise_ValueError("Invalid size of data");
|
||||
}
|
||||
uint16_t iconfgcolor;
|
||||
uint16_t iconfgcolor = 0;
|
||||
if (n_args > 7) { // icon color provided
|
||||
iconfgcolor = mp_obj_get_int(args[7]);
|
||||
} else {
|
||||
@ -276,7 +276,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_loader_obj, 6,
|
||||
/// Renders text using 5x8 bitmap font (using special text mode).
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_print(mp_obj_t self, mp_obj_t text) {
|
||||
mp_buffer_info_t buf;
|
||||
mp_buffer_info_t buf = {0};
|
||||
mp_get_buffer_raise(text, &buf, MP_BUFFER_READ);
|
||||
if (buf.len > 0) {
|
||||
display_print(buf.buf, buf.len);
|
||||
@ -305,7 +305,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorui_Display_print_obj,
|
||||
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;
|
||||
mp_buffer_info_t text = {0};
|
||||
mp_get_buffer_raise(args[3], &text, MP_BUFFER_READ);
|
||||
mp_int_t font = mp_obj_get_int(args[4]);
|
||||
mp_int_t fgcolor = mp_obj_get_int(args[5]);
|
||||
@ -342,7 +342,7 @@ 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;
|
||||
mp_buffer_info_t text = {0};
|
||||
mp_get_buffer_raise(args[3], &text, MP_BUFFER_READ);
|
||||
mp_int_t font = mp_obj_get_int(args[4]);
|
||||
mp_int_t fgcolor = mp_obj_get_int(args[5]);
|
||||
@ -380,7 +380,7 @@ 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;
|
||||
mp_buffer_info_t text = {0};
|
||||
mp_get_buffer_raise(args[3], &text, MP_BUFFER_READ);
|
||||
mp_int_t font = mp_obj_get_int(args[4]);
|
||||
mp_int_t fgcolor = mp_obj_get_int(args[5]);
|
||||
@ -404,7 +404,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_right_obj,
|
||||
/// """
|
||||
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_buffer_info_t txt = {0};
|
||||
mp_get_buffer_raise(text, &txt, MP_BUFFER_READ);
|
||||
mp_int_t f = mp_obj_get_int(font);
|
||||
int w = display_text_width(txt.buf, txt.len, f);
|
||||
@ -421,7 +421,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorui_Display_text_width_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_text_split(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_buffer_info_t text;
|
||||
mp_buffer_info_t text = {0};
|
||||
mp_get_buffer_raise(args[1], &text, MP_BUFFER_READ);
|
||||
mp_int_t font = mp_obj_get_int(args[2]);
|
||||
mp_int_t requested_width = mp_obj_get_int(args[3]);
|
||||
@ -445,7 +445,7 @@ STATIC mp_obj_t mod_trezorui_Display_qrcode(size_t n_args,
|
||||
if (scale < 1 || scale > 10) {
|
||||
mp_raise_ValueError("Scale has to be between 1 and 10");
|
||||
}
|
||||
mp_buffer_info_t data;
|
||||
mp_buffer_info_t data = {0};
|
||||
mp_get_buffer_raise(args[3], &data, MP_BUFFER_READ);
|
||||
if (data.len > 0) {
|
||||
display_qrcode(x, y, data.buf, data.len, scale);
|
||||
@ -510,10 +510,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_backlight_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_offset(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
int xy[2], x, y;
|
||||
int xy[2] = {0}, x = 0, y = 0;
|
||||
if (n_args > 1) {
|
||||
size_t xy_cnt;
|
||||
mp_obj_t *xy_obj;
|
||||
size_t xy_cnt = 0;
|
||||
mp_obj_t *xy_obj = NULL;
|
||||
if (MP_OBJ_IS_TYPE(args[1], &mp_type_tuple)) {
|
||||
mp_obj_tuple_get(args[1], &xy_cnt, &xy_obj);
|
||||
} else {
|
||||
@ -541,7 +541,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_offset_obj, 1,
|
||||
/// Saves current display contents to PNG file with given prefix.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_save(mp_obj_t self, mp_obj_t prefix) {
|
||||
mp_buffer_info_t pfx;
|
||||
mp_buffer_info_t pfx = {0};
|
||||
mp_get_buffer_raise(prefix, &pfx, MP_BUFFER_READ);
|
||||
if (pfx.len > 0) {
|
||||
display_save(pfx.buf);
|
||||
|
@ -36,9 +36,9 @@
|
||||
/// expected to avoid any invalid memory access.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorutils_consteq(mp_obj_t sec, mp_obj_t pub) {
|
||||
mp_buffer_info_t secbuf;
|
||||
mp_buffer_info_t secbuf = {0};
|
||||
mp_get_buffer_raise(sec, &secbuf, MP_BUFFER_READ);
|
||||
mp_buffer_info_t pubbuf;
|
||||
mp_buffer_info_t pubbuf = {0};
|
||||
mp_get_buffer_raise(pub, &pubbuf, MP_BUFFER_READ);
|
||||
|
||||
size_t diff = secbuf.len - pubbuf.len;
|
||||
@ -73,11 +73,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorutils_consteq_obj,
|
||||
STATIC mp_obj_t mod_trezorutils_memcpy(size_t n_args, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, 0, 4, 5, false);
|
||||
|
||||
mp_buffer_info_t dst;
|
||||
mp_buffer_info_t dst = {0};
|
||||
mp_get_buffer_raise(args[0], &dst, MP_BUFFER_WRITE);
|
||||
uint32_t dst_ofs = trezor_obj_get_uint(args[1]);
|
||||
|
||||
mp_buffer_info_t src;
|
||||
mp_buffer_info_t src = {0};
|
||||
mp_get_buffer_raise(args[2], &src, MP_BUFFER_READ);
|
||||
uint32_t src_ofs = trezor_obj_get_uint(args[3]);
|
||||
|
||||
@ -104,7 +104,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorutils_memcpy_obj, 4, 5,
|
||||
/// Halts execution.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorutils_halt(size_t n_args, const mp_obj_t *args) {
|
||||
mp_buffer_info_t msg;
|
||||
mp_buffer_info_t msg = {0};
|
||||
if (n_args > 0 && mp_get_buffer(args[0], &msg, MP_BUFFER_READ)) {
|
||||
ensure(secfalse, msg.buf);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user