xref: /aosp_15_r20/external/tink/cc/experimental/pqcrypto/kem/subtle/cecpq2_aead_hkdf_hybrid_encrypt.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_ENCRYPT_H_
18 #define TINK_EXPERIMENTAL_PQCRYPTO_KEM_SUBTLE_CECPQ2_AEAD_HKDF_HYBRID_ENCRYPT_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_sender_kem_boringssl.h"
26 #include "tink/experimental/pqcrypto/kem/subtle/cecpq2_subtle_boringssl_util.h"
27 #include "tink/hybrid_encrypt.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 encryption with HKDF-KEM (key encapsulation mechanism) and
35 // AEAD-DEM (data encapsulation mechanism)
36 class Cecpq2AeadHkdfHybridEncrypt : public HybridEncrypt {
37  public:
38   // Returns an HybridEncrypt-primitive that uses the key material
39   // given in 'recipient_key'
40   static crypto::tink::util::StatusOr<std::unique_ptr<HybridEncrypt>> New(
41       const google::crypto::tink::Cecpq2AeadHkdfPublicKey& recipient_key);
42 
43   crypto::tink::util::StatusOr<std::string> Encrypt(
44       absl::string_view plaintext,
45       absl::string_view context_info) const override;
46 
47  private:
Cecpq2AeadHkdfHybridEncrypt(const google::crypto::tink::Cecpq2AeadHkdfPublicKey & recipient_key,std::unique_ptr<const subtle::Cecpq2HkdfSenderKemBoringSsl> sender_kem,std::unique_ptr<const Cecpq2AeadHkdfDemHelper> dem_helper)48   Cecpq2AeadHkdfHybridEncrypt(
49       const google::crypto::tink::Cecpq2AeadHkdfPublicKey& recipient_key,
50       std::unique_ptr<const subtle::Cecpq2HkdfSenderKemBoringSsl> sender_kem,
51       std::unique_ptr<const Cecpq2AeadHkdfDemHelper> dem_helper)
52       : recipient_key_(recipient_key),
53         sender_kem_(std::move(sender_kem)),
54         dem_helper_(std::move(dem_helper)) {}
55 
56   google::crypto::tink::Cecpq2AeadHkdfPublicKey recipient_key_;
57   std::unique_ptr<const subtle::Cecpq2HkdfSenderKemBoringSsl> sender_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_ENCRYPT_H_
65