From patchwork Fri Nov 13 11:01:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 7610831 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 23FA9BF90C for ; Fri, 13 Nov 2015 11:01:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 41EDA20635 for ; Fri, 13 Nov 2015 11:01:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4C7B8207A5 for ; Fri, 13 Nov 2015 11:01:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754465AbbKMLBx (ORCPT ); Fri, 13 Nov 2015 06:01:53 -0500 Received: from mail-wm0-f42.google.com ([74.125.82.42]:36255 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753659AbbKMLBw (ORCPT ); Fri, 13 Nov 2015 06:01:52 -0500 Received: by wmww144 with SMTP id w144so23801915wmw.1 for ; Fri, 13 Nov 2015 03:01:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=aSOzRq2GYLgKxEMWjHC7PU8xAcuvU7Bgk5KYSRNgM0o=; b=EBKEvX7XcRxxw6qVJC2sTc1ZAYNldjuXqsGhuTCzoD3OMwT7JpuKB0rfdAjXAOMnI5 gdDQhwD7SYEyIKaGRnlJl8zIXtteuIw7Cm5dbF0pNktCVRoMwIc0wJ8j8xcRc6CHVIF+ UAkm5oqo4/8P1sgI2A+WgOLI/i3kwKI9KPi4086Mv6PdsL0GyJ2NGYq1e7YMsXF+Vz0R MZ1sWa49Rxn4wlpPAvE4xjjnbLIC2IUexDIEaCaJRHDOW37wZWwJy+oWSW6nn4V7uqcl r/NuKw9ulRTIIIIQdnMSGqoRDbqvDQYzAhDcIAsThZcqRmT+aEdi+amR4llXp06uptKb xNdg== X-Received: by 10.194.78.112 with SMTP id a16mr21903253wjx.70.1447412511678; Fri, 13 Nov 2015 03:01:51 -0800 (PST) Received: from localhost.localdomain (9.Red-2-136-109.dynamicIP.rima-tde.net. [2.136.109.9]) by smtp.gmail.com with ESMTPSA id w73sm3401681wme.12.2015.11.13.03.01.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Nov 2015 03:01:51 -0800 (PST) From: Andrew Zaborowski To: linux-crypto@vger.kernel.org Subject: [PATCH 2/4] crypto: rsa: only require output buffers as big as needed. Date: Fri, 13 Nov 2015 12:01:33 +0100 Message-Id: <1447412495-4370-2-git-send-email-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1447412495-4370-1-git-send-email-andrew.zaborowski@intel.com> References: <1447412495-4370-1-git-send-email-andrew.zaborowski@intel.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, 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 rhe RSA operations explicitly left-align the integers being written skipping any leading zero bytes, but still require the output buffers to include just enough space for the integer + the leading zero bytes. Since the size of integer + the leading zero bytes (i.e. the key modulus size) can now be obtained more easily through crypto_akcipher_maxsize change the operations to only require as big a buffer as actually needed if the caller has that information. The semantics for request->dst_len don't change. Signed-off-by: Andrew Zaborowski --- crypto/rsa.c | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/crypto/rsa.c b/crypto/rsa.c index 1093e04..58aad69 100644 --- a/crypto/rsa.c +++ b/crypto/rsa.c @@ -91,12 +91,6 @@ static int rsa_enc(struct akcipher_request *req) goto err_free_c; } - if (req->dst_len < mpi_get_size(pkey->n)) { - req->dst_len = mpi_get_size(pkey->n); - ret = -EOVERFLOW; - goto err_free_c; - } - ret = -ENOMEM; m = mpi_read_raw_from_sgl(req->src, req->src_len); if (!m) @@ -136,12 +130,6 @@ static int rsa_dec(struct akcipher_request *req) goto err_free_m; } - if (req->dst_len < mpi_get_size(pkey->n)) { - req->dst_len = mpi_get_size(pkey->n); - ret = -EOVERFLOW; - goto err_free_m; - } - ret = -ENOMEM; c = mpi_read_raw_from_sgl(req->src, req->src_len); if (!c) @@ -180,12 +168,6 @@ static int rsa_sign(struct akcipher_request *req) goto err_free_s; } - if (req->dst_len < mpi_get_size(pkey->n)) { - req->dst_len = mpi_get_size(pkey->n); - ret = -EOVERFLOW; - goto err_free_s; - } - ret = -ENOMEM; m = mpi_read_raw_from_sgl(req->src, req->src_len); if (!m) @@ -225,12 +207,6 @@ static int rsa_verify(struct akcipher_request *req) goto err_free_m; } - if (req->dst_len < mpi_get_size(pkey->n)) { - req->dst_len = mpi_get_size(pkey->n); - ret = -EOVERFLOW; - goto err_free_m; - } - ret = -ENOMEM; s = mpi_read_raw_from_sgl(req->src, req->src_len); if (!s) {