def test_aes256_ctr_hmac_sha256(self): template = aead_key_templates.AES128_CTR_HMAC_SHA256 self.assertEqual('type.googleapis.com/google.crypto.tink.AesCtrHmacAeadKey', template.type_url) self.assertEqual(tink_pb2.TINK, template.output_prefix_type) key_format = aes_ctr_hmac_aead_pb2.AesCtrHmacAeadKeyFormat() key_format.ParseFromString(template.value) self.assertEqual(16, key_format.aes_ctr_key_format.params.iv_size) self.assertEqual(16, key_format.aes_ctr_key_format.key_size) self.assertEqual(common_pb2.SHA256, key_format.hmac_key_format.params.hash) self.assertEqual(16, key_format.hmac_key_format.params.tag_size) self.assertEqual(32, key_format.hmac_key_format.key_size)
def create_aes_ctr_hmac_aead_key_template( aes_key_size: int, iv_size: int, hmac_key_size: int, tag_size: int, hash_type: common_pb2.HashType) -> tink_pb2.KeyTemplate: """Creates an AES CTR HMAC AEAD KeyTemplate, and fills in its values.""" key_format = aes_ctr_hmac_aead_pb2.AesCtrHmacAeadKeyFormat() key_format.aes_ctr_key_format.params.iv_size = iv_size key_format.aes_ctr_key_format.key_size = aes_key_size key_format.hmac_key_format.params.hash = hash_type key_format.hmac_key_format.params.tag_size = tag_size key_format.hmac_key_format.key_size = hmac_key_size key_template = tink_pb2.KeyTemplate() key_template.value = key_format.SerializeToString() key_template.type_url = _AES_CTR_HMAC_AEAD_KEY_TYPE_URL key_template.output_prefix_type = tink_pb2.TINK return key_template
def test_create_aes_ctr_hmac_aead_key_template(self): # Intentionally using 'weird' or invalid values for parameters, # to test that the function correctly puts them in the resulting template. template = aead_key_templates.create_aes_ctr_hmac_aead_key_template( aes_key_size=34, iv_size=93, hmac_key_size=46, tag_size=99, hash_type=common_pb2.SHA1) self.assertEqual('type.googleapis.com/google.crypto.tink.AesCtrHmacAeadKey', template.type_url) self.assertEqual(tink_pb2.TINK, template.output_prefix_type) key_format = aes_ctr_hmac_aead_pb2.AesCtrHmacAeadKeyFormat() key_format.ParseFromString(template.value) self.assertEqual(93, key_format.aes_ctr_key_format.params.iv_size) self.assertEqual(34, key_format.aes_ctr_key_format.key_size) self.assertEqual(common_pb2.SHA1, key_format.hmac_key_format.params.hash) self.assertEqual(99, key_format.hmac_key_format.params.tag_size) self.assertEqual(46, key_format.hmac_key_format.key_size)