1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

update docu, add display.backlight

This commit is contained in:
Pavol Rusnak 2016-04-03 15:26:49 +02:00
parent 516057a7fa
commit 089409c995
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
5 changed files with 185 additions and 149 deletions

145
docs/api-ideas.md Normal file
View File

@ -0,0 +1,145 @@
##trezor.crypto
###trezor.crypto.aes
``` python
AES_CTX = object # AES context
def aes_encrypt_key128(key: bytes16, iv: bytes16 = None) -> AES_CTX: # context
def aes_encrypt_key192(key: bytes24, iv: bytes16 = None) -> AES_CTX: # context
def aes_encrypt_key256(key: bytes32, iv: bytes16 = None) -> AES_CTX: # context
def aes_decrypt_key128(key: bytes16, iv: bytes16 = None) -> AES_CTX: # context
def aes_decrypt_key192(key: bytes24, iv: bytes16 = None) -> AES_CTX: # context
def aes_decrypt_key256(key: bytes32, iv: bytes16 = None) -> AES_CTX: # context
def aes_ecb_encrypt(ctx: AES_CTX, data: bytes) -> bytes: # encrypted
def aes_cbc_encrypt(ctx: AES_CTX, data: bytes) -> bytes: # encrypted
def aes_cfb_encrypt(ctx: AES_CTX, data: bytes) -> bytes: # encrypted
def aes_ofb_encrypt(ctx: AES_CTX, data: bytes) -> bytes: # encrypted
def aes_ctr_encrypt(ctx: AES_CTX, data: bytes) -> bytes: # encrypted
def aes_ecb_decrypt(ctx: AES_CTX, data: bytes) -> bytes: # decrypted
def aes_cbc_decrypt(ctx: AES_CTX, data: bytes) -> bytes: # decrypted
def aes_cfb_decrypt(ctx: AES_CTX, data: bytes) -> bytes: # decrypted
def aes_ofb_decrypt(ctx: AES_CTX, data: bytes) -> bytes: # decrypted
def aes_ctr_decrypt(ctx: AES_CTX, data: bytes) -> bytes: # decrypted
```
###trezor.crypto.base58
``` python
def encode(data: bytes) -> bytes: # encoded
def decode(data: bytes) -> bytes: # decoded
def encode_check(data: bytes) -> bytes: # encoded
def decode_check(data: bytes) -> bytes: # decoded
```
###trezor.crypto.ed25519
``` python
def to_public(secret_key: bytes32) -> bytes32: # public_key
def sign(message: bytes, secret_key: bytes32, public_key: bytes32 = None) -> bytes64: # signature
def verify(message: bytes, public_key: bytes32, signature: bytes64) -> bool: # valid
```
###trezor.crypto.hash
``` python
def sha256(data: bytes) -> bytes32: # hashed
def sha512(data: bytes) -> bytes64: # hashed
def ripemd160(data: bytes) -> bytes20: # hashed
```
###trezor.crypto.hd
TODO
###trezor.crypto.hmac
``` python
def hmac_sha256(key: bytes, message: bytes) -> bytes32: # hmac
def hmac_sha512(key: bytes, message: bytes) -> bytes64: # hmac
```
###trezor.crypto.kdf
``` python
def pbkdf2_hmac_sha256(password: bytes, salt: bytes, iterations: int, keylen: int) -> bytes32: # key
def pbkdf2_hmac_sha512(password: bytes, salt: bytes, iterations: int, keylen: int) -> bytes32: # key
```
###trezor.crypto.mnemonic
``` python
def bip39_generate(strength: int) -> bytes: # sentence
def bip39_fromdata(data: bytes) -> bytes: # sentence
def bip39_check(mnemonic: bytes) -> bool: # valid
def bip39_seed(mnemonic: bytes, passphrase: bytes) -> bytes64: # seed
```
###trezor.crypto.nistp256
``` python
def to_public(secret_key: bytes32) -> bytes33: # public_key
def sign(message: bytes, secret_key: bytes32, public_key: bytes33 = None) -> bytes65: # signature
def verify(message: bytes, public_key: bytes33, signature: bytes65) -> bool: # valid
```
###trezor.crypto.reedsolomon
``` python
def encode(data: bytes) -> bytes: # encoded
def decode(data: bytes) -> bytes: # decoded
```
###trezor.crypto.secp256k1
``` python
def to_public(secret_key: bytes32) -> bytes33: # public_key
def sign(message: bytes, secret_key: bytes32, public_key: bytes33 = None) -> bytes65: # signature
def verify(message: bytes, public_key: bytes33, signature: bytes65) -> bool: # valid
```
##trezor.utils
###trezor.utils.qrenc
``` python
class QrLevel(Enum):
L = 0
M = 1
Q = 2
H = 3
def encode(source: bytes, level: QrLevel = QrLevel.H) -> list: # data
```

View File

@ -15,158 +15,34 @@ bytes65 = bytes # bytes variable of exactly 65 bytes
Syntax used below is a valid Python function declaration with type hints defined in [PEP 0484](https://www.python.org/dev/peps/pep-0484/).
##trezor.crypto
##trezor.ui
###trezor.crypto.aes
###trezor.ui.display
``` python
AES_CTX = object # AES context
trezor.ui.display.bar(self, x: int, y: int, w: int, h: int, color: int) -> None
def aes_encrypt_key128(key: bytes16, iv: bytes16 = None) -> AES_CTX: # context
trezor.ui.display.blit(self, x: int, y: int, w: int, h: int, data: bytes) -> None
def aes_encrypt_key192(key: bytes24, iv: bytes16 = None) -> AES_CTX: # context
trezor.ui.display.image(self, x: int, y: int, image: bytes) -> None
def aes_encrypt_key256(key: bytes32, iv: bytes16 = None) -> AES_CTX: # context
trezor.ui.display.icon(self, x: int, y: int, icon: bytes, fgcolor: int, bgcolor: int) -> None
def aes_decrypt_key128(key: bytes16, iv: bytes16 = None) -> AES_CTX: # context
trezor.ui.display.text(self, x: int, y: int, text: bytes, font: int, fgcolor: int, bgcolor: int) -> None
def aes_decrypt_key192(key: bytes24, iv: bytes16 = None) -> AES_CTX: # context
trezor.ui.display.orientation(self, degrees: int) -> None
def aes_decrypt_key256(key: bytes32, iv: bytes16 = None) -> AES_CTX: # context
trezor.ui.display.rawcmd(self, reg: int, data: bytes) -> None
def aes_ecb_encrypt(ctx: AES_CTX, data: bytes) -> bytes: # encrypted
def aes_cbc_encrypt(ctx: AES_CTX, data: bytes) -> bytes: # encrypted
def aes_cfb_encrypt(ctx: AES_CTX, data: bytes) -> bytes: # encrypted
def aes_ofb_encrypt(ctx: AES_CTX, data: bytes) -> bytes: # encrypted
def aes_ctr_encrypt(ctx: AES_CTX, data: bytes) -> bytes: # encrypted
def aes_ecb_decrypt(ctx: AES_CTX, data: bytes) -> bytes: # decrypted
def aes_cbc_decrypt(ctx: AES_CTX, data: bytes) -> bytes: # decrypted
def aes_cfb_decrypt(ctx: AES_CTX, data: bytes) -> bytes: # decrypted
def aes_ofb_decrypt(ctx: AES_CTX, data: bytes) -> bytes: # decrypted
def aes_ctr_decrypt(ctx: AES_CTX, data: bytes) -> bytes: # decrypted
trezor.ui.display.backlight(self, val: int) -> None
```
###trezor.crypto.base58
###trezor.ui.touch
``` python
def encode(data: bytes) -> bytes: # encoded
trezor.ui.touch.callback_start(self, callback) -> None
def decode(data: bytes) -> bytes: # decoded
trezor.ui.touch.callback_move(self, callback) -> None
def encode_check(data: bytes) -> bytes: # encoded
def decode_check(data: bytes) -> bytes: # decoded
```
###trezor.crypto.ed25519
``` python
def to_public(secret_key: bytes32) -> bytes32: # public_key
def sign(message: bytes, secret_key: bytes32, public_key: bytes32 = None) -> bytes64: # signature
def verify(message: bytes, public_key: bytes32, signature: bytes64) -> bool: # valid
```
###trezor.crypto.hash
``` python
def sha256(data: bytes) -> bytes32: # hashed
def sha512(data: bytes) -> bytes64: # hashed
def ripemd160(data: bytes) -> bytes20: # hashed
```
###trezor.crypto.hd
TODO
###trezor.crypto.hmac
``` python
def hmac_sha256(key: bytes, message: bytes) -> bytes32: # hmac
def hmac_sha512(key: bytes, message: bytes) -> bytes64: # hmac
```
###trezor.crypto.kdf
``` python
def pbkdf2_hmac_sha256(password: bytes, salt: bytes, iterations: int, keylen: int) -> bytes32: # key
def pbkdf2_hmac_sha512(password: bytes, salt: bytes, iterations: int, keylen: int) -> bytes32: # key
```
###trezor.crypto.mnemonic
``` python
def bip39_generate(strength: int) -> bytes: # sentence
def bip39_fromdata(data: bytes) -> bytes: # sentence
def bip39_check(mnemonic: bytes) -> bool: # valid
def bip39_seed(mnemonic: bytes, passphrase: bytes) -> bytes64: # seed
```
###trezor.crypto.nistp256
``` python
def to_public(secret_key: bytes32) -> bytes33: # public_key
def sign(message: bytes, secret_key: bytes32, public_key: bytes33 = None) -> bytes65: # signature
def verify(message: bytes, public_key: bytes33, signature: bytes65) -> bool: # valid
```
###trezor.crypto.reedsolomon
``` python
def encode(data: bytes) -> bytes: # encoded
def decode(data: bytes) -> bytes: # decoded
```
###trezor.crypto.secp256k1
``` python
def to_public(secret_key: bytes32) -> bytes33: # public_key
def sign(message: bytes, secret_key: bytes32, public_key: bytes33 = None) -> bytes65: # signature
def verify(message: bytes, public_key: bytes33, signature: bytes65) -> bool: # valid
```
##trezor.hw
###trezor.hw.button
TODO
###trezor.hw.display
TODO
##trezor.utils
###trezor.utils.qrenc
``` python
class QrLevel(Enum):
L = 0
M = 1
Q = 2
H = 3
def encode(source: bytes, level: QrLevel = QrLevel.H) -> list: # data
trezor.ui.touch.callback_end(self, callback) -> None
```

View File

@ -170,3 +170,7 @@ static void display_rawcmd(uint8_t reg, uint8_t *data, int datalen)
CMD(reg);
DATAS(data, datalen);
}
static void display_backlight(uint8_t val)
{
}

View File

@ -111,3 +111,7 @@ static void display_orientation(int degrees)
static void display_rawcmd(uint8_t reg, uint8_t *data, int datalen)
{
}
static void display_backlight(uint8_t val)
{
}

View File

@ -187,7 +187,7 @@ STATIC mp_obj_t mod_TrezorUi_Display_make_new(const mp_obj_type_t *type, size_t
return MP_OBJ_FROM_PTR(o);
}
// def Display.bar(self, x: int, y: int, w: int, h: int, color: int) -> None:
// def Display.bar(self, x: int, y: int, w: int, h: int, color: int) -> None
STATIC mp_obj_t mod_TrezorUi_Display_bar(size_t n_args, const mp_obj_t *args) {
mp_int_t x = mp_obj_get_int(args[1]);
mp_int_t y = mp_obj_get_int(args[2]);
@ -202,7 +202,7 @@ STATIC mp_obj_t mod_TrezorUi_Display_bar(size_t n_args, const mp_obj_t *args) {
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_bar_obj, 6, 6, mod_TrezorUi_Display_bar);
// def Display.blit(self, x: int, y: int, w: int, h: int, data: bytes) -> None:
// def Display.blit(self, x: int, y: int, w: int, h: int, data: bytes) -> None
STATIC mp_obj_t mod_TrezorUi_Display_blit(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]);
@ -218,7 +218,7 @@ STATIC mp_obj_t mod_TrezorUi_Display_blit(size_t n_args, const mp_obj_t *args) {
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_blit_obj, 6, 6, mod_TrezorUi_Display_blit);
// def Display.image(self, x: int, y: int, image: bytes) -> None:
// def Display.image(self, x: int, y: int, image: bytes) -> None
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]);
@ -238,7 +238,7 @@ STATIC mp_obj_t mod_TrezorUi_Display_image(size_t n_args, const mp_obj_t *args)
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_image_obj, 4, 4, mod_TrezorUi_Display_image);
// def Display.icon(self, x: int, y: int, icon: bytes, fgcolor: int, bgcolor: int) -> None:
// def Display.icon(self, x: int, y: int, icon: bytes, fgcolor: int, bgcolor: int) -> None
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]);
@ -260,7 +260,7 @@ STATIC mp_obj_t mod_TrezorUi_Display_icon(size_t n_args, const mp_obj_t *args) {
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_icon_obj, 6, 6, mod_TrezorUi_Display_icon);
// def Display.text(self, x: int, y: int, text: bytes, font: int, fgcolor: int, bgcolor: int) -> None:
// def Display.text(self, x: int, y: int, text: bytes, font: int, fgcolor: int, bgcolor: int) -> None
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]);
@ -274,7 +274,7 @@ STATIC mp_obj_t mod_TrezorUi_Display_text(size_t n_args, const mp_obj_t *args) {
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_text_obj, 7, 7, mod_TrezorUi_Display_text);
// def Display.text(self, degrees: int) -> None:
// def Display.orientation(self, degrees: int) -> None
STATIC mp_obj_t mod_TrezorUi_Display_orientation(mp_obj_t self, mp_obj_t degrees) {
mp_int_t deg = mp_obj_get_int(degrees);
if (deg != 0 && deg != 90 && deg != 180 && deg != 270) {
@ -285,7 +285,7 @@ STATIC mp_obj_t mod_TrezorUi_Display_orientation(mp_obj_t self, mp_obj_t degrees
}
MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUi_Display_orientation_obj, mod_TrezorUi_Display_orientation);
// def Display.rawcmd(self, reg: int, data: bytes) -> None:
// def Display.rawcmd(self, reg: int, data: bytes) -> None
STATIC mp_obj_t mod_TrezorUi_Display_rawcmd(mp_obj_t self, mp_obj_t reg, mp_obj_t data) {
mp_int_t r = mp_obj_get_int(reg);
mp_buffer_info_t bufinfo;
@ -295,6 +295,13 @@ STATIC mp_obj_t mod_TrezorUi_Display_rawcmd(mp_obj_t self, mp_obj_t reg, mp_obj_
}
MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorUi_Display_rawcmd_obj, mod_TrezorUi_Display_rawcmd);
// def Display.backlight(self, val: int) -> None
STATIC mp_obj_t mod_TrezorUi_Display_backlight(mp_obj_t self, mp_obj_t reg) {
display_backlight(mp_obj_get_int(reg));
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUi_Display_backlight_obj, mod_TrezorUi_Display_backlight);
// Display stuff
STATIC const mp_rom_map_elem_t mod_TrezorUi_Display_locals_dict_table[] = {
@ -305,6 +312,7 @@ STATIC const mp_rom_map_elem_t mod_TrezorUi_Display_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&mod_TrezorUi_Display_text_obj) },
{ MP_ROM_QSTR(MP_QSTR_orientation), MP_ROM_PTR(&mod_TrezorUi_Display_orientation_obj) },
{ MP_ROM_QSTR(MP_QSTR_rawcmd), MP_ROM_PTR(&mod_TrezorUi_Display_rawcmd_obj) },
{ MP_ROM_QSTR(MP_QSTR_backlight), MP_ROM_PTR(&mod_TrezorUi_Display_backlight_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorUi_Display_locals_dict, mod_TrezorUi_Display_locals_dict_table);
@ -327,21 +335,21 @@ STATIC mp_obj_t mod_TrezorUi_Touch_make_new(const mp_obj_type_t *type, size_t n_
return MP_OBJ_FROM_PTR(o);
}
// def Touch.callback_start(self, callback) -> None:
// def Touch.callback_start(self, callback) -> None
STATIC mp_obj_t mod_TrezorUi_Touch_callback_start(mp_obj_t self, mp_obj_t callback) {
touch_start_callback = callback;
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUi_Touch_callback_start_obj, mod_TrezorUi_Touch_callback_start);
// def Touch.callback_move(self, callback) -> None:
// def Touch.callback_move(self, callback) -> None
STATIC mp_obj_t mod_TrezorUi_Touch_callback_move(mp_obj_t self, mp_obj_t callback) {
touch_move_callback = callback;
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUi_Touch_callback_move_obj, mod_TrezorUi_Touch_callback_move);
// def Touch.callback_end(self, callback) -> None:
// def Touch.callback_end(self, callback) -> None
STATIC mp_obj_t mod_TrezorUi_Touch_callback_end(mp_obj_t self, mp_obj_t callback) {
touch_end_callback = callback;
return mp_const_none;
@ -380,5 +388,4 @@ const mp_obj_module_t mp_module_TrezorUi = {
.globals = (mp_obj_dict_t*)&mp_module_TrezorUi_globals,
};
#endif // MICROPY_PY_TREZORUI