From patchwork Thu Jul 30 19:11:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Horia_Geant=C4=83?= X-Patchwork-Id: 6906611 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 91599C05AC for ; Thu, 30 Jul 2015 19:25:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9095420609 for ; Thu, 30 Jul 2015 19:25:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4975C2045E for ; Thu, 30 Jul 2015 19:25:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752134AbbG3TZm (ORCPT ); Thu, 30 Jul 2015 15:25:42 -0400 Received: from mail-bn1bon0132.outbound.protection.outlook.com ([157.56.111.132]:26848 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752057AbbG3TZl (ORCPT ); Thu, 30 Jul 2015 15:25:41 -0400 Received: from BY2PR03CA055.namprd03.prod.outlook.com (10.141.249.28) by SN1PR0301MB1614.namprd03.prod.outlook.com (10.162.130.24) with Microsoft SMTP Server (TLS) id 15.1.219.17; Thu, 30 Jul 2015 19:11:31 +0000 Received: from BL2FFO11OLC001.protection.gbl (2a01:111:f400:7c09::127) by BY2PR03CA055.outlook.office365.com (2a01:111:e400:2c5d::28) with Microsoft SMTP Server (TLS) id 15.1.225.19 via Frontend Transport; Thu, 30 Jul 2015 19:11:31 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BL2FFO11OLC001.mail.protection.outlook.com (10.173.161.185) with Microsoft SMTP Server (TLS) id 15.1.231.11 via Frontend Transport; Thu, 30 Jul 2015 19:11:31 +0000 Received: from enigma.ea.freescale.net (enigma.ea.freescale.net [10.171.77.120]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id t6UJBS73005218; Thu, 30 Jul 2015 12:11:29 -0700 From: =?UTF-8?q?Horia=20Geant=C4=83?= To: Herbert Xu CC: , Tudor Ambarus Subject: [PATCH v2] crypto: caam - fix rfc4106 encap shared descriptor Date: Thu, 30 Jul 2015 22:11:18 +0300 Message-ID: <1438283478-32198-1-git-send-email-horia.geanta@freescale.com> X-Mailer: git-send-email 2.4.4 In-Reply-To: <55BA435C.1000803@freescale.com> References: <55BA435C.1000803@freescale.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11OLC001; 1:ANKqVIo97VSbvB2y+cmy/cd6tsSl6RhFKNPbzvLtSMFGtQTHE2whh9le8eOg3Wo9wqv4cq+9OZTYCerQRm4R76ox7hsGx74pUPHxTv/lszp0qk8zsWZKl6m3FT83dba5A5Hp2jFp2j5ZU3nAxQpYf5SpVd6IrCi2Gk76+jPvooi6Y/vqvZ1riTjl3LiEx87Je+/ALN9EOIZa9TE44zW1tqzhhX1m2YGv1/0fuaioNMpRtg9ofIvznHrLvASVcgCX+VfXpRedPlVa5R0QatJvTm17oIFUYaRu7p06M5X5QMi/zdyNMPcmOjOalM2ZFEctaf127CDhes6kB1Ia+ycKdA== X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(339900001)(189002)(199003)(36756003)(19580395003)(19580405001)(189998001)(50226001)(5820100001)(76176999)(110136002)(107886002)(5001960100002)(50986999)(6806004)(33646002)(50466002)(47776003)(104016003)(46102003)(77156002)(62966003)(2950100001)(106466001)(85426001)(105606002)(86362001)(92566002)(87936001)(77096005)(23676002)(229853001)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:SN1PR0301MB1614; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; SN1PR0301MB1614; 2:MqAWwsiJY+NO1ImJ/FS7iLLAToSi85C9TbVZrAfNZ6p2+Q3KaZCBlc4KaqaW75Im; 3:ef4ys7bZ86wLgiHYpD4xN2f//YjvVIMn8Wl2AT1j2Qdacnup3hUgo4qHuyxh+apavCHdRlxl9lXjj+oYaGpjRyHFTHpJ179A9yGxzm+3TaHWvrWpvbVlp+Tz3Yihy6mK6LdmwMat5Oxv3Tvm+qiNWTIUYtARkv5JeBswVVNOtLin5J65ZYkWm3Sfx5JayCyNDJRyUXKM7FcCWq+xOQcILcqCPU0EVhWv1jnmgZ/PsHw=; 25:dBlE/ilM7APVhCbMtRcblsuj57toFIIgS2UGWh3nL4+M6RG3e9Ff3iafgrzP/FOmIzJc4gHY2OmHaeVV5q1tZ4tDVsTEwxBqwu/icc3/zqRXPRfxQxCqE1sZJVi7YcAUxVuQIjZDvekeY8igT7cdNvbpeDBEz2Q5S4pIBVtpl8Wtf6eIjh+lG4J43T1BWTXO/LOewtZ9g4/33To1iypMRu3rSff04gAWMkBLOfmGeFLTN9zI+CQABhEKz2YiP/eh; 20:l2Q/F3ezs3j1pAMhJdBJsepnSCBZctUHMeE7O8Ih+5pd5MbOteaZW7q4pNm8gp6YXRV8o6pjIH2BvgsyzTvAJ6hCtzdUasyW8J53A/Nq1u+k7AsoMZCbY56fvU6byTwLdfchzeGs5YPxMWqMYzfajh95nHxU0m0q92aMKcS1k++4WQ5w9MO6ed3VcpZ8feqGlciWRNd0syNhJfKAx4+JqpkLkLTxo105vM4gLRPRucwgcZuxsTc2obgBkKa//rTl4ZE+MQKMEtEJUX0qoY53NhTek1OfyUJhvsNuUl5EXpJcgFFDAOH8EZxXE/DO2p8syaA5pvXEBqtPiVvMaHOAq65+zZs6/8VP2CIh4FvVKSI= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN1PR0301MB1614; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:SN1PR0301MB1614; BCL:0; PCL:0; RULEID:; SRVR:SN1PR0301MB1614; X-Microsoft-Exchange-Diagnostics: 1; SN1PR0301MB1614; 4:zhZAzbuJdxlhJwh4ZE0Z1RD2ORclwRiT/UunKSA2dWAcUGNhpQMh5QRuwMM/g5zJ5ReKI8c17LxF2OgIfsfg4UehcOYq2YjV0gE/krfaihp4L0GLoXfdqVTyzDgWMH1gFv3ZDLK8SC52kNPJs8M0kkj2wS0+t1+rpjbMvLCcNj+C9TYeJfKUjxYW8pMCvZ0VwTRYi3WpXPv8949VE8onlGNQNwJgSaplRwKErAh1AAh69koXagicV1wjVkvi7grYXAwX6q1sc0W0qnqWJ3qfu3A0AWOR/V6MNRQe7pKL0EM= X-Forefront-PRVS: 06530126A4 X-Microsoft-Exchange-Diagnostics: 1; SN1PR0301MB1614; 23:4+N7PzYbQecN4irHdsk3YjF/NajHuCzOZA6FVJOb+zm9YCilO/vC8mEGZO2cKsW/WKd2PogukmrvHu6/p7i6e27D4VsPAX/niu/lU4su8P2m5UCfFScvzXaTD2jHDNy4bnl7RILIqzvLPLotBh91r4UukbHf1UQ2o7edv+HkCS3OmhK8esN+gRidIvvZYWVp7OQuocAqG62TjkBzSB0y/NieDfbt08+fbVwqa6v1FkcYj+oHxNEGfh12zy5xao+sTuPXibHk02Vgwr0E5jZ4+cC1Q/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ale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2015 19:11:31.0076 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR0301MB1614 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 The encap shared descriptor was changed to use the new IV convention. In the process some commands were shifted, making the output length zero, caam effectively writing garbage in dst. While here, update the decap descriptor to execute the "write" commands before the "read"s (as it previously was). This makes sure the input fifo is drained before becoming full. Fixes: 46218750d523 ("crypto: caam - Use new IV convention") Signed-off-by: Horia Geant? Signed-off-by: Tudor Ambarus --- v2 - added erratum workaround drivers/crypto/caam/caamalg.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c index 3c50a5082127..e49373409582 100644 --- a/drivers/crypto/caam/caamalg.c +++ b/drivers/crypto/caam/caamalg.c @@ -87,8 +87,8 @@ #define DESC_GCM_DEC_LEN (DESC_GCM_BASE + 12 * CAAM_CMD_SZ) #define DESC_RFC4106_BASE (3 * CAAM_CMD_SZ) -#define DESC_RFC4106_ENC_LEN (DESC_RFC4106_BASE + 12 * CAAM_CMD_SZ) -#define DESC_RFC4106_DEC_LEN (DESC_RFC4106_BASE + 12 * CAAM_CMD_SZ) +#define DESC_RFC4106_ENC_LEN (DESC_RFC4106_BASE + 13 * CAAM_CMD_SZ) +#define DESC_RFC4106_DEC_LEN (DESC_RFC4106_BASE + 13 * CAAM_CMD_SZ) #define DESC_RFC4543_BASE (3 * CAAM_CMD_SZ) #define DESC_RFC4543_ENC_LEN (DESC_RFC4543_BASE + 11 * CAAM_CMD_SZ) @@ -989,19 +989,22 @@ static int rfc4106_set_sh_desc(struct crypto_aead *aead) /* Will read cryptlen bytes */ append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ); - /* Read payload data */ - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF | - FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1); + /* Workaround for erratum A-005473 (simultaneous SEQ FIFO skips) */ + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLD_TYPE_MSG); /* Skip assoc data */ append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF); /* cryptlen = seqoutlen - assoclen */ - append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ); + append_math_sub(desc, VARSEQOUTLEN, VARSEQINLEN, REG0, CAAM_CMD_SZ); /* Write encrypted data */ append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF); + /* Read payload data */ + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF | + FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1); + /* Write ICV */ append_seq_store(desc, ctx->authsize, LDST_CLASS_1_CCB | LDST_SRCDST_BYTE_CONTEXT); @@ -1060,9 +1063,8 @@ static int rfc4106_set_sh_desc(struct crypto_aead *aead) /* Will read cryptlen bytes */ append_math_sub(desc, VARSEQINLEN, SEQOUTLEN, REG3, CAAM_CMD_SZ); - /* Read encrypted data */ - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF | - FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1); + /* Workaround for erratum A-005473 (simultaneous SEQ FIFO skips) */ + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLD_TYPE_MSG); /* Skip assoc data */ append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF); @@ -1073,6 +1075,10 @@ static int rfc4106_set_sh_desc(struct crypto_aead *aead) /* Store payload data */ append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF); + /* Read encrypted data */ + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF | + FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1); + /* Read ICV */ append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS1 | FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1);