def test_hmac_vectors(self): key1_id = random.randint(1, 0xfffe) key2_id = random.randint(1, 0xfffe) key3_id = random.randint(1, 0xfffe) key4_id = random.randint(1, 0xfffe) caps = CAPABILITY.SIGN_HMAC | CAPABILITY.VERIFY_HMAC for v in self.vectors: key1 = HmacKey.put(self.session, key1_id, 'Test HMAC Vectors 0x%04x' % key1_id, 1, caps, v['key'], ALGORITHM.HMAC_SHA1) key2 = HmacKey.put(self.session, key2_id, 'Test HMAC Vectors 0x%04x' % key2_id, 1, caps, v['key'], ALGORITHM.HMAC_SHA256) key3 = HmacKey.put(self.session, key3_id, 'Test HMAC Vectors 0x%04x' % key3_id, 1, caps, v['key'], ALGORITHM.HMAC_SHA384) key4 = HmacKey.put(self.session, key4_id, 'Test HMAC Vectors 0x%04x' % key4_id, 1, caps, v['key'], ALGORITHM.HMAC_SHA512) self.assertEqual(key1.sign_hmac(v['chal']), v['exp_sha1']) self.assertEqual(key2.sign_hmac(v['chal']), v['exp_sha256']) self.assertEqual(key3.sign_hmac(v['chal']), v['exp_sha384']) self.assertEqual(key4.sign_hmac(v['chal']), v['exp_sha512']) self.assertTrue(key1.verify_hmac(v['exp_sha1'], v['chal'])) self.assertTrue(key2.verify_hmac(v['exp_sha256'], v['chal'])) self.assertTrue(key3.verify_hmac(v['exp_sha384'], v['chal'])) self.assertTrue(key4.verify_hmac(v['exp_sha512'], v['chal'])) key1.delete() key2.delete() key3.delete() key4.delete()
def test_hmac_vectors(session, vector): key1_id = random.randint(1, 0xFFFE) key2_id = random.randint(1, 0xFFFE) key3_id = random.randint(1, 0xFFFE) key4_id = random.randint(1, 0xFFFE) caps = CAPABILITY.SIGN_HMAC | CAPABILITY.VERIFY_HMAC key1 = HmacKey.put( session, key1_id, "Test HMAC Vectors 0x%04x" % key1_id, 1, caps, vector["key"], ALGORITHM.HMAC_SHA1, ) key2 = HmacKey.put( session, key2_id, "Test HMAC Vectors 0x%04x" % key2_id, 1, caps, vector["key"], ALGORITHM.HMAC_SHA256, ) key3 = HmacKey.put( session, key3_id, "Test HMAC Vectors 0x%04x" % key3_id, 1, caps, vector["key"], ALGORITHM.HMAC_SHA384, ) key4 = HmacKey.put( session, key4_id, "Test HMAC Vectors 0x%04x" % key4_id, 1, caps, vector["key"], ALGORITHM.HMAC_SHA512, ) assert key1.sign_hmac(vector["chal"]) == vector["exp_sha1"] assert key2.sign_hmac(vector["chal"]) == vector["exp_sha256"] assert key3.sign_hmac(vector["chal"]) == vector["exp_sha384"] assert key4.sign_hmac(vector["chal"]) == vector["exp_sha512"] assert key1.verify_hmac(vector["exp_sha1"], vector["chal"]) assert key2.verify_hmac(vector["exp_sha256"], vector["chal"]) assert key3.verify_hmac(vector["exp_sha384"], vector["chal"]) assert key4.verify_hmac(vector["exp_sha512"], vector["chal"]) key1.delete() key2.delete() key3.delete() key4.delete()
def test_hmac_vectors(self): key1_id = random.randint(1, 0xFFFE) key2_id = random.randint(1, 0xFFFE) key3_id = random.randint(1, 0xFFFE) key4_id = random.randint(1, 0xFFFE) caps = CAPABILITY.SIGN_HMAC | CAPABILITY.VERIFY_HMAC for v in self.vectors: key1 = HmacKey.put( self.session, key1_id, "Test HMAC Vectors 0x%04x" % key1_id, 1, caps, v["key"], ALGORITHM.HMAC_SHA1, ) key2 = HmacKey.put( self.session, key2_id, "Test HMAC Vectors 0x%04x" % key2_id, 1, caps, v["key"], ALGORITHM.HMAC_SHA256, ) key3 = HmacKey.put( self.session, key3_id, "Test HMAC Vectors 0x%04x" % key3_id, 1, caps, v["key"], ALGORITHM.HMAC_SHA384, ) key4 = HmacKey.put( self.session, key4_id, "Test HMAC Vectors 0x%04x" % key4_id, 1, caps, v["key"], ALGORITHM.HMAC_SHA512, ) self.assertEqual(key1.sign_hmac(v["chal"]), v["exp_sha1"]) self.assertEqual(key2.sign_hmac(v["chal"]), v["exp_sha256"]) self.assertEqual(key3.sign_hmac(v["chal"]), v["exp_sha384"]) self.assertEqual(key4.sign_hmac(v["chal"]), v["exp_sha512"]) self.assertTrue(key1.verify_hmac(v["exp_sha1"], v["chal"])) self.assertTrue(key2.verify_hmac(v["exp_sha256"], v["chal"])) self.assertTrue(key3.verify_hmac(v["exp_sha384"], v["chal"])) self.assertTrue(key4.verify_hmac(v["exp_sha512"], v["chal"])) key1.delete() key2.delete() key3.delete() key4.delete()
def test_hmac_key(hsm, session): obj = HmacKey.put(session, 0, "Test delete HMAC", 1, CAPABILITY.SIGN_HMAC, b"key") _test_delete(hsm, session, obj, CAPABILITY.DELETE_HMAC_KEY)
def test_hmac_key(self): obj = HmacKey.put(self.session, 0, 'Test delete HMAC', 1, CAPABILITY.SIGN_HMAC, b'key') self._test_delete(obj, CAPABILITY.DELETE_HMAC_KEY)