未验证 提交 62b4ff7d 编写于 作者: Y Yanghello 提交者: GitHub

Aes_cipher_test and cipher_utils_test failed fixed (#24816)

上级 b490e41c
......@@ -88,7 +88,7 @@ option(WITH_DGC "Use DGC(Deep Gradient Compression) or not" ${WITH_DISTRIBUTE}
option(SANITIZER_TYPE "Choose the type of sanitizer, options are: Address, Leak, Memory, Thread, Undefined" OFF)
option(WITH_LITE "Compile Paddle Fluid with Lite Engine" OFF)
option(WITH_NCCL "Compile PaddlePaddle with NCCL support" ON)
option(WITH_CRYPTO "Compile PaddlePaddle with crypto support" OFF)
option(WITH_CRYPTO "Compile PaddlePaddle with crypto support" ON)
# PY_VERSION
if(NOT PY_VERSION)
......
......@@ -68,7 +68,8 @@ ExternalProject_Add(
SOURCE_DIR ${CRYPTOPP_SOURCE_DIR}
PATCH_COMMAND
COMMAND ${CMAKE_COMMAND} -E remove_directory "<SOURCE_DIR>/cmake/"
COMMAND git clone -b ${CRYPTOPP_TAG} https://github.com/noloader/cryptopp-cmake "<SOURCE_DIR>/cmake"
COMMAND git clone https://github.com/noloader/cryptopp-cmake "<SOURCE_DIR>/cmake"
COMMAND cd "<SOURCE_DIR>/cmake" && git checkout tags/${CRYPTOPP_TAG} -b ${CRYPTOPP_TAG}
COMMAND ${CMAKE_COMMAND} -E copy_directory "<SOURCE_DIR>/cmake/" "<SOURCE_DIR>/"
INSTALL_DIR ${CRYPTOPP_INSTALL_DIR}
CMAKE_ARGS ${CRYPTOPP_CMAKE_ARGS}
......
......@@ -60,7 +60,6 @@ std::string AESCipher::EncryptInternal(const std::string& plaintext,
CryptoPP::member_ptr<CryptoPP::SymmetricCipher> m_cipher;
CryptoPP::member_ptr<CryptoPP::StreamTransformationFilter> m_filter;
bool need_iv = false;
std::string iv = "";
const unsigned char* key_char =
reinterpret_cast<const unsigned char*>(&(key.at(0)));
BuildCipher(true, &need_iv, &m_cipher, &m_filter);
......@@ -77,7 +76,7 @@ std::string AESCipher::EncryptInternal(const std::string& plaintext,
m_filter->Attach(new CryptoPP::StringSink(ciphertext));
CryptoPP::StringSource(plaintext, true, new CryptoPP::Redirector(*m_filter));
if (need_iv) {
ciphertext = iv_.append(ciphertext);
return iv_ + ciphertext;
}
return ciphertext;
......@@ -88,7 +87,6 @@ std::string AESCipher::DecryptInternal(const std::string& ciphertext,
CryptoPP::member_ptr<CryptoPP::SymmetricCipher> m_cipher;
CryptoPP::member_ptr<CryptoPP::StreamTransformationFilter> m_filter;
bool need_iv = false;
std::string iv = "";
const unsigned char* key_char =
reinterpret_cast<const unsigned char*>(&(key.at(0)));
BuildCipher(false, &need_iv, &m_cipher, &m_filter);
......@@ -115,7 +113,6 @@ std::string AESCipher::AuthenticatedEncryptInternal(
CryptoPP::member_ptr<CryptoPP::AuthenticatedSymmetricCipher> m_cipher;
CryptoPP::member_ptr<CryptoPP::AuthenticatedEncryptionFilter> m_filter;
bool need_iv = false;
std::string iv = "";
const unsigned char* key_char =
reinterpret_cast<const unsigned char*>(&(key.at(0)));
BuildAuthEncCipher(&need_iv, &m_cipher, &m_filter);
......@@ -143,7 +140,6 @@ std::string AESCipher::AuthenticatedDecryptInternal(
CryptoPP::member_ptr<CryptoPP::AuthenticatedSymmetricCipher> m_cipher;
CryptoPP::member_ptr<CryptoPP::AuthenticatedDecryptionFilter> m_filter;
bool need_iv = false;
std::string iv = "";
const unsigned char* key_char =
reinterpret_cast<const unsigned char*>(&(key.at(0)));
BuildAuthDecCipher(&need_iv, &m_cipher, &m_filter);
......@@ -266,14 +262,15 @@ std::string AESCipher::Decrypt(const std::string& ciphertext,
void AESCipher::EncryptToFile(const std::string& plaintext,
const std::string& key,
const std::string& filename) {
std::ofstream fout(filename);
fout << this->Encrypt(plaintext, key);
std::ofstream fout(filename, std::ios::binary);
std::string ciphertext = this->Encrypt(plaintext, key);
fout.write(ciphertext.data(), ciphertext.size());
fout.close();
}
std::string AESCipher::DecryptFromFile(const std::string& key,
const std::string& filename) {
std::ifstream fin(filename);
std::ifstream fin(filename, std::ios::binary);
std::string ciphertext{std::istreambuf_iterator<char>(fin),
std::istreambuf_iterator<char>()};
fin.close();
......
......@@ -43,7 +43,7 @@ std::string CipherUtils::GenKeyToFile(int length, const std::string& filename) {
// CryptoPP::byte key[length];
prng.GenerateBlock(reinterpret_cast<unsigned char*>(&(rng.at(0))),
rng.size());
std::ofstream fout(filename);
std::ofstream fout(filename, std::ios::binary);
PADDLE_ENFORCE_EQ(fout.is_open(), true,
paddle::platform::errors::Unavailable(
"Failed to open file : %s, "
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册