From faa807f995d46d5fb2429ec62757f6d0513972dc Mon Sep 17 00:00:00 2001 From: matejcik Date: Wed, 13 Oct 2021 16:06:08 +0200 Subject: [PATCH] feat(core): show progress for SLIP39 derivation fixes #1842 --- core/src/apps/common/mnemonic.py | 6 +++++- core/src/trezor/crypto/slip39.py | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/src/apps/common/mnemonic.py b/core/src/apps/common/mnemonic.py index dcd570b07b..3e2bd571ee 100644 --- a/core/src/apps/common/mnemonic.py +++ b/core/src/apps/common/mnemonic.py @@ -47,7 +47,11 @@ def get_seed(passphrase: str = "", progress_bar: bool = True) -> bytes: # Identifier or exponent expected but not found raise RuntimeError seed = slip39.decrypt( - mnemonic_secret, passphrase.encode(), iteration_exponent, identifier + mnemonic_secret, + passphrase.encode(), + iteration_exponent, + identifier, + render_func, ) return seed diff --git a/core/src/trezor/crypto/slip39.py b/core/src/trezor/crypto/slip39.py index 5624979bcf..5032f3af25 100644 --- a/core/src/trezor/crypto/slip39.py +++ b/core/src/trezor/crypto/slip39.py @@ -37,7 +37,7 @@ from trezor.crypto import hmac, pbkdf2, random from trezor.errors import MnemonicError if False: - from typing import Iterable, Tuple + from typing import Callable, Iterable, Tuple Indices = Tuple[int, ...] MnemonicGroups = dict[int, tuple[int, set[tuple[int, bytes]]]] @@ -162,6 +162,7 @@ def decrypt( passphrase: bytes, iteration_exponent: int, identifier: int, + progress_callback: Callable[[int, int], None] | None = None, ) -> bytes: """ Converts the Encrypted Master Secret to a Master Secret by applying the passphrase. @@ -177,6 +178,8 @@ def decrypt( r, _xor(l, _round_function(i, passphrase, iteration_exponent, salt, r)), ) + if progress_callback: + progress_callback(_ROUND_COUNT - i, _ROUND_COUNT) return r + l