0

I get an error when compiling a crypto library

crypto/ope.cpp: In member function ‘NTL::ZZ OPE::encrypt(const NTL::ZZ&, int)’:
crypto/ope.cpp:80: error: expected primary-expression before ‘[’ token
crypto/ope.cpp:80: error: expected primary-expression before ‘const’
crypto/ope.cpp:80: error: expected primary-expression before ‘const’
crypto/ope.cpp: In member function ‘NTL::ZZ OPE::decrypt(const NTL::ZZ&)’:
crypto/ope.cpp:110: error: expected primary-expression before ‘[’ token
crypto/ope.cpp:110: error: expected primary-expression before ‘const’
crypto/ope.cpp:110: error: expected primary-expression before ‘const’

The code snippet is as follows:

template<class CB> 
ope_domain_range
OPE::search(CB go_low)
{
    blockrng<AES> r(aesk);

    return lazy_sample(to_ZZ(0), to_ZZ(1) << pbits,
                       to_ZZ(0), to_ZZ(1) << cbits,
                       go_low, &r);
}

ZZ
OPE::encrypt(const ZZ &ptext, int offset)
{
    ope_domain_range dr =
        search([&ptext](const ZZ &d, const ZZ &) { return ptext < d; }); 

    blockrng<AES> aesrand(aesk);
    auto v = sha256::hash(StringFromZZ(ptext));
    v.resize(16);
    aesrand.set_ctr(v);

    ZZ nrange = dr.r_hi - dr.r_lo + 1;
    if (nrange < 4 || det)
        return dr.r_lo + aesrand.rand_zz_mod(nrange);

    ZZ nrquad = nrange / 4;
    static urandom urand;

    switch (offset) {
    case -1: 
        return dr.r_lo + urand.rand_zz_mod(nrquad);
    case 0:
        return dr.r_lo + nrquad + urand.rand_zz_mod(nrquad * 2); 
    case 1:
        return dr.r_lo + nrquad * 3 + urand.rand_zz_mod(nrquad);
    default:
        assert(0);
    }   
}

The codes on Line 80 are (those on Line 110 are similar):

ope_domain_range dr =
        search([&ptext](const ZZ &d, const ZZ &) { return ptext < d; }); 

I am not quite familiar with C++11, the new C++ standard. Is this newly introduced by the new standard? If no, what does that mean? If yes, could I compile the C++11 codes with g++ version 4.4.7? (currently I compile the library with g++ 4.4.7 flagged as -std=c++0x.)

Thank you very much.

Summer_More_More_Tea
  • 12,740
  • 12
  • 51
  • 83

1 Answers1

2

The code in question is a C++11 lambda and the part enclosed by "[]" is the capture which tells the compiler which variables and constants that live outside the lambda should be passed in, and how.

In this particular case, the lambda captures ptext by reference.

A quick check on GCC's c++0x page for GCC 4.4 suggests that it doesn't implement lambdas. You'll have to upgrade to a newer compiler.

Timo Geusch
  • 24,095
  • 5
  • 52
  • 70