From patchwork Wed Sep 23 22:49:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tadeusz Struk X-Patchwork-Id: 7252891 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5858C9F40A for ; Wed, 23 Sep 2015 22:51:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6F3B6206EE for ; Wed, 23 Sep 2015 22:51:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5DB70206E6 for ; Wed, 23 Sep 2015 22:51:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755161AbbIWWu7 (ORCPT ); Wed, 23 Sep 2015 18:50:59 -0400 Received: from mga02.intel.com ([134.134.136.20]:16945 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754634AbbIWWu7 (ORCPT ); Wed, 23 Sep 2015 18:50:59 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP; 23 Sep 2015 15:50:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,579,1437462000"; d="scan'208";a="795960945" Received: from tstruk-mobl1.jf.intel.com (HELO [127.0.1.1]) ([134.134.171.62]) by fmsmga001.fm.intel.com with ESMTP; 23 Sep 2015 15:50:59 -0700 Subject: [PATCH 2/2] crytpo: rsa - use mpi slg helpers to import and export data From: Tadeusz Struk To: herbert@gondor.apana.org.au Cc: linux-crypto@vger.kernel.org, tadeusz.struk@intel.com Date: Wed, 23 Sep 2015 15:49:03 -0700 Message-ID: <20150923224903.23780.96938.stgit@tstruk-mobl1> In-Reply-To: <20150923224853.23780.95440.stgit@tstruk-mobl1> References: <20150923224853.23780.95440.stgit@tstruk-mobl1> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Use the new mpi_write_to_sgl and mpi_read_raw_from_sgl helpers to import and export data. Signed-off-by: Tadeusz Struk --- crypto/rsa.c | 127 +++++----------------------------------------------------- 1 file changed, 12 insertions(+), 115 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/crypto/rsa.c b/crypto/rsa.c index df81bbf..ce293d3 100644 --- a/crypto/rsa.c +++ b/crypto/rsa.c @@ -13,7 +13,6 @@ #include #include #include -#include /* * RSAEP function [RFC3447 sec 5.1.1] @@ -100,18 +99,7 @@ static int rsa_enc(struct akcipher_request *req) } ret = -ENOMEM; - if (sg_is_last(req->src)) { - m = mpi_read_raw_data(sg_virt(req->src), src_len); - } else { - void *ptr = kmalloc(src_len, GFP_KERNEL); - - if (!ptr) - goto err_free_c; - - scatterwalk_map_and_copy(ptr, req->src, 0, src_len, 0); - m = mpi_read_raw_data(ptr, src_len); - kfree(ptr); - } + m = mpi_read_raw_from_sgl(req->src); if (!m) goto err_free_c; @@ -119,26 +107,12 @@ static int rsa_enc(struct akcipher_request *req) if (ret) goto err_free_m; - if (sg_is_last(req->dst)) { - ret = mpi_read_buffer(c, sg_virt(req->dst), dst_len, - &req->out_len, &sign); - } else { - void *ptr = kmalloc(dst_len, GFP_KERNEL); - - if (!ptr) - goto err_free_m; - - ret = mpi_read_buffer(c, ptr, dst_len, &req->out_len, &sign); - scatterwalk_map_and_copy(ptr, req->dst, 0, dst_len, 1); - kfree(ptr); - } + ret = mpi_write_to_sgl(c, req->dst, &req->out_len, &sign); if (ret) goto err_free_m; - if (sign < 0) { + if (sign < 0) ret = -EBADMSG; - goto err_free_m; - } err_free_m: mpi_free(m); @@ -171,18 +145,7 @@ static int rsa_dec(struct akcipher_request *req) } ret = -ENOMEM; - if (sg_is_last(req->src)) { - c = mpi_read_raw_data(sg_virt(req->src), src_len); - } else { - void *ptr = kmalloc(src_len, GFP_KERNEL); - - if (!ptr) - goto err_free_m; - - scatterwalk_map_and_copy(ptr, req->src, 0, src_len, 0); - c = mpi_read_raw_data(ptr, src_len); - kfree(ptr); - } + c = mpi_read_raw_from_sgl(req->src); if (!c) goto err_free_m; @@ -190,27 +153,12 @@ static int rsa_dec(struct akcipher_request *req) if (ret) goto err_free_c; - if (sg_is_last(req->dst)) { - ret = mpi_read_buffer(m, sg_virt(req->dst), dst_len, - &req->out_len, &sign); - } else { - void *ptr = kmalloc(dst_len, GFP_KERNEL); - - if (!ptr) - goto err_free_c; - - ret = mpi_read_buffer(m, ptr, dst_len, &req->out_len, &sign); - scatterwalk_map_and_copy(ptr, req->dst, 0, dst_len, 1); - kfree(ptr); - } + ret = mpi_write_to_sgl(m, req->dst, &req->out_len, &sign); if (ret) goto err_free_c; - if (sign < 0) { + if (sign < 0) ret = -EBADMSG; - goto err_free_c; - } - err_free_c: mpi_free(c); err_free_m: @@ -242,19 +190,7 @@ static int rsa_sign(struct akcipher_request *req) } ret = -ENOMEM; - if (sg_is_last(req->src)) { - m = mpi_read_raw_data(sg_virt(req->src), src_len); - } else { - void *ptr = kmalloc(src_len, GFP_KERNEL); - - if (!ptr) - goto err_free_s; - - scatterwalk_map_and_copy(ptr, req->src, 0, src_len, 0); - m = mpi_read_raw_data(ptr, src_len); - kfree(ptr); - - } + m = mpi_read_raw_from_sgl(req->src); if (!m) goto err_free_s; @@ -262,26 +198,12 @@ static int rsa_sign(struct akcipher_request *req) if (ret) goto err_free_m; - if (sg_is_last(req->dst)) { - ret = mpi_read_buffer(s, sg_virt(req->dst), dst_len, - &req->out_len, &sign); - } else { - void *ptr = kmalloc(dst_len, GFP_KERNEL); - - if (!ptr) - goto err_free_m; - - ret = mpi_read_buffer(s, ptr, dst_len, &req->out_len, &sign); - scatterwalk_map_and_copy(ptr, req->dst, 0, dst_len, 1); - kfree(ptr); - } + ret = mpi_write_to_sgl(s, req->dst, &req->out_len, &sign); if (ret) goto err_free_m; - if (sign < 0) { + if (sign < 0) ret = -EBADMSG; - goto err_free_m; - } err_free_m: mpi_free(m); @@ -314,18 +236,7 @@ static int rsa_verify(struct akcipher_request *req) } ret = -ENOMEM; - if (sg_is_last(req->src)) { - s = mpi_read_raw_data(sg_virt(req->src), src_len); - } else { - void *ptr = kmalloc(src_len, GFP_KERNEL); - - if (!ptr) - goto err_free_m; - - scatterwalk_map_and_copy(ptr, req->src, 0, src_len, 0); - s = mpi_read_raw_data(ptr, src_len); - kfree(ptr); - } + s = mpi_read_raw_from_sgl(req->src); if (!s) { ret = -ENOMEM; goto err_free_m; @@ -335,26 +246,12 @@ static int rsa_verify(struct akcipher_request *req) if (ret) goto err_free_s; - if (sg_is_last(req->dst)) { - ret = mpi_read_buffer(m, sg_virt(req->dst), dst_len, - &req->out_len, &sign); - } else { - void *ptr = kmalloc(dst_len, GFP_KERNEL); - - if (!ptr) - goto err_free_s; - - ret = mpi_read_buffer(m, ptr, dst_len, &req->out_len, &sign); - scatterwalk_map_and_copy(ptr, req->dst, 0, dst_len, 1); - kfree(ptr); - } + ret = mpi_write_to_sgl(m, req->dst, &req->out_len, &sign); if (ret) goto err_free_s; - if (sign < 0) { + if (sign < 0) ret = -EBADMSG; - goto err_free_s; - } err_free_s: mpi_free(s);