Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
aabb0651
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
aabb0651
编写于
5月 22, 2020
作者:
Y
yangqingyou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix CI bug, test=develop
上级
011dd3b8
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
19 addition
and
10 deletion
+19
-10
paddle/fluid/framework/io/crypto/aes_cipher.cc
paddle/fluid/framework/io/crypto/aes_cipher.cc
+6
-6
paddle/fluid/framework/io/crypto/aes_cipher_test.cc
paddle/fluid/framework/io/crypto/aes_cipher_test.cc
+9
-0
paddle/fluid/framework/io/crypto/cipher.cc
paddle/fluid/framework/io/crypto/cipher.cc
+2
-2
paddle/fluid/framework/io/crypto/cipher_utils.cc
paddle/fluid/framework/io/crypto/cipher_utils.cc
+1
-1
paddle/fluid/framework/io/crypto/cipher_utils_test.cc
paddle/fluid/framework/io/crypto/cipher_utils_test.cc
+1
-1
未找到文件。
paddle/fluid/framework/io/crypto/aes_cipher.cc
浏览文件 @
aabb0651
...
@@ -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
());
}
}
...
...
paddle/fluid/framework/io/crypto/aes_cipher_test.cc
浏览文件 @
aabb0651
...
@@ -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
);
}
}
}
}
...
...
paddle/fluid/framework/io/crypto/cipher.cc
浏览文件 @
aabb0651
...
@@ -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
;
}
}
...
...
paddle/fluid/framework/io/crypto/cipher_utils.cc
浏览文件 @
aabb0651
...
@@ -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
paddle/fluid/framework/io/crypto/cipher_utils_test.cc
浏览文件 @
aabb0651
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录