mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: maitesin <oscar.forner.martinez@gmail.com>
To: herbert@gondor.apana.org.au, davem@davemloft.net
Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
	maitesin <violador.de.segmentos@gmail.com>,
	Oscar Forner Martinez <oscar.forner.martinez@gmail.com>
Subject: [PATCH] crypto: cleaning and refactoring in rsa.c
Date: Fri, 18 Mar 2016 20:39:51 +0000	[thread overview]
Message-ID: <1458333591-28297-1-git-send-email-violador.de.segmentos@gmail.com> (raw)

* Removed several unused initializations of variables.
* Inlined couple of functions.
* rsa_check_key_length: changed to use only the switch statement.
* rsa_setkey: refactored the implementation to be closer to the other
functions in the file.

Signed-off-by: Oscar Forner Martinez <oscar.forner.martinez@gmail.com>
---
 crypto/rsa.c | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/crypto/rsa.c b/crypto/rsa.c
index 466003e..0832b38 100644
--- a/crypto/rsa.c
+++ b/crypto/rsa.c
@@ -80,8 +80,7 @@ static int rsa_enc(struct akcipher_request *req)
 	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
 	const struct rsa_key *pkey = rsa_get_key(tfm);
 	MPI m, c = mpi_alloc(0);
-	int ret = 0;
-	int sign;
+	int ret, sign;
 
 	if (!c)
 		return -ENOMEM;
@@ -128,8 +127,7 @@ static int rsa_dec(struct akcipher_request *req)
 	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
 	const struct rsa_key *pkey = rsa_get_key(tfm);
 	MPI c, m = mpi_alloc(0);
-	int ret = 0;
-	int sign;
+	int ret, sign;
 
 	if (!m)
 		return -ENOMEM;
@@ -176,8 +174,7 @@ static int rsa_sign(struct akcipher_request *req)
 	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
 	const struct rsa_key *pkey = rsa_get_key(tfm);
 	MPI m, s = mpi_alloc(0);
-	int ret = 0;
-	int sign;
+	int ret, sign;
 
 	if (!s)
 		return -ENOMEM;
@@ -224,8 +221,7 @@ static int rsa_verify(struct akcipher_request *req)
 	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
 	const struct rsa_key *pkey = rsa_get_key(tfm);
 	MPI s, m = mpi_alloc(0);
-	int ret = 0;
-	int sign;
+	int ret, sign;
 
 	if (!m)
 		return -ENOMEM;
@@ -277,25 +273,24 @@ static int rsa_check_key_length(unsigned int len)
 	case 3072:
 	case 4096:
 		return 0;
+	default:
+		return -EINVAL;
 	}
-
-	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;
+	int ret = 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)) {
+	ret = rsa_check_key_length(mpi_get_size(pkey->n) << 3);
+	if (ret)
 		rsa_free_key(pkey);
-		ret = -EINVAL;
-	}
+
 	return ret;
 }
 
@@ -322,12 +317,12 @@ static struct akcipher_alg rsa = {
 	},
 };
 
-static int rsa_init(void)
+static inline int rsa_init(void)
 {
 	return crypto_register_akcipher(&rsa);
 }
 
-static void rsa_exit(void)
+static inline void rsa_exit(void)
 {
 	crypto_unregister_akcipher(&rsa);
 }
-- 
2.7.3

             reply	other threads:[~2016-03-18 20:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-18 20:39 maitesin [this message]
2016-03-19  8:03 ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1458333591-28297-1-git-send-email-violador.de.segmentos@gmail.com \
    --to=oscar.forner.martinez@gmail.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=violador.de.segmentos@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®