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_DECRYPT_H_ 18 #define TINK_HYBRID_ECIES_AEAD_HKDF_HYBRID_DECRYPT_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_decrypt.h" 26 #include "tink/subtle/ecies_hkdf_recipient_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 decryption with HKDF-KEM (key encapsulation mechanism) and 34 // AEAD-DEM (data encapsulation mechanism). 35 class EciesAeadHkdfHybridDecrypt : public HybridDecrypt { 36 public: 37 // Returns an HybridDecrypt-primitive that uses the key material 38 // given in 'recipient_key'. 39 static crypto::tink::util::StatusOr<std::unique_ptr<HybridDecrypt>> New( 40 const google::crypto::tink::EciesAeadHkdfPrivateKey& recipient_key); 41 42 crypto::tink::util::StatusOr<std::string> Decrypt( 43 absl::string_view ciphertext, 44 absl::string_view context_info) const override; 45 46 private: EciesAeadHkdfHybridDecrypt(google::crypto::tink::EciesAeadHkdfParams recipient_key_params,std::unique_ptr<const subtle::EciesHkdfRecipientKemBoringSsl> kem,std::unique_ptr<const EciesAeadHkdfDemHelper> dem_helper)47 EciesAeadHkdfHybridDecrypt( 48 google::crypto::tink::EciesAeadHkdfParams recipient_key_params, 49 std::unique_ptr<const subtle::EciesHkdfRecipientKemBoringSsl> kem, 50 std::unique_ptr<const EciesAeadHkdfDemHelper> dem_helper) 51 : recipient_key_params_(std::move(recipient_key_params)), 52 recipient_kem_(std::move(kem)), 53 dem_helper_(std::move(dem_helper)) {} 54 55 google::crypto::tink::EciesAeadHkdfParams recipient_key_params_; 56 std::unique_ptr<const subtle::EciesHkdfRecipientKemBoringSsl> recipient_kem_; 57 std::unique_ptr<const EciesAeadHkdfDemHelper> dem_helper_; 58 }; 59 60 } // namespace tink 61 } // namespace crypto 62 63 #endif // TINK_HYBRID_ECIES_AEAD_HKDF_HYBRID_DECRYPT_H_ 64