栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

TFHE同态库的安装与简单使用

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

TFHE同态库的安装与简单使用

环境:

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 
#include 
#include 

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)。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/768031.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号