mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-13 17:00:59 +00:00
fix(tests): update shamir_mnemonic usage
This commit is contained in:
parent
00c8080ad8
commit
a1cd0b0949
@ -1,4 +1,4 @@
|
|||||||
import shamir_mnemonic as shamir
|
from shamir_mnemonic import shamir
|
||||||
|
|
||||||
from trezorlib import messages
|
from trezorlib import messages
|
||||||
|
|
||||||
@ -72,7 +72,6 @@ def confirm_words(debug, words):
|
|||||||
def validate_mnemonics(mnemonics, expected_ems):
|
def validate_mnemonics(mnemonics, expected_ems):
|
||||||
# We expect these combinations to recreate the secret properly
|
# We expect these combinations to recreate the secret properly
|
||||||
# In case of click tests the mnemonics are always XofX so no need for combinations
|
# In case of click tests the mnemonics are always XofX so no need for combinations
|
||||||
ms = shamir.combine_mnemonics(mnemonics)
|
groups = shamir.decode_mnemonics(mnemonics)
|
||||||
identifier, iteration_exponent, _, _, _ = shamir._decode_mnemonics(mnemonics)
|
ems = shamir.recover_ems(groups)
|
||||||
ems = shamir._encrypt(ms, b"", iteration_exponent, identifier)
|
assert expected_ems == ems.ciphertext
|
||||||
assert ems == expected_ems
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import shamir_mnemonic as shamir
|
from shamir_mnemonic import shamir
|
||||||
|
|
||||||
from trezorlib import device, messages as proto
|
from trezorlib import device, messages as proto
|
||||||
from trezorlib.exceptions import TrezorFailure
|
from trezorlib.exceptions import TrezorFailure
|
||||||
@ -186,7 +186,6 @@ def validate_mnemonics(mnemonics, threshold, expected_ems):
|
|||||||
# 3of5 shares 3of5 groups
|
# 3of5 shares 3of5 groups
|
||||||
# TODO: test all possible group+share combinations?
|
# TODO: test all possible group+share combinations?
|
||||||
test_combination = mnemonics[0:3] + mnemonics[5:8] + mnemonics[10:13]
|
test_combination = mnemonics[0:3] + mnemonics[5:8] + mnemonics[10:13]
|
||||||
ms = shamir.combine_mnemonics(test_combination)
|
groups = shamir.decode_mnemonics(test_combination)
|
||||||
identifier, iteration_exponent, _, _, _ = shamir._decode_mnemonics(test_combination)
|
ems = shamir.recover_ems(groups)
|
||||||
ems = shamir._encrypt(ms, b"", iteration_exponent, identifier)
|
assert expected_ems == ems.ciphertext
|
||||||
assert ems == expected_ems
|
|
||||||
|
@ -18,8 +18,7 @@ from itertools import combinations
|
|||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import shamir_mnemonic as shamir
|
from shamir_mnemonic import MnemonicError, shamir
|
||||||
from shamir_mnemonic import MnemonicError
|
|
||||||
|
|
||||||
from trezorlib import device, messages as proto
|
from trezorlib import device, messages as proto
|
||||||
from trezorlib.exceptions import TrezorFailure
|
from trezorlib.exceptions import TrezorFailure
|
||||||
@ -144,11 +143,9 @@ class TestMsgResetDeviceT2:
|
|||||||
def validate_mnemonics(mnemonics, threshold, expected_ems):
|
def validate_mnemonics(mnemonics, threshold, expected_ems):
|
||||||
# We expect these combinations to recreate the secret properly
|
# We expect these combinations to recreate the secret properly
|
||||||
for test_group in combinations(mnemonics, threshold):
|
for test_group in combinations(mnemonics, threshold):
|
||||||
# TODO: HOTFIX, we should fix this properly by modifying and unifying the python-shamir-mnemonic API
|
groups = shamir.decode_mnemonics(test_group)
|
||||||
ms = shamir.combine_mnemonics(test_group)
|
ems = shamir.recover_ems(groups)
|
||||||
identifier, iteration_exponent, _, _, _ = shamir._decode_mnemonics(test_group)
|
assert expected_ems == ems.ciphertext
|
||||||
ems = shamir._encrypt(ms, b"", iteration_exponent, identifier)
|
|
||||||
assert ems == expected_ems
|
|
||||||
# We expect these combinations to raise MnemonicError
|
# We expect these combinations to raise MnemonicError
|
||||||
for test_group in combinations(mnemonics, threshold - 1):
|
for test_group in combinations(mnemonics, threshold - 1):
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import shamir_mnemonic as shamir
|
from shamir_mnemonic import shamir
|
||||||
|
|
||||||
from trezorlib import device, messages
|
from trezorlib import device, messages
|
||||||
from trezorlib.messages import BackupType, ButtonRequestType as B
|
from trezorlib.messages import BackupType, ButtonRequestType as B
|
||||||
@ -108,11 +108,9 @@ def backup_flow_slip39_basic(client):
|
|||||||
)
|
)
|
||||||
device.backup(client)
|
device.backup(client)
|
||||||
|
|
||||||
mnemonics = mnemonics[:3]
|
groups = shamir.decode_mnemonics(mnemonics[:3])
|
||||||
ms = shamir.combine_mnemonics(mnemonics)
|
ems = shamir.recover_ems(groups)
|
||||||
identifier, iteration_exponent, _, _, _ = shamir._decode_mnemonics(mnemonics)
|
return ems.ciphertext
|
||||||
secret = shamir._encrypt(ms, b"", iteration_exponent, identifier)
|
|
||||||
return secret
|
|
||||||
|
|
||||||
|
|
||||||
def backup_flow_slip39_advanced(client):
|
def backup_flow_slip39_advanced(client):
|
||||||
@ -172,10 +170,9 @@ def backup_flow_slip39_advanced(client):
|
|||||||
device.backup(client)
|
device.backup(client)
|
||||||
|
|
||||||
mnemonics = mnemonics[0:3] + mnemonics[5:8] + mnemonics[10:13]
|
mnemonics = mnemonics[0:3] + mnemonics[5:8] + mnemonics[10:13]
|
||||||
ms = shamir.combine_mnemonics(mnemonics)
|
groups = shamir.decode_mnemonics(mnemonics)
|
||||||
identifier, iteration_exponent, _, _, _ = shamir._decode_mnemonics(mnemonics)
|
ems = shamir.recover_ems(groups)
|
||||||
secret = shamir._encrypt(ms, b"", iteration_exponent, identifier)
|
return ems.ciphertext
|
||||||
return secret
|
|
||||||
|
|
||||||
|
|
||||||
VECTORS = [
|
VECTORS = [
|
||||||
|
Loading…
Reference in New Issue
Block a user