summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLegrandin <gooksankoo@hoiptorrow.mailexpire.com>2011-01-16 21:46:15 +0100
committerDwayne C. Litzenberger <dlitz@dlitz.net>2011-10-17 22:15:13 -0400
commit61f296be7d9d5f0b20be189e2cc69d6b2f9b2e69 (patch)
tree61c302cd9c4eb6c7bd75faade21f8cd82ca95fe3
parentc1ad8f08c96e273f49fd0a37940da04fb42b7c89 (diff)
downloadpycrypto-61f296be7d9d5f0b20be189e2cc69d6b2f9b2e69.tar.gz
_RSAKey._decrypt() uses Garner's algorithmwhen possible, as _fastmath.c does.
-rw-r--r--lib/Crypto/PublicKey/_slowmath.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/Crypto/PublicKey/_slowmath.py b/lib/Crypto/PublicKey/_slowmath.py
index 478b530..d7502ba 100644
--- a/lib/Crypto/PublicKey/_slowmath.py
+++ b/lib/Crypto/PublicKey/_slowmath.py
@@ -50,7 +50,15 @@ class _RSAKey(object):
# compute c**d (mod n)
if not self.has_private():
raise TypeError("No private key")
- return pow(c, self.d, self.n) # TODO: CRT exponentiation
+ if (hasattr(self,'p') and hasattr(self,'q') and hasattr(self,'u')):
+ m1 = pow(c, self.d % (self.p-1), self.p)
+ m2 = pow(c, self.d % (self.q-1), self.q)
+ h = m2 - m1
+ if (h<0):
+ h = h + self.q
+ h = h*self.u % self.q
+ return h*self.p+m1
+ return pow(c, self.d, self.n)
def _encrypt(self, m):
# compute m**d (mod n)