-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from CEA-LIST/wifs_tuto_examples
ease tfhe project creation. wifs tutorial examples
- Loading branch information
Showing
22 changed files
with
904 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
cmake_minimum_required(VERSION 3.9) | ||
|
||
set(test_names | ||
hello | ||
trans1 | ||
trans2 | ||
) | ||
FILE(GLOB test_names [^_]*) | ||
|
||
set(target_names "") | ||
foreach (name IN ITEMS ${test_names}) | ||
add_subdirectory(${name}) | ||
list(APPEND target_names "tfhe-${name}") | ||
foreach (child ${test_names}) | ||
if(IS_DIRECTORY ${child}) | ||
get_filename_component(name ${child} NAME) | ||
add_subdirectory(${name}) | ||
list(APPEND target_names "tfhe-${name}") | ||
endif() | ||
endforeach() | ||
|
||
add_custom_target(tests_tfhe ALL | ||
DEPENDS | ||
${target_names} | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
cmake_minimum_required(VERSION 3.9) | ||
|
||
set(NAME "@NAME@") # project name | ||
|
||
add_executable(tfhe-${NAME}-exec main.cxx) | ||
target_link_libraries(tfhe-${NAME}-exec common tfhe_bit_exec) | ||
|
||
add_executable(tfhe-${NAME}-encrypt encrypt.cxx) | ||
target_link_libraries(tfhe-${NAME}-encrypt common tfhe_bit_exec) | ||
|
||
add_executable(tfhe-${NAME}-decrypt decrypt.cxx) | ||
target_link_libraries(tfhe-${NAME}-decrypt common tfhe_bit_exec) | ||
|
||
add_custom_target(tfhe-${NAME} | ||
DEPENDS | ||
tfhe-${NAME}-exec | ||
tfhe-${NAME}-encrypt | ||
tfhe-${NAME}-decrypt | ||
tfhe | ||
) | ||
|
||
set(APPS_DIR ${CMAKE_BINARY_DIR}/apps) | ||
configure_file("run.sh.in" "run.sh" @ONLY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
(C) Copyright 2019 CEA LIST. All Rights Reserved. | ||
Contributor(s): Cingulata team (formerly Armadillo team) | ||
This software is governed by the CeCILL-C license under French law and | ||
abiding by the rules of distribution of free software. You can use, | ||
modify and/ or redistribute the software under the terms of the CeCILL-C | ||
license as circulated by CEA, CNRS and INRIA at the following URL | ||
"http://www.cecill.info". | ||
As a counterpart to the access to the source code and rights to copy, | ||
modify and redistribute granted by the license, users are provided only | ||
with a limited warranty and the software's author, the holder of the | ||
economic rights, and the successive licensors have only limited | ||
liability. | ||
The fact that you are presently reading this means that you have had | ||
knowledge of the CeCILL-C license and that you accept its terms. | ||
*/ | ||
|
||
#include <iostream> | ||
|
||
/* local includes */ | ||
#include <tfhe_bit_exec.hxx> | ||
#include <ci_context.hxx> | ||
#include <ci_int.hxx> | ||
|
||
|
||
/* namespaces */ | ||
using namespace std; | ||
using namespace cingulata; | ||
|
||
int main() { | ||
/* Only tfhe bit executor is needed for encryption/decryption and IO operations */ | ||
CiContext::set_bit_exec(make_shared<TfheBitExec>("tfhe.sk", TfheBitExec::Secret)); | ||
|
||
CiInt c{(uint16_t)-1}; // automatically determine size and signedness from value | ||
|
||
c.read("c").decrypt(); | ||
|
||
uint16_t c_val = c.get_val(); | ||
|
||
cout << c_val << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
(C) Copyright 2019 CEA LIST. All Rights Reserved. | ||
Contributor(s): Cingulata team (formerly Armadillo team) | ||
This software is governed by the CeCILL-C license under French law and | ||
abiding by the rules of distribution of free software. You can use, | ||
modify and/ or redistribute the software under the terms of the CeCILL-C | ||
license as circulated by CEA, CNRS and INRIA at the following URL | ||
"http://www.cecill.info". | ||
As a counterpart to the access to the source code and rights to copy, | ||
modify and redistribute granted by the license, users are provided only | ||
with a limited warranty and the software's author, the holder of the | ||
economic rights, and the successive licensors have only limited | ||
liability. | ||
The fact that you are presently reading this means that you have had | ||
knowledge of the CeCILL-C license and that you accept its terms. | ||
*/ | ||
|
||
#include <iostream> | ||
|
||
/* local includes */ | ||
#include <tfhe_bit_exec.hxx> | ||
#include <ci_context.hxx> | ||
#include <ci_int.hxx> | ||
|
||
|
||
/* namespaces */ | ||
using namespace std; | ||
using namespace cingulata; | ||
|
||
int main(int argc, char* argv[]) { | ||
if (argc < 3) { | ||
cerr << "Usage: " << argv[0] << " <a> <b>" << endl; | ||
exit(-1); | ||
} | ||
|
||
/* get input values */ | ||
int a_val = atoi(argv[1]); | ||
int b_val = atoi(argv[2]); | ||
|
||
/* Only tfhe bit executor is needed for encryption/decryption and IO operations */ | ||
CiContext::set_bit_exec(make_shared<TfheBitExec>("tfhe.sk", TfheBitExec::Secret)); | ||
|
||
CiInt a{a_val, 8, false}; | ||
CiInt b{b_val, 8, false}; | ||
|
||
a.encrypt().write("a"); | ||
b.encrypt().write("b"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
(C) Copyright 2019 CEA LIST. All Rights Reserved. | ||
Contributor(s): Cingulata team (formerly Armadillo team) | ||
This software is governed by the CeCILL-C license under French law and | ||
abiding by the rules of distribution of free software. You can use, | ||
modify and/ or redistribute the software under the terms of the CeCILL-C | ||
license as circulated by CEA, CNRS and INRIA at the following URL | ||
"http://www.cecill.info". | ||
As a counterpart to the access to the source code and rights to copy, | ||
modify and redistribute granted by the license, users are provided only | ||
with a limited warranty and the software's author, the holder of the | ||
economic rights, and the successive licensors have only limited | ||
liability. | ||
The fact that you are presently reading this means that you have had | ||
knowledge of the CeCILL-C license and that you accept its terms. | ||
*/ | ||
|
||
/* local includes */ | ||
#include <bit_exec/decorator/attach.hxx> | ||
#include <bit_exec/decorator/stat.hxx> | ||
#include <ci_context.hxx> | ||
#include <ci_int.hxx> | ||
#include <int_op_gen/size.hxx> | ||
#include <tfhe_bit_exec.hxx> | ||
|
||
/* namespaces */ | ||
using namespace std; | ||
using namespace cingulata; | ||
|
||
int main() { | ||
/* Set context to tfhe bit executor and size minimized integer | ||
* operations */ | ||
CiContext::set_config( | ||
make_shared<decorator::Attach<TfheBitExec, decorator::Stat<IBitExecFHE>>>( | ||
"tfhe.pk", TfheBitExec::Public), | ||
make_shared<IntOpGenSize>()); | ||
|
||
CiInt a{CiInt::u8}; // create from unsigned 8-bit template | ||
CiInt b{0, 8, false}; // manually specify value, size and signedness | ||
CiInt c{ | ||
(uint16_t)-1}; // automatically determine size and signedness from value | ||
|
||
a.read("a"); | ||
b.read("b"); | ||
|
||
c = a + b; | ||
// c = a * a * b - a; | ||
|
||
c.write("c"); | ||
|
||
CiContext::get_bit_exec_t<decorator::Stat<IBitExecFHE>>()->print(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# (C) Copyright 2019 CEA LIST. All Rights Reserved. | ||
# Contributor(s): Cingulata team (formerly Armadillo team) | ||
# | ||
# This software is governed by the CeCILL-C license under French law and | ||
# abiding by the rules of distribution of free software. You can use, | ||
# modify and/ or redistribute the software under the terms of the CeCILL-C | ||
# license as circulated by CEA, CNRS and INRIA at the following URL | ||
# "http://www.cecill.info". | ||
# | ||
# As a counterpart to the access to the source code and rights to copy, | ||
# modify and redistribute granted by the license, users are provided only | ||
# with a limited warranty and the software's author, the holder of the | ||
# economic rights, and the successive licensors have only limited | ||
# liability. | ||
# | ||
# The fact that you are presently reading this means that you have had | ||
# knowledge of the CeCILL-C license and that you accept its terms. | ||
# | ||
# | ||
|
||
APPS_DIR=@APPS_DIR@ | ||
NAME=@NAME@ | ||
|
||
cd `dirname $0` | ||
|
||
rm -f a_* b_* c_* | ||
|
||
echo "Input encryption" | ||
|
||
# Generate keys | ||
echo "TFHE key generation" | ||
$APPS_DIR/tfhe-keygen | ||
|
||
# Encrypt input "a" and "b" | ||
./tfhe-$NAME-encrypt 5 3 | ||
|
||
echo "Homomorphic execution..." | ||
time ./tfhe-$NAME-exec | ||
|
||
echo "Output decryption" | ||
./tfhe-$NAME-decrypt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
# Script for creating a new tfhe project. The new project is the same as _template project. | ||
|
||
SCRIPT_DIR=$0 | ||
|
||
if [ "$#" -lt 1 ]; then | ||
echo "Usage: $SCRIPT_DIR <project name>" | ||
exit | ||
fi | ||
|
||
NAME=$1 | ||
|
||
# goto script directory, as next commands are relative to it | ||
cd `dirname $SCRIPT_DIR` | ||
|
||
mkdir $NAME || exit | ||
|
||
cp -rn _template/* $NAME/ | ||
|
||
# rename variables | ||
sed -i "s/@NAME@/$NAME/g" $NAME/CMakeLists.txt | ||
sed -i "s/@NAME@/$NAME/g" $NAME/run.sh.in | ||
|
||
touch CMakeLists.txt #do it so that cmake rebuilts | ||
echo "Project $NAME created" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
cmake_minimum_required(VERSION 3.9) | ||
|
||
set(NAME "wifs_cmp") # project name | ||
|
||
add_executable(tfhe-${NAME}-exec main.cxx) | ||
target_link_libraries(tfhe-${NAME}-exec common tfhe_bit_exec) | ||
|
||
add_executable(tfhe-${NAME}-encrypt encrypt.cxx) | ||
target_link_libraries(tfhe-${NAME}-encrypt common tfhe_bit_exec) | ||
|
||
add_executable(tfhe-${NAME}-decrypt decrypt.cxx) | ||
target_link_libraries(tfhe-${NAME}-decrypt common tfhe_bit_exec) | ||
|
||
add_custom_target(tfhe-${NAME} | ||
DEPENDS | ||
tfhe-${NAME}-exec | ||
tfhe-${NAME}-encrypt | ||
tfhe-${NAME}-decrypt | ||
tfhe | ||
) | ||
|
||
set(APPS_DIR ${CMAKE_BINARY_DIR}/apps) | ||
configure_file("run.sh.in" "run.sh" @ONLY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
(C) Copyright 2019 CEA LIST. All Rights Reserved. | ||
Contributor(s): Cingulata team (formerly Armadillo team) | ||
This software is governed by the CeCILL-C license under French law and | ||
abiding by the rules of distribution of free software. You can use, | ||
modify and/ or redistribute the software under the terms of the CeCILL-C | ||
license as circulated by CEA, CNRS and INRIA at the following URL | ||
"http://www.cecill.info". | ||
As a counterpart to the access to the source code and rights to copy, | ||
modify and redistribute granted by the license, users are provided only | ||
with a limited warranty and the software's author, the holder of the | ||
economic rights, and the successive licensors have only limited | ||
liability. | ||
The fact that you are presently reading this means that you have had | ||
knowledge of the CeCILL-C license and that you accept its terms. | ||
*/ | ||
|
||
#include <iostream> | ||
|
||
/* local includes */ | ||
#include <tfhe_bit_exec.hxx> | ||
#include <ci_context.hxx> | ||
#include <ci_int.hxx> | ||
|
||
|
||
/* namespaces */ | ||
using namespace std; | ||
using namespace cingulata; | ||
|
||
int main() { | ||
/* Only tfhe bit executor is needed for encryption/decryption and IO operations */ | ||
CiContext::set_bit_exec(make_shared<TfheBitExec>("tfhe.sk", TfheBitExec::Secret)); | ||
|
||
CiBit c; // automatically determine size and signedness from value | ||
|
||
c.read("c").decrypt(); | ||
|
||
uint16_t c_val = c.get_val(); | ||
|
||
cout << c_val << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
(C) Copyright 2019 CEA LIST. All Rights Reserved. | ||
Contributor(s): Cingulata team (formerly Armadillo team) | ||
This software is governed by the CeCILL-C license under French law and | ||
abiding by the rules of distribution of free software. You can use, | ||
modify and/ or redistribute the software under the terms of the CeCILL-C | ||
license as circulated by CEA, CNRS and INRIA at the following URL | ||
"http://www.cecill.info". | ||
As a counterpart to the access to the source code and rights to copy, | ||
modify and redistribute granted by the license, users are provided only | ||
with a limited warranty and the software's author, the holder of the | ||
economic rights, and the successive licensors have only limited | ||
liability. | ||
The fact that you are presently reading this means that you have had | ||
knowledge of the CeCILL-C license and that you accept its terms. | ||
*/ | ||
|
||
#include <iostream> | ||
|
||
/* local includes */ | ||
#include <tfhe_bit_exec.hxx> | ||
#include <ci_context.hxx> | ||
#include <ci_int.hxx> | ||
|
||
|
||
/* namespaces */ | ||
using namespace std; | ||
using namespace cingulata; | ||
|
||
int main(int argc, char* argv[]) { | ||
if (argc < 3) { | ||
cerr << "Usage: " << argv[0] << " <a> <b>" << endl; | ||
exit(-1); | ||
} | ||
|
||
/* get input values */ | ||
int a_val = atoi(argv[1]); | ||
int b_val = atoi(argv[2]); | ||
|
||
/* Only tfhe bit executor is needed for encryption/decryption and IO operations */ | ||
CiContext::set_bit_exec(make_shared<TfheBitExec>("tfhe.sk", TfheBitExec::Secret)); | ||
|
||
CiInt a{a_val, 128, false}; | ||
CiInt b{b_val, 128, false}; | ||
|
||
a.encrypt().write("a"); | ||
b.encrypt().write("b"); | ||
} |
Oops, something went wrong.