def test_4(self): """test_4 Make sure all client secret are unique""" # random number generator rng = mpin_ZZZ.create_csprng(self.seed) # Generate master secret share rtn, ms1 = mpin_ZZZ.random_generate(rng) self.assertEqual(rtn, 0) s = set() match = 0 for i in range(1, 1000): rand_val = os.urandom(32) hash_mpin_id = mpin_ZZZ.hash_id(HASH_TYPE_MPIN, rand_val) # Generate client secret shares rtn, cs1 = mpin_ZZZ.get_client_secret(ms1, hash_mpin_id) self.assertEqual(rtn, 0) cs1Hex = cs1.encode("hex") if cs1Hex in s: match = 1 self.assertEqual(match, 0) s.add(cs1Hex)
rng = mpin_ZZZ.create_csprng(seed) # Identity mpin_id = "*****@*****.**" # Hash mpin_id hash_mpin_id = mpin_ZZZ.hash_id(HASH_TYPE_MPIN, mpin_id) if DEBUG: print "mpin_id: %s" % mpin_id.encode("hex") print "hash_mpin_id: %s" % hash_mpin_id.encode("hex") mpin_id = mpin_id # Generate master secret for MIRACL and Customer time_func('rtn, ms1 = mpin_ZZZ.random_generate(rng)', nIter) rtn, ms1 = mpin_ZZZ.random_generate(rng) if rtn != 0: print "random_generate(rng) Error %s", rtn rtn, ms2 = mpin_ZZZ.random_generate(rng) if rtn != 0: print "random_generate(rng) Error %s", rtn if DEBUG: print "ms1: %s" % ms1.encode("hex") print "ms2: %s" % ms2.encode("hex") # Generate server secret shares time_func('rtn, ss1 = mpin_ZZZ.get_server_secret(ms1)', nIter) rtn, ss1 = mpin_ZZZ.get_server_secret(ms1) if rtn != 0: print "get_server_secret(ms1) Error %s" % rtn rtn, ss2 = mpin_ZZZ.get_server_secret(ms2)
def test_1(self): """test_1 Good PIN and good token""" PIN1 = 1234 PIN2 = 1234 # random number generator rng = mpin_ZZZ.create_csprng(self.seed) # Generate Client master secret share for MIRACL and Customer rtn, ms1 = mpin_ZZZ.random_generate(rng) self.assertEqual(rtn, 0) rtn, ms2 = mpin_ZZZ.random_generate(rng) self.assertEqual(rtn, 0) # Generate server secret shares rtn, ss1 = mpin_ZZZ.get_server_secret(ms1) self.assertEqual(rtn, 0) rtn, ss2 = mpin_ZZZ.get_server_secret(ms2) self.assertEqual(rtn, 0) # Combine server secret shares rtn, server_secret = mpin_ZZZ.recombine_G2(ss1, ss2) self.assertEqual(rtn, 0) # Generate client secret shares rtn, cs1 = mpin_ZZZ.get_client_secret(ms1, self.hash_mpin_id) self.assertEqual(rtn, 0) rtn, cs2 = mpin_ZZZ.get_client_secret(ms2, self.hash_mpin_id) self.assertEqual(rtn, 0) # Combine client secret shares rtn, client_secret = mpin_ZZZ.recombine_G1(cs1, cs2) self.assertEqual(rtn, 0) # Generate Time Permit shares rtn, tp1 = mpin_ZZZ.get_client_permit( HASH_TYPE_MPIN, self.date, ms1, self.hash_mpin_id) self.assertEqual(rtn, 0) rtn, tp2 = mpin_ZZZ.get_client_permit( HASH_TYPE_MPIN, self.date, ms2, self.hash_mpin_id) self.assertEqual(rtn, 0) # Combine Time Permit shares rtn, time_permit = mpin_ZZZ.recombine_G1(tp1, tp2) self.assertEqual(rtn, 0) # Client extracts PIN from secret to create Token rtn, token = mpin_ZZZ.extract_pin( HASH_TYPE_MPIN, self.mpin_id, PIN1, client_secret) self.assertEqual(rtn, 0) # Client first pass rtn, x, u, ut, sec = mpin_ZZZ.client_1( HASH_TYPE_MPIN, self.date, self.mpin_id, rng, None, PIN2, token, time_permit) self.assertEqual(rtn, 0) # Server calculates H(ID) and H(T|H(ID)) HID, HTID = mpin_ZZZ.server_1(HASH_TYPE_MPIN, self.date, self.mpin_id) # Server generates Random number Y and sends it to Client rtn, y = mpin_ZZZ.random_generate(rng) self.assertEqual(rtn, 0) # Client second pass rtn, v = mpin_ZZZ.client_2(x, y, sec) self.assertEqual(rtn, 0) # Server second pass rtn, E, F = mpin_ZZZ.server_2( self.date, HID, HTID, y, server_secret, u, ut, v, None) self.assertEqual(rtn, 0)