1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-03-05 09:46:07 +00:00

rename buffer variables, add const where possible

This commit is contained in:
Pavol Rusnak 2016-05-02 18:55:32 +02:00
parent 588be646c0
commit d2f65d67cd
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
11 changed files with 125 additions and 125 deletions

View File

@ -24,48 +24,48 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_make_new(const mp_obj_type_t *type, siz
// def Ed25519.publickey(self, secret_key: bytes) -> bytes // def Ed25519.publickey(self, secret_key: bytes) -> bytes
STATIC mp_obj_t mod_TrezorCrypto_Ed25519_publickey(mp_obj_t self, mp_obj_t secret_key) { STATIC mp_obj_t mod_TrezorCrypto_Ed25519_publickey(mp_obj_t self, mp_obj_t secret_key) {
mp_buffer_info_t skbuf; mp_buffer_info_t sk;
mp_get_buffer_raise(secret_key, &skbuf, MP_BUFFER_READ); mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
if (skbuf.len != 32) { if (sk.len != 32) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of secret key")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of secret key"));
} }
vstr_t vstr; vstr_t vstr;
vstr_init_len(&vstr, 32); vstr_init_len(&vstr, 32);
ed25519_publickey(*(const ed25519_secret_key *)skbuf.buf, *(ed25519_public_key *)vstr.buf); ed25519_publickey(*(const ed25519_secret_key *)sk.buf, *(ed25519_public_key *)vstr.buf);
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Ed25519_publickey_obj, mod_TrezorCrypto_Ed25519_publickey); STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Ed25519_publickey_obj, mod_TrezorCrypto_Ed25519_publickey);
// def Ed25519.sign(self, secret_key: bytes, message: bytes) -> bytes // def Ed25519.sign(self, secret_key: bytes, message: bytes) -> bytes
STATIC mp_obj_t mod_TrezorCrypto_Ed25519_sign(mp_obj_t self, mp_obj_t secret_key, mp_obj_t message) { STATIC mp_obj_t mod_TrezorCrypto_Ed25519_sign(mp_obj_t self, mp_obj_t secret_key, mp_obj_t message) {
mp_buffer_info_t skbuf, messagebuf; mp_buffer_info_t sk, msg;
mp_get_buffer_raise(secret_key, &skbuf, MP_BUFFER_READ); mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
mp_get_buffer_raise(message, &messagebuf, MP_BUFFER_READ); mp_get_buffer_raise(message, &msg, MP_BUFFER_READ);
if (skbuf.len != 32) { if (sk.len != 32) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of secret key")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of secret key"));
} }
ed25519_public_key pk; ed25519_public_key pk;
ed25519_publickey(*(const ed25519_secret_key *)skbuf.buf, pk); ed25519_publickey(*(const ed25519_secret_key *)sk.buf, pk);
vstr_t vstr; vstr_t vstr;
vstr_init_len(&vstr, 64); vstr_init_len(&vstr, 64);
ed25519_sign(messagebuf.buf, messagebuf.len, *(const ed25519_secret_key *)skbuf.buf, pk, *(ed25519_signature *)vstr.buf); ed25519_sign(msg.buf, msg.len, *(const ed25519_secret_key *)sk.buf, pk, *(ed25519_signature *)vstr.buf);
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Ed25519_sign_obj, mod_TrezorCrypto_Ed25519_sign); STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Ed25519_sign_obj, mod_TrezorCrypto_Ed25519_sign);
// def Ed25519.verify(self, public_key: bytes, signature: bytes, message: bytes) -> bool // def Ed25519.verify(self, public_key: bytes, signature: bytes, message: bytes) -> bool
STATIC mp_obj_t mod_TrezorCrypto_Ed25519_verify(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_TrezorCrypto_Ed25519_verify(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t pkbuf, sigbuf, messagebuf; mp_buffer_info_t pk, sig, msg;
mp_get_buffer_raise(args[1], &pkbuf, MP_BUFFER_READ); mp_get_buffer_raise(args[1], &pk, MP_BUFFER_READ);
mp_get_buffer_raise(args[2], &sigbuf, MP_BUFFER_READ); mp_get_buffer_raise(args[2], &sig, MP_BUFFER_READ);
mp_get_buffer_raise(args[3], &messagebuf, MP_BUFFER_READ); mp_get_buffer_raise(args[3], &msg, MP_BUFFER_READ);
if (pkbuf.len != 32) { if (pk.len != 32) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of public key")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of public key"));
} }
if (sigbuf.len != 64) { if (sig.len != 64) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of signature")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of signature"));
} }
return (0 == ed25519_sign_open(messagebuf.buf, messagebuf.len, *(const ed25519_public_key *)pkbuf.buf, *(const ed25519_signature *)sigbuf.buf)) ? mp_const_true : mp_const_false; return (0 == ed25519_sign_open(msg.buf, msg.len, *(const ed25519_public_key *)pk.buf, *(const ed25519_signature *)sig.buf)) ? mp_const_true : mp_const_false;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Ed25519_verify_obj, 4, 4, mod_TrezorCrypto_Ed25519_verify); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Ed25519_verify_obj, 4, 4, mod_TrezorCrypto_Ed25519_verify);

View File

@ -25,19 +25,19 @@ STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_make_new(const mp_obj_type_t *type, s
// def Nist256p1.publickey(self, secret_key: bytes, compressed: bool=True) -> bytes // def Nist256p1.publickey(self, secret_key: bytes, compressed: bool=True) -> bytes
STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_publickey(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_publickey(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t skbuf; mp_buffer_info_t sk;
mp_get_buffer_raise(args[1], &skbuf, MP_BUFFER_READ); mp_get_buffer_raise(args[1], &sk, MP_BUFFER_READ);
if (skbuf.len != 32) { if (sk.len != 32) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of secret key")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of secret key"));
} }
bool compressed = n_args < 3 || args[2] == mp_const_true; bool compressed = n_args < 3 || args[2] == mp_const_true;
vstr_t vstr; vstr_t vstr;
if (compressed) { if (compressed) {
vstr_init_len(&vstr, 33); vstr_init_len(&vstr, 33);
ecdsa_get_public_key33(&nist256p1, (const uint8_t *)skbuf.buf, (uint8_t *)vstr.buf); ecdsa_get_public_key33(&nist256p1, (const uint8_t *)sk.buf, (uint8_t *)vstr.buf);
} else { } else {
vstr_init_len(&vstr, 65); vstr_init_len(&vstr, 65);
ecdsa_get_public_key65(&nist256p1, (const uint8_t *)skbuf.buf, (uint8_t *)vstr.buf); ecdsa_get_public_key65(&nist256p1, (const uint8_t *)sk.buf, (uint8_t *)vstr.buf);
} }
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
} }
@ -45,16 +45,16 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Nist256p1_publickey_
// def Nist256p1.sign(self, secret_key: bytes, message: bytes) -> bytes // def Nist256p1.sign(self, secret_key: bytes, message: bytes) -> bytes
STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_sign(mp_obj_t self, mp_obj_t secret_key, mp_obj_t message) { STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_sign(mp_obj_t self, mp_obj_t secret_key, mp_obj_t message) {
mp_buffer_info_t skbuf, messagebuf; mp_buffer_info_t sk, msg;
mp_get_buffer_raise(secret_key, &skbuf, MP_BUFFER_READ); mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
mp_get_buffer_raise(message, &messagebuf, MP_BUFFER_READ); mp_get_buffer_raise(message, &msg, MP_BUFFER_READ);
if (skbuf.len != 32) { if (sk.len != 32) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of secret key")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of secret key"));
} }
vstr_t vstr; vstr_t vstr;
vstr_init_len(&vstr, 65); vstr_init_len(&vstr, 65);
uint8_t pby; uint8_t pby;
if (0 != ecdsa_sign(&nist256p1, (const uint8_t *)skbuf.buf, (const uint8_t *)messagebuf.buf, messagebuf.len, (uint8_t *)vstr.buf, &pby)) { if (0 != ecdsa_sign(&nist256p1, (const uint8_t *)sk.buf, (const uint8_t *)msg.buf, msg.len, (uint8_t *)vstr.buf, &pby)) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Signing failed")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Signing failed"));
} }
(void)pby; (void)pby;
@ -64,17 +64,17 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Nist256p1_sign_obj, mod_Trezor
// def Nist256p1.verify(self, public_key: bytes, signature: bytes, message: bytes) -> bool // def Nist256p1.verify(self, public_key: bytes, signature: bytes, message: bytes) -> bool
STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_verify(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_verify(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t pkbuf, sigbuf, messagebuf; mp_buffer_info_t pk, sig, msg;
mp_get_buffer_raise(args[1], &pkbuf, MP_BUFFER_READ); mp_get_buffer_raise(args[1], &pk, MP_BUFFER_READ);
mp_get_buffer_raise(args[2], &sigbuf, MP_BUFFER_READ); mp_get_buffer_raise(args[2], &sig, MP_BUFFER_READ);
mp_get_buffer_raise(args[3], &messagebuf, MP_BUFFER_READ); mp_get_buffer_raise(args[3], &msg, MP_BUFFER_READ);
if (pkbuf.len != 33 && pkbuf.len != 65) { if (pk.len != 33 && pk.len != 65) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of public key")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of public key"));
} }
if (sigbuf.len != 65) { if (sig.len != 65) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of signature")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of signature"));
} }
return mp_obj_new_bool(0 == ecdsa_verify(&nist256p1, (const uint8_t *)pkbuf.buf, (const uint8_t *)sigbuf.buf, (const uint8_t *)messagebuf.buf, messagebuf.len)); return mp_obj_new_bool(0 == ecdsa_verify(&nist256p1, (const uint8_t *)pk.buf, (const uint8_t *)sig.buf, (const uint8_t *)msg.buf, msg.len));
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Nist256p1_verify_obj, 4, 4, mod_TrezorCrypto_Nist256p1_verify); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Nist256p1_verify_obj, 4, 4, mod_TrezorCrypto_Nist256p1_verify);

View File

@ -36,9 +36,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_make_new(const mp_obj_type_t *type, s
// def Ripemd160.update(self, data: bytes) -> None // def Ripemd160.update(self, data: bytes) -> None
STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data) { STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self); mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t databuf; mp_buffer_info_t msg;
mp_get_buffer_raise(data, &databuf, MP_BUFFER_READ); mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
ripemd160_Update(&(o->ctx), databuf.buf, databuf.len); ripemd160_Update(&(o->ctx), msg.buf, msg.len);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Ripemd160_update_obj, mod_TrezorCrypto_Ripemd160_update); STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Ripemd160_update_obj, mod_TrezorCrypto_Ripemd160_update);

View File

@ -25,19 +25,19 @@ STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_make_new(const mp_obj_type_t *type, s
// def Secp256k1.publickey(self, secret_key: bytes, compressed: bool=True) -> bytes // def Secp256k1.publickey(self, secret_key: bytes, compressed: bool=True) -> bytes
STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_publickey(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_publickey(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t skbuf; mp_buffer_info_t sk;
mp_get_buffer_raise(args[1], &skbuf, MP_BUFFER_READ); mp_get_buffer_raise(args[1], &sk, MP_BUFFER_READ);
if (skbuf.len != 32) { if (sk.len != 32) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of secret key")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of secret key"));
} }
bool compressed = n_args < 3 || args[2] == mp_const_true; bool compressed = n_args < 3 || args[2] == mp_const_true;
vstr_t vstr; vstr_t vstr;
if (compressed) { if (compressed) {
vstr_init_len(&vstr, 33); vstr_init_len(&vstr, 33);
ecdsa_get_public_key33(&secp256k1, (const uint8_t *)skbuf.buf, (uint8_t *)vstr.buf); ecdsa_get_public_key33(&secp256k1, (const uint8_t *)sk.buf, (uint8_t *)vstr.buf);
} else { } else {
vstr_init_len(&vstr, 65); vstr_init_len(&vstr, 65);
ecdsa_get_public_key65(&secp256k1, (const uint8_t *)skbuf.buf, (uint8_t *)vstr.buf); ecdsa_get_public_key65(&secp256k1, (const uint8_t *)sk.buf, (uint8_t *)vstr.buf);
} }
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
} }
@ -45,16 +45,16 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Secp256k1_publickey_
// def Secp256k1.sign(self, secret_key: bytes, message: bytes) -> bytes // def Secp256k1.sign(self, secret_key: bytes, message: bytes) -> bytes
STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_sign(mp_obj_t self, mp_obj_t secret_key, mp_obj_t message) { STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_sign(mp_obj_t self, mp_obj_t secret_key, mp_obj_t message) {
mp_buffer_info_t skbuf, messagebuf; mp_buffer_info_t sk, msg;
mp_get_buffer_raise(secret_key, &skbuf, MP_BUFFER_READ); mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
mp_get_buffer_raise(message, &messagebuf, MP_BUFFER_READ); mp_get_buffer_raise(message, &msg, MP_BUFFER_READ);
if (skbuf.len != 32) { if (sk.len != 32) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of secret key")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of secret key"));
} }
vstr_t vstr; vstr_t vstr;
vstr_init_len(&vstr, 65); vstr_init_len(&vstr, 65);
uint8_t pby; uint8_t pby;
if (0 != ecdsa_sign(&secp256k1, (const uint8_t *)skbuf.buf, (const uint8_t *)messagebuf.buf, messagebuf.len, (uint8_t *)vstr.buf, &pby)) { if (0 != ecdsa_sign(&secp256k1, (const uint8_t *)sk.buf, (const uint8_t *)msg.buf, msg.len, (uint8_t *)vstr.buf, &pby)) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Signing failed")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Signing failed"));
} }
(void)pby; (void)pby;
@ -64,17 +64,17 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Secp256k1_sign_obj, mod_Trezor
// def Secp256k1.verify(self, public_key: bytes, signature: bytes, message: bytes) -> bool // def Secp256k1.verify(self, public_key: bytes, signature: bytes, message: bytes) -> bool
STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_verify(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_verify(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t pkbuf, sigbuf, messagebuf; mp_buffer_info_t pk, sig, msg;
mp_get_buffer_raise(args[1], &pkbuf, MP_BUFFER_READ); mp_get_buffer_raise(args[1], &pk, MP_BUFFER_READ);
mp_get_buffer_raise(args[2], &sigbuf, MP_BUFFER_READ); mp_get_buffer_raise(args[2], &sig, MP_BUFFER_READ);
mp_get_buffer_raise(args[3], &messagebuf, MP_BUFFER_READ); mp_get_buffer_raise(args[3], &msg, MP_BUFFER_READ);
if (pkbuf.len != 33 && pkbuf.len != 65) { if (pk.len != 33 && pk.len != 65) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of public key")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of public key"));
} }
if (sigbuf.len != 65) { if (sig.len != 65) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of signature")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid length of signature"));
} }
return mp_obj_new_bool(0 == ecdsa_verify(&secp256k1, (const uint8_t *)pkbuf.buf, (const uint8_t *)sigbuf.buf, (const uint8_t *)messagebuf.buf, messagebuf.len)); return mp_obj_new_bool(0 == ecdsa_verify(&secp256k1, (const uint8_t *)pk.buf, (const uint8_t *)sig.buf, (const uint8_t *)msg.buf, msg.len));
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Secp256k1_verify_obj, 4, 4, mod_TrezorCrypto_Secp256k1_verify); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Secp256k1_verify_obj, 4, 4, mod_TrezorCrypto_Secp256k1_verify);

View File

@ -36,9 +36,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha256_make_new(const mp_obj_type_t *type, size
// def Sha256.update(self, data: bytes) -> None // def Sha256.update(self, data: bytes) -> None
STATIC mp_obj_t mod_TrezorCrypto_Sha256_update(mp_obj_t self, mp_obj_t data) { STATIC mp_obj_t mod_TrezorCrypto_Sha256_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self); mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t databuf; mp_buffer_info_t msg;
mp_get_buffer_raise(data, &databuf, MP_BUFFER_READ); mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
sha256_Update(&(o->ctx), databuf.buf, databuf.len); sha256_Update(&(o->ctx), msg.buf, msg.len);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha256_update_obj, mod_TrezorCrypto_Sha256_update); STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha256_update_obj, mod_TrezorCrypto_Sha256_update);

View File

@ -36,9 +36,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_make_new(const mp_obj_type_t *type, si
// def Sha3_256.update(self, data: bytes) -> None // def Sha3_256.update(self, data: bytes) -> None
STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data) { STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(self); mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t databuf; mp_buffer_info_t msg;
mp_get_buffer_raise(data, &databuf, MP_BUFFER_READ); mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
sha3_Update(&(o->ctx), databuf.buf, databuf.len); sha3_Update(&(o->ctx), msg.buf, msg.len);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha3_256_update_obj, mod_TrezorCrypto_Sha3_256_update); STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha3_256_update_obj, mod_TrezorCrypto_Sha3_256_update);

View File

@ -36,9 +36,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_make_new(const mp_obj_type_t *type, si
// def Sha3_512.update(self, data: bytes) -> None // def Sha3_512.update(self, data: bytes) -> None
STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data) { STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(self); mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t databuf; mp_buffer_info_t msg;
mp_get_buffer_raise(data, &databuf, MP_BUFFER_READ); mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
sha3_Update(&(o->ctx), databuf.buf, databuf.len); sha3_Update(&(o->ctx), msg.buf, msg.len);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha3_512_update_obj, mod_TrezorCrypto_Sha3_512_update); STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha3_512_update_obj, mod_TrezorCrypto_Sha3_512_update);

View File

@ -35,9 +35,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha512_make_new(const mp_obj_type_t *type, size
// def Sha512.hash(self, data: bytes) -> None // def Sha512.hash(self, data: bytes) -> None
STATIC mp_obj_t mod_TrezorCrypto_Sha512_update(mp_obj_t self, mp_obj_t data) { STATIC mp_obj_t mod_TrezorCrypto_Sha512_update(mp_obj_t self, mp_obj_t data) {
mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self); mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self);
mp_buffer_info_t databuf; mp_buffer_info_t msg;
mp_get_buffer_raise(data, &databuf, MP_BUFFER_READ); mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
sha512_Update(&(o->ctx), databuf.buf, databuf.len); sha512_Update(&(o->ctx), msg.buf, msg.len);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha512_update_obj, mod_TrezorCrypto_Sha512_update); STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha512_update_obj, mod_TrezorCrypto_Sha512_update);

View File

@ -40,9 +40,9 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_make_new(const mp_obj_type_t *type, size_t n_a
// def Msg.send(self, message) -> int // def Msg.send(self, message) -> int
STATIC mp_obj_t mod_TrezorMsg_Msg_send(mp_obj_t self, mp_obj_t message) { STATIC mp_obj_t mod_TrezorMsg_Msg_send(mp_obj_t self, mp_obj_t message) {
mp_buffer_info_t buf; mp_buffer_info_t msg;
mp_get_buffer_raise(message, &buf, MP_BUFFER_READ); mp_get_buffer_raise(message, &msg, MP_BUFFER_READ);
int r = msg_send(buf.buf, buf.len); int r = msg_send(msg.buf, msg.len);
return MP_OBJ_NEW_SMALL_INT(r); return MP_OBJ_NEW_SMALL_INT(r);
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorMsg_Msg_send_obj, mod_TrezorMsg_Msg_send); STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorMsg_Msg_send_obj, mod_TrezorMsg_Msg_send);
@ -51,9 +51,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorMsg_Msg_send_obj, mod_TrezorMsg_Msg_s
// def Msg.select(self, timeout_us: int) -> None/tuple/bytes // def Msg.select(self, timeout_us: int) -> None/tuple/bytes
STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_us) { STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_us) {
int to = mp_obj_get_int(timeout_us); int timeout = mp_obj_get_int(timeout_us);
if (to < 0) { if (timeout < 0) {
to = 0; timeout = 0;
} }
for(;;) { for(;;) {
uint32_t e = msg_poll_ui_event(); uint32_t e = msg_poll_ui_event();
@ -74,11 +74,11 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_us) {
tuple->items[1] = mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); tuple->items[1] = mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
return MP_OBJ_FROM_PTR(tuple); return MP_OBJ_FROM_PTR(tuple);
} }
if (to <= 0) { if (timeout <= 0) {
break; break;
} }
mp_hal_delay_us_fast(TICK_RESOLUTION); mp_hal_delay_us_fast(TICK_RESOLUTION);
to -= TICK_RESOLUTION; timeout -= TICK_RESOLUTION;
} }
return mp_const_none; return mp_const_none;
} }

View File

@ -14,7 +14,7 @@
// common display functions // common display functions
static void DATAS(void *bytes, int len) { static void DATAS(const void *bytes, int len) {
const uint8_t *c = (const uint8_t *)bytes; const uint8_t *c = (const uint8_t *)bytes;
while (len-- > 0) { while (len-- > 0) {
DATA(*c); DATA(*c);
@ -31,7 +31,7 @@ static void display_bar(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t c)
display_update(); display_update();
} }
static void display_blit(uint8_t x, uint8_t y, uint8_t w, uint8_t h, void *data, int datalen) { static void display_blit(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const void *data, int datalen) {
display_set_window(x, y, w, h); display_set_window(x, y, w, h);
DATAS(data, datalen); DATAS(data, datalen);
display_update(); display_update();
@ -42,7 +42,7 @@ static void inflate_callback_image(uint8_t byte, uint32_t pos, void *userdata)
DATA(byte); DATA(byte);
} }
static void display_image(uint8_t x, uint8_t y, uint8_t w, uint8_t h, void *data, int datalen) { static void display_image(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const void *data, int datalen) {
display_set_window(x, y, w, h); display_set_window(x, y, w, h);
sinf_inflate(data, inflate_callback_image, NULL); sinf_inflate(data, inflate_callback_image, NULL);
display_update(); display_update();
@ -68,7 +68,7 @@ static void inflate_callback_icon(uint8_t byte, uint32_t pos, void *userdata)
DATA(colortable[byte & 0x0F] & 0xFF); DATA(colortable[byte & 0x0F] & 0xFF);
} }
static void display_icon(uint8_t x, uint8_t y, uint8_t w, uint8_t h, void *data, int datalen, uint16_t fgcolor, uint16_t bgcolor) { static void display_icon(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const void *data, int datalen, uint16_t fgcolor, uint16_t bgcolor) {
display_set_window(x, y, w, h); display_set_window(x, y, w, h);
uint16_t colortable[16]; uint16_t colortable[16];
set_color_table(colortable, fgcolor, bgcolor); set_color_table(colortable, fgcolor, bgcolor);
@ -102,7 +102,7 @@ static const uint8_t *get_glyph(uint8_t font, uint8_t c) {
// first two bytes are width and height of the glyph // first two bytes are width and height of the glyph
// third, fourth and fifth bytes are advance, bearingX and bearingY of the horizontal metrics of the glyph // third, fourth and fifth bytes are advance, bearingX and bearingY of the horizontal metrics of the glyph
// rest is packed 4-bit glyph data // rest is packed 4-bit glyph data
static void display_text(uint8_t x, uint8_t y, uint8_t *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor) { static void display_text(uint8_t x, uint8_t y, const uint8_t *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor) {
uint32_t px = x; uint32_t px = x;
uint16_t colortable[16]; uint16_t colortable[16];
set_color_table(colortable, fgcolor, bgcolor); set_color_table(colortable, fgcolor, bgcolor);
@ -133,7 +133,7 @@ static void display_text(uint8_t x, uint8_t y, uint8_t *text, int textlen, uint8
} }
// compute the width of the text (in pixels) // compute the width of the text (in pixels)
static uint32_t display_text_width(uint8_t *text, int textlen, uint8_t font) { static uint32_t display_text_width(const uint8_t *text, int textlen, uint8_t font) {
uint32_t w = 0; uint32_t w = 0;
for (int i = 0; i < textlen; i++) { for (int i = 0; i < textlen; i++) {
const uint8_t *g = get_glyph(font, text[i]); const uint8_t *g = get_glyph(font, text[i]);
@ -143,7 +143,7 @@ static uint32_t display_text_width(uint8_t *text, int textlen, uint8_t font) {
return w; return w;
} }
static void display_qrcode(uint8_t x, uint8_t y, char *data, int datalen, int scale) { static void display_qrcode(uint8_t x, uint8_t y, const char *data, int datalen, int scale) {
uint8_t bitdata[QR_MAX_BITDATA]; uint8_t bitdata[QR_MAX_BITDATA];
int side = qr_encode(QR_LEVEL_M, 0, data, datalen, bitdata); int side = qr_encode(QR_LEVEL_M, 0, data, datalen, bitdata);
display_set_window(x, y, side * scale, side * scale); display_set_window(x, y, side * scale, side * scale);
@ -215,7 +215,7 @@ static void display_loader(uint16_t progress, uint16_t fgcolor, uint16_t bgcolor
display_update(); display_update();
} }
static void display_raw(uint8_t reg, uint8_t *data, int datalen) static void display_raw(uint8_t reg, const uint8_t *data, int datalen)
{ {
if (reg) { if (reg) {
CMD(reg); CMD(reg);
@ -258,12 +258,12 @@ STATIC mp_obj_t mod_TrezorUi_Display_blit(size_t n_args, const mp_obj_t *args) {
mp_int_t y = mp_obj_get_int(args[2]); mp_int_t y = mp_obj_get_int(args[2]);
mp_int_t w = mp_obj_get_int(args[3]); mp_int_t w = mp_obj_get_int(args[3]);
mp_int_t h = mp_obj_get_int(args[4]); mp_int_t h = mp_obj_get_int(args[4]);
mp_buffer_info_t bufinfo; mp_buffer_info_t data;
mp_get_buffer_raise(args[5], &bufinfo, MP_BUFFER_READ); mp_get_buffer_raise(args[5], &data, MP_BUFFER_READ);
if (bufinfo.len != 2 * w * h) { if (data.len != 2 * w * h) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Wrong data size (got %d bytes, expected %d bytes)", bufinfo.len, 2 * w * h)); nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Wrong data size (got %d bytes, expected %d bytes)", data.len, 2 * w * h));
} }
display_blit(x, y, w, h, bufinfo.buf, bufinfo.len); display_blit(x, y, w, h, data.buf, data.len);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_blit_obj, 6, 6, mod_TrezorUi_Display_blit); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_blit_obj, 6, 6, mod_TrezorUi_Display_blit);
@ -272,10 +272,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_blit_obj, 6, 6,
STATIC mp_obj_t mod_TrezorUi_Display_image(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_TrezorUi_Display_image(size_t n_args, const mp_obj_t *args) {
mp_int_t x = mp_obj_get_int(args[1]); mp_int_t x = mp_obj_get_int(args[1]);
mp_int_t y = mp_obj_get_int(args[2]); mp_int_t y = mp_obj_get_int(args[2]);
mp_buffer_info_t bufinfo; mp_buffer_info_t image;
mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ); mp_get_buffer_raise(args[3], &image, MP_BUFFER_READ);
uint8_t *data = bufinfo.buf; const uint8_t *data = image.buf;
if (bufinfo.len < 8 || memcmp(data, "TOIf", 4) != 0) { if (image.len < 8 || memcmp(data, "TOIf", 4) != 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid image format")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid image format"));
} }
mp_int_t w = *(uint16_t *)(data + 4); mp_int_t w = *(uint16_t *)(data + 4);
@ -284,10 +284,10 @@ STATIC mp_obj_t mod_TrezorUi_Display_image(size_t n_args, const mp_obj_t *args)
if ((x < 0) || (y < 0) || (x + w > RESX) || (y + h > RESY)) { if ((x < 0) || (y < 0) || (x + w > RESX) || (y + h > RESY)) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Out of bounds")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Out of bounds"));
} }
if (datalen != bufinfo.len - 12) { if (datalen != image.len - 12) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid size of data")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid size of data"));
} }
display_image(x, y, w, h, data + 12, bufinfo.len - 12); display_image(x, y, w, h, data + 12, image.len - 12);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_image_obj, 4, 4, mod_TrezorUi_Display_image); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_image_obj, 4, 4, mod_TrezorUi_Display_image);
@ -296,10 +296,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_image_obj, 4, 4,
STATIC mp_obj_t mod_TrezorUi_Display_icon(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_TrezorUi_Display_icon(size_t n_args, const mp_obj_t *args) {
mp_int_t x = mp_obj_get_int(args[1]); mp_int_t x = mp_obj_get_int(args[1]);
mp_int_t y = mp_obj_get_int(args[2]); mp_int_t y = mp_obj_get_int(args[2]);
mp_buffer_info_t bufinfo; mp_buffer_info_t icon;
mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ); mp_get_buffer_raise(args[3], &icon, MP_BUFFER_READ);
uint8_t *data = bufinfo.buf; const uint8_t *data = icon.buf;
if (bufinfo.len < 8 || memcmp(data, "TOIg", 4) != 0) { if (icon.len < 8 || memcmp(data, "TOIg", 4) != 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid image format")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid image format"));
} }
mp_int_t w = *(uint16_t *)(data + 4); mp_int_t w = *(uint16_t *)(data + 4);
@ -308,12 +308,12 @@ STATIC mp_obj_t mod_TrezorUi_Display_icon(size_t n_args, const mp_obj_t *args) {
if ((x < 0) || (y < 0) || (x + w > RESX) || (y + h > RESY)) { if ((x < 0) || (y < 0) || (x + w > RESX) || (y + h > RESY)) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Out of bounds")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Out of bounds"));
} }
if (datalen != bufinfo.len - 12) { if (datalen != icon.len - 12) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid size of data")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid size of data"));
} }
mp_int_t fgcolor = mp_obj_get_int(args[4]); mp_int_t fgcolor = mp_obj_get_int(args[4]);
mp_int_t bgcolor = mp_obj_get_int(args[5]); mp_int_t bgcolor = mp_obj_get_int(args[5]);
display_icon(x, y, w, h, data + 12, bufinfo.len - 12, fgcolor, bgcolor); display_icon(x, y, w, h, data + 12, icon.len - 12, fgcolor, bgcolor);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_icon_obj, 6, 6, mod_TrezorUi_Display_icon); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_icon_obj, 6, 6, mod_TrezorUi_Display_icon);
@ -322,12 +322,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_icon_obj, 6, 6,
STATIC mp_obj_t mod_TrezorUi_Display_text(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_TrezorUi_Display_text(size_t n_args, const mp_obj_t *args) {
mp_int_t x = mp_obj_get_int(args[1]); mp_int_t x = mp_obj_get_int(args[1]);
mp_int_t y = mp_obj_get_int(args[2]); mp_int_t y = mp_obj_get_int(args[2]);
mp_buffer_info_t bufinfo; mp_buffer_info_t text;
mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ); mp_get_buffer_raise(args[3], &text, MP_BUFFER_READ);
mp_int_t font = mp_obj_get_int(args[4]); mp_int_t font = mp_obj_get_int(args[4]);
mp_int_t fgcolor = mp_obj_get_int(args[5]); mp_int_t fgcolor = mp_obj_get_int(args[5]);
mp_int_t bgcolor = mp_obj_get_int(args[6]); mp_int_t bgcolor = mp_obj_get_int(args[6]);
display_text(x, y, bufinfo.buf, bufinfo.len, font, fgcolor, bgcolor); display_text(x, y, text.buf, text.len, font, fgcolor, bgcolor);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_text_obj, 7, 7, mod_TrezorUi_Display_text); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_text_obj, 7, 7, mod_TrezorUi_Display_text);
@ -336,13 +336,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_text_obj, 7, 7,
STATIC mp_obj_t mod_TrezorUi_Display_text_center(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_TrezorUi_Display_text_center(size_t n_args, const mp_obj_t *args) {
mp_int_t x = mp_obj_get_int(args[1]); mp_int_t x = mp_obj_get_int(args[1]);
mp_int_t y = mp_obj_get_int(args[2]); mp_int_t y = mp_obj_get_int(args[2]);
mp_buffer_info_t bufinfo; mp_buffer_info_t text;
mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ); mp_get_buffer_raise(args[3], &text, MP_BUFFER_READ);
mp_int_t font = mp_obj_get_int(args[4]); mp_int_t font = mp_obj_get_int(args[4]);
mp_int_t fgcolor = mp_obj_get_int(args[5]); mp_int_t fgcolor = mp_obj_get_int(args[5]);
mp_int_t bgcolor = mp_obj_get_int(args[6]); mp_int_t bgcolor = mp_obj_get_int(args[6]);
uint32_t w = display_text_width(bufinfo.buf, bufinfo.len, font); uint32_t w = display_text_width(text.buf, text.len, font);
display_text(x - w / 2, y, bufinfo.buf, bufinfo.len, font, fgcolor, bgcolor); display_text(x - w / 2, y, text.buf, text.len, font, fgcolor, bgcolor);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_text_center_obj, 7, 7, mod_TrezorUi_Display_text_center); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_text_center_obj, 7, 7, mod_TrezorUi_Display_text_center);
@ -351,23 +351,23 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_text_center_obj,
STATIC mp_obj_t mod_TrezorUi_Display_text_right(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_TrezorUi_Display_text_right(size_t n_args, const mp_obj_t *args) {
mp_int_t x = mp_obj_get_int(args[1]); mp_int_t x = mp_obj_get_int(args[1]);
mp_int_t y = mp_obj_get_int(args[2]); mp_int_t y = mp_obj_get_int(args[2]);
mp_buffer_info_t bufinfo; mp_buffer_info_t text;
mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ); mp_get_buffer_raise(args[3], &text, MP_BUFFER_READ);
mp_int_t font = mp_obj_get_int(args[4]); mp_int_t font = mp_obj_get_int(args[4]);
mp_int_t fgcolor = mp_obj_get_int(args[5]); mp_int_t fgcolor = mp_obj_get_int(args[5]);
mp_int_t bgcolor = mp_obj_get_int(args[6]); mp_int_t bgcolor = mp_obj_get_int(args[6]);
uint32_t w = display_text_width(bufinfo.buf, bufinfo.len, font); uint32_t w = display_text_width(text.buf, text.len, font);
display_text(x - w, y, bufinfo.buf, bufinfo.len, font, fgcolor, bgcolor); display_text(x - w, y, text.buf, text.len, font, fgcolor, bgcolor);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_text_right_obj, 7, 7, mod_TrezorUi_Display_text_right); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_text_right_obj, 7, 7, mod_TrezorUi_Display_text_right);
// def Display.text_width(self, text: bytes, font: int) -> int // def Display.text_width(self, text: bytes, font: int) -> int
STATIC mp_obj_t mod_TrezorUi_Display_text_width(mp_obj_t self, mp_obj_t text, mp_obj_t font) { STATIC mp_obj_t mod_TrezorUi_Display_text_width(mp_obj_t self, mp_obj_t text, mp_obj_t font) {
mp_buffer_info_t bufinfo; mp_buffer_info_t txt;
mp_get_buffer_raise(text, &bufinfo, MP_BUFFER_READ); mp_get_buffer_raise(text, &txt, MP_BUFFER_READ);
mp_int_t f = mp_obj_get_int(font); mp_int_t f = mp_obj_get_int(font);
uint32_t w = display_text_width(bufinfo.buf, bufinfo.len, f); uint32_t w = display_text_width(txt.buf, txt.len, f);
return MP_OBJ_NEW_SMALL_INT(w); return MP_OBJ_NEW_SMALL_INT(w);
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorUi_Display_text_width_obj, mod_TrezorUi_Display_text_width); STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorUi_Display_text_width_obj, mod_TrezorUi_Display_text_width);
@ -380,9 +380,9 @@ STATIC mp_obj_t mod_TrezorUi_Display_qrcode(size_t n_args, const mp_obj_t *args)
if (scale < 1 || scale > 10) { if (scale < 1 || scale > 10) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Scale has to be between 1 and 10")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Scale has to be between 1 and 10"));
} }
mp_buffer_info_t bufinfo; mp_buffer_info_t data;
mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ); mp_get_buffer_raise(args[3], &data, MP_BUFFER_READ);
display_qrcode(x, y, bufinfo.buf, bufinfo.len, scale); display_qrcode(x, y, data.buf, data.len, scale);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_qrcode_obj, 5, 5, mod_TrezorUi_Display_qrcode); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_qrcode_obj, 5, 5, mod_TrezorUi_Display_qrcode);
@ -400,10 +400,10 @@ STATIC mp_obj_t mod_TrezorUi_Display_loader(size_t n_args, const mp_obj_t *args)
mp_int_t fgcolor = mp_obj_get_int(args[2]); mp_int_t fgcolor = mp_obj_get_int(args[2]);
mp_int_t bgcolor = mp_obj_get_int(args[3]); mp_int_t bgcolor = mp_obj_get_int(args[3]);
if (n_args > 4) { // icon provided if (n_args > 4) { // icon provided
mp_buffer_info_t bufinfo; mp_buffer_info_t icon;
mp_get_buffer_raise(args[4], &bufinfo, MP_BUFFER_READ); mp_get_buffer_raise(args[4], &icon, MP_BUFFER_READ);
uint8_t *data = bufinfo.buf; const uint8_t *data = icon.buf;
if (bufinfo.len < 8 || memcmp(data, "TOIg", 4) != 0) { if (icon.len < 8 || memcmp(data, "TOIg", 4) != 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid image format")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid image format"));
} }
mp_int_t w = *(uint16_t *)(data + 4); mp_int_t w = *(uint16_t *)(data + 4);
@ -412,7 +412,7 @@ STATIC mp_obj_t mod_TrezorUi_Display_loader(size_t n_args, const mp_obj_t *args)
if (w != 96 || h != 96) { if (w != 96 || h != 96) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid icon size")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid icon size"));
} }
if (datalen != bufinfo.len - 12) { if (datalen != icon.len - 12) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid size of data")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid size of data"));
} }
uint8_t icondata[96 * 96 /2]; uint8_t icondata[96 * 96 /2];
@ -445,9 +445,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUi_Display_orientation_obj, mod_Trezo
// def Display.raw(self, reg: int, data: bytes) -> None // def Display.raw(self, reg: int, data: bytes) -> None
STATIC mp_obj_t mod_TrezorUi_Display_raw(mp_obj_t self, mp_obj_t reg, mp_obj_t data) { STATIC mp_obj_t mod_TrezorUi_Display_raw(mp_obj_t self, mp_obj_t reg, mp_obj_t data) {
mp_int_t r = mp_obj_get_int(reg); mp_int_t r = mp_obj_get_int(reg);
mp_buffer_info_t bufinfo; mp_buffer_info_t raw;
mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ); mp_get_buffer_raise(data, &raw, MP_BUFFER_READ);
display_raw(r, bufinfo.buf, bufinfo.len); display_raw(r, raw.buf, raw.len);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorUi_Display_raw_obj, mod_TrezorUi_Display_raw); STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorUi_Display_raw_obj, mod_TrezorUi_Display_raw);

View File

@ -394,7 +394,7 @@ static int sinf_inflate_dynamic_block(SINF_DATA *d)
* ---------------------- */ * ---------------------- */
/* inflate stream from source */ /* inflate stream from source */
static int sinf_inflate(uint8_t *data, void (*write_callback)(uint8_t byte, uint32_t pos, void *userdata), void *userdata) static int sinf_inflate(const uint8_t *data, void (*write_callback)(uint8_t byte, uint32_t pos, void *userdata), void *userdata)
{ {
SINF_DATA d; SINF_DATA d;
int bfinal; int bfinal;