环境:
Ubuntu
需要c++的编译环境
安装cmake:
sudo apt-get install build-essential cmake cmake-curses-gui
TFHE库的安装
下载库( TFHE):
git clone --recurse-submodules --branch=master https://github.com/tfhe/tfhe.git
运行下面命令:
cd tfhe
mkdir build
cd build
cmake ../src -DENABLE_TESTS=on -DENABLE_FFTW=on -DCMAKE_BUILD_TYPE=debug
make
出现第一个问题:
这里是因为没有fftw3:
解决方法:下载fftw
下载之后解压
cd ./fftw-3.3.10
./configure --enable-shared
make
sudo make install
sudo ldconfig
解决之后再次运行:
cd tfhe
mkdir build
cd build
cmake ../src -DENABLE_TESTS=on -DENABLE_FFTW=on -DCMAKE_BUILD_TYPE=debug
make
出现第二个问题:
In file included from /home/vulhub/tfhe/src/test/googletest/googletest/src/gtest-all.cc:43:
/home/vulhub/tfhe/src/test/googletest/googletest/src/gtest-death-test.cc: In function ‘bool testing::internal::StackGrowsDown()’:
/home/vulhub/tfhe/src/test/googletest/googletest/src/gtest-death-test.cc:1008:24: error: ‘dummy’ may be used uninitialized [-Werror=maybe-uninitialized]
1008 | StackLowerThanAddress(&dummy, &result);
| ~~~~~^
这里是因为googletest的问题:
解决方法:下载最新的googletest来替换
git clone https://github.com/google/googletest.git
cd googletest
mkdir mybuild
cd mybuild
cmake -Dgtest_build_tests=on -DCMAKE_INSTALL_PREFIX=. ..
make; make install
等待运行完成之后,手动将/home/vulhub/tfhe/src/test中的googletest文件换成新下载的。
接着运行以下指令显示成功。
cd tfhe
mkdir build
cd build
cmake ../src -DENABLE_TESTS=on -DENABLE_FFTW=on -DCMAKE_BUILD_TYPE=debug
make
sudo make install
测试:
#include <tfhe/tfhe.h>
#include <tfhe/tfhe_io.h>
#include <stdio.h>
int main() {
//generate a keyset
const int minimum_lambda = 110; //安全级别
TFheGateBootstrappingParameterSet* params = new_default_gate_bootstrapping_parameters(minimum_lambda);
//generate a random key
uint32_t seed[] = { 314, 1592, 657 };
tfhe_random_generator_setSeed(seed,3);
TFheGateBootstrappingSecretKeySet* key = new_random_gate_bootstrapping_secret_keyset(params);
//export the secret key to file for later use
FILE* secret_key = fopen("secret.key","wb");
export_tfheGateBootstrappingSecretKeySet_toFile(secret_key, key);
fclose(secret_key);
//export the cloud key to a file (for the cloud)
FILE* cloud_key = fopen("cloud.key","wb");
export_tfheGateBootstrappingCloudKeySet_toFile(cloud_key, &key->cloud);
fclose(cloud_key);
//you can put additional instructions here!!
//...
//clean up all pointers
delete_gate_bootstrapping_secret_keyset(key);
delete_gate_bootstrapping_parameters(params);
}
将代码进行编译运行,会成功生成一个密钥(secret.key)和一个云密钥(cloud.key)。