Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1360915 > unrolled thread
| Started by | maitesin <oscar.forner.martinez@gmail.com> |
|---|---|
| First post | 2016-03-18 21:50 +0100 |
| Last post | 2016-03-19 09:10 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH] crypto: cleaning and refactoring in rsa.c maitesin <oscar.forner.martinez@gmail.com> - 2016-03-18 21:50 +0100
Re: [PATCH] crypto: cleaning and refactoring in rsa.c Herbert Xu <herbert@gondor.apana.org.au> - 2016-03-19 09:10 +0100
| From | maitesin <oscar.forner.martinez@gmail.com> |
|---|---|
| Date | 2016-03-18 21:50 +0100 |
| Subject | [PATCH] crypto: cleaning and refactoring in rsa.c |
| Message-ID | <re9vj-824-1@gated-at.bofh.it> |
* 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
[toc] | [next] | [standalone]
| From | Herbert Xu <herbert@gondor.apana.org.au> |
|---|---|
| Date | 2016-03-19 09:10 +0100 |
| Message-ID | <rek7n-5yp-9@gated-at.bofh.it> |
| In reply to | #1360915 |
On Fri, Mar 18, 2016 at 08:39:51PM +0000, maitesin wrote: > * 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> Nack. I don't think this patch improves the code at all. -- Email: Herbert Xu <herbert@gondor.apana.org.au> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web