Esempio n. 1
0
 def new_hmac_key_template(self, hash_type, tag_size, key_size):
   key_format = hmac_pb2.HmacKeyFormat()
   key_format.params.hash = hash_type
   key_format.params.tag_size = tag_size
   key_format.key_size = key_size
   key_template = tink_pb2.KeyTemplate()
   key_template.type_url = 'type.googleapis.com/google.crypto.tink.HmacKey'
   key_template.value = key_format.SerializeToString()
   return key_template.SerializeToString()
Esempio n. 2
0
 def test_hmac_sha512_512bittag(self):
     template = mac_key_templates.HMAC_SHA512_512BITTAG
     self.assertEqual('type.googleapis.com/google.crypto.tink.HmacKey',
                      template.type_url)
     self.assertEqual(tink_pb2.TINK, template.output_prefix_type)
     key_format = hmac_pb2.HmacKeyFormat()
     key_format.ParseFromString(template.value)
     self.assertEqual(64, key_format.key_size)
     self.assertEqual(64, key_format.params.tag_size)
     self.assertEqual(common_pb2.SHA512, key_format.params.hash)
Esempio n. 3
0
def _create_hmac_key_template(
        key_size: int, tag_size: int,
        hash_type: common_pb2.HashType) -> tink_pb2.KeyTemplate:
    """Creates a HMAC KeyTemplate, and fills in its values."""
    key_format = hmac_pb2.HmacKeyFormat()
    key_format.params.hash = hash_type
    key_format.params.tag_size = tag_size
    key_format.key_size = key_size
    key_template = tink_pb2.KeyTemplate()
    key_template.value = key_format.SerializeToString()
    key_template.type_url = 'type.googleapis.com/google.crypto.tink.HmacKey'
    key_template.output_prefix_type = tink_pb2.TINK
    return key_template
Esempio n. 4
0
 def test_create_hmac_key_template(self):
     # Intentionally using "weird" or invalid values for parameters,
     # to test that the function correctly puts them in the resulting template.
     template = mac.mac_key_templates.create_hmac_key_template(
         key_size=42, tag_size=24, hash_type=common_pb2.SHA512)
     self.assertEqual('type.googleapis.com/google.crypto.tink.HmacKey',
                      template.type_url)
     self.assertEqual(tink_pb2.TINK, template.output_prefix_type)
     key_format = hmac_pb2.HmacKeyFormat()
     key_format.ParseFromString(template.value)
     self.assertEqual(42, key_format.key_size)
     self.assertEqual(24, key_format.params.tag_size)
     self.assertEqual(common_pb2.SHA512, key_format.params.hash)