From 3b8f0a64c2e71d6bfa748b90d214e1f97159a5c1 Mon Sep 17 00:00:00 2001 From: MRXLT Date: Thu, 2 Jul 2020 11:25:22 +0800 Subject: [PATCH] Encryption infer (#25119) * add encrypt api for inference lib --- cmake/generic.cmake | 2 ++ cmake/inference_lib.cmake | 10 +++++++++- paddle/fluid/framework/io/crypto/aes_cipher_test.cc | 2 +- paddle/fluid/framework/io/crypto/cipher.cc | 9 ++++++++- paddle/fluid/framework/io/crypto/cipher.h | 1 - paddle/fluid/framework/io/crypto/cipher_utils.h | 4 +--- paddle/fluid/inference/api/paddle_api.h | 8 +++++--- 7 files changed, 26 insertions(+), 10 deletions(-) diff --git a/cmake/generic.cmake b/cmake/generic.cmake index a47ffa71b6c..69f4ccae884 100644 --- a/cmake/generic.cmake +++ b/cmake/generic.cmake @@ -89,6 +89,8 @@ # including binary directory for generated headers. include_directories(${CMAKE_CURRENT_BINARY_DIR}) +# including io directory for inference lib paddle_api.h +include_directories("${PADDLE_SOURCE_DIR}/paddle/fluid/framework/io") if(NOT APPLE) find_package(Threads REQUIRED) diff --git a/cmake/inference_lib.cmake b/cmake/inference_lib.cmake index 8c2549cc051..6fc81f2387b 100644 --- a/cmake/inference_lib.cmake +++ b/cmake/inference_lib.cmake @@ -107,6 +107,11 @@ function(copy_part_of_thrid_party TARGET DST) SRCS ${GLOG_INCLUDE_DIR} ${GLOG_LIBRARIES} DSTS ${dst_dir} ${dst_dir}/lib) + set(dst_dir "${DST}/third_party/install/cryptopp") + copy(${TARGET} + SRCS ${CRYPTOPP_INCLUDE_DIR} ${CRYPTOPP_LIBRARIES} + DSTS ${dst_dir} ${dst_dir}/lib) + set(dst_dir "${DST}/third_party/install/xxhash") copy(${TARGET} SRCS ${XXHASH_INCLUDE_DIR} ${XXHASH_LIBRARIES} @@ -178,7 +183,10 @@ endif() copy(inference_lib_dist SRCS ${CMAKE_BINARY_DIR}/paddle/fluid/framework/framework.pb.h DSTS ${FLUID_INFERENCE_INSTALL_DIR}/paddle/include/internal) - +copy(inference_lib_dist + SRCS ${CMAKE_BINARY_DIR}/../paddle/fluid/framework/io/crypto/cipher.h + DSTS ${FLUID_INFERENCE_INSTALL_DIR}/paddle/include/crypto/) +include_directories(${CMAKE_BINARY_DIR}/../paddle/fluid/framework/io) # CAPI inference library for only inference set(FLUID_INFERENCE_C_INSTALL_DIR "${CMAKE_BINARY_DIR}/fluid_inference_c_install_dir" CACHE STRING "A path setting CAPI fluid inference shared") diff --git a/paddle/fluid/framework/io/crypto/aes_cipher_test.cc b/paddle/fluid/framework/io/crypto/aes_cipher_test.cc index 3ba55f4f455..393c1bffdd0 100644 --- a/paddle/fluid/framework/io/crypto/aes_cipher_test.cc +++ b/paddle/fluid/framework/io/crypto/aes_cipher_test.cc @@ -18,9 +18,9 @@ limitations under the License. */ #include #include +#include #include #include - #include "paddle/fluid/framework/io/crypto/cipher.h" #include "paddle/fluid/framework/io/crypto/cipher_utils.h" diff --git a/paddle/fluid/framework/io/crypto/cipher.cc b/paddle/fluid/framework/io/crypto/cipher.cc index eca175c020c..c258028e250 100644 --- a/paddle/fluid/framework/io/crypto/cipher.cc +++ b/paddle/fluid/framework/io/crypto/cipher.cc @@ -16,7 +16,9 @@ #include "paddle/fluid/framework/io/crypto/aes_cipher.h" #include "paddle/fluid/framework/io/crypto/cipher_utils.h" #include "paddle/fluid/platform/enforce.h" - +#ifdef ON_INFER +#include "paddle/fluid/inference/api/paddle_api.h" +#endif namespace paddle { namespace framework { @@ -57,4 +59,9 @@ std::shared_ptr CipherFactory::CreateCipher( } } // namespace framework +#ifdef ON_INFER +std::shared_ptr MakeCipher(const std::string& config_file) { + return framework::CipherFactory::CreateCipher(config_file); +} +#endif } // namespace paddle diff --git a/paddle/fluid/framework/io/crypto/cipher.h b/paddle/fluid/framework/io/crypto/cipher.h index 9072cb1180d..fc31653c240 100644 --- a/paddle/fluid/framework/io/crypto/cipher.h +++ b/paddle/fluid/framework/io/crypto/cipher.h @@ -46,6 +46,5 @@ class CipherFactory { CipherFactory() = default; static std::shared_ptr CreateCipher(const std::string& config_file); }; - } // namespace framework } // namespace paddle diff --git a/paddle/fluid/framework/io/crypto/cipher_utils.h b/paddle/fluid/framework/io/crypto/cipher_utils.h index 0533275798f..936f62f6ba6 100644 --- a/paddle/fluid/framework/io/crypto/cipher_utils.h +++ b/paddle/fluid/framework/io/crypto/cipher_utils.h @@ -14,11 +14,9 @@ #pragma once +#include #include #include - -#include "paddle/fluid/platform/enforce.h" - namespace paddle { namespace framework { diff --git a/paddle/fluid/inference/api/paddle_api.h b/paddle/fluid/inference/api/paddle_api.h index d871661497a..bf243bf9a45 100644 --- a/paddle/fluid/inference/api/paddle_api.h +++ b/paddle/fluid/inference/api/paddle_api.h @@ -27,10 +27,10 @@ #include #include #include +#include "crypto/cipher.h" #include "paddle_infer_declare.h" // NOLINT - -/*! \namespace paddle - */ + /*! \namespace paddle + */ namespace paddle { /// \brief Paddle data type. @@ -431,4 +431,6 @@ PD_INFER_DECL std::string get_version(); PD_INFER_DECL std::string UpdateDllFlag(const char* name, const char* value); +PD_INFER_DECL std::shared_ptr MakeCipher( + const std::string& config_file); } // namespace paddle -- GitLab