def _test_case(aes_key_size=16,
                iv_size=16,
                hmac_key_size=16,
                hmac_tag_size=16,
                hash_type=common_pb2.SHA256,
                key_version=0,
                aes_ctr_version=0,
                hmac_version=0):
   key = aes_ctr_hmac_aead_pb2.AesCtrHmacAeadKey()
   key.version = key_version
   key.aes_ctr_key.version = aes_ctr_version
   key.aes_ctr_key.params.iv_size = iv_size
   key.aes_ctr_key.key_value = _gen_key_value(aes_key_size)
   key.hmac_key.version = hmac_version
   key.hmac_key.params.tag_size = hmac_tag_size
   key.hmac_key.params.hash = hash_type
   key.hmac_key.key_value = _gen_key_value(hmac_key_size)
   keyset = _gen_keyset(
       'type.googleapis.com/google.crypto.tink.AesCtrHmacAeadKey',
       key.SerializeToString(),
       tink_pb2.KeyData.SYMMETRIC)
   return ('AesCtrHmacAeadKey(%d,%d,%d,%d,%s,%d,%d,%d)' %
           (aes_key_size, iv_size, hmac_key_size, hmac_tag_size,
            common_pb2.HashType.Name(hash_type),
            key_version, aes_ctr_version, hmac_version), keyset)
Пример #2
0
 def test_new_key_data_aes_ctr_hmac_aead(self):
   template = aead.aead_key_templates.create_aes_ctr_hmac_aead_key_template(
       aes_key_size=16,
       iv_size=12,
       hmac_key_size=32,
       tag_size=16,
       hash_type=common_pb2.SHA256)
   key_manager = core.Registry.key_manager(template.type_url)
   key_data = key_manager.new_key_data(template)
   self.assertEqual(key_data.type_url, template.type_url)
   self.assertEqual(key_data.key_material_type, tink_pb2.KeyData.SYMMETRIC)
   key = aes_ctr_hmac_aead_pb2.AesCtrHmacAeadKey()
   key.ParseFromString(key_data.value)
   self.assertEqual(key.version, 0)
   self.assertEqual(key.aes_ctr_key.version, 0)
   self.assertLen(key.aes_ctr_key.key_value, 16)
   self.assertEqual(key.aes_ctr_key.params.iv_size, 12)
   self.assertEqual(key.hmac_key.version, 0)
   self.assertLen(key.hmac_key.key_value, 32)
   self.assertEqual(key.hmac_key.params.tag_size, 16)
   self.assertEqual(key.hmac_key.params.hash, common_pb2.SHA256)