xref: /aosp_15_r20/external/tink/cc/hybrid/internal/hpke_decrypt_boringssl.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_HYBRID_INTERNAL_HPKE_DECRYPT_BORINGSSL_H_
18 #define TINK_HYBRID_INTERNAL_HPKE_DECRYPT_BORINGSSL_H_
19 
20 #include <memory>
21 #include <string>
22 #include <utility>
23 
24 #include "absl/base/attributes.h"
25 #include "openssl/hpke.h"
26 #include "tink/hybrid/internal/hpke_key_boringssl.h"
27 #include "tink/util/statusor.h"
28 #include "proto/hpke.pb.h"
29 
30 namespace crypto {
31 namespace tink {
32 namespace internal {
33 
34 class ABSL_DEPRECATED("Use HpkeContext.") HpkeDecryptBoringSsl {
35  public:
36   // Sets up an HPKE recipient context.  Returns an error if initialization
37   // fails.  Otherwise, returns a unique pointer to the recipient context.
38   //
39   //   `params`: HPKE parameters proto (KEM, KDF, and AEAD).
40   //   `hpke_key`: Recipient private key.
41   //   `encapsulated_key`: Encapsulated key.
42   //   `context_info`: Application-specific context for key derivation.
43   static util::StatusOr<std::unique_ptr<HpkeDecryptBoringSsl>> New(
44       const google::crypto::tink::HpkeParams& params,
45       const HpkeKeyBoringSsl& hpke_key, absl::string_view encapsulated_key,
46       absl::string_view context_info);
47 
48   // Performs an AEAD decryption of `ciphertext` with `associated_data`.
49   // Returns an error if decryption fails.  Otherwise, returns the plaintext.
50   util::StatusOr<std::string> Decrypt(absl::string_view ciphertext,
51                                       absl::string_view associated_data);
52 
53  private:
HpkeDecryptBoringSsl()54   HpkeDecryptBoringSsl() {}
55 
56   util::Status Init(const google::crypto::tink::HpkeParams& params,
57                     const HpkeKeyBoringSsl& hpke_key,
58                     absl::string_view encapsulated_key,
59                     absl::string_view context_info);
60 
61   bssl::ScopedEVP_HPKE_CTX recipient_ctx_;
62 };
63 
64 }  // namespace internal
65 }  // namespace tink
66 }  // namespace crypto
67 
68 #endif  // TINK_HYBRID_INTERNAL_HPKE_DECRYPT_BORINGSSL_H_
69