xref: /aosp_15_r20/external/tink/cc/hybrid/internal/hpke_key_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_KEY_BORINGSSL_H_
18 #define TINK_HYBRID_INTERNAL_HPKE_KEY_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/util/statusor.h"
27 #include "proto/hpke.pb.h"
28 
29 namespace crypto {
30 namespace tink {
31 namespace internal {
32 
33 class ABSL_DEPRECATED("Store keys in util::SecretData.") HpkeKeyBoringSsl {
34  public:
35   // Initializes an HPKE recipient private key.  Returns an error if
36   // initialization fails.  Otherwise, returns a unique pointer to the key.
37   //
38   //   `kem`: HPKE KEM parameter.
39   //   `recipient_private_key`: KEM-encoding of recipient private key.
40   static util::StatusOr<std::unique_ptr<HpkeKeyBoringSsl>> New(
41       const google::crypto::tink::HpkeKem& kem,
42       absl::string_view recipient_private_key);
43 
44   // HpkeKeyBoringSsl objects are neither movable, nor copyable.
45   HpkeKeyBoringSsl(HpkeKeyBoringSsl&& other) = delete;
46   HpkeKeyBoringSsl& operator=(HpkeKeyBoringSsl&& other) = delete;
47   HpkeKeyBoringSsl(const HpkeKeyBoringSsl&) = delete;
48   HpkeKeyBoringSsl& operator=(const HpkeKeyBoringSsl&) = delete;
49 
kem()50   const google::crypto::tink::HpkeKem& kem() const { return kem_; }
51 
recipient_private_key()52   const EVP_HPKE_KEY* recipient_private_key() const {
53     return recipient_private_key_.get();
54   }
55 
56  private:
HpkeKeyBoringSsl(const google::crypto::tink::HpkeKem & kem)57   explicit HpkeKeyBoringSsl(const google::crypto::tink::HpkeKem& kem)
58       : kem_(kem) {}
59 
60   util::Status Init(absl::string_view recipient_private_key);
61 
62   google::crypto::tink::HpkeKem kem_;
63   bssl::ScopedEVP_HPKE_KEY recipient_private_key_;
64 };
65 
66 }  // namespace internal
67 }  // namespace tink
68 }  // namespace crypto
69 
70 #endif  // TINK_HYBRID_INTERNAL_HPKE_KEY_BORINGSSL_H_
71