xref: /aosp_15_r20/external/tink/cc/experimental/pqcrypto/kem/subtle/cecpq2_aead_hkdf_hybrid_decrypt.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 
17 #ifndef TINK_EXPERIMENTAL_PQCRYPTO_KEM_SUBTLE_CECPQ2_AEAD_HKDF_HYBRID_DECRYPT_H_
18 #define TINK_EXPERIMENTAL_PQCRYPTO_KEM_SUBTLE_CECPQ2_AEAD_HKDF_HYBRID_DECRYPT_H_
19 
20 #include <memory>
21 #include <string>
22 #include <utility>
23 
24 #include "tink/experimental/pqcrypto/kem/cecpq2_aead_hkdf_dem_helper.h"
25 #include "tink/experimental/pqcrypto/kem/subtle/cecpq2_hkdf_recipient_kem_boringssl.h"
26 #include "tink/experimental/pqcrypto/kem/subtle/cecpq2_subtle_boringssl_util.h"
27 #include "tink/hybrid_decrypt.h"
28 #include "tink/util/statusor.h"
29 #include "proto/experimental/pqcrypto/cecpq2_aead_hkdf.pb.h"
30 
31 namespace crypto {
32 namespace tink {
33 
34 // CECPQ2 decryption with HKDF-KEM (key encapsulation mechanism) and
35 // AEAD-DEM (data encapsulation mechanism)
36 class Cecpq2AeadHkdfHybridDecrypt : public HybridDecrypt {
37  public:
38   // Returns an HybridDecrypt-primitive that uses the key material
39   // given in 'recipient_key'
40   static crypto::tink::util::StatusOr<std::unique_ptr<HybridDecrypt>> New(
41       const google::crypto::tink::Cecpq2AeadHkdfPrivateKey& private_key);
42 
43   crypto::tink::util::StatusOr<std::string> Decrypt(
44       absl::string_view ciphertext,
45       absl::string_view context_info) const override;
46 
47  private:
Cecpq2AeadHkdfHybridDecrypt(const google::crypto::tink::Cecpq2AeadHkdfParams & recipient_key_params,std::unique_ptr<const subtle::Cecpq2HkdfRecipientKemBoringSsl> kem,std::unique_ptr<const Cecpq2AeadHkdfDemHelper> dem_helper)48   Cecpq2AeadHkdfHybridDecrypt(
49       const google::crypto::tink::Cecpq2AeadHkdfParams& recipient_key_params,
50       std::unique_ptr<const subtle::Cecpq2HkdfRecipientKemBoringSsl> kem,
51       std::unique_ptr<const Cecpq2AeadHkdfDemHelper> dem_helper)
52       : recipient_key_params_(recipient_key_params),
53         recipient_kem_(std::move(kem)),
54         dem_helper_(std::move(dem_helper)) {}
55 
56   google::crypto::tink::Cecpq2AeadHkdfParams recipient_key_params_;
57   std::unique_ptr<const subtle::Cecpq2HkdfRecipientKemBoringSsl> recipient_kem_;
58   std::unique_ptr<const Cecpq2AeadHkdfDemHelper> dem_helper_;
59 };
60 
61 }  // namespace tink
62 }  // namespace crypto
63 
64 #endif  // TINK_EXPERIMENTAL_PQCRYPTO_KEM_SUBTLE_CECPQ2_AEAD_HKDF_HYBRID_DECRYPT_H_
65