From nobody Sun Sep 28 16:35:31 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=jan.kiszka@siemens.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; dmarc=pass(p=reject dis=none) header.from=siemens.com ARC-Seal: i=1; a=rsa-sha256; t=1756706914; cv=none; d=zohomail.com; s=zohoarc; b=c0tcOK3DXev/Gij8/zXn3jdI2yjDJAsFRlsjlzgooae1tze+RwsTtOBDyP1JQ9+sFjaRgxosmLnS3OEPHEXtyY92vYAtrDxVlKSagcMoFJthulBfdV6HNrJqGdi2RoMIuJX5vc0YItwsri28OWy666qavPIq7SbXG6poANDWGUE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756706914; 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=nZs+NHAiWdhZBHbplOH5ZYJbBCMnmaq0QyMHL4r+xHM=; b=MfuLD8WfqJV8dRLILlxk1sTAHQOR1dMaXQPrdC/RlINcUvsEdS3tA+FxchYTmvAv8eGKJhSWaI/gbdgk0r5Ua2KJf9Ru5eawxZ4iB1Qvprly+3xVUrn2sAk+yVocjBqDSXhNgPTjTV99bQHwhLEoQrA25n/zFuuJIcU7+9jGz2o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=jan.kiszka@siemens.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; 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 1756706913474512.7882071093533; Sun, 31 Aug 2025 23:08:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1usxgi-00039s-M3; Mon, 01 Sep 2025 02:06:44 -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 1usxge-00037v-Tn for qemu-devel@nongnu.org; Mon, 01 Sep 2025 02:06:40 -0400 Received: from mta-64-228.siemens.flowmailer.net ([185.136.64.228]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1usxgb-0001wx-Vy for qemu-devel@nongnu.org; Mon, 01 Sep 2025 02:06:40 -0400 Received: by mta-64-228.siemens.flowmailer.net with ESMTPSA id 2025090105563123583e3955000207ce for ; Mon, 01 Sep 2025 07:56:31 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=jan.kiszka@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=nZs+NHAiWdhZBHbplOH5ZYJbBCMnmaq0QyMHL4r+xHM=; b=FMLijawcCu81EiztfC9DYKPB+Y8D+oM63QWJYxaUrUIxx2d2RI3pmA+Sd+b8uQ8QCvenRw zguAx+7C0ho+QiqthAquUwAMMsqvNvlxF2mPjyXcH9qWk5g76LgtHXZ6joAhrKDWvnnu3CIj czaFgot9U0oRQ6Gv54K3/vlte8hC2YDTnaAne7iEu14HSSjL6mpt91rGZtZBIyCz7BzUWoMs znt0+R+zSOl6ailpQXb26p+IwiWbiVF71yVnvLkTrtnv4O/wHKYNUVZIvsCb9Fc+NNDCenHC aiGfCtppcrgtXAvyugTj2hprp/Y20CvqQ5KdYRLowJgFcO0G8+DYpC+A==; From: Jan Kiszka To: qemu-devel Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Bin Meng , qemu-block@nongnu.org, Ilias Apalodimas , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v2 6/8] crypto/hmac: Allow to build hmac over multiple qcrypto_gnutls_hmac_bytes[v] calls Date: Mon, 1 Sep 2025 07:56:26 +0200 Message-ID: <2d3539c247a6c323491a3821f0e5b6fc382a4686.1756706188.git.jan.kiszka@siemens.com> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-294854:519-21489:flowmailer 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=185.136.64.228; envelope-from=fm-294854-2025090105563123583e3955000207ce-C3inl0@rts-flowmailer.siemens.com; helo=mta-64-228.siemens.flowmailer.net X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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 jan.kiszka@siemens.com) X-ZM-MESSAGEID: 1756706916498116600 From: Jan Kiszka If the buffers that should be considered for building the hmac are not available at the same time, the current API is unsuitable. Extend it so that passing a NULL pointer as result_len is used as indicator that further buffers will be passed in succeeding calls to qcrypto_gnutls_hmac_bytes[v]. Signed-off-by: Jan Kiszka Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Daniel P. Berrang=C3=A9 --- Cc: "Daniel P. Berrang=C3=A9" --- crypto/hmac-gcrypt.c | 4 +++- crypto/hmac-glib.c | 4 +++- crypto/hmac-gnutls.c | 4 +++- crypto/hmac-nettle.c | 4 +++- include/crypto/hmac.h | 12 ++++++++++++ 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/crypto/hmac-gcrypt.c b/crypto/hmac-gcrypt.c index 5273086eb9..e428d17479 100644 --- a/crypto/hmac-gcrypt.c +++ b/crypto/hmac-gcrypt.c @@ -121,7 +121,9 @@ qcrypto_gcrypt_hmac_bytesv(QCryptoHmac *hmac, return -1; } =20 - if (*resultlen =3D=3D 0) { + if (resultlen =3D=3D NULL) { + return 0; + } else if (*resultlen =3D=3D 0) { *resultlen =3D ret; *result =3D g_new0(uint8_t, *resultlen); } else if (*resultlen !=3D ret) { diff --git a/crypto/hmac-glib.c b/crypto/hmac-glib.c index ea80c8d1b2..b845133a05 100644 --- a/crypto/hmac-glib.c +++ b/crypto/hmac-glib.c @@ -104,7 +104,9 @@ qcrypto_glib_hmac_bytesv(QCryptoHmac *hmac, return -1; } =20 - if (*resultlen =3D=3D 0) { + if (resultlen =3D=3D NULL) { + return 0; + } else if (*resultlen =3D=3D 0) { *resultlen =3D ret; *result =3D g_new0(uint8_t, *resultlen); } else if (*resultlen !=3D ret) { diff --git a/crypto/hmac-gnutls.c b/crypto/hmac-gnutls.c index 822995505c..3c5bcbe80b 100644 --- a/crypto/hmac-gnutls.c +++ b/crypto/hmac-gnutls.c @@ -119,7 +119,9 @@ qcrypto_gnutls_hmac_bytesv(QCryptoHmac *hmac, return -1; } =20 - if (*resultlen =3D=3D 0) { + if (resultlen =3D=3D NULL) { + return 0; + } else if (*resultlen =3D=3D 0) { *resultlen =3D ret; *result =3D g_new0(uint8_t, *resultlen); } else if (*resultlen !=3D ret) { diff --git a/crypto/hmac-nettle.c b/crypto/hmac-nettle.c index dd5b2ab7a1..2cff7931e1 100644 --- a/crypto/hmac-nettle.c +++ b/crypto/hmac-nettle.c @@ -164,7 +164,9 @@ qcrypto_nettle_hmac_bytesv(QCryptoHmac *hmac, } } =20 - if (*resultlen =3D=3D 0) { + if (resultlen =3D=3D NULL) { + return 0; + } else if (*resultlen =3D=3D 0) { *resultlen =3D qcrypto_hmac_alg_map[hmac->alg].len; *result =3D g_new0(uint8_t, *resultlen); } else if (*resultlen !=3D qcrypto_hmac_alg_map[hmac->alg].len) { diff --git a/include/crypto/hmac.h b/include/crypto/hmac.h index da8a1e3ceb..af3d5f8feb 100644 --- a/include/crypto/hmac.h +++ b/include/crypto/hmac.h @@ -90,6 +90,12 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoHmac, qcrypto_hmac_= free) * The memory referenced in @result must be released with a call * to g_free() when no longer required by the caller. * + * If @result_len is set to a NULL pointer, no result will be returned, and + * the hmac object can be used for further invocations of qcrypto_hmac_byt= es() + * or qcrypto_hmac_bytesv() until a non-NULL pointer is provided. This all= ows + * to build the hmac across memory regions that are not available at the s= ame + * time. + * * Returns: * 0 on success, -1 on error */ @@ -123,6 +129,12 @@ int qcrypto_hmac_bytesv(QCryptoHmac *hmac, * The memory referenced in @result must be released with a call * to g_free() when no longer required by the caller. * + * If @result_len is set to a NULL pointer, no result will be returned, and + * the hmac object can be used for further invocations of qcrypto_hmac_byt= es() + * or qcrypto_hmac_bytesv() until a non-NULL pointer is provided. This all= ows + * to build the hmac across memory regions that are not available at the s= ame + * time. + * * Returns: * 0 on success, -1 on error */ --=20 2.43.0