From 446ea33dc1b0ee359ae24a19439cb2047ae5e622 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 7 Oct 2016 13:27:43 +0200 Subject: [PATCH] minor changes in modtrezorcrypto docu --- .../modtrezorcrypto/modtrezorcrypto-bip32.h | 2 +- .../modtrezorcrypto/modtrezorcrypto-pbkdf2.h | 12 +++- mocks/trezor/crypto.py | 4 +- mocks/trezor/crypto/.mock-generated | 0 mocks/trezor/crypto/HDNode.py | 60 +++++++++++++++++++ mocks/trezor/crypto/__init__.py | 0 mocks/trezor/crypto/bip32.py | 6 ++ mocks/trezor/crypto/pbkdf2/Pbkdf2.py | 8 ++- mocks/trezor/ui/display.py | 18 +++++- 9 files changed, 100 insertions(+), 10 deletions(-) create mode 100644 mocks/trezor/crypto/.mock-generated create mode 100644 mocks/trezor/crypto/HDNode.py create mode 100644 mocks/trezor/crypto/__init__.py create mode 100644 mocks/trezor/crypto/bip32.py diff --git a/extmod/modtrezorcrypto/modtrezorcrypto-bip32.h b/extmod/modtrezorcrypto/modtrezorcrypto-bip32.h index c2fb406e79..a45def24f9 100644 --- a/extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +++ b/extmod/modtrezorcrypto/modtrezorcrypto-bip32.h @@ -195,7 +195,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip32_make_new(const mp_obj_type_t *type, size_ return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.Bip32.from_seed(seed: bytes, curve_name: str) -> HDNode: +/// def trezor.crypto.bip32.from_seed(seed: bytes, curve_name: str) -> HDNode: /// ''' /// Construct a BIP0032 HD node from a BIP0039 seed value. /// ''' diff --git a/extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h b/extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h index bf92e0590d..d9525b7368 100644 --- a/extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h +++ b/extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h @@ -21,7 +21,9 @@ typedef struct _mp_obj_Pbkdf2_t { STATIC mp_obj_t mod_TrezorCrypto_Pbkdf2_update(mp_obj_t self, mp_obj_t data); /// def trezor.crypto.pbkdf2(prf: str, password: bytes, salt: bytes, iterations: int=None) -> Pbkdf2: -/// pass +/// ''' +/// Create a PBKDF2 context +/// ''' STATIC mp_obj_t mod_TrezorCrypto_Pbkdf2_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 3, 4, false); mp_obj_Pbkdf2_t *o = m_new_obj(mp_obj_Pbkdf2_t); @@ -61,7 +63,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Pbkdf2_make_new(const mp_obj_type_t *type, size } /// def trezor.crypto.pbkdf2.Pbkdf2.update(self, iterations: int) -> None: -/// pass +/// ''' +/// Update a PBKDF2 context +/// ''' STATIC mp_obj_t mod_TrezorCrypto_Pbkdf2_update(mp_obj_t self, mp_obj_t iterations) { mp_obj_Pbkdf2_t *o = MP_OBJ_TO_PTR(self); uint32_t iter = mp_obj_get_int(iterations); @@ -76,7 +80,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Pbkdf2_update(mp_obj_t self, mp_obj_t iteration STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Pbkdf2_update_obj, mod_TrezorCrypto_Pbkdf2_update); /// def trezor.crypto.pbkdf2.Pbkdf2.key(self) -> bytes: -/// pass +/// ''' +/// Retreive derived key +/// ''' STATIC mp_obj_t mod_TrezorCrypto_Pbkdf2_key(mp_obj_t self) { mp_obj_Pbkdf2_t *o = MP_OBJ_TO_PTR(self); vstr_t vstr; diff --git a/mocks/trezor/crypto.py b/mocks/trezor/crypto.py index 1e64f9ca17..5b2854be8f 100644 --- a/mocks/trezor/crypto.py +++ b/mocks/trezor/crypto.py @@ -1,4 +1,6 @@ # ../extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h def pbkdf2(prf: str, password: bytes, salt: bytes, iterations: int=None) -> Pbkdf2: - pass + ''' + Create a PBKDF2 context + ''' diff --git a/mocks/trezor/crypto/.mock-generated b/mocks/trezor/crypto/.mock-generated new file mode 100644 index 0000000000..e69de29bb2 diff --git a/mocks/trezor/crypto/HDNode.py b/mocks/trezor/crypto/HDNode.py new file mode 100644 index 0000000000..cbd15a2732 --- /dev/null +++ b/mocks/trezor/crypto/HDNode.py @@ -0,0 +1,60 @@ + +# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +def derive(index: int) -> None: + ''' + Derive a BIP0032 child node in place. + ''' + +# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +def derive_path(path: list) -> None: + ''' + Go through a list of indexes and iteratively derive a child node in place. + ''' + +# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +def serialize_public(version: int) -> str: + ''' + Serialize the public info from HD node to base58 string. + ''' + +# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +def serialize_private(version: int) -> str: + ''' + Serialize the private info HD node to base58 string. + ''' + +# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +def depth() -> int: + ''' + Returns a depth of the HD node. + ''' + +# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +def fingerprint() -> int: + ''' + Returns a fingerprint of the HD node (hash of the parent public key). + ''' + +# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +def child_num() -> int: + ''' + Returns a child index of the HD node. + ''' + +# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +def chain_code() -> bytes: + ''' + Returns a chain code of the HD node. + ''' + +# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +def public_key() -> bytes: + ''' + Returns a public key of the HD node. + ''' + +# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +def private_key() -> bytes: + ''' + Returns a private key of the HD node. + ''' diff --git a/mocks/trezor/crypto/__init__.py b/mocks/trezor/crypto/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/mocks/trezor/crypto/bip32.py b/mocks/trezor/crypto/bip32.py new file mode 100644 index 0000000000..e0b774ff7c --- /dev/null +++ b/mocks/trezor/crypto/bip32.py @@ -0,0 +1,6 @@ + +# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +def from_seed(seed: bytes, curve_name: str) -> HDNode: + ''' + Construct a BIP0032 HD node from a BIP0039 seed value. + ''' diff --git a/mocks/trezor/crypto/pbkdf2/Pbkdf2.py b/mocks/trezor/crypto/pbkdf2/Pbkdf2.py index bfa9dec962..c110ec8f25 100644 --- a/mocks/trezor/crypto/pbkdf2/Pbkdf2.py +++ b/mocks/trezor/crypto/pbkdf2/Pbkdf2.py @@ -1,8 +1,12 @@ # ../extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h def update(self, iterations: int) -> None: - pass + ''' + Update a PBKDF2 context + ''' # ../extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h def key(self) -> bytes: - pass + ''' + Retreive derived key + ''' diff --git a/mocks/trezor/ui/display.py b/mocks/trezor/ui/display.py index 63540dde43..5e514182c1 100644 --- a/mocks/trezor/ui/display.py +++ b/mocks/trezor/ui/display.py @@ -12,10 +12,16 @@ def refresh() -> None ''' # ../extmod/modtrezorui/modtrezorui-display.h -def bar(x: int, y: int, w: int, h: int, fgcolor: int, bgcolor: int=None, radius: int=None) -> None: +def bar(x: int, y: int, w: int, h: int, color: int) -> None: ''' - Renders a bar at position (x,y = upper left corner) with width w and height h of color fgcolor. - When a bgcolor is set, the bar is drawn with rounded corners and bgcolor is used for background. + Renders a bar at position (x,y = upper left corner) with width w and height h of color color. + ''' + +# ../extmod/modtrezorui/modtrezorui-display.h +def bar_radius(x: int, y: int, w: int, h: int, fgcolor: int, bgcolor: int=None, radius: int=None) -> None: + ''' + Renders a rounded bar at position (x,y = upper left corner) with width w and height h of color fgcolor. + Background is set to bgcolor and corners are drawn with radius radius. ''' # ../extmod/modtrezorui/modtrezorui-display.h @@ -102,3 +108,9 @@ def raw(reg: int, data: bytes) -> None: ''' Performs a raw command on the display. Read the datasheet to learn more. ''' + +# ../extmod/modtrezorui/modtrezorui-display.h +def save(filename: string) -> None: + ''' + Saves current display contents to file filename. + '''