1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 23:48:12 +00:00

core/slip39: use condensed wordlist

(cherry picked from commit a3717c7b6c)
This commit is contained in:
Pavol Rusnak 2019-05-27 19:39:41 +02:00
parent fae234e2d6
commit fc41a7a232
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 6 additions and 1030 deletions

View File

@ -85,15 +85,16 @@ DIGEST_INDEX = 254
def word_index(word): def word_index(word):
word = word + " " * (8 - len(word))
lo = 0 lo = 0
hi = len(wordlist) hi = RADIX
while hi - lo > 1: while hi - lo > 1:
mid = (hi + lo) // 2 mid = (hi + lo) // 2
if wordlist[mid] > word: if wordlist[mid * 8 : mid * 8 + 8] > word:
hi = mid hi = mid
else: else:
lo = mid lo = mid
if not wordlist[lo].startswith(word): if wordlist[lo * 8 : lo * 8 + 8] != word:
raise MnemonicError('Invalid mnemonic word "{}".'.format(word)) raise MnemonicError('Invalid mnemonic word "{}".'.format(word))
return lo return lo
@ -151,7 +152,7 @@ def _int_to_indices(value, length, bits):
def mnemonic_from_indices(indices): def mnemonic_from_indices(indices):
return " ".join(wordlist[i] for i in indices) return " ".join(wordlist[i * 8 : i * 8 + 8].strip() for i in indices)
def mnemonic_to_indices(mnemonic): def mnemonic_to_indices(mnemonic):

File diff suppressed because one or more lines are too long