Integer ModularRoot(const Integer &a, const Integer &e, const Integer &p, const Integer &q) { Integer dp = EuclideanMultiplicativeInverse(e, p-1); Integer dq = EuclideanMultiplicativeInverse(e, q-1); Integer u = EuclideanMultiplicativeInverse(p, q); assert(!!dp && !!dq && !!u); return ModularRoot(a, dp, dq, p, q, u); }
Integer InvertibleRSAFunction::CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const { DoQuickSanityCheck(); ModularArithmetic modn(m_n); Integer r(rng, Integer::One(), m_n - Integer::One()); Integer re = modn.Exponentiate(r, m_e); re = modn.Multiply(re, x); // blind // here we follow the notation of PKCS #1 and let u=q inverse mod p // but in ModRoot, u=p inverse mod q, so we reverse the order of p and q Integer y = ModularRoot(re, m_dq, m_dp, m_q, m_p, m_u); y = modn.Divide(y, r); // unblind ASSERT( modn.Exponentiate(y, m_e) == x ); // check return y; }
Integer InvertibleRSAFunction::CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const { DoQuickSanityCheck(); ModularArithmetic modn(m_n); Integer r(rng, Integer::One(), m_n - Integer::One()); Integer re = modn.Exponentiate(r, m_e); re = modn.Multiply(re, x); // blind // here we follow the notation of PKCS #1 and let u=q inverse mod p // but in ModRoot, u=p inverse mod q, so we reverse the order of p and q Integer y = ModularRoot(re, m_dq, m_dp, m_q, m_p, m_u); y = modn.Divide(y, r); // unblind if (modn.Exponentiate(y, m_e) != x) // check throw Exception(Exception::OTHER_ERROR, "InvertibleRSAFunction: computational error during private key operation"); return y; }
Integer RSA_PrivateKey::CalculateInverse(RandomNumberGenerator& rng, const Integer& x) const { ModularArithmetic modn(n_); Integer r(rng, Integer::One(), n_ - Integer::One()); Integer re = modn.Exponentiate(r, e_); re = modn.Multiply(re, x); // blind // here we follow the notation of PKCS #1 and let u=q inverse mod p // but in ModRoot, u=p inverse mod q, so we reverse the order of p and q Integer y = ModularRoot(re, dq_, dp_, q_, p_, u_); y = modn.Divide(y, r); // unblind return y; }
Integer InvertableRSAFunction::CalculateInverse(const Integer &x) const { // here we follow the notation of PKCS #1 and let u=q inverse mod p // but in ModRoot, u=p inverse mod q, so we reverse the order of p and q return ModularRoot(x, dq, dp, q, p, u); }