From patchwork Tue Nov 5 14:00:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 178500 Delivered-To: patch@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp709186ocf; Tue, 5 Nov 2019 06:01:31 -0800 (PST) X-Google-Smtp-Source: APXvYqxaBMUCosoZxMvCTItHqqpZewV+G5z4sPFx3ydNrpm9VDl9b6R4d3cMUQkxwNqd3+no4/v5 X-Received: by 2002:adf:f306:: with SMTP id i6mr27347355wro.209.1572962490964; Tue, 05 Nov 2019 06:01:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572962490; cv=none; d=google.com; s=arc-20160816; b=xLdzhhC2YXUQvxIBRZIZGwjjXZybp/6KUXtbVFSLgqm1XUR5Lf4j2js2OUWKfXz9CE ARh7xOl4HcX3n2mWwI2IWrmvUVR/rLdjH4/nKuOHci3y1gPpn+gFkim7UC4H4ry8liYd 5zO+1U48EfMd1emRKQBCMHHb1I2nh1aNgaP1/MSzm/FFvfVjeK9mxKiCVsdYXWnbNctz QmhGF5MaCTu62Wwnky7plZe/+AND1Kqr1itYNPnnuRZT6hQaoSNg0YOjV9GTPJbSVl3O QwnX+/Q8KWHzL48EZnUaGLIys/sCrjWa/kSaZSLqL11IPMicjCuFEr/yXfly11RjGQYH XOHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=LtkTVpWL6TMo5645N6f1i/Ciz76+fqNN9ZgDR0Mf4kQ=; b=LTjY/SVU0V2rUJFXIwDicQs99VmE7JFMj4fiimdHmTNHtM5HZYQDTPjnypU2GpucZL O/fYoG/dCzBMXyD+++Hv31d+q8Yqw0AehnN0+YfVYvPHgWF2aIDR7+ta0OsYk3/Y+IEi YvAkyTszD7KJcKYZCbkFryeDT0WtH35UNjZj4x1MuzklKpo7q9fc00AYGKa/JBkuDzCZ 8RTdcLhPalk66AQcBTAG0iZO4z5exCMg6BpMHaIXdFgJoV6pJxClSuXxByI+Tcdc1eWm taKhjXWnr6zSlW986q4BmvZN19YAJKJo6asyvXt0A4I8wMJsbyYNU1UE1ZUM/JNdYtHw zZMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=fF5JqDG8; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dk11si13340421ejb.97.2019.11.05.06.01.30; Tue, 05 Nov 2019 06:01:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=fF5JqDG8; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389300AbfKEOB3 (ORCPT + 3 others); Tue, 5 Nov 2019 09:01:29 -0500 Received: from fllv0015.ext.ti.com ([198.47.19.141]:43890 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389290AbfKEOB3 (ORCPT ); Tue, 5 Nov 2019 09:01:29 -0500 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1MQE071469; Tue, 5 Nov 2019 08:01:22 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1572962482; bh=LtkTVpWL6TMo5645N6f1i/Ciz76+fqNN9ZgDR0Mf4kQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=fF5JqDG8JDj3W8+d+8u0LXMQK3EEmlRBxS40lG8cW6/6rAwK45Jcr8l+BMChbNKl9 gqXQ79RMaSinl0Spzp0JRzxwHPauaYrPBd1+GRAwu4NwlKb8H4v+GBwFen6n46iZqd sGHeetRSAB5hAfdWeTttO2cEyaP73DBW9T6j/f08= Received: from DLEE111.ent.ti.com (dlee111.ent.ti.com [157.170.170.22]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id xA5E1Mo5007769 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 5 Nov 2019 08:01:22 -0600 Received: from DLEE114.ent.ti.com (157.170.170.25) by DLEE111.ent.ti.com (157.170.170.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Tue, 5 Nov 2019 08:01:06 -0600 Received: from fllv0040.itg.ti.com (10.64.41.20) by DLEE114.ent.ti.com (157.170.170.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Tue, 5 Nov 2019 08:01:06 -0600 Received: from sokoban.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1FFf068289; Tue, 5 Nov 2019 08:01:19 -0600 From: Tero Kristo To: , , CC: , Subject: [PATCHv2 02/22] crypto: omap-sham: remove the sysfs group during driver removal Date: Tue, 5 Nov 2019 16:00:51 +0200 Message-ID: <20191105140111.20285-3-t-kristo@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191105140111.20285-1-t-kristo@ti.com> References: <20191105140111.20285-1-t-kristo@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The driver removal should also cleanup the created sysfs group. If not, the driver fails the subsequent probe as the files exist already. Signed-off-by: Tero Kristo --- drivers/crypto/omap-sham.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.17.1 -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c index 2e9435577cea..0bf07a7c060b 100644 --- a/drivers/crypto/omap-sham.c +++ b/drivers/crypto/omap-sham.c @@ -2270,6 +2270,8 @@ static int omap_sham_remove(struct platform_device *pdev) if (!dd->polling_mode) dma_release_channel(dd->dma_lch); + sysfs_remove_group(&dd->dev->kobj, &omap_sham_attr_group); + return 0; } From patchwork Tue Nov 5 14:00:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 178503 Delivered-To: patch@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp709542ocf; Tue, 5 Nov 2019 06:01:44 -0800 (PST) X-Google-Smtp-Source: APXvYqzs8kw9Rtx5P/C6l4p93Q3R+ypmSHd/dbJnYXsnEHa8/C2FDvKmiaBp8VEZEfZlFXVWCWJi X-Received: by 2002:a17:906:945:: with SMTP id j5mr22880940ejd.211.1572962503958; Tue, 05 Nov 2019 06:01:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572962503; cv=none; d=google.com; s=arc-20160816; b=TEnUZlRVc0HCT0NqaO3EBYzWLLBXVYblj15mvMlqFK12bg7km3nciURbZFOszHE3VJ vZoHSC+IsW/Y7gQ1Uq1UrTYX5cZcUTs7e3YUcmdzAYrDbpRwldTNoepw3eA8a4TDJsP5 /TR0QvGZ3Rc5oftG+7lr1iZbxKntyZ/jVXY2ArMCWI3HHqD0fIdHaf915crTwVRvg3my 3hFJSdTeU6bHXsWlzB8T178z8IJvde1pQClbdDOfHgbdCLJCbtY/K/GKXn7r0WB+5eds dFv/x/Na0z+MymhO69C+is9KBbhPcC7dMj3EC7GtIb1NPOeHaCDIsrg8c8tGtDTCxViG o6Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=nrw79wvcWzgTlVnIkkp/iAS37hs/nXQ21HoyDm5EaZw=; b=YvHlmv4SFHCEUajQZHWTyjsA+vbaW588Q3ZL3GeEFRnrXjqMlUBvwDHR0vCmobqHie nA2L1EVJCflclbFD9FN+gLKfrXQl3KqSS/0/QZAamXaDJDfLtFanvyCHDnppbGDeiSJt +q9ojQxSMa6jpJ+0vR7DOYavfPxq7aUYseIRBv0Yy5UneP2jb+sXPbEuHtu87/vmC8lR b8cp4qQEr5mQ5UoJeOWUMNmYU2VV4SGpFpTrw4o7l+UNToOjQmT/8+dxw5tEfLlgbMjB WJm8NbXYMtXAAH+ECv5ZUq/rveFawx1cOSFJL9vfX31rXQFnWDvPEN27ckBr0z+vJ5cx hEHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=UEpdwjcS; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dk11si13340421ejb.97.2019.11.05.06.01.43; Tue, 05 Nov 2019 06:01:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=UEpdwjcS; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389373AbfKEOBm (ORCPT + 3 others); Tue, 5 Nov 2019 09:01:42 -0500 Received: from fllv0015.ext.ti.com ([198.47.19.141]:43946 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388605AbfKEOBl (ORCPT ); Tue, 5 Nov 2019 09:01:41 -0500 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1YiD071523; Tue, 5 Nov 2019 08:01:34 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1572962494; bh=nrw79wvcWzgTlVnIkkp/iAS37hs/nXQ21HoyDm5EaZw=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=UEpdwjcSm3zYxT4I5hz9VKQY5oMDKbUc8ISIIQ+wgvprL+yn4kdaD569OcKhf9Yfp tuQCnI2yA2Ka49e04Sd+Weq9RpBUC9jCk9hSdEq0blSQgGawggTQBxwHY1VYZVkjOU TsTqNQEc68JNtFOQ3iBOR6C/xcIHMWHMCWfpcZho= Received: from DFLE104.ent.ti.com (dfle104.ent.ti.com [10.64.6.25]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1YOL084579; Tue, 5 Nov 2019 08:01:34 -0600 Received: from DFLE115.ent.ti.com (10.64.6.36) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Tue, 5 Nov 2019 08:01:17 -0600 Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE115.ent.ti.com (10.64.6.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Tue, 5 Nov 2019 08:01:17 -0600 Received: from sokoban.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1FFi068289; Tue, 5 Nov 2019 08:01:27 -0600 From: Tero Kristo To: , , CC: , Subject: [PATCHv2 05/22] crypto: omap-aes: add IV output handling Date: Tue, 5 Nov 2019 16:00:54 +0200 Message-ID: <20191105140111.20285-6-t-kristo@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191105140111.20285-1-t-kristo@ti.com> References: <20191105140111.20285-1-t-kristo@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Currently omap-aes driver does not copy end result IV out at all. This is evident with the additional checks done at the crypto test manager. Fix by copying out the IV values from HW. Signed-off-by: Tero Kristo --- drivers/crypto/omap-aes.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) -- 2.17.1 -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki diff --git a/drivers/crypto/omap-aes.c b/drivers/crypto/omap-aes.c index 38c750e83dbe..e3f2ed0184f8 100644 --- a/drivers/crypto/omap-aes.c +++ b/drivers/crypto/omap-aes.c @@ -479,6 +479,14 @@ static int omap_aes_crypt_req(struct crypto_engine *engine, return omap_aes_crypt_dma_start(dd); } +static void omap_aes_copy_ivout(struct omap_aes_dev *dd, u8 *ivbuf) +{ + int i; + + for (i = 0; i < 4; i++) + ((u32 *)ivbuf)[i] = omap_aes_read(dd, AES_REG_IV(dd, i)); +} + static void omap_aes_done_task(unsigned long data) { struct omap_aes_dev *dd = (struct omap_aes_dev *)data; @@ -500,6 +508,10 @@ static void omap_aes_done_task(unsigned long data) omap_crypto_cleanup(&dd->out_sgl, dd->orig_out, 0, dd->total_save, FLAGS_OUT_DATA_ST_SHIFT, dd->flags); + /* Update IV output */ + if (dd->flags & (FLAGS_CBC | FLAGS_CTR)) + omap_aes_copy_ivout(dd, dd->req->iv); + omap_aes_finish_req(dd, 0); pr_debug("exit\n"); From patchwork Tue Nov 5 14:00:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 178504 Delivered-To: patch@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp709570ocf; Tue, 5 Nov 2019 06:01:45 -0800 (PST) X-Google-Smtp-Source: APXvYqyeRL6InsXglLdJDtBkwjOUy98U83l/Uy0+xxlgPbvHkmi7MVFWs1Stw6NcJaA3xdavCg1n X-Received: by 2002:a17:906:6d82:: with SMTP id h2mr29572956ejt.127.1572962504773; Tue, 05 Nov 2019 06:01:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572962504; cv=none; d=google.com; s=arc-20160816; b=vu3RR3LcddBkcFLJHv1Gzoi4K/7MVZX0E7kccxW2shrnynD14GVwKl2/wxPYUHCUCR ppOW72HxwqqvSKX1GFbK+TtZ/SmZ7oeqBheFSYh+yiik4CjTCIE8hLQino/iK33DSJID 6iNZl2PXsGIlkxLVFU1PX7h55dArxM6XoN+ElovUEKwnhDz32hrg0pLpmsIZ/N9e+Tmi 0eHBjmsRpGD6dnfJ2LaXZkc2lyy5ThIZ/SnZR4VCtJOMBf57cntYaYrX51JOzWEqPDeV gCfzTuOYghusiUdIX1hge2K57D/CXuQWyfBISfdBhLznOaWku+FFUl+UfI19e4XfVvTS 28Pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=gf7Wxfh77f7HHA3L8Iq0WB8JJs92egQOvoT79mDTzZI=; b=NTOb9Hp4zadfuidtIGpUcvr8hQGWDU0p4bMGBa8Sdhgwtakr0YJKbUTUST34fYSYWX f8WUrQkUjQOWTFsyNaqv4LJ1pXgK1cEOpJR+IlX1uay48TRyngR5pi4l6R8pmFOeBDIe VetSAnGE1Y4Ej8NI43gmrqJYm+X9+5liaxDVaJpxbMuMYp7HZ6CR4vusycFj6M27TYsZ NErLvhcmfXf/DG4n4XyUTgmKy2xHLsBP3RcyPJdug1KV2bNgOKjmA9V4SgsJ4MP/qjpF qXCVQXGwgeCozgbrVEEl4sr7zys4pTRUw9EyvF4/RYhold9KQ2e1xCRA7A6Q45n0wO3k hXdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=PSUTMr5k; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dk11si13340421ejb.97.2019.11.05.06.01.44; Tue, 05 Nov 2019 06:01:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=PSUTMr5k; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388605AbfKEOBm (ORCPT + 3 others); Tue, 5 Nov 2019 09:01:42 -0500 Received: from lelv0142.ext.ti.com ([198.47.23.249]:45256 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389368AbfKEOBm (ORCPT ); Tue, 5 Nov 2019 09:01:42 -0500 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1Yp4101155; Tue, 5 Nov 2019 08:01:34 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1572962494; bh=gf7Wxfh77f7HHA3L8Iq0WB8JJs92egQOvoT79mDTzZI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=PSUTMr5k2hWcFS0rA9u1WNFHmhecrzz+6sfOyePpzRyWZo74oz/S1ggx79py6sucN haaUFjANx4koDqw/9ena01D2dT7f0JjrM8dOkW3Drk7wRH9i1kBepWw7ThOiJg225s jk5szRz+IJVAhrM68RPlCczDIflh9gRjSNv/epUc= Received: from DFLE104.ent.ti.com (dfle104.ent.ti.com [10.64.6.25]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id xA5E1YhP059697 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 5 Nov 2019 08:01:34 -0600 Received: from DFLE103.ent.ti.com (10.64.6.24) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Tue, 5 Nov 2019 08:01:19 -0600 Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Tue, 5 Nov 2019 08:01:19 -0600 Received: from sokoban.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1FFj068289; Tue, 5 Nov 2019 08:01:32 -0600 From: Tero Kristo To: , , CC: , Subject: [PATCHv2 06/22] crypto: omap-sham: fix buffer handling for split test cases Date: Tue, 5 Nov 2019 16:00:55 +0200 Message-ID: <20191105140111.20285-7-t-kristo@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191105140111.20285-1-t-kristo@ti.com> References: <20191105140111.20285-1-t-kristo@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Current buffer handling logic fails in a case where the buffer contains existing data from previous update which is divisible by block size. This results in a block size of data to be left missing from the sg list going out to the hw accelerator, ending up in stalling the crypto accelerator driver (the last request never completes fully due to missing data.) Fix this by passing the total size of the data instead of the data size of current request, and also parsing the buffer contents within the prepare request handling. Signed-off-by: Tero Kristo --- drivers/crypto/omap-sham.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) -- 2.17.1 -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c index 0bf07a7c060b..e71cd977b621 100644 --- a/drivers/crypto/omap-sham.c +++ b/drivers/crypto/omap-sham.c @@ -740,11 +740,12 @@ static int omap_sham_align_sgs(struct scatterlist *sg, struct scatterlist *sg_tmp = sg; int new_len; int offset = rctx->offset; + int bufcnt = rctx->bufcnt; if (!sg || !sg->length || !nbytes) return 0; - new_len = nbytes - offset; + new_len = nbytes; if (offset) list_ok = false; @@ -763,6 +764,16 @@ static int omap_sham_align_sgs(struct scatterlist *sg, while (nbytes > 0 && sg_tmp) { n++; + if (bufcnt) { + if (!IS_ALIGNED(bufcnt, bs)) { + aligned = false; + break; + } + nbytes -= bufcnt; + bufcnt = 0; + continue; + } + #ifdef CONFIG_ZONE_DMA if (page_zonenum(sg_page(sg_tmp)) != ZONE_DMA) { aligned = false; @@ -859,7 +870,7 @@ static int omap_sham_prepare_request(struct ahash_request *req, bool update) if (rctx->bufcnt) memcpy(rctx->dd->xmit_buf, rctx->buffer, rctx->bufcnt); - ret = omap_sham_align_sgs(req->src, nbytes, bs, final, rctx); + ret = omap_sham_align_sgs(req->src, rctx->total, bs, final, rctx); if (ret) return ret; From patchwork Tue Nov 5 14:00:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 178505 Delivered-To: patch@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp709595ocf; Tue, 5 Nov 2019 06:01:45 -0800 (PST) X-Google-Smtp-Source: APXvYqxd3nrPmQZL2zYodbzqoG+l28YbM6NdkhLhwCwubJnO7yhZdevPlq2qTTxH8CLRsv8Dbq6y X-Received: by 2002:a50:fc1a:: with SMTP id i26mr9213413edr.9.1572962505663; Tue, 05 Nov 2019 06:01:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572962505; cv=none; d=google.com; s=arc-20160816; b=aSK+ufQw+Nm4akjXe4Ni03t06WyDvimFguyeXERVSsh0AmyBEm7nmfMpfd3VcObYlW SPM/6cb4WZePgdphIu3hxGnqKOlNWPyKJIYjPprWyWakv4ggTpvklXkC7XsNNDYriswE JcTGnimkJZmEqwKpUfZCMzsh6yjSjLNtic1Nhz6BRo84KDyBeihGT2jFlnVRazh+hnK+ 5NATwaJRtboEyHSVEhE38oo4pL/0Kxb245DOg4U05/n6aG4rDBV28Swq071aUVQlLf+q yGAdjD6amJSdw9nDvLqkGHpgJ9TAv5+7Oyc1liNhKcfjYnPb32xeRZ8EAfB9Vg8rhFxo dk/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=9OwOcAzmISWskR6psmzxNFNO/2lnZlaYpyywZJ98T/0=; b=R4uw8y1/GL9NKmLx8HxtoNFF0a+trS064Kr9D7CZfrk4jPM99qW5PiUXhpZCMs3a28 p84mxSwavDjiBGM4fz9PYJhNvZVBazA7/eeabeV4mpOEIO/BohaDNO1NWq4JhU55dm4K 6P+C2HOBMXEnxAY9d2dTvCJjlzbyMwjE0DvUoEU1iD399Q9nl4jY1uMeVLHf7U7VhXOl GUbVGmnzQ0Q06SDp+HAUep7GpiK4VAQzMJauMuha5q71dG33g6syQllQZtmH2epDbM2q V3CnsXUZSfGEIg0bfib6q519gNbdmprMcJmqx3IVlY1ijo4OiqFuqIW/a0uAI0T7qDl7 aT8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=azNehCvq; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dk11si13340421ejb.97.2019.11.05.06.01.45; Tue, 05 Nov 2019 06:01:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=azNehCvq; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389380AbfKEOBo (ORCPT + 3 others); Tue, 5 Nov 2019 09:01:44 -0500 Received: from fllv0015.ext.ti.com ([198.47.19.141]:43962 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389368AbfKEOBo (ORCPT ); Tue, 5 Nov 2019 09:01:44 -0500 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1cd9071560; Tue, 5 Nov 2019 08:01:38 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1572962498; bh=9OwOcAzmISWskR6psmzxNFNO/2lnZlaYpyywZJ98T/0=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=azNehCvqXPkDKmKVhKDHwfad8f/CzcItSOg7afM1wJWyOKcVfxeiz+SQJCp1ykVop B6NHMdsy4+vLXjFoHpg4/p0XHtcWakT/um5+HjV2Qd3IKIupwSff8C+fbmnap4DRa+ PW0sl340Z/5TdEZt579V2HCwP1swO2W8vJgmE/bQ= Received: from DFLE104.ent.ti.com (dfle104.ent.ti.com [10.64.6.25]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id xA5E1cDq059747 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 5 Nov 2019 08:01:38 -0600 Received: from DFLE105.ent.ti.com (10.64.6.26) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Tue, 5 Nov 2019 08:01:23 -0600 Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Tue, 5 Nov 2019 08:01:23 -0600 Received: from sokoban.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1FFl068289; Tue, 5 Nov 2019 08:01:36 -0600 From: Tero Kristo To: , , CC: , Subject: [PATCHv2 08/22] crypto: omap-sham: fix split update cases with cryptomgr tests Date: Tue, 5 Nov 2019 16:00:57 +0200 Message-ID: <20191105140111.20285-9-t-kristo@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191105140111.20285-1-t-kristo@ti.com> References: <20191105140111.20285-1-t-kristo@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The updated crypto manager finds a couple of new bugs from the omap-sham driver. Basically the split update cases fail to calculate the amount of data to be sent properly, leading into failed results and hangs with the hw accelerator. To fix these, the buffer handling needs to be fixed, but we do some cleanup for the code at the same time to cut away some unnecessary code so that it is easier to fix. Signed-off-by: Tero Kristo --- drivers/crypto/omap-sham.c | 102 ++++++++++++------------------------- 1 file changed, 33 insertions(+), 69 deletions(-) -- 2.17.1 -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c index e71cd977b621..33a58ebf652c 100644 --- a/drivers/crypto/omap-sham.c +++ b/drivers/crypto/omap-sham.c @@ -648,6 +648,8 @@ static int omap_sham_copy_sg_lists(struct omap_sham_reqctx *ctx, struct scatterlist *tmp; int offset = ctx->offset; + ctx->total = new_len; + if (ctx->bufcnt) n++; @@ -665,6 +667,7 @@ static int omap_sham_copy_sg_lists(struct omap_sham_reqctx *ctx, sg_set_buf(tmp, ctx->dd->xmit_buf, ctx->bufcnt); tmp = sg_next(tmp); ctx->sg_len++; + new_len -= ctx->bufcnt; } while (sg && new_len) { @@ -682,15 +685,18 @@ static int omap_sham_copy_sg_lists(struct omap_sham_reqctx *ctx, if (len > 0) { new_len -= len; sg_set_page(tmp, sg_page(sg), len, sg->offset); + ctx->sg_len++; if (new_len <= 0) - sg_mark_end(tmp); + break; tmp = sg_next(tmp); - ctx->sg_len++; } sg = sg_next(sg); } + if (tmp) + sg_mark_end(tmp); + set_bit(FLAGS_SGS_ALLOCED, &ctx->dd->flags); ctx->offset += new_len - ctx->bufcnt; @@ -726,6 +732,7 @@ static int omap_sham_copy_sgs(struct omap_sham_reqctx *ctx, ctx->sg_len = 1; ctx->offset += new_len - ctx->bufcnt; ctx->bufcnt = 0; + ctx->total = new_len; return 0; } @@ -771,6 +778,9 @@ static int omap_sham_align_sgs(struct scatterlist *sg, } nbytes -= bufcnt; bufcnt = 0; + if (!nbytes) + list_ok = false; + continue; } @@ -820,9 +830,9 @@ static int omap_sham_align_sgs(struct scatterlist *sg, return omap_sham_copy_sgs(rctx, sg, bs, new_len); else if (!list_ok) return omap_sham_copy_sg_lists(rctx, sg, bs, new_len); - else - rctx->offset += new_len; + rctx->total = new_len; + rctx->offset += new_len; rctx->sg_len = n; rctx->sg = sg; @@ -834,99 +844,54 @@ static int omap_sham_prepare_request(struct ahash_request *req, bool update) struct omap_sham_reqctx *rctx = ahash_request_ctx(req); int bs; int ret; - int nbytes; + unsigned int nbytes; bool final = rctx->flags & BIT(FLAGS_FINUP); - int xmit_len, hash_later; + int hash_later; bs = get_block_size(rctx); - if (update) - nbytes = req->nbytes; - else - nbytes = 0; + nbytes = rctx->bufcnt; - rctx->total = nbytes + rctx->bufcnt - rctx->offset; + if (update) + nbytes += req->nbytes - rctx->offset; dev_dbg(rctx->dd->dev, "%s: nbytes=%d, bs=%d, total=%d, offset=%d, bufcnt=%d\n", __func__, nbytes, bs, rctx->total, rctx->offset, rctx->bufcnt); - if (!rctx->total) + if (!nbytes) return 0; - if (nbytes && (!IS_ALIGNED(rctx->bufcnt, bs))) { + rctx->total = nbytes; + + if (update && req->nbytes && (!IS_ALIGNED(rctx->bufcnt, bs))) { int len = bs - rctx->bufcnt % bs; - if (len > nbytes) - len = nbytes; + if (len > req->nbytes) + len = req->nbytes; scatterwalk_map_and_copy(rctx->buffer + rctx->bufcnt, req->src, 0, len, 0); rctx->bufcnt += len; - nbytes -= len; rctx->offset = len; } if (rctx->bufcnt) memcpy(rctx->dd->xmit_buf, rctx->buffer, rctx->bufcnt); - ret = omap_sham_align_sgs(req->src, rctx->total, bs, final, rctx); + ret = omap_sham_align_sgs(req->src, nbytes, bs, final, rctx); if (ret) return ret; - xmit_len = rctx->total; - - if (xmit_len > OMAP_SHA_MAX_DMA_LEN) - xmit_len = OMAP_SHA_MAX_DMA_LEN; - - if (!IS_ALIGNED(xmit_len, bs)) { - if (final) - xmit_len = DIV_ROUND_UP(xmit_len, bs) * bs; - else - xmit_len = xmit_len / bs * bs; - } else if (!final && rctx->total == xmit_len) { - xmit_len -= bs; - } - - hash_later = rctx->total - xmit_len; + hash_later = nbytes - rctx->total; if (hash_later < 0) hash_later = 0; - if (rctx->bufcnt && nbytes) { - /* have data from previous operation and current */ - sg_init_table(rctx->sgl, 2); - sg_set_buf(rctx->sgl, rctx->dd->xmit_buf, rctx->bufcnt); - - sg_chain(rctx->sgl, 2, req->src); - - rctx->sg = rctx->sgl; - - rctx->sg_len++; - } else if (rctx->bufcnt) { - /* have buffered data only */ - sg_init_table(rctx->sgl, 1); - sg_set_buf(rctx->sgl, rctx->dd->xmit_buf, xmit_len); - - rctx->sg = rctx->sgl; - - rctx->sg_len = 1; - } - - if (hash_later && hash_later <= rctx->buflen) { - int offset = 0; - - if (hash_later > req->nbytes) { - memcpy(rctx->buffer, rctx->buffer + xmit_len, - hash_later - req->nbytes); - offset = hash_later - req->nbytes; - } - - if (req->nbytes) { - scatterwalk_map_and_copy(rctx->buffer + offset, - req->src, - offset + req->nbytes - - hash_later, hash_later, 0); - } + if (hash_later) { + scatterwalk_map_and_copy(rctx->buffer, + req->src, + req->nbytes - hash_later, + hash_later, 0); rctx->bufcnt = hash_later; } else { @@ -936,8 +901,7 @@ static int omap_sham_prepare_request(struct ahash_request *req, bool update) if (hash_later > rctx->buflen) set_bit(FLAGS_HUGE, &rctx->dd->flags); - if (!final) - rctx->total = xmit_len; + rctx->total = min(nbytes, rctx->total); return 0; } From patchwork Tue Nov 5 14:01:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 178508 Delivered-To: patch@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp709790ocf; Tue, 5 Nov 2019 06:01:52 -0800 (PST) X-Google-Smtp-Source: APXvYqz9YLNWoK92QHMCZFkINwlTo2RNOQ2PYodj1cNoegsx2qSqIthRCtMargAy/sgiyPwEmza9 X-Received: by 2002:a2e:c42:: with SMTP id o2mr19445637ljd.166.1572962512316; Tue, 05 Nov 2019 06:01:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572962512; cv=none; d=google.com; s=arc-20160816; b=DvSMKcnIiWaZRo5f/U0o4zV6hoANCDRbJMlD2rZyOvyg/eCvl1Fnpn0KMbaBCGU+Bj DFRTnkFdo3mZxteda1mnxX5lqW/iuopKktP0FMe/x2QgaMWg+zZa3Y1mFcSu0/Xnv1hx ggJhNmne0QLrCvMCJjrUpdYxPlTBEA24it7TuY9u5IJmdSER5hzb7bN2wZFwgZ3mIIxw j2amheUWjBqWn6kgkxFhL8cRF//T2BFRSQdkZ02dRNiIyjykO9ocaW8GwmBfXDM/QGHa xByTFAyB9DQ1XEZR79wE8RQRHp95qhAAQ/HLq834xSWttpx16WsP/Rtl4zHcrYMK8BtR 8JbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=upit1y8CUJ/UG9U3l05ijSh8ThRDpMaSJFs1e/vfhUM=; b=yEu4Us03xgjBWgAeCEtabwZgff2zUWL02QAYxtca1WGqkwYBGcdD4YeITGGmn7+b/D GR4fpEhFQabfdhTGa0vs8ZUPriUp0btiF+vbqo9UjJNWHLDeqGDvnrkGnRPB55uFrXYe 9nD/sXrIRpFGdzFR2x7lRR+KIKn279yJgnpLiaBk8TnUOlJRb4gYXSgnDb3Yd4uHYvwB oOJllt6vA8lSLm9KUCTLYQFn0l7b75JmXLpmc3q7zhRTVUl+eu3kEyh5TtghtbGUfM8P 9pxy0GiZzSl41BOc+wP+Rlte6vh9YiR4WE+qobWPPF3vqzHZ9DSCGcV13HS1fpRuU0dO g8hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=LCKWfEOD; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dk11si13340421ejb.97.2019.11.05.06.01.52; Tue, 05 Nov 2019 06:01:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=LCKWfEOD; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389417AbfKEOBt (ORCPT + 3 others); Tue, 5 Nov 2019 09:01:49 -0500 Received: from fllv0016.ext.ti.com ([198.47.19.142]:44744 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389377AbfKEOBs (ORCPT ); Tue, 5 Nov 2019 09:01:48 -0500 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1htl043494; Tue, 5 Nov 2019 08:01:43 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1572962503; bh=upit1y8CUJ/UG9U3l05ijSh8ThRDpMaSJFs1e/vfhUM=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=LCKWfEOD7NI4AuoaE3wiOaqgvKfsh23oVAerXggwu4NLxGozUWxcnJLTFd8EJNxtA RHAPV4GdmAu/39DhhWGw4NU4kBTxL+UO9M+TBNhxQlOwQNjTr8UvB15LXZrQrxZJM/ bz5Hvo/dcK+RY4x8ASAC3XMQegIrw4Kscqf0eyjg= Received: from DLEE107.ent.ti.com (dlee107.ent.ti.com [157.170.170.37]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1hMk084677; Tue, 5 Nov 2019 08:01:43 -0600 Received: from DLEE115.ent.ti.com (157.170.170.26) by DLEE107.ent.ti.com (157.170.170.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 5 Nov 2019 08:01:43 -0600 Received: from fllv0040.itg.ti.com (10.64.41.20) by DLEE115.ent.ti.com (157.170.170.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Tue, 5 Nov 2019 08:01:43 -0600 Received: from sokoban.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1FFo068289; Tue, 5 Nov 2019 08:01:41 -0600 From: Tero Kristo To: , , CC: , , Ard Biesheuvel Subject: [PATCHv2 11/22] crypto: omap-aes - reject invalid input sizes for block modes Date: Tue, 5 Nov 2019 16:01:00 +0200 Message-ID: <20191105140111.20285-12-t-kristo@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191105140111.20285-1-t-kristo@ti.com> References: <20191105140111.20285-1-t-kristo@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Ard Biesheuvel Block modes such as ECB and CBC only support input sizes that are a round multiple of the block size, so align with the generic code which returns -EINVAL when encountering inputs that violate this rule. Signed-off-by: Ard Biesheuvel Reviewed-by: Tero Kristo Tested-by: Tero Kristo --- drivers/crypto/omap-aes.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.17.1 -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki diff --git a/drivers/crypto/omap-aes.c b/drivers/crypto/omap-aes.c index de05b35283bf..067f4cd7c005 100644 --- a/drivers/crypto/omap-aes.c +++ b/drivers/crypto/omap-aes.c @@ -525,6 +525,9 @@ static int omap_aes_crypt(struct skcipher_request *req, unsigned long mode) struct omap_aes_dev *dd; int ret; + if ((req->cryptlen % AES_BLOCK_SIZE) && !(mode & FLAGS_CTR)) + return -EINVAL; + pr_debug("nbytes: %d, enc: %d, cbc: %d\n", req->cryptlen, !!(mode & FLAGS_ENCRYPT), !!(mode & FLAGS_CBC)); From patchwork Tue Nov 5 14:01:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 178509 Delivered-To: patch@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp709814ocf; Tue, 5 Nov 2019 06:01:53 -0800 (PST) X-Google-Smtp-Source: APXvYqzyhCj948gse3eBrDM30wTmwqTbeLKFOkasDx0WxsljMYFdmnhFWzEYLn0pJ3SNkbxaZFhO X-Received: by 2002:aa7:d908:: with SMTP id a8mr17333557edr.173.1572962513272; Tue, 05 Nov 2019 06:01:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572962513; cv=none; d=google.com; s=arc-20160816; b=btO9M+qxo1uQ0z3C51bCendjCz6K8wG2dD2EgguvcvpORlvzTYN4vlmSjVx7P4AQ0Y GOsGvGhhubTQ+lcJr0pdKbrbmleFhSYknwzAWhzblA4VQUITYUP+0GjPgk+9dlizrKTv gdMPDzi7lj56mlMn/ybkIfC7bwPvELl0RHitX0gSqtwLAoq8tvZLCc0KLykPdemWpoqF rQwy6gbebyNb/9ZYTU9V39vuz7B5jk6NqvIHBwmBWNnTNO/VKM0nLShyVeVlRgTUFeN6 0vExnUEILo3mYQ55+zsW3EYfSVvITsLivgUHjKpyn9VC5N91LQ62vYYrScN+Mi30xB8a KfJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=x+b6VIJEL39omp1au72B8HOV7pXjNXoHA6sjkn0go0s=; b=laRbToxzxCg8AOrQ0L+HijfwWjDM+Xd753MvecGsdLooDVvYIS1I73ot6JM83WfIfc am1LaZhOh338RU5Ad9E+LDwvNF71x3FVvoFVBfe2SWikLi1mjgZAXdAOW+GhBapN5aXd /LUU/qQcAgAEsVn977uzMaVn4+BjmMS5eCfKRgmeVYpBUuUmrChXSzD/VwcS8GYUFc2U Kjm0hFvD4p7gya2mWNOURK3LFZbG+Q5kwEpSXw2NcZDWcVun1pdTct4eNeWQZ09oLc3a /moeXJMkXP6Tp31L217c7wgK6BB/VLo1s16+M8Km99pdclgnSxsv+i+TtRObnx5qwkbv wRkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=Sx1fjDQK; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dk11si13340421ejb.97.2019.11.05.06.01.53; Tue, 05 Nov 2019 06:01:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=Sx1fjDQK; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389420AbfKEOBw (ORCPT + 3 others); Tue, 5 Nov 2019 09:01:52 -0500 Received: from lelv0143.ext.ti.com ([198.47.23.248]:35170 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389416AbfKEOBw (ORCPT ); Tue, 5 Nov 2019 09:01:52 -0500 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1jvW038208; Tue, 5 Nov 2019 08:01:45 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1572962505; bh=x+b6VIJEL39omp1au72B8HOV7pXjNXoHA6sjkn0go0s=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=Sx1fjDQKGS9ANr8iPshkNdtkEVEZIPcQk5ZSG8XYJBelHSbgkV3vY0VPylj8hpSiu u2CzNgDhXdcR7arBUwiTuzfsiT9r94bNryxDq5HEaCINm8uI5heog3Bo6dvMvuuvgu yfTAPIsHbbTr1WEwuo0imQyiqwk3+wdr5ldXdd+Q= Received: from DLEE107.ent.ti.com (dlee107.ent.ti.com [157.170.170.37]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id xA5E1j0p008088 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 5 Nov 2019 08:01:45 -0600 Received: from DLEE100.ent.ti.com (157.170.170.30) by DLEE107.ent.ti.com (157.170.170.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 5 Nov 2019 08:01:45 -0600 Received: from fllv0040.itg.ti.com (10.64.41.20) by DLEE100.ent.ti.com (157.170.170.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Tue, 5 Nov 2019 08:01:30 -0600 Received: from sokoban.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1FFp068289; Tue, 5 Nov 2019 08:01:43 -0600 From: Tero Kristo To: , , CC: , , Ard Biesheuvel Subject: [PATCHv2 12/22] crypto: omap-aes-ctr - set blocksize to 1 Date: Tue, 5 Nov 2019 16:01:01 +0200 Message-ID: <20191105140111.20285-13-t-kristo@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191105140111.20285-1-t-kristo@ti.com> References: <20191105140111.20285-1-t-kristo@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Ard Biesheuvel CTR is a streamcipher mode of AES, so set the blocksize accordingly. Signed-off-by: Ard Biesheuvel Reviewed-by: Tero Kristo Tested-by: Tero Kristo --- drivers/crypto/omap-aes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.17.1 -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki diff --git a/drivers/crypto/omap-aes.c b/drivers/crypto/omap-aes.c index 067f4cd7c005..33cba7a2d6df 100644 --- a/drivers/crypto/omap-aes.c +++ b/drivers/crypto/omap-aes.c @@ -747,7 +747,7 @@ static struct skcipher_alg algs_ctr[] = { .base.cra_flags = CRYPTO_ALG_KERN_DRIVER_ONLY | CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK, - .base.cra_blocksize = AES_BLOCK_SIZE, + .base.cra_blocksize = 1, .base.cra_ctxsize = sizeof(struct omap_aes_ctx), .base.cra_module = THIS_MODULE, From patchwork Tue Nov 5 14:01:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 178511 Delivered-To: patch@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp709984ocf; Tue, 5 Nov 2019 06:01:59 -0800 (PST) X-Google-Smtp-Source: APXvYqzxN9uUmib7/mK3sD4cqUU+Py54G0KtdSvobFXYWaqrHSmgnGG0NCc+NSg5fgFgozjcV6EU X-Received: by 2002:a05:6402:88c:: with SMTP id e12mr35067274edy.170.1572962519258; Tue, 05 Nov 2019 06:01:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572962519; cv=none; d=google.com; s=arc-20160816; b=uWZc/xjQyOw7GYDkHVzcvdSafxkZsmJZuV2P3fp0PE6XBZdpUmKcrpNR7uw/8yvbWI ZP/TFjh0LaIXuBMBO51uyvL8nW0vhKRsdtAogLgx+w+X5QQ46PYkMb8G2gPKnRVHq5G+ j3n85fDCfIteQdCWJXm1ht+TKF2BLecN8WtOFYwKqsGvqBWJ4hOM3AA0EgeZyoRR0l8q 3150rNS5DxLfxgYNzLNtsFsOxnBfUxN5Cx8aYFFbAofVy6LZHDFd5/mXdVtubToWzJfC Vek0S5sSt3RLBRMXHujPOu2Lek7VboJhOY2Pxql6aZaraOpFvqicWpSMmRhAJlErjvzA CC2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=x6mnPZEAweuMt7UUUU0v9RH245BYNKQW3yqgTHTHW8g=; b=bimVhf5X1Co2MRx7X0QEVa3Y3OKW/BNECjzVTi+Anyt5WwIQL+7e/0Piq0Y3Xl9FJ7 b4lT7P4AzwdPhmIBbep2NnhHnxgIrXj4BLmdJ1TOLoLocjvBmZHSXr0lM38EbN/8F7cK m/OYA3mtTMFwNbF7G9B8yv+gTKRzr0VL3W/LKUhrz3qSe0JyFw6O5zWeVgrQce2R/kXb 2732JeLTtW6p+Qit2Tn+sSlc8oNEwdcepaAdE23lkiavntDg6CEhUYDs4QMgcfDVeO1M /ACSLlQa+KUmLkyMd+sNquuoGpNd+abyLCfY36LpXeaZCNATPxHdktgt6EG9hs/jvPo0 hlAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="jj+l/hj+"; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dk11si13340421ejb.97.2019.11.05.06.01.59; Tue, 05 Nov 2019 06:01:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="jj+l/hj+"; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389426AbfKEOB6 (ORCPT + 3 others); Tue, 5 Nov 2019 09:01:58 -0500 Received: from lelv0142.ext.ti.com ([198.47.23.249]:45296 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389421AbfKEOB6 (ORCPT ); Tue, 5 Nov 2019 09:01:58 -0500 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1qZg101208; Tue, 5 Nov 2019 08:01:52 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1572962513; bh=x6mnPZEAweuMt7UUUU0v9RH245BYNKQW3yqgTHTHW8g=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=jj+l/hj+ItZh11o8chsD2acLLs142KzZqbRjjonBUFgpf265NAPyDtZgy2v0jR6dl hL5hnXxsBWZGX7F30uEurimcaME82uM0QucKHZRB3V0ZVVUa6Bgm/D2KR1V8fVXz7Z jIZQfUWhTLrVL5AXOFysXNwDNVaA64v81AZzxunw= Received: from DFLE106.ent.ti.com (dfle106.ent.ti.com [10.64.6.27]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id xA5E1qas008211 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 5 Nov 2019 08:01:52 -0600 Received: from DFLE104.ent.ti.com (10.64.6.25) by DFLE106.ent.ti.com (10.64.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Tue, 5 Nov 2019 08:01:36 -0600 Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Tue, 5 Nov 2019 08:01:36 -0600 Received: from sokoban.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1FFs068289; Tue, 5 Nov 2019 08:01:49 -0600 From: Tero Kristo To: , , CC: , , Ard Biesheuvel Subject: [PATCHv2 15/22] crypto: omap-aes-gcm - check length of assocdata in RFC4106 mode Date: Tue, 5 Nov 2019 16:01:04 +0200 Message-ID: <20191105140111.20285-16-t-kristo@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191105140111.20285-1-t-kristo@ti.com> References: <20191105140111.20285-1-t-kristo@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Ard Biesheuvel RFC4106 requires the associated data to be a certain size, so reject inputs that are wrong. This also prevents crashes or other problems due to assoclen becoming negative after subtracting 8 bytes. Signed-off-by: Ard Biesheuvel Reviewed-by: Tero Kristo Tested-by: Tero Kristo --- drivers/crypto/omap-aes-gcm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) -- 2.17.1 -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki diff --git a/drivers/crypto/omap-aes-gcm.c b/drivers/crypto/omap-aes-gcm.c index 70398fbd669d..1aabf9a72066 100644 --- a/drivers/crypto/omap-aes-gcm.c +++ b/drivers/crypto/omap-aes-gcm.c @@ -365,7 +365,8 @@ int omap_aes_4106gcm_encrypt(struct aead_request *req) memcpy(rctx->iv, ctx->nonce, 4); memcpy(rctx->iv + 4, req->iv, 8); - return omap_aes_gcm_crypt(req, FLAGS_ENCRYPT | FLAGS_GCM | + return crypto_ipsec_check_assoclen(req->assoclen) ?: + omap_aes_gcm_crypt(req, FLAGS_ENCRYPT | FLAGS_GCM | FLAGS_RFC4106_GCM); } @@ -376,7 +377,8 @@ int omap_aes_4106gcm_decrypt(struct aead_request *req) memcpy(rctx->iv, ctx->nonce, 4); memcpy(rctx->iv + 4, req->iv, 8); - return omap_aes_gcm_crypt(req, FLAGS_GCM | FLAGS_RFC4106_GCM); + return crypto_ipsec_check_assoclen(req->assoclen) ?: + omap_aes_gcm_crypt(req, FLAGS_GCM | FLAGS_RFC4106_GCM); } int omap_aes_gcm_setkey(struct crypto_aead *tfm, const u8 *key, From patchwork Tue Nov 5 14:01:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 178519 Delivered-To: patch@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp712499ocf; Tue, 5 Nov 2019 06:03:40 -0800 (PST) X-Google-Smtp-Source: APXvYqwRDW6AQF4DzF2tw7n2W3TuRRsaXdVOSiAU/tRTcaV6cj7IqFABEE+IWzJBRoex9wQTTvly X-Received: by 2002:a17:907:2078:: with SMTP id qp24mr1734947ejb.157.1572962521904; Tue, 05 Nov 2019 06:02:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572962521; cv=none; d=google.com; s=arc-20160816; b=c/Vu4g3EQjbLC+EmgtcFSTNepuj5eSGwgsSm+xtdYi6YLsRE6H5rRK4EbAiWWy+ii5 HQws2ExZ5zCq5aarWgeb8GM8wfQAgMVDXtPLJ0tEMBhGYEwXu3YtLaov+ITMKup5dIdp 69vqCg8yvj76STRnrCEtILDXyRR4qY+atTUUvl8jDXqlImExBxObhVULENMkGnmxlmor eZbpru83OUgEtPkzCjjitRf7I5MVZ7cvZ7LbtOP9qjBpMKdohgDs4ikmvP/Cbz4cZTky omy6dddt2Izq20Hebg0/frGmexY17y4wMH5hVyO73Q5XHOak1BfvsMd8gCA85dYgqYfS Hv8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=LmAyLnfz8YM25OuVd13njs2VbIXOcCSwKLiFJrFKgBI=; b=okqXOYS7cO0l2cj+dfr8b/A+tpkLmE6tZMx0DxR1fjsnBFzx5PXGdolY9Wp4FWN7EX 1kwB3VXANbX+NaYGmZXYL0uYhN4Ccvje0t1zzd3M95+PlrMU12wx9Ov4F2k7IeDQtfBf ebugY1FIVBZ+siYNPIAN4jPwnvPHFwzaaPYBkc0isSyt/XlczQJPoYEPiYTuWeXWPNA5 YVstfF4ue+F/etnhmQe1YJOSoO4YbWuYisPDEO6CQiPSz0RKQS2et7yu6Q7OgpPgKAfX HwIMr2M9vy/zMG0/FiSNkc+Ma4N4654B6gYPC8LLEFc7ffab5m/MFbSurZ+6IQDzvuL2 punQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=wB5X9yex; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dk11si13340421ejb.97.2019.11.05.06.02.01; Tue, 05 Nov 2019 06:02:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=wB5X9yex; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389429AbfKEOCA (ORCPT + 3 others); Tue, 5 Nov 2019 09:02:00 -0500 Received: from fllv0015.ext.ti.com ([198.47.19.141]:44044 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389421AbfKEOCA (ORCPT ); Tue, 5 Nov 2019 09:02:00 -0500 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1rvY071630; Tue, 5 Nov 2019 08:01:53 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1572962513; bh=LmAyLnfz8YM25OuVd13njs2VbIXOcCSwKLiFJrFKgBI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=wB5X9yexbeeiGItPyVJeTOmWUa19DpRAkIvLYFqBxTMam50eeeb3StnQR5r9tZkfC buwRcn1t1WHIXXeaZeZu+C1Y34wgRz4LT4fJ/7iDIAlgvFNE6qrWnc/NQTV6rmEaFC IwDDglM+goq8FWz2bxSRNCmbsY+OToqyOUzFlAxI= Received: from DLEE113.ent.ti.com (dlee113.ent.ti.com [157.170.170.24]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id xA5E1rEs059930 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 5 Nov 2019 08:01:53 -0600 Received: from DLEE112.ent.ti.com (157.170.170.23) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 5 Nov 2019 08:01:38 -0600 Received: from fllv0040.itg.ti.com (10.64.41.20) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Tue, 5 Nov 2019 08:01:52 -0600 Received: from sokoban.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1FFt068289; Tue, 5 Nov 2019 08:01:51 -0600 From: Tero Kristo To: , , CC: , , Ard Biesheuvel Subject: [PATCHv2 16/22] crypto: omap-aes-gcm - use the AES library to encrypt the tag Date: Tue, 5 Nov 2019 16:01:05 +0200 Message-ID: <20191105140111.20285-17-t-kristo@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191105140111.20285-1-t-kristo@ti.com> References: <20191105140111.20285-1-t-kristo@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Ard Biesheuvel The OMAP AES-GCM implementation uses a fallback ecb(aes) skcipher to produce the keystream to encrypt the output tag. Let's use the new AES library instead - this is much simpler, and shouldn't affect performance given that it only involves a single block. Signed-off-by: Ard Biesheuvel Reviewed-by: Tero Kristo Tested-by: Tero Kristo --- drivers/crypto/omap-aes-gcm.c | 98 +++++++++-------------------------- drivers/crypto/omap-aes.c | 26 +--------- drivers/crypto/omap-aes.h | 7 ++- 3 files changed, 33 insertions(+), 98 deletions(-) -- 2.17.1 -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki diff --git a/drivers/crypto/omap-aes-gcm.c b/drivers/crypto/omap-aes-gcm.c index 1aabf9a72066..6da05149b195 100644 --- a/drivers/crypto/omap-aes-gcm.c +++ b/drivers/crypto/omap-aes-gcm.c @@ -167,62 +167,12 @@ static int omap_aes_gcm_copy_buffers(struct omap_aes_dev *dd, return 0; } -static void omap_aes_gcm_complete(struct crypto_async_request *req, int err) -{ - struct omap_aes_gcm_result *res = req->data; - - if (err == -EINPROGRESS) - return; - - res->err = err; - complete(&res->completion); -} - static int do_encrypt_iv(struct aead_request *req, u32 *tag, u32 *iv) { - struct scatterlist iv_sg, tag_sg; - struct skcipher_request *sk_req; - struct omap_aes_gcm_result result; - struct omap_aes_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req)); - int ret = 0; - - sk_req = skcipher_request_alloc(ctx->ctr, GFP_KERNEL); - if (!sk_req) { - pr_err("skcipher: Failed to allocate request\n"); - return -ENOMEM; - } - - init_completion(&result.completion); - - sg_init_one(&iv_sg, iv, AES_BLOCK_SIZE); - sg_init_one(&tag_sg, tag, AES_BLOCK_SIZE); - skcipher_request_set_callback(sk_req, CRYPTO_TFM_REQ_MAY_BACKLOG, - omap_aes_gcm_complete, &result); - ret = crypto_skcipher_setkey(ctx->ctr, (u8 *)ctx->key, ctx->keylen); - skcipher_request_set_crypt(sk_req, &iv_sg, &tag_sg, AES_BLOCK_SIZE, - NULL); - ret = crypto_skcipher_encrypt(sk_req); - switch (ret) { - case 0: - break; - case -EINPROGRESS: - case -EBUSY: - ret = wait_for_completion_interruptible(&result.completion); - if (!ret) { - ret = result.err; - if (!ret) { - reinit_completion(&result.completion); - break; - } - } - /* fall through */ - default: - pr_err("Encryption of IV failed for GCM mode\n"); - break; - } + struct omap_aes_gcm_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req)); - skcipher_request_free(sk_req); - return ret; + aes_encrypt(&ctx->actx, (u8 *)tag, (u8 *)iv); + return 0; } void omap_aes_gcm_dma_out_callback(void *data) @@ -252,7 +202,7 @@ void omap_aes_gcm_dma_out_callback(void *data) static int omap_aes_gcm_handle_queue(struct omap_aes_dev *dd, struct aead_request *req) { - struct omap_aes_ctx *ctx; + struct omap_aes_gcm_ctx *ctx; struct aead_request *backlog; struct omap_aes_reqctx *rctx; unsigned long flags; @@ -281,7 +231,7 @@ static int omap_aes_gcm_handle_queue(struct omap_aes_dev *dd, ctx = crypto_aead_ctx(crypto_aead_reqtfm(req)); rctx = aead_request_ctx(req); - dd->ctx = ctx; + dd->ctx = &ctx->octx; rctx->dd = dd; dd->aead_req = req; @@ -360,10 +310,10 @@ int omap_aes_gcm_decrypt(struct aead_request *req) int omap_aes_4106gcm_encrypt(struct aead_request *req) { - struct omap_aes_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req)); + struct omap_aes_gcm_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req)); struct omap_aes_reqctx *rctx = aead_request_ctx(req); - memcpy(rctx->iv, ctx->nonce, 4); + memcpy(rctx->iv, ctx->octx.nonce, 4); memcpy(rctx->iv + 4, req->iv, 8); return crypto_ipsec_check_assoclen(req->assoclen) ?: omap_aes_gcm_crypt(req, FLAGS_ENCRYPT | FLAGS_GCM | @@ -372,10 +322,10 @@ int omap_aes_4106gcm_encrypt(struct aead_request *req) int omap_aes_4106gcm_decrypt(struct aead_request *req) { - struct omap_aes_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req)); + struct omap_aes_gcm_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req)); struct omap_aes_reqctx *rctx = aead_request_ctx(req); - memcpy(rctx->iv, ctx->nonce, 4); + memcpy(rctx->iv, ctx->octx.nonce, 4); memcpy(rctx->iv + 4, req->iv, 8); return crypto_ipsec_check_assoclen(req->assoclen) ?: omap_aes_gcm_crypt(req, FLAGS_GCM | FLAGS_RFC4106_GCM); @@ -384,14 +334,15 @@ int omap_aes_4106gcm_decrypt(struct aead_request *req) int omap_aes_gcm_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) { - struct omap_aes_ctx *ctx = crypto_aead_ctx(tfm); + struct omap_aes_gcm_ctx *ctx = crypto_aead_ctx(tfm); + int ret; - if (keylen != AES_KEYSIZE_128 && keylen != AES_KEYSIZE_192 && - keylen != AES_KEYSIZE_256) - return -EINVAL; + ret = aes_expandkey(&ctx->actx, key, keylen); + if (ret) + return ret; - memcpy(ctx->key, key, keylen); - ctx->keylen = keylen; + memcpy(ctx->octx.key, key, keylen); + ctx->octx.keylen = keylen; return 0; } @@ -399,19 +350,20 @@ int omap_aes_gcm_setkey(struct crypto_aead *tfm, const u8 *key, int omap_aes_4106gcm_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) { - struct omap_aes_ctx *ctx = crypto_aead_ctx(tfm); + struct omap_aes_gcm_ctx *ctx = crypto_aead_ctx(tfm); + int ret; if (keylen < 4) return -EINVAL; - keylen -= 4; - if (keylen != AES_KEYSIZE_128 && keylen != AES_KEYSIZE_192 && - keylen != AES_KEYSIZE_256) - return -EINVAL; - memcpy(ctx->key, key, keylen); - memcpy(ctx->nonce, key + keylen, 4); - ctx->keylen = keylen; + ret = aes_expandkey(&ctx->actx, key, keylen); + if (ret) + return ret; + + memcpy(ctx->octx.key, key, keylen); + memcpy(ctx->octx.nonce, key + keylen, 4); + ctx->octx.keylen = keylen; return 0; } diff --git a/drivers/crypto/omap-aes.c b/drivers/crypto/omap-aes.c index 161af3bf667c..d63ab370030e 100644 --- a/drivers/crypto/omap-aes.c +++ b/drivers/crypto/omap-aes.c @@ -645,7 +645,6 @@ static int omap_aes_init_tfm(struct crypto_skcipher *tfm) static int omap_aes_gcm_cra_init(struct crypto_aead *tfm) { struct omap_aes_dev *dd = NULL; - struct omap_aes_ctx *ctx = crypto_aead_ctx(tfm); int err; /* Find AES device, currently picks the first device */ @@ -663,12 +662,6 @@ static int omap_aes_gcm_cra_init(struct crypto_aead *tfm) } tfm->reqsize = sizeof(struct omap_aes_reqctx); - ctx->ctr = crypto_alloc_skcipher("ecb(aes)", 0, 0); - if (IS_ERR(ctx->ctr)) { - pr_warn("could not load aes driver for encrypting IV\n"); - return PTR_ERR(ctx->ctr); - } - return 0; } @@ -682,19 +675,6 @@ static void omap_aes_exit_tfm(struct crypto_skcipher *tfm) ctx->fallback = NULL; } -static void omap_aes_gcm_cra_exit(struct crypto_aead *tfm) -{ - struct omap_aes_ctx *ctx = crypto_aead_ctx(tfm); - - if (ctx->fallback) - crypto_free_sync_skcipher(ctx->fallback); - - ctx->fallback = NULL; - - if (ctx->ctr) - crypto_free_skcipher(ctx->ctr); -} - /* ********************** ALGS ************************************ */ static struct skcipher_alg algs_ecb_cbc[] = { @@ -778,12 +758,11 @@ static struct aead_alg algs_aead_gcm[] = { .cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY, .cra_blocksize = 1, - .cra_ctxsize = sizeof(struct omap_aes_ctx), + .cra_ctxsize = sizeof(struct omap_aes_gcm_ctx), .cra_alignmask = 0xf, .cra_module = THIS_MODULE, }, .init = omap_aes_gcm_cra_init, - .exit = omap_aes_gcm_cra_exit, .ivsize = GCM_AES_IV_SIZE, .maxauthsize = AES_BLOCK_SIZE, .setkey = omap_aes_gcm_setkey, @@ -799,12 +778,11 @@ static struct aead_alg algs_aead_gcm[] = { .cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY, .cra_blocksize = 1, - .cra_ctxsize = sizeof(struct omap_aes_ctx), + .cra_ctxsize = sizeof(struct omap_aes_gcm_ctx), .cra_alignmask = 0xf, .cra_module = THIS_MODULE, }, .init = omap_aes_gcm_cra_init, - .exit = omap_aes_gcm_cra_exit, .maxauthsize = AES_BLOCK_SIZE, .ivsize = GCM_RFC4106_IV_SIZE, .setkey = omap_aes_4106gcm_setkey, diff --git a/drivers/crypto/omap-aes.h b/drivers/crypto/omap-aes.h index 1bcca7957e92..b89d2e673699 100644 --- a/drivers/crypto/omap-aes.h +++ b/drivers/crypto/omap-aes.h @@ -9,6 +9,7 @@ #ifndef __OMAP_AES_H__ #define __OMAP_AES_H__ +#include #include #define DST_MAXBURST 4 @@ -98,7 +99,11 @@ struct omap_aes_ctx { u32 key[AES_KEYSIZE_256 / sizeof(u32)]; u8 nonce[4]; struct crypto_sync_skcipher *fallback; - struct crypto_skcipher *ctr; +}; + +struct omap_aes_gcm_ctx { + struct omap_aes_ctx octx; + struct crypto_aes_ctx actx; }; struct omap_aes_reqctx { From patchwork Tue Nov 5 14:01:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 178513 Delivered-To: patch@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp710099ocf; Tue, 5 Nov 2019 06:02:03 -0800 (PST) X-Google-Smtp-Source: APXvYqx1scsPUqNVoH2btUUSzyawKyGOjo2KyRGGLvwWDXD1DeR/Xqbpt6ryo0T0h9tEaAslST0M X-Received: by 2002:a17:906:bb16:: with SMTP id jz22mr8574115ejb.261.1572962522895; Tue, 05 Nov 2019 06:02:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572962522; cv=none; d=google.com; s=arc-20160816; b=seGlNJ0pmDrfCZyU9HQs5lkl3mQQGHyPZRGvCr8ZkJW9MfFZkRzHnsJGLoOVb0D+jo 0syIpTwlFr59b5KJ+s3qW3jbD2cE1K7Zqs3Nw1nQ0k+isnGYTqH9w4SooGWd3qrNXcf2 h3iqw9YJxobLTZCre6aa8cudWu/iTbxYbmGB9yN3I3OdoVLpm/uBRCPlMm3/Md4+u9lu eyZxuFXt1MQkDqBl4bqvZKwrOrvR/yW3WXBcR0TM9kJa8AyI+l6pMDd0mk4wCD+/KyS2 Hln69QbNmIm4ztOGtQ6rgojB0VAXd/cURvxiKAkjfMBLl9qipS+IzRH/mShXMobr/A5f 5OYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=8YJ88Fsu5FkvkfTgzLP7sEbx6NyeVx/fGIXHCLJBBBg=; b=lb5VCtQ+8cFkj+bnqilHjjVXsTVWZhosVhKfQqWTA1QWkkiOUUqPTqAPb4c4lhtxTM /i2rJjSauNpXOdDvkfueczwvn+Kti/9PdfNfDs6QArrwpK1Qy9gzQotLgQM2cqArxwxL eG9W36UqUN9Gx8pSv2hvdcJ1VM4Ip5sa5eSYuaYFLJKZYUI8M86Ur90p/n2f19q58Fid d8DUW8t+dl8b5fRVMV4+zCMuU3MAPW9EbOvi1MLEDqadtz9r+lzA9zfNZ0ihjYwMCs/y UDJhjXEguE0ICpNz4ncS7HutaVzW8NMG0tjsw9a3dMSPwfkXnRDiVDxVGhQKGgIeDJ3f 1kbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=baSyLuP4; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dk11si13340421ejb.97.2019.11.05.06.02.02; Tue, 05 Nov 2019 06:02:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=baSyLuP4; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389436AbfKEOCC (ORCPT + 3 others); Tue, 5 Nov 2019 09:02:02 -0500 Received: from lelv0142.ext.ti.com ([198.47.23.249]:45314 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389421AbfKEOCB (ORCPT ); Tue, 5 Nov 2019 09:02:01 -0500 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1tkb101214; Tue, 5 Nov 2019 08:01:55 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1572962515; bh=8YJ88Fsu5FkvkfTgzLP7sEbx6NyeVx/fGIXHCLJBBBg=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=baSyLuP4/JZFRznR/EuIPt4wHb1oVipew35ktPmT9moxr2xsPfYQ16NSf775B2Eid NM3KnSwGIyyrpytS2maHxPtMP2RA8RRD8ul3cE7enzetBgXnDieVrYepqcUy78SxLb YOldxtqPzAXWkxZo4pyilnWS1LOpHdxbRgmilohk= Received: from DFLE110.ent.ti.com (dfle110.ent.ti.com [10.64.6.31]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id xA5E1tw3008282 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 5 Nov 2019 08:01:55 -0600 Received: from DFLE103.ent.ti.com (10.64.6.24) by DFLE110.ent.ti.com (10.64.6.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 5 Nov 2019 08:01:39 -0600 Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Tue, 5 Nov 2019 08:01:39 -0600 Received: from sokoban.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1FFu068289; Tue, 5 Nov 2019 08:01:53 -0600 From: Tero Kristo To: , , CC: , Subject: [PATCHv2 17/22] crypto: omap-aes-gcm: fix failure with assocdata only Date: Tue, 5 Nov 2019 16:01:06 +0200 Message-ID: <20191105140111.20285-18-t-kristo@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191105140111.20285-1-t-kristo@ti.com> References: <20191105140111.20285-1-t-kristo@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org If we only have assocdata with an omap-aes-gcm, it currently just completes it directly without passing it over to the crypto HW. This produces wrong results. Fix by passing the request down to the crypto HW, and fix the DMA support code to accept a case where we don't expect any output data. In the case where only assocdata is provided, it just passes through the accelerator and provides authentication results, without any encrypted/decrypted buffer via DMA. Signed-off-by: Tero Kristo --- drivers/crypto/omap-aes-gcm.c | 2 +- drivers/crypto/omap-aes.c | 67 +++++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 27 deletions(-) -- 2.17.1 -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki diff --git a/drivers/crypto/omap-aes-gcm.c b/drivers/crypto/omap-aes-gcm.c index 6da05149b195..e92000846f16 100644 --- a/drivers/crypto/omap-aes-gcm.c +++ b/drivers/crypto/omap-aes-gcm.c @@ -244,7 +244,7 @@ static int omap_aes_gcm_handle_queue(struct omap_aes_dev *dd, err = omap_aes_write_ctrl(dd); if (!err) { - if (dd->in_sg_len && dd->out_sg_len) + if (dd->in_sg_len) err = omap_aes_crypt_dma_start(dd); else omap_aes_gcm_dma_out_callback(dd); diff --git a/drivers/crypto/omap-aes.c b/drivers/crypto/omap-aes.c index d63ab370030e..758c93908fa5 100644 --- a/drivers/crypto/omap-aes.c +++ b/drivers/crypto/omap-aes.c @@ -269,13 +269,14 @@ static int omap_aes_crypt_dma(struct omap_aes_dev *dd, struct scatterlist *out_sg, int in_sg_len, int out_sg_len) { - struct dma_async_tx_descriptor *tx_in, *tx_out; + struct dma_async_tx_descriptor *tx_in, *tx_out = NULL, *cb_desc; struct dma_slave_config cfg; int ret; if (dd->pio_only) { scatterwalk_start(&dd->in_walk, dd->in_sg); - scatterwalk_start(&dd->out_walk, dd->out_sg); + if (out_sg_len) + scatterwalk_start(&dd->out_walk, dd->out_sg); /* Enable DATAIN interrupt and let it take care of the rest */ @@ -312,34 +313,45 @@ static int omap_aes_crypt_dma(struct omap_aes_dev *dd, /* No callback necessary */ tx_in->callback_param = dd; + tx_in->callback = NULL; /* OUT */ - ret = dmaengine_slave_config(dd->dma_lch_out, &cfg); - if (ret) { - dev_err(dd->dev, "can't configure OUT dmaengine slave: %d\n", - ret); - return ret; - } + if (out_sg_len) { + ret = dmaengine_slave_config(dd->dma_lch_out, &cfg); + if (ret) { + dev_err(dd->dev, "can't configure OUT dmaengine slave: %d\n", + ret); + return ret; + } - tx_out = dmaengine_prep_slave_sg(dd->dma_lch_out, out_sg, out_sg_len, - DMA_DEV_TO_MEM, - DMA_PREP_INTERRUPT | DMA_CTRL_ACK); - if (!tx_out) { - dev_err(dd->dev, "OUT prep_slave_sg() failed\n"); - return -EINVAL; + tx_out = dmaengine_prep_slave_sg(dd->dma_lch_out, out_sg, + out_sg_len, + DMA_DEV_TO_MEM, + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); + if (!tx_out) { + dev_err(dd->dev, "OUT prep_slave_sg() failed\n"); + return -EINVAL; + } + + cb_desc = tx_out; + } else { + cb_desc = tx_in; } if (dd->flags & FLAGS_GCM) - tx_out->callback = omap_aes_gcm_dma_out_callback; + cb_desc->callback = omap_aes_gcm_dma_out_callback; else - tx_out->callback = omap_aes_dma_out_callback; - tx_out->callback_param = dd; + cb_desc->callback = omap_aes_dma_out_callback; + cb_desc->callback_param = dd; + dmaengine_submit(tx_in); - dmaengine_submit(tx_out); + if (tx_out) + dmaengine_submit(tx_out); dma_async_issue_pending(dd->dma_lch_in); - dma_async_issue_pending(dd->dma_lch_out); + if (out_sg_len) + dma_async_issue_pending(dd->dma_lch_out); /* start DMA */ dd->pdata->trigger(dd, dd->total); @@ -361,11 +373,13 @@ int omap_aes_crypt_dma_start(struct omap_aes_dev *dd) return -EINVAL; } - err = dma_map_sg(dd->dev, dd->out_sg, dd->out_sg_len, - DMA_FROM_DEVICE); - if (!err) { - dev_err(dd->dev, "dma_map_sg() error\n"); - return -EINVAL; + if (dd->out_sg_len) { + err = dma_map_sg(dd->dev, dd->out_sg, dd->out_sg_len, + DMA_FROM_DEVICE); + if (!err) { + dev_err(dd->dev, "dma_map_sg() error\n"); + return -EINVAL; + } } } @@ -373,8 +387,9 @@ int omap_aes_crypt_dma_start(struct omap_aes_dev *dd) dd->out_sg_len); if (err && !dd->pio_only) { dma_unmap_sg(dd->dev, dd->in_sg, dd->in_sg_len, DMA_TO_DEVICE); - dma_unmap_sg(dd->dev, dd->out_sg, dd->out_sg_len, - DMA_FROM_DEVICE); + if (dd->out_sg_len) + dma_unmap_sg(dd->dev, dd->out_sg, dd->out_sg_len, + DMA_FROM_DEVICE); } return err;