1# Copyright 2019 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15"""Pre-generated KeyTemplate for DeterministicAead. 16 17One can use these templates to generate a new tink_pb2.Keyset with 18tink_pb2.KeysetHandle. To generate a new keyset that contains a single 19tink_pb2.HmacKey, one can do: 20handle = keyset_handle.KeysetHandle(aead_key_templates.AES128_EAX). 21""" 22 23import warnings 24 25from tink.proto import aes_siv_pb2 26from tink.proto import tink_pb2 27 28 29_AES_SIV_KEY_TYPE_URL = 'type.googleapis.com/google.crypto.tink.AesSivKey' 30 31 32def _create_aes_siv_key_template(key_size: int) -> tink_pb2.KeyTemplate: 33 """Creates an AES EAX KeyTemplate, and fills in its values.""" 34 key_format = aes_siv_pb2.AesSivKeyFormat( 35 key_size=key_size, 36 ) 37 key_template = tink_pb2.KeyTemplate( 38 type_url=_AES_SIV_KEY_TYPE_URL, 39 output_prefix_type=tink_pb2.TINK, 40 value=key_format.SerializeToString(), 41 ) 42 return key_template 43 44 45AES256_SIV = _create_aes_siv_key_template(key_size=64) 46 47 48# Deprecated. Use the predefined constant AES256_SIV instead. 49def create_aes_siv_key_template(key_size: int) -> tink_pb2.KeyTemplate: 50 warnings.warn('The "create_aes_siv_key_template" function is deprecated.', 51 DeprecationWarning, 2) 52 return _create_aes_siv_key_template(key_size) 53