From patchwork Wed Nov 25 10:12:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 7696831 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 A537A9F1D3 for ; Wed, 25 Nov 2015 10:12:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C0C40208D7 for ; Wed, 25 Nov 2015 10:12:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E9A23208D1 for ; Wed, 25 Nov 2015 10:12:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752179AbbKYKMc (ORCPT ); Wed, 25 Nov 2015 05:12:32 -0500 Received: from mail-wm0-f52.google.com ([74.125.82.52]:38568 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752181AbbKYKMb (ORCPT ); Wed, 25 Nov 2015 05:12:31 -0500 Received: by wmec201 with SMTP id c201so63146685wme.1 for ; Wed, 25 Nov 2015 02:12:30 -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=nm47n7UWjfnfhQatX61kA6wEhgu8Lk9xVN1sTBPnuZo=; b=hWfkW2636pYMAZ62WYvnz7adDJB9nBzLSs0/nZ7FYFTcR2jAomMcifZ6GCYIlBeXWN xEkexqoUYaOC24KB42nVQJ7CzVFuHd5TlkYcWE0TYjy2H3qiGOwXzqQLzHoI8vOhbOfb 18K5ucN4Zih/R65ECF912YLwfcPKyGGWf3m8EBns2vcnCmIxaZXN1vHnSBz2O10CgDta +g6RWk9kBqnrLEC287LD94N3n3nSf4y4UOxPk/NXkTZWxpISCUcr+vGlRAog1hDY/sl2 5VQY8JT+8VW6HNzVxBcbCQ2Qez2C/vis2Awa8uhPBfBYjaUYRYemqpfiW4HxRqt0CjFw 8FZg== X-Received: by 10.28.126.215 with SMTP id z206mr3522708wmc.71.1448446350439; Wed, 25 Nov 2015 02:12:30 -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 z13sm22062283wjr.47.2015.11.25.02.12.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Nov 2015 02:12:29 -0800 (PST) From: Andrew Zaborowski To: linux-crypto@vger.kernel.org Subject: [PATCH v4 2/4] crypto: rsa: only require output buffers as big as needed. Date: Wed, 25 Nov 2015 11:12:15 +0100 Message-Id: <1448446337-17176-2-git-send-email-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1448446337-17176-1-git-send-email-andrew.zaborowski@intel.com> References: <1448446337-17176-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.4 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 --- No changes since v1 --- 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) {