xref: /aosp_15_r20/external/tink/cc/mac/mac_key_templates.h (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2018 Google Inc.
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 ///////////////////////////////////////////////////////////////////////////////
16 
17 #ifndef TINK_MAC_MAC_KEY_TEMPLATES_H_
18 #define TINK_MAC_MAC_KEY_TEMPLATES_H_
19 
20 #include "proto/tink.pb.h"
21 
22 namespace crypto {
23 namespace tink {
24 
25 ///////////////////////////////////////////////////////////////////////////////
26 // Pre-generated KeyTemplate for Mac key types. One can use these templates
27 // to generate a new KeysetHandle object with fresh keys.
28 // To generate a new keyset that contains a single HmacKey, one can do:
29 //
30 //   auto status = MacConfig::Register();
31 //   if (!status.ok()) { /* fail with error */ }
32 //   auto handle_result =
33 //       KeysetHandle::GenerateNew(MacKeyTemplates::HmacSha256HalfSizeTag());
34 //   if (!handle_result.ok()) { /* fail with error */ }
35 //   auto keyset_handle = std::move(handle_result.value());
36 class MacKeyTemplates {
37  public:
38   // Returns a KeyTemplate that generates new instances of HmacKey
39   // with the following parameters:
40   //   - key size: 32 bytes
41   //   - tag size: 16 bytes
42   //   - hash function: SHA256
43   //   - OutputPrefixType: TINK
44   static const google::crypto::tink::KeyTemplate& HmacSha256HalfSizeTag();
45 
46   // Returns a KeyTemplate that generates new instances of HmacKey
47   // with the following parameters:
48   //   - key size: 32 bytes
49   //   - tag size: 32 bytes
50   //   - hash function: SHA256
51   //   - OutputPrefixType: TINK
52   static const google::crypto::tink::KeyTemplate& HmacSha256();
53 
54   // Returns a KeyTemplate that generates new instances of HmacKey
55   // with the following parameters:
56   //   - key size: 64 bytes
57   //   - tag size: 32 bytes
58   //   - hash function: SHA512
59   //   - OutputPrefixType: TINK
60   static const google::crypto::tink::KeyTemplate& HmacSha512HalfSizeTag();
61 
62   // Returns a KeyTemplate that generates new instances of HmacKey
63   // with the following parameters:
64   //   - key size: 64 bytes
65   //   - tag size: 64 bytes
66   //   - hash function: SHA512
67   //   - OutputPrefixType: TINK
68   static const google::crypto::tink::KeyTemplate& HmacSha512();
69 
70   // Returns a KeyTemplate that generates new instances of AesCmacKey
71   // with the following parameters:
72   //   - key size: 32 bytes
73   //   - tag size: 16 bytes
74   //   - OutputPrefixType: TINK
75   static const google::crypto::tink::KeyTemplate& AesCmac();
76 };
77 
78 }  // namespace tink
79 }  // namespace crypto
80 
81 #endif  // TINK_MAC_MAC_KEY_TEMPLATES_H_
82