summaryrefslogtreecommitdiff
path: root/crypto/rsa.c
diff options
context:
space:
mode:
authorTadeusz Struk <tadeusz.struk@intel.com>2015-07-15 15:28:43 -0700
committerHerbert Xu <herbert@gondor.apana.org.au>2015-07-17 21:20:19 +0800
commit16e79e47b3f59cae50770d56db5ad297e79af7b5 (patch)
treea6cf0165f13a7b2d3ec205692be163c4a5924e71 /crypto/rsa.c
parent1f8db2bd3e0d3fb98be1be8f682a0efb3c6e883b (diff)
downloadlinux-crypto-16e79e47b3f59cae50770d56db5ad297e79af7b5.tar.gz
linux-crypto-16e79e47b3f59cae50770d56db5ad297e79af7b5.zip
crypto: rsa - limit supported key lengths
Introduce constrains for RSA keys lengths. Only key lengths of 512, 1024, 1536, 2048, 3072, and 4096 bits will be supported. Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/rsa.c')
-rw-r--r--crypto/rsa.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/crypto/rsa.c b/crypto/rsa.c
index 752af065..466003e1 100644
--- a/crypto/rsa.c
+++ b/crypto/rsa.c
@@ -267,12 +267,36 @@ err_free_m:
return ret;
}
+static int rsa_check_key_length(unsigned int len)
+{
+ switch (len) {
+ case 512:
+ case 1024:
+ case 1536:
+ case 2048:
+ case 3072:
+ case 4096:
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
static int rsa_setkey(struct crypto_akcipher *tfm, const void *key,
unsigned int keylen)
{
struct rsa_key *pkey = akcipher_tfm_ctx(tfm);
+ int ret;
- return rsa_parse_key(pkey, key, keylen);
+ ret = rsa_parse_key(pkey, key, keylen);
+ if (ret)
+ return ret;
+
+ if (rsa_check_key_length(mpi_get_size(pkey->n) << 3)) {
+ rsa_free_key(pkey);
+ ret = -EINVAL;
+ }
+ return ret;
}
static void rsa_exit_tfm(struct crypto_akcipher *tfm)