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

core: cache seed without passphrase (#478)

This commit is contained in:
Andrew Kozlik 2019-09-02 12:09:03 +02:00 committed by Pavol Rusnak
parent 41b76f4f31
commit c1f0c642df
2 changed files with 19 additions and 2 deletions

View File

@ -6,6 +6,7 @@ if False:
from typing import Optional from typing import Optional
_cached_seed = None # type: Optional[bytes] _cached_seed = None # type: Optional[bytes]
_cached_seed_without_passphrase = None # type: Optional[bytes]
_cached_passphrase = None # type: Optional[str] _cached_passphrase = None # type: Optional[str]
_cached_passphrase_fprint = b"\x00\x00\x00\x00" # type: bytes _cached_passphrase_fprint = b"\x00\x00\x00\x00" # type: bytes
@ -36,6 +37,10 @@ def get_seed() -> Optional[bytes]:
return _cached_seed return _cached_seed
def get_seed_without_passphrase() -> Optional[bytes]:
return _cached_seed_without_passphrase
def get_passphrase() -> Optional[str]: def get_passphrase() -> Optional[str]:
return _cached_passphrase return _cached_passphrase
@ -53,6 +58,11 @@ def set_seed(seed: Optional[bytes]) -> None:
_cached_seed = seed _cached_seed = seed
def set_seed_without_passphrase(seed: Optional[bytes]) -> None:
global _cached_seed_without_passphrase
_cached_seed_without_passphrase = seed
def set_passphrase(passphrase: Optional[str]) -> None: def set_passphrase(passphrase: Optional[str]) -> None:
global _cached_passphrase, _cached_passphrase_fprint global _cached_passphrase, _cached_passphrase_fprint
_cached_passphrase = passphrase _cached_passphrase = passphrase
@ -61,5 +71,6 @@ def set_passphrase(passphrase: Optional[str]) -> None:
def clear(keep_passphrase: bool = False) -> None: def clear(keep_passphrase: bool = False) -> None:
set_seed(None) set_seed(None)
set_seed_without_passphrase(None)
if not keep_passphrase: if not keep_passphrase:
set_passphrase(None) set_passphrase(None)

View File

@ -126,7 +126,10 @@ def derive_node_without_passphrase(
) -> bip32.HDNode: ) -> bip32.HDNode:
if not storage.is_initialized(): if not storage.is_initialized():
raise Exception("Device is not initialized") raise Exception("Device is not initialized")
seed = mnemonic.get_seed(progress_bar=False) seed = cache.get_seed_without_passphrase()
if seed is None:
seed = mnemonic.get_seed(progress_bar=False)
cache.set_seed_without_passphrase(seed)
node = bip32.from_seed(seed, curve_name) node = bip32.from_seed(seed, curve_name)
node.derive_path(path) node.derive_path(path)
return node return node
@ -135,7 +138,10 @@ def derive_node_without_passphrase(
def derive_slip21_node_without_passphrase(path: list) -> Slip21Node: def derive_slip21_node_without_passphrase(path: list) -> Slip21Node:
if not storage.is_initialized(): if not storage.is_initialized():
raise Exception("Device is not initialized") raise Exception("Device is not initialized")
seed = mnemonic.get_seed(progress_bar=False) seed = cache.get_seed_without_passphrase()
if seed is None:
seed = mnemonic.get_seed(progress_bar=False)
cache.set_seed_without_passphrase(seed)
node = Slip21Node(seed) node = Slip21Node(seed)
node.derive_path(path) node.derive_path(path)
return node return node