[PATCH v2 11/11] crypto: rsa - do checks before allocating data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Tudor Ambarus <tudor.ambarus@xxxxxxxxxxxxx>
---
 crypto/rsa.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/crypto/rsa.c b/crypto/rsa.c
index 4c280b6..a80f76d 100644
--- a/crypto/rsa.c
+++ b/crypto/rsa.c
@@ -279,6 +279,9 @@ static int rsa_set_pub_key(struct crypto_akcipher *tfm, const void *key,
 	if (ret)
 		return ret;
 
+	if (rsa_check_key_length(raw_key.n_sz << 3))
+		return -EINVAL;
+
 	mpi_key->e = mpi_read_raw_data(raw_key.e, raw_key.e_sz);
 	if (!mpi_key->e)
 		goto err;
@@ -287,11 +290,6 @@ static int rsa_set_pub_key(struct crypto_akcipher *tfm, const void *key,
 	if (!mpi_key->n)
 		goto err;
 
-	if (rsa_check_key_length(mpi_get_size(mpi_key->n) << 3)) {
-		rsa_free_mpi_key(mpi_key);
-		return -EINVAL;
-	}
-
 	return 0;
 
 err:
@@ -313,6 +311,9 @@ static int rsa_set_priv_key(struct crypto_akcipher *tfm, const void *key,
 	if (ret)
 		return ret;
 
+	if (rsa_check_key_length(raw_key.n_sz << 3))
+		return -EINVAL;
+
 	mpi_key->d = mpi_read_raw_data(raw_key.d, raw_key.d_sz);
 	if (!mpi_key->d)
 		goto err;
@@ -325,11 +326,6 @@ static int rsa_set_priv_key(struct crypto_akcipher *tfm, const void *key,
 	if (!mpi_key->n)
 		goto err;
 
-	if (rsa_check_key_length(mpi_get_size(mpi_key->n) << 3)) {
-		rsa_free_mpi_key(mpi_key);
-		return -EINVAL;
-	}
-
 	return 0;
 
 err:
-- 
2.7.4




[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]

  Powered by Linux