def test_nacl(self): master_secret = 'No, I am your father'.encode() keys_1 = hkdf(master_secret, 5, salt=b'and pepper') keys_2 = hkdf(master_secret, 5, salt=b'and vinegar') for k1, k2 in zip(keys_1, keys_2): self.assertNotEqual(k1, k2, msg='using different salts should result in ' 'different keys')
def test_kdf(self): master_secret = 'No, I am your father'.encode() for num_keys in (1, 10, 50): for key_size in (2, 20): keys = hkdf(master_secret, num_keys, key_size=key_size) self.assertEqual(len(keys), num_keys) for key in keys: self.assertEqual(len(key), key_size)
def test_kdf(self): secret = 'No, I am your father'.encode() for num_keys in (1, 10, 50): for key_size in (2, 20): keys = hkdf(secret, num_keys, key_size=key_size) self.assertEqual(len(keys), num_keys) set_of_keys = set() for key in keys: self.assertEqual(len(key), key_size) set_of_keys.add(key) # Checking that there are no duplicate keys self.assertEqual(num_keys, len(set_of_keys))
def test_wrong_hash_function(self): with self.assertRaises(ValueError): hkdf('foo'.encode('ascii'), 3, hash_algo='obviously_unsupported')