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 <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)。在这里插入图片描述

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 16
    评论
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值