From nobody Sun Feb 8 18:32:27 2026 Received: from PH0PR06CU001.outbound.protection.outlook.com (mail-westus3azon11011055.outbound.protection.outlook.com [40.107.208.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99FAB26E6EB; Thu, 13 Nov 2025 14:08:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.208.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763042908; cv=fail; b=PbdoLRkd3kcxUkFO1neuSF8Ch58IE7InGpEEAzKzNunIvLIU/JTo9F4k5F/wiCWCaWtIL5I5kQI8XQT+7D8LeYAMyB2fGNY9HRMBpDHiltgkZUD5gCM6NDIV1oQEkV3amBJsCamhxqijBRl6THoz9PdXQdvQz4Ao9TQ0ulcFekU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763042908; c=relaxed/simple; bh=tw3mYPt5Dp0gY6fYyA2YIbriQi256DWcDyIBim3t0/o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OXMi3RgWIhBkt9AxZGb785NGkJa8XWU+eISEyL4dLrU92b0kZq4eNcyk5J7kvvnpS51a5WsS76ND/mduZu44sPMsIB2x5H6ePa/mAvgij4NO8qOksrceRJEs/4w3XC/KR3atbpbG50fBS2UtcXdH4ve2ek6+YoclS0RMH41dFNE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=YhS4cRQn; arc=fail smtp.client-ip=40.107.208.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="YhS4cRQn" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JYx4Ct+JiuF4rzCnrp9yZ7pcO3NFUWrkOp1F0bg7VyX2BA1pKQRNzDoxpvuWf7qdxDPws3cYULBQCKaT0c6QaeQ3U98DYHoZDaZ6uBwvOwBFpXzVYTB7GzK2ZA6bP1aJuJ74Xr2IW0Uqa8w0bowp+w+7oG+B890T5iuknfaxTmhnbmVDu1fJQlvvB+Mzkg81tT3rbzZJi1I2xrPg8UdXPAiRoqLKRJIj5FMU22p/JP1S5MPdjeK68Eh3W2GeMHQGZmSDg/TNmqt11SZ7OSZNOHHhbv2xU4X++4yR37Fs1NHwzLDMI4Rksl12Hsp4C8OdG1Fr1uezpq95sdxZ2srucw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TK3QnIiFjRAnuT2gkBgd0Nfy/8mEjcLseOL9qtiQZAM=; b=yXFmWdu+znDNfNXx+224srizqvREPzMHoEIH3J2Nc4GtuNYmMOVg6JbPy99rg72wT9lX+/6m42RpyBqbLwg5gIvrDF972ZSY7sIg0WR52SVabz/g5mFh1ogwLZPQwh27ObQFmSSl832pABjIAooNNPKZSDUCTQBtUc6nKo4cA6QjMVAd9nDGNVJelu6bpOZMPWplmcLNAxyva5+ODesL4l92Axb4WYcIh4wihTklU2EO/0LvJbPPPo7MZMk2d3yeKsGcN6+Sf/OIJ598q4u67x8wsr1+BwjeTSTc0J6IY4TPpfTRQfkjYkIHK4JezJ627pyBnrbUZZzLivYyrpYTng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 198.47.23.195) smtp.rcpttodomain=gondor.apana.org.au smtp.mailfrom=ti.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=ti.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TK3QnIiFjRAnuT2gkBgd0Nfy/8mEjcLseOL9qtiQZAM=; b=YhS4cRQnfgrCG56bel5GGD0iqo1Gv+OFcoz5mMrppY5KshFbS5GIpiLVxeC2ETL7kINdgZNi2zHGQqSSqFqw0CHxqfVJ3cQvPAT24dc+1ukvPbJxWq+lboMQ0uRbrrNZS8g/c3SJ4vCfhL42/lb/DnpGGZ/MpYDyjhE94/lMna4= Received: from BL1PR13CA0074.namprd13.prod.outlook.com (2603:10b6:208:2b8::19) by DM3PPF2DE5834CD.namprd10.prod.outlook.com (2603:10b6:f:fc00::c14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.17; Thu, 13 Nov 2025 14:08:21 +0000 Received: from BL6PEPF0001AB50.namprd04.prod.outlook.com (2603:10b6:208:2b8:cafe::cf) by BL1PR13CA0074.outlook.office365.com (2603:10b6:208:2b8::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9343.6 via Frontend Transport; Thu, 13 Nov 2025 14:08:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 198.47.23.195) smtp.mailfrom=ti.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ti.com; Received-SPF: Pass (protection.outlook.com: domain of ti.com designates 198.47.23.195 as permitted sender) receiver=protection.outlook.com; client-ip=198.47.23.195; helo=lewvzet201.ext.ti.com; pr=C Received: from lewvzet201.ext.ti.com (198.47.23.195) by BL6PEPF0001AB50.mail.protection.outlook.com (10.167.242.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.13 via Frontend Transport; Thu, 13 Nov 2025 14:08:19 +0000 Received: from DLEE209.ent.ti.com (157.170.170.98) by lewvzet201.ext.ti.com (10.4.14.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Thu, 13 Nov 2025 08:08:14 -0600 Received: from DLEE203.ent.ti.com (157.170.170.78) by DLEE209.ent.ti.com (157.170.170.98) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Thu, 13 Nov 2025 08:08:13 -0600 Received: from lelvem-mr06.itg.ti.com (10.180.75.8) by DLEE203.ent.ti.com (157.170.170.78) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20 via Frontend Transport; Thu, 13 Nov 2025 08:08:13 -0600 Received: from pratham-Workstation-PC (pratham-workstation-pc.dhcp.ti.com [10.24.69.191]) by lelvem-mr06.itg.ti.com (8.18.1/8.18.1) with ESMTP id 5ADE8C00385904; Thu, 13 Nov 2025 08:08:13 -0600 From: T Pratham To: , Herbert Xu , "David S. Miller" CC: , , "Manorit Chawdhry" , Shiva Tripathi Subject: [BUG 1/2] crypto: ahash - import/export fails for algs using CRYPTO_AHASH_ALG_BLOCK_ONLY Date: Thu, 13 Nov 2025 19:30:12 +0530 Message-ID: <20251113140634.1559529-2-t-pratham@ti.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251113140634.1559529-1-t-pratham@ti.com> References: <20251113140634.1559529-1-t-pratham@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB50:EE_|DM3PPF2DE5834CD:EE_ X-MS-Office365-Filtering-Correlation-Id: 3951c038-b495-4274-5095-08de22be192e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?23CmcE4tUNInCHlNUaO/Lxm86GIGvTfmUpvSVTkyXEfe3GDzUId5u9bLysvq?= =?us-ascii?Q?YjbjqYCBFfpOc5IhuLxjFmMHf2xvbrXJyJcQzXDVqXhRh7ksFlnu9yfiVKAK?= =?us-ascii?Q?53imXrkiag/TRuZkf5roM2gEfBTTcQvU+arplO3qUrZSVb7QfN7GuotIJkkB?= =?us-ascii?Q?u/LfO+oONcZXy0AjqgMZzKGAHZglbZSdbgIWYYvdqzl1s/yo4IeUtZvIn14u?= =?us-ascii?Q?3YZTf57CTW698brMoL2msRBUnpENdBQ2JYOcuiKLEKQ1/xuz3vMtsQnl+7yH?= =?us-ascii?Q?EBBf40JVWtckVDjLn7hphMgHoWYkjhx4Qf2LKfCRyk7T9MhK50hfwYDAh8be?= =?us-ascii?Q?Mm5eez3VefrivpHU34EoFW4nVnH5I/MgFl3phJ1Wu/ADixTRXDF4L5FhDW7e?= =?us-ascii?Q?7YQVfD+EcCvkmLfi8A3MoC65kQGpzGtkvvzB0IO8CPLkkxFg6AAaHkRFumXL?= =?us-ascii?Q?8cdpQeGxvL6RELcSbPykl+lsnP5e9kGKzbnnHVovFeHUyFCRoT8DRmWUwzck?= =?us-ascii?Q?+ugtH/Yf+9owaxCmcTummb4AcUW+Ys//oFkMQoeg8qoJncJXGvNjq4WEMAIt?= =?us-ascii?Q?0QuW6jJG+qeZTYwufJeKeatP9wtQZsJijR6jBvfxXr5iSb1uxXUMmeiPdQLx?= =?us-ascii?Q?fp5JqfHExPymQLVSo4BsonJ5hw7tD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= =?us-ascii?Q?0q+ICMId0623yfeL8Tk=3D?= X-Forefront-Antispam-Report: CIP:198.47.23.195;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:lewvzet201.ext.ti.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: ti.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2025 14:08:19.4060 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3951c038-b495-4274-5095-08de22be192e X-MS-Exchange-CrossTenant-Id: e5b49634-450b-4709-8abb-1e2b19b982b7 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=e5b49634-450b-4709-8abb-1e2b19b982b7;Ip=[198.47.23.195];Helo=[lewvzet201.ext.ti.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB50.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PPF2DE5834CD Content-Type: text/plain; charset="utf-8" Hi, Commit 9d7a0ab1c7536 ("crypto: ahash - Handle partial blocks in API") introduced partial block handling for ahashes in the crypto API layer itsel= f. This enables ahash algorithms to return a positive integer from the update function to indicate the number of bytes in the input which are not process= ed and should be buffered for next update/finup/final call to process. When CRYPTO_AHASH_ALG_BLOCK_ONLY is enabled to let crypto layer handle the buffering for ahashes, it appears that the import/export for ahashes is bro= ken. Below are dmesg logs from my (work-in-progress) TI dthev2 hash driver: [ 12.713654] alg: ahash: sha256-dthev2 test failed (wrong result) on test= vector 1, cfg=3D"import/export" [ 12.735778] alg: ahash: sha512-dthev2 test failed (wrong result) on test= vector 1, cfg=3D"import/export" [ 12.740207] alg: self-tests for sha256 using sha256-dthev2 failed (rc=3D= -22) [ 12.752055] alg: self-tests for sha256 using sha256-dthev2 failed (rc=3D= -22) [ 12.760127] alg: self-tests for sha512 using sha512-dthev2 failed (rc=3D= -22) [ 12.847079] alg: self-tests for sha512 using sha512-dthev2 failed (rc=3D= -22) [ 13.632318] alg: ahash: md5-dthev2 test failed (wrong result) on test ve= ctor 2, cfg=3D"import/export" [ 13.643908] alg: self-tests for md5 using md5-dthev2 failed (rc=3D-22) [ 13.655051] alg: self-tests for md5 using md5-dthev2 failed (rc=3D-22) While debugging, I noticed the rather odd asymmetrical handling of the buff= er which stores the partial block in crypto_ahash_export vs crypto_ahash_impor= t in crypto/ahash.c:=20 Export: > if (crypto_ahash_block_only(tfm)) { > unsigned int plen =3D crypto_ahash_blocksize(tfm) + 1; > unsigned int reqsize =3D crypto_ahash_reqsize(tfm); > unsigned int ss =3D crypto_ahash_statesize(tfm); > u8 *buf =3D ahash_request_ctx(req); >=20 > memcpy(out + ss - plen, buf + reqsize - plen, plen); > } Import: > if (crypto_ahash_block_only(tfm)) { > unsigned int reqsize =3D crypto_ahash_reqsize(tfm); > u8 *buf =3D ahash_request_ctx(req); >=20 > buf[reqsize - 1] =3D 0; > } Import seemingly not copying the buffer back to request ctx and zeroing the length seems incorrect. Making export and import symmetrical seems to work = and my driver passes through import/export tests. diff --git a/crypto/ahash.c b/crypto/ahash.c index dfb4f5476428f..9510bdeda51de 100644 --- a/crypto/ahash.c +++ b/crypto/ahash.c @@ -674,10 +674,12 @@ int crypto_ahash_import(struct ahash_request *req, co= nst void *in) if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY) return -ENOKEY; if (crypto_ahash_block_only(tfm)) { + unsigned int plen =3D crypto_ahash_blocksize(tfm) + 1; unsigned int reqsize =3D crypto_ahash_reqsize(tfm); + unsigned int ss =3D crypto_ahash_statesize(tfm); u8 *buf =3D ahash_request_ctx(req); =20 - buf[reqsize - 1] =3D 0; + memcpy(buf + reqsize - plen, in + ss - plen, plen); } return crypto_ahash_alg(tfm)->import(req, in); } Is there any particular reason why import is like how it is currently? As p= er my understanding import should reverse whatever export is doing and vice-ve= rsa. It is also noteworthy that similarly import/export could be broken for shash algorithms as well. There also, import function zeros the length byte and d= oes not copy the buffer when CRYPTO_AHASH_ALG_BLOCK_ONLY is used. However I hav= en't tested any shash algorithm to verify this. Let me know if the above is the complete fix for ahash, so that I can send = it as a patch. --=20 Regards T Pratham From nobody Sun Feb 8 18:32:27 2026 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010069.outbound.protection.outlook.com [52.101.201.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4319826F2AC; Thu, 13 Nov 2025 14:08:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763042910; cv=fail; b=RJobB6EPIbN9hQF9B7AqPFPnxipaXsHjXKj1jYRuNgZIesY+kftoEnHyr/BlvOUZOSeutAhgwde4S7R4WhUoV9pmCKpW5oSiwI8hsjQvzxxcgfD9wIXcu65G7XZVGfqdI9bwWvOlnWmGmSyYEaQj6T+o0VJyhjraiIhiH5s12Tg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763042910; c=relaxed/simple; bh=bijiED3waRnrfhEn1OXomHEVmGfmd9CKZImKLpXToMU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iKIEwFMKP1jiKGP3Ddpjg1GcgB1I0Kz06QsSW9kOrrmFoMFi3mLXdwq6ZfFjA21/6g7y0UTowKBH7Hi1u+cqcWpQ4e8BqmTeStLhHxCjoYzT+L0vUDYRYT8mWV4mN2yTORfgL6lQJ/DSmETOJV86crh4h4WvPh5OmHLXzJfj8a0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=OK11rXwX; arc=fail smtp.client-ip=52.101.201.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="OK11rXwX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=R6iOn9GYZlt98vW8tc3pj1kJO1PL1rZhVzfxrLWsbWvjfEGZeYa3tYCHtHvQdlLh6ro9pRsJ3Wm3LsoF6l37cARWxFHVajxbw/pwhQ4/rceVGz+sPvA9+fzRt4UOAhDKJRSSwu7jHEX8oWLxrDiiI6ZNRq8JojbyGCwv7PjcpwAHAqg31Wx2PC091l7aDhAUuIpp/x2qyPttsq0mUSMKEaIKpjrPeVGJcRMsrpQ+L+qaK2bD8xN0nNd+lMyV7r6evGuGG5Vtng/KMyaDnq3fyQrO1vBHB6v6Yf+ouf9btIX/sryCZ4mEPTZjWOUehWgyI3Eg+RR/ZJiDhsIjD4U0wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=51L8M/eKotKFaYQ2OxK48bJTGQmL0j6+hH0lQYIZ4FY=; b=kcopPZnafC13zLg3BTaD6puvEyzgXcYu7vmkZvd3pSgp5VEIxz1Fg+HefTV9xjlVuh7GR2Hbi+jI4UgpG7h2IgiH6/mtdBlemlEv2IJaZPhUe+UWnCcuD/Rckjm/febsNK4ACAP9qIufE1w4bNXy1k6Wk2Nt/h6760oMJk9t84mwy7LS5KSd3YXslmh0gMjlkpOcisVy7eCrZH6t62rn3TyvLtl1P/CUe1W2aeRIvuFS4Q+ETpCB88so9lCcS4aWO1lq63DBcilk3aLHMo8xlXYotU5+/QzOwFn2Zkos6cwIOa1Yd/tNpV2p/XcSZxXwcHvKEbHeq7o7DmY0ADKwLg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 198.47.23.195) smtp.rcpttodomain=gondor.apana.org.au smtp.mailfrom=ti.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=ti.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=51L8M/eKotKFaYQ2OxK48bJTGQmL0j6+hH0lQYIZ4FY=; b=OK11rXwXTYb4i0lLJn2BP8LQeoSphXYHxIk/8PJZa7NR8W1fyZVz+LnhXu9bjTbfLcQhht8bromv9dN0x1CciaVM04FhEWjuJ0b+dCAZIs6D84QPlgjXMbNQ/MiVcJmPJeHG1DPUVyhKQStHzMTMwa9hTgXwBj+NQyD6qlSbT+Q= Received: from DS7PR03CA0254.namprd03.prod.outlook.com (2603:10b6:5:3b3::19) by MW4PR10MB5750.namprd10.prod.outlook.com (2603:10b6:303:18e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.16; Thu, 13 Nov 2025 14:08:24 +0000 Received: from DS2PEPF00003445.namprd04.prod.outlook.com (2603:10b6:5:3b3:cafe::2) by DS7PR03CA0254.outlook.office365.com (2603:10b6:5:3b3::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9298.16 via Frontend Transport; Thu, 13 Nov 2025 14:08:23 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 198.47.23.195) smtp.mailfrom=ti.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ti.com; Received-SPF: Pass (protection.outlook.com: domain of ti.com designates 198.47.23.195 as permitted sender) receiver=protection.outlook.com; client-ip=198.47.23.195; helo=lewvzet201.ext.ti.com; pr=C Received: from lewvzet201.ext.ti.com (198.47.23.195) by DS2PEPF00003445.mail.protection.outlook.com (10.167.17.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.13 via Frontend Transport; Thu, 13 Nov 2025 14:08:22 +0000 Received: from DLEE211.ent.ti.com (157.170.170.113) by lewvzet201.ext.ti.com (10.4.14.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Thu, 13 Nov 2025 08:08:17 -0600 Received: from DLEE200.ent.ti.com (157.170.170.75) by DLEE211.ent.ti.com (157.170.170.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Thu, 13 Nov 2025 08:08:16 -0600 Received: from lelvem-mr05.itg.ti.com (10.180.75.9) by DLEE200.ent.ti.com (157.170.170.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20 via Frontend Transport; Thu, 13 Nov 2025 08:08:16 -0600 Received: from pratham-Workstation-PC (pratham-workstation-pc.dhcp.ti.com [10.24.69.191]) by lelvem-mr05.itg.ti.com (8.18.1/8.18.1) with ESMTP id 5ADE8Fmt344544; Thu, 13 Nov 2025 08:08:15 -0600 From: T Pratham To: , Herbert Xu , "David S. Miller" CC: , , "Manorit Chawdhry" , Shiva Tripathi Subject: [BUG 2/2] crypto: ahash - testmgr false failures with CRYPTO_AHASH_ALG_BLOCK_ONLY Date: Thu, 13 Nov 2025 19:30:13 +0530 Message-ID: <20251113140634.1559529-3-t-pratham@ti.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251113140634.1559529-1-t-pratham@ti.com> References: <20251113140634.1559529-1-t-pratham@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF00003445:EE_|MW4PR10MB5750:EE_ X-MS-Office365-Filtering-Correlation-Id: 17867920-deaa-44d8-5a8b-08de22be1ad2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?FjobrQFLkHtDXGZNHmj9dRuOqqVKGXTc+swVs9dgljngVgxCs8lcY+mVirbz?= =?us-ascii?Q?gLTPobOs67+9h+cIGYTTMp6U0CInJJsSoqIgYeVcqWr+asfzoZ1dbxabdjS3?= =?us-ascii?Q?mRmLRCdcFsWc6OSLKtqNX/2hZyiIUjcm3vKJVlw3FEnrCQloph7iIFmcYXl+?= =?us-ascii?Q?NjBiJCmerAqarskwePb+DR+mT88m/zW7qX7IBvVjpj5QhONwfsdjOQ8h9QzX?= =?us-ascii?Q?OJdQ7ZNoApOg7Mr69th8CMRMqkubuAzwrL3gtc6wu9sZvtrnY+bL/qolDmjh?= =?us-ascii?Q?c67DfgXXogxKHfT4PRYNwrzsKoSIPbd0FSkCuLePaR699ZaGhFsmQZ0XAgdr?= =?us-ascii?Q?Xt6PKGN344Ucxn3YPof6Muf3EiCZveCvd7/vwdc934IFc40v/pbLwfj4oT1z?= =?us-ascii?Q?KlyuZ6m3h2wrk+PedjD8N29K6E2D5ABvqxGJ1QnenZBSXM35UWvBZsQYHyPx?= =?us-ascii?Q?8rkpghy+1PWXKxg5DU5boSFGZPnJnKemGxGHeIu86N1I7QLLdi0b+4u8qj9W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Of2ye9qpLe1L9PdcmIy/aJL?= =?us-ascii?Q?6afIRA05unW8YuSGCRFBGlhGjLFWXwJ4LhjNsFqTo6Xu9BwpG6TK35dVZ1Hm?= =?us-ascii?Q?1/XA0s/6lpuoZZP39KjRt2JuGnrai91f2wJ7hWF7l6/n9AQJAt37UhzxUrly?= =?us-ascii?Q?bKoTz06JAb3IevcLue4=3D?= X-Forefront-Antispam-Report: CIP:198.47.23.195;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:lewvzet201.ext.ti.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: ti.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2025 14:08:22.1496 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 17867920-deaa-44d8-5a8b-08de22be1ad2 X-MS-Exchange-CrossTenant-Id: e5b49634-450b-4709-8abb-1e2b19b982b7 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=e5b49634-450b-4709-8abb-1e2b19b982b7;Ip=[198.47.23.195];Helo=[lewvzet201.ext.ti.com] X-MS-Exchange-CrossTenant-AuthSource: DS2PEPF00003445.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB5750 Content-Type: text/plain; charset="utf-8" Hi, Commit 9d7a0ab1c7536 ("crypto: ahash - Handle partial blocks in API") introduced partial block handling for ahashes in the crypto API layer itsel= f. This enables ahash algorithms to return a positive integer from the update function to indicate the number of bytes in the input which are not process= ed and should be buffered for next update/finup/final call to process. It appears that the testmgr is not updated to handle this positive return v= alue from update(). As a result, self-tests fail (falsely) for such ahash algorithms. Below are dmesg logs from my (work-in-progress) TI dthev2 hash driver: [ 12.933924] alg: ahash: sha256-dthev2 update() failed with err 62 on tes= t vector 4, cfg=3D"init+update+final aligned buffer" [ 12.951212] alg: self-tests for sha256 using sha256-dthev2 failed (rc=3D= 62) [ 13.008108] alg: self-tests for sha256 using sha256-dthev2 failed (rc=3D= 62) [ 13.361625] alg: ahash: sha512-dthev2 update() failed with err 126 on te= st vector 5, cfg=3D"init+update+final aligned buffer" [ 13.376311] alg: self-tests for sha512 using sha512-dthev2 failed (rc=3D= 126) [ 13.388088] alg: self-tests for sha512 using sha512-dthev2 failed (rc=3D= 126) [ 13.389503] alg: ahash: md5-dthev2 update() failed with err 15 on test v= ector 6, cfg=3D"init+update+final aligned buffer" [ 13.421488] alg: self-tests for md5 using md5-dthev2 failed (rc=3D15) [ 13.478062] alg: self-tests for md5 using md5-dthev2 failed (rc=3D15) Note: the driver works completely fine on a TI internal v6.12 LTS tree where this buffering is being handled by the driver itself. Now, while debugging the issue, this messy fixup in testmgr code works fine= and my ahash driver passes. diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 6a490aaa71b9a..523507e79f760 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include =20 @@ -1571,9 +1572,16 @@ static int test_ahash_vec_cfg(const struct hash_test= vec *vec, pending_len); err =3D do_ahash_op(crypto_ahash_update, req, &wait, divs[i]->nosimd); - err =3D check_nonfinal_ahash_op("update", err, - result, digestsize, - driver, vec_name, cfg= ); + if ((crypto_ahash_alg(tfm)->halg.base.cra_flags & + CRYPTO_AHASH_ALG_BLOCK_ONLY) && + err >=3D 0) + err =3D check_nonfinal_ahash_op("update", 0, + result, diges= tsize, + driver, vec_n= ame, cfg); + else + err =3D check_nonfinal_ahash_op("update", e= rr, + result, diges= tsize, + driver, vec_n= ame, cfg); if (err) return err; pending_sgl =3D NULL; @@ -1614,8 +1622,14 @@ static int test_ahash_vec_cfg(const struct hash_test= vec *vec, if (cfg->finalization_type =3D=3D FINALIZATION_TYPE_FINAL) { /* finish with update() and final() */ err =3D do_ahash_op(crypto_ahash_update, req, &wait, cfg->n= osimd); - err =3D check_nonfinal_ahash_op("update", err, result, dige= stsize, - driver, vec_name, cfg); + if ((crypto_ahash_alg(tfm)->halg.base.cra_flags & + CRYPTO_AHASH_ALG_BLOCK_ONLY) && + err >=3D 0) + err =3D check_nonfinal_ahash_op("update", 0, result= , digestsize, + driver, vec_name, cfg= ); + else + err =3D check_nonfinal_ahash_op("update", err, resu= lt, digestsize, + driver, vec_name, cfg= ); if (err) return err; err =3D do_ahash_op(crypto_ahash_final, req, &wait, cfg->no= simd); While I have not tested any shash code with CRYPTO_AHASH_ALG_BLOCK_ONLY, it= is highly possible that testmgr will report a false negative there as well. I can send a fix for ahash. Let me know if it is better to just add a separ= ate check in the testmgr (in which case, I'll cleanup the above diff and send a= s a separate patch), or should we modify the crypto_ahash_update() function in crypto/ahash.c to return 0 as it handles all the buffer management inside itself. The callers of crypto_ahash_update() anyway don't expect a non-zero positive value on success as far as I can see.=20 --=20 Regards T Pratham