mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-02 02:41:28 +00:00
core: modify function signatures to match python-shamir-mnemonic
This commit is contained in:
parent
f491239c26
commit
f90ba10af3
@ -48,7 +48,7 @@ def get_seed(passphrase: str = "", progress_bar: bool = True) -> bytes:
|
||||
# Identifier or exponent expected but not found
|
||||
raise RuntimeError
|
||||
seed = slip39.decrypt(
|
||||
identifier, iteration_exponent, mnemonic_secret, passphrase.encode()
|
||||
mnemonic_secret, passphrase.encode(), iteration_exponent, identifier
|
||||
)
|
||||
|
||||
return seed
|
||||
|
@ -24,15 +24,17 @@ async def load_device(ctx, msg):
|
||||
secret = msg.mnemonics[0].encode()
|
||||
backup_type = BackupType.Bip39
|
||||
else:
|
||||
identifier, iteration_exponent, secret, group_count = slip39.combine_mnemonics(
|
||||
msg.mnemonics
|
||||
)
|
||||
if group_count == 1:
|
||||
identifier, iteration_exponent, secret = slip39.recover_ems(msg.mnemonics)
|
||||
|
||||
# this must succeed if the recover_ems call succeeded
|
||||
share = slip39.decode_mnemonic(msg.mnemonics[0])
|
||||
if share.group_count == 1:
|
||||
backup_type = BackupType.Slip39_Basic
|
||||
elif group_count > 1:
|
||||
elif share.group_count > 1:
|
||||
backup_type = BackupType.Slip39_Advanced
|
||||
else:
|
||||
raise RuntimeError("Invalid group count")
|
||||
|
||||
storage.device.set_slip39_identifier(identifier)
|
||||
storage.device.set_slip39_iteration_exponent(iteration_exponent)
|
||||
|
||||
|
@ -46,9 +46,7 @@ def process_slip39(words: str) -> Tuple[Optional[bytes], slip39.Share]:
|
||||
# if share threshold and group threshold are 1
|
||||
# we can calculate the secret right away
|
||||
if share.threshold == 1 and share.group_threshold == 1:
|
||||
identifier, iteration_exponent, secret, _ = slip39.combine_mnemonics(
|
||||
[words]
|
||||
)
|
||||
identifier, iteration_exponent, secret = slip39.recover_ems([words])
|
||||
return secret, share
|
||||
else:
|
||||
# we need more shares
|
||||
@ -89,7 +87,7 @@ def process_slip39(words: str) -> Tuple[Optional[bytes], slip39.Share]:
|
||||
# in case of slip39 basic we only need the first and only group
|
||||
mnemonics = storage.recovery_shares.fetch_group(0)
|
||||
|
||||
identifier, iteration_exponent, secret, _ = slip39.combine_mnemonics(mnemonics)
|
||||
identifier, iteration_exponent, secret = slip39.recover_ems(mnemonics)
|
||||
return secret, share
|
||||
|
||||
|
||||
|
@ -101,12 +101,12 @@ async def backup_slip39_basic(
|
||||
threshold = await layout.slip39_prompt_threshold(ctx, shares_count)
|
||||
|
||||
# generate the mnemonics
|
||||
mnemonics = slip39.generate_mnemonics_from_data(
|
||||
encrypted_master_secret,
|
||||
storage.device.get_slip39_identifier(),
|
||||
mnemonics = slip39.split_ems(
|
||||
1, # Single Group threshold
|
||||
[(threshold, shares_count)], # Single Group threshold/count
|
||||
storage.device.get_slip39_identifier(),
|
||||
storage.device.get_slip39_iteration_exponent(),
|
||||
encrypted_master_secret,
|
||||
)[0]
|
||||
|
||||
# show and confirm individual shares
|
||||
@ -136,12 +136,12 @@ async def backup_slip39_advanced(
|
||||
groups.append((share_threshold, share_count))
|
||||
|
||||
# generate the mnemonics
|
||||
mnemonics = slip39.generate_mnemonics_from_data(
|
||||
encrypted_master_secret=encrypted_master_secret,
|
||||
identifier=storage.device.get_slip39_identifier(),
|
||||
mnemonics = slip39.split_ems(
|
||||
group_threshold=group_threshold,
|
||||
groups=groups,
|
||||
identifier=storage.device.get_slip39_identifier(),
|
||||
iteration_exponent=storage.device.get_slip39_iteration_exponent(),
|
||||
encrypted_master_secret=encrypted_master_secret,
|
||||
)
|
||||
|
||||
# show and confirm individual shares
|
||||
|
@ -165,10 +165,10 @@ class Share:
|
||||
|
||||
|
||||
def decrypt(
|
||||
identifier: int,
|
||||
iteration_exponent: int,
|
||||
encrypted_master_secret: bytes,
|
||||
passphrase: bytes,
|
||||
iteration_exponent: int,
|
||||
identifier: int,
|
||||
) -> bytes:
|
||||
"""
|
||||
Converts the Encrypted Master Secret to a Master Secret by applying the passphrase.
|
||||
@ -194,12 +194,12 @@ def generate_random_identifier() -> int:
|
||||
return identifier & ((1 << _ID_LENGTH_BITS) - 1)
|
||||
|
||||
|
||||
def generate_mnemonics_from_data(
|
||||
encrypted_master_secret: bytes, # The encrypted master secret to split.
|
||||
identifier: int,
|
||||
def split_ems(
|
||||
group_threshold: int, # The number of groups required to reconstruct the master secret.
|
||||
groups: List[Tuple[int, int]], # A list of (member_threshold, member_count).
|
||||
identifier: int,
|
||||
iteration_exponent: int,
|
||||
encrypted_master_secret: bytes, # The encrypted master secret to split.
|
||||
) -> List[List[str]]:
|
||||
"""
|
||||
Splits an encrypted master secret into mnemonic shares using Shamir's secret sharing scheme.
|
||||
@ -253,7 +253,7 @@ def generate_mnemonics_from_data(
|
||||
return mnemonics
|
||||
|
||||
|
||||
def combine_mnemonics(mnemonics: List[str]) -> Tuple[int, int, bytes, int]:
|
||||
def recover_ems(mnemonics: List[str]) -> Tuple[int, int, bytes]:
|
||||
"""
|
||||
Combines mnemonic shares to obtain the encrypted master secret which was previously
|
||||
split using Shamir's secret sharing scheme.
|
||||
@ -292,7 +292,7 @@ def combine_mnemonics(mnemonics: List[str]) -> Tuple[int, int, bytes, int]:
|
||||
]
|
||||
|
||||
encrypted_master_secret = _recover_secret(group_threshold, group_shares)
|
||||
return identifier, iteration_exponent, encrypted_master_secret, group_count
|
||||
return identifier, iteration_exponent, encrypted_master_secret
|
||||
|
||||
|
||||
def decode_mnemonic(mnemonic: str) -> Share:
|
||||
|
Loading…
Reference in New Issue
Block a user