xref: /aosp_15_r20/external/tink/cc/experimental/pqcrypto/kem/cecpq2_aead_hkdf_public_key_manager.h (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2021 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_EXPERIMENTAL_PQCRYPTO_KEM_CECPQ2_AEAD_HKDF_PUBLIC_KEY_MANAGER_H_
17 #define TINK_EXPERIMENTAL_PQCRYPTO_KEM_CECPQ2_AEAD_HKDF_PUBLIC_KEY_MANAGER_H_
18 
19 #include <memory>
20 #include <string>
21 
22 #include "absl/memory/memory.h"
23 #include "absl/strings/str_cat.h"
24 #include "tink/core/key_type_manager.h"
25 #include "tink/experimental/pqcrypto/kem/cecpq2_aead_hkdf_dem_helper.h"
26 #include "tink/experimental/pqcrypto/kem/subtle/cecpq2_aead_hkdf_hybrid_encrypt.h"
27 #include "tink/hybrid_encrypt.h"
28 #include "tink/util/enums.h"
29 #include "tink/util/errors.h"
30 #include "tink/util/protobuf_helper.h"
31 #include "tink/util/status.h"
32 #include "tink/util/statusor.h"
33 #include "proto/experimental/pqcrypto/cecpq2_aead_hkdf.pb.h"
34 #include "proto/tink.pb.h"
35 
36 namespace crypto {
37 namespace tink {
38 
39 class Cecpq2AeadHkdfPublicKeyManager
40     : public KeyTypeManager<google::crypto::tink::Cecpq2AeadHkdfPublicKey, void,
41                             List<HybridEncrypt>> {
42  public:
43   class HybridEncryptFactory : public PrimitiveFactory<HybridEncrypt> {
Create(const google::crypto::tink::Cecpq2AeadHkdfPublicKey & cecpq2_public_key)44     crypto::tink::util::StatusOr<std::unique_ptr<HybridEncrypt>> Create(
45         const google::crypto::tink::Cecpq2AeadHkdfPublicKey& cecpq2_public_key)
46         const override {
47       return Cecpq2AeadHkdfHybridEncrypt::New(cecpq2_public_key);
48     }
49   };
50 
Cecpq2AeadHkdfPublicKeyManager()51   Cecpq2AeadHkdfPublicKeyManager()
52       : KeyTypeManager(absl::make_unique<HybridEncryptFactory>()) {}
53 
get_version()54   uint32_t get_version() const override { return 0; }
55 
key_material_type()56   google::crypto::tink::KeyData::KeyMaterialType key_material_type()
57       const override {
58     return google::crypto::tink::KeyData::ASYMMETRIC_PUBLIC;
59   }
60 
get_key_type()61   const std::string& get_key_type() const override { return key_type_; }
62 
63   crypto::tink::util::Status ValidateKey(
64       const google::crypto::tink::Cecpq2AeadHkdfPublicKey& key) const override;
65 
66   crypto::tink::util::Status ValidateParams(
67       const google::crypto::tink::Cecpq2AeadHkdfParams& params) const;
68 
69  private:
70   const std::string key_type_ = absl::StrCat(
71       "type.googleapis.com/",
72       google::crypto::tink::Cecpq2AeadHkdfPublicKey().GetTypeName());
73 };
74 
75 }  // namespace tink
76 }  // namespace crypto
77 
78 #endif  // TINK_EXPERIMENTAL_PQCRYPTO_KEM_CECPQ2_AEAD_HKDF_PUBLIC_KEY_MANAGER_H_
79