From nobody Sun Nov 24 12:49:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@seagate.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=seagate.com); dmarc=pass(p=reject dis=none) header.from=seagate.com ARC-Seal: i=2; a=rsa-sha256; t=1723060551; cv=pass; d=zohomail.com; s=zohoarc; b=Qg4SRFW+BJXuTZYnlIY1QpONQ/IfuyGI/1nLH+kcC+8T8vYgmvM/VUBZ2f9qK6j6WYJ1qiFWblhSljAa27l1gXwJCSu7hmYuM9QPDV4v9QUBtvgvVOFzT288uUBWS+x3dbfx+6WERUNVkFvty0IMH2rHZtebAUKTF61attD/hMI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723060551; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EO1IU54H8vQK0dXuyDOjclGCiyTYYeFW2YISuKH4O9E=; b=njk1frF8USxitr8Vc6kT9Osonskx1aZU6DpXbsnRAbCNf/YMlhdUNFcq1fMAeVvaM/cvPpF0P3gGEyBO8fBOjkCDnzFD9TNr8mcnQuKHPf0Q2ruyw9YchPen9ODEGu6EXT+ans/g44JerDZTvWI6QfBgirCz90E8j4s3NjO956Q= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass header.i=@seagate.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=seagate.com); dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1723060551407161.94821042985745; Wed, 7 Aug 2024 12:55:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sbmjg-0006aK-7y; Wed, 07 Aug 2024 15:54:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sbmjR-00069M-Lc; Wed, 07 Aug 2024 15:54:02 -0400 Received: from esa.hc4959-67.iphmx.com ([139.138.35.140]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sbmjP-00020B-Dw; Wed, 07 Aug 2024 15:54:01 -0400 Received: from mail-dm6nam11lp2169.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.169]) by ob1.hc4959-67.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2024 12:53:57 -0700 Received: from CYZPR20CA0006.namprd20.prod.outlook.com (2603:10b6:930:a2::28) by IA1PR20MB4876.namprd20.prod.outlook.com (2603:10b6:208:3e4::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.27; Wed, 7 Aug 2024 19:53:52 +0000 Received: from CY4PEPF0000EE3A.namprd03.prod.outlook.com (2603:10b6:930:a2:cafe::51) by CYZPR20CA0006.outlook.office365.com (2603:10b6:930:a2::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14 via Frontend Transport; Wed, 7 Aug 2024 19:53:51 +0000 Received: from sgspzesaa002.seagate.com (192.55.16.51) by CY4PEPF0000EE3A.mail.protection.outlook.com (10.167.242.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.19 via Frontend Transport; Wed, 7 Aug 2024 19:53:50 +0000 Received: from sgspiesaa002.seagate.com ([10.4.144.53]) by sgspzesaa002.seagate.com with ESMTP; 07 Aug 2024 12:53:41 -0700 Received: from unknown (HELO cortana..) ([10.4.50.14]) by sgspiesaa002.seagate.com with ESMTP; 07 Aug 2024 12:53:34 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=seagate.com; i=@seagate.com; q=dns/txt; s=stxiport; t=1723060439; x=1754596439; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TuMPf6/LLf4Mzv5FzQ3tLLQAiSRSY4I0dNxCq32DUQA=; b=KmK8zWFcVQXvMC9A3jvELfXjnMI2HCyX4Q8QVegZiq2WEfVNlgED11Uo vRsKi1rO0MVVfKLUH4heSQLNzpJPzJoQd7H1Jr7WQv8bFcfalYAbuEHxa m9PFMJyBrHK5pGg6cWghBT7gWITCQanBvyydUGVP+/k38O5/QsAgsNVMS I=; X-CSE-ConnectionGUID: LRYR6gWnTYyvaZ0eUFr46A== X-CSE-MsgGUID: 4JlBm6a7RCa1kNL90O27yQ== ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=V9pn0YMGgSpRtwpB84JjzXPcOnT/MJpyPWNweZCu/jO0SvXhdaKQr58FNvMZxiQTZH1FUIrhhZaK3kYK66YzOrIxL2ktmws/kY/erNqqgdZoTf5c0yqL+sBm0FiEzKNm2WuaoAd+0vVpm/3cm6KYTgGpzg058H8UMsAncEBkYK6HyBVX/C6FB0jcmDd58V6LL1kmKfYuUsH6zlub9dpiwvwC+luYT5aoftcNpv0+IyIOMa35F3w+i1PD6Sn1o3hUB7LfN6P4IOoJomhQV1cevsQ19OG6e2H0zxd8La0ywU8V9lCHw/1L6qkDbHMusIrIxotJchAtXR7q+v3vjTmgrQ== 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=EO1IU54H8vQK0dXuyDOjclGCiyTYYeFW2YISuKH4O9E=; b=vgu2ztNWnXmHyXR48UAmnbqR2/aplvHTU6qk9eJbU5bZ4na7u37ERKeodPr0c0FSrWVIIMpWhNWHsG0owWDaY/HwBjlZmYcqwkLU7FfY5Rk0X6A/c4JeddvhGDtgHk/AMG9IPzmgJYq2IexkWtwYI0OYA9AD1Rk3sVRuF4h/gyXNiH8093pvKy3+mDxiT2JNk6qO2CSD3Xco2C0O2rPCZtfwnj77R7DsBWkC3rjfRc72UO+e2w8Ywf0RK9/tCHMf4k4pZDH68AWVAAKmLmQLbvtiEHOl3RmHvz78wRyipOV4aXU94xnRJmhXYo0PIIBF3/jbaucHULOWJ50y+2+PEw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=softfail (sender ip is 192.55.16.51) smtp.rcpttodomain=nongnu.org smtp.mailfrom=seagate.com; dmarc=fail (p=reject sp=reject pct=100) action=oreject header.from=seagate.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seagate.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EO1IU54H8vQK0dXuyDOjclGCiyTYYeFW2YISuKH4O9E=; b=EZ/y588fC1BZ8HGoJFaKKZ4hn1xlkzWdwkZK+0XDN9fkrSdYFY2XcrdA5fGk/a59MBEN60nCbOvk21hcd0HgwVG5wJx0PIP8/eHSYunVcz0xJmBcamQhVRGyU6pwxYE29+qmjDuPBHcoCbPXsvwl+Or4SLXPpAnF6G9+lzWQKAc= X-MS-Exchange-Authentication-Results: spf=softfail (sender IP is 192.55.16.51) smtp.mailfrom=seagate.com; dkim=none (message not signed) header.d=none;dmarc=fail action=oreject header.from=seagate.com; X-CSE-ConnectionGUID: GPdMGsk/S7Gc+zbwzy7UsA== X-CSE-MsgGUID: xd9NqDviQUeb3Q9Jc3J91A== X-CSE-ConnectionGUID: UBrA4w9rR+qqzdh3R1dPOg== X-CSE-MsgGUID: tHnGkgjmT+WlpI/c5WYodA== X-IronPort-AV: E=Sophos;i="6.09,270,1716274800"; d="scan'208";a="122235464" STX-Internal-Mailhost: TRUE From: Alejandro Zeise To: qemu-arm@nongnu.org Cc: alejandro.zeise@seagate.com, kris.conklin@seagate.com, jonathan.henze@seagate.com, evan.burgess@seagate.com, clg@kaod.org, peter.maydell@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v4 06/15] crypto/hash-afalg: Implement new hash API Date: Wed, 7 Aug 2024 19:51:13 +0000 Message-Id: <20240807195122.2827364-7-alejandro.zeise@seagate.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240807195122.2827364-1-alejandro.zeise@seagate.com> References: <20240807195122.2827364-1-alejandro.zeise@seagate.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3A:EE_|IA1PR20MB4876:EE_ X-MS-Office365-Filtering-Correlation-Id: 87b21e79-7d5d-48e0-c863-08dcb71aa94e STX-Hosted-IronPort-Oubound: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|1800799024|36860700013|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Kk/P4q6zrSu80C8wFKL3s18kX1CntKIzaTOEAbT5eqzlmknbXd/FQLNnmUKf?= =?us-ascii?Q?ZpOV5F88XKGt6A5En2LkuNToUF9aKa+ynhUpJXoASJ+8rv42zj5VJA6VnOJK?= =?us-ascii?Q?LKMKxjeaQxNvuJ22YI7jZXEB6X6bZX3imuOEJe2IdRDx/3VhPHaJG/v1doKs?= =?us-ascii?Q?Ir2ONu5Tj753lgCx6HYIsBl30PH/6ifIroDQrWXYam5sxGgEfIn28WRrd8oY?= =?us-ascii?Q?gU37iMVXcaG2frDk1vD++kQa9dN0EZYx+cew2b5goii/q1QXic/juE0wyfTo?= =?us-ascii?Q?nIuiZS1POyrPAYnZEpqchZ7/MzKUwNoQNyJslWiR/OOddnmokRVWbBwbu7vG?= =?us-ascii?Q?Fq7JmJLBxHBUN5OLEGyye/y7bmkxY1NlfhBgGVCSq08z3z1c5MhYBhPrSTh5?= =?us-ascii?Q?brFoMyipfoqi8aT0VtzSHych9eM3QXo/j6jcGda/0pZxdEMl4QIWCg0MWpPL?= =?us-ascii?Q?uYDEiV+eJ1cvhGo37/zyKyWagvmrCi3BAnomIIKt0ckUg7s4zMP5SXdOyM8E?= =?us-ascii?Q?+y5MrxvQb9zLTajEsdmXIZI3gwyNCSHElFIzt1Rwm81+o+u93XY2QflPF+uF?= =?us-ascii?Q?WcFAcS2YNII4KxtRw3TdkzADuRdrva78/4690bJBzllLpwtqlFjZys3EI7yS?= =?us-ascii?Q?N8UXRklnHWigehDpkVVPX7a36URmZ17OieIV1xIam2EYFd2TcNIqFBOmmmee?= =?us-ascii?Q?unTyhWrOMwjRrUrYO+lzmjm62lfsPA0QVfSpaAeEqeYk71I87bPHUCo32ESg?= =?us-ascii?Q?ZxezX54ThsFEqt9lb1XtJAdkVTGorceikzjX70QfReUQBqQWsoH/xurwirI5?= =?us-ascii?Q?aCPF8O/JZ58jpLyYshCLvh9AGgmtyQgIbpsl7/ZStrNTf2dhdWn1brwt86Et?= =?us-ascii?Q?SFOqB916dDIj8VrfdC+8slZ8P1be02k4fCcuARLsCGrf5Bh6rTbRBmmJMbZs?= =?us-ascii?Q?mQeZS829UEA+hitGkf0EbQjWXOVz9RViTjij0IULsiuDhx1LO7N7saUiUZbd?= =?us-ascii?Q?GwWZTG3mCBF77dK9F6pj+s3uk86n/ZDlOWV47OzrPm3wOomxyN1H2e1dG7XR?= =?us-ascii?Q?uf5j/+Qf/oj2aQ0Bu3M9DESwbwRbfKuaWDAd2DD02V3+f33lIveRGLYCCD0X?= =?us-ascii?Q?ADftEvgxomPWKrmXZ010Jb4JV91tINrzjCLMMp+UppZsGHGcTgAzZBdWIyPl?= =?us-ascii?Q?N/If34g4quqis0huI6/oWmw5Hxvr8FN3F6Zhznrkt27VshC4XIL5HZEbyzuh?= =?us-ascii?Q?ELRatC/wb3ozzG39ZefNk+fu7l3W3Cmj/5iIZawnTWLKPB9WZxxk/QU0i3sW?= =?us-ascii?Q?6vKkjuHyQRG5yqk9UAILdwf9EPOgtS8K9wDxeSPWaO/nmR0lopthn8skjDME?= =?us-ascii?Q?eej4EDsPxPjiO8F8y/f4R3c42XAOQhqaqovTkefP6JIltA+6OmeFu6jgcQIo?= =?us-ascii?Q?58koLjTRxZEd/QNq+aTpbEnf2WOjjv88?= X-Forefront-Antispam-Report: CIP:192.55.16.51; CTRY:SG; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:sgspzesaa002.seagate.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(82310400026)(1800799024)(36860700013)(376014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: sbSBDt5A2A1SUYkct7fh4k/tauDfFKieDEqLYavSb8VKZfXk0hSZyN5CL86q0ZL8ChcHx1/pSHDefPx10kn24GfAKmQbIprqoJj1RetdrNeip1dePAFMwe9Cyo44vdTJU3woSNfoU4PhDm6ab3SUrTEtDU/awqL8qhshZpHsetdqxWdsQ/eLq1BlkzzY2YTOoDa2wRl+EpaErJQq88DpMs27J750CZp51BOIE2HOBrWkB329Pwgz0u4Vxg9XQIlOJPFjJpp12DA4FlRIpske9liXyE3XOI8viG8qdvPk6C7YJRzx1olqc+JDgsrMsuTA2XXEYZoPlSPIkFgEECtagNT0f+KbYm4DtVkFJqlnuZRTHjJW3wb/UWIaVDuj6ywpw04K+XEcnCXb2C9uS5rIkXVgbYj0SrAdudsq9cZPAL6hbrLm7QJxF1eaifL5kl7PfhobNjE3S/U1AcopN3VQjVL0q3Wncl/8O+ZruLnjoNd8RmfZfLIxCWifUMDaBnU4klMAZpL4oNnVuTMjWFOOyfkz+GdVdmyyT507t2u07dEODxST496CphOEzRTZcHd6FQ7zlBz6GpGoWUphB0bhKHPupA4uH2agA6SJvnrLqJlGqj+6jOC/F6HYqrMNUZYo X-OriginatorOrg: seagate.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 19:53:50.9813 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 87b21e79-7d5d-48e0-c863-08dcb71aa94e X-MS-Exchange-CrossTenant-Id: d466216a-c643-434a-9c2e-057448c17cbe X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d466216a-c643-434a-9c2e-057448c17cbe; Ip=[192.55.16.51]; Helo=[sgspzesaa002.seagate.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE3A.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR20MB4876 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=139.138.35.140; envelope-from=alejandro.zeise@seagate.com; helo=esa.hc4959-67.iphmx.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @seagate.com) X-ZM-MESSAGEID: 1723060553226116600 Content-Type: text/plain; charset="utf-8" Updates the afalg hash driver to support the new accumulative hashing changes as part of the patch series. Implements opening/closing of contexts, updating hash data and finalizing the hash digest. In order to support the update function, a flag needs to be passed to the kernel via the socket send call (MSG_MORE) to notify it that more data is to be expected to calculate the hash correctly. As a result, a new function was added to the iov helper utils to allow passing a flag to the socket send call. Signed-off-by: Alejandro Zeise --- crypto/hash-afalg.c | 126 ++++++++++++++++++++++++++++++++++++++++++++ include/qemu/iov.h | 26 +++++++++ util/iov.c | 22 +++++--- 3 files changed, 167 insertions(+), 7 deletions(-) diff --git a/crypto/hash-afalg.c b/crypto/hash-afalg.c index 3ebea39292..9548c04933 100644 --- a/crypto/hash-afalg.c +++ b/crypto/hash-afalg.c @@ -1,6 +1,7 @@ /* * QEMU Crypto af_alg-backend hash/hmac support * + * Copyright (c) 2024 Seagate Technology LLC and/or its Affiliates * Copyright (c) 2017 HUAWEI TECHNOLOGIES CO., LTD. * * Authors: @@ -113,6 +114,127 @@ qcrypto_afalg_hmac_ctx_new(QCryptoHashAlgorithm alg, return qcrypto_afalg_hash_hmac_ctx_new(alg, key, nkey, true, errp); } =20 +static +QCryptoHash *qcrypto_afalg_hash_new(QCryptoHashAlgorithm alg, Error **errp) +{ + /* Check if hash algorithm is supported */ + char *alg_name =3D qcrypto_afalg_hash_format_name(alg, false, NULL); + QCryptoHash *hash =3D NULL; + + if (alg_name =3D=3D NULL) { + error_setg(errp, + "Unknown hash algorithm %d", + alg); + } else { + hash =3D g_new(QCryptoHash, 1); + hash->alg =3D alg; + hash->opaque =3D qcrypto_afalg_hash_ctx_new(alg, errp); + } + + return hash; +} + +static +void qcrypto_afalg_hash_free(QCryptoHash *hash) +{ + QCryptoAFAlg *ctx =3D hash->opaque; + + if (ctx) { + qcrypto_afalg_comm_free(ctx); + } + + g_free(hash); +} + +/** + * Send data to the kernel's crypto core. + * + * The more_data parameter is used to notify the crypto engine + * that this is an "update" operation, and that more data will + * be provided to calculate the final hash. + */ +static +int qcrypto_afalg_send_to_kernel(QCryptoAFAlg *afalg, + const struct iovec *iov, + size_t niov, + bool more_data, + Error **errp) +{ + int ret =3D 0; + int flags =3D (more_data ? MSG_MORE : 0); + + /* send data to kernel's crypto core */ + ret =3D iov_send_recv_with_flags(afalg->opfd, flags, iov, niov, + 0, iov_size(iov, niov), true); + if (ret < 0) { + error_setg_errno(errp, errno, "Send data to afalg-core failed"); + ret =3D -1; + } else { + /* No error, so return 0 */ + ret =3D 0; + } + + return ret; +} + +static +int qcrypto_afalg_recv_from_kernel(QCryptoAFAlg *afalg, + QCryptoHashAlgorithm alg, + uint8_t **result, + size_t *result_len, + Error **errp) +{ + struct iovec outv; + int ret =3D 0; + const int expected_len =3D qcrypto_hash_digest_len(alg); + + if (*result_len =3D=3D 0) { + *result_len =3D expected_len; + *result =3D g_new0(uint8_t, *result_len); + } else if (*result_len !=3D expected_len) { + error_setg(errp, + "Result buffer size %zu is not match hash %d", + *result_len, expected_len); + ret =3D -1; + } + + if (ret =3D=3D 0) { + /* hash && get result */ + outv.iov_base =3D *result; + outv.iov_len =3D *result_len; + ret =3D iov_send_recv(afalg->opfd, &outv, 1, + 0, iov_size(&outv, 1), false); + if (ret < 0) { + error_setg_errno(errp, errno, "Recv result from afalg-core fai= led"); + ret =3D -1; + } else { + ret =3D 0; + } + } + + return ret; +} + +static +int qcrypto_afalg_hash_update(QCryptoHash *hash, + const struct iovec *iov, + size_t niov, + Error **errp) +{ + return qcrypto_afalg_send_to_kernel((QCryptoAFAlg *) hash->opaque, + iov, niov, true, errp); +} + +static +int qcrypto_afalg_hash_finalize(QCryptoHash *hash, + uint8_t **result, + size_t *result_len, + Error **errp) +{ + return qcrypto_afalg_recv_from_kernel((QCryptoAFAlg *) hash->opaque, + hash->alg, result, result_len, e= rrp); +} + static int qcrypto_afalg_hash_hmac_bytesv(QCryptoAFAlg *hmac, QCryptoHashAlgorithm alg, @@ -205,6 +327,10 @@ static void qcrypto_afalg_hmac_ctx_free(QCryptoHmac *h= mac) =20 QCryptoHashDriver qcrypto_hash_afalg_driver =3D { .hash_bytesv =3D qcrypto_afalg_hash_bytesv, + .hash_new =3D qcrypto_afalg_hash_new, + .hash_free =3D qcrypto_afalg_hash_free, + .hash_update =3D qcrypto_afalg_hash_update, + .hash_finalize =3D qcrypto_afalg_hash_finalize }; =20 QCryptoHmacDriver qcrypto_hmac_afalg_driver =3D { diff --git a/include/qemu/iov.h b/include/qemu/iov.h index 63a1c01965..43884cdd64 100644 --- a/include/qemu/iov.h +++ b/include/qemu/iov.h @@ -1,6 +1,7 @@ /* * Helpers for using (partial) iovecs. * + * Copyright (c) 2024 Seagate Technology LLC and/or its Affiliates * Copyright (C) 2010 Red Hat, Inc. * * Author(s): @@ -75,6 +76,31 @@ iov_to_buf(const struct iovec *iov, const unsigned int i= ov_cnt, size_t iov_memset(const struct iovec *iov, const unsigned int iov_cnt, size_t offset, int fillc, size_t bytes); =20 +/* + * Send/recv data from/to iovec buffers directly, with the provided + * socket flags. + * + * `offset' bytes in the beginning of iovec buffer are skipped and + * next `bytes' bytes are used, which must be within data of iovec. + * + * r =3D iov_send_recv_with_flags(sockfd, sockflags, iov, iovcnt, offset= , bytes, true); + * + * is logically equivalent to + * + * char *buf =3D malloc(bytes); + * iov_to_buf(iov, iovcnt, offset, buf, bytes); + * r =3D send(sockfd, buf, bytes, sockflags); + * free(buf); + * + * For iov_send_recv_with_flags() _whole_ area being sent or received + * should be within the iovec, not only beginning of it. + */ +ssize_t iov_send_recv_with_flags(int sockfd, int sockflags, + const struct iovec *iov, + unsigned iov_cnt, size_t offset, + size_t bytes, + bool do_send); + /* * Send/recv data from/to iovec buffers directly * diff --git a/util/iov.c b/util/iov.c index 7e73948f5e..5644e0b73c 100644 --- a/util/iov.c +++ b/util/iov.c @@ -3,6 +3,7 @@ * * Copyright IBM, Corp. 2007, 2008 * Copyright (C) 2010 Red Hat, Inc. + * Copyright (c) 2024 Seagate Technology LLC and/or its Affiliates * * Author(s): * Anthony Liguori @@ -92,7 +93,7 @@ size_t iov_size(const struct iovec *iov, const unsigned i= nt iov_cnt) =20 /* helper function for iov_send_recv() */ static ssize_t -do_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, bool do_send) +do_send_recv(int sockfd, int flags, struct iovec *iov, unsigned iov_cnt, b= ool do_send) { #ifdef CONFIG_POSIX ssize_t ret; @@ -102,8 +103,8 @@ do_send_recv(int sockfd, struct iovec *iov, unsigned io= v_cnt, bool do_send) msg.msg_iovlen =3D iov_cnt; do { ret =3D do_send - ? sendmsg(sockfd, &msg, 0) - : recvmsg(sockfd, &msg, 0); + ? sendmsg(sockfd, &msg, flags) + : recvmsg(sockfd, &msg, flags); } while (ret < 0 && errno =3D=3D EINTR); return ret; #else @@ -114,8 +115,8 @@ do_send_recv(int sockfd, struct iovec *iov, unsigned io= v_cnt, bool do_send) ssize_t off =3D 0; while (i < iov_cnt) { ssize_t r =3D do_send - ? send(sockfd, iov[i].iov_base + off, iov[i].iov_len - off, 0) - : recv(sockfd, iov[i].iov_base + off, iov[i].iov_len - off, 0); + ? send(sockfd, iov[i].iov_base + off, iov[i].iov_len - off, fl= ags) + : recv(sockfd, iov[i].iov_base + off, iov[i].iov_len - off, fl= ags); if (r > 0) { ret +=3D r; off +=3D r; @@ -144,6 +145,13 @@ do_send_recv(int sockfd, struct iovec *iov, unsigned i= ov_cnt, bool do_send) ssize_t iov_send_recv(int sockfd, const struct iovec *_iov, unsigned iov_c= nt, size_t offset, size_t bytes, bool do_send) +{ + return iov_send_recv_with_flags(sockfd, 0, _iov, iov_cnt, offset, byte= s, do_send); +} + +ssize_t iov_send_recv_with_flags(int sockfd, int sockflags, const struct i= ovec *_iov, + unsigned iov_cnt, size_t offset, size_t b= ytes, + bool do_send) { ssize_t total =3D 0; ssize_t ret; @@ -192,11 +200,11 @@ ssize_t iov_send_recv(int sockfd, const struct iovec = *_iov, unsigned iov_cnt, assert(iov[niov].iov_len > tail); orig_len =3D iov[niov].iov_len; iov[niov++].iov_len =3D tail; - ret =3D do_send_recv(sockfd, iov, niov, do_send); + ret =3D do_send_recv(sockfd, sockflags, iov, niov, do_send); /* Undo the changes above before checking for errors */ iov[niov-1].iov_len =3D orig_len; } else { - ret =3D do_send_recv(sockfd, iov, niov, do_send); + ret =3D do_send_recv(sockfd, sockflags, iov, niov, do_send); } if (offset) { iov[0].iov_base -=3D offset; --=20 2.34.1