Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
hoang-gia.nguyen
dap-pattern-search-standalone
Commits
c6c9d2f5
Commit
c6c9d2f5
authored
May 04, 2023
by
Hoang Gia NGUYEN
Browse files
first commit
parent
fe2d6195
Pipeline
#60
failed with stages
in 0 seconds
Changes
275
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
2285 additions
and
0 deletions
+2285
-0
bigpiseal3.5.1/native/examples/patternSearch/v1/util.h
bigpiseal3.5.1/native/examples/patternSearch/v1/util.h
+15
-0
bigpiseal3.5.1/native/examples/patternSearch/v2/CMakeLists.txt
...seal3.5.1/native/examples/patternSearch/v2/CMakeLists.txt
+167
-0
bigpiseal3.5.1/native/examples/patternSearch/v2/decrypt.sh
bigpiseal3.5.1/native/examples/patternSearch/v2/decrypt.sh
+12
-0
bigpiseal3.5.1/native/examples/patternSearch/v2/decrypt_result.sh
...l3.5.1/native/examples/patternSearch/v2/decrypt_result.sh
+12
-0
bigpiseal3.5.1/native/examples/patternSearch/v2/encrypt.sh
bigpiseal3.5.1/native/examples/patternSearch/v2/encrypt.sh
+16
-0
bigpiseal3.5.1/native/examples/patternSearch/v2/eval.sh
bigpiseal3.5.1/native/examples/patternSearch/v2/eval.sh
+30
-0
bigpiseal3.5.1/native/examples/patternSearch/v2/genkey.sh
bigpiseal3.5.1/native/examples/patternSearch/v2/genkey.sh
+8
-0
bigpiseal3.5.1/native/examples/patternSearch/v2/patternSearch_decrypt_result_v2.cpp
...ples/patternSearch/v2/patternSearch_decrypt_result_v2.cpp
+139
-0
bigpiseal3.5.1/native/examples/patternSearch/v2/patternSearch_decrypt_v2.cpp
...ve/examples/patternSearch/v2/patternSearch_decrypt_v2.cpp
+73
-0
bigpiseal3.5.1/native/examples/patternSearch/v2/patternSearch_encrypt_v2.cpp
...ve/examples/patternSearch/v2/patternSearch_encrypt_v2.cpp
+54
-0
bigpiseal3.5.1/native/examples/patternSearch/v2/patternSearch_evaluate_v2.cpp
...e/examples/patternSearch/v2/patternSearch_evaluate_v2.cpp
+515
-0
bigpiseal3.5.1/native/examples/patternSearch/v2/patternSearch_genkey_v2.cpp
...ive/examples/patternSearch/v2/patternSearch_genkey_v2.cpp
+31
-0
bigpiseal3.5.1/native/examples/patternSearch/v2/seal_api.cpp
bigpiseal3.5.1/native/examples/patternSearch/v2/seal_api.cpp
+748
-0
bigpiseal3.5.1/native/examples/patternSearch/v2/seal_api.h
bigpiseal3.5.1/native/examples/patternSearch/v2/seal_api.h
+97
-0
bigpiseal3.5.1/native/examples/patternSearch/v2/test_v2.sh
bigpiseal3.5.1/native/examples/patternSearch/v2/test_v2.sh
+115
-0
bigpiseal3.5.1/native/examples/patternSearch/v2/util.cpp
bigpiseal3.5.1/native/examples/patternSearch/v2/util.cpp
+73
-0
bigpiseal3.5.1/native/examples/patternSearch/v2/util.h
bigpiseal3.5.1/native/examples/patternSearch/v2/util.h
+15
-0
bigpiseal3.5.1/native/examples/similarityMatch/v1/CMakeLists.txt
...al3.5.1/native/examples/similarityMatch/v1/CMakeLists.txt
+143
-0
bigpiseal3.5.1/native/examples/similarityMatch/v1/decrypt.sh
bigpiseal3.5.1/native/examples/similarityMatch/v1/decrypt.sh
+11
-0
bigpiseal3.5.1/native/examples/similarityMatch/v1/decrypt_1st_result.sh
.../native/examples/similarityMatch/v1/decrypt_1st_result.sh
+11
-0
No files found.
Too many changes to show.
To preserve performance only
275 of 275+
files are displayed.
Plain diff
Email patch
bigpiseal3.5.1/native/examples/patternSearch/v1/util.h
0 → 100644
View file @
c6c9d2f5
#ifndef _UTIL_H_
#define _UTIL_H_
#include <string>
#include <vector>
// int findNumberOfFilesInDirectory(const std::string &path);
bool
sub_str_exist
(
const
std
::
string
&
str
,
const
std
::
string
&
sub_str
);
// std::vector<std::string> get_directories(const std::string &s);
// std::vector<std::string> get_directories_deep(const std::string &s);
#endif
bigpiseal3.5.1/native/examples/patternSearch/v2/CMakeLists.txt
0 → 100644
View file @
c6c9d2f5
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT license.
cmake_minimum_required
(
VERSION 3.10
)
set
(
TEST_NAME patternSearch
)
#set(GENKEY_BIN ${TEST_NAME}_genkey)
#set(ENCR_BIN ${TEST_NAME}_encrypt)
#set(DECR_BIN ${TEST_NAME}_decrypt)
#set(EVAL_BIN ${TEST_NAME}_evaluate)
#set(SCR_TEST test.sh)
set
(
GENKEY_BIN_2
${
TEST_NAME
}
_genkey_v2
)
set
(
ENCR_BIN_2
${
TEST_NAME
}
_encrypt_v2
)
set
(
DECR_BIN_2
${
TEST_NAME
}
_decrypt_v2
)
set
(
DECR_RESULT_BIN_2
${
TEST_NAME
}
_decrypt_result_v2
)
set
(
EVAL_BIN_2
${
TEST_NAME
}
_evaluate_v2
)
set
(
SCR_ENC encrypt.sh
)
set
(
SCR_DEC decrypt.sh
)
set
(
SCR_DEC_RESULT decrypt_result.sh
)
set
(
SCR_EVAL eval.sh
)
set
(
SCR_GEN genkey.sh
)
set
(
SCR_TEST_V2 test_v2.sh
)
set
(
GENKEY_SRCS
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/
${
TEST_NAME
}
_genkey.cpp
)
set
(
ENCR_SRCS
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/
${
TEST_NAME
}
_encrypt.cpp
)
set
(
DECR_SRCS
${
CMAKE_CURRENT_LIST_DIR
}
/util.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/
${
TEST_NAME
}
_decrypt.cpp
)
set
(
EVAL_SRCS
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/util.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/
${
TEST_NAME
}
_evaluate.cpp
)
set
(
GENKEY_SRCS_2
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/
${
TEST_NAME
}
_genkey_v2.cpp
)
set
(
ENCR_SRCS_2
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/
${
TEST_NAME
}
_encrypt_v2.cpp
)
set
(
DECR_SRCS_2
${
CMAKE_CURRENT_LIST_DIR
}
/util.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/
${
TEST_NAME
}
_decrypt_v2.cpp
)
set
(
DECR_RESULT_SRCS_2
${
CMAKE_CURRENT_LIST_DIR
}
/util.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/
${
TEST_NAME
}
_decrypt_result_v2.cpp
)
set
(
EVAL_SRCS_2
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/util.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/
${
TEST_NAME
}
_evaluate_v2.cpp
)
set
(
HEADER_FILES
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.h
${
CMAKE_CURRENT_LIST_DIR
}
/util.h
)
#add_executable(${GENKEY_BIN} ${GENKEY_SRCS} ${HEADER_FILES})
#add_executable(${ENCR_BIN} ${ENCR_SRCS} ${HEADER_FILES})
#add_executable(${DECR_BIN} ${DECR_SRCS} ${HEADER_FILES})
#add_executable(${EVAL_BIN} ${EVAL_SRCS} ${HEADER_FILES})
#target_include_directories(${TEST_NAME} PRIVATE ${HEADER_DIR})
add_executable
(
${
GENKEY_BIN_2
}
${
GENKEY_SRCS_2
}
${
HEADER_FILES
}
)
add_executable
(
${
ENCR_BIN_2
}
${
ENCR_SRCS_2
}
${
HEADER_FILES
}
)
add_executable
(
${
DECR_BIN_2
}
${
DECR_SRCS_2
}
${
HEADER_FILES
}
)
add_executable
(
${
DECR_RESULT_BIN_2
}
${
DECR_RESULT_SRCS_2
}
${
HEADER_FILES
}
)
add_executable
(
${
EVAL_BIN_2
}
${
EVAL_SRCS_2
}
${
HEADER_FILES
}
)
#target_include_directories(${TEST_NAME} PRIVATE ${HEADER_DIR})
# Import Microsoft SEAL
find_package
(
SEAL 3.5 REQUIRED
)
# Link Microsoft SEAL
#target_link_libraries(${GENKEY_BIN} SEAL::seal)
#target_link_libraries(${ENCR_BIN} SEAL::seal)
#target_link_libraries(${DECR_BIN} SEAL::seal)
#target_link_libraries(${EVAL_BIN} SEAL::seal)
target_link_libraries
(
${
GENKEY_BIN_2
}
SEAL::seal
)
target_link_libraries
(
${
ENCR_BIN_2
}
SEAL::seal
)
target_link_libraries
(
${
DECR_BIN_2
}
SEAL::seal
)
target_link_libraries
(
${
DECR_RESULT_BIN_2
}
SEAL::seal
)
target_link_libraries
(
${
EVAL_BIN_2
}
SEAL::seal
)
set
(
CMAKE_RUNTIME_OUTPUT_DIRECTORY
${
CMAKE_SOURCE_DIR
}
/bin
)
#set_target_properties(${GENKEY_BIN}
# PROPERTIES
# RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TEST_NAME}"
# )
#set_target_properties(${ENCR_BIN}
# PROPERTIES
# RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TEST_NAME}"
# )
#set_target_properties(${DECR_BIN}
# PROPERTIES
# RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TEST_NAME}"
# )
#set_target_properties(${EVAL_BIN}
# PROPERTIES
# RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TEST_NAME}"
# )
set_target_properties
(
${
GENKEY_BIN_2
}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
"
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v2"
)
set_target_properties
(
${
ENCR_BIN_2
}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
"
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v2"
)
set_target_properties
(
${
DECR_BIN_2
}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
"
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v2"
)
set_target_properties
(
${
DECR_RESULT_BIN_2
}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
"
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v2"
)
set_target_properties
(
${
EVAL_BIN_2
}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
"
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v2"
)
file
(
COPY
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
SCR_TEST
}
DESTINATION
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v2
)
file
(
COPY
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
SCR_ENC
}
DESTINATION
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v2
)
file
(
COPY
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
SCR_DEC
}
DESTINATION
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v2
)
file
(
COPY
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
SCR_DEC_RESULT
}
DESTINATION
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v2
)
file
(
COPY
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
SCR_EVAL
}
DESTINATION
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v2
)
file
(
COPY
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
SCR_GEN
}
DESTINATION
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v2
)
file
(
COPY
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
SCR_TEST_V2
}
DESTINATION
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v2
)
\ No newline at end of file
bigpiseal3.5.1/native/examples/patternSearch/v2/decrypt.sh
0 → 100644
View file @
c6c9d2f5
#decrypt
resultPath
=
$1
# ex: result/l.ct
sample
=
$2
# ex: 40
keyDir
=
$3
# ex: keys/
CURR_DIR
=
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
# time ./patternSearch_decrypt_v2 "$resultPath" "$sample" "$keyDir"
time
${
CURR_DIR
}
/patternSearch_decrypt_v2
"
$resultPath
"
"
$sample
"
"
$keyDir
"
\ No newline at end of file
bigpiseal3.5.1/native/examples/patternSearch/v2/decrypt_result.sh
0 → 100644
View file @
c6c9d2f5
#decrypt result
resultPath
=
$1
# ex: result/l.ct
sample
=
$2
# ex: 40
keyDir
=
$3
# ex: keys/
CURR_DIR
=
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
# time ./patternSearch_decrypt_result_v2 "$resultPath" "$sample" "$keyDir"
time
${
CURR_DIR
}
/patternSearch_decrypt_result_v2
"
$resultPath
"
"
$sample
"
"
$keyDir
"
\ No newline at end of file
bigpiseal3.5.1/native/examples/patternSearch/v2/encrypt.sh
0 → 100644
View file @
c6c9d2f5
#encrypt
licenseNo
=
$1
# ex: "23 65 78 127 255" (en ASCII)
filename
=
$2
# ex: "l" (extension will be .ct)
outputDir
=
$3
# ex: lcheck/
sample
=
$4
# ex: 40
keyDir
=
$5
# ex: keys/
CURR_DIR
=
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
# time ./patternSearch_encrypt_v2 "$licenseNo" "$filename" "$outputDir" "$sample" "$keyDir"
time
${
CURR_DIR
}
/patternSearch_encrypt_v2
"
$licenseNo
"
"
$filename
"
"
$outputDir
"
"
$sample
"
"
$keyDir
"
\ No newline at end of file
bigpiseal3.5.1/native/examples/patternSearch/v2/eval.sh
0 → 100644
View file @
c6c9d2f5
# evaluate
licensePath
=
$1
# ex: lcheck/l.ct
licensePathList
=
${
@
:
2
:
$#-5
}
# licensePathList="${@:2:102}"
# for var in "${@: 2:$#-7}"
# do
# echo "$var"
# done
# ex: parent/l0/l.ct parent/l1/l.ct parent/l2/l.ct parent/l3/l.ct parent/l4/l.ct parent/l5/l.ct parent/l6/l.ct parent/l7/l.ct parent/l8/l.ct parent/l9/l.ct
filename
=
${
@
:
-4
:1
}
# ex: "l" (extension will be .ct)
outputDir
=
${
@
:
-3
:1
}
# ex: result/
sample
=
${
@
:
-2
:1
}
# ex: 40
KeyDir
=
${
@
:
-1
}
# ex: keys/
# linkingKeyPath=${@: -3:1}
# # ex: bfv.lk
# galoisKeyPath=${@: -2:1}
# # ex: bfv.gk
# publicKeyPath=${@: -1}
# # ex: bfv.pk
CURR_DIR
=
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
# time ./patternSearch_evaluate_v2 "$licensePath" $licensePathList "$filename" "$outputDir" "$sample" "$linkingKeyPath" "$galoisKeyPath" "$publicKeyPath"
# time ./patternSearch_evaluate_v2 "$licensePath" $licensePathList "$filename" "$outputDir" "$sample" "$KeyDir"
time
${
CURR_DIR
}
/patternSearch_evaluate_v2
"
$licensePath
"
$licensePathList
"
$filename
"
"
$outputDir
"
"
$sample
"
"
$KeyDir
"
\ No newline at end of file
bigpiseal3.5.1/native/examples/patternSearch/v2/genkey.sh
0 → 100644
View file @
c6c9d2f5
#gen key
keyDir
=
$1
# ex: keys/
CURR_DIR
=
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
# time ./patternSearch_genkey_v2 "$keyDir"
time
${
CURR_DIR
}
/patternSearch_genkey_v2
"
$keyDir
"
\ No newline at end of file
bigpiseal3.5.1/native/examples/patternSearch/v2/patternSearch_decrypt_result_v2.cpp
0 → 100644
View file @
c6c9d2f5
#include <iomanip>
#include "seal_api.h"
#include "util.h"
using
namespace
seal
;
using
namespace
std
;
string
ciphertext_name
;
string
key_dir
;
// bool decrypt(size_t poly_d, size_t p_modulus, int &sample_size, string &ciphertext_dir);
bool
decrypt
(
int
&
sample_size
,
string
&
ciphertext_dir
);
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
!=
4
)
{
// cout << "[ERROR] please enter /full/path/to/file/to/decrypt full/path/key " << endl;
// cout << "[ERROR] please enter prefix_file_to_decrypt full/path/key /full/path/to/storage" << endl;
// cout << "[ERROR] please enter a ciphertext file path, sample size and secret key path" << endl;
return
-
1
;
}
else
{
string
dir
=
argv
[
1
];
int
sample_size
=
atol
(
argv
[
2
]);
key_dir
=
argv
[
3
];
bool
result_str
=
decrypt
(
sample_size
,
dir
);
cout
<<
result_str
<<
endl
;
return
0
;
}
}
bool
decrypt
(
int
&
sample_size
,
string
&
ciphertext_dir
)
{
struct
decryptor_t
decr
;
init_operator_batching
(
decr
,
key_dir
);
bool
isContain
=
false
;
if
(
sample_size
<=
decr
.
bcode
->
slot_count
()
/
2
)
{
Ciphertext
cipher_matrix
;
vector
<
int64_t
>
pod_matrix
;
load_ciphertext
(
decr
,
cipher_matrix
,
ciphertext_dir
);
pod_matrix
=
decrypt_ciphermatrix
(
decr
,
cipher_matrix
);
// cout << pod_matrix.size() << endl;
int
no_dual_vectors
=
(
decr
.
bcode
->
slot_count
()
/
2
)
/
(
sample_size
);
vector
<
int64_t
>
v1
,
v2
;
for
(
size_t
i
=
0
;
i
<
no_dual_vectors
*
sample_size
;
i
++
)
{
v1
.
push_back
(
pod_matrix
[
i
]);
v2
.
push_back
(
pod_matrix
[(
pod_matrix
.
size
()
/
2
)
+
i
]);
}
int64_t
sum
=
0
;
if
(
isContain
==
false
)
{
// cout << "1 : ";
for
(
size_t
i
=
0
;
i
<
v1
.
size
();
i
++
)
{
// cout << v1[i];
if
((
i
+
1
)
%
sample_size
==
0
)
{
// cout << endl;
if
(
i
<
v1
.
size
()
-
1
)
{
// cout << ((i + 1) / 40) + 1 << " : ";
}
}
else
{
// cout << ", ";
}
if
(
v1
[
i
]
==
0
)
{
sum
=
sum
+
1
;
}
else
{
sum
=
0
;
}
if
(
sum
==
sample_size
)
{
isContain
=
true
;
}
}
}
// cout << endl;
if
(
isContain
==
false
)
{
sum
=
0
;
// cout << (v2.size() + 1) / 40 + 1 << " : ";
for
(
size_t
i
=
0
;
i
<
v2
.
size
();
i
++
)
{
// cout << v2[i];
if
((
i
+
1
)
%
sample_size
==
0
)
{
// cout << endl;
if
(
i
<
v2
.
size
()
-
1
)
{
// cout << ((v2.size() + i + 1) / 40) + 1 << " : ";
}
}
else
{
// cout << ", ";
}
if
(
v2
[
i
]
==
0
)
{
sum
=
sum
+
1
;
}
else
{
sum
=
0
;
}
if
(
sum
==
sample_size
)
{
isContain
=
true
;
}
}
}
}
else
{
// cout << endl << "Sample size is too large" << endl;
}
delete_operator_batching
(
decr
);
return
isContain
;
}
bigpiseal3.5.1/native/examples/patternSearch/v2/patternSearch_decrypt_v2.cpp
0 → 100644
View file @
c6c9d2f5
#include <iomanip>
#include "seal_api.h"
#include "util.h"
using
namespace
seal
;
using
namespace
std
;
string
ciphertext_name
;
string
key_dir
;
// vector<int64_t> decrypt(size_t poly_d, size_t p_modulus, int &sample_size, string &ciphertext_dir);
vector
<
int64_t
>
decrypt
(
int
&
sample_size
,
string
&
ciphertext_dir
);
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
!=
4
)
{
// cout << "[ERROR] please enter /full/path/to/file/to/decrypt full/path/key " << endl;
// cout << "[ERROR] please enter prefix_file_to_decrypt full/path/key /full/path/to/storage" << endl;
cout
<<
"[ERROR] please enter a ciphertext file path, sample size and secret key path"
<<
endl
;
return
-
1
;
}
else
{
string
dir
=
argv
[
1
];
int
sample_size
=
atol
(
argv
[
2
]);
key_dir
=
argv
[
3
];
vector
<
int64_t
>
result
=
decrypt
(
sample_size
,
dir
);
for
(
int
i
=
0
;
i
<
result
.
size
();
++
i
)
{
std
::
cout
<<
result
[
i
]
<<
' '
;
}
std
::
cout
<<
endl
;
return
0
;
}
}
vector
<
int64_t
>
decrypt
(
int
&
sample_size
,
string
&
ciphertext_dir
)
{
struct
decryptor_t
decr
;
init_operator_batching
(
decr
,
key_dir
);
// init_operator_batching(2048, 4294967296, decr, key_dir);
// init_operator_batching(4096, 4294967296, decr, key_dir);
// init_operator_batching(8192, 4294967296, decr, key_dir);
// init_operator_batching(16384, 4294967296, decr, key_dir);
// init_operator_batching(32768, 4294967296, decr, key_dir);
vector
<
int64_t
>
v
;
if
(
sample_size
<=
decr
.
bcode
->
slot_count
()
/
2
)
{
Ciphertext
cipher_matrix
;
vector
<
int64_t
>
pod_matrix
;
load_ciphertext
(
decr
,
cipher_matrix
,
ciphertext_dir
);
pod_matrix
=
decrypt_ciphermatrix
(
decr
,
cipher_matrix
);
for
(
size_t
i
=
0
;
i
<
sample_size
;
i
++
)
{
v
.
push_back
(
pod_matrix
[
i
]);
}
}
else
{
// cout << endl << "Sample size is too large" << endl;
}
delete_operator_batching
(
decr
);
return
v
;
}
bigpiseal3.5.1/native/examples/patternSearch/v2/patternSearch_encrypt_v2.cpp
0 → 100644
View file @
c6c9d2f5
#include "seal_api.h"
using
namespace
seal
;
using
namespace
std
;
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
!=
6
)
{
// cout << "[ERROR] please enter 1 plaintext values, prefix pathstorage(exists) " << endl;
cout
<<
"[ERROR] please enter plaintext vector value (eg. 75 67 8 23 076 2 23), output ciphertext file name or "
"prefix, ciphertext output file directory, sample size and public key path"
<<
endl
;
return
-
1
;
}
else
{
string
plaintext
=
argv
[
1
];
string
ciphertext_name
=
argv
[
2
];
string
ciphertext_dir
=
argv
[
3
];
int
sample_size
=
atol
(
argv
[
4
]);
string
key_dir
=
argv
[
5
];
struct
encryptor_t
encr
;
init_operator_batching
(
encr
,
key_dir
);
stringstream
ss
;
ss
<<
plaintext
;
vector
<
int64_t
>
pod_matrix
;
int64_t
x
=
0
;
while
(
ss
>>
x
)
{
pod_matrix
.
push_back
(
x
);
}
if
(
pod_matrix
.
size
()
<=
encr
.
bcode
->
slot_count
()
/
2
&&
pod_matrix
.
size
()
<=
sample_size
)
{
Ciphertext
encrypted_matrix
;
init_ciphermatrix
(
encr
,
pod_matrix
,
encrypted_matrix
);
save_ciphertext
(
encrypted_matrix
,
ciphertext_dir
+
"/"
+
ciphertext_name
+
".ct"
);
delete_operator_batching
(
encr
);
return
0
;
}
else
{
delete_operator_batching
(
encr
);
return
-
1
;
}
// delete_operator_batching(encr);
// return 0;
}
}
bigpiseal3.5.1/native/examples/patternSearch/v2/patternSearch_evaluate_v2.cpp
0 → 100644
View file @
c6c9d2f5
#include <iostream>
#include "seal_api.h"
#include "util.h"
// #include <algorithm>
// #include <iterator>
// #include <vector>
// #include <filesystem>
using
namespace
seal
;
using
namespace
std
;
void
sub_ciphertext
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct1
,
Ciphertext
&
ct2
,
Ciphertext
&
ct_out
);
void
add_ciphertext
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct1
,
Ciphertext
&
ct2
,
Ciphertext
&
ct_out
);
void
multiply_ciphertext
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct1
,
Ciphertext
&
ct2
,
Ciphertext
&
ct_out
);
bool
is_number
(
const
string
&
s
);
void
printStrVector
(
const
vector
<
string
>
&
v
);
vector
<
vector
<
string
>>
split_ends
(
const
vector
<
string
>
&
data
,
const
vector
<
int
>
&
ends
);
void
multiply_ciphertexts
(
struct
evaluator_t
&
op_st
,
vector
<
Ciphertext
>
&
cts
,
Ciphertext
&
ct_out
);
void
relinearize_inplace
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct
);
void
rescale_to_next_inplace
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct
);
void
multiply_inplace_ciphertext
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct1
,
Ciphertext
&
ct2
);
void
relinearize
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct
,
Ciphertext
&
ct_out
);
void
sub_inplace_ciphertext
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct1
,
Ciphertext
&
ct2
);
void
negate_inplace__ciphertext
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct
);
void
add_plain_inplace_ciphertext
(
struct
evaluator_t
&
op_st
,
struct
Ciphertext
&
ct
,
const
Plaintext
&
plain
);
void
multiply_plain_inplace
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct
,
const
Plaintext
&
plain
);
void
add_many_ciphertext
(
struct
evaluator_t
&
op_st
,
vector
<
Ciphertext
>
&
cts
,
Ciphertext
&
ct_out
);
void
exponentiate_inplace_ciphertext
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct
,
uint64_t
&
exponent
);
void
sub_plain_inplace_ciphertext
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct
,
const
Plaintext
&
plain
);
void
mod_switch_to_next_inplace_ciphertext
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct
);
int
simpleCheck
(
string
&
source
,
vector
<
string
>
&
data
,
string
&
result_name
,
string
&
result_dir
,
int
&
sample_size
,
string
&
key_dir
);
int
checkSq
(
string
&
source
,
vector
<
string
>
&
data
,
string
&
result_name
,
string
&
result_dir
,
int
&
sample_size
,
string
&
key_dir
);
Ciphertext
check
(
string
&
source
,
vector
<
string
>
&
data
,
string
&
result_name
,
string
&
result_dir
,
int
&
sample_size
,
string
&
key_dir
,
struct
encryptor_t
&
encr
,
struct
evaluator_t
&
eval
);
// string relink_key_path;
// string galois_key_path;
// string public_key_path;
string
key_dir
=
""
;
int
main
(
int
argc
,
char
**
argv
)
{
// input processing - begin
// string result_name = argv[argc - 6];
// string result_dir = argv[argc - 5];
// int sample_size = atoi(argv[argc - 4]);
// relink_key_path = argv[argc - 3];
// galois_key_path = argv[argc - 2];
// public_key_path = argv[argc - 1];
string
source
=
argv
[
1
];
string
result_name
=
argv
[
argc
-
4
];
string
result_dir
=
argv
[
argc
-
3
];
int
sample_size
=
atoi
(
argv
[
argc
-
2
]);
key_dir
=
argv
[
argc
-
1
];
vector
<
string
>
data
;
for
(
int
i
=
2
;
i
<
argc
-
4
;
i
++
)
{
data
.
push_back
(
argv
[
i
]);
}
// if (source == "" || data.size() == 0 || result_name == "" || result_dir == "" || sample_size == 0 ||
// relink_key_path == "" || galois_key_path == "" || public_key_path == "")
if
(
source
==
""
||
data
.
size
()
==
0
||
result_name
==
""
||
result_dir
==
""
||
sample_size
==
0
||
key_dir
==
""
)
{
// error handling
cout
<<
"[ERROR] please enter a source path, data paths, output ciphertext file name or prefix, output "
"ciphertext directory, sample size, linking key path, galois key path and public key path"
<<
endl
;
return
-
1
;
}
// input processing - end
// simple algo
// int result = simpleCheck(source, data, result_name, result_dir, sample_size, key_dir);
// sequence algo
int
result
=
checkSq
(
source
,
data
,
result_name
,
result_dir
,
sample_size
,
key_dir
);
// error handling
if
(
result
==
-
1
)
{
fprintf
(
stderr
,
"error!
\n
"
);
}
else
{
cout
<<
"done"
;
}
// checkSq(source, data, result_name, result_dir, sample_size, relink_key_path, galois_key_path, public_key_path);
return
result
;
}
int
simpleCheck
(
string
&
source
,
vector
<
string
>
&
data
,
string
&
result_name
,
string
&
result_dir
,
int
&
sample_size
,
string
&
key_dir
)
{
struct
evaluator_t
eval
;
init_operator_batching
(
eval
,
key_dir
);
struct
encryptor_t
encr
;
init_operator_batching
(
encr
,
key_dir
);
// cout << sample_size*data.size() << endl;
// cout << encr.bcode->slot_count() << endl;
if
(
sample_size
*
data
.
size
()
>
encr
.
bcode
->
slot_count
()
||
sample_size
>
encr
.
bcode
->
slot_count
()
/
2
)
{
// error handling
delete_operator_batching
(
encr
);
delete_operator_batching
(
eval
);
return
-
1
;
}
else
{
Ciphertext
encrypted_result_matrix
;
vector
<
int64_t
>
result_matrix
;
init_ciphermatrix
(
encr
,
result_matrix
,
encrypted_result_matrix
);
vector
<
int64_t
>
dummy_matrix
;
for
(
size_t
i
=
0
;
i
<
sample_size
;
i
++
)
{
dummy_matrix
.
push_back
(
1
);
}
Ciphertext
encrypted_dummy_matrix
;
init_ciphermatrix
(
encr
,
dummy_matrix
,
encrypted_dummy_matrix
);
// normalize input data if its size is odd
int
normalized_data_size
;
if
(
data
.
size
()
%
2
==
0
)
{
normalized_data_size
=
data
.
size
();
}
else
{
normalized_data_size
=
data
.
size
()
+
1
;
}
int
required_range
=
normalized_data_size
*
sample_size
;
int
required_no_row_elements
=
required_range
/
2
;
int
required_range_row
=
required_range
/
2
;
// create padding matrix
int
padding_slots
=
(
encr
.
bcode
->
slot_count
()
/
2
)
-
required_range_row
;
vector
<
int64_t
>
padding_matrix
(
encr
.
bcode
->
slot_count
(),
0ULL
);
for
(
size_t
i
=
0
;
i
<
padding_slots
;
i
++
)
{
padding_matrix
[
required_no_row_elements
+
i
]
=
1
;
padding_matrix
[
encr
.
bcode
->
slot_count
()
-
i
]
=
1
;
}
Ciphertext
encrypted_padding_matrix
;
init_ciphermatrix
(
encr
,
padding_matrix
,
encrypted_padding_matrix
);
if
(
required_range_row
<=
encr
.
bcode
->
slot_count
()
&&
required_range_row
>
0
)
{
for
(
int
index
=
0
;
index
<
normalized_data_size
/
2
;
index
++
)
{
Ciphertext
ct1
,
ct2
,
ct3
;
Ciphertext
temp1
,
temp2
;
// cout << "[INFO] loading ciphertext 1" << endl;
load_ciphertext
(
eval
,
ct1
,
source
);
// cout << "[INFO] loading ciphertext 2" << endl;
load_ciphertext
(
eval
,
ct2
,
data
.
at
(
index
));
sub_ciphertext
(
eval
,
ct1
,
ct2
,
temp1
);
if
((
normalized_data_size
/
2
)
+
index
<
data
.
size
())
{
// cout << "[INFO] loading ciphertext 3" << endl;
load_ciphertext
(
eval
,
ct3
,
data
.
at
((
normalized_data_size
/
2
)
+
index
));
sub_ciphertext
(
eval
,
ct1
,
ct3
,
temp2
);
}
else
{
// add dummy vector for oddy data
temp2
=
encrypted_dummy_matrix
;
}
eval
.
eval
->
rotate_columns_inplace
(
temp2
,
eval
.
gk
);
add_ciphertext
(
eval
,
temp1
,
temp2
,
temp1
);
add_ciphertext
(
eval
,
temp1
,
encrypted_result_matrix
,
encrypted_result_matrix
);
// avoid the last shift
if
(
index
+
1
!=
(
normalized_data_size
/
2
))
{
eval
.
eval
->
rotate_rows_inplace
(
encrypted_result_matrix
,
-
sample_size
,
eval
.
gk
);
}
}
// add renmaining padding slots
add_ciphertext
(
eval
,
encrypted_result_matrix
,
encrypted_padding_matrix
,
encrypted_result_matrix
);
}
save_ciphertext
(
encrypted_result_matrix
,
result_dir
+
"/"
+
result_name
+
".ct"
);
delete_operator_batching
(
encr
);
delete_operator_batching
(
eval
);
return
0
;
}
}
// int checkSq(
// string &source, vector<string> &data, string &result_name, string &result_dir, int &sample_size,
// string &relink_key_path, string &galois_key_path, string &public_key_path)
int
checkSq
(
string
&
source
,
vector
<
string
>
&
data
,
string
&
result_name
,
string
&
result_dir
,
int
&
sample_size
,
string
&
key_dir
)
{
struct
evaluator_t
eval
;
// init_operator_batching(2048, 4294967296, eval, relink_key_path, galois_key_path);
// init_operator_batching(4096, 4294967296, eval, relink_key_path, galois_key_path);
// init_operator_batching(8192, 4294967296, eval, relink_key_path, galois_key_path);
// init_operator_batching(16384, 4294967296, eval, relink_key_path, galois_key_path);
// init_operator_batching(32768, 4294967296, eval, relink_key_path, galois_key_path);
init_operator_batching
(
eval
,
key_dir
);
struct
encryptor_t
encr
;
// init_operator_batching(4096, 4294967296, encr, public_key_path);
// init_operator_batching(8192, 4294967296, encr, public_key_path);
// init_operator_batching(16384, 4294967296, encr, public_key_path);
// init_operator_batching(32768, 4294967296, encr, public_key_path);
init_operator_batching
(
encr
,
key_dir
);
// if (sample_size*data.size() > encr.bcode->slot_count() || sample_size > encr.bcode->slot_count()/2)
if
(
sample_size
>
encr
.
bcode
->
slot_count
()
/
2
)
{
// error handling
delete_operator_batching
(
encr
);
delete_operator_batching
(
eval
);
return
-
1
;
}
else
{
// struct evaluator_t eval;
// // init_operator_batching(2048, 4294967296, eval, relink_key_path, galois_key_path);
// // init_operator_batching(4096, 4294967296, eval, relink_key_path, galois_key_path);
// init_operator_batching(8192, 4294967296, eval, relink_key_path, galois_key_path);
// // init_operator_batching(16384, 4294967296, eval, relink_key_path, galois_key_path);
// // init_operator_batching(32768, 4294967296, eval, relink_key_path, galois_key_path);
// struct encryptor_t encr;
// // init_operator_batching(4096, 4294967296, encr, public_key_path);
// init_operator_batching(8192, 4294967296, encr, public_key_path);
// // init_operator_batching(16384, 4294967296, encr, public_key_path);
// // init_operator_batching(32768, 4294967296, encr, public_key_path);
int
capacity
=
(
encr
.
bcode
->
slot_count
())
/
sample_size
;
// cout << capacity << endl;
// vector<string> v_temp;
// vector<string> v_v_temp;
// Ciphertext result;
vector
<
Ciphertext
>
v_result
;
int
nSq
=
data
.
size
()
/
capacity
;
for
(
size_t
i
=
0
;
i
<
nSq
;
i
++
)
{
Ciphertext
result
;
// cout << "sq : " << i << endl;
vector
<
string
>
v_temp
;
for
(
size_t
j
=
0
;
j
<
capacity
;
j
++
)
{
string
str
=
data
.
back
();
v_temp
.
push_back
(
str
);
data
.
pop_back
();
}
if
(
i
==
0
)
{
// cout << "sq : init" << endl;
// result = check(
// source, v_temp, result_name, result_dir, sample_size, relink_key_path, galois_key_path,
// public_key_path, encr, eval);
result
=
check
(
source
,
v_temp
,
result_name
,
result_dir
,
sample_size
,
key_dir
,
encr
,
eval
);
v_result
.
push_back
(
result
);
}
else
{
// cout << "sq : other" << endl;
// Ciphertext result2 = check(
// source, v_temp, result_name, result_dir, sample_size, relink_key_path, galois_key_path,
// public_key_path, encr, eval);
// multiply_ciphertext(eval, result2, result, result);
// relinearize_inplace(eval, result);
// result = check(
// source, v_temp, result_name, result_dir, sample_size, relink_key_path, galois_key_path,
// public_key_path, encr, eval);
result
=
check
(
source
,
v_temp
,
result_name
,
result_dir
,
sample_size
,
key_dir
,
encr
,
eval
);
v_result
.
push_back
(
result
);
}
}
if
(
data
.
size
()
%
capacity
!=
0
)
{
// cout << "oddy!!! " << endl;
// Ciphertext result = check(
// source, data, result_name, result_dir, sample_size, relink_key_path, galois_key_path,
// public_key_path, encr, eval);
Ciphertext
result
=
check
(
source
,
data
,
result_name
,
result_dir
,
sample_size
,
key_dir
,
encr
,
eval
);
// multiply_ciphertext(eval, result2, result, result);
// relinearize_inplace(eval, result);
v_result
.
push_back
(
result
);
}
Ciphertext
result
;
multiply_ciphertexts
(
eval
,
v_result
,
result
);
relinearize_inplace
(
eval
,
result
);
save_ciphertext
(
result
,
result_dir
+
"/"
+
result_name
+
".ct"
);
delete_operator_batching
(
encr
);
delete_operator_batching
(
eval
);
return
0
;
}
}
// Ciphertext check(
// string &source, vector<string> &data, string &result_name, string &result_dir, int &sample_size,
// string &relink_key_path, string &galois_key_path, string &public_key_path, struct encryptor_t &encr,
// struct evaluator_t &eval)
Ciphertext
check
(
string
&
source
,
vector
<
string
>
&
data
,
string
&
result_name
,
string
&
result_dir
,
int
&
sample_size
,
string
&
key_dir
,
struct
encryptor_t
&
encr
,
struct
evaluator_t
&
eval
)
{
// if (source == "" || data.size() == 0 || result_name == "" || result_dir == "" || sample_size == 0)
// {
// // error handling
// // return -1;
// }
// else
// {
Ciphertext
encrypted_result_matrix
;
vector
<
int64_t
>
result_matrix
;
init_ciphermatrix
(
encr
,
result_matrix
,
encrypted_result_matrix
);
vector
<
int64_t
>
dummy_matrix
;
for
(
size_t
i
=
0
;
i
<
sample_size
;
i
++
)
{
dummy_matrix
.
push_back
(
1
);
}
Ciphertext
encrypted_dummy_matrix
;
init_ciphermatrix
(
encr
,
dummy_matrix
,
encrypted_dummy_matrix
);
// normalize input data if its size is odd
int
normalized_data_size
;
if
(
data
.
size
()
%
2
==
0
)
{
normalized_data_size
=
data
.
size
();
}
else
{
normalized_data_size
=
data
.
size
()
+
1
;
}
int
required_range
=
normalized_data_size
*
sample_size
;
int
required_no_row_elements
=
required_range
/
2
;
int
required_range_row
=
required_range
/
2
;
// create padding matrix
int
padding_slots
=
(
encr
.
bcode
->
slot_count
()
/
2
)
-
required_range_row
;
vector
<
int64_t
>
padding_matrix
(
encr
.
bcode
->
slot_count
(),
0ULL
);
for
(
size_t
i
=
0
;
i
<
padding_slots
;
i
++
)
{
padding_matrix
[
required_no_row_elements
+
i
]
=
1
;
padding_matrix
[(
encr
.
bcode
->
slot_count
()
-
1
)
-
i
]
=
1
;
}
Ciphertext
encrypted_padding_matrix
;
init_ciphermatrix
(
encr
,
padding_matrix
,
encrypted_padding_matrix
);
if
(
required_range_row
<=
encr
.
bcode
->
slot_count
()
&&
required_range_row
>
0
)
{
for
(
int
index
=
0
;
index
<
normalized_data_size
/
2
;
index
++
)
{
Ciphertext
ct1
,
ct2
,
ct3
;
Ciphertext
temp1
,
temp2
;
// cout << "[INFO] loading ciphertext 1" << endl;
load_ciphertext
(
eval
,
ct1
,
source
);
// cout << "[INFO] loading ciphertext 2" << endl;
load_ciphertext
(
eval
,
ct2
,
data
.
at
(
index
));
sub_ciphertext
(
eval
,
ct1
,
ct2
,
temp1
);
if
((
normalized_data_size
/
2
)
+
index
<
data
.
size
())
{
// cout << "[INFO] loading ciphertext 3" << endl;
load_ciphertext
(
eval
,
ct3
,
data
.
at
((
normalized_data_size
/
2
)
+
index
));
sub_ciphertext
(
eval
,
ct1
,
ct3
,
temp2
);
}
else
{
// add dummy vector for oddy data
temp2
=
encrypted_dummy_matrix
;
}
eval
.
eval
->
rotate_columns_inplace
(
temp2
,
eval
.
gk
);
add_ciphertext
(
eval
,
temp1
,
temp2
,
temp1
);
add_ciphertext
(
eval
,
temp1
,
encrypted_result_matrix
,
encrypted_result_matrix
);
// avoid the last shift
if
(
index
+
1
!=
(
normalized_data_size
/
2
))
{
eval
.
eval
->
rotate_rows_inplace
(
encrypted_result_matrix
,
-
sample_size
,
eval
.
gk
);
}
}
// add renmaining padding slots
add_ciphertext
(
eval
,
encrypted_result_matrix
,
encrypted_padding_matrix
,
encrypted_result_matrix
);
}
// // save_ciphertext(encrypted_result_matrix, result_dir + "/" + result_name + ".ct");
// delete_operator_batching(eval);
return
encrypted_result_matrix
;
// }
}
void
sub_ciphertext
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct1
,
Ciphertext
&
ct2
,
Ciphertext
&
ct_out
)
{
op_st
.
eval
->
sub
(
ct1
,
ct2
,
ct_out
);
}
void
sub_inplace_ciphertext
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct1
,
Ciphertext
&
ct2
)
{
op_st
.
eval
->
sub_inplace
(
ct1
,
ct2
);
}
void
sub_plain_inplace_ciphertext
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct
,
const
Plaintext
&
plain
)
{
op_st
.
eval
->
sub_plain_inplace
(
ct
,
plain
);
}
void
negate_inplace_ciphertext
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct
)
{
op_st
.
eval
->
negate_inplace
(
ct
);
}
void
add_plain_inplace_ciphertext
(
struct
evaluator_t
&
op_st
,
struct
Ciphertext
&
ct
,
const
Plaintext
&
plain
)
{
op_st
.
eval
->
add_plain_inplace
(
ct
,
plain
);
}
void
add_ciphertext
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct1
,
Ciphertext
&
ct2
,
Ciphertext
&
ct_out
)
{
op_st
.
eval
->
add
(
ct1
,
ct2
,
ct_out
);
}
void
add_many_ciphertext
(
struct
evaluator_t
&
op_st
,
vector
<
Ciphertext
>
&
cts
,
Ciphertext
&
ct_out
)
{
op_st
.
eval
->
add_many
(
cts
,
ct_out
);
}
void
multiply_ciphertext
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct1
,
Ciphertext
&
ct2
,
Ciphertext
&
ct_out
)
{
op_st
.
eval
->
multiply
(
ct1
,
ct2
,
ct_out
);
}
void
multiply_inplace_ciphertext
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct1
,
Ciphertext
&
ct2
)
{
op_st
.
eval
->
multiply_inplace
(
ct1
,
ct2
);
}
void
multiply_ciphertexts
(
struct
evaluator_t
&
op_st
,
vector
<
Ciphertext
>
&
cts
,
Ciphertext
&
ct_out
)
{
op_st
.
eval
->
multiply_many
(
cts
,
op_st
.
lk
,
ct_out
);
}
void
multiply_plain_inplace
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct
,
const
Plaintext
&
plain
)
{
op_st
.
eval
->
multiply_plain_inplace
(
ct
,
plain
);
}
void
relinearize_inplace
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct
)
{
op_st
.
eval
->
relinearize_inplace
(
ct
,
op_st
.
lk
);
}
void
relinearize
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct
,
Ciphertext
&
ct_out
)
{
op_st
.
eval
->
relinearize
(
ct
,
op_st
.
lk
,
ct_out
);
}
void
rescale_to_next_inplace
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct
)
{
op_st
.
eval
->
rescale_to_next_inplace
(
ct
);
}
void
exponentiate_inplace_ciphertext
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct
,
uint64_t
&
exponent
)
{
op_st
.
eval
->
exponentiate_inplace
(
ct
,
exponent
,
op_st
.
lk
);
}
void
mod_switch_to_next_inplace_ciphertext
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct
)
{
op_st
.
eval
->
mod_switch_to_next_inplace
(
ct
);
}
bigpiseal3.5.1/native/examples/patternSearch/v2/patternSearch_genkey_v2.cpp
0 → 100644
View file @
c6c9d2f5
#include "seal_api.h"
using
namespace
std
;
using
namespace
seal
;
int
main
(
int
argc
,
char
**
argv
)
{
string
key_dir
=
argv
[
1
];
size_t
poly_d
=
4096
;
// Params option 1
int
bit_size
=
20
;
// Params option 2
// uint64_t plain_modulus = 1032193;
// vector<int> bit_sizes = { 36, 36, 37 };
// timeval t0, t1;
// unsigned long dt = 0;
// gettimeofday(&t0, NULL);
batching_generate_keys
(
poly_d
,
bit_size
,
key_dir
,
true
);
// batching_generate_keys(poly_d, bit_sizes, plain_modulus, key_dir, true);
// gettimeofday(&t1, NULL);
// dt = 1000000 * (t1.tv_sec - t0.tv_sec) + (t1.tv_usec - t0.tv_usec);
// cout << "[INFO] keys generation time in seconds: " << ((float)dt)/1000000 << endl;
return
0
;
}
bigpiseal3.5.1/native/examples/patternSearch/v2/seal_api.cpp
0 → 100644
View file @
c6c9d2f5
#include "seal_api.h"
/* namespaces */
using
namespace
std
;
using
namespace
seal
;
/* functions */
int
open_binary_file
(
ifstream
&
in_file
,
const
string
&
filename
)
{
int
ret
=
1
;
in_file
=
ifstream
(
filename
,
ios
::
binary
);
if
(
!
in_file
)
{
// cerr << "[ERRROR] file opening failure" << endl;
ret
=
0
;
}
return
ret
;
}
int
open_binary_file
(
ofstream
&
out_file
,
const
string
&
filename
)
{
int
ret
=
1
;
out_file
=
ofstream
(
filename
,
ios
::
binary
);
if
(
!
out_file
)
{
// cerr << "[ERRROR] file opening failure" << endl;
ret
=
0
;
}
return
ret
;
}
int
save_params
(
EncryptionParameters
&
params
,
const
string
&
filename
)
{
int
ret
=
1
;
ofstream
out_file
;
if
(
open_binary_file
(
out_file
,
filename
))
params
.
save
(
out_file
);
else
ret
=
0
;
return
ret
;
}
int
load_params
(
EncryptionParameters
&
params
,
const
string
&
filename
)
{
int
ret
=
1
;
ifstream
in_file
;
if
(
open_binary_file
(
in_file
,
filename
))
params
.
load
(
in_file
);
else
ret
=
0
;
return
ret
;
}
void
init_context
(
size_t
poly_d
,
size_t
p_modulus
,
shared_ptr
<
SEALContext
>
&
context
)
{
EncryptionParameters
params
(
scheme_type
::
BFV
);
params
.
set_poly_modulus_degree
(
poly_d
);
params
.
set_coeff_modulus
(
CoeffModulus
::
BFVDefault
(
poly_d
));
params
.
set_plain_modulus
(
p_modulus
);
save_params
(
params
,
"bfv_params.conf"
);
context
=
SEALContext
::
Create
(
params
);
print_context
(
context
);
}
void
init_context_batching
(
size_t
poly_d
,
int
bit_size
,
shared_ptr
<
SEALContext
>
&
context
,
const
std
::
string
&
key_dir
)
{
EncryptionParameters
params
(
scheme_type
::
BFV
);
params
.
set_poly_modulus_degree
(
poly_d
);
params
.
set_coeff_modulus
(
CoeffModulus
::
BFVDefault
(
poly_d
));
params
.
set_plain_modulus
(
PlainModulus
::
Batching
(
poly_d
,
bit_size
));
save_params
(
params
,
key_dir
+
"bfv_params.conf"
);
context
=
SEALContext
::
Create
(
params
);
print_context
(
context
);
}
void
init_context_batching
(
size_t
poly_d
,
vector
<
int
>
bit_sizes
,
std
::
uint64_t
plain_modulus
,
shared_ptr
<
SEALContext
>
&
context
,
const
std
::
string
&
key_dir
)
{
EncryptionParameters
params
(
scheme_type
::
BFV
);
params
.
set_poly_modulus_degree
(
poly_d
);
params
.
set_coeff_modulus
(
CoeffModulus
::
Create
(
poly_d
,
{
36
,
36
,
37
}));
params
.
set_plain_modulus
(
plain_modulus
);
save_params
(
params
,
key_dir
+
"bfv_params.conf"
);
context
=
SEALContext
::
Create
(
params
);
print_context
(
context
);
}
void
load_context
(
shared_ptr
<
SEALContext
>
&
context
,
const
string
&
filename
)
{
EncryptionParameters
params
;
load_params
(
params
,
filename
);
context
=
SEALContext
::
Create
(
params
);
print_context
(
context
);
}
/* print paramaeters function from examples.h */
void
print_context
(
shared_ptr
<
SEALContext
>
&
context
)
{
if
(
!
context
)
throw
invalid_argument
(
"[ERROR] context is not set"
);
auto
&
context_data
=
*
context
->
key_context_data
();
/* which scheme is used */
string
scheme_name
;
switch
(
context_data
.
parms
().
scheme
())
{
case
seal
::
scheme_type
::
BFV
:
scheme_name
=
"BFV"
;
break
;
case
seal
::
scheme_type
::
CKKS
:
scheme_name
=
"CKKS"
;
break
;
default:
throw
invalid_argument
(
"[ERROR] unsupported scheme"
);
}
// cout << "[CONTEXT] scheme: " << scheme_name << endl;
// cout << "[CONTEXT] poly_modulus_degree: " << context_data.parms().poly_modulus_degree() << endl;
/* Print the size of the true (product) coefficient modulus */
// cout << "[CONTEXT] coeff_modulus size: ";
// cout << context_data.total_coeff_modulus_bit_count() << " (";
auto
coeff_modulus
=
context_data
.
parms
().
coeff_modulus
();
size_t
coeff_modulus_size
=
coeff_modulus
.
size
();
for
(
size_t
i
=
0
;
i
<
coeff_modulus_size
-
1
;
i
++
)
// cout << coeff_modulus[i].bit_count() << " + ";
// cout << coeff_modulus.back().bit_count();
// cout << ") bits" << endl;
// cout << "[CONTEXT] coeff_modulus values: (" ;
for
(
int
i
=
0
;
i
<
(
coeff_modulus
.
size
()
-
1
);
++
i
)
{
// cout << coeff_modulus[i].value() << ",\t";
// cout << coeff_modulus[coeff_modulus.size() - 1].value() << ")" << endl;
}
/* For the BFV scheme print the plain_modulus parameter */
if
(
context_data
.
parms
().
scheme
()
==
seal
::
scheme_type
::
BFV
)
{
// cout << "[CONTEXT] plain_modulus: " << context_data.parms().plain_modulus().value() << endl;
}
}
int
save_key
(
PublicKey
&
k
,
const
string
&
filename
)
{
int
ret
=
1
;
ofstream
out_file
;
if
(
open_binary_file
(
out_file
,
filename
))
k
.
save
(
out_file
);
else
ret
=
0
;
return
ret
;
}
int
save_key
(
SecretKey
&
k
,
const
string
&
filename
)
{
int
ret
=
1
;
ofstream
out_file
;
if
(
open_binary_file
(
out_file
,
filename
))
k
.
save
(
out_file
);
else
ret
=
0
;
return
ret
;
}
int
save_key
(
RelinKeys
&
k
,
const
string
&
filename
)
{
int
ret
=
1
;
ofstream
out_file
;
if
(
open_binary_file
(
out_file
,
filename
))
k
.
save
(
out_file
);
else
ret
=
0
;
return
ret
;
}
int
save_key
(
Serializable
<
RelinKeys
>
&
k
,
const
string
&
filename
)
{
int
ret
=
1
;
ofstream
out_file
;
if
(
open_binary_file
(
out_file
,
filename
))
k
.
save
(
out_file
);
else
ret
=
0
;
return
ret
;
}
int
save_key
(
GaloisKeys
&
k
,
const
string
&
filename
)
{
int
ret
=
1
;
ofstream
out_file
;
if
(
open_binary_file
(
out_file
,
filename
))
k
.
save
(
out_file
);
else
ret
=
0
;
return
ret
;
}
int
save_key
(
Serializable
<
GaloisKeys
>
&
k
,
const
string
&
filename
)
{
int
ret
=
1
;
ofstream
out_file
;
if
(
open_binary_file
(
out_file
,
filename
))
k
.
save
(
out_file
);
else
ret
=
0
;
return
ret
;
}
int
load_key
(
shared_ptr
<
SEALContext
>
&
context
,
const
string
&
filename
,
PublicKey
&
k
)
{
int
ret
=
1
;
ifstream
in_file
;
if
(
open_binary_file
(
in_file
,
filename
))
k
.
load
(
context
,
in_file
);
else
ret
=
0
;
return
ret
;
}
int
load_key
(
shared_ptr
<
SEALContext
>
&
context
,
const
string
&
filename
,
SecretKey
&
k
)
{
int
ret
=
1
;
ifstream
in_file
;
if
(
open_binary_file
(
in_file
,
filename
))
k
.
load
(
context
,
in_file
);
else
ret
=
0
;
return
ret
;
}
int
load_key
(
shared_ptr
<
SEALContext
>
&
context
,
const
string
&
filename
,
RelinKeys
&
k
)
{
int
ret
=
1
;
ifstream
in_file
;
if
(
open_binary_file
(
in_file
,
filename
))
k
.
load
(
context
,
in_file
);
else
ret
=
0
;
return
ret
;
}
int
load_key
(
shared_ptr
<
SEALContext
>
&
context
,
const
string
&
filename
,
GaloisKeys
&
k
)
{
int
ret
=
1
;
ifstream
in_file
;
if
(
open_binary_file
(
in_file
,
filename
))
k
.
load
(
context
,
in_file
);
else
ret
=
0
;
return
ret
;
}
void
generate_keys
(
size_t
poly_d
,
size_t
p_modulus
,
bool
serializable
)
{
shared_ptr
<
SEALContext
>
context
;
init_context
(
poly_d
,
p_modulus
,
context
);
KeyGenerator
keygen
(
context
);
PublicKey
pk
=
keygen
.
public_key
();
save_key
(
pk
,
"bfv.pk"
);
SecretKey
sk
=
keygen
.
secret_key
();
save_key
(
sk
,
"bfv.sk"
);
if
(
serializable
)
{
Serializable
<
RelinKeys
>
lk
=
keygen
.
relin_keys
();
save_key
(
lk
,
"bfv.lk"
);
}
else
{
RelinKeys
lk
=
keygen
.
relin_keys_local
();
save_key
(
lk
,
"bfv.lk"
);
}
}
bool
suffix_exist
(
const
std
::
string
&
str
,
const
std
::
string
&
suffix
)
{
return
str
.
size
()
>=
suffix
.
size
()
&&
str
.
compare
(
str
.
size
()
-
suffix
.
size
(),
suffix
.
size
(),
suffix
)
==
0
;
}
/*
Helper function: Prints the parameters in a SEALContext.
*/
inline
void
print_parameters
(
std
::
shared_ptr
<
seal
::
SEALContext
>
context
)
{
// Verify parameters
if
(
!
context
)
{
throw
std
::
invalid_argument
(
"context is not set"
);
}
auto
&
context_data
=
*
context
->
key_context_data
();
/*
Which scheme are we using?
*/
std
::
string
scheme_name
;
switch
(
context_data
.
parms
().
scheme
())
{
case
seal
::
scheme_type
::
BFV
:
scheme_name
=
"BFV"
;
break
;
case
seal
::
scheme_type
::
CKKS
:
scheme_name
=
"CKKS"
;
break
;
default:
throw
std
::
invalid_argument
(
"unsupported scheme"
);
}
// cout << "/" << std::endl;
// cout << "| Encryption parameters :" << std::endl;
// cout << "| scheme: " << scheme_name << std::endl;
// cout << "| poly_modulus_degree: " << context_data.parms().poly_modulus_degree() << std::endl;
/*
Print the size of the true (product) coefficient modulus.
*/
// cout << "| coeff_modulus size: ";
// cout << context_data.total_coeff_modulus_bit_count() << " (";
auto
coeff_modulus
=
context_data
.
parms
().
coeff_modulus
();
std
::
size_t
coeff_modulus_size
=
coeff_modulus
.
size
();
// for (std::size_t i = 0; i < coeff_modulus_size - 1; i++)
// {
// cout << coeff_modulus[i].bit_count() << " + ";
// }
// cout << coeff_modulus.back().bit_count();
// cout << ") bits" << std::endl;
/*
For the BFV scheme print the plain_modulus parameter.
*/
// if (context_data.parms().scheme() == seal::scheme_type::BFV)
// {
// cout << "| plain_modulus: " << context_data.parms().plain_modulus().value() << std::endl;
// }
// cout << "\\" << std::endl;
}
void
batching_generate_keys
(
size_t
poly_d
,
int
bit_size
,
string
key_dir
,
bool
serializable
)
{
shared_ptr
<
SEALContext
>
context
;
// init_context_batching(poly_d, bit_size, context, key_dir);
// auto qualifiers = context->first_context_data()->qualifiers();
// cout << "Batching enabled: " << boolalpha << qualifiers.using_batching << endl;
string
keypath
(
""
);
string
keypath1
(
"/bfv.pk"
);
string
keypath2
(
"/bfv.sk"
);
string
keypath3
(
"/bfv.lk"
);
string
keypath4
(
"/bfv.gk"
);
string
bfv_params_path
(
key_dir
+
"/"
);
if
(
suffix_exist
(
key_dir
,
"/"
))
{
keypath1
=
"bfv.pk"
;
keypath2
=
"bfv.sk"
;
keypath3
=
"bfv.lk"
;
keypath4
=
"bfv.gk"
;
bfv_params_path
=
key_dir
;
}
init_context_batching
(
poly_d
,
bit_size
,
context
,
bfv_params_path
);
KeyGenerator
keygen
(
context
);
PublicKey
pk
=
keygen
.
public_key
();
keypath
.
append
(
key_dir
);
keypath
.
append
(
keypath1
);
// cout << "[INFO] Keypathname pk: " << keypath << endl;
save_key
(
pk
,
keypath
);
keypath
=
""
;
keypath
.
append
(
key_dir
);
keypath
.
append
(
keypath2
);
SecretKey
sk
=
keygen
.
secret_key
();
// cout << "[INFO] Keypathname sk: " << keypath << endl;
save_key
(
sk
,
keypath
);
keypath
=
""
;
keypath
.
append
(
key_dir
);
keypath
.
append
(
keypath3
);
// cout << "[INFO] Keypathname lk: " << keypath << endl;
if
(
serializable
)
{
Serializable
<
RelinKeys
>
lk
=
keygen
.
relin_keys
();
save_key
(
lk
,
keypath
);
}
else
{
RelinKeys
lk
=
keygen
.
relin_keys_local
();
save_key
(
lk
,
keypath
);
}
keypath
=
""
;
keypath
.
append
(
key_dir
);
keypath
.
append
(
keypath4
);
// cout << "[INFO] Keypathname gk: " << keypath << endl;
if
(
serializable
)
{
Serializable
<
GaloisKeys
>
gk
=
keygen
.
galois_keys
();
save_key
(
gk
,
keypath
);
}
else
{
GaloisKeys
gk
=
keygen
.
galois_keys_local
();
save_key
(
gk
,
keypath
);
}
// print_parameters(context);
}
void
batching_generate_keys
(
size_t
poly_d
,
vector
<
int
>
bit_sizes
,
std
::
uint64_t
plain_modulus
,
string
key_dir
,
bool
serializable
)
{
shared_ptr
<
SEALContext
>
context
;
// init_context_batching(poly_d, bit_sizes, plain_modulus, context, key_dir);
// auto qualifiers = context->first_context_data()->qualifiers();
// cout << "Batching enabled: " << boolalpha << qualifiers.using_batching << endl;
string
keypath
(
""
);
string
keypath1
(
"/bfv.pk"
);
string
keypath2
(
"/bfv.sk"
);
string
keypath3
(
"/bfv.lk"
);
string
keypath4
(
"/bfv.gk"
);
string
bfv_params_path
(
key_dir
+
"/"
);
if
(
suffix_exist
(
key_dir
,
"/"
))
{
keypath1
=
"bfv.pk"
;
keypath2
=
"bfv.sk"
;
keypath3
=
"bfv.lk"
;
keypath4
=
"bfv.gk"
;
bfv_params_path
=
key_dir
;
}
init_context_batching
(
poly_d
,
bit_sizes
,
plain_modulus
,
context
,
bfv_params_path
);
KeyGenerator
keygen
(
context
);
PublicKey
pk
=
keygen
.
public_key
();
keypath
.
append
(
key_dir
);
keypath
.
append
(
keypath1
);
// cout << "[INFO] Keypathname pk: " << keypath << endl;
save_key
(
pk
,
keypath
);
keypath
=
""
;
keypath
.
append
(
key_dir
);
keypath
.
append
(
keypath2
);
SecretKey
sk
=
keygen
.
secret_key
();
// cout << "[INFO] Keypathname sk: " << keypath << endl;
save_key
(
sk
,
keypath
);
keypath
=
""
;
keypath
.
append
(
key_dir
);
keypath
.
append
(
keypath3
);
// cout << "[INFO] Keypathname lk: " << keypath << endl;
if
(
serializable
)
{
Serializable
<
RelinKeys
>
lk
=
keygen
.
relin_keys
();
save_key
(
lk
,
keypath
);
}
else
{
RelinKeys
lk
=
keygen
.
relin_keys_local
();
save_key
(
lk
,
keypath
);
}
keypath
=
""
;
keypath
.
append
(
key_dir
);
keypath
.
append
(
keypath4
);
// cout << "[INFO] Keypathname gk: " << keypath << endl;
if
(
serializable
)
{
Serializable
<
GaloisKeys
>
gk
=
keygen
.
galois_keys
();
save_key
(
gk
,
keypath
);
}
else
{
GaloisKeys
gk
=
keygen
.
galois_keys_local
();
save_key
(
gk
,
keypath
);
}
// print_parameters(context);
}
void
init_operator
(
struct
encryptor_t
&
op_st
)
{
load_context
(
op_st
.
context
,
"bfv_params.conf"
);
PublicKey
pk
;
load_key
(
op_st
.
context
,
"bfv.pk"
,
pk
);
op_st
.
encr
=
new
Encryptor
(
op_st
.
context
,
pk
);
op_st
.
icode
=
new
IntegerEncoder
(
op_st
.
context
);
}
void
init_operator
(
struct
encryptor_t
&
op_st
,
const
string
&
key_dir
)
{
string
bfv_params_path
(
""
);
string
bfv_params_path1
(
"/bfv_params.conf"
);
bfv_params_path
=
""
;
bfv_params_path
.
append
(
key_dir
);
bfv_params_path
.
append
(
bfv_params_path1
);
// cout << "[INFO] bfvparams: " << bfv_params_path << endl;
load_context
(
op_st
.
context
,
bfv_params_path
);
PublicKey
pk
;
string
keypath
(
""
);
string
keypath1
(
"bfv.pk"
);
keypath
.
append
(
key_dir
);
keypath
.
append
(
keypath1
);
// cout << "[INFO] Keypath encrypt: " << keypath << endl;
load_key
(
op_st
.
context
,
keypath
,
pk
);
op_st
.
encr
=
new
Encryptor
(
op_st
.
context
,
pk
);
op_st
.
icode
=
new
IntegerEncoder
(
op_st
.
context
);
}
void
init_operator_batching
(
struct
encryptor_t
&
op_st
,
const
string
&
key_dir
)
{
init_operator
(
op_st
,
key_dir
);
op_st
.
bcode
=
new
BatchEncoder
(
op_st
.
context
);
}
void
delete_operator
(
struct
encryptor_t
&
op_st
)
{
delete
op_st
.
encr
;
delete
op_st
.
icode
;
}
void
delete_operator_batching
(
struct
encryptor_t
&
op_st
)
{
delete_operator
(
op_st
);
delete
op_st
.
bcode
;
}
void
init_operator
(
struct
decryptor_t
&
op_st
)
{
load_context
(
op_st
.
context
,
"bfv_params.conf"
);
SecretKey
sk
;
load_key
(
op_st
.
context
,
"bfv.sk"
,
sk
);
op_st
.
decr
=
new
Decryptor
(
op_st
.
context
,
sk
);
op_st
.
icode
=
new
IntegerEncoder
(
op_st
.
context
);
}
void
init_operator
(
struct
decryptor_t
&
op_st
,
const
std
::
string
&
key_dir
)
{
string
bfv_params_path
(
""
);
string
bfv_params_path1
(
"/bfv_params.conf"
);
bfv_params_path
=
""
;
bfv_params_path
.
append
(
key_dir
);
bfv_params_path
.
append
(
bfv_params_path1
);
// cout << "[INFO] bfvparams: " << bfv_params_path << endl;
load_context
(
op_st
.
context
,
bfv_params_path
);
SecretKey
sk
;
string
keypath
(
""
);
string
keypath1
(
"bfv.sk"
);
keypath
.
append
(
key_dir
);
keypath
.
append
(
keypath1
);
// cout << "[INFO] Keypath decrypt: " << keypath << endl;
load_key
(
op_st
.
context
,
keypath
,
sk
);
op_st
.
decr
=
new
Decryptor
(
op_st
.
context
,
sk
);
op_st
.
icode
=
new
IntegerEncoder
(
op_st
.
context
);
}
void
init_operator_batching
(
struct
decryptor_t
&
op_st
,
const
string
&
key_dir
)
{
init_operator
(
op_st
,
key_dir
);
op_st
.
bcode
=
new
BatchEncoder
(
op_st
.
context
);
}
void
delete_operator
(
struct
decryptor_t
&
op_st
)
{
delete
op_st
.
decr
;
delete
op_st
.
icode
;
}
void
delete_operator_batching
(
struct
decryptor_t
&
op_st
)
{
delete_operator
(
op_st
);
delete
op_st
.
bcode
;
}
void
init_operator
(
struct
evaluator_t
&
op_st
)
{
load_context
(
op_st
.
context
,
"bfv_params.conf"
);
load_key
(
op_st
.
context
,
"bfv.lk"
,
op_st
.
lk
);
op_st
.
eval
=
new
Evaluator
(
op_st
.
context
);
}
void
init_operator
(
struct
evaluator_t
&
op_st
,
const
string
&
relink_key_path
)
{
load_context
(
op_st
.
context
,
"bfv_params.conf"
);
load_key
(
op_st
.
context
,
relink_key_path
,
op_st
.
lk
);
op_st
.
eval
=
new
Evaluator
(
op_st
.
context
);
}
void
init_operator_batching
(
struct
evaluator_t
&
op_st
,
const
string
&
key_dir
)
{
string
bfv_params_path
(
""
);
string
bfv_params_path1
(
"/bfv_params.conf"
);
bfv_params_path
=
""
;
bfv_params_path
.
append
(
key_dir
);
bfv_params_path
.
append
(
bfv_params_path1
);
// cout << "[INFO] bfvparams: " << bfv_params_path << endl;
load_context
(
op_st
.
context
,
bfv_params_path
);
string
keypath
(
""
);
string
keypath1
(
"bfv.lk"
);
keypath
.
append
(
key_dir
);
keypath
.
append
(
keypath1
);
// cout << "[INFO] Keypath evaluator: " << keypath << endl;
load_key
(
op_st
.
context
,
keypath
,
op_st
.
lk
);
string
keypath3
(
""
);
string
keypath4
(
"bfv.gk"
);
keypath3
.
append
(
key_dir
);
keypath3
.
append
(
keypath4
);
// cout << "[INFO] Keypath evaluator: " << keypath3 << endl;
load_key
(
op_st
.
context
,
keypath3
,
op_st
.
gk
);
op_st
.
eval
=
new
Evaluator
(
op_st
.
context
);
}
void
delete_operator
(
struct
evaluator_t
&
op_st
)
{
delete
op_st
.
eval
;
}
void
delete_operator_batching
(
struct
evaluator_t
&
op_st
)
{
delete_operator
(
op_st
);
}
void
init_plaintext
(
struct
encryptor_t
&
op_st
,
int64_t
plain
,
Plaintext
&
pt
)
{
pt
=
Plaintext
(
op_st
.
icode
->
encode
(
plain
));
}
void
init_ciphertext
(
struct
encryptor_t
&
op_st
,
int64_t
plain
,
Ciphertext
&
ct
)
{
// cout << "[INFO] encrypting: " << endl;
op_st
.
encr
->
encrypt
(
Plaintext
(
op_st
.
icode
->
encode
(
plain
)),
ct
);
// cout << plain << endl;
}
void
init_ciphermatrix
(
struct
encryptor_t
&
op_st
,
vector
<
int64_t
>
&
plain_matrix
,
Ciphertext
&
encrypted_matrix
)
{
// cout << "[INFO] encrypting: " << endl;
Plaintext
plaintext_matrix
;
// BatchEncoder batch_encoder(op_st.context);
// batch_encoder.encode(plain_matrix, plaintext_matrix);
op_st
.
bcode
->
encode
(
plain_matrix
,
plaintext_matrix
);
op_st
.
encr
->
encrypt
(
plaintext_matrix
,
encrypted_matrix
);
// cout << plain << endl;
}
void
decrypt_ciphertext
(
struct
decryptor_t
&
op_st
,
Ciphertext
&
ct
)
{
Plaintext
pt
;
op_st
.
decr
->
decrypt
(
ct
,
pt
);
int64_t
res
=
op_st
.
icode
->
decode_int64
(
pt
);
// cout << "[INFO] decrypted result: " << res << endl;
}
int64_t
decrypt_ciphertext_and_return_value
(
struct
decryptor_t
&
op_st
,
Ciphertext
&
ct
)
{
Plaintext
pt
;
op_st
.
decr
->
decrypt
(
ct
,
pt
);
int64_t
res
=
op_st
.
icode
->
decode_int64
(
pt
);
// cout << "[INFO] Decrypted result: " << res << endl;
return
res
;
}
vector
<
int64_t
>
decrypt_ciphermatrix
(
struct
decryptor_t
&
op_st
,
Ciphertext
&
ct
)
{
Plaintext
pt
;
op_st
.
decr
->
decrypt
(
ct
,
pt
);
vector
<
int64_t
>
pod_matrix
;
BatchEncoder
batch_encoder
(
op_st
.
context
);
batch_encoder
.
decode
(
pt
,
pod_matrix
);
// print_matrix(pod_matrix, 3);
return
pod_matrix
;
}
int
save_plaintext
(
Plaintext
&
pt
,
const
string
&
filename
)
{
int
ret
=
1
;
ofstream
out_file
;
if
(
open_binary_file
(
out_file
,
filename
))
pt
.
save
(
out_file
);
else
ret
=
0
;
return
ret
;
}
int
save_ciphertext
(
Ciphertext
&
ct
,
const
string
&
filename
)
{
int
ret
=
1
;
ofstream
out_file
;
if
(
open_binary_file
(
out_file
,
filename
))
ct
.
save
(
out_file
);
else
ret
=
0
;
return
ret
;
}
int
load_plaintext
(
shared_ptr
<
SEALContext
>
&
context
,
Plaintext
&
pt
,
const
string
&
filename
)
{
int
ret
=
1
;
ifstream
in_file
;
if
(
open_binary_file
(
in_file
,
filename
))
pt
.
load
(
context
,
in_file
);
else
ret
=
0
;
return
ret
;
}
int
load_plaintext
(
struct
evaluator_t
&
op_st
,
Plaintext
&
pt
,
const
string
&
filename
)
{
return
load_plaintext
(
op_st
.
context
,
pt
,
filename
);
}
int
load_plaintext
(
struct
decryptor_t
&
op_st
,
Plaintext
&
pt
,
const
string
&
filename
)
{
return
load_plaintext
(
op_st
.
context
,
pt
,
filename
);
}
int
load_ciphertext
(
shared_ptr
<
SEALContext
>
&
context
,
Ciphertext
&
ct
,
const
string
&
filename
)
{
int
ret
=
1
;
ifstream
in_file
;
if
(
open_binary_file
(
in_file
,
filename
))
ct
.
load
(
context
,
in_file
);
else
ret
=
0
;
return
ret
;
}
int
load_ciphertext
(
struct
evaluator_t
&
op_st
,
Ciphertext
&
ct
,
const
string
&
filename
)
{
return
load_ciphertext
(
op_st
.
context
,
ct
,
filename
);
}
int
load_ciphertext
(
struct
decryptor_t
&
op_st
,
Ciphertext
&
ct
,
const
string
&
filename
)
{
return
load_ciphertext
(
op_st
.
context
,
ct
,
filename
);
}
bigpiseal3.5.1/native/examples/patternSearch/v2/seal_api.h
0 → 100644
View file @
c6c9d2f5
#ifndef _SEAL_API_H_
#define _SEAL_API_H_
/* includes */
#include <sys/time.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <cstdio>
#include <cassert>
#include <cstdint>
#include <boost/lexical_cast.hpp>
#include "seal/seal.h"
/* definitions */
struct
encryptor_t
{
std
::
shared_ptr
<
seal
::
SEALContext
>
context
;
seal
::
Encryptor
*
encr
;
seal
::
BatchEncoder
*
bcode
;
seal
::
IntegerEncoder
*
icode
;
};
struct
decryptor_t
{
std
::
shared_ptr
<
seal
::
SEALContext
>
context
;
seal
::
Decryptor
*
decr
;
seal
::
BatchEncoder
*
bcode
;
seal
::
IntegerEncoder
*
icode
;
};
struct
evaluator_t
{
std
::
shared_ptr
<
seal
::
SEALContext
>
context
;
seal
::
RelinKeys
lk
;
seal
::
GaloisKeys
gk
;
seal
::
Evaluator
*
eval
;
};
/* prototypes */
/** for binary files management **/
int
open_binary_file
(
std
::
ifstream
&
in_file
,
const
std
::
string
&
filename
);
int
open_binary_file
(
std
::
ofstream
&
out_file
,
const
std
::
string
&
filename
);
/** for context management **/
int
save_params
(
seal
::
EncryptionParameters
&
params
,
const
std
::
string
&
filename
);
int
load_params
(
seal
::
EncryptionParameters
&
params
,
const
std
::
string
&
filename
);
void
init_context
(
size_t
poly_d
,
size_t
p_modulus
,
std
::
shared_ptr
<
seal
::
SEALContext
>&
context
);
void
load_context
(
std
::
shared_ptr
<
seal
::
SEALContext
>&
context
,
const
std
::
string
&
filename
);
void
print_context
(
std
::
shared_ptr
<
seal
::
SEALContext
>&
context
);
/** for key management **/
int
save_key
(
seal
::
PublicKey
&
k
,
const
std
::
string
&
filename
);
int
save_key
(
seal
::
SecretKey
&
k
,
const
std
::
string
&
filename
);
int
save_key
(
seal
::
RelinKeys
&
k
,
const
std
::
string
&
filename
);
int
save_key
(
seal
::
GaloisKeys
&
k
,
const
std
::
string
&
filename
);
int
load_key
(
std
::
shared_ptr
<
seal
::
SEALContext
>&
context
,
const
std
::
string
&
filename
,
seal
::
PublicKey
&
k
);
int
load_key
(
std
::
shared_ptr
<
seal
::
SEALContext
>&
context
,
const
std
::
string
&
filename
,
seal
::
SecretKey
&
k
);
int
load_key
(
std
::
shared_ptr
<
seal
::
SEALContext
>&
context
,
const
std
::
string
&
filename
,
seal
::
RelinKeys
&
k
);
void
generate_keys
(
size_t
poly_d
,
size_t
p_modulus
,
bool
seriablizable
=
false
);
void
batching_generate_keys
(
size_t
poly_d
,
int
bit_size
,
const
std
::
string
key_path
,
bool
serializable
=
false
);
void
batching_generate_keys
(
size_t
poly_d
,
std
::
vector
<
int
>
bit_sizes
,
std
::
uint64_t
plain_modulus
,
std
::
string
key_dir
,
bool
serializable
=
false
);
/** for homomorphic operators management **/
void
init_operator
(
struct
encryptor_t
&
op_st
);
void
init_operator
(
struct
encryptor_t
&
op_st
,
const
std
::
string
&
public_key_path
);
void
init_operator_batching
(
struct
encryptor_t
&
op_st
,
const
std
::
string
&
key_dir
);
void
init_operator
(
struct
decryptor_t
&
op_st
);
void
init_operator
(
struct
decryptor_t
&
op_st
,
const
std
::
string
&
secret_key_path
);
void
init_operator_batching
(
struct
decryptor_t
&
op_st
,
const
std
::
string
&
key_dir
);
void
init_operator
(
struct
evaluator_t
&
op_st
);
void
init_operator
(
struct
evaluator_t
&
op_st
,
const
std
::
string
&
relink_key_path
);
void
init_operator_batching
(
struct
evaluator_t
&
op_st
,
const
std
::
string
&
key_dir
);
void
delete_operator
(
struct
encryptor_t
&
op_st
);
void
delete_operator_batching
(
struct
encryptor_t
&
op_st
);
void
delete_operator
(
struct
decryptor_t
&
op_st
);
void
delete_operator_batching
(
struct
decryptor_t
&
op_st
);
void
delete_operator
(
struct
evaluator_t
&
op_st
);
void
delete_operator_batching
(
struct
evaluator_t
&
op_st
);
/** for plaintexts and ciphertexts management **/
void
init_plaintext
(
struct
encryptor_t
&
op_st
,
int64_t
plain
,
seal
::
Plaintext
&
pt
);
void
init_ciphertext
(
struct
encryptor_t
&
op_st
,
int64_t
plain
,
seal
::
Ciphertext
&
ct
);
void
init_ciphermatrix
(
struct
encryptor_t
&
op_st
,
std
::
vector
<
int64_t
>
&
plain_matrix
,
seal
::
Ciphertext
&
encrypted_matrix
);
void
decrypt_ciphertext
(
struct
decryptor_t
&
op_st
,
seal
::
Ciphertext
&
ct
);
std
::
int64_t
decrypt_ciphertext_and_return_value
(
struct
decryptor_t
&
op_st
,
seal
::
Ciphertext
&
ct
);
std
::
vector
<
int64_t
>
decrypt_ciphermatrix
(
struct
decryptor_t
&
op_st
,
seal
::
Ciphertext
&
ct
);
int
save_plaintext
(
seal
::
Plaintext
&
pt
,
const
std
::
string
&
filename
);
int
save_ciphertext
(
seal
::
Ciphertext
&
ct
,
const
std
::
string
&
filename
);
int
load_plaintext
(
std
::
shared_ptr
<
seal
::
SEALContext
>&
context
,
seal
::
Plaintext
&
pt
,
const
std
::
string
&
filename
);
int
load_plaintext
(
struct
evaluator_t
&
op_st
,
seal
::
Plaintext
&
pt
,
const
std
::
string
&
filename
);
int
load_plaintext
(
struct
decryptor_t
&
op_st
,
seal
::
Plaintext
&
pt
,
const
std
::
string
&
filename
);
int
load_ciphertext
(
std
::
shared_ptr
<
seal
::
SEALContext
>&
context
,
seal
::
Ciphertext
&
ct
,
const
std
::
string
&
filename
);
int
load_ciphertext
(
struct
evaluator_t
&
op_st
,
seal
::
Ciphertext
&
ct
,
const
std
::
string
&
filename
);
int
load_ciphertext
(
struct
decryptor_t
&
op_st
,
seal
::
Ciphertext
&
ct
,
const
std
::
string
&
filename
);
#endif
bigpiseal3.5.1/native/examples/patternSearch/v2/test_v2.sh
0 → 100644
View file @
c6c9d2f5
mkdir
-p
keys/
mkdir
-p
lcheck/
mkdir
-p
parent/
mkdir
-p
result/
# rm ls.txt
# bash data_creating.sh 0 99 9 1000
# Number of driving licenses, eg: (0..99)
min
=
0
max
=
101
# max=1631
# max=101
# sim: (eval: 0.465s, 0.488s, 0.480s decrypt: 0.028s, 0.080s, 0.077s)
# seq: (eval: 0.xxx, 0.xxx, 0.xxx decrypt: 0.xxx, 0.xxx, 0.xxx)
# max=203
# (eval: 3.635s, 3.510s, 3.628s decrypt: 0.062s, 0.153s. 0.134s)
# seq: (eval: 0.xxx, 0.xxx, 0.xxx decrypt: 0.xxx, 0.xxx, 0.xxx)
# max=407
# (eval: 38.607s, 39.600s, 39.565s decrypt: 0.264s, 0.260s, 0.245s)
# seq: (eval: 0.xxx, 0.xxx, 0.xxx decrypt: 0.xxx, 0.xxx, 0.xxx)
# max=815
# (eval: x decrypt: x )
# Number of chars/words of a driving license, eg: 9
n_char
=
39
# Encrypted number range, eg: 10, 100, 1000 for 1 2 3 4 digits
range
=
255
# (8-bit)
# sampling size
sample
=
40
CURR_DIR
=
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
# Note
# gen keys
# ./patternSearch_genkey_v2 keys/
${
CURR_DIR
}
/patternSearch_genkey_v2 keys/
line
=
$((
RANDOM
%
max
))
lcheck
=
""
# gen data
for
i
in
$(
seq
$min
$max
)
do
mkdir
-p
parent/l
"
$i
"
/
echo
"Created folder
$i
"
value
=
""
for
j
in
$(
seq
0
$n_char
)
do
value+
=
"
$((
RANDOM
%
$range
))
"
done
echo
$value
echo
$value
>>
ls.txt
# ./patternSearch_encrypt_v2 "$value" "l" parent/l"$i"/ $sample keys/
${
CURR_DIR
}
/patternSearch_encrypt_v2
"
$value
"
"l"
parent/l
"
$i
"
/
$sample
keys/
if
[[
"
$line
"
-eq
"
$i
"
]]
then
lcheck
=
"
$value
"
fi
done
# get random lc
# lcheck=$(sed -n "$((RANDOM %9){p;q}" ls.txt)
# line=$((RANDOM %max))
# lcheck="$(sed -n "${line}{p;q}" ls.txt)"
echo
"Pick up license to check:
$lcheck
"
# ./patternSearch_encrypt_v2 "$lcheck" "l" lcheck/ $sample keys/
${
CURR_DIR
}
/patternSearch_encrypt_v2
"
$lcheck
"
"l"
lcheck/
$sample
keys/
# ./patternSearch_encrypt "47 25 76 23 30 21 1 47 88 3" "a" keys/bfv.pk lcheck/
# eval
value1
=
"lcheck/l.ct "
value2
=
""
for
i
in
$(
seq
0
$max
)
do
value2+
=
"parent/l
${
i
}
/l.ct "
done
# value2="${value1} ${value2}"
value3
=
"
$value1$value2
"
echo
"
$value3
"
# time ./patternSearch_evaluate_v2 $value3 "l" result/ $sample keys/
# ./patternSearch_evaluate_v2 $value3 "l" result/ $sample keys/
time
${
CURR_DIR
}
/patternSearch_evaluate_v2
$value3
"l"
result/
$sample
keys/
echo
""
# time ./patternSearch_decrypt_result_v2 result/l.ct $sample keys/
# ./patternSearch_decrypt_result_v2 result/l.ct $sample keys/
${
CURR_DIR
}
/patternSearch_decrypt_result_v2 result/l.ct
$sample
keys/
# rm -r keys/*
# rm -r lcheck/*
# rm -r parent/*
# rm -r result/*
# rm ls.txt
bigpiseal3.5.1/native/examples/patternSearch/v2/util.cpp
0 → 100644
View file @
c6c9d2f5
#include "util.h"
// #include <filesystem>
#include "seal_api.h"
// #include <boost/filesystem.hpp>
// namespace fs = boost::filesystem;
bool
sub_str_exist
(
const
std
::
string
&
str
,
const
std
::
string
&
sub_str
)
{
return
str
.
size
()
>=
sub_str
.
size
()
&&
str
.
compare
(
str
.
size
()
-
sub_str
.
size
(),
sub_str
.
size
(),
sub_str
)
==
0
;
}
// int findNumberOfFilesInDirectory(const std::string &path)
// {
// auto dirIter = std::filesystem::directory_iterator(path);
// int fileCount = std::count_if(
// begin(dirIter),
// end(dirIter),
// [](auto &entry) { return entry.is_regular_file(); });
// return fileCount;
// }
// int findNumberOfFilesInDirectory(std::string &path, std::string &ext)
// int findNumberOfFilesInDirectory(const std::string &path)
// {
// // namespace fs = boost::filesystem;
// std::string ext = ".ct";
// fs::path Path(path);
// int Nb_ext = 0;
// fs::directory_iterator end_iter; // Default constructor for an iterator is the end iterator
// for (fs::directory_iterator iter(Path); iter != end_iter; ++iter)
// if (iter->path().extension() == ext)
// ++Nb_ext;
// return Nb_ext;
// }
// c++ 17
// std::vector<std::string> get_directories(const std::string &s)
// {
// std::vector<std::string> r;
// for(auto& p : std::filesystem::recursive_directory_iterator(s))
// if (p.is_directory())
// r.push_back(p.path().string());
// return r;
// }
// struct path_leaf_string
// {
// std::string operator()(const boost::filesystem::directory_entry &entry) const
// {
// return entry.path().leaf().string();
// }
// };
// std::vector<std::string> get_directories(const std::string &s)
// {
// std::vector<std::string> v;
// boost::filesystem::path p(s);
// boost::filesystem::directory_iterator start(p);
// boost::filesystem::directory_iterator end;
// std::transform(start, end, std::back_inserter(v), path_leaf_string());
// std::copy(v.begin(), v.end(),
// std::ostream_iterator<std::string>(std::cout, "\n"));
// return v;
// }
bigpiseal3.5.1/native/examples/patternSearch/v2/util.h
0 → 100644
View file @
c6c9d2f5
#ifndef _UTIL_H_
#define _UTIL_H_
#include <string>
#include <vector>
// int findNumberOfFilesInDirectory(const std::string &path);
bool
sub_str_exist
(
const
std
::
string
&
str
,
const
std
::
string
&
sub_str
);
// std::vector<std::string> get_directories(const std::string &s);
// std::vector<std::string> get_directories_deep(const std::string &s);
#endif
bigpiseal3.5.1/native/examples/similarityMatch/v1/CMakeLists.txt
0 → 100644
View file @
c6c9d2f5
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT license.
cmake_minimum_required
(
VERSION 3.10
)
set
(
TEST_NAME similarityMatch
)
set
(
GENKEY_BIN
${
TEST_NAME
}
_genkey
)
set
(
ENCR_BIN
${
TEST_NAME
}
_encrypt
)
set
(
DECR_BIN
${
TEST_NAME
}
_decrypt
)
set
(
DECR_RESULT_BIN
${
TEST_NAME
}
_decrypt_result
)
set
(
DECR_RESULT_BIN
${
TEST_NAME
}
_decrypt_1st_result
)
set
(
EVAL_BIN
${
TEST_NAME
}
_evaluate
)
#set(SCR_TEST test.sh)
set
(
SCR_ENC encrypt.sh
)
set
(
SCR_DEC decrypt.sh
)
set
(
SCR_DEC_RESULT decrypt_1st_result.sh
)
set
(
SCR_DEC_RESULT decrypt_result.sh
)
set
(
SCR_EVAL eval.sh
)
set
(
SCR_GEN genkey.sh
)
set
(
SCR_TEST test.sh
)
set
(
GENKEY_SRCS
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/
${
TEST_NAME
}
_genkey.cpp
)
set
(
ENCR_SRCS
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/
${
TEST_NAME
}
_encrypt.cpp
)
set
(
DECR_SRCS
${
CMAKE_CURRENT_LIST_DIR
}
/util.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/
${
TEST_NAME
}
_decrypt.cpp
)
set
(
EVAL_SRCS
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/util.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/
${
TEST_NAME
}
_evaluate.cpp
)
set
(
GENKEY_SRCS
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/
${
TEST_NAME
}
_genkey.cpp
)
set
(
ENCR_SRCS
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/
${
TEST_NAME
}
_encrypt.cpp
)
set
(
DECR_SRCS
${
CMAKE_CURRENT_LIST_DIR
}
/util.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/
${
TEST_NAME
}
_decrypt.cpp
)
set
(
DECR_RESULT_SRCS
${
CMAKE_CURRENT_LIST_DIR
}
/util.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/
${
TEST_NAME
}
_decrypt_result.cpp
)
set
(
DECR_RESULT_SRCS
${
CMAKE_CURRENT_LIST_DIR
}
/util.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/
${
TEST_NAME
}
_decrypt_1st_result.cpp
)
set
(
EVAL_SRCS
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/util.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/
${
TEST_NAME
}
_evaluate.cpp
)
set
(
HEADER_FILES
${
CMAKE_CURRENT_LIST_DIR
}
/seal_api.h
${
CMAKE_CURRENT_LIST_DIR
}
/util.h
)
add_executable
(
${
GENKEY_BIN
}
${
GENKEY_SRCS
}
${
HEADER_FILES
}
)
add_executable
(
${
ENCR_BIN
}
${
ENCR_SRCS
}
${
HEADER_FILES
}
)
add_executable
(
${
DECR_BIN
}
${
DECR_SRCS
}
${
HEADER_FILES
}
)
add_executable
(
${
DECR_RESULT_BIN
}
${
DECR_RESULT_SRCS
}
${
HEADER_FILES
}
)
add_executable
(
${
EVAL_BIN
}
${
EVAL_SRCS
}
${
HEADER_FILES
}
)
#target_include_directories(${TEST_NAME} PRIVATE ${HEADER_DIR})
# Import Microsoft SEAL
find_package
(
SEAL 3.5 REQUIRED
)
target_link_libraries
(
${
GENKEY_BIN
}
SEAL::seal
)
target_link_libraries
(
${
ENCR_BIN
}
SEAL::seal
)
target_link_libraries
(
${
DECR_BIN
}
SEAL::seal
)
target_link_libraries
(
${
DECR_RESULT_BIN
}
SEAL::seal
)
target_link_libraries
(
${
EVAL_BIN
}
SEAL::seal
)
set
(
CMAKE_RUNTIME_OUTPUT_DIRECTORY
${
CMAKE_SOURCE_DIR
}
/bin
)
set_target_properties
(
${
GENKEY_BIN
}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
"
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v1"
)
set_target_properties
(
${
ENCR_BIN
}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
"
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v1"
)
set_target_properties
(
${
DECR_BIN
}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
"
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v1"
)
set_target_properties
(
${
DECR_RESULT_BIN
}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
"
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v1"
)
set_target_properties
(
${
EVAL_BIN
}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
"
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v1"
)
file
(
COPY
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
SCR_TEST
}
DESTINATION
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v1
)
file
(
COPY
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
SCR_ENC
}
DESTINATION
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v1
)
file
(
COPY
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
SCR_DEC
}
DESTINATION
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v1
)
file
(
COPY
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
SCR_DEC_RESULT
}
DESTINATION
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v1
)
file
(
COPY
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
SCR_EVAL
}
DESTINATION
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v1
)
file
(
COPY
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
SCR_GEN
}
DESTINATION
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v1
)
file
(
COPY
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
SCR_TEST_V2
}
DESTINATION
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/
${
TEST_NAME
}
/v1
)
\ No newline at end of file
bigpiseal3.5.1/native/examples/similarityMatch/v1/decrypt.sh
0 → 100644
View file @
c6c9d2f5
# Decrypt Data
CURR_DIR
=
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
###################### General - Begin ######################
resultPath
=
$1
# ex: result/l.ct
sample
=
$2
# ex: 40
keyDir
=
$3
# ex: keys/
time
${
CURR_DIR
}
/similarityMatch_decrypt
"
$resultPath
"
"
$sample
"
"
$keyDir
"
###################### General - End ########################
\ No newline at end of file
bigpiseal3.5.1/native/examples/similarityMatch/v1/decrypt_1st_result.sh
0 → 100644
View file @
c6c9d2f5
# Decrypt Result
CURR_DIR
=
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
###################### General - Begin ######################
resultPath
=
$1
# ex: result/l.ct
sample
=
$2
# ex: 40
keyDir
=
$3
# ex: keys/
time
${
CURR_DIR
}
/similarityMatch_decrypt_1st_result
"
$resultPath
"
"
$sample
"
"
$keyDir
"
###################### General - End ########################
\ No newline at end of file
Prev
1
…
7
8
9
10
11
12
13
14
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment