提交 aabb0651 编写于 作者: Y yangqingyou

fix CI bug, test=develop

上级 011dd3b8
...@@ -65,7 +65,7 @@ std::string AESCipher::EncryptInternal(const std::string& plaintext, ...@@ -65,7 +65,7 @@ std::string AESCipher::EncryptInternal(const std::string& plaintext,
iv_ = CipherUtils::GenKey(iv_size_); iv_ = CipherUtils::GenKey(iv_size_);
m_cipher.get()->SetKeyWithIV( m_cipher.get()->SetKeyWithIV(
key_char, key.size(), key_char, key.size(),
reinterpret_cast<const unsigned char*>(&(iv_.at(0)))); reinterpret_cast<const unsigned char*>(&(iv_.at(0))), iv_.size());
} else { } else {
m_cipher.get()->SetKey(key_char, key.size()); m_cipher.get()->SetKey(key_char, key.size());
} }
...@@ -74,7 +74,7 @@ std::string AESCipher::EncryptInternal(const std::string& plaintext, ...@@ -74,7 +74,7 @@ std::string AESCipher::EncryptInternal(const std::string& plaintext,
m_filter->Attach(new CryptoPP::StringSink(ciphertext)); m_filter->Attach(new CryptoPP::StringSink(ciphertext));
CryptoPP::StringSource(plaintext, true, new CryptoPP::Redirector(*m_filter)); CryptoPP::StringSource(plaintext, true, new CryptoPP::Redirector(*m_filter));
if (need_iv) { if (need_iv) {
ciphertext = iv_ + ciphertext; ciphertext = iv_.append(ciphertext);
} }
return ciphertext; return ciphertext;
...@@ -95,7 +95,7 @@ std::string AESCipher::DecryptInternal(const std::string& ciphertext, ...@@ -95,7 +95,7 @@ std::string AESCipher::DecryptInternal(const std::string& ciphertext,
ciphertext_beg = iv_size_ / 8; ciphertext_beg = iv_size_ / 8;
m_cipher.get()->SetKeyWithIV( m_cipher.get()->SetKeyWithIV(
key_char, key.size(), key_char, key.size(),
reinterpret_cast<const unsigned char*>(&(iv_.at(0)))); reinterpret_cast<const unsigned char*>(&(iv_.at(0))), iv_.size());
} else { } else {
m_cipher.get()->SetKey(key_char, key.size()); m_cipher.get()->SetKey(key_char, key.size());
} }
...@@ -120,7 +120,7 @@ std::string AESCipher::AuthenticatedEncryptInternal( ...@@ -120,7 +120,7 @@ std::string AESCipher::AuthenticatedEncryptInternal(
iv_ = CipherUtils::GenKey(iv_size_); iv_ = CipherUtils::GenKey(iv_size_);
m_cipher.get()->SetKeyWithIV( m_cipher.get()->SetKeyWithIV(
key_char, key.size(), key_char, key.size(),
reinterpret_cast<const unsigned char*>(&(iv_.at(0)))); reinterpret_cast<const unsigned char*>(&(iv_.at(0))), iv_.size());
} else { } else {
m_cipher.get()->SetKey(key_char, key.size()); m_cipher.get()->SetKey(key_char, key.size());
} }
...@@ -129,7 +129,7 @@ std::string AESCipher::AuthenticatedEncryptInternal( ...@@ -129,7 +129,7 @@ std::string AESCipher::AuthenticatedEncryptInternal(
m_filter->Attach(new CryptoPP::StringSink(ciphertext)); m_filter->Attach(new CryptoPP::StringSink(ciphertext));
CryptoPP::StringSource(plaintext, true, new CryptoPP::Redirector(*m_filter)); CryptoPP::StringSource(plaintext, true, new CryptoPP::Redirector(*m_filter));
if (need_iv) { if (need_iv) {
ciphertext = iv_ + ciphertext; ciphertext = iv_.append(ciphertext);
} }
return ciphertext; return ciphertext;
...@@ -150,7 +150,7 @@ std::string AESCipher::AuthenticatedDecryptInternal( ...@@ -150,7 +150,7 @@ std::string AESCipher::AuthenticatedDecryptInternal(
ciphertext_beg = iv_size_ / 8; ciphertext_beg = iv_size_ / 8;
m_cipher.get()->SetKeyWithIV( m_cipher.get()->SetKeyWithIV(
key_char, key.size(), key_char, key.size(),
reinterpret_cast<const unsigned char*>(&(iv_.at(0)))); reinterpret_cast<const unsigned char*>(&(iv_.at(0))), iv_.size());
} else { } else {
m_cipher.get()->SetKey(key_char, key.size()); m_cipher.get()->SetKey(key_char, key.size());
} }
......
...@@ -45,6 +45,7 @@ TEST_F(AESTest, security_string) { ...@@ -45,6 +45,7 @@ TEST_F(AESTest, security_string) {
{"AES_CTR_NoPadding", "AES_CBC_PKCSPadding", "AES_ECB_PKCSPadding", {"AES_CTR_NoPadding", "AES_CBC_PKCSPadding", "AES_ECB_PKCSPadding",
"AES_GCM_NoPadding"}); "AES_GCM_NoPadding"});
const std::string plaintext("hello world."); const std::string plaintext("hello world.");
bool is_throw = false;
for (auto& i : name_list) { for (auto& i : name_list) {
AESTest::GenConfigFile(i); AESTest::GenConfigFile(i);
try { try {
...@@ -54,8 +55,10 @@ TEST_F(AESTest, security_string) { ...@@ -54,8 +55,10 @@ TEST_F(AESTest, security_string) {
std::string plaintext1 = cipher->Decrypt(ciphertext, AESTest::key); std::string plaintext1 = cipher->Decrypt(ciphertext, AESTest::key);
EXPECT_EQ(plaintext, plaintext1); EXPECT_EQ(plaintext, plaintext1);
} catch (CryptoPP::Exception& e) { } catch (CryptoPP::Exception& e) {
is_throw = true;
LOG(ERROR) << e.what(); LOG(ERROR) << e.what();
} }
EXPECT_FALSE(is_throw);
} }
} }
...@@ -64,6 +67,7 @@ TEST_F(AESTest, security_vector) { ...@@ -64,6 +67,7 @@ TEST_F(AESTest, security_vector) {
{"AES_CTR_NoPadding", "AES_CBC_PKCSPadding", "AES_ECB_PKCSPadding", {"AES_CTR_NoPadding", "AES_CBC_PKCSPadding", "AES_ECB_PKCSPadding",
"AES_GCM_NoPadding"}); "AES_GCM_NoPadding"});
std::vector<int> input{1, 2, 3, 4}; std::vector<int> input{1, 2, 3, 4};
bool is_throw = false;
for (auto& i : name_list) { for (auto& i : name_list) {
AESTest::GenConfigFile(i); AESTest::GenConfigFile(i);
try { try {
...@@ -79,8 +83,10 @@ TEST_F(AESTest, security_vector) { ...@@ -79,8 +83,10 @@ TEST_F(AESTest, security_vector) {
EXPECT_EQ(i, output); EXPECT_EQ(i, output);
} }
} catch (CryptoPP::Exception& e) { } catch (CryptoPP::Exception& e) {
is_throw = true;
LOG(ERROR) << e.what(); LOG(ERROR) << e.what();
} }
EXPECT_FALSE(is_throw);
} }
} }
...@@ -90,6 +96,7 @@ TEST_F(AESTest, encrypt_to_file) { ...@@ -90,6 +96,7 @@ TEST_F(AESTest, encrypt_to_file) {
"AES_GCM_NoPadding"}); "AES_GCM_NoPadding"});
const std::string plaintext("hello world."); const std::string plaintext("hello world.");
std::string filename("aes_test.ciphertext"); std::string filename("aes_test.ciphertext");
bool is_throw = false;
for (auto& i : name_list) { for (auto& i : name_list) {
AESTest::GenConfigFile(i); AESTest::GenConfigFile(i);
try { try {
...@@ -98,8 +105,10 @@ TEST_F(AESTest, encrypt_to_file) { ...@@ -98,8 +105,10 @@ TEST_F(AESTest, encrypt_to_file) {
std::string plaintext1 = cipher->DecryptFromFile(AESTest::key, filename); std::string plaintext1 = cipher->DecryptFromFile(AESTest::key, filename);
EXPECT_EQ(plaintext, plaintext1); EXPECT_EQ(plaintext, plaintext1);
} catch (CryptoPP::Exception& e) { } catch (CryptoPP::Exception& e) {
is_throw = true;
LOG(ERROR) << e.what(); LOG(ERROR) << e.what();
} }
EXPECT_FALSE(is_throw);
} }
} }
......
...@@ -48,10 +48,10 @@ std::shared_ptr<Cipher> CipherFactory::CreateCipher( ...@@ -48,10 +48,10 @@ std::shared_ptr<Cipher> CipherFactory::CreateCipher(
ret->Init(cipher_name, iv_size, tag_size); ret->Init(cipher_name, iv_size, tag_size);
return ret; return ret;
} else { } else {
PADDLE_THROW( PADDLE_THROW(paddle::platform::errors::InvalidArgument(
"Invalid cipher name is specied. " "Invalid cipher name is specied. "
"Please check you have specified valid cipher" "Please check you have specified valid cipher"
" name in CryptoProperties."); " name in CryptoProperties."));
} }
return nullptr; return nullptr;
} }
......
...@@ -111,7 +111,7 @@ bool CipherUtils::GetValue<bool>( ...@@ -111,7 +111,7 @@ bool CipherUtils::GetValue<bool>(
return true; return true;
} }
const int CipherUtils::AES_DEFAULT_IV_SIZE = 96; const int CipherUtils::AES_DEFAULT_IV_SIZE = 128;
const int CipherUtils::AES_DEFAULT_TAG_SIZE = 128; const int CipherUtils::AES_DEFAULT_TAG_SIZE = 128;
} // namespace framework } // namespace framework
} // namespace paddle } // namespace paddle
...@@ -70,7 +70,7 @@ TEST(CipherUtils, gen_key) { ...@@ -70,7 +70,7 @@ TEST(CipherUtils, gen_key) {
EXPECT_NE(key, key1); EXPECT_NE(key, key1);
std::string key2 = CipherUtils::ReadKeyFromFile(filename); std::string key2 = CipherUtils::ReadKeyFromFile(filename);
EXPECT_EQ(key1, key2); EXPECT_EQ(key1, key2);
EXPECT_EQ(key.size(), 256 / 8); EXPECT_EQ(static_cast<int>(key.size()), 32);
} }
} // namespace framework } // namespace framework
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册