1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-27 08:38:07 +00:00

core/slip39: Update code logic, tests and test vectors in accordance with the new requirement that the number of shares provided is equal to the threshold.

This commit is contained in:
Andrew Kozlik 2019-05-03 18:28:14 +02:00
parent ff594753e0
commit bebce78881
3 changed files with 138 additions and 162 deletions

View File

@ -23,10 +23,6 @@ from trezor.crypto.slip39_wordlist import wordlist
from trezorcrypto import shamir
class ConfigurationError(Exception):
pass
class MnemonicError(Exception):
pass
@ -211,9 +207,7 @@ def _create_digest(random_data, shared_secret):
def _split_secret(threshold, share_count, shared_secret):
if threshold < 1:
raise ValueError(
"The requested threshold ({}) must be a positive integer.".format(
threshold
)
"The requested threshold ({}) must be a positive integer.".format(threshold)
)
if threshold > share_count:
@ -585,30 +579,25 @@ def combine_mnemonics(mnemonics):
mnemonics
)
if len(groups) < group_threshold:
if len(groups) != group_threshold:
raise MnemonicError(
"Insufficient number of mnemonic groups ({}). The required number of groups is {}.".format(
len(groups), group_threshold
"Wrong number of mnemonic groups. Expected {} groups, but {} were provided.".format(
group_threshold, len(groups)
)
)
# Remove the groups, where the number of shares is below the member threshold.
bad_groups = {
group_index: group
for group_index, group in groups.items()
if len(group[1]) < group[0]
}
for group_index in bad_groups:
groups.pop(group_index)
if len(groups) < group_threshold:
group_index, group = next(iter(bad_groups.items()))
for group_index, group in groups.items():
if len(group[1]) != group[0]:
prefix = _group_prefix(
identifier, iteration_exponent, group_index, group_threshold, group_count
identifier,
iteration_exponent,
group_index,
group_threshold,
group_count,
)
raise MnemonicError(
'Insufficient number of mnemonics. At least {} mnemonics starting with "{} ..." are required.'.format(
group[0], mnemonic_from_indices(prefix)
'Wrong number of mnemonics. Expected {} mnemonics starting with "{} ...", but {} were provided.'.format(
group[0], mnemonic_from_indices(prefix), len(group[1])
)
)

View File

@ -20,15 +20,7 @@ vectors = [
[
[
"shadow pistol academic always adequate wildlife fancy gross oasis cylinder mustang wrist rescue view short owner flip making coding armed",
"shadow pistol academic acid actress prayer class unknown daughter sweater depict flip twice unkind craft early superior advocate guest smoking",
"shadow pistol academic agency acid license obtain preach firefly permit flavor library learn tension flea unusual nylon terminal exercise become"
],
"b43ceb7e57a0ea8766221624d01b0864"
],
[
[
"shadow pistol academic always adequate wildlife fancy gross oasis cylinder mustang wrist rescue view short owner flip making coding armed",
"shadow pistol academic agency acid license obtain preach firefly permit flavor library learn tension flea unusual nylon terminal exercise become"
"shadow pistol academic acid actress prayer class unknown daughter sweater depict flip twice unkind craft early superior advocate guest smoking"
],
"b43ceb7e57a0ea8766221624d01b0864"
],
@ -40,280 +32,250 @@ vectors = [
],
[
[
"numb stay academic acid aide deny bulge romp kernel rumor flavor estate traffic video email living grief move corner laundry",
"numb smoking academic agency cleanup false acne luxury withdraw swing ceramic adjust forget editor remind bedroom practice ting fancy theory"
"adequate smoking academic acid debut wine petition glen cluster slow rhyme slow simple epidemic rumor junk tracks treat olympic tolerate",
"adequate stay academic agency agency formal party ting frequent learn upstairs remember smear leaf damage anatomy ladle market hush corner"
],
""
],
[
[
"enlarge pants academic acid alien become warmth exclude unfold yield square unusual increase chest wireless rainbow duration cause wrote taste",
"enlarge painting academic agency anatomy infant carve platform nail already flavor mailman iris video beam rapids smoking teacher gross failure"
"peasant leaves academic acid desert exact olympic math alive axle trial tackle drug deny decent smear dominant desert bucket remind",
"peasant leader academic agency cultural blessing percent network envelope medal junk primary human pumps jacket fragment payroll ticket evoke voice"
],
""
],
[
[
"script smoking beard echo blimp diminish pencil curious vampire devote valuable skin mama starting tension explain elegant surface venture judicial",
"script smoking beard email charity clock join peasant acquire tidy dress drove width depend smart trust guitar bulb echo duration",
"script smoking academic easy diet theater twin guard already image increase trash lend pink general crowd chest metric together heat"
"liberty category beard echo animal fawn temple briefing math username various wolf aviation fancy visual holy thunder yelp helpful payment",
"liberty category beard email beyond should fancy romp founder easel pink holy hairy romp loyalty material victim owner toxic custody",
"liberty category academic easy being hazard crush diminish oral lizard reaction cluster force dilemma deploy force club veteran expect photo"
],
""
],
[
[
"scroll leader academic leaf become alcohol adapt tactics born orange eraser mobile fragment playoff easel nail edge sympathy liberty closet",
"scroll leader academic agency alcohol rhyme excuse image wolf sidewalk index yoga upgrade flip inmate blue relate twin mental corner"
"average senior academic leaf broken teacher expect surface hour capture obesity desire negative dynamic dominant pistol mineral mailman iris aide",
"average senior academic agency curious pants blimp spew clothes slice script dress wrap firm shaft regular slavery negative theater roster"
],
""
],
[
[
"client isolate acrobat acid chew both garlic holy artist gums already package spray story remind tricycle texture trouble amazing evil",
"client isolate acrobat agency daisy retreat slush genuine trip overall burden beyond enforce shaft decrease loud crazy exact round answer",
"client isolate beard academic campus verdict wine lunch rapids born warn spend patent surface elevator satoshi upgrade general echo legs"
"music husband acrobat acid artist finance center either graduate swimming object bike medical clothes station aspect spider maiden bulb welcome",
"music husband acrobat agency advance hunting bike corner density careful material civil evil tactics remind hawk discuss hobo voice rainbow",
"music husband beard academic black tricycle clock mayor estimate level photo episode exclude ecology papa source amazing salt verify divorce"
],
""
],
[
[
"involve deal academic always boundary formal answer genius science civil envy thunder duckling trip tracks exceed response grin humidity wolf",
"involve deal academic agency civil revenue program sharp merchant false ending credit wrote slush simple gather fiber justice emphasis hand",
"involve deal academic always display memory damage center promise rumor drove subject large payment spelling alpha twin browser dilemma revenue"
"device stay academic always dive coal antenna adult black exceed stadium herald advance soldier busy dryer daughter evaluate minister laser",
"device stay academic always dwarf afraid robin gravity crunch adjust soul branch walnut coastal dream costume scholar mortgage mountain pumps"
],
""
],
[
[
"patrol necklace academic academic dream empty advance artist hush prayer galaxy adequate camera presence patrol entrance excuse quantity gesture cradle",
"patrol necklace academic agency duckling kidney prize desire forecast imply moisture envy express beyond that profile involve dance much auction"
"hour painting academic academic device formal evoke guitar random modern justice filter withdraw trouble identify mailman insect general cover oven",
"hour painting academic agency artist again daisy capital beaver fiber much enjoy suitable symbolic identify photo editor romp float echo"
],
""
],
[
[
"drift deal academic acid acquire busy elephant crucial thumb jewelry lift agency amazing laden isolate negative smoking campus march teaspoon",
"drift deal academic agency adequate pants adjust cards champion aunt strategy fatigue observe aircraft valuable primary dominant webcam bike wits"
"guilt walnut academic acid deliver remove equip listen vampire tactics nylon rhythm failure husband fatigue alive blind enemy teaspoon rebound",
"guilt walnut academic agency brave hamster hobo declare herd taste alpha slim criminal mild arcade formal romp branch pink ambition"
],
""
],
[
[
"memory stay beard romp depend idle unfold stilt thorn obesity alarm slap thumb says python ordinary mineral insect square cards"
"eraser senior beard romp adorn nuclear spill corner cradle style ancient family general leader ambition exchange unusual garlic promise voice"
],
""
],
[
[
"memory stay decision spew duckling carve single profile frozen result forbid pecan game greatest shaped advance craft golden visitor fangs",
"memory stay decision roster deliver organize olympic quantity clogs gather goat energy literary library pupal exotic season index yelp vexed"
"eraser senior decision scared cargo theory device idea deliver modify curly include pancake both news skin realize vitamins away join",
"eraser senior decision roster beard treat identify grumpy salt index fake aviation theater cubic bike cause research dragon emphasis counter"
],
""
],
[
[
"memory stay decision shadow always sheriff rich wine wrote raspy vintage boring careful recover overall reaction bishop writing blessing corner",
"memory stay beard romp depend idle unfold stilt thorn obesity alarm slap thumb says python ordinary mineral insect square cards"
"eraser senior decision shadow artist work morning estate greatest pipeline plan ting petition forget hormone flexible general goat admit surface",
"eraser senior beard romp adorn nuclear spill corner cradle style ancient family general leader ambition exchange unusual garlic promise voice"
],
""
],
[
[
"memory stay decision smug acid device switch likely fatal starting cluster fiction puny view trust program painting paper recover luxury",
"memory stay ceramic snake clothes loan company credit phantom blessing jewelry welcome smith legs unknown paid moisture unwrap become lobe",
"memory stay decision spew duckling carve single profile frozen result forbid pecan game greatest shaped advance craft golden visitor fangs",
"memory stay ceramic shaft cause receiver geology space ancient shelter tension universe radar learn round shrimp deal fragment desire hormone",
"memory stay ceramic round duration snapshot orbit cage debris script herald item have election adequate pink artist profile born eclipse"
"eraser senior decision roster beard treat identify grumpy salt index fake aviation theater cubic bike cause research dragon emphasis counter",
"eraser senior ceramic snake clay various huge numb argue hesitate auction category timber browser greatest hanger petition script leaf pickup",
"eraser senior ceramic shaft dynamic become junior wrist silver peasant force math alto coal amazing segment yelp velvet image paces",
"eraser senior ceramic round column hawk trust auction smug shame alive greatest sheriff living perfect corner chest sled fumes adequate",
"eraser senior decision smug corner ruin rescue cubic angel tackle skin skunk program roster trash rumor slush angel flea amazing"
],
"97a292a5941682d7a4ae2d898d11a519"
"7c3397a292a5941682d7a4ae2d898d11"
],
[
[
"memory stay beard romp depend idle unfold stilt thorn obesity alarm slap thumb says python ordinary mineral insect square cards",
"memory stay acrobat romp dilemma echo ruler process vintage leaves detailed speak tolerate timber lunch damage strategy junior element prevent"
"eraser senior decision smug corner ruin rescue cubic angel tackle skin skunk program roster trash rumor slush angel flea amazing",
"eraser senior beard romp adorn nuclear spill corner cradle style ancient family general leader ambition exchange unusual garlic promise voice",
"eraser senior decision scared cargo theory device idea deliver modify curly include pancake both news skin realize vitamins away join"
],
"97a292a5941682d7a4ae2d898d11a519"
"7c3397a292a5941682d7a4ae2d898d11"
],
[
[
"memory stay ceramic snake clothes loan company credit phantom blessing jewelry welcome smith legs unknown paid moisture unwrap become lobe",
"memory stay decision scared aquatic receiver mason package corner animal cage receiver hazard beyond merit tension exotic reaction pulse deadline",
"memory stay acrobat romp dilemma echo ruler process vintage leaves detailed speak tolerate timber lunch damage strategy junior element prevent",
"memory stay beard romp depend idle unfold stilt thorn obesity alarm slap thumb says python ordinary mineral insect square cards",
"memory stay ceramic round duration snapshot orbit cage debris script herald item have election adequate pink artist profile born eclipse",
"memory stay decision spew duckling carve single profile frozen result forbid pecan game greatest shaped advance craft golden visitor fangs",
"memory stay decision roster deliver organize olympic quantity clogs gather goat energy literary library pupal exotic season index yelp vexed",
"memory stay decision sister devote theory promise staff venture symbolic mailman timely valid counter retreat building order dominant forward verify",
"memory stay ceramic skin crowd building glimpse space angry early language mortgage burden grumpy class deadline wildlife unhappy gums thorn",
"memory stay decision smug acid device switch likely fatal starting cluster fiction puny view trust program painting paper recover luxury",
"memory stay decision shadow always sheriff rich wine wrote raspy vintage boring careful recover overall reaction bishop writing blessing corner",
"memory stay ceramic shaft cause receiver geology space ancient shelter tension universe radar learn round shrimp deal fragment desire hormone",
"memory stay ceramic scatter detailed knit oral cage decent debut upstairs adequate science petition temple exchange scroll camera evaluate shrimp"
"eraser senior beard romp adorn nuclear spill corner cradle style ancient family general leader ambition exchange unusual garlic promise voice",
"eraser senior acrobat romp bishop medical gesture pumps secret alive ultimate quarter priest subject class dictate spew material endless market"
],
"97a292a5941682d7a4ae2d898d11a519"
"7c3397a292a5941682d7a4ae2d898d11"
],
[
[
"spark leader academic academic artwork crazy pacific friar holy preach trust empty remember syndrome mineral aviation medical dive cluster scroll organize painting helpful critical spend smug tackle cowboy identify pitch unfair flavor percent"
"theory painting academic academic armed sweater year military elder discuss acne wildlife boring employer fused large satoshi bundle carbon diagnose anatomy hamster leaves tracks paces beyond phantom capital marvel lips brave detect luck"
],
"33dfd8cc75e42477025dce88ae83e75a230086a0e00e9271f4c938b319067687"
"989baf9dcaad5b10ca33dfd8cc75e42477025dce88ae83e75a230086a0e00e92"
],
[
[
"spark leader academic academic artwork crazy pacific friar holy preach trust empty remember syndrome mineral aviation medical dive cluster scroll organize painting helpful critical spend smug tackle cowboy identify pitch unfair flavor pencil"
"theory painting academic academic armed sweater year military elder discuss acne wildlife boring employer fused large satoshi bundle carbon diagnose anatomy hamster leaves tracks paces beyond phantom capital marvel lips brave detect lunar"
],
""
],
[
[
"spark leader academic academic capacity crazy pacific friar holy preach trust empty remember syndrome mineral aviation medical dive cluster scroll organize painting helpful critical spend smug tackle cowboy identify pitch permit wavy unkind"
"theory painting academic academic campus sweater year military elder discuss acne wildlife boring employer fused large satoshi bundle carbon diagnose anatomy hamster leaves tracks paces beyond phantom capital marvel lips facility obtain sister"
],
""
],
[
[
"seafood learn academic always adult harvest inform custody space ending frequent coding lamp amazing museum year argue mandate should minister jacket float duke client survive large entrance unknown rhythm angel genuine safari talent",
"seafood learn academic agency ancient clay execute browser railroad system brother anxiety focus elephant merit standard slap numerous insect hush hospital emphasis depend nail morning epidemic lawsuit aluminum buyer drift metric meaning burning",
"seafood learn academic acid armed survive flip soul analysis crucial species similar rescue regret mixture twin marvel pleasure trend soul afraid depict rumor champion skunk bumpy obtain impulse texture fantasy year maiden kidney"
"humidity disease academic always aluminum jewelry energy woman receiver strategy amuse duckling lying evidence network walnut tactics forget hairy rebound impulse brother survive clothes stadium mailman rival ocean reward venture always armed unwrap",
"humidity disease academic agency actress jacket gross physics cylinder solution fake mortgage benefit public busy prepare sharp friar change work slow purchase ruler again tricycle involve viral wireless mixture anatomy desert cargo upgrade"
],
"e05e0da0ecce1278f75ff58d9853f19dcaeed5de104aae37c7af367d74bc8756"
"c938b319067687e990e05e0da0ecce1278f75ff58d9853f19dcaeed5de104aae"
],
[
[
"seafood learn academic acid armed survive flip soul analysis crucial species similar rescue regret mixture twin marvel pleasure trend soul afraid depict rumor champion skunk bumpy obtain impulse texture fantasy year maiden kidney",
"seafood learn academic agency ancient clay execute browser railroad system brother anxiety focus elephant merit standard slap numerous insect hush hospital emphasis depend nail morning epidemic lawsuit aluminum buyer drift metric meaning burning"
],
"e05e0da0ecce1278f75ff58d9853f19dcaeed5de104aae37c7af367d74bc8756"
],
[
[
"seafood learn academic agency ancient clay execute browser railroad system brother anxiety focus elephant merit standard slap numerous insect hush hospital emphasis depend nail morning epidemic lawsuit aluminum buyer drift metric meaning burning"
"humidity disease academic always aluminum jewelry energy woman receiver strategy amuse duckling lying evidence network walnut tactics forget hairy rebound impulse brother survive clothes stadium mailman rival ocean reward venture always armed unwrap"
],
""
],
[
[
"practice enlarge academic acid born verdict dominant cylinder earth bracelet dining resident public garden desktop course fact exact vanish branch",
"practice easy academic agency advance broken firm elder exact axle plunge dream glance depict username flexible airline station include priority"
"smear husband academic acid deadline scene venture distance dive overall parking bracelet elevator justice echo burning oven chest duke nylon",
"smear isolate academic agency alpha mandate decorate burden recover guard exercise fatal force syndrome fumes thank guest drift dramatic mule"
],
""
],
[
[
"expand ecology academic acid drug coastal forbid sister blanket salary unusual fridge phrase amuse hesitate repair much findings practice slavery",
"expand easy academic agency column lungs dilemma chest depict trial member intimate gums rich mayor grin husband reward western debris"
"finger trash academic acid average priority dish revenue academic hospital spirit western ocean fact calcium syndrome greatest plan losing dictate",
"finger traffic academic agency building lilac deny paces subject threaten diploma eclipse window unknown health slim piece dragon focus smirk"
],
""
],
[
[
"depart branch beard echo dilemma likely building hand treat trial pumps writing photo fragment lunar ranked sympathy wrap alien debris",
"depart branch beard email darkness tracks national discuss fluff merit gesture order mule firefly evaluate both element adult walnut stick",
"depart branch academic easy august moisture snapshot smear genuine sister order crisis gums afraid dress romantic imply activity skunk shelter"
"flavor pink beard echo depart forbid retreat become frost helpful juice unwrap reunion credit math burning spine black capital lair",
"flavor pink beard email diet teaspoon freshman identify document rebound cricket prune headset loyalty smell emission skin often square rebound",
"flavor pink academic easy credit cage raisin crazy closet lobe mobile become drink human tactics valuable hand capture sympathy finger"
],
""
],
[
[
"race flea academic leaf crazy carpet item lyrics galaxy remind lungs distance thank lunch cowboy emission fridge center music costume",
"race flea academic agency cricket response sack geology maiden spray salon enforce fishing junction oven repair video phrase pumps duration"
"column flea academic leaf debut extra surface slow timber husky lawsuit game behavior husky swimming already paper episode tricycle scroll",
"column flea academic agency blessing garbage party software stadium verify silent umbrella therapy decorate chemical erode dramatic eclipse replace apart"
],
""
],
[
[
"cleanup garden acrobat acid branch idle season upstairs mountain energy aspect intimate black exchange purchase arcade making tricycle primary thunder",
"cleanup garden acrobat agency clay that finger phantom solution forward evil rival item much mansion lecture device decrease advocate ounce",
"cleanup garden beard academic cowboy desktop submit liquid branch olympic smith render category grumpy group campus impulse drift society starting"
"smirk pink acrobat acid auction wireless impulse spine sprinkle fortune clogs elbow guest hush loyalty crush dictate tracks airport talent",
"smirk pink acrobat agency dwarf emperor ajar organize legs slice harvest plastic dynamic style mobile float bulb health coding credit",
"smirk pink beard academic alto strategy carve shame language rapids ruin smart location spray training acquire eraser endorse submit peaceful"
],
""
],
[
[
"paper branch academic always bolt secret senior starting society artwork ocean marathon parcel large revenue hush jerky sympathy indicate therapy",
"paper branch academic agency auction plan charity identify yelp glad webcam provide evaluate response hunting belong veteran unknown speak twin",
"paper branch academic always coastal bumpy burning nylon silent speak forward findings velvet terminal busy aircraft glasses firm extra mandate"
"fishing recover academic always device craft trend snapshot gums skin downtown watch device sniff hour clock public maximum garlic born",
"fishing recover academic always aircraft view software cradle fangs amazing package plastic evaluate intend penalty epidemic anatomy quarter cage apart"
],
""
],
[
[
"payroll guest academic academic being holiday relate alive wrist shadow intimate inmate ocean method system repeat capital dress iris zero",
"payroll guest academic agency body type agree single amuse charity jump building medical omit fancy losing obtain again flash mandate"
"evoke garden academic academic answer wolf scandal modern warmth station devote emerald market physics surface formal amazing aquatic gesture medical",
"evoke garden academic agency deal revenue knit reunion decrease magazine flexible company goat repair alarm military facility clogs aide mandate"
],
""
],
[
[
"triumph necklace academic acid campus deadline estate corner result dress main debris research stick fawn freshman alarm obtain keyboard standard",
"triumph necklace academic agency decorate cradle charity ajar multiple station tidy cricket fiction slice midst mobile writing company chest jewelry"
"river deal academic acid average forbid pistol peanut custody bike class aunt hairy merit valid flexible learn ajar very easel",
"river deal academic agency camera amuse lungs numb isolate display smear piece traffic worthy year patrol crush fact fancy emission"
],
""
],
[
[
"grumpy upgrade beard romp academic owner package lawsuit industry auction market install acrobat blimp pregnant trial agency dismiss species wildlife briefing painting mailman spine angel mental violence rainbow cowboy kidney industry friendly sled"
"wildlife deal beard romp alcohol space mild usual clothes union nuclear testify course research heat listen task location thank hospital slice smell failure fawn helpful priest ambition average recover lecture process dough stadium"
],
""
],
[
[
"grumpy upgrade decision shadow aspect transfer mailman intimate payroll raspy mother sack unfair soul famous ladybug leaf width evaluate acrobat envy mailman crystal rich spark forbid revenue findings permit formal sled twice unknown",
"grumpy upgrade decision spew advance column ladybug hanger ancestor cinema require material dwarf laden peanut teacher market parking typical space quantity mayor dynamic radar paid leaves swimming writing flip style fishing yield award"
"wildlife deal decision scared acne fatal snake paces obtain election dryer dominant romp tactics railroad marvel trust helpful flip peanut theory theater photo luck install entrance taxi step oven network dictate intimate listen",
"wildlife deal decision smug ancestor genuine move huge cubic strategy smell game costume extend swimming false desire fake traffic vegan senior twice timber submit leader payroll fraction apart exact forward pulse tidy install"
],
""
],
[
[
"grumpy upgrade decision shadow aspect transfer mailman intimate payroll raspy mother sack unfair soul famous ladybug leaf width evaluate acrobat envy mailman crystal rich spark forbid revenue findings permit formal sled twice unknown",
"grumpy upgrade beard romp academic owner package lawsuit industry auction market install acrobat blimp pregnant trial agency dismiss species wildlife briefing painting mailman spine angel mental violence rainbow cowboy kidney industry friendly sled"
"wildlife deal decision shadow analysis adjust bulb skunk muscle mandate obesity total guitar coal gravity carve slim jacket ruin rebuild ancestor numerous hour mortgage require herd maiden public ceiling pecan pickup shadow club",
"wildlife deal beard romp alcohol space mild usual clothes union nuclear testify course research heat listen task location thank hospital slice smell failure fawn helpful priest ambition average recover lecture process dough stadium"
],
""
],
[
[
"grumpy upgrade decision scared aviation echo mama junk mama robin finance industry piece rapids leader slush swimming insect holiday document ancient tofu exotic square shaped artist easel diet thorn railroad fridge hobo dictate",
"grumpy upgrade ceramic round acrobat blue enemy admit wildlife exotic inform mustang symbolic pickup salary insect plunge miracle retailer clogs shelter focus privacy bolt carbon rebound cinema tidy lying born pregnant divorce payroll",
"grumpy upgrade decision shadow aspect transfer mailman intimate payroll raspy mother sack unfair soul famous ladybug leaf width evaluate acrobat envy mailman crystal rich spark forbid revenue findings permit formal sled twice unknown",
"grumpy upgrade ceramic skin august review medical dynamic year tackle juice percent profile magazine violence arena gums anxiety move election paper withdraw petition fangs tension segment junk pickup ranked alto animal snapshot spider",
"grumpy upgrade ceramic shaft acrobat fitness much slow vintage scout agree dismiss mustang remove violence reunion kidney campus moment quarter rocky hairy calcium machine editor living floral evidence trash tracks fridge believe transfer"
"wildlife deal ceramic round aluminum pitch goat racism employer miracle percent math decision episode dramatic editor lily prospect program scene rebuild display sympathy have single mustang junction relate often chemical society wits estate",
"wildlife deal decision scared acne fatal snake paces obtain election dryer dominant romp tactics railroad marvel trust helpful flip peanut theory theater photo luck install entrance taxi step oven network dictate intimate listen",
"wildlife deal ceramic scatter argue equip vampire together ruin reject literary rival distance aquatic agency teammate rebound false argue miracle stay again blessing peaceful unknown cover beard acid island language debris industry idle",
"wildlife deal ceramic snake agree voter main lecture axis kitchen physics arcade velvet spine idea scroll promise platform firm sharp patrol divorce ancestor fantasy forbid goat ajar believe swimming cowboy symbolic plastic spelling",
"wildlife deal decision shadow analysis adjust bulb skunk muscle mandate obesity total guitar coal gravity carve slim jacket ruin rebuild ancestor numerous hour mortgage require herd maiden public ceiling pecan pickup shadow club"
],
"cde0a3318493262591e78b8c14c6686167123b7d868483aa5b67e2fb45294834"
"5385577c8cfc6c1a8aa0f7f10ecde0a3318493262591e78b8c14c6686167123b"
],
[
[
"grumpy upgrade beard romp academic owner package lawsuit industry auction market install acrobat blimp pregnant trial agency dismiss species wildlife briefing painting mailman spine angel mental violence rainbow cowboy kidney industry friendly sled",
"grumpy upgrade acrobat romp album herald epidemic rebuild alcohol rapids element receiver belong wrap liquid large script magazine pregnant election estate vegan density beard duckling counter grill island screw humidity engage wireless detect"
"wildlife deal decision scared acne fatal snake paces obtain election dryer dominant romp tactics railroad marvel trust helpful flip peanut theory theater photo luck install entrance taxi step oven network dictate intimate listen",
"wildlife deal beard romp alcohol space mild usual clothes union nuclear testify course research heat listen task location thank hospital slice smell failure fawn helpful priest ambition average recover lecture process dough stadium",
"wildlife deal decision smug ancestor genuine move huge cubic strategy smell game costume extend swimming false desire fake traffic vegan senior twice timber submit leader payroll fraction apart exact forward pulse tidy install"
],
"cde0a3318493262591e78b8c14c6686167123b7d868483aa5b67e2fb45294834"
"5385577c8cfc6c1a8aa0f7f10ecde0a3318493262591e78b8c14c6686167123b"
],
[
[
"grumpy upgrade decision spew advance column ladybug hanger ancestor cinema require material dwarf laden peanut teacher market parking typical space quantity mayor dynamic radar paid leaves swimming writing flip style fishing yield award",
"grumpy upgrade decision roster acquire necklace knife laundry glimpse warmth theory dynamic valuable flash slow fridge ivory usher loan volume scatter knife numerous artwork pajamas response editor deploy crucial problem material fatal various",
"grumpy upgrade beard romp academic owner package lawsuit industry auction market install acrobat blimp pregnant trial agency dismiss species wildlife briefing painting mailman spine angel mental violence rainbow cowboy kidney industry friendly sled",
"grumpy upgrade decision scared aviation echo mama junk mama robin finance industry piece rapids leader slush swimming insect holiday document ancient tofu exotic square shaped artist easel diet thorn railroad fridge hobo dictate",
"grumpy upgrade acrobat romp album herald epidemic rebuild alcohol rapids element receiver belong wrap liquid large script magazine pregnant election estate vegan density beard duckling counter grill island screw humidity engage wireless detect",
"grumpy upgrade ceramic snake ambition strike estate dance multiple clothes mixture cubic staff very husband valid burning sheriff emission raisin huge snake merchant omit firm security deadline home cleanup chubby airport forget taxi",
"grumpy upgrade ceramic skin august review medical dynamic year tackle juice percent profile magazine violence arena gums anxiety move election paper withdraw petition fangs tension segment junk pickup ranked alto animal snapshot spider",
"grumpy upgrade decision smug arena zero lunch hobo testify graduate artist seafood gums olympic unfair include counter climate alto carve ladle blind traffic huge vitamins declare patent window music romp lobe rumor silent",
"grumpy upgrade decision shadow aspect transfer mailman intimate payroll raspy mother sack unfair soul famous ladybug leaf width evaluate acrobat envy mailman crystal rich spark forbid revenue findings permit formal sled twice unknown",
"grumpy upgrade ceramic shaft acrobat fitness much slow vintage scout agree dismiss mustang remove violence reunion kidney campus moment quarter rocky hairy calcium machine editor living floral evidence trash tracks fridge believe transfer",
"grumpy upgrade decision sister actress decent keyboard imply evening valid chemical makeup resident deploy calcium undergo clay lawsuit pants single loan become wine gravity repair training says eyebrow hawk ecology camera spirit crowd",
"grumpy upgrade ceramic scatter august wits fragment very username finger ancient angel tidy mustang salary scandal rhythm liquid reunion spew standard skunk born skunk reward vintage activity amuse spray voice welcome warmth paces",
"grumpy upgrade ceramic round acrobat blue enemy admit wildlife exotic inform mustang symbolic pickup salary insect plunge miracle retailer clogs shelter focus privacy bolt carbon rebound cinema tidy lying born pregnant divorce payroll"
"wildlife deal beard romp alcohol space mild usual clothes union nuclear testify course research heat listen task location thank hospital slice smell failure fawn helpful priest ambition average recover lecture process dough stadium",
"wildlife deal acrobat romp anxiety axis starting require metric flexible geology game drove editor edge screw helpful have huge holy making pitch unknown carve holiday numb glasses survive already tenant adapt goat fangs"
],
"cde0a3318493262591e78b8c14c6686167123b7d868483aa5b67e2fb45294834"
"5385577c8cfc6c1a8aa0f7f10ecde0a3318493262591e78b8c14c6686167123b"
],
[
[
"home aluminum academic academic acid member verdict purchase blind camera duration email fortune forbid obtain birthday mountain distance agree"
"junk necklace academic academic acne isolate join hesitate lunar roster dough calcium chemical ladybug amount mobile glasses verify cylinder"
],
""
],
[
[
"regular guest academic academic award saver tidy filter destroy infant luxury pants member boundary valid hesitate mama hairy avoid insect acrobat"
"fraction necklace academic academic award teammate mouse regular testify coding building member verdict purchase blind camera duration email prepare spirit quarter"
],
""
]

View File

@ -1,20 +1,37 @@
from common import *
from trezor.crypto import slip39
from trezor.crypto import slip39, random
from slip39_vectors import vectors
def combinations(iterable, r):
# Taken from https://docs.python.org/3.7/library/itertools.html#itertools.combinations
pool = tuple(iterable)
n = len(pool)
if r > n:
return
indices = list(range(r))
yield tuple(pool[i] for i in indices)
while True:
for i in reversed(range(r)):
if indices[i] != i + n - r:
break
else:
return
indices[i] += 1
for j in range(i+1, r):
indices[j] = indices[j-1] + 1
yield tuple(pool[i] for i in indices)
class TestCryptoSlip39(unittest.TestCase):
MS = b"ABCDEFGHIJKLMNOP"
def test_basic_sharing_random(self):
mnemonics = slip39.generate_mnemonics_random(1, [(3, 5)])[0]
self.assertEqual(slip39.combine_mnemonics(mnemonics[1:4]), slip39.combine_mnemonics(mnemonics))
self.assertEqual(slip39.combine_mnemonics(mnemonics[:3]), slip39.combine_mnemonics(mnemonics[2:]))
def test_basic_sharing_fixed(self):
mnemonics = slip39.generate_mnemonics(1, [(3, 5)], self.MS)[0]
identifier, exponent, ems = slip39.combine_mnemonics(mnemonics)
identifier, exponent, ems = slip39.combine_mnemonics(mnemonics[:3])
self.assertEqual(slip39.decrypt(identifier, exponent, ems, b""), self.MS)
self.assertEqual(slip39.combine_mnemonics(mnemonics[1:4])[2], ems)
with self.assertRaises(slip39.MnemonicError):
@ -41,19 +58,27 @@ class TestCryptoSlip39(unittest.TestCase):
def test_group_sharing(self):
mnemonics = slip39.generate_mnemonics(2, [(3, 5), (2, 3), (2, 5), (1, 1)], self.MS)
group_threshold = 2
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
)
# All mnemonics.
identifier, exponent, ems = slip39.combine_mnemonics([mnemonic for group in mnemonics for mnemonic in group])
# Test all valid combinations of mnemonics.
for groups in combinations(zip(mnemonics, member_thresholds), group_threshold):
for group1_subset in combinations(groups[0][0], groups[0][1]):
for group2_subset in combinations(groups[1][0], groups[1][1]):
mnemonic_subset = list(group1_subset + group2_subset)
random.shuffle(mnemonic_subset)
identifier, exponent, ems = slip39.combine_mnemonics(mnemonic_subset)
self.assertEqual(slip39.decrypt(identifier, exponent, ems, b""), self.MS)
# Minimal sets of mnemonics.
self.assertEqual(slip39.combine_mnemonics([mnemonics[2][0], mnemonics[2][2], mnemonics[3][0]])[2], ems)
self.assertEqual(slip39.combine_mnemonics([mnemonics[2][3], mnemonics[3][0], mnemonics[2][4]])[2], ems)
# Two complete groups and one incomplete group.
self.assertEqual(slip39.combine_mnemonics(mnemonics[0] + [mnemonics[1][1]] + mnemonics[2])[2], ems)
self.assertEqual(slip39.combine_mnemonics(mnemonics[0][1:4] + mnemonics[1][1:3] + mnemonics[2][2:4])[2], ems)
# Minimal sets of mnemonics.
identifier, exponent, ems = slip39.combine_mnemonics([mnemonics[2][0], mnemonics[2][2], mnemonics[3][0]])
self.assertEqual(slip39.decrypt(identifier, exponent, ems, b""), self.MS)
self.assertEqual(slip39.combine_mnemonics([mnemonics[2][3], mnemonics[3][0], mnemonics[2][4]])[2], ems)
# One complete group and one incomplete group out of two groups required.
with self.assertRaises(slip39.MnemonicError):