From patchwork Thu Jul 2 05:18:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lokesh Vutla X-Patchwork-Id: 6707761 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 D25009FBF9 for ; Thu, 2 Jul 2015 05:24:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0BB4720671 for ; Thu, 2 Jul 2015 05:24:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CB53D206E0 for ; Thu, 2 Jul 2015 05:24:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752993AbbGBFWM (ORCPT ); Thu, 2 Jul 2015 01:22:12 -0400 Received: from comal.ext.ti.com ([198.47.26.152]:35625 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752398AbbGBFWA (ORCPT ); Thu, 2 Jul 2015 01:22:00 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id t625LvtY020687; Thu, 2 Jul 2015 00:21:57 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id t625LvRN015366; Thu, 2 Jul 2015 00:21:57 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.224.2; Thu, 2 Jul 2015 00:21:51 -0500 Received: from a0131933.apr.dhcp.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id t625Lb9b024297; Thu, 2 Jul 2015 00:21:54 -0500 From: Lokesh Vutla To: , , CC: , , , , Subject: [PATCH 06/10] crypto: omap-aes: gcm: Handle inputs properly Date: Thu, 2 Jul 2015 10:48:36 +0530 Message-ID: <1435814320-30347-7-git-send-email-lokeshvutla@ti.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1435814320-30347-1-git-send-email-lokeshvutla@ti.com> References: <1435814320-30347-1-git-send-email-lokeshvutla@ti.com> 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=-7.5 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 Its not necessary that assoc data and plain text is passed always. Add these checks before processing the input. Signed-off-by: Lokesh Vutla --- drivers/crypto/omap-aes-gcm.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/omap-aes-gcm.c b/drivers/crypto/omap-aes-gcm.c index 1be9d91..72815af 100644 --- a/drivers/crypto/omap-aes-gcm.c +++ b/drivers/crypto/omap-aes-gcm.c @@ -87,7 +87,7 @@ static int omap_aes_gcm_copy_buffers(struct omap_aes_dev *dd, struct aead_request *req) { void *buf_in; - int alen, clen; + int alen, clen, nsg; struct crypto_aead *aead = crypto_aead_reqtfm(req); unsigned int authlen = crypto_aead_authsize(aead); u32 dec = !(dd->flags & FLAGS_ENCRYPT); @@ -97,12 +97,18 @@ static int omap_aes_gcm_copy_buffers(struct omap_aes_dev *dd, dd->sgs_copied = 0; - sg_init_table(dd->in_sgl, 2); - buf_in = sg_virt(req->assoc); - sg_set_buf(dd->in_sgl, buf_in, alen); + nsg = 1 + !!(req->assoclen && req->cryptlen); - buf_in = sg_virt(req->src); - sg_set_buf(&dd->in_sgl[1], buf_in, clen); + sg_init_table(dd->in_sgl, nsg); + if (req->assoclen) { + buf_in = sg_virt(req->assoc); + sg_set_buf(dd->in_sgl, buf_in, alen); + } + + if (req->cryptlen) { + buf_in = sg_virt(req->src); + sg_set_buf(&dd->in_sgl[nsg - 1], buf_in, clen); + } dd->in_sg = dd->in_sgl; dd->total = clen; @@ -258,6 +264,8 @@ static int omap_aes_gcm_crypt(struct aead_request *req, unsigned long mode) { struct omap_aes_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req)); struct omap_aes_reqctx *rctx = aead_request_ctx(req); + struct crypto_aead *aead = crypto_aead_reqtfm(req); + unsigned int authlen = crypto_aead_authsize(aead); struct omap_aes_dev *dd; __be32 counter = cpu_to_be32(1); int err; @@ -270,6 +278,12 @@ static int omap_aes_gcm_crypt(struct aead_request *req, unsigned long mode) if (err) return err; + if (req->assoclen + req->cryptlen == 0) { + scatterwalk_map_and_copy(ctx->auth_tag, req->dst, 0, authlen, + 1); + return 0; + } + dd = omap_aes_find_dev(ctx); if (!dd) return -ENODEV;