From nobody Sat Nov 15 05:39:10 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=1756020668; cv=none; d=zohomail.com; s=zohoarc; b=MDgo9EaiSNwpLY6ZWky9526TzTcLxoOujJxnXzinZ9awusD59JzNRLWVuGHJ38b8gfZAPy//odNFfwi+gR58X+3tILhkdVnC44phf5IF+DEVGGUrTHF4hpTog4Bb5s7A7NLyxndwM84YnU7TbGfEb6JPU5pplTgEodZ0AMI2N5g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756020668; 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=SIKQRmNfznvZEbxFQHjPE4pGJUEzLHeeKpiYiSJr/po=; b=C9aUjACx5yXpCKDizE8iwsAwt2IO+6jNucELBPzJgCcqp0ClRk2/UL5q3Ak0QNES+CuA/2FGtpbXVKspB2tyYN0fgpAsYG7DmaCMQo+wEeRITmOCmgORb9ZEMpH+S4clOyZTwMKkOalLtVyaN7Cr/NajodR4WDYnCn0/fBslRrk= 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 1756020667787389.90638638186726; Sun, 24 Aug 2025 00:31:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uq59u-0006Sc-0e; Sun, 24 Aug 2025 03:28:58 -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 1uq59r-0006RX-QX for qemu-devel@nongnu.org; Sun, 24 Aug 2025 03:28:56 -0400 Received: from mta-64-225.siemens.flowmailer.net ([185.136.64.225]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uq59k-0005Mm-Km for qemu-devel@nongnu.org; Sun, 24 Aug 2025 03:28:55 -0400 Received: by mta-64-225.siemens.flowmailer.net with ESMTPSA id 202508240718430f8a9a1b4a50f90b60 for ; Sun, 24 Aug 2025 09:18:43 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm2; 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=SIKQRmNfznvZEbxFQHjPE4pGJUEzLHeeKpiYiSJr/po=; b=D6r87iljbI0hUpLzqLUnJrX4lpBpobqoGrdvhfKMRSFqvg3ky1kHXlZBeaLpEf/svJWoq2 gxR+sY+6FuqWaquv5tE2TaAtVk8iOdjgOeQ639MSOrrFHbnYbXHMN9Az+0MuVmzODF9GD7hS 6YifHSkEbVo3Km6x+2XEq8szbpUL+j+bl5ZiOfpBw+Ljmn8+AsZ9ZP8W8zUAqvSsOIumth4G QxQvHKmeBmMgWJNMvL/OPTaR4wRySFL5L7DEb8fx8ihI1zB5dUXSQYNZ4G6nS5AS+VhFUUSG e7C1wUCquzIm2VRLc2tVxLRy1/N8RH5W43HDoNAUcPglzM3tILVvGNUA==; 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 6/8] crypto/hmac: Allow to build hmac over multiple qcrypto_gnutls_hmac_bytes[v] calls Date: Sun, 24 Aug 2025 09:18:38 +0200 Message-ID: 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.225; envelope-from=fm-294854-202508240718430f8a9a1b4a50f90b60-rw1433@rts-flowmailer.siemens.com; helo=mta-64-225.siemens.flowmailer.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.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=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1756020670038116600 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 --- 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