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