Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleX
提交
82275ca1
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看板
提交
82275ca1
编写于
7月 01, 2020
作者:
Z
zhongjiafeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change linux -> __linux__ & WIN32 -> _WIN32 & use existed key encrypt files in dir
上级
82b2f814
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
55 addition
and
25 deletion
+55
-25
deploy/encryption/build.sh
deploy/encryption/build.sh
+1
-1
deploy/encryption/include/paddle_model_decrypt.h
deploy/encryption/include/paddle_model_decrypt.h
+2
-2
deploy/encryption/include/paddle_model_encrypt.h
deploy/encryption/include/paddle_model_encrypt.h
+2
-2
deploy/encryption/sample/paddle_encrypt_tool.cpp
deploy/encryption/sample/paddle_encrypt_tool.cpp
+44
-14
deploy/encryption/src/util/io_utils.cpp
deploy/encryption/src/util/io_utils.cpp
+6
-6
未找到文件。
deploy/encryption/build.sh
浏览文件 @
82275ca1
PADDLE_DIR
=
/
home/parallels/developers/paddleX-PR
/paddle
PADDLE_DIR
=
/
path/to
/paddle
if
[
!
-d
"3rd"
]
;
then
if
[
!
-d
"3rd"
]
;
then
mkdir
3rd
mkdir
3rd
...
...
deploy/encryption/include/paddle_model_decrypt.h
浏览文件 @
82275ca1
...
@@ -6,14 +6,14 @@
...
@@ -6,14 +6,14 @@
#ifndef PADDLE_MODEL_PROTECT_API_PADDLE_MODEL_DECRYPT_H
#ifndef PADDLE_MODEL_PROTECT_API_PADDLE_MODEL_DECRYPT_H
#define PADDLE_MODEL_PROTECT_API_PADDLE_MODEL_DECRYPT_H
#define PADDLE_MODEL_PROTECT_API_PADDLE_MODEL_DECRYPT_H
#ifdef WIN32
#ifdef
_
WIN32
#ifdef PM_EXPORTS
#ifdef PM_EXPORTS
#define PDD_MODEL_API __declspec(dllexport)
#define PDD_MODEL_API __declspec(dllexport)
#else
#else
#define PDD_MODEL_API __declspec(dllimport)
#define PDD_MODEL_API __declspec(dllimport)
#endif
#endif
#endif
#endif
#ifdef
linux
#ifdef
__linux__
#define PDD_MODEL_API __attribute__((visibility("default")))
#define PDD_MODEL_API __attribute__((visibility("default")))
#endif
#endif
...
...
deploy/encryption/include/paddle_model_encrypt.h
浏览文件 @
82275ca1
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
#ifndef PADDLE_MODEL_PROTECT_API_PADDLE_MODEL_ENCRYPT_H
#ifndef PADDLE_MODEL_PROTECT_API_PADDLE_MODEL_ENCRYPT_H
#define PADDLE_MODEL_PROTECT_API_PADDLE_MODEL_ENCRYPT_H
#define PADDLE_MODEL_PROTECT_API_PADDLE_MODEL_ENCRYPT_H
#ifdef WIN32
#ifdef
_
WIN32
#ifdef PM_EXPORTS
#ifdef PM_EXPORTS
#define PDE_MODEL_API __declspec(dllexport)
#define PDE_MODEL_API __declspec(dllexport)
#else
#else
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
#endif
#endif
#endif
#endif
#ifdef
linux
#ifdef
__linux__
#define PDE_MODEL_API __attribute__((visibility("default")))
#define PDE_MODEL_API __attribute__((visibility("default")))
#endif
#endif
...
...
deploy/encryption/sample/paddle_encrypt_tool.cpp
浏览文件 @
82275ca1
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#define RESET "\033[0m"
#define RESET "\033[0m"
#define BOLD "\033[1m"
#define BOLD "\033[1m"
#define BOLDGREEN "\033[1m\033[32m"
#define BOLDGREEN "\033[1m\033[32m"
#elif WIN32
#elif
_
WIN32
#define RESET ""
#define RESET ""
#define BOLD ""
#define BOLD ""
#define BOLDGREEN ""
#define BOLDGREEN ""
...
@@ -21,9 +21,11 @@ void help() {
...
@@ -21,9 +21,11 @@ void help() {
std
::
cout
<<
"
\t
-h"
<<
std
::
endl
;
std
::
cout
<<
"
\t
-h"
<<
std
::
endl
;
std
::
cout
<<
"[2]Generate random key and encrypt dir files"
<<
std
::
endl
;
std
::
cout
<<
"[2]Generate random key and encrypt dir files"
<<
std
::
endl
;
std
::
cout
<<
"
\t
-model_dir
\t
model_dir_ori
\t
-save_dir
\t
encrypted_models"
<<
std
::
endl
;
std
::
cout
<<
"
\t
-model_dir
\t
model_dir_ori
\t
-save_dir
\t
encrypted_models"
<<
std
::
endl
;
std
::
cout
<<
"[3]Generate random key for encrypt file"
<<
std
::
endl
;
std
::
cout
<<
"[3]Encrypt dir files with key"
<<
std
::
endl
;
std
::
cout
<<
"
\t
-key
\t
keydata
\t
-model_dir
\t
model_dir_ori
\t
-save_dir
\t
encrypted_models"
<<
std
::
endl
;
std
::
cout
<<
"[4]Generate random key for encrypt file"
<<
std
::
endl
;
std
::
cout
<<
"
\t
-g"
<<
std
::
endl
;
std
::
cout
<<
"
\t
-g"
<<
std
::
endl
;
std
::
cout
<<
"[
4
]Encrypt file:"
<<
std
::
endl
;
std
::
cout
<<
"[
5
]Encrypt file:"
<<
std
::
endl
;
std
::
cout
<<
"
\t
-e
\t
-key
\t
keydata
\t
-infile
\t
infile
\t
-outfile
\t
outfile"
<<
std
::
endl
;
std
::
cout
<<
"
\t
-e
\t
-key
\t
keydata
\t
-infile
\t
infile
\t
-outfile
\t
outfile"
<<
std
::
endl
;
}
}
...
@@ -46,27 +48,22 @@ int main(int argc, char** argv) {
...
@@ -46,27 +48,22 @@ int main(int argc, char** argv) {
int
ret
=
paddle_encrypt_dir
(
key_random
.
c_str
(),
argv
[
2
],
argv
[
4
]);
int
ret
=
paddle_encrypt_dir
(
key_random
.
c_str
(),
argv
[
2
],
argv
[
4
]);
switch
(
ret
)
{
switch
(
ret
)
{
case
CODE_OK
:
case
CODE_OK
:
std
::
cout
<<
"Success, Encrypt __model__, __params__ to "
<<
argv
[
4
]
<<
"(dir) success!"
std
::
cout
<<
"Success, Encrypt __model__, __params__ to "
<<
argv
[
4
]
<<
"(dir) success!"
<<
std
::
endl
;
<<
std
::
endl
;
break
;
break
;
case
CODE_MODEL_FILE_NOT_EXIST
:
case
CODE_MODEL_FILE_NOT_EXIST
:
std
::
cout
<<
"Failed, errorcode = "
<<
ret
<<
", could't find __model__(file) in "
<<
argv
[
2
]
std
::
cout
<<
"Failed, errorcode = "
<<
ret
<<
", could't find __model__(file) in "
<<
argv
[
2
]
<<
std
::
endl
;
<<
std
::
endl
;
break
;
break
;
case
CODE_MODEL_YML_FILE_NOT_EXIST
:
case
CODE_MODEL_YML_FILE_NOT_EXIST
:
std
::
cout
<<
"Failed, errorcode = "
<<
ret
<<
", could't find model.yml(file) in "
<<
argv
[
2
]
std
::
cout
<<
"Failed, errorcode = "
<<
ret
<<
", could't find model.yml(file) in "
<<
argv
[
2
]
<<
std
::
endl
;
<<
std
::
endl
;
break
;
break
;
case
CODE_PARAMS_FILE_NOT_EXIST
:
case
CODE_PARAMS_FILE_NOT_EXIST
:
std
::
cout
<<
"Failed, errorcode = "
<<
ret
<<
", could't find __params__(file) in "
<<
argv
[
2
]
std
::
cout
<<
"Failed, errorcode = "
<<
ret
<<
", could't find __params__(file) in "
<<
argv
[
2
]
<<
std
::
endl
;
<<
std
::
endl
;
break
;
break
;
case
CODE_NOT_EXIST_DIR
:
case
CODE_NOT_EXIST_DIR
:
std
::
cout
<<
"Failed, errorcode = "
<<
ret
<<
", "
<<
argv
[
2
]
<<
"(dir) not exist"
<<
std
::
endl
;
std
::
cout
<<
"Failed, errorcode = "
<<
ret
<<
", "
<<
argv
[
2
]
<<
"(dir) not exist"
<<
std
::
endl
;
break
;
break
;
case
CODE_FILES_EMPTY_WITH_DIR
:
case
CODE_FILES_EMPTY_WITH_DIR
:
std
::
cout
<<
"Failed, errorcode = "
<<
ret
<<
", could't find any files in "
<<
argv
[
2
]
std
::
cout
<<
"Failed, errorcode = "
<<
ret
<<
", could't find any files in "
<<
argv
[
2
]
<<
std
::
endl
;
<<
std
::
endl
;
break
;
break
;
default:
std
::
cout
<<
"Failed, errorcode = "
<<
ret
<<
", others"
<<
std
::
endl
;
default:
std
::
cout
<<
"Failed, errorcode = "
<<
ret
<<
", others"
<<
std
::
endl
;
break
;
break
;
...
@@ -75,6 +72,39 @@ int main(int argc, char** argv) {
...
@@ -75,6 +72,39 @@ int main(int argc, char** argv) {
help
();
help
();
}
}
break
;
break
;
case
7
:
if
(
strcmp
(
argv
[
1
],
"-key"
)
==
0
&&
strcmp
(
argv
[
3
],
"-model_dir"
)
==
0
&&
strcmp
(
argv
[
5
],
"-save_dir"
)
==
0
)
{
int
ret_e
=
paddle_encrypt_dir
(
argv
[
2
],
argv
[
4
],
argv
[
6
]);
switch
(
ret_e
)
{
case
CODE_OK
:
std
::
cout
<<
"Success, Encrypt __model__, __params__ to "
<<
argv
[
6
]
<<
"(dir) success!"
<<
std
::
endl
;
break
;
case
CODE_KEY_LENGTH_ABNORMAL
:
std
::
cout
<<
"Failed, errorcode = "
<<
ret_e
<<
", key length normal"
<<
argv
[
2
]
<<
std
::
endl
;
break
;
case
CODE_MODEL_FILE_NOT_EXIST
:
std
::
cout
<<
"Failed, errorcode = "
<<
ret_e
<<
", could't find __model__(file) in "
<<
argv
[
4
]
<<
std
::
endl
;
break
;
case
CODE_MODEL_YML_FILE_NOT_EXIST
:
std
::
cout
<<
"Failed, errorcode = "
<<
ret_e
<<
", could't find model.yml(file) in "
<<
argv
[
4
]
<<
std
::
endl
;
break
;
case
CODE_PARAMS_FILE_NOT_EXIST
:
std
::
cout
<<
"Failed, errorcode = "
<<
ret_e
<<
", could't find __params__(file) in "
<<
argv
[
4
]
<<
std
::
endl
;
break
;
case
CODE_NOT_EXIST_DIR
:
std
::
cout
<<
"Failed, errorcode = "
<<
ret_e
<<
", "
<<
argv
[
4
]
<<
"(dir) not exist"
<<
std
::
endl
;
break
;
case
CODE_FILES_EMPTY_WITH_DIR
:
std
::
cout
<<
"Failed, errorcode = "
<<
ret_e
<<
", could't find any files in "
<<
argv
[
4
]
<<
std
::
endl
;
break
;
default:
std
::
cout
<<
"Failed, errorcode = "
<<
ret_e
<<
", others"
<<
std
::
endl
;
break
;
}
}
else
{
help
();
}
break
;
case
8
:
case
8
:
if
(
strcmp
(
argv
[
1
],
"-e"
)
==
0
&&
strcmp
(
argv
[
2
],
"-key"
)
==
0
&&
strcmp
(
argv
[
4
],
"-infile"
)
==
0
if
(
strcmp
(
argv
[
1
],
"-e"
)
==
0
&&
strcmp
(
argv
[
2
],
"-key"
)
==
0
&&
strcmp
(
argv
[
4
],
"-infile"
)
==
0
&&
strcmp
(
argv
[
6
],
"-outfile"
)
==
0
)
{
&&
strcmp
(
argv
[
6
],
"-outfile"
)
==
0
)
{
...
@@ -91,7 +121,7 @@ int main(int argc, char** argv) {
...
@@ -91,7 +121,7 @@ int main(int argc, char** argv) {
default:
help
();
default:
help
();
}
}
#ifdef WIN32
#ifdef
_
WIN32
system
(
"pause"
);
system
(
"pause"
);
#endif
#endif
...
...
deploy/encryption/src/util/io_utils.cpp
浏览文件 @
82275ca1
#ifdef
linux
#ifdef
__linux__
#include <unistd.h>
#include <unistd.h>
#include <dirent.h>
#include <dirent.h>
#endif
#endif
#ifdef WIN32
#ifdef
_
WIN32
#include <windows.h>
#include <windows.h>
#include <io.h>
#include <io.h>
#endif
#endif
...
@@ -141,7 +141,7 @@ int read_file_to_file(const char* src_path, const char* dst_path) {
...
@@ -141,7 +141,7 @@ int read_file_to_file(const char* src_path, const char* dst_path) {
}
}
int
read_dir_files
(
const
char
*
dir_path
,
std
::
vector
<
std
::
string
>&
files
)
{
int
read_dir_files
(
const
char
*
dir_path
,
std
::
vector
<
std
::
string
>&
files
)
{
#ifdef
linux
#ifdef
__linux__
struct
dirent
*
ptr
;
struct
dirent
*
ptr
;
DIR
*
dir
=
NULL
;
DIR
*
dir
=
NULL
;
dir
=
opendir
(
dir_path
);
dir
=
opendir
(
dir_path
);
...
@@ -155,7 +155,7 @@ int read_dir_files(const char* dir_path, std::vector<std::string>& files) {
...
@@ -155,7 +155,7 @@ int read_dir_files(const char* dir_path, std::vector<std::string>& files) {
}
}
closedir
(
dir
);
closedir
(
dir
);
#endif
#endif
#ifdef WIN32
#ifdef
_
WIN32
intptr_t
handle
;
intptr_t
handle
;
struct
_finddata_t
fileinfo
;
struct
_finddata_t
fileinfo
;
...
@@ -190,7 +190,7 @@ std::cout << files.size() << std::endl;
...
@@ -190,7 +190,7 @@ std::cout << files.size() << std::endl;
}
}
int
dir_exist_or_mkdir
(
const
char
*
dir
)
{
int
dir_exist_or_mkdir
(
const
char
*
dir
)
{
#ifdef WIN32
#ifdef
_
WIN32
if
(
CreateDirectory
(
dir
,
NULL
))
{
if
(
CreateDirectory
(
dir
,
NULL
))
{
// return CODE_OK;
// return CODE_OK;
}
else
{
}
else
{
...
@@ -198,7 +198,7 @@ int dir_exist_or_mkdir(const char* dir) {
...
@@ -198,7 +198,7 @@ int dir_exist_or_mkdir(const char* dir) {
}
}
#endif
#endif
#ifdef
linux
#ifdef
__linux__
if
(
access
(
dir
,
0
)
!=
0
)
{
if
(
access
(
dir
,
0
)
!=
0
)
{
mkdir
(
dir
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
mkdir
(
dir
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录