Visual Studio错误2784:无法从FLINT推导出GMP的模板参数

时间:2016-02-24 02:46:05

标签: gmp mpir flint

运行使用YASHE和FV级别同态密码系统的"同态Simon加密的源代码时出现问题" (https://github.com/tlepoint/homomorphic-simon)在Visual Studio 2012中。

我使用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:   &#39; __ gmp_expr,mpir_ui,__ gmp_binary_multiplies&GT;&GT;   operator *(const __gmp_expr&amp;,unsigned __int64)&#39; : 不能   演绎&#39; const __gmp_expr&amp;&#39;的模板参数从   &#39; INT&#39; fvkey.cpp 115错误C2784:   &#39; __ gmp_expr,__ gmp_binary_multiplies&GT;&GT;   operator *(unsigned short,const __gmp_expr&amp;)&#39; :无法演绎   &#39; const __gmp_expr&amp;&#39;的模板参数来自&#39; flint :: fmpzxx&#39;
  错误C2784:   &#39; __ gmp_expr,__ gmp_binary_minus&GT;&GT; operator - (unsigned short,const __gmp_expr&amp;)&#39; :无法演绎   &#39; const __gmp_expr&amp;&#39;的模板参数来自&#39; const   火石:: fmpzxx&#39; fvkey.cpp 116

     

错误C2784:   &#39; __ gmp_expr,__ gmp_binary_divides&GT;&GT;   operator /(unsigned short,const __gmp_expr&amp;)&#39; :无法演绎   &#39; const __gmp_expr&amp;&#39;的模板参数从   &#39;火石:: fmpzxx&#39; fvkey.cpp 135错误C2784:   &#39; __ gmp_expr,__ gmp_binary_multiplies&GT;&GT;   operator *(signed char,const __gmp_expr&amp;)&#39; :无法演绎   &#39; const __gmp_expr&amp;&#39;的模板参数来自&#39; flint :: fmpzxx&#39;   fvkey.cpp 115

     

错误C2784:&#39; __ gmp_expr,__ gmp_binary_minus&gt;&gt;操作员 - (长   double,const __gmp_expr&amp;)&#39; :无法推断出模板参数   for&#39; const __gmp_expr&amp;&#39;来自&#39; const flint :: fmpzxx&#39;   &#39;火石:: fmpzxx&#39; fvkey.cpp 116

     

错误C2784:   &#39; __ gmp_expr,mpir_ui,__ gmp_binary_multiplies&GT;&GT;   operator *(const __gmp_expr&amp ;, unsigned int)&#39; :无法演绎   &#39; const __gmp_expr&amp;&#39;的模板参数从   &#39; INT&#39; &#39;火石:: fmpzxx&#39; fvkey.cpp 115

     

错误C2678:二进制&#39;&lt;&lt;&# :没有找到左手的操作员   类型&#39; flint :: fmpzxx_expression&#39;的操作数(或那里   是不可接受的转换)fvkey.cpp 50

我试图解决它几周但仍未成功。是否由&#34; fmpz-conversions.h&#34;来自FLINT?

请帮我弄清楚我做错了什么。我已将我的视觉项目上传到http://1drv.ms/1LFpCI4

0 个答案:

没有答案