Ejemplo n.º 1
0
		def collisions():
			ss_count,ltr,last_sid,collisions_chk = (
				(SubSeedIdxRange.max_idx,'S','2788F26B',470),
				(49509,'L','8D1FE500',2)
			)[bool(opt.fast)]

			last_idx = str(ss_count) + ltr

			msg_r('Testing Seed ID collisions ({} subseed pairs)...'.format(ss_count))

			seed_bin = bytes.fromhex('12abcdef' * 8)
			seed = Seed(seed_bin)

			seed.subseeds._generate(ss_count)
			ss = seed.subseeds

			assert seed.subseed(last_idx).sid == last_sid, seed.subseed(last_idx).sid

			for sid in ss.data['long']:
				# msg(sid)
				assert sid not in ss.data['short']

			collisions = 0
			for k in ('short','long'):
				for sid in ss.data[k]:
					collisions += ss.data[k][sid][1]

			assert collisions == collisions_chk, collisions
			vmsg_r('\n{} collisions, last_sid {}'.format(collisions,last_sid))
			msg('OK')
Ejemplo n.º 2
0
        def collisions(seed_hex, ss_count, last_sid, collisions_chk,
                       master_idx):

            msg_r(
                'Testing Seed ID collisions ({} seed shares, master_idx={})...'
                .format(ss_count, master_idx))
            vmsg('')

            seed_bin = bytes.fromhex(seed_hex)
            seed = Seed(seed_bin)

            SeedShareIdx.max_val = ss_count
            shares = seed.split(ss_count, master_idx=master_idx)
            A = shares.get_share_by_idx(ss_count).sid
            B = shares.get_share_by_seed_id(last_sid).sid
            assert A == last_sid, A
            assert B == last_sid, B

            assert shares.nonce_start == 0, shares.nonce_start

            collisions = 0
            for sid in shares.data['long']:
                collisions += shares.data['long'][sid][1]

            assert collisions == collisions_chk, collisions
            vmsg_r('{} collisions, last_sid {}'.format(collisions, last_sid))
            msg('OK')
Ejemplo n.º 3
0
        def collisions():
            ss_count, last_sid, collisions_chk = (65535, 'B5CBCE0A', 3)

            msg_r('Testing Seed ID collisions ({} seed splits)...'.format(
                ss_count))
            vmsg('')

            seed_bin = bytes.fromhex('1dabcdef' * 4)
            seed = Seed(seed_bin)

            g.max_seed_splits = ss_count
            splitlist = seed.splitlist(g.max_seed_splits)
            A = splitlist.get_split_by_idx(ss_count).sid
            B = splitlist.get_split_by_seed_id(last_sid).sid
            assert A == last_sid, A
            assert B == last_sid, B

            assert splitlist.nonce_start == 0, splitlist.nonce_start

            collisions = 0
            for sid in splitlist.data['long']:
                collisions += splitlist.data['long'][sid][1]

            assert collisions == collisions_chk, collisions
            vmsg_r('\n{} collisions, last_sid {}'.format(collisions, last_sid))
            msg('OK')
Ejemplo n.º 4
0
		def collisions():
			ss_count,ltr,last_sid,collisions_chk = (
				(SubSeedIdxRange.max_idx,'S','2788F26B',470),
				(49509,'L','8D1FE500',2)
			)[bool(opt.fast)]

			last_idx = str(ss_count) + ltr

			msg_r('Testing Seed ID collisions ({} subseed pairs)...'.format(ss_count))

			seed_bin = bytes.fromhex('12abcdef' * 8)
			seed = Seed(seed_bin)

			seed.gen_subseeds(ss_count)
			ss = seed.subseeds

			assert seed.subseed(last_idx).sid == last_sid, seed.subseed(last_idx).sid

			for sid in ss['long']:
				# msg(sid)
				assert sid not in ss['short']

			collisions = 0
			for k in ('short','long'):
				for sid in ss[k]:
					collisions += ss[k][sid][1]

			assert collisions == collisions_chk, collisions
			msg_r('({} collisions) '.format(collisions))
			msg('OK')
Ejemplo n.º 5
0
		def defaults_and_limits():
			msg_r('Testing defaults and limits...')

			seed_bin = bytes.fromhex('deadbeef' * 8)
			seed = Seed(seed_bin)
			seed.gen_subseeds()
			ss = seed.subseeds
			assert len(ss['short']) == g.subseeds, ss['short']
			assert len(ss['long']) == g.subseeds, ss['long']

			seed = Seed(seed_bin)
			seed.subseed_by_seed_id('EEEEEEEE')
			ss = seed.subseeds
			assert len(ss['short']) == g.subseeds, ss['short']
			assert len(ss['long']) == g.subseeds, ss['long']

			seed = Seed(seed_bin)
			subseed = seed.subseed_by_seed_id('803B165C')
			assert subseed.sid == '803B165C', subseed.sid
			assert subseed.idx == 3, subseed.idx

			seed = Seed(seed_bin)
			subseed = seed.subseed_by_seed_id('803B165C',last_idx=1)
			assert subseed == None, subseed

			r = SubSeedIdxRange('1-5')
			r2 = SubSeedIdxRange(1,5)
			assert r2 == r, r2
			assert r == (r.first,r.last), r
			assert r.first == 1, r.first
			assert r.last == 5, r.last
			assert r.items == [1,2,3,4,5], r.items
			assert list(r.iterate()) == r.items, list(r.iterate())

			r = SubSeedIdxRange('22')
			r2 = SubSeedIdxRange(22,22)
			assert r2 == r, r2
			assert r == (r.first,r.last), r
			assert r.first == 22, r.first
			assert r.last == 22, r.last
			assert r.items == [22], r
			assert list(r.iterate()) == r.items, list(r.iterate())

			r = SubSeedIdxRange('3-3')
			assert r.items == [3], r.items

			r = SubSeedIdxRange('{}-{}'.format(g.subseeds-1,g.subseeds))
			assert r.items == [g.subseeds-1,g.subseeds], r.items

			for n,e in enumerate(SubSeedIdxRange('1-5').iterate(),1):
				assert n == e, e

			assert n == 5, n

			msg('OK')
Ejemplo n.º 6
0
        def defaults_and_limits():
            msg_r('Testing defaults and limits...')

            seed_bin = bytes.fromhex('deadbeef' * 8)
            seed = Seed(seed_bin)

            shares = seed.split(SeedShareIdx.max_val)
            s = shares.format()
            #			vmsg_r('\n{}'.format(s))
            assert len(s.strip().split('\n')) == 1030, s

            A = shares.get_share_by_idx(1024).sid
            B = shares.get_share_by_seed_id('4BA23728').sid
            assert A == '4BA23728', A
            assert B == '4BA23728', B

            A = shares.join().sid
            B = seed.sid
            assert A == B, A

            msg('OK')
Ejemplo n.º 7
0
 def last_share_collisions():
     msg_r('Testing last share collisions with shortened Seed IDs')
     vmsg('')
     seed_bin = bytes.fromhex('2eadbeef' * 8)
     seed = Seed(seed_bin)
     ssm_save = SeedShareIdx.max_val
     ssm = SeedShareIdx.max_val = 2048
     shares = SeedShareList(seed,
                            count=ssm,
                            id_str='foo',
                            master_idx=1,
                            debug_last_share=True)
     lsid = shares.last_share.sid
     collisions = shares.data['long'][lsid][1]
     assert collisions == 2, collisions
     assert lsid == 'B5B8AD09', lsid
     SeedShareIdx.max_val = ssm_save
     vmsg_r('{} collisions, last_share sid {}'.format(collisions, lsid))
     msg('..OK')
Ejemplo n.º 8
0
        def basic_ops(master_idx):
            test_data = {
                'default': (
                    (8, '4710FBF0', 'B3D9411B', '2670E83D', 'D1FC57ED',
                     'AE49CABE', '63FFBA62', 0, 0),
                    (6, '9D07ABBD', 'AF5DC2F6', '1A3BBDAC', '2548AEE9',
                     'B94F7450', '1F4E5A12', 0, 0),
                    (4, '43670520', '1F72C066', 'E5AA8DA1', 'A33966A0',
                     'D2BCE0A5', 'A568C315', 0, 0),
                ),
                'φυβαρ': (
                    (8, '4710FBF0', '269D658C', '9D25889E', '6D730ECB',
                     'C61A963F', '9FE99C05', 0, 0),
                    (6, '9D07ABBD', '4998B33E', 'F00CE041', 'C612BEE5',
                     '35CD3675', '41B3BE61', 0, 0),
                    (4, '43670520', '77140076', 'EA82CB30', '80F7AEDE',
                     'D168D768', '77BE57AA', 0, 0),
                )
            }
            test_data_master = {
                '1': {
                    'default': (
                        (8, '4710FBF0', '6AE6177F', 'AC12090C', '6AE6177F',
                         '3E87A907', '7D1FEA56', 'BFEBFFFF', '629A9808'),
                        (4, '43670520', '6739535C', 'ABF4DD38', '6739535C',
                         '778E9C60', '89CBCFD2', '689FABF5', '70BED76B'),
                    ),
                    'φυβαρ':
                    ((8, '4710FBF0', '6AE6177F', 'AC5FA32E', '6AE6177F',
                      '9777A750', 'C7CF2AFC', '035AAACB', 'C777FBE4'),
                     (4, '43670520', '6739535C', '37EBA2F5', '6739535C',
                      '927549D2', '29BADEE7', '9CA73A03', '313F5528'))
                },
                '5': {
                    'default': (
                        (8, '4710FBF0', '5EFAC3D6', 'B489167D', '5EFAC3D6',
                         'BB004DC5', '1A0381C0', '4EA182E3', '547FB2DC'),
                        (4, '43670520', 'EE93DB0E', '44962A7D', 'EE93DB0E',
                         '07339882', '376A05B1', 'CE51D022', '00149CA3'),
                    ),
                    'φυβαρ':
                    ((8, '4710FBF0', '5EFAC3D6', 'A6E27EE3', '5EFAC3D6',
                      '32C24668', 'B4C54297', '1EC9B71B', '8C5C6B1C'),
                     (4, '43670520', 'EE93DB0E', 'B584E963', 'EE93DB0E',
                      '4BEA2AB2', '4BEA65C7', '140FC43F', 'BBD19461'))
                }
            }
            if master_idx:
                test_data = test_data_master[str(master_idx)]

            for id_str in (None, 'default', 'φυβαρ'):
                msg_r(
                    'Testing basic ops (id_str={!r}, master_idx={})...'.format(
                        id_str, master_idx))
                vmsg('')

                for a, b, c, d, e, f, h, i, p in test_data[
                        id_str if id_str is not None else 'default']:
                    seed_bin = bytes.fromhex('deadbeef' * a)
                    seed = Seed(seed_bin)
                    assert seed.sid == b, seed.sid

                    for share_count, j, k, l, m in ((2, c, c, d, i), (5, e, f,
                                                                      h, p)):

                        shares = seed.split(share_count, id_str, master_idx)
                        A = len(shares)
                        assert A == share_count, A

                        s = shares.format()
                        vmsg_r('\n{}'.format(s))
                        assert len(s.strip().split('\n')) == share_count + 6, s

                        if master_idx:
                            A = shares.get_share_by_idx(1, base_seed=False).sid
                            B = shares.get_share_by_seed_id(
                                j, base_seed=False).sid
                            assert A == B == m, A

                        A = shares.get_share_by_idx(1, base_seed=True).sid
                        B = shares.get_share_by_seed_id(j, base_seed=True).sid
                        assert A == B == j, A

                        A = shares.get_share_by_idx(share_count - 1,
                                                    base_seed=True).sid
                        B = shares.get_share_by_seed_id(k, base_seed=True).sid
                        assert A == B == k, A

                        A = shares.get_share_by_idx(share_count).sid
                        B = shares.get_share_by_seed_id(l).sid
                        assert A == B == l, A

                        A = shares.join().sid
                        assert A == b, A

                        if master_idx:
                            slist = [
                                shares.get_share_by_idx(i + 1, base_seed=True)
                                for i in range(len(shares))
                            ]
                            A = Seed.join_shares(slist, master_idx, id_str).sid
                            assert A == b, A

                msg('OK')
Ejemplo n.º 9
0
		def defaults_and_limits():
			msg_r('Testing defaults and limits...')

			seed_bin = bytes.fromhex('deadbeef' * 8)
			seed = Seed(seed_bin)
			seed.subseeds._generate()
			ss = seed.subseeds
			assert len(ss.data['long']) == len(ss.data['short']), len(ss.data['short'])
			assert len(ss) == g.subseeds, len(ss)

			seed = Seed(seed_bin)
			seed.subseed_by_seed_id('EEEEEEEE')
			ss = seed.subseeds
			assert len(ss.data['long']) == len(ss.data['short']), len(ss.data['short'])
			assert len(ss) == g.subseeds, len(ss)

			seed = Seed(seed_bin)
			subseed = seed.subseed_by_seed_id('803B165C')
			assert len(ss.data['long']) == len(ss.data['short']), len(ss.data['short'])
			assert subseed.sid == '803B165C', subseed.sid
			assert subseed.idx == 3, subseed.idx

			seed = Seed(seed_bin)
			subseed = seed.subseed_by_seed_id('803B165C',last_idx=1)
			assert len(ss.data['long']) == len(ss.data['short']), len(ss.data['short'])
			assert subseed == None, subseed

			r = SubSeedIdxRange('1-5')
			r2 = SubSeedIdxRange(1,5)
			assert r2 == r, r2
			assert r == (r.first,r.last), r
			assert r.first == 1, r.first
			assert r.last == 5, r.last
			assert r.items == [1,2,3,4,5], r.items
			assert list(r.iterate()) == r.items, list(r.iterate())

			r = SubSeedIdxRange('22')
			r2 = SubSeedIdxRange(22,22)
			assert r2 == r, r2
			assert r == (r.first,r.last), r
			assert r.first == 22, r.first
			assert r.last == 22, r.last
			assert r.items == [22], r
			assert list(r.iterate()) == r.items, list(r.iterate())

			r = SubSeedIdxRange('3-3')
			assert r.items == [3], r.items

			r = SubSeedIdxRange('{}-{}'.format(g.subseeds-1,g.subseeds))
			assert r.items == [g.subseeds-1,g.subseeds], r.items

			for n,e in enumerate(SubSeedIdxRange('1-5').iterate(),1):
				assert n == e, e

			assert n == 5, n

			msg('OK')
Ejemplo n.º 10
0
		def basic_ops():
			msg_r('Testing basic ops...')
			for a,b,c,d,e,f,h in (
					(8,'4710FBF0','0C1B0615','803B165C','2669AC64',256,'10L'),
					(6,'9D07ABBD','EBA9C33F','20787E6A','192E2AA2',192,'10L'),
					(4,'43670520','04A4CCB3','B5F21D7B','C1934CFF',128,'10L'),
				):

				seed_bin = bytes.fromhex('deadbeef' * a)
				seed = Seed(seed_bin)
				assert seed.sid == b, seed.sid

				subseed = seed.subseed('2s')
				assert subseed.sid == c, subseed.sid

				subseed = seed.subseed('3')
				assert subseed.sid == d, subseed.sid

				subseed = seed.subseed_by_seed_id(e)
				assert subseed.bitlen == f, subseed.bitlen
				assert subseed.sid == e, subseed.sid
				assert subseed.idx == 10, subseed.idx
				assert subseed.ss_idx == h, subseed.ss_idx

				seed2 = Seed(seed_bin)
				ss2_list = seed2.subseeds

				seed2.subseeds._generate(1)
				assert len(ss2_list) == 1, len(ss2_list)

				seed2.subseeds._generate(1) # do nothing
				seed2.subseeds._generate(2) # append one item

				seed2.subseeds._generate(5)
				assert len(ss2_list) == 5, len(ss2_list)

				seed2.subseeds._generate(3) # do nothing
				assert len(ss2_list) == 5, len(ss2_list)

				seed2.subseeds._generate(10)
				assert len(ss2_list) == 10, len(ss2_list)

				assert seed.ppformat() == seed2.ppformat()

				s = seed.subseeds.format(1,g.subseeds)
				s_lines = s.strip().split('\n')
				assert len(s_lines) == g.subseeds + 4, s

				a = seed.subseed('2L').sid
				b = [e for e in s_lines if ' 2L:' in e][0].strip().split()[1]
				assert a == b, b

				c = seed.subseed('2').sid
				assert c == a, c

				a = seed.subseed('5S').sid
				b = [e for e in s_lines if ' 5S:' in e][0].strip().split()[3]
				assert a == b, b

				s = seed.subseeds.format(g.subseeds+1,g.subseeds+2)
				s_lines = s.strip().split('\n')
				assert len(s_lines) == 6, s

				ss_idx = str(g.subseeds+2) + 'S'
				a = seed.subseed(ss_idx).sid
				b = [e for e in s_lines if ' {}:'.format(ss_idx) in e][0].strip().split()[3]
				assert a == b, b

				s = seed.subseeds.format(1,10)
				s_lines = s.strip().split('\n')
				assert len(s_lines) == 14, s

				vmsg_r('\n{}'.format(s))

			msg('OK')
Ejemplo n.º 11
0
        def basic_ops():
            test_data = {
                'default': (
                    (8, '4710FBF0', 'B3D9411B', '2670E83D', 'D1FC57ED',
                     'AE49CABE', '63FFBA62', 256),
                    (6, '9D07ABBD', 'AF5DC2F6', '1A3BBDAC', '2548AEE9',
                     'B94F7450', '1F4E5A12', 192),
                    (4, '43670520', '1F72C066', 'E5AA8DA1', 'A33966A0',
                     'D2BCE0A5', 'A568C315', 128),
                ),
                'φυβαρ': (
                    (8, '4710FBF0', '269D658C', '9D25889E', '6D730ECB',
                     'C61A963F', '9FE99C05', 256),
                    (6, '9D07ABBD', '4998B33E', 'F00CE041', 'C612BEE5',
                     '35CD3675', '41B3BE61', 192),
                    (4, '43670520', '77140076', 'EA82CB30', '80F7AEDE',
                     'D168D768', '77BE57AA', 128),
                )
            }

            for id_str in (None, 'default', 'φυβαρ'):
                msg_r('Testing basic ops (id_str={!r})...'.format(id_str))
                vmsg('')

                for a, b, c, d, e, f, h, i in test_data[
                        id_str if id_str is not None else 'default']:
                    seed_bin = bytes.fromhex('deadbeef' * a)
                    seed = Seed(seed_bin)
                    assert seed.sid == b, seed.sid

                    splitlist = seed.splitlist(2, id_str)
                    A = len(splitlist)
                    assert A == 2, A

                    s = splitlist.format()
                    vmsg_r('\n{}'.format(s))
                    assert len(s.strip().split('\n')) == 8, s

                    A = splitlist.get_split_by_idx(1).sid
                    B = splitlist.get_split_by_seed_id(c).sid
                    assert A == B == c, A

                    A = splitlist.get_split_by_idx(2).sid
                    B = splitlist.get_split_by_seed_id(d).sid
                    assert A == B == d, A

                    splitlist = seed.splitlist(5, id_str)
                    A = len(splitlist)
                    assert A == 5, A

                    s = splitlist.format()
                    vmsg_r('\n{}'.format(s))
                    assert len(s.strip().split('\n')) == 11, s

                    A = splitlist.get_split_by_idx(1).sid
                    B = splitlist.get_split_by_seed_id(e).sid
                    assert A == B == e, A

                    A = splitlist.get_split_by_idx(4).sid
                    B = splitlist.get_split_by_seed_id(f).sid
                    assert A == B == f, A

                    A = splitlist.get_split_by_idx(5).sid
                    B = splitlist.get_split_by_seed_id(h).sid
                    assert A == B == h, A

                    A = splitlist.join().sid
                    assert A == b, A

                msg('OK')
Ejemplo n.º 12
0
		def basic_ops():
			msg_r('Testing basic ops...')
			for a,b,c,d,e,f,h in (
					(8,'4710FBF0','0C1B0615','803B165C','2669AC64',256,'10L'),
					(6,'9D07ABBD','EBA9C33F','20787E6A','192E2AA2',192,'10L'),
					(4,'43670520','04A4CCB3','B5F21D7B','C1934CFF',128,'10L'),
				):

				seed_bin = bytes.fromhex('deadbeef' * a)
				seed = Seed(seed_bin)
				assert seed.sid == b, seed.sid

				subseed = seed.subseed('2s')
				assert subseed.sid == c, subseed.sid

				subseed = seed.subseed('3')
				assert subseed.sid == d, subseed.sid

				subseed = seed.subseed_by_seed_id(e)
				assert subseed.length == f, subseed.length
				assert subseed.sid == e, subseed.sid
				assert subseed.idx == 10, subseed.idx
				assert subseed.ss_idx == h, subseed.ss_idx

				seed2 = Seed(seed_bin)
				s2s = seed2.subseeds['short']
				s2l = seed2.subseeds['long']

				seed2.gen_subseeds(1)
				assert len(s2s) == 1, len(s2s)

				seed2.gen_subseeds(1) # do nothing
				seed2.gen_subseeds(2) # append one item

				seed2.gen_subseeds(5)
				assert len(s2s) == 5, len(s2s)

				seed2.gen_subseeds(3) # do nothing
				assert len(s2l) == 5, len(s2l)

				seed2.gen_subseeds(10)
				assert len(s2s) == 10, len(s2s)

				assert seed.pformat() == seed2.pformat()

				s = seed.fmt_subseeds(1,g.subseeds)
				s_lines = s.strip().split('\n')
				assert len(s_lines) == g.subseeds + 4, s

				a = seed.subseed('2L').sid
				b = [e for e in s_lines if ' 2L:' in e][0].strip().split()[1]
				assert a == b, b

				c = seed.subseed('2').sid
				assert c == a, c

				a = seed.subseed('5S').sid
				b = [e for e in s_lines if ' 5S:' in e][0].strip().split()[3]
				assert a == b, b

				s = seed.fmt_subseeds(g.subseeds+1,g.subseeds+2)
				s_lines = s.strip().split('\n')
				assert len(s_lines) == 6, s

				ss_idx = str(g.subseeds+2) + 'S'
				a = seed.subseed(ss_idx).sid
				b = [e for e in s_lines if ' {}:'.format(ss_idx) in e][0].strip().split()[3]
				assert a == b, b

				s = seed.fmt_subseeds(1,2)
				s_lines = s.strip().split('\n')
				assert len(s_lines) == 6, s

			msg('OK')