HEhub同态加密库
HEhub 是首个由国内开源的同态加密库,可以实现在密文基础上进行加、乘等基础运算,并得到与明文相同的结果,从而实现数据可用不可见的目标。同态库是隐私计算领域基础的加密库。
使用示例:
#include "fhe/ckks/ckks.h"
#include <cmath>
#include <iostream>
using namespace hehub;
int main() {
int precision_bits = 30;
auto params = ckks::create_params(4096, precision_bits);
CkksSk sk(params);
auto relin_key = get_relin_key(sk, params.additional_mod);
CkksCt ct_sum;
for (int i = 1; i <= 100000; i++) {
auto pt = ckks::encode(1.0 / i, params);
auto ct = ckks::encrypt(pt, sk);
auto ct_squared = ckks::mult(ct, ct, relin_key);
if (i == 1) {
ct_sum = ct_squared;
} else {
ct_sum = ckks::add(ct_sum, ct_squared);
}
}
double sum = ckks::decode(ckks::decrypt(ct_sum, sk));
std::cout << "(" << sum << ", " << M_PI * M_PI / 6 << ")" << std::endl;
}
评论