summaryrefslogtreecommitdiff
path: root/rsa.cpp
diff options
context:
space:
mode:
authorweidai <weidai11@users.noreply.github.com>2003-03-25 02:11:53 +0000
committerweidai <weidai11@users.noreply.github.com>2003-03-25 02:11:53 +0000
commit2ccaf2ef1d78727194b59d986b491e717c508917 (patch)
treec0941e611df79f42cd10632c1cd2fd4dc2895078 /rsa.cpp
parenta7d2ffa2b3d5148f28ef1232d11b2b2ad5068d77 (diff)
downloadcryptopp-git-2ccaf2ef1d78727194b59d986b491e717c508917.tar.gz
minor changes
Diffstat (limited to 'rsa.cpp')
-rw-r--r--rsa.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/rsa.cpp b/rsa.cpp
index 62e95921..76d4aa9a 100644
--- a/rsa.cpp
+++ b/rsa.cpp
@@ -217,13 +217,17 @@ Integer InvertibleRSAFunction::CalculateInverse(RandomNumberGenerator &rng, cons
{
DoQuickSanityCheck();
ModularArithmetic modn(m_n);
- Integer r(rng, Integer::One(), m_n - Integer::One());
+ Integer r, rInv;
+ do { // do this loop for people using small numbers for testing
+ r.Randomize(rng, Integer::One(), m_n - Integer::One());
+ rInv = modn.MultiplicativeInverse(r);
+ } while (rInv.IsZero());
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
+ y = modn.Multiply(y, rInv); // unblind
if (modn.Exponentiate(y, m_e) != x) // check
throw Exception(Exception::OTHER_ERROR, "InvertibleRSAFunction: computational error during private key operation");
return y;