我在 Visual Studio 2012 中运行“使用 YASHE 和 FV 水平同态密码系统的同态西蒙加密”(https://github.com/tlepoint/homomorphic-simon )的源代码时遇到问题。
我正在使用 FLINT 2.5.2、MPIR 2.7.2、MPFR 1.3.1 并收到许多错误,如下所示:
#include "stdafx.h"
#include "FVKey.h"
#include "Sampler.h"
#include <iostream>
#include "arith.h"
#include "timing.h"
#include <string>
/* Static values */
fmpzxx W((fmpzxx(1) << WORDLENGTH)); //error C2678
fmpzxx MASKING((fmpzxx(1) << WORDLENGTH)-fmpzxx(1)); //error C2678
/* Print Key */
std::ostream& operator<<(std::ostream& os, const FVKey& k) {
os << "<FVKey with ell=" << k.ell << " num_slots=" << k.get_num_slots() << " q=" << k.q
<< " t=" << k.t << " sigma_key=" << k.sigmakey << " sigma_err=" << k.sigmaerr
<< ">";
return os;
}
/* Small useful functions */
bool isPowerOfTwo(int n)
{
return (n) && !(n & (n - 1)); //this checks if the integer n is a power of two or not
}
void binaryGen(fmpz_mod_polyxx& f, unsigned degree)
{
for (unsigned i=0; i<=degree; i++)
f.set_coeff(i, fmpzxx((rand()%3)-1));
}
fmpz_mod_polyxx FVKey::BitVectorToPoly(BitVector& m)
{
assert(m.l() == num_slots);
if (!batching || num_slots == 1)
{
fmpz_mod_polyxx pf(q);
for (unsigned i=0; i<m.l(); i++)
pf.set_coeff(i, m[i]);
return pf;
}
else
{
fmpz_mod_polyxx pf(t);
fmpz_mod_polyxx mess(t);
mess.set_coeff(0, m[0]);
pf = mess;
for (unsigned i=1; i<num_slots; i++)
{
mess.set_coeff(0, m[i]);
pf = CRT(pf, mess, i-1);
}
fmpz_mod_polyxx result(q);
result = pf.to<fmpz_polyxx>();
return result;
}
}
unsigned noise_from_poly(const fmpz_mod_polyxx& cval, const fmpzxx &q, unsigned ell)
{
unsigned bitnoise = 0;
fmpzxx coeff;
for (unsigned i=0; i<ell; i++)
{
coeff = (cval.get_coeff(i).to<fmpzxx>()); //error C2893 ,C2228,C2059
if (2*coeff > q) //error C2893, error C2784
coeff = coeff - q; //error C2893, error C2784
if (coeff.sizeinbase(2)>bitnoise)
bitnoise = coeff.sizeinbase(2);
}
return bitnoise;
}
/* Constructor */
FVKey::FVKey(const struct FVParams& params, bool batch)
{
// Initializations
n = params.n;
sigmakey = params.sigmakey;
sigmaerr = params.sigmaerr;
q = params.q;
t = params.t;
logwq = q.sizeinbase(2)/WORDLENGTH+1;
qdivt = q/t; //error C2893, error C2784
qdiv2t = q/(2*t); //error C2784
// Define polynomial modulus
arith_cyclotomic_polynomial(poly._data().inner, n);
phi = new fmpz_mod_polyxx(q);
*phi = poly;
ell = phi->degree();
// Factorize the modulus if batching is set
batching = batch;
num_slots = 1;
if (batching)
{
std::cout << "Factorize the cyclotomic polynomial modulo " << t << std::endl;
fmpz_mod_polyxx phimodt(t);
phimodt = poly;
timing T;
T.start();
factors = new fmpz_mod_poly_factorxx(factor_cantor_zassenhaus(phimodt));
T.stop("Factorize");
unsigned degreeFactors = 0;
for (unsigned i=0; i<factors->size(); i++)
{
degreeFactors += factors->p(i).degree();
}
if (degreeFactors == phimodt.degree() && factors->size()>1)
{
std::cout << "Batching possible on " << factors->size() << " slots" << std::endl;
num_slots = factors->size();
invfactors.resize(num_slots-1, fmpz_mod_polyxx(t));
fmpz_mod_polyxx num(t);
num.set_coeff(0, 1);
for (unsigned i=0; i<num_slots-1; i++)
{
num = num*factors->p(i);
invfactors[i] = num.invmod(factors->p(i+1));
}
}
else
{
std::cout << "Batching impossible" << std::endl;
}
}
// Creating sk/pk
std::cerr << "Creating sk/pk" << std::endl;
a = new fmpz_mod_polyxx(q);
s = new fmpz_mod_polyxx(q);
b = new fmpz_mod_polyxx(q);
for (unsigned i=0; i<ell; i++)
{
fmpzxx coeff = fmpzxx(random.getRandomLong());
for (unsigned j=0; j<q.sizeinbase(2)/64; j++)
coeff = (coeff<<64)+fmpzxx(random.getRandomLong());
a->set_coeff(i, coeff);
}
samplerkey = new Sampler(sigmakey*0.4, 1., &random); // 1/sqrt(2*pi) ~ 0.4
if (sigmakey == 1) binaryGen(*s, ell-1);
else
{
for (unsigned i=0; i<ell; i++)
{
long value = samplerkey->SamplerGaussian();
if (value>=0) s->set_coeff(i, fmpzxx(value));
else s->set_coeff(i, q-fmpzxx(-value));
}
}
samplererr = new Sampler(sigmaerr*0.4, 1., &random); // 1/sqrt(2*pi) ~ 0.4
fmpz_mod_polyxx e(q);
if (sigmaerr == 1) binaryGen(e, ell-1);
else
{
for (unsigned i=0; i<ell; i++)
{
long value = samplererr->SamplerGaussian();
if (value>=0) e.set_coeff(i, fmpzxx(value));
else e.set_coeff(i, q-fmpzxx(-value));
}
}
*b = (-((*a)*(*s)%(*phi)))+e;
// Create evaluation key
gamma.resize(2);
gamma[0].resize(logwq, fmpz_mod_polyxx(q));
for (unsigned i=0; i<logwq; i++)
{
for (unsigned j=0; j<ell; j++)
{
fmpzxx coeff = fmpzxx(random.getRandomLong());
for (unsigned k=0; k<q.sizeinbase(2)/64; k++)
coeff = (coeff<<64)+fmpzxx(random.getRandomLong());
gamma[0][i].set_coeff(j, coeff);
}
}
gamma[1].resize(logwq, fmpz_mod_polyxx(q));
for (unsigned i=0; i<logwq; i++)
{
gamma[1][i] = (*s)*(*s);
for (unsigned j=0; j<i; j++)
gamma[1][i] = gamma[1][i]*W;
fmpz_mod_polyxx e2(q);
if (sigmaerr == 1) binaryGen(e2, ell-1);
else
{
for (unsigned i=0; i<ell; i++)
{
long value = samplererr->SamplerGaussian();
if (value>=0) e2.set_coeff(i, fmpzxx(value));
else e2.set_coeff(i, q-fmpzxx(-value));
}
}
gamma[1][i] += (-(gamma[0][i]*(*s)%(*phi)))+e2;
}
}
错误 C2784: '__gmp_expr,mpir_ui,__gmp_binary_multiplies>> operator *(const __gmp_expr &,unsigned __int64)' : 无法从 'int' fvkey.cpp 推导出 'const __gmp_expr &' 的模板参数 115 错误 C2784: '__gmp_expr,__gmp_binary_multiplies> > operator *(unsigned short,const __gmp_expr &)' : 无法从 'flint::fmpzxx' 推导出 'const __gmp_expr &' 的模板参数
错误 C2784: '__gmp_expr,__gmp_binary_minus>> operator -(unsigned short,const __gmp_expr &) ' : 无法从 'const flint::fmpzxx' fvkey.cpp 116 推导出 'const __gmp_expr &' 的模板参数错误 C2784: '__gmp_expr,__gmp_binary_divides>> operator /(unsigned short,const __gmp_expr &)' : 无法从 'flint::fmpzxx' fvkey.cpp 推导出 'const __gmp_expr &' 的模板参数 135 错误 C2784: '__gmp_expr,__gmp_binary_multiplies >> operator *(signed char,const __gmp_expr &)' : 无法从 'flint::fmpzxx' fvkey.cpp 115 推导出 'const __gmp_expr &' 的模板参数
错误 C2784: '__gmp_expr,__gmp_binary_minus>> operator -(long double,const __gmp_expr &)' : 无法从 'const flint::fmpzxx' 'flint::fmpzxx' fvkey.cpp 116 推导出 'const __gmp_expr &' 的模板参数
错误 C2784: '__gmp_expr,mpir_ui,__gmp_binary_multiplies>> operator *(const __gmp_expr &,unsigned int)' : 无法从 'int' 'flint::fmpzxx' fvkey.cpp 115 推导出 'const __gmp_expr &' 的模板参数
错误 C2678:二进制“<<”:未找到采用“flint::fmpzxx_expression”类型的左侧操作数的运算符(或没有可接受的转换)fvkey.cpp 50
我试图解决它几个星期,但仍然没有成功。是否是由fmpz-conversions.h
FLINT的“”引起的?
请帮助我弄清楚我做错了什么。我已将我的视觉项目上传到http://1drv.ms/1LFpCI4。