summaryrefslogtreecommitdiff
path: root/rsa-decrypt.c
diff options
context:
space:
mode:
Diffstat (limited to 'rsa-decrypt.c')
-rw-r--r--rsa-decrypt.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/rsa-decrypt.c b/rsa-decrypt.c
index 7681439d..540d8baa 100644
--- a/rsa-decrypt.c
+++ b/rsa-decrypt.c
@@ -48,6 +48,16 @@ rsa_decrypt(const struct rsa_private_key *key,
int res;
mpz_init(m);
+
+ /* First check that input is in range. Since we don't have the
+ public key available here, we need to reconstruct n. */
+ mpz_mul (m, key->p, key->q);
+ if (mpz_sgn (gibberish) < 0 || mpz_cmp (gibberish, m) >= 0)
+ {
+ mpz_clear (m);
+ return 0;
+ }
+
rsa_compute_root(key, m, gibberish);
res = pkcs1_decrypt (key->size, m, length, message);