def testFragmentedBackup(self): self.subtestAllFragmentedBackups(SECRET, 2, 3) self.subtestAllFragmentedBackups(SECRET, 2, 3) self.subtestAllFragmentedBackups(SECRET, 3, 4) self.subtestAllFragmentedBackups(SECRET, 5, 7) self.subtestAllFragmentedBackups(SECRET, 8, 8) self.subtestAllFragmentedBackups(SECRET, 2, 12) # Secret Too big test self.assertRaises(FiniteFieldError, SplitSecret, BAD_SECRET, 2, 3) # More needed than pieces self.assertRaises(FiniteFieldError, SplitSecret, SECRET, 4, 3) # Secret Too many needed needed self.assertRaises(FiniteFieldError, SplitSecret, SECRET, 9, 12) # Too few pieces needed self.assertRaises(FiniteFieldError, SplitSecret, SECRET, 1, 12) # Test Reconstuction failures fragmentList = SplitSecret(SECRET, 3, 5) reconSecret = ReconstructSecret(fragmentList[:2], 2, len(SECRET)) self.assertNotEqual(reconSecret, SECRET) # Running tests with "python <module name>" will NOT work for any Armory tests # You must run tests with "python -m unittest <module name>" or run all tests with "python -m unittest discover" # if __name__ == "__main__": # unittest.main()
def testFragmentedBackup(self): self.subtestAllFragmentedBackups(SECRET, 2, 3) self.subtestAllFragmentedBackups(SECRET, 2, 3) self.subtestAllFragmentedBackups(SECRET, 3, 4) self.subtestAllFragmentedBackups(SECRET, 5, 7) self.subtestAllFragmentedBackups(SECRET, 8, 8) self.subtestAllFragmentedBackups(SECRET, 2, 12) # Secret Too big test self.assertRaises(FiniteFieldError, SplitSecret, BAD_SECRET, 2, 3) # More needed than pieces self.assertRaises(FiniteFieldError, SplitSecret, SECRET, 4, 3) # Secret Too many needed needed self.assertRaises(FiniteFieldError, SplitSecret, SECRET, 9, 12) # Too few pieces needed self.assertRaises(FiniteFieldError, SplitSecret, SECRET, 1, 12) # Test Reconstuction failures fragmentList = SplitSecret(SECRET, 3, 5) reconSecret = ReconstructSecret(fragmentList[:2], 2, len(SECRET)) self.assertNotEqual(reconSecret, SECRET)
def callSplitSecret(self, secretHex, M, N, nbytes=1): secret = hex_to_binary(secretHex) print '\nSplitting secret into %d-of-%d: secret=%s' % (M,N,secretHex) tstart = RightNow() out = SplitSecret(secret, M, N) tsplit = RightNow() - tstart print 'Fragments:' for i in range(len(out)): x = binary_to_hex(out[i][0]) y = binary_to_hex(out[i][1]) print ' Fragment %d: [%s, %s]' % (i+1,x,y) trecon = 0 print 'Reconstructing secret from various subsets of fragments...' for i in range(10): shuffle(out) tstart = RightNow() reconstruct = ReconstructSecret(out, M, nbytes) trecon += RightNow() - tstart print ' The reconstructed secret is:', binary_to_hex(reconstruct) self.assertEqual(binary_to_hex(reconstruct), secretHex) print 'Splitting secret took: %0.5f sec' % tsplit print 'Reconstructing takes: %0.5f sec' % (trecon/10) # Running tests with "python <module name>" will NOT work for any Armory tests # You must run tests with "python -m unittest <module name>" or run all tests with "python -m unittest discover" # if __name__ == "__main__": # unittest.main()
def callSplitSecret(self, secretHex, M, N, nbytes=1): secret = hex_to_binary(secretHex) print '\nSplitting secret into %d-of-%d: secret=%s' % (M,N,secretHex) tstart = RightNow() out = SplitSecret(secret, M, N) tsplit = RightNow() - tstart print 'Fragments:' for i in range(len(out)): x = binary_to_hex(out[i][0]) y = binary_to_hex(out[i][1]) print ' Fragment %d: [%s, %s]' % (i+1,x,y) trecon = 0 print 'Reconstructing secret from various subsets of fragments...' for i in range(10): shuffle(out) tstart = RightNow() reconstruct = ReconstructSecret(out, M, nbytes) trecon += RightNow() - tstart print ' The reconstructed secret is:', binary_to_hex(reconstruct) self.assertEqual(binary_to_hex(reconstruct), secretHex) print 'Splitting secret took: %0.5f sec' % tsplit print 'Reconstructing takes: %0.5f sec' % (trecon/10)
def subtestAllFragmentedBackups(self, secret, m, n): fragmentMap = splitSecretToFragmentMap(SplitSecret(secret, m, n)) for combinationMap in self.getNextCombination(fragmentMap, m): fragmentList = [value for value in combinationMap.itervalues()] reconSecret = ReconstructSecret(fragmentList, m, len(secret)) self.assertEqual(reconSecret, secret)