Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleX
提交
6ade801a
P
PaddleX
项目概览
PaddlePaddle
/
PaddleX
通知
138
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
43
列表
看板
标记
里程碑
合并请求
5
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleX
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
43
Issue
43
列表
看板
标记
里程碑
合并请求
5
合并请求
5
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6ade801a
编写于
9月 08, 2020
作者:
Z
zhongjiafeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
compile with paddlepaddle-1.8.4 & optimize memory
上级
f21cee02
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
45 addition
and
14 deletion
+45
-14
deploy/encryption/include/model_code.h
deploy/encryption/include/model_code.h
+2
-1
deploy/encryption/src/safeapi/paddle_model_decrypt.cpp
deploy/encryption/src/safeapi/paddle_model_decrypt.cpp
+32
-10
deploy/encryption/src/util/io_utils.cpp
deploy/encryption/src/util/io_utils.cpp
+11
-3
未找到文件。
deploy/encryption/include/model_code.h
浏览文件 @
6ade801a
...
...
@@ -18,7 +18,8 @@ extern "C" {
CODE_MODEL_FILE_NOT_EXIST
=
108
,
CODE_PARAMS_FILE_NOT_EXIST
=
109
,
CODE_MODEL_YML_FILE_NOT_EXIST
=
110
,
CODE_MKDIR_FAILED
=
111
CODE_MKDIR_FAILED
=
111
,
CODE_MALLOC_FAILED
=
112
};
...
...
deploy/encryption/src/safeapi/paddle_model_decrypt.cpp
浏览文件 @
6ade801a
...
...
@@ -18,9 +18,10 @@ int paddle_check_file_encrypted(const char* file_path) {
return
util
::
SystemUtils
::
check_file_encrypted
(
file_path
);
}
std
::
string
decrypt_file
(
const
char
*
file_path
,
const
char
*
key
)
{
int
ret
=
paddle_check_file_encrypted
(
file_path
);
std
::
string
decrypt_file
_with_code
(
const
char
*
file_path
,
const
char
*
key
,
int
*
decrypt_code
)
{
int
ret
=
paddle_check_file_encrypted
(
file_path
);
if
(
ret
!=
CODE_OK
)
{
*
decrypt_code
=
ret
;
LOGD
(
"[M]check file encrypted failed, code: %d"
,
ret
);
return
std
::
string
();
}
...
...
@@ -29,6 +30,7 @@ std::string decrypt_file(const char* file_path, const char* key) {
std
::
string
key_str
=
baidu
::
base
::
base64
::
base64_decode
(
std
::
string
(
key
));
int
ret_check
=
util
::
SystemUtils
::
check_key_match
(
key_str
.
c_str
(),
file_path
);
if
(
ret_check
!=
CODE_OK
)
{
*
decrypt_code
=
ret_check
;
LOGD
(
"[M]check key failed in decrypt_file, code: %d"
,
ret_check
);
return
std
::
string
();
}
...
...
@@ -44,6 +46,7 @@ std::string decrypt_file(const char* file_path, const char* key) {
size_t
data_len
=
0
;
int
ret_read_data
=
ioutil
::
read_with_pos
(
file_path
,
pos
,
&
dataptr
,
&
data_len
);
if
(
ret_read_data
!=
CODE_OK
)
{
*
decrypt_code
=
ret_read_data
;
LOGD
(
"[M]read file failed, code = %d"
,
ret_read_data
);
return
std
::
string
();
}
...
...
@@ -51,6 +54,11 @@ std::string decrypt_file(const char* file_path, const char* key) {
// decrypt model data
size_t
model_plain_len
=
data_len
-
AES_GCM_TAG_LENGTH
;
unsigned
char
*
model_plain
=
(
unsigned
char
*
)
malloc
(
sizeof
(
unsigned
char
)
*
model_plain_len
);
if
(
model_plain
==
NULL
)
{
*
decrypt_code
=
CODE_MALLOC_FAILED
;
LOGD
(
"model_plain malloc failed(decrypt_file), code: %d"
,
CODE_MALLOC_FAILED
);
return
std
::
string
();
}
int
ret_decrypt_file
=
util
::
crypto
::
AesGcm
::
decrypt_aes_gcm
(
...
...
@@ -64,12 +72,23 @@ std::string decrypt_file(const char* file_path, const char* key) {
free
(
aes_key
);
free
(
aes_iv
);
if
(
ret_decrypt_file
!=
CODE_OK
)
{
*
decrypt_code
=
ret_decrypt_file
;
free
(
model_plain
);
LOGD
(
"[M]decrypt file failed, decrypt ret = %d"
,
ret_decrypt_file
);
return
std
::
string
();
}
std
::
string
result
((
const
char
*
)
model_plain
);
std
::
string
result
((
const
char
*
)
model_plain
,
(
const
char
*
)
model_plain
+
model_plain_len
);
free
(
model_plain
);
*
decrypt_code
=
CODE_OK
;
return
result
;
}
std
::
string
decrypt_file
(
const
char
*
file_path
,
const
char
*
key
)
{
int
decrypt_code
=
0
;
std
::
string
result
=
decrypt_file_with_code
(
file_path
,
key
,
&
decrypt_code
);
if
(
decrypt_code
!=
CODE_OK
)
{
LOGD
(
"[M]decrypt file failed(decrypt_file), decrypt ret = %d"
,
decrypt_code
);
}
return
result
;
}
...
...
@@ -139,6 +158,10 @@ int paddle_security_load_model(
// decrypt model data
model_plain_len
=
model_data_len
-
AES_GCM_TAG_LENGTH
;
model_plain
=
(
unsigned
char
*
)
malloc
(
sizeof
(
unsigned
char
)
*
model_plain_len
);
if
(
model_plain
==
NULL
)
{
LOGD
(
"model_plain malloc failed"
);
return
CODE_MALLOC_FAILED
;
}
int
ret_decrypt_model
=
util
::
crypto
::
AesGcm
::
decrypt_aes_gcm
(
model_dataptr
,
...
...
@@ -176,6 +199,10 @@ int paddle_security_load_model(
// decrypt params data
params_plain_len
=
params_data_len
-
AES_GCM_TAG_LENGTH
;
params_plain
=
(
unsigned
char
*
)
malloc
(
sizeof
(
unsigned
char
)
*
params_plain_len
);
if
(
params_plain
==
NULL
)
{
LOGD
(
"params_plain malloc failed"
);
return
CODE_MALLOC_FAILED
;
}
int
ret_decrypt_params
=
util
::
crypto
::
AesGcm
::
decrypt_aes_gcm
(
params_dataptr
,
...
...
@@ -202,13 +229,8 @@ int paddle_security_load_model(
config
->
SetModelBuffer
(
reinterpret_cast
<
const
char
*>
(
model_plain
),
model_plain_len
,
reinterpret_cast
<
const
char
*>
(
params_plain
),
params_plain_len
);
if
(
m_en_flag
==
1
)
{
free
(
model_dataptr
);
}
if
(
p_en_flag
==
1
)
{
free
(
params_dataptr
);
}
free
(
model_plain
);
free
(
params_plain
);
return
CODE_OK
;
}
deploy/encryption/src/util/io_utils.cpp
浏览文件 @
6ade801a
...
...
@@ -28,6 +28,10 @@ int read_file(const char* file_path, unsigned char** dataptr, size_t* sizeptr) {
fseek
(
fp
,
0
,
SEEK_END
);
*
sizeptr
=
ftell
(
fp
);
*
dataptr
=
(
unsigned
char
*
)
malloc
(
sizeof
(
unsigned
char
)
*
(
*
sizeptr
));
if
(
*
dataptr
==
NULL
)
{
LOGD
(
"malloc failed when read file"
);
return
CODE_MALLOC_FAILED
;
}
fseek
(
fp
,
0
,
SEEK_SET
);
fread
(
*
dataptr
,
1
,
*
sizeptr
,
fp
);
...
...
@@ -68,6 +72,10 @@ int read_with_pos(const char* file_path, size_t pos, unsigned char** dataptr, si
*
sizeptr
=
filesize
-
pos
;
*
dataptr
=
(
unsigned
char
*
)
malloc
(
sizeof
(
unsigned
char
)
*
(
filesize
-
pos
));
if
(
*
dataptr
==
NULL
)
{
LOGD
(
"malloc failed when read file"
);
return
CODE_MALLOC_FAILED
;
}
fseek
(
fp
,
pos
,
SEEK_SET
);
fread
(
*
dataptr
,
1
,
filesize
-
pos
,
fp
);
fclose
(
fp
);
...
...
@@ -172,17 +180,17 @@ int read_dir_files(const char* dir_path, std::vector<std::string>& files) {
}
do
{
std
::
cout
<<
"File name = "
<<
fileinfo
.
name
<<
std
::
endl
;
//
std::cout << "File name = " << fileinfo.name << std::endl;
if
(
strcmp
(
fileinfo
.
name
,
"."
)
!=
0
&&
strcmp
(
fileinfo
.
name
,
".."
)
!=
0
)
{
files
.
push_back
(
fileinfo
.
name
);
}
}
while
(
!
_findnext
(
handle
,
&
fileinfo
));
std
::
cout
<<
files
.
size
()
<<
std
::
endl
;
/*
std::cout << files.size() << std::endl;
for (size_t i = 0; i < files.size(); i++)
{
std::cout << files[i] << std::endl;
}
}
*/
_findclose
(
handle
);
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录