提交 aabb0651 编写于 作者: Y yangqingyou

fix CI bug, test=develop

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