Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
AES256_GCM = create_aes_gcm_key_template(key_size=32)
AES128_CTR_HMAC_SHA256 = create_aes_ctr_hmac_aead_key_template(
aes_key_size=16,
iv_size=16,
hmac_key_size=32,
tag_size=16,
hash_type=common_pb2.SHA256)
AES256_CTR_HMAC_SHA256 = create_aes_ctr_hmac_aead_key_template(
aes_key_size=32,
iv_size=16,
hmac_key_size=32,
tag_size=32,
hash_type=common_pb2.SHA256)
XCHACHA20_POLY1305 = tink_pb2.KeyTemplate(
type_url=_XCHACHA20_POLY1305_KEY_TYPE_URL,
output_prefix_type=tink_pb2.TINK)
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
curve_type: common_pb2.EllipticCurveType,
ec_point_format: common_pb2.EcPointFormat,
hash_type: common_pb2.HashType,
dem_key_template: tink_pb2.KeyTemplate) -> tink_pb2.KeyTemplate:
"""Creates a HMAC KeyTemplate, and fills in its values."""
key_format = ecies_aead_hkdf_pb2.EciesAeadHkdfKeyFormat()
key_format.params.kem_params.curve_type = curve_type
key_format.params.kem_params.hkdf_hash_type = hash_type
key_format.params.dem_params.aead_dem.CopyFrom(dem_key_template)
key_format.params.ec_point_format = ec_point_format
key_template = tink_pb2.KeyTemplate()
key_template.type_url = (
'type.googleapis.com/google.crypto.tink.EciesAeadHkdfPrivateKey')
key_template.value = key_format.SerializeToString()
key_template.output_prefix_type = tink_pb2.TINK
return key_template
def create_aes_gcm_key_template(key_size: int) -> tink_pb2.KeyTemplate:
"""Creates an AES GCM KeyTemplate, and fills in its values."""
key_format = aes_gcm_pb2.AesGcmKeyFormat()
key_format.key_size = key_size
key_template = tink_pb2.KeyTemplate()
key_template.value = key_format.SerializeToString()
key_template.type_url = _AES_GCM_KEY_TYPE_URL
key_template.output_prefix_type = tink_pb2.TINK
return key_template
def create_ecdsa_key_template(hash_type: common_pb2.HashType,
curve: common_pb2.EllipticCurveType,
encoding: ecdsa_pb2.EcdsaSignatureEncoding
) -> tink_pb2.KeyTemplate:
"""Creates a KeyTemplate containing an EcdsaKeyFormat."""
params = ecdsa_pb2.EcdsaParams(
hash_type=hash_type, curve=curve, encoding=encoding)
key_format = ecdsa_pb2.EcdsaKeyFormat(params=params)
key_template = tink_pb2.KeyTemplate(
value=key_format.SerializeToString(),
type_url=_ECDSA_KEY_TYPE_URL,
output_prefix_type=tink_pb2.TINK)
return key_template
def create_aes_siv_key_template(key_size: int) -> tink_pb2.KeyTemplate:
"""Creates an AES EAX KeyTemplate, and fills in its values."""
key_format = aes_siv_pb2.AesSivKeyFormat()
key_format.key_size = key_size
key_template = tink_pb2.KeyTemplate()
key_template.type_url = _AES_SIV_KEY_TYPE_URL
key_template.output_prefix_type = tink_pb2.TINK
key_template.value = key_format.SerializeToString()
return key_template