예제 #1
0
void PaillierParty::secretShare() {
    ZZ beta = getRandomInNStar(m_n);

    std::vector<ZZ> coefficients;

    coefficients.push_back(MulMod(beta,m_m,m_n*m_m));

    for (uint32_t i=1; i < m_numOfParties; i++) {
        coefficients.push_back(getRandomInNStar(m_n*m_m));
    }

    ZZ_p::init(m_n*m_m);
    ZZ_pX polynomial;
    for (uint32_t i=0; i < m_numOfParties; i++) {
        SetCoeff(polynomial, i, conv<ZZ_p>(coefficients[i]));
    }

    for (auto &party : m_parties) {
        ZZ result = rep(eval(polynomial,ZZ_p(party.first)));
        sendZZTo(result,party.second);
    }

    ZZ_p s_i = eval(polynomial,ZZ_p(m_partyId));
    for (auto &party : m_parties) {
        ZZ value;
        receiveZZFrom(value,party.second);
        ZZ_p coefficient = conv<ZZ_p>(value);
        s_i = s_i + coefficient;
    }

    m_share = rep(s_i);

    m_pubKey = MulMod(MulMod(m_a,beta,m_n),m_m,m_n);
}
예제 #2
0
// Sets the prime defining the field for the curve and stores certain values
void Icart::setPrime(ZZ* p)
{
    //ZZ_p::init(*p);
    // Icart hash function uses 1/3 root, which is equivalent to (2p-1)/3
    exp = MulMod( SubMod( MulMod(ZZ(2), *p, *p), ZZ(1), *p), InvMod(ZZ(3),*p), *p);
    // Store inverse values to be used later
    ts = inv(ZZ_p(27));
    th = inv(ZZ_p(3));
}
예제 #3
0
// Icart's hash function
EPoint Icart::hash(ZZ_p u)
{
    // 0 maps to the point at infinity
    if (IsZero(u))
    {
        return EPoint(ZZ_p(0), ZZ_p(0), true);
    }

    // v = (3a - u^4) / 6u
    ZZ_p v = ((ZZ_p(3) * a) - power(u, 4)) * inv(ZZ_p(6) * u);
    // x = (v^2 - b - u^6/27)^(1/3) + u^2/3
    ZZ_p x = power( sqr(v) - b - (power(u, ZZ(6)) * ts), exp) + (sqr(u) * th);
    // y = ux + v
    ZZ_p y = (u * x) + v;

    return EPoint(x, y, false);
}