xref: /aosp_15_r20/external/tink/cc/hybrid/ecies_aead_hkdf_hybrid_encrypt.h (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2017 Google Inc.
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_HYBRID_ECIES_AEAD_HKDF_HYBRID_ENCRYPT_H_
18 #define TINK_HYBRID_ECIES_AEAD_HKDF_HYBRID_ENCRYPT_H_
19 
20 #include <memory>
21 #include <string>
22 #include <utility>
23 
24 #include "tink/hybrid/ecies_aead_hkdf_dem_helper.h"
25 #include "tink/hybrid_encrypt.h"
26 #include "tink/subtle/ecies_hkdf_sender_kem_boringssl.h"
27 #include "tink/util/statusor.h"
28 #include "proto/ecies_aead_hkdf.pb.h"
29 
30 namespace crypto {
31 namespace tink {
32 
33 // ECIES encryption with HKDF-KEM (key encapsulation mechanism) and
34 // AEAD-DEM (data encapsulation mechanism).
35 class EciesAeadHkdfHybridEncrypt : public HybridEncrypt {
36  public:
37   // Returns an HybridEncrypt-primitive that uses the key material
38   // given in 'recipient_key'.
39   static crypto::tink::util::StatusOr<std::unique_ptr<HybridEncrypt>> New(
40       const google::crypto::tink::EciesAeadHkdfPublicKey& recipient_key);
41 
42   crypto::tink::util::StatusOr<std::string> Encrypt(
43       absl::string_view plaintext,
44       absl::string_view context_info) const override;
45 
46  private:
EciesAeadHkdfHybridEncrypt(const google::crypto::tink::EciesAeadHkdfPublicKey & recipient_key,std::unique_ptr<const subtle::EciesHkdfSenderKemBoringSsl> sender_kem,std::unique_ptr<const EciesAeadHkdfDemHelper> dem_helper)47   EciesAeadHkdfHybridEncrypt(
48       const google::crypto::tink::EciesAeadHkdfPublicKey& recipient_key,
49       std::unique_ptr<const subtle::EciesHkdfSenderKemBoringSsl> sender_kem,
50       std::unique_ptr<const EciesAeadHkdfDemHelper> dem_helper)
51       : recipient_key_(recipient_key), sender_kem_(std::move(sender_kem)),
52         dem_helper_(std::move(dem_helper)) {}
53 
54   google::crypto::tink::EciesAeadHkdfPublicKey recipient_key_;
55   std::unique_ptr<const subtle::EciesHkdfSenderKemBoringSsl> sender_kem_;
56   std::unique_ptr<const EciesAeadHkdfDemHelper> dem_helper_;
57 };
58 
59 }  // namespace tink
60 }  // namespace crypto
61 
62 #endif  // TINK_HYBRID_ECIES_AEAD_HKDF_HYBRID_ENCRYPT_H_
63