xref: /aosp_15_r20/external/tink/cc/aead/aes_ctr_hmac_aead_key_manager.h (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2017 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 ///////////////////////////////////////////////////////////////////////////////
16 #ifndef TINK_AEAD_AES_CTR_HMAC_AEAD_KEY_MANAGER_H_
17 #define TINK_AEAD_AES_CTR_HMAC_AEAD_KEY_MANAGER_H_
18 
19 #include <stdint.h>
20 
21 #include <memory>
22 #include <string>
23 
24 #include "absl/memory/memory.h"
25 #include "absl/strings/str_cat.h"
26 #include "tink/aead.h"
27 #include "tink/core/key_type_manager.h"
28 #include "tink/core/template_util.h"
29 #include "tink/internal/fips_utils.h"
30 #include "tink/util/constants.h"
31 #include "tink/util/status.h"
32 #include "tink/util/statusor.h"
33 #include "proto/aes_ctr_hmac_aead.pb.h"
34 #include "proto/tink.pb.h"
35 
36 namespace crypto {
37 namespace tink {
38 
39 class AesCtrHmacAeadKeyManager
40     : public KeyTypeManager<google::crypto::tink::AesCtrHmacAeadKey,
41                             google::crypto::tink::AesCtrHmacAeadKeyFormat,
42                             List<Aead>> {
43  public:
44   class AeadFactory : public PrimitiveFactory<Aead> {
45     crypto::tink::util::StatusOr<std::unique_ptr<Aead>> Create(
46         const google::crypto::tink::AesCtrHmacAeadKey& key) const override;
47   };
48 
AesCtrHmacAeadKeyManager()49   AesCtrHmacAeadKeyManager()
50       : KeyTypeManager(absl::make_unique<AeadFactory>()) {}
51 
get_version()52   uint32_t get_version() const override { return 0; }
53 
key_material_type()54   google::crypto::tink::KeyData::KeyMaterialType key_material_type()
55       const override {
56     return google::crypto::tink::KeyData::SYMMETRIC;
57   }
58 
get_key_type()59   const std::string& get_key_type() const override { return key_type_; }
60 
61   crypto::tink::util::Status ValidateKey(
62       const google::crypto::tink::AesCtrHmacAeadKey& key) const override;
63   crypto::tink::util::Status ValidateKeyFormat(
64       const google::crypto::tink::AesCtrHmacAeadKeyFormat& key) const override;
65 
66   crypto::tink::util::StatusOr<google::crypto::tink::AesCtrHmacAeadKey>
67   CreateKey(const google::crypto::tink::AesCtrHmacAeadKeyFormat& key_format)
68       const override;
69 
70   crypto::tink::util::StatusOr<google::crypto::tink::AesCtrHmacAeadKey>
71   DeriveKey(const google::crypto::tink::AesCtrHmacAeadKeyFormat& key_format,
72             InputStream* input_stream) const override;
73 
FipsStatus()74   internal::FipsCompatibility FipsStatus() const override {
75     return internal::FipsCompatibility::kRequiresBoringCrypto;
76   }
77 
78  private:
79   const std::string key_type_ =
80       absl::StrCat(kTypeGoogleapisCom,
81                    google::crypto::tink::AesCtrHmacAeadKey().GetTypeName());
82 };
83 
84 }  // namespace tink
85 }  // namespace crypto
86 
87 #endif  // TINK_AEAD_AES_CTR_HMAC_AEAD_KEY_MANAGER_H_
88