From patchwork Fri Mar 18 20:39:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Forner Martinez X-Patchwork-Id: 8623701 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id ABB41C0553 for ; Fri, 18 Mar 2016 20:44:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CD65E2028D for ; Fri, 18 Mar 2016 20:44:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B8A3E2026F for ; Fri, 18 Mar 2016 20:44:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754494AbcCRUoX (ORCPT ); Fri, 18 Mar 2016 16:44:23 -0400 Received: from mail-wm0-f53.google.com ([74.125.82.53]:38190 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752804AbcCRUoW (ORCPT ); Fri, 18 Mar 2016 16:44:22 -0400 Received: by mail-wm0-f53.google.com with SMTP id l68so52939634wml.1; Fri, 18 Mar 2016 13:44:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=claR84BWJ4oxJPnpA8DW9Wj0WjIGGqBYHykqahDD2sw=; b=k71VLOAcsZubBmJYknYpVtdS8YwuMcU7c49i68CszjYVhtvew38BknnkawfCdmjuAv nVyIK3aToT3vxvYvIk0TwgbRD9SAQnBX2pLl3WL+N7O6OUAh+GjKQZLSz9KFCmEOeT/H FLmzLJSPlWwue3EFT4jS8hLYJenlvh9TU0i2tXOW8g/1nOiLuXOKgK88RVH4KKWkngBA yYspZR1ahCI0yVLIEDAPXC3Ey6bJPr3DG/5qB+kCdqNcqDDywoJpXoVfX3Iwk0IdJwlx DWXX4DPjsxm0j9mdd6hp/FEg+HMGHjazfd64LFx040uq+zfssHqmkFCUYVn3aEz1xQ/g 6IcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=claR84BWJ4oxJPnpA8DW9Wj0WjIGGqBYHykqahDD2sw=; b=HmeCSfbfOKL/FpxSOpEz2uWdtCZ4KpuBiemzBKRzsFPkqaVF2TVnXFaWH9uXBnJULy yyl073P+Gw7obbe4PYbpTM0sZs5VbjPYAQzJxmk+kTWvRO37KXaXv4b4O/LGnhzJD0l9 ++x8TCAf0fFX3c9VMHCOvsjHXTdf8UP4DCadbTTSjFUaOAgagCpCNb295PeDBMsc9v5U jniLtb2ARjBMnEW0E5EmXOzOdWZZ7/t+LNA97QupPXPKWn11HJPsltqDovl7syOMT8T/ 5+MjOmYAX23SY+nztniNoCfpMYt3KYmxL5b3vWtJaui2UFwrDKHt4yPKd012MceRbmF8 GJVg== X-Gm-Message-State: AD7BkJJeqAp4Lh6CJnUq8u8v2+vqFf0AdlWOeudB1V6mRtzpjoJZaBa27YpfR5pEpDABQw== X-Received: by 10.194.216.2 with SMTP id om2mr17841245wjc.164.1458333861209; Fri, 18 Mar 2016 13:44:21 -0700 (PDT) Received: from Ryuk.Home (97e107d4.skybroadband.com. [151.225.7.212]) by smtp.gmail.com with ESMTPSA id v188sm875514wmv.3.2016.03.18.13.44.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 18 Mar 2016 13:44:20 -0700 (PDT) From: maitesin X-Google-Original-From: maitesin To: herbert@gondor.apana.org.au, davem@davemloft.net Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, maitesin , Oscar Forner Martinez Subject: [PATCH] crypto: cleaning and refactoring in rsa.c Date: Fri, 18 Mar 2016 20:39:51 +0000 Message-Id: <1458333591-28297-1-git-send-email-violador.de.segmentos@gmail.com> X-Mailer: git-send-email 2.7.3 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP * 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 --- 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); }