summaryrefslogtreecommitdiff
path: root/rsa.cpp
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2004-04-29 14:48:51 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2004-04-29 14:48:51 +0000
commitf0e00c67ca788de19b18cac39ed3fdc904dbc811 (patch)
treeae70583b825bc83dedf5550661fdd3402502a0a7 /rsa.cpp
parent4891b094ae23709e802a3b636a6bee5618a12e78 (diff)
downloadcryptopp-f0e00c67ca788de19b18cac39ed3fdc904dbc811.tar.gz
add check for invalid RSA private key given n, e, d
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@164 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'rsa.cpp')
-rw-r--r--rsa.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/rsa.cpp b/rsa.cpp
index eb68a67..a7972c8 100644
--- a/rsa.cpp
+++ b/rsa.cpp
@@ -147,13 +147,20 @@ void InvertibleRSAFunction::Initialize(RandomNumberGenerator &rng, unsigned int
void InvertibleRSAFunction::Initialize(const Integer &n, const Integer &e, const Integer &d)
{
+ if (n.IsEven() || e.IsEven() | d.IsEven())
+ throw InvalidArgument("InvertibleRSAFunction: input is not a valid RSA private key");
+
m_n = n;
m_e = e;
m_d = d;
Integer r = --(d*e);
+ unsigned int s = 0;
while (r.IsEven())
+ {
r >>= 1;
+ s++;
+ }
ModularArithmetic modn(n);
for (Integer i = 2; ; ++i)
@@ -162,6 +169,7 @@ void InvertibleRSAFunction::Initialize(const Integer &n, const Integer &e, const
if (a == 1)
continue;
Integer b;
+ unsigned int j = 0;
while (a != -1)
{
b = modn.Square(a);
@@ -174,6 +182,8 @@ void InvertibleRSAFunction::Initialize(const Integer &n, const Integer &e, const
m_u = m_q.InverseMod(m_p);
return;
}
+ if (++j == s)
+ throw InvalidArgument("InvertibleRSAFunction: input is not a valid RSA private key");
a = b;
}
}