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

add trezor.crypto.bip39

This commit is contained in:
Pavol Rusnak 2016-05-13 20:33:14 +02:00
parent 9222b77a03
commit 910926e25c
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
10 changed files with 260 additions and 26 deletions

View File

@ -31,6 +31,27 @@ def trezor.crypto.base58.decode_check(string: str) -> bytes
Convert base58 encoded string to bytes and verify checksum.
###trezor.crypto.bip39
``` python
def trezor.crypto.bip39.generate(strength: int) -> tuple
```
Generate a mnemonic of given strength (128, 160, 192, 224 and 256 bits)
``` python
def trezor.crypto.bip39.from_data(data: bytes) -> tuple
```
Generate a mnemonic from given data (of 16, 20, 24, 28 and 32 bytes)
``` python
def trezor.crypto.bip39.check(mnemonic: str) -> bool
```
Check whether given mnemonic is valid
###trezor.crypto.curve
####trezor.crypto.curve.ed25519

View File

@ -8,6 +8,10 @@ Syntax used below is a valid Python function declaration with type hints defined
@src/trezor/crypto/base58.py
###trezor.crypto.bip39
@extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
###trezor.crypto.curve
####trezor.crypto.curve.ed25519

View File

@ -0,0 +1,94 @@
/*
* Copyright (c) Pavol Rusnak, SatoshiLabs
*
* Licensed under Microsoft Reference Source License (Ms-RSL)
* see LICENSE.md file for details
*/
#include "py/objstr.h"
#include "trezor-crypto/bip39.h"
typedef struct _mp_obj_Bip39_t {
mp_obj_base_t base;
} mp_obj_Bip39_t;
STATIC mp_obj_t mod_TrezorCrypto_Bip39_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
mp_obj_Bip39_t *o = m_new_obj(mp_obj_Bip39_t);
o->base.type = type;
return MP_OBJ_FROM_PTR(o);
}
/// def trezor.crypto.bip39.generate(strength: int) -> tuple
///
/// Generate a mnemonic of given strength (128, 160, 192, 224 and 256 bits)
///
STATIC mp_obj_t mod_TrezorCrypto_Bip39_generate(mp_obj_t self, mp_obj_t strength) {
int bits = mp_obj_get_int(strength);
if (bits % 32 || bits < 128 || bits > 256) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid bit strength (only 128, 160, 192, 224 and 256 values are allowed)"));
}
int words = bits / 32 * 3;
const char * const *wordlist = mnemonic_wordlist();
const uint16_t *mnemo = mnemonic_generate_indexes(bits);
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(words, NULL));
for (int i = 0; i < words; i++) {
vstr_t vstr;
vstr_init_len(&vstr, strlen(wordlist[mnemo[i]]));
strcpy(vstr.buf, wordlist[mnemo[i]]);
tuple->items[i] = mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
}
return MP_OBJ_FROM_PTR(tuple);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Bip39_generate_obj, mod_TrezorCrypto_Bip39_generate);
/// def trezor.crypto.bip39.from_data(data: bytes) -> tuple
///
/// Generate a mnemonic from given data (of 16, 20, 24, 28 and 32 bytes)
///
STATIC mp_obj_t mod_TrezorCrypto_Bip39_from_data(mp_obj_t self, mp_obj_t data) {
mp_buffer_info_t bin;
mp_get_buffer_raise(data, &bin, MP_BUFFER_READ);
if (bin.len % 4 || bin.len < 16 || bin.len > 32) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid data length (only 16, 20, 24, 28 and 32 bytes are allowed)"));
}
int words = bin.len / 4 * 3;
const char * const *wordlist = mnemonic_wordlist();
const uint16_t *mnemo = mnemonic_from_data_indexes(bin.buf, bin.len);
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(words, NULL));
for (int i = 0; i < words; i++) {
vstr_t vstr;
vstr_init_len(&vstr, strlen(wordlist[mnemo[i]]));
strcpy(vstr.buf, wordlist[mnemo[i]]);
tuple->items[i] = mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
}
return MP_OBJ_FROM_PTR(tuple);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Bip39_from_data_obj, mod_TrezorCrypto_Bip39_from_data);
/// def trezor.crypto.bip39.check(mnemonic: str) -> bool
///
/// Check whether given mnemonic is valid
///
STATIC mp_obj_t mod_TrezorCrypto_Bip39_check(mp_obj_t self, mp_obj_t mnemonic) {
mp_buffer_info_t text;
mp_get_buffer_raise(mnemonic, &text, MP_BUFFER_READ);
return mnemonic_check(text.buf) ? mp_const_true : mp_const_false;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Bip39_check_obj, mod_TrezorCrypto_Bip39_check);
STATIC const mp_rom_map_elem_t mod_TrezorCrypto_Bip39_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_generate), MP_ROM_PTR(&mod_TrezorCrypto_Bip39_generate_obj) },
{ MP_ROM_QSTR(MP_QSTR_from_data), MP_ROM_PTR(&mod_TrezorCrypto_Bip39_from_data_obj) },
{ MP_ROM_QSTR(MP_QSTR_check), MP_ROM_PTR(&mod_TrezorCrypto_Bip39_check_obj) },
// { MP_ROM_QSTR(MP_QSTR_seed), MP_ROM_PTR(&mod_TrezorCrypto_Bip39_seed_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorCrypto_Bip39_locals_dict, mod_TrezorCrypto_Bip39_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorCrypto_Bip39_type = {
{ &mp_type_type },
.name = MP_QSTR_Bip39,
.make_new = mod_TrezorCrypto_Bip39_make_new,
.locals_dict = (void*)&mod_TrezorCrypto_Bip39_locals_dict,
};

View File

@ -15,6 +15,7 @@
#if MICROPY_PY_TREZORCRYPTO
#include "modtrezorcrypto-bip39.h"
#include "modtrezorcrypto-ed25519.h"
#include "modtrezorcrypto-pbkdf2.h"
#include "modtrezorcrypto-ripemd160.h"
@ -27,6 +28,7 @@
STATIC const mp_rom_map_elem_t mp_module_TrezorCrypto_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_TrezorCrypto) },
{ MP_ROM_QSTR(MP_QSTR_Bip39), MP_ROM_PTR(&mod_TrezorCrypto_Bip39_type) },
{ MP_ROM_QSTR(MP_QSTR_Ed25519), MP_ROM_PTR(&mod_TrezorCrypto_Ed25519_type) },
{ MP_ROM_QSTR(MP_QSTR_Nist256p1), MP_ROM_PTR(&mod_TrezorCrypto_Nist256p1_type) },
{ MP_ROM_QSTR(MP_QSTR_Pbkdf2), MP_ROM_PTR(&mod_TrezorCrypto_Pbkdf2_type) },

View File

@ -37,19 +37,3 @@ def aes_ctr_decrypt(ctx: AES_CTX, data: bytes) -> bytes: # decrypted
###trezor.crypto.hd
TODO
###trezor.crypto.mnemonic
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.reedsolomon
def encode(data: bytes) -> bytes: # encoded
def decode(data: bytes) -> bytes: # decoded

View File

@ -0,0 +1,126 @@
import sys
sys.path.append('..')
sys.path.append('../lib')
import unittest
from ubinascii import unhexlify
from trezor.crypto import bip39
class TestCryptoBip39(unittest.TestCase):
def test_mnemonic(self):
v = [
('00000000000000000000000000000000', 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about', 'c55257c360c07c72029aebc1b53c05ed0362ada38ead3e3e9efa3708e53495531f09a6987599d18264c1e1c92f2cf141630c7a3c4ab7c81b2f001698e7463b04'),
('7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f', 'legal winner thank year wave sausage worth useful legal winner thank yellow', '2e8905819b8723fe2c1d161860e5ee1830318dbf49a83bd451cfb8440c28bd6fa457fe1296106559a3c80937a1c1069be3a3a5bd381ee6260e8d9739fce1f607'),
('80808080808080808080808080808080', 'letter advice cage absurd amount doctor acoustic avoid letter advice cage above', 'd71de856f81a8acc65e6fc851a38d4d7ec216fd0796d0a6827a3ad6ed5511a30fa280f12eb2e47ed2ac03b5c462a0358d18d69fe4f985ec81778c1b370b652a8'),
('ffffffffffffffffffffffffffffffff', 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong', 'ac27495480225222079d7be181583751e86f571027b0497b5b5d11218e0a8a13332572917f0f8e5a589620c6f15b11c61dee327651a14c34e18231052e48c069'),
('000000000000000000000000000000000000000000000000', 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon agent', '035895f2f481b1b0f01fcf8c289c794660b289981a78f8106447707fdd9666ca06da5a9a565181599b79f53b844d8a71dd9f439c52a3d7b3e8a79c906ac845fa'),
('7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f', 'legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal will', 'f2b94508732bcbacbcc020faefecfc89feafa6649a5491b8c952cede496c214a0c7b3c392d168748f2d4a612bada0753b52a1c7ac53c1e93abd5c6320b9e95dd'),
('808080808080808080808080808080808080808080808080', 'letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter always', '107d7c02a5aa6f38c58083ff74f04c607c2d2c0ecc55501dadd72d025b751bc27fe913ffb796f841c49b1d33b610cf0e91d3aa239027f5e99fe4ce9e5088cd65'),
('ffffffffffffffffffffffffffffffffffffffffffffffff', 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo when', '0cd6e5d827bb62eb8fc1e262254223817fd068a74b5b449cc2f667c3f1f985a76379b43348d952e2265b4cd129090758b3e3c2c49103b5051aac2eaeb890a528'),
('0000000000000000000000000000000000000000000000000000000000000000', 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art', 'bda85446c68413707090a52022edd26a1c9462295029f2e60cd7c4f2bbd3097170af7a4d73245cafa9c3cca8d561a7c3de6f5d4a10be8ed2a5e608d68f92fcc8'),
('7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f', 'legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth title', 'bc09fca1804f7e69da93c2f2028eb238c227f2e9dda30cd63699232578480a4021b146ad717fbb7e451ce9eb835f43620bf5c514db0f8add49f5d121449d3e87'),
('8080808080808080808080808080808080808080808080808080808080808080', 'letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic bless', 'c0c519bd0e91a2ed54357d9d1ebef6f5af218a153624cf4f2da911a0ed8f7a09e2ef61af0aca007096df430022f7a2b6fb91661a9589097069720d015e4e982f'),
('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote', 'dd48c104698c30cfe2b6142103248622fb7bb0ff692eebb00089b32d22484e1613912f0a5b694407be899ffd31ed3992c456cdf60f5d4564b8ba3f05a69890ad'),
('77c2b00716cec7213839159e404db50d', 'jelly better achieve collect unaware mountain thought cargo oxygen act hood bridge', 'b5b6d0127db1a9d2226af0c3346031d77af31e918dba64287a1b44b8ebf63cdd52676f672a290aae502472cf2d602c051f3e6f18055e84e4c43897fc4e51a6ff'),
('b63a9c59a6e641f288ebc103017f1da9f8290b3da6bdef7b', 'renew stay biology evidence goat welcome casual join adapt armor shuffle fault little machine walk stumble urge swap', '9248d83e06f4cd98debf5b6f010542760df925ce46cf38a1bdb4e4de7d21f5c39366941c69e1bdbf2966e0f6e6dbece898a0e2f0a4c2b3e640953dfe8b7bbdc5'),
('3e141609b97933b66a060dcddc71fad1d91677db872031e85f4c015c5e7e8982', 'dignity pass list indicate nasty swamp pool script soccer toe leaf photo multiply desk host tomato cradle drill spread actor shine dismiss champion exotic', 'ff7f3184df8696d8bef94b6c03114dbee0ef89ff938712301d27ed8336ca89ef9635da20af07d4175f2bf5f3de130f39c9d9e8dd0472489c19b1a020a940da67'),
('0460ef47585604c5660618db2e6a7e7f', 'afford alter spike radar gate glance object seek swamp infant panel yellow', '65f93a9f36b6c85cbe634ffc1f99f2b82cbb10b31edc7f087b4f6cb9e976e9faf76ff41f8f27c99afdf38f7a303ba1136ee48a4c1e7fcd3dba7aa876113a36e4'),
('72f60ebac5dd8add8d2a25a797102c3ce21bc029c200076f', 'indicate race push merry suffer human cruise dwarf pole review arch keep canvas theme poem divorce alter left', '3bbf9daa0dfad8229786ace5ddb4e00fa98a044ae4c4975ffd5e094dba9e0bb289349dbe2091761f30f382d4e35c4a670ee8ab50758d2c55881be69e327117ba'),
('2c85efc7f24ee4573d2b81a6ec66cee209b2dcbd09d8eddc51e0215b0b68e416', 'clutch control vehicle tonight unusual clog visa ice plunge glimpse recipe series open hour vintage deposit universe tip job dress radar refuse motion taste', 'fe908f96f46668b2d5b37d82f558c77ed0d69dd0e7e043a5b0511c48c2f1064694a956f86360c93dd04052a8899497ce9e985ebe0c8c52b955e6ae86d4ff4449'),
('eaebabb2383351fd31d703840b32e9e2', 'turtle front uncle idea crush write shrug there lottery flower risk shell', 'bdfb76a0759f301b0b899a1e3985227e53b3f51e67e3f2a65363caedf3e32fde42a66c404f18d7b05818c95ef3ca1e5146646856c461c073169467511680876c'),
('7ac45cfe7722ee6c7ba84fbc2d5bd61b45cb2fe5eb65aa78', 'kiss carry display unusual confirm curtain upgrade antique rotate hello void custom frequent obey nut hole price segment', 'ed56ff6c833c07982eb7119a8f48fd363c4a9b1601cd2de736b01045c5eb8ab4f57b079403485d1c4924f0790dc10a971763337cb9f9c62226f64fff26397c79'),
('4fa1a8bc3e6d80ee1316050e862c1812031493212b7ec3f3bb1b08f168cabeef', 'exile ask congress lamp submit jacket era scheme attend cousin alcohol catch course end lucky hurt sentence oven short ball bird grab wing top', '095ee6f817b4c2cb30a5a797360a81a40ab0f9a4e25ecd672a3f58a0b5ba0687c096a6b14d2c0deb3bdefce4f61d01ae07417d502429352e27695163f7447a8c'),
('18ab19a9f54a9274f03e5209a2ac8a91', 'board flee heavy tunnel powder denial science ski answer betray cargo cat', '6eff1bb21562918509c73cb990260db07c0ce34ff0e3cc4a8cb3276129fbcb300bddfe005831350efd633909f476c45c88253276d9fd0df6ef48609e8bb7dca8'),
('18a2e1d81b8ecfb2a333adcb0c17a5b9eb76cc5d05db91a4', 'board blade invite damage undo sun mimic interest slam gaze truly inherit resist great inject rocket museum chief', 'f84521c777a13b61564234bf8f8b62b3afce27fc4062b51bb5e62bdfecb23864ee6ecf07c1d5a97c0834307c5c852d8ceb88e7c97923c0a3b496bedd4e5f88a9'),
('15da872c95a13dd738fbf50e427583ad61f18fd99f628c417a61cf8343c90419', 'beyond stage sleep clip because twist token leaf atom beauty genius food business side grid unable middle armed observe pair crouch tonight away coconut', 'b15509eaa2d09d3efd3e006ef42151b30367dc6e3aa5e44caba3fe4d3e352e65101fbdb86a96776b91946ff06f8eac594dc6ee1d3e82a42dfe1b40fef6bcc3fd'),
]
for d, m, s in v:
self.assertEqual(bip39.from_data(unhexlify(d)), tuple(m.split(' ')))
def test_check_ok(self):
v = [
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
'legal winner thank year wave sausage worth useful legal winner thank yellow',
'letter advice cage absurd amount doctor acoustic avoid letter advice cage above',
'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong',
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon agent',
'legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal will',
'letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter always',
'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo when',
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art',
'legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth title',
'letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic bless',
'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote',
'jelly better achieve collect unaware mountain thought cargo oxygen act hood bridge',
'renew stay biology evidence goat welcome casual join adapt armor shuffle fault little machine walk stumble urge swap',
'dignity pass list indicate nasty swamp pool script soccer toe leaf photo multiply desk host tomato cradle drill spread actor shine dismiss champion exotic',
'afford alter spike radar gate glance object seek swamp infant panel yellow',
'indicate race push merry suffer human cruise dwarf pole review arch keep canvas theme poem divorce alter left',
'clutch control vehicle tonight unusual clog visa ice plunge glimpse recipe series open hour vintage deposit universe tip job dress radar refuse motion taste',
'turtle front uncle idea crush write shrug there lottery flower risk shell',
'kiss carry display unusual confirm curtain upgrade antique rotate hello void custom frequent obey nut hole price segment',
'exile ask congress lamp submit jacket era scheme attend cousin alcohol catch course end lucky hurt sentence oven short ball bird grab wing top',
'board flee heavy tunnel powder denial science ski answer betray cargo cat',
'board blade invite damage undo sun mimic interest slam gaze truly inherit resist great inject rocket museum chief',
'beyond stage sleep clip because twist token leaf atom beauty genius food business side grid unable middle armed observe pair crouch tonight away coconut',
]
for m in v:
self.assertEqual(bip39.check(m), True)
def test_check_fail(self):
v = [
'above abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
'above winner thank year wave sausage worth useful legal winner thank yellow',
'above advice cage absurd amount doctor acoustic avoid letter advice cage above',
'above zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong',
'above abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon agent',
'above winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal will',
'above advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter always',
'above zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo when',
'above abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art',
'above winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth title',
'above advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic bless',
'above zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote',
'above better achieve collect unaware mountain thought cargo oxygen act hood bridge',
'above stay biology evidence goat welcome casual join adapt armor shuffle fault little machine walk stumble urge swap',
'above pass list indicate nasty swamp pool script soccer toe leaf photo multiply desk host tomato cradle drill spread actor shine dismiss champion exotic',
'above alter spike radar gate glance object seek swamp infant panel yellow',
'above race push merry suffer human cruise dwarf pole review arch keep canvas theme poem divorce alter left',
'above control vehicle tonight unusual clog visa ice plunge glimpse recipe series open hour vintage deposit universe tip job dress radar refuse motion taste',
'above front uncle idea crush write shrug there lottery flower risk shell',
'above carry display unusual confirm curtain upgrade antique rotate hello void custom frequent obey nut hole price segment',
'above ask congress lamp submit jacket era scheme attend cousin alcohol catch course end lucky hurt sentence oven short ball bird grab wing top',
'above flee heavy tunnel powder denial science ski answer betray cargo cat',
'above blade invite damage undo sun mimic interest slam gaze truly inherit resist great inject rocket museum chief',
'above stage sleep clip because twist token leaf atom beauty genius food business side grid unable middle armed observe pair crouch tonight away coconut',
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
'winner thank year wave sausage worth useful legal winner thank yellow',
'advice cage absurd amount doctor acoustic avoid letter advice cage above',
'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong',
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon agent',
'winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal will',
'advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter always',
'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo when',
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art',
'winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth title',
'advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic bless',
'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote',
'better achieve collect unaware mountain thought cargo oxygen act hood bridge',
'stay biology evidence goat welcome casual join adapt armor shuffle fault little machine walk stumble urge swap',
'pass list indicate nasty swamp pool script soccer toe leaf photo multiply desk host tomato cradle drill spread actor shine dismiss champion exotic',
'alter spike radar gate glance object seek swamp infant panel yellow',
'race push merry suffer human cruise dwarf pole review arch keep canvas theme poem divorce alter left',
'control vehicle tonight unusual clog visa ice plunge glimpse recipe series open hour vintage deposit universe tip job dress radar refuse motion taste',
'front uncle idea crush write shrug there lottery flower risk shell',
'carry display unusual confirm curtain upgrade antique rotate hello void custom frequent obey nut hole price segment',
'ask congress lamp submit jacket era scheme attend cousin alcohol catch course end lucky hurt sentence oven short ball bird grab wing top',
'flee heavy tunnel powder denial science ski answer betray cargo cat',
'blade invite damage undo sun mimic interest slam gaze truly inherit resist great inject rocket museum chief',
'stage sleep clip because twist token leaf atom beauty genius food business side grid unable middle armed observe pair crouch tonight away coconut',
]
for m in v:
self.assertEqual(bip39.check(m), False)
if __name__ == '__main__':
unittest.main()

View File

@ -10,14 +10,14 @@ class TestCryptoEd25519(unittest.TestCase):
# vectors from https://github.com/torproject/tor/blob/master/src/test/ed25519_vectors.in
vectors = [
("26c76712d89d906e6672dafa614c42e5cb1caac8c6568e4d2493087db51f0d36", "c2247870536a192d142d056abefca68d6193158e7c1a59c1654c954eccaff894", "d23188eac3773a316d46006fa59c095060be8b1a23582a0dd99002a82a0662bd246d8449e172e04c5f46ac0d1404cebe4aabd8a75a1457aa06cae41f3334f104"),
("fba7a5366b5cb98c2667a18783f5cf8f4f8d1a2ce939ad22a6e685edde85128d", "1519a3b15816a1aafab0b213892026ebf5c0dc232c58b21088d88cb90e9b940d", "3a785ac1201c97ee5f6f0d99323960d5f264c7825e61aa7cc81262f15bef75eb4fa5723add9b9d45b12311b6d403eb3ac79ff8e4e631fc3cd51e4ad2185b200b"),
("67e3aa7a14fac8445d15e45e38a523481a69ae35513c9e4143eb1c2196729a0e", "081faa81992e360ea22c06af1aba096e7a73f1c665bc8b3e4e531c46455fd1dd", "cf431fd0416bfbd20c9d95ef9b723e2acddffb33900edc72195dea95965d52d888d30b7b8a677c0bd8ae1417b1e1a0ec6700deadd5d8b54b6689275e04a04509"),
("d51385942033a76dc17f089a59e6a5a7fe80d9c526ae8ddd8c3a506b99d3d0a6", "73cfa1189a723aad7966137cbffa35140bb40d7e16eae4c40b79b5f0360dd65a", "2375380cd72d1a6c642aeddff862be8a5804b916acb72c02d9ed052c1561881aa658a5af856fcd6d43113e42f698cd6687c99efeef7f2ce045824440d26c5d00"),
("5c8eac469bb3f1b85bc7cd893f52dc42a9ab66f1b02b5ce6a68e9b175d3bb433", "66c1a77104d86461b6f98f73acf3cd229c80624495d2d74d6fda1e940080a96b", "2385a472f599ca965bbe4d610e391cdeabeba9c336694b0d6249e551458280be122c2441dd9746a81bbfb9cd619364bab0df37ff4ceb7aefd24469c39d3bc508"),
("eda433d483059b6d1ff8b7cfbd0fe406bfb23722c8f3c8252629284573b61b86", "d21c294db0e64cb2d8976625786ede1d9754186ae8197a64d72f68c792eecc19", "e500cd0b8cfff35442f88008d894f3a2fa26ef7d3a0ca5714ae0d3e2d40caae58ba7cdf69dd126994dad6be536fcda846d89dd8138d1683cc144c8853dce7607"),
("4377c40431c30883c5fbd9bc92ae48d1ed8a47b81d13806beac5351739b5533d", "c4d58b4cf85a348ff3d410dd936fa460c4f18da962c01b1963792b9dcc8a6ea6", "d187b9e334b0050154de10bf69b3e4208a584e1a65015ec28b14bcc252cf84b8baa9c94867daa60f2a82d09ba9652d41e8dde292b624afc8d2c26441b95e3c0e"),
("c6bbcce615839756aed2cc78b1de13884dd3618f48367a17597a16c1cd7a290b", "95126f14d86494020665face03f2d42ee2b312a85bc729903eb17522954a1c4a", "815213640a643d198bd056e02bba74e1c8d2d931643e84497adf3347eb485079c9afe0afce9284cdc084946b561abbb214f1304ca11228ff82702185cf28f60d"), ]
('26c76712d89d906e6672dafa614c42e5cb1caac8c6568e4d2493087db51f0d36', 'c2247870536a192d142d056abefca68d6193158e7c1a59c1654c954eccaff894', 'd23188eac3773a316d46006fa59c095060be8b1a23582a0dd99002a82a0662bd246d8449e172e04c5f46ac0d1404cebe4aabd8a75a1457aa06cae41f3334f104'),
('fba7a5366b5cb98c2667a18783f5cf8f4f8d1a2ce939ad22a6e685edde85128d', '1519a3b15816a1aafab0b213892026ebf5c0dc232c58b21088d88cb90e9b940d', '3a785ac1201c97ee5f6f0d99323960d5f264c7825e61aa7cc81262f15bef75eb4fa5723add9b9d45b12311b6d403eb3ac79ff8e4e631fc3cd51e4ad2185b200b'),
('67e3aa7a14fac8445d15e45e38a523481a69ae35513c9e4143eb1c2196729a0e', '081faa81992e360ea22c06af1aba096e7a73f1c665bc8b3e4e531c46455fd1dd', 'cf431fd0416bfbd20c9d95ef9b723e2acddffb33900edc72195dea95965d52d888d30b7b8a677c0bd8ae1417b1e1a0ec6700deadd5d8b54b6689275e04a04509'),
('d51385942033a76dc17f089a59e6a5a7fe80d9c526ae8ddd8c3a506b99d3d0a6', '73cfa1189a723aad7966137cbffa35140bb40d7e16eae4c40b79b5f0360dd65a', '2375380cd72d1a6c642aeddff862be8a5804b916acb72c02d9ed052c1561881aa658a5af856fcd6d43113e42f698cd6687c99efeef7f2ce045824440d26c5d00'),
('5c8eac469bb3f1b85bc7cd893f52dc42a9ab66f1b02b5ce6a68e9b175d3bb433', '66c1a77104d86461b6f98f73acf3cd229c80624495d2d74d6fda1e940080a96b', '2385a472f599ca965bbe4d610e391cdeabeba9c336694b0d6249e551458280be122c2441dd9746a81bbfb9cd619364bab0df37ff4ceb7aefd24469c39d3bc508'),
('eda433d483059b6d1ff8b7cfbd0fe406bfb23722c8f3c8252629284573b61b86', 'd21c294db0e64cb2d8976625786ede1d9754186ae8197a64d72f68c792eecc19', 'e500cd0b8cfff35442f88008d894f3a2fa26ef7d3a0ca5714ae0d3e2d40caae58ba7cdf69dd126994dad6be536fcda846d89dd8138d1683cc144c8853dce7607'),
('4377c40431c30883c5fbd9bc92ae48d1ed8a47b81d13806beac5351739b5533d', 'c4d58b4cf85a348ff3d410dd936fa460c4f18da962c01b1963792b9dcc8a6ea6', 'd187b9e334b0050154de10bf69b3e4208a584e1a65015ec28b14bcc252cf84b8baa9c94867daa60f2a82d09ba9652d41e8dde292b624afc8d2c26441b95e3c0e'),
('c6bbcce615839756aed2cc78b1de13884dd3618f48367a17597a16c1cd7a290b', '95126f14d86494020665face03f2d42ee2b312a85bc729903eb17522954a1c4a', '815213640a643d198bd056e02bba74e1c8d2d931643e84497adf3347eb485079c9afe0afce9284cdc084946b561abbb214f1304ca11228ff82702185cf28f60d'), ]
def test_publickey(self):
for sk, pk, _ in self.vectors:

View File

@ -1 +1,4 @@
from TrezorCrypto import Pbkdf2 as pbkdf2
from TrezorCrypto import Bip39
bip39 = Bip39()

2
vendor/micropython vendored

@ -1 +1 @@
Subproject commit fcbbda764a68dc2c7453bfce9dc793c636cf8cf6
Subproject commit a15a57d3740b7b63433247514eab2089f2a5d0ac

@ -1 +1 @@
Subproject commit 51c0bb09d8f1066555d28ae3824988b318d2f39e
Subproject commit aae96e8285146d284c1e472711bd9e05ffbf8964