xref: /aosp_15_r20/external/tink/cc/experimental/pqcrypto/kem/cecpq2_aead_hkdf_private_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_PRIVATE_KEY_MANAGER_H_
17 #define TINK_EXPERIMENTAL_PQCRYPTO_KEM_CECPQ2_AEAD_HKDF_PRIVATE_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 "openssl/hrss.h"
25 #include "tink/core/key_type_manager.h"
26 #include "tink/core/private_key_type_manager.h"
27 #include "tink/experimental/pqcrypto/kem/cecpq2_aead_hkdf_dem_helper.h"
28 #include "tink/experimental/pqcrypto/kem/subtle/cecpq2_aead_hkdf_hybrid_decrypt.h"
29 #include "tink/hybrid_decrypt.h"
30 #include "tink/util/enums.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 Cecpq2AeadHkdfPrivateKeyManager
40     : public PrivateKeyTypeManager<
41           google::crypto::tink::Cecpq2AeadHkdfPrivateKey,
42           google::crypto::tink::Cecpq2AeadHkdfKeyFormat,
43           google::crypto::tink::Cecpq2AeadHkdfPublicKey, List<HybridDecrypt>> {
44  public:
45   class HybridDecryptFactory : public PrimitiveFactory<HybridDecrypt> {
Create(const google::crypto::tink::Cecpq2AeadHkdfPrivateKey & cecpq2_private_key)46     crypto::tink::util::StatusOr<std::unique_ptr<HybridDecrypt>> Create(
47         const google::crypto::tink::Cecpq2AeadHkdfPrivateKey&
48             cecpq2_private_key) const override {
49       return Cecpq2AeadHkdfHybridDecrypt::New(cecpq2_private_key);
50     }
51   };
52 
Cecpq2AeadHkdfPrivateKeyManager()53   Cecpq2AeadHkdfPrivateKeyManager()
54       : PrivateKeyTypeManager(absl::make_unique<HybridDecryptFactory>()) {}
55 
get_version()56   uint32_t get_version() const override { return 0; }
57 
key_material_type()58   google::crypto::tink::KeyData::KeyMaterialType key_material_type()
59       const override {
60     return google::crypto::tink::KeyData::ASYMMETRIC_PRIVATE;
61   }
62 
get_key_type()63   const std::string& get_key_type() const override { return key_type_; }
64 
65   crypto::tink::util::Status ValidateKey(
66       const google::crypto::tink::Cecpq2AeadHkdfPrivateKey& key) const override;
67 
68   crypto::tink::util::Status ValidateKeyFormat(
69       const google::crypto::tink::Cecpq2AeadHkdfKeyFormat& cecpq2_key_format)
70       const override;
71 
72   crypto::tink::util::StatusOr<google::crypto::tink::Cecpq2AeadHkdfPrivateKey>
73   CreateKey(const google::crypto::tink::Cecpq2AeadHkdfKeyFormat& key_format)
74       const override;
75 
76   crypto::tink::util::StatusOr<google::crypto::tink::Cecpq2AeadHkdfPublicKey>
77   GetPublicKey(const google::crypto::tink::Cecpq2AeadHkdfPrivateKey&
78                    private_key) const override;
79 
80  private:
81   const std::string key_type_ = absl::StrCat(
82       "type.googleapis.com/",
83       google::crypto::tink::Cecpq2AeadHkdfPrivateKey().GetTypeName());
84 };
85 
86 }  // namespace tink
87 }  // namespace crypto
88 
89 #endif  // TINK_EXPERIMENTAL_PQCRYPTO_KEM_CECPQ2_AEAD_HKDF_PRIVATE_KEY_MANAGER_H_
90