Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752057AbdIEPdK (ORCPT ); Tue, 5 Sep 2017 11:33:10 -0400 Received: from mail-db5eur01on0082.outbound.protection.outlook.com ([104.47.2.82]:2283 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751630AbdIEPdH (ORCPT ); Tue, 5 Sep 2017 11:33:07 -0400 From: =?iso-8859-2?Q?Horia_Geant=E3?= To: Gilad Ben-Yossef CC: David Gstir , Dan Douglass , "herbert@gondor.apana.org.au" , "davem@davemloft.net" , "richard@sigma-star.at" , "linux-crypto@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" Subject: Re: [PATCH] crypto: caam - properly set IV after {en,de}crypt Thread-Topic: [PATCH] crypto: caam - properly set IV after {en,de}crypt Thread-Index: AQHS8BJRT1JvsDHapk2P0fMxyxi4Kg== Date: Tue, 5 Sep 2017 15:33:01 +0000 Message-ID: References: <20170602122446.2427-1-david@sigma-star.at> <20170628132710.97278-1-david@sigma-star.at> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=horia.geanta@nxp.com; x-originating-ip: [192.88.146.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;VI1PR0402MB3600;6:earYYDbdmkfHhNAhlUTwB8nHW32/LFJDvbO1cmFhhZX9u/0wISItRKk/tbks0oxped7+p7uicmwfBGHYUey8BQ+3I7VnhBTrAAGwmNU4NrMlUYTZIHo2r4cduQeb536qILknMtzryMR9Vrbp0/QB//s2ty9Imq9lgvaiejl24BCN/7dg8fMxAh82vyydCMFwGqRsmkgLgMicGN09OWh/xesY0VsOnMsr7DLJ0OfX+QsPzoYKFcc4b9Y1/atb1EYRsQEvhdEkwquUD2F7qapy5zJRGkwomwdZCMkRrg3macCeQPg0a895VO3Sh1iB280srIr9o9kdsHRGp5VQrCVvtw==;5:LaOO9tVFpzXqNOvOvtmyC+E3jdrm1eNIx+msELlnETws9ZwBb0sNf+5tK5bcWbLeDNzNDXd8vekIyCNgNoLYDaHTKoOnOGi8yDhBxVquGS3VR60dSiddhfaOAieCsNvchbERBnFIeRch8NSOFTUH9A==;24:tiwawDlv5cURRGCmIt/LH54K23dasZVpu8ZgtA0zFyi4lAuGeu/7HuVVlM1cOd/tWxHMh+IeWIc8i1T32lmbdjN0UVL3hK2mwAvhu6SvRzk=;7:rkhj1PwCBBpe19syS75P9XYFexY2gD2+mjnooRPcvGt5NcYB9+F/YuZshXnTj8E8wwDEFXH7+E7IoXUvU9dYXHz9CDcI3TVG7pcWomzjv3EXfoVkuttyNMKRzms80CJSW9IDllR0RDjq/c9fLhZGlmMTdjUFF7VbOLdCnX/k6wGeJyqrSTqLrqFhKaxLU2dnWJfSGaskiY9zaxd1A3fVTL+MsNC3FiHalWEL4JTC1g8= x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-forefront-antispam-report: SFV:SKI;SCL:-1;SFV:NSPM;SFS:(10009020)(979002)(6009001)(39860400002)(24454002)(377454003)(199003)(189002)(53936002)(101416001)(478600001)(74316002)(6506006)(6436002)(53546010)(14454004)(189998001)(6916009)(106356001)(105586002)(6246003)(5250100002)(76176999)(54356999)(50986999)(66066001)(2900100001)(68736007)(229853002)(25786009)(97736004)(93886005)(110136004)(33656002)(9686003)(55016002)(99286003)(54906002)(3660700001)(3846002)(102836003)(6116002)(7696004)(305945005)(3280700002)(86362001)(5660300001)(81166006)(81156014)(4326008)(7736002)(8676002)(2906002)(8936002)(142933001)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR0402MB3600;H:VI1PR0402MB3342.eurprd04.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; x-ms-office365-filtering-correlation-id: b2074307-6a0c-4702-d8a8-08d4f47364d9 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(48565401081)(300000503095)(300135400095)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:VI1PR0402MB3600; x-ms-traffictypediagnostic: VI1PR0402MB3600: x-exchange-antispam-report-test: UriScan:(9452136761055)(185117386973197); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(3002001)(100000703101)(100105400095)(10201501046)(93006095)(93001095)(6055026)(6041248)(20161123555025)(20161123558100)(20161123560025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:VI1PR0402MB3600;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:VI1PR0402MB3600; x-forefront-prvs: 0421BF7135 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-2" MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Sep 2017 15:33:01.5559 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3600 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id v85FXGOk010215 Content-Length: 2398 Lines: 54 On 8/14/2017 10:59 AM, Gilad Ben-Yossef wrote: > Hi, > > On Thu, Jun 29, 2017 at 1:19 PM, Horia Geant? wrote: >> On 6/28/2017 4:42 PM, Horia Geant? wrote: >>> On 6/28/2017 4:27 PM, David Gstir wrote: >>>> Certain cipher modes like CTS expect the IV (req->info) of >>>> ablkcipher_request (or equivalently req->iv of skcipher_request) to >>>> contain the last ciphertext block when the {en,de}crypt operation is done. >>>> This is currently not the case for the CAAM driver which in turn breaks >>>> e.g. cts(cbc(aes)) when the CAAM driver is enabled. >>>> >>>> This patch fixes the CAAM driver to properly set the IV after the >>>> {en,de}crypt operation of ablkcipher finishes. >>>> >>>> This issue was revealed by the changes in the SW CTS mode in commit >>>> 0605c41cc53ca ("crypto: cts - Convert to skcipher") >>>> >>>> Cc: # 4.8+ >>>> Signed-off-by: David Gstir >>> Reviewed-by: Horia Geant? >>> >> Btw, instead of updating the IV in SW, CAAM engine could be programmed >> to do it - by saving the Context Register of the AES accelerator. >> >> Unfortunately this would require changes in quite a few places: shared >> descriptor, HW S/G generation logic, IV dma (un)mapping and maybe others. >> >> So it's better to have this fix now (which, considering size, is >> appropriate for -stable) and later, if needed, offload IV updating in HW. >> > > My apologies for reviving this thread from the dead, but doesn't the patch fail > for in-place decryption since we are copying from req->dst after > the operation is done, and therefore it no longer contains the ciphertext? > You are right, thanks! Will follow up with a fix. Though cts(cbc(aes)) in particular is working, see below. > I'm asking since I ran into a similar issue in the ccree driver and thought > to deploy a similar fix but could not convince myself why this works. > IIUC cts(cbc(aes)) in-place decryption (with cbc(aes) offloaded to CAAM engine) works since SW implementation of cts, when performing the ciphertext stealing phase in cts_cbc_decrypt() does not use req->iv, but a previously value, saved before staring decryption in crypto_cts_decrypt(): if (cbc_blocks <= 1) memcpy(space, req->iv, bsize); else scatterwalk_map_and_copy(space, req->src, offset - 2 * bsize, bsize, 0); Horia