Exemplo n.º 1
0
bool ElGamal::decrypt(const BigInteger &a, const BigInteger &b, BigInteger &out) const
{
    try
    {
        out = b.modMulRecip(a.modExp(x, p, recip, nb).inverseModN(p), p, recip, nb);
        return true;
    }
    catch (ArithmeticException &)
    {
    }

    return false;
}
Exemplo n.º 2
0
bool ElGamal::BogusVerify(const BigInteger &M, const BigInteger &a, const BigInteger &b) const
{

// check a != 0 && a == (g^b * y^a + m) mod q

    try
    {
        if(a.cmp(BigInteger::ZERO)==0)
            return false;

//		BigInteger a1 = a.mod(q);
//		BigInteger b1 = b.mod(q);

        BigInteger gbq = g.modExp(b,p,recip,nb);
        BigInteger yaq = y.modExp(a,p,recip,nb);

        /*
        	cout << "p = " << p << endl;
        	cout << "g = mod(" << g << ",p)" << endl;
        	cout << "a = " << a << endl;
        	cout << "b = " << b << endl;
        	cout << "y = " << y << endl;

        	cout << "gbq = " << gbq << endl;
        	cout << "yaq = " << yaq << endl;*/

        BigInteger result;

        result = gbq.modMulRecip(yaq,p,recip,nb);
//		result = gbq.mul(yaq);
        result = result.add(M);
//		result = result.mod(p);
        result = result.mod(q);

        if(a.cmp(result)==0)
            return true;
        else
            return false;
    }
    catch(ArithmeticException &)
    {
    }

    return false;
}