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

core/slip39: use condensed wordlist

This commit is contained in:
Pavol Rusnak 2019-05-27 19:39:41 +02:00
parent 11aac67c82
commit a3717c7b6c
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):
word = word + " " * (8 - len(word))
lo = 0
hi = len(wordlist)
hi = RADIX
while hi - lo > 1:
mid = (hi + lo) // 2
if wordlist[mid] > word:
if wordlist[mid * 8 : mid * 8 + 8] > word:
hi = mid
else:
lo = mid
if not wordlist[lo].startswith(word):
if wordlist[lo * 8 : lo * 8 + 8] != word:
raise MnemonicError('Invalid mnemonic word "{}".'.format(word))
return lo
@ -151,7 +152,7 @@ def _int_to_indices(value, length, bits):
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):

File diff suppressed because one or more lines are too long