core/slip39: Fixed a bug when generating shares with group_threshold = 1.

pull/353/head
Andrew Kozlik 5 years ago
parent 0b96b48a8c
commit 0e277dfcb0

@ -229,7 +229,7 @@ def _split_secret(threshold, share_count, shared_secret):
# If the threshold is 1, then the digest of the shared secret is not used.
if threshold == 1:
return [(0, shared_secret)]
return [(i, shared_secret) for i in range(share_count)]
random_share_count = threshold - 2

@ -89,6 +89,31 @@ class TestCryptoSlip39(unittest.TestCase):
slip39.combine_mnemonics(mnemonics[0][1:4])
def test_group_sharing_threshold_1(self):
group_threshold = 1
group_sizes = (5, 3, 5, 1)
member_thresholds = (3, 2, 2, 1)
mnemonics = slip39.generate_mnemonics(
group_threshold, list(zip(member_thresholds, group_sizes)), self.MS
)
# Test all valid combinations of mnemonics.
for group, threshold in zip(mnemonics, member_thresholds):
for group_subset in combinations(group, threshold):
mnemonic_subset = list(group_subset)
random.shuffle(mnemonic_subset)
identifier, exponent, ems = slip39.combine_mnemonics(mnemonic_subset)
self.assertEqual(slip39.decrypt(identifier, exponent, ems, b""), self.MS)
def test_all_groups_exist(self):
for group_threshold in (1, 2, 5):
mnemonics = slip39.generate_mnemonics(
group_threshold, [(3, 5), (1, 1), (2, 3), (2, 5), (3, 5)], self.MS
)
self.assertEqual(len(mnemonics), 5)
self.assertEqual(len(sum(mnemonics, [])), 19)
def test_invalid_sharing(self):
# Short master secret.
with self.assertRaises(ValueError):

Loading…
Cancel
Save