From nobody Sun Nov 24 05:51:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1725891497; cv=none; d=zohomail.com; s=zohoarc; b=IpLoSOgRHsUVWTMz5IK77jCdAdjIhBf9AUXpdCDabtqNjC1pjJci14uq8awBzS+cKXx6NzKMGs4FmRI5feZ8RijsuYxYFdQvx9TsAgK51MfUMOR4i2E6y8e5KG7efIavFAQHDsUsERN6pN47a06bNsZwJVGRzQZhitmhNKooeM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725891497; 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=VHge9MB3dqWUcYgb0KJrksuENWfix4LIAEKGj69pBVM=; b=ey22WnRwWgO9ABiQ3VSPmoWuRVJLSQy2C3ajzT4VfcrkigiPx4oqOA0viKN6dILZPvT33L5ccvXes44Y4IBLEP6murNCFV9zav1ZIM/Hj1cWXs6NxNS0mBGruJugukGRQisuYM0fjRzxuM/uzpD8TLI9aAjDf+Fp4iD7U5ikdzw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1725891497586938.9471866510075; Mon, 9 Sep 2024 07:18:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snfCU-0007to-Ap; Mon, 09 Sep 2024 10:17:06 -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 1snfCS-0007oS-KV for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1snfCM-0003HL-RF for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:04 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-283-FJZMl-bkPs2mGh1p-0zCLw-1; Mon, 09 Sep 2024 10:16:54 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F09051955DD2; Mon, 9 Sep 2024 14:16:51 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.212]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 317611956054; Mon, 9 Sep 2024 14:16:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725891417; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VHge9MB3dqWUcYgb0KJrksuENWfix4LIAEKGj69pBVM=; b=Oxu6g4s3os746FuS9kcGlXvCZUeXPnXkDgmK3JVlKrg3XkKBsrNXy8O05mz+zoqclC77Dn +sbBZRWtJn5h9yWUsFds2HkqN4RAI9O85Cx2uNGHdnH1rJsjrU6p1QTsM8cUaw3ZJGJtnt QFMWFqDtaN3EqSSz+gSnidjvvB9lCOg= X-MC-Unique: FJZMl-bkPs2mGh1p-0zCLw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hyman Huang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Hanna Reitz , qemu-block@nongnu.org, qemu-stable@nongnu.org, Laurent Vivier , Thomas Huth , Paolo Bonzini , Kevin Wolf , Markus Armbruster Subject: [PULL 01/10] iotests: fix expected output from gnutls Date: Mon, 9 Sep 2024 15:16:26 +0100 Message-ID: <20240909141635.1459701-2-berrange@redhat.com> In-Reply-To: <20240909141635.1459701-1-berrange@redhat.com> References: <20240909141635.1459701-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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 @redhat.com) X-ZM-MESSAGEID: 1725891499564116600 Error reporting from gnutls was improved by: commit 57941c9c86357a6a642f9ee3279d881df4043b6d Author: Daniel P. Berrang=C3=A9 Date: Fri Mar 15 14:07:58 2024 +0000 crypto: push error reporting into TLS session I/O APIs This has the effect of changing the output from one of the NBD tests. Reported-by: Thomas Huth Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/qemu-iotests/233.out | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/qemu-iotests/233.out b/tests/qemu-iotests/233.out index 1910f7df20..d498d55e0e 100644 --- a/tests/qemu-iotests/233.out +++ b/tests/qemu-iotests/233.out @@ -69,8 +69,8 @@ read 1048576/1048576 bytes at offset 1048576 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 =3D=3D check TLS with authorization =3D=3D -qemu-img: Could not open 'driver=3Dnbd,host=3D127.0.0.1,port=3DPORT,tls-cr= eds=3Dtls0': Failed to read option reply: Cannot read from TLS channel: Sof= tware caused connection abort -qemu-img: Could not open 'driver=3Dnbd,host=3D127.0.0.1,port=3DPORT,tls-cr= eds=3Dtls0': Failed to read option reply: Cannot read from TLS channel: Sof= tware caused connection abort +qemu-img: Could not open 'driver=3Dnbd,host=3D127.0.0.1,port=3DPORT,tls-cr= eds=3Dtls0': Failed to read option reply: Cannot read from TLS channel: The= TLS connection was non-properly terminated. +qemu-img: Could not open 'driver=3Dnbd,host=3D127.0.0.1,port=3DPORT,tls-cr= eds=3Dtls0': Failed to read option reply: Cannot read from TLS channel: The= TLS connection was non-properly terminated. =20 =3D=3D check TLS fail over UNIX with no hostname =3D=3D qemu-img: Could not open 'driver=3Dnbd,path=3DSOCK_DIR/qemu-nbd.sock,tls-c= reds=3Dtls0': No hostname for certificate validation @@ -103,14 +103,14 @@ qemu-img: Could not open 'driver=3Dnbd,path=3DSOCK_DI= R/qemu-nbd.sock,tls-creds=3Dtls0' qemu-nbd: TLS handshake failed: The TLS connection was non-properly termin= ated. =20 =3D=3D final server log =3D=3D -qemu-nbd: option negotiation failed: Failed to read opts magic: Cannot rea= d from TLS channel: Software caused connection abort -qemu-nbd: option negotiation failed: Failed to read opts magic: Cannot rea= d from TLS channel: Software caused connection abort +qemu-nbd: option negotiation failed: Failed to read opts magic: Cannot rea= d from TLS channel: The TLS connection was non-properly terminated. +qemu-nbd: option negotiation failed: Failed to read opts magic: Cannot rea= d from TLS channel: The TLS connection was non-properly terminated. qemu-nbd: option negotiation failed: Verify failed: No certificate was fou= nd. qemu-nbd: option negotiation failed: Verify failed: No certificate was fou= nd. qemu-nbd: option negotiation failed: TLS x509 authz check for DISTINGUISHE= D-NAME is denied qemu-nbd: option negotiation failed: TLS x509 authz check for DISTINGUISHE= D-NAME is denied -qemu-nbd: option negotiation failed: Failed to read opts magic: Cannot rea= d from TLS channel: Software caused connection abort -qemu-nbd: option negotiation failed: Failed to read opts magic: Cannot rea= d from TLS channel: Software caused connection abort +qemu-nbd: option negotiation failed: Failed to read opts magic: Cannot rea= d from TLS channel: The TLS connection was non-properly terminated. +qemu-nbd: option negotiation failed: Failed to read opts magic: Cannot rea= d from TLS channel: The TLS connection was non-properly terminated. qemu-nbd: option negotiation failed: TLS handshake failed: An illegal para= meter has been received. qemu-nbd: option negotiation failed: TLS handshake failed: An illegal para= meter has been received. *** done --=20 2.45.2 From nobody Sun Nov 24 05:51:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1725891483; cv=none; d=zohomail.com; s=zohoarc; b=O6KmRD3Ws/5fqML6AYxPXvxcfgg4a87+n51M8TygX8EA0fxkkNn3E0iphOvkKN6z1jVwGTyNpeMDP6CNe8JKuVuR7792alGrjPv3LYNyWx41KoZjwIND1YpS4aDGuSnhBSksTDxKPK/ZQC/KLRnU62IbhRQYWVsrCk8J9gGIJ1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725891483; 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=fPO4I0oxWW77zveyLGOcTMiBWgRiSGpWO8LL8G9uTno=; b=exZHrCtLHTneXafCocYuW4Z8asGTq49CmccQoqla71yUWmBcRz22NOPuxNmUyYNtVKk9T67ikuyalsbwaus6P9e8+uSRGAbdMVqRgITpH8Ezd4ZHlRQJTrn2eAHzjAeMyNVzx8sqt15OP+br3hZcKpE8U3Gj+hvYPyrr9z8GzDY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172589148338057.29519456024093; Mon, 9 Sep 2024 07:18:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snfCU-0007u2-Bw; Mon, 09 Sep 2024 10:17:06 -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 1snfCT-0007s2-KW for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1snfCR-0003Ix-Ps for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:05 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-526-ilg3g7raMgmWJL1ADe6MUw-1; Mon, 09 Sep 2024 10:16:59 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7C4A01953965; Mon, 9 Sep 2024 14:16:57 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.212]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 86A4C1955F45; Mon, 9 Sep 2024 14:16:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725891423; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fPO4I0oxWW77zveyLGOcTMiBWgRiSGpWO8LL8G9uTno=; b=iPrLjLFYMIo8Ra5zA7EvKfmzf//GDZPQ/lWCKr39Sw+l8tAdaF0R0QXLjehaAGfdavrlYn PzgrHLdkIoM/G7Z8Jltr4iqG0a0W35aShEJTCKOiwxH4Oq8iMncvPyR6SIZJH3uEJLpJFx S8HBTxj2vvP5cGZts0nW9qMvNS1P5Ww= X-MC-Unique: ilg3g7raMgmWJL1ADe6MUw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hyman Huang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Hanna Reitz , qemu-block@nongnu.org, qemu-stable@nongnu.org, Laurent Vivier , Thomas Huth , Paolo Bonzini , Kevin Wolf , Markus Armbruster , Tiago Pasqualini Subject: [PULL 02/10] crypto: run qcrypto_pbkdf2_count_iters in a new thread Date: Mon, 9 Sep 2024 15:16:27 +0100 Message-ID: <20240909141635.1459701-3-berrange@redhat.com> In-Reply-To: <20240909141635.1459701-1-berrange@redhat.com> References: <20240909141635.1459701-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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 @redhat.com) X-ZM-MESSAGEID: 1725891485442116600 From: Tiago Pasqualini CPU time accounting in the kernel has been demonstrated to have a sawtooth pattern[1][2]. This can cause the getrusage system call to not be as accurate as we are expecting, which can cause this calculation to stall. The kernel discussions shows that this inaccuracy happens when CPU time gets big enough, so this patch changes qcrypto_pbkdf2_count_iters to run in a fresh thread to avoid this inaccuracy. It also adds a sanity check to fail the process if CPU time is not accounted. [1] https://lore.kernel.org/lkml/159231011694.16989.16351419333851309713.ti= p-bot2@tip-bot2/ [2] https://lore.kernel.org/lkml/20221226031010.4079885-1-maxing.lan@byteda= nce.com/t/#m1c7f2fdc0ea742776a70fd1aa2a2e414c437f534 Resolves: #2398 Signed-off-by: Tiago Pasqualini Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/pbkdf.c | 53 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/crypto/pbkdf.c b/crypto/pbkdf.c index 8d198c152c..d1c06ef3ed 100644 --- a/crypto/pbkdf.c +++ b/crypto/pbkdf.c @@ -19,6 +19,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/thread.h" #include "qapi/error.h" #include "crypto/pbkdf.h" #ifndef _WIN32 @@ -85,12 +86,28 @@ static int qcrypto_pbkdf2_get_thread_cpu(unsigned long = long *val_ms, #endif } =20 -uint64_t qcrypto_pbkdf2_count_iters(QCryptoHashAlgorithm hash, - const uint8_t *key, size_t nkey, - const uint8_t *salt, size_t nsalt, - size_t nout, - Error **errp) +typedef struct CountItersData { + QCryptoHashAlgorithm hash; + const uint8_t *key; + size_t nkey; + const uint8_t *salt; + size_t nsalt; + size_t nout; + uint64_t iterations; + Error **errp; +} CountItersData; + +static void *threaded_qcrypto_pbkdf2_count_iters(void *data) { + CountItersData *iters_data =3D (CountItersData *) data; + QCryptoHashAlgorithm hash =3D iters_data->hash; + const uint8_t *key =3D iters_data->key; + size_t nkey =3D iters_data->nkey; + const uint8_t *salt =3D iters_data->salt; + size_t nsalt =3D iters_data->nsalt; + size_t nout =3D iters_data->nout; + Error **errp =3D iters_data->errp; + uint64_t ret =3D -1; g_autofree uint8_t *out =3D g_new(uint8_t, nout); uint64_t iterations =3D (1 << 15); @@ -114,7 +131,10 @@ uint64_t qcrypto_pbkdf2_count_iters(QCryptoHashAlgorit= hm hash, =20 delta_ms =3D end_ms - start_ms; =20 - if (delta_ms > 500) { + if (delta_ms =3D=3D 0) { /* sanity check */ + error_setg(errp, "Unable to get accurate CPU usage"); + goto cleanup; + } else if (delta_ms > 500) { break; } else if (delta_ms < 100) { iterations =3D iterations * 10; @@ -129,5 +149,24 @@ uint64_t qcrypto_pbkdf2_count_iters(QCryptoHashAlgorit= hm hash, =20 cleanup: memset(out, 0, nout); - return ret; + iters_data->iterations =3D ret; + return NULL; +} + +uint64_t qcrypto_pbkdf2_count_iters(QCryptoHashAlgorithm hash, + const uint8_t *key, size_t nkey, + const uint8_t *salt, size_t nsalt, + size_t nout, + Error **errp) +{ + CountItersData data =3D { + hash, key, nkey, salt, nsalt, nout, 0, errp + }; + QemuThread thread; + + qemu_thread_create(&thread, "pbkdf2", threaded_qcrypto_pbkdf2_count_it= ers, + &data, QEMU_THREAD_JOINABLE); + qemu_thread_join(&thread); + + return data.iterations; } --=20 2.45.2 From nobody Sun Nov 24 05:51:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1725891493; cv=none; d=zohomail.com; s=zohoarc; b=AnqCua0RluB9NytpT1xj79Nc83MUA5PMk43OpzIPiim9QYmxK5UTG6maUR7C1s5G3ibG2pSAUw5/Ske4ZXDHJRtxGomNi72yu7/lR1ujiTedzIq66YBp4YMZNIId2JV3lptDOciA0I5Wjq+6ghbPw2nqdopF+Z8gZxNScaWrAsg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725891493; 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=fzSgkZRTe0ukTEfrZ3XtCYZUuRb9VVr70aYi3iC5M04=; b=XdBeyliZhTWCivpdmkSzEzQDe6haXnxfBlefvNy9cIdXr8Qg2S4ia/YBPJ/SwyQ0yoeP8oEmcyG6CZUEuX6Krx3ioQuEOFf/qL9/cqviTH7o5J9PImE7LwGekTErwCb3UtpqlmLkhCkMubsr3S1Xr7lOwr8p1IUsw6tjs+dTMSY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1725891493082703.3519901773832; Mon, 9 Sep 2024 07:18:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snfCr-0000g7-0f; Mon, 09 Sep 2024 10:17:29 -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 1snfCa-0008NS-JC for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1snfCZ-0003Ki-8E for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:12 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-160-k08X1KiJMVy1ZsjWQDBikg-1; Mon, 09 Sep 2024 10:17:03 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6FE27197701C; Mon, 9 Sep 2024 14:17:02 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.212]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C72391956054; Mon, 9 Sep 2024 14:16:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725891429; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fzSgkZRTe0ukTEfrZ3XtCYZUuRb9VVr70aYi3iC5M04=; b=Z+fNrwo707i69nL8IF9eAgyz9KVC51SnNUUsahM1ScZUhJfvuj/fXjYZkEvuESLMr0pWEI ZwJPQIkLNipg5/hp+UDHEsBDXm+Gsakz4OUBfUB8GakOY6RR7AE4JC6YrE3qPAsCogrwPq 47HZ6ULhB+aesx3WOB2mVXajnH8saIQ= X-MC-Unique: k08X1KiJMVy1ZsjWQDBikg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hyman Huang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Hanna Reitz , qemu-block@nongnu.org, qemu-stable@nongnu.org, Laurent Vivier , Thomas Huth , Paolo Bonzini , Kevin Wolf , Markus Armbruster Subject: [PULL 03/10] crypto: check gnutls & gcrypt support the requested pbkdf hash Date: Mon, 9 Sep 2024 15:16:28 +0100 Message-ID: <20240909141635.1459701-4-berrange@redhat.com> In-Reply-To: <20240909141635.1459701-1-berrange@redhat.com> References: <20240909141635.1459701-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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 @redhat.com) X-ZM-MESSAGEID: 1725891493453116600 Both gnutls and gcrypt can be configured to exclude support for certain algorithms via a runtime check against system crypto policies. Thus it is not sufficient to have a compile time test for hash support in their pbkdf implementations. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/pbkdf-gcrypt.c | 2 +- crypto/pbkdf-gnutls.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto/pbkdf-gcrypt.c b/crypto/pbkdf-gcrypt.c index a8d8e64f4d..bc0719c831 100644 --- a/crypto/pbkdf-gcrypt.c +++ b/crypto/pbkdf-gcrypt.c @@ -33,7 +33,7 @@ bool qcrypto_pbkdf2_supports(QCryptoHashAlgorithm hash) case QCRYPTO_HASH_ALG_SHA384: case QCRYPTO_HASH_ALG_SHA512: case QCRYPTO_HASH_ALG_RIPEMD160: - return true; + return qcrypto_hash_supports(hash); default: return false; } diff --git a/crypto/pbkdf-gnutls.c b/crypto/pbkdf-gnutls.c index 2dfbbd382c..911b565bea 100644 --- a/crypto/pbkdf-gnutls.c +++ b/crypto/pbkdf-gnutls.c @@ -33,7 +33,7 @@ bool qcrypto_pbkdf2_supports(QCryptoHashAlgorithm hash) case QCRYPTO_HASH_ALG_SHA384: case QCRYPTO_HASH_ALG_SHA512: case QCRYPTO_HASH_ALG_RIPEMD160: - return true; + return qcrypto_hash_supports(hash); default: return false; } --=20 2.45.2 From nobody Sun Nov 24 05:51:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1725891621; cv=none; d=zohomail.com; s=zohoarc; b=VDNn7EdOs5aSgd7VzngEnKL2IsXAkctcRqC1Q5eJhmg481RzHIopOKXesvc1fTkJX4vTi1YZ6STbE1B+ayVh6E5wxWGl5eBr5FtBDFhCawAYUQkFpVbEXBxTwgi2G+aA5TLzlhNyg1/5u4WBNcNXhZViIKL9GEQGu7ddztE/lcQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725891621; 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=zIFpkpAxeAzkjaGmQ0Ee0RDU0FU/iIkRoY2HTVLtNNY=; b=nY+1SpMqMBAOO4ubqP80w1Dynke1lo5B1TshbQz8XTltaVKhqxWhOIfNqwNJQFNe27xOrwRIlz/ImA4l2oFq8+wxrMC2rBCWpkx4QhIGCFY8aF7pl//rvaAO69uqfJvB/Df32KxfciGuOf7tjjy0mCdEE42V9BMFDZlWJtDXCGY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1725891621476218.22796532669986; Mon, 9 Sep 2024 07:20:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snfCx-0001OL-LU; Mon, 09 Sep 2024 10:17:35 -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 1snfCf-0000P1-Pi for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1snfCd-0003LF-07 for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:17 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-266-Mg7ODw25NeSJIZdKRzgA6Q-1; Mon, 09 Sep 2024 10:17:10 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 19F07196CE18; Mon, 9 Sep 2024 14:17:09 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.212]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E8F7B1956054; Mon, 9 Sep 2024 14:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725891433; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zIFpkpAxeAzkjaGmQ0Ee0RDU0FU/iIkRoY2HTVLtNNY=; b=f7zmu70H4G3+n/+CsPOzTV2nh1Mga3znticmVnEav79Mreo99Gk64WAfOWkxmSgdmPiLTc ZF/+wYmYClf5zr1nQ9g6TbiYoI770jPxmVY4k0q8OgrXyWaRjN8zfuYNGqREOAKErxUlJa rA3Fug2ozUviMalINq29BkhMF1lRgTE= X-MC-Unique: Mg7ODw25NeSJIZdKRzgA6Q-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hyman Huang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Hanna Reitz , qemu-block@nongnu.org, qemu-stable@nongnu.org, Laurent Vivier , Thomas Huth , Paolo Bonzini , Kevin Wolf , Markus Armbruster Subject: [PULL 04/10] tests/unit: always build the pbkdf crypto unit test Date: Mon, 9 Sep 2024 15:16:29 +0100 Message-ID: <20240909141635.1459701-5-berrange@redhat.com> In-Reply-To: <20240909141635.1459701-1-berrange@redhat.com> References: <20240909141635.1459701-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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 @redhat.com) X-ZM-MESSAGEID: 1725891622133116600 The meson rules were excluding the pbkdf crypto test when gnutls was the crypto backend. It was then excluded again in #if statements in the test file. Rather than update these conditions, remove them all, and use the result of the qcrypto_pbkdf_supports() function to determine whether to skip test registration. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/unit/meson.build | 4 +--- tests/unit/test-crypto-pbkdf.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/unit/meson.build b/tests/unit/meson.build index 490ab8182d..972d792883 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -121,9 +121,7 @@ if have_block if config_host_data.get('CONFIG_REPLICATION') tests +=3D {'test-replication': [testblock]} endif - if nettle.found() or gcrypt.found() - tests +=3D {'test-crypto-pbkdf': [io]} - endif + tests +=3D {'test-crypto-pbkdf': [io]} endif =20 if have_system diff --git a/tests/unit/test-crypto-pbkdf.c b/tests/unit/test-crypto-pbkdf.c index 43c417f6b4..241e1c2cf0 100644 --- a/tests/unit/test-crypto-pbkdf.c +++ b/tests/unit/test-crypto-pbkdf.c @@ -25,8 +25,7 @@ #include #endif =20 -#if ((defined(CONFIG_NETTLE) || defined(CONFIG_GCRYPT)) && \ - (defined(_WIN32) || defined(RUSAGE_THREAD))) +#if defined(_WIN32) || defined(RUSAGE_THREAD) #include "crypto/pbkdf.h" =20 typedef struct QCryptoPbkdfTestData QCryptoPbkdfTestData; @@ -394,7 +393,7 @@ static void test_pbkdf(const void *opaque) } =20 =20 -static void test_pbkdf_timing(void) +static void test_pbkdf_timing_sha256(void) { uint8_t key[32]; uint8_t salt[32]; @@ -422,14 +421,18 @@ int main(int argc, char **argv) g_assert(qcrypto_init(NULL) =3D=3D 0); =20 for (i =3D 0; i < G_N_ELEMENTS(test_data); i++) { + if (!qcrypto_pbkdf2_supports(test_data[i].hash)) { + continue; + } + if (!test_data[i].slow || g_test_slow()) { g_test_add_data_func(test_data[i].path, &test_data[i], test_pb= kdf); } } =20 - if (g_test_slow()) { - g_test_add_func("/crypt0/pbkdf/timing", test_pbkdf_timing); + if (g_test_slow() && qcrypto_pbkdf2_supports(QCRYPTO_HASH_ALG_SHA256))= { + g_test_add_func("/crypt0/pbkdf/timing/sha256", test_pbkdf_timing_s= ha256); } =20 return g_test_run(); --=20 2.45.2 From nobody Sun Nov 24 05:51:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1725891586; cv=none; d=zohomail.com; s=zohoarc; b=IpuVrMHE0yntAWLmIsPyKpCok0PAafz7kPKgPwFr8rJOHnOyBV8loXANk9m0Bzc/xN1UyCOMzN+uJ4I9MXhAHFIGuyHsNvlxr0NkaZELVaDF1Jd5Oq6QKs/SqjuEZcZ4AIkfYjU47k92oLfbasjVTBZOm6H+u6mT4qD9ySP+6JM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725891586; 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=UPFnH22MPczYMVc+yW9UC879PuAziGUI3OWBh5A/gVI=; b=jD+7nztNg0e8qyPh3Q/zomzQSE0o+IC44zq2BAwszEsLCnXdLIQklAMDJOMigFQOeXYur2niBlBhrFHMoZK/aVjAZOWcPADjVsz5GAFOa2EbCIotnrJr56XTKpJrmuvRhWN8rDpqwfa9L++SVz3SFSF6pD1dAXgAWXRv++yowYM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1725891586204240.92864498936865; Mon, 9 Sep 2024 07:19:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snfCy-0001WP-Hw; Mon, 09 Sep 2024 10:17:36 -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 1snfCl-0000Zo-3H for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1snfCj-0003ML-MN for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:22 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-255-nlf3zoijOFCBj1cZTnmZOA-1; Mon, 09 Sep 2024 10:17:15 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7C1411944D46; Mon, 9 Sep 2024 14:17:13 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.212]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 41BC71955F45; Mon, 9 Sep 2024 14:17:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725891440; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UPFnH22MPczYMVc+yW9UC879PuAziGUI3OWBh5A/gVI=; b=Ejvh85wlz6adn0ut3oko7v73eyLFToDYnoDp+WQmNcXrDIxe1LcQfbglv3ppC+8j1To5oy AEtw0xrC7DB54Qb78JPb+3CZbzuKDVqol96VdthRp6ePFtdK1XYm9LMXeCrZed9unp/J9N VU11nCray2Yp84uj20dIM53Zs89NJi8= X-MC-Unique: nlf3zoijOFCBj1cZTnmZOA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hyman Huang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Hanna Reitz , qemu-block@nongnu.org, qemu-stable@nongnu.org, Laurent Vivier , Thomas Huth , Paolo Bonzini , Kevin Wolf , Markus Armbruster Subject: [PULL 05/10] tests/unit: build pbkdf test on macOS Date: Mon, 9 Sep 2024 15:16:30 +0100 Message-ID: <20240909141635.1459701-6-berrange@redhat.com> In-Reply-To: <20240909141635.1459701-1-berrange@redhat.com> References: <20240909141635.1459701-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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 @redhat.com) X-ZM-MESSAGEID: 1725891588150116600 Add CONFIG_DARWIN to the pbkdf test build condition, since we have a way to measure CPU time on this platform since commit bf98afc75efedf1. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/unit/test-crypto-pbkdf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test-crypto-pbkdf.c b/tests/unit/test-crypto-pbkdf.c index 241e1c2cf0..39264cb662 100644 --- a/tests/unit/test-crypto-pbkdf.c +++ b/tests/unit/test-crypto-pbkdf.c @@ -25,7 +25,7 @@ #include #endif =20 -#if defined(_WIN32) || defined(RUSAGE_THREAD) +#if defined(_WIN32) || defined(RUSAGE_THREAD) || defined(CONFIG_DARWNI) #include "crypto/pbkdf.h" =20 typedef struct QCryptoPbkdfTestData QCryptoPbkdfTestData; --=20 2.45.2 From nobody Sun Nov 24 05:51:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1725891641; cv=none; d=zohomail.com; s=zohoarc; b=kFalZ2Rh9Emb+2AZ06P6dexTY7uVO2Tro53ml2iz0EXShwB795dKkUYUAoI+O2VQvNGCuqxyDNkz7SfSZXXprCSNqsq/dDHqKxidtYUassvxRbkTXOvKbh89szuLWPE8TBBXBOiz4qqK/LKYiEPXqj80F8TprE4wg++IKcZMios= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725891641; 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=YFAkaiR0fjrqA2GqckLaPVwtf3hYK4UWq/V1KGW3Uok=; b=QICxmMry0gAnbz5fCZqg7g/uu3/lFhAuRCTyGxhU3Onbv6GT4TGnIhlTp06t7jBndbE3lz2eHhTgIA6ZS/IFhpdbZnC2c3fWvIQRF5pJWPfNKepiKBt0j1GnIKQH9CtCWc4SGVBRIZx1Ng8vLrnU4IFXN9l7y7/1IFdowhdmsVY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1725891641907151.07481469310676; Mon, 9 Sep 2024 07:20:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snfCy-0001VR-Fj; Mon, 09 Sep 2024 10:17:36 -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 1snfCr-0000nC-2H for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1snfCo-0003MY-CW for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:28 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-244-IVSuy0fjOkCAaptoHpqThw-1; Mon, 09 Sep 2024 10:17:20 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DF5F91944DDF; Mon, 9 Sep 2024 14:17:18 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.212]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CBEFC1956054; Mon, 9 Sep 2024 14:17:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725891441; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YFAkaiR0fjrqA2GqckLaPVwtf3hYK4UWq/V1KGW3Uok=; b=M/G1ur00LpdsMBswe7sC2e+pjhAfh8jJayA0WgLw2WMgMVhT6Yi9q6ylEnaBxkIaUCpVoU 4AoRCxm3NhDcPqqJ8uNUf72wIU4nQJB/gltnECuDrJk3o4tDItR870QFmGq5mE5fCuqdhk nU818fNm/5trsc7Oa5AGLZNKwqk1IQI= X-MC-Unique: IVSuy0fjOkCAaptoHpqThw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hyman Huang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Hanna Reitz , qemu-block@nongnu.org, qemu-stable@nongnu.org, Laurent Vivier , Thomas Huth , Paolo Bonzini , Kevin Wolf , Markus Armbruster , Peter Maydell Subject: [PULL 06/10] crypto: avoid leak of ctx when bad cipher mode is given Date: Mon, 9 Sep 2024 15:16:31 +0100 Message-ID: <20240909141635.1459701-7-berrange@redhat.com> In-Reply-To: <20240909141635.1459701-1-berrange@redhat.com> References: <20240909141635.1459701-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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 @redhat.com) X-ZM-MESSAGEID: 1725891642103116600 Fixes: Coverity CID 1546884 Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/cipher-nettle.c.inc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crypto/cipher-nettle.c.inc b/crypto/cipher-nettle.c.inc index 42b39e18a2..766de036ba 100644 --- a/crypto/cipher-nettle.c.inc +++ b/crypto/cipher-nettle.c.inc @@ -734,16 +734,19 @@ static QCryptoCipher *qcrypto_cipher_ctx_new(QCryptoC= ipherAlgorithm alg, #ifdef CONFIG_CRYPTO_SM4 case QCRYPTO_CIPHER_ALG_SM4: { - QCryptoNettleSm4 *ctx =3D g_new0(QCryptoNettleSm4, 1); + QCryptoNettleSm4 *ctx; + const QCryptoCipherDriver *drv; =20 switch (mode) { case QCRYPTO_CIPHER_MODE_ECB: - ctx->base.driver =3D &qcrypto_nettle_sm4_driver_ecb; + drv =3D &qcrypto_nettle_sm4_driver_ecb; break; default: goto bad_cipher_mode; } =20 + ctx =3D g_new0(QCryptoNettleSm4, 1); + ctx->base.driver =3D drv; sm4_set_encrypt_key(&ctx->key[0], key); sm4_set_decrypt_key(&ctx->key[1], key); =20 --=20 2.45.2 From nobody Sun Nov 24 05:51:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1725891572; cv=none; d=zohomail.com; s=zohoarc; b=QEeudAGNuhrnIG5ywmtdkW2kWg49UDSiUqeYTRAi3cmzwCtpgaUYpQmP3/Uc85kItWboLb4mxBlEGdixhdGBZ9mfcQf1TrNhdqYLMPHEzP7gRQLsbbS+yma2VABClcOWPD1xraSGsxL9WqgnwNkn1R/vWnwWC7XD04+Ds4zX5Oo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725891572; 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=Nalh1+79GlyeQ+YYTpcXp5ltQDqfxzrzl6n63Cas7OU=; b=drE34M38qN+bGv4BINaBv7d/zG2PFo/JQZQ6EH0tqZkgw8PnpkcRmMOV6THisYlvRFHXgXKcbdzE9pttse6IK6rnayPes/4wSpSP8bVs7O/LNCDI3tizsDEqVVLerxmYp2DCps3iVBlMCQUptK33vzCuBiZBTIWg6vbSHsxebMM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1725891572136667.5067007126355; Mon, 9 Sep 2024 07:19:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snfCy-0001So-6N; Mon, 09 Sep 2024 10:17:36 -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 1snfCs-0000zY-Rq for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1snfCr-0003NS-6N for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:30 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-589-ePW6mmoSP0WjR99pT7ybpA-1; Mon, 09 Sep 2024 10:17:25 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 995871953965; Mon, 9 Sep 2024 14:17:23 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.212]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2D0491956054; Mon, 9 Sep 2024 14:17:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725891448; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Nalh1+79GlyeQ+YYTpcXp5ltQDqfxzrzl6n63Cas7OU=; b=hybcNdNpXZvwYUPtzbcwlKlnU1G30fO6bQ8P+ZiiBIQcofBrf5YtgLe/ibMU1/FQ0lPYTa NjCTiW89/bheKwnqfk21KbpnkKclAhcDPhZtgePw3L3ESfWyPBbyrlq8UJGMSyKEmQexQu XP+khO8B3h3yxEC25P3LrCo/lcpdLgg= X-MC-Unique: ePW6mmoSP0WjR99pT7ybpA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hyman Huang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Hanna Reitz , qemu-block@nongnu.org, qemu-stable@nongnu.org, Laurent Vivier , Thomas Huth , Paolo Bonzini , Kevin Wolf , Markus Armbruster , Peter Maydell Subject: [PULL 07/10] crypto: use consistent error reporting pattern for unsupported cipher modes Date: Mon, 9 Sep 2024 15:16:32 +0100 Message-ID: <20240909141635.1459701-8-berrange@redhat.com> In-Reply-To: <20240909141635.1459701-1-berrange@redhat.com> References: <20240909141635.1459701-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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 @redhat.com) X-ZM-MESSAGEID: 1725891573885116600 Not all paths in qcrypto_cipher_ctx_new() were correctly distinguishing between valid user input for cipher mode (which should report a user facing error), vs program logic errors (which should assert). Reported-by: Peter Maydell Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/cipher-nettle.c.inc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/crypto/cipher-nettle.c.inc b/crypto/cipher-nettle.c.inc index 766de036ba..2654b439c1 100644 --- a/crypto/cipher-nettle.c.inc +++ b/crypto/cipher-nettle.c.inc @@ -525,8 +525,10 @@ static QCryptoCipher *qcrypto_cipher_ctx_new(QCryptoCi= pherAlgorithm alg, case QCRYPTO_CIPHER_MODE_CTR: drv =3D &qcrypto_nettle_des_driver_ctr; break; - default: + case QCRYPTO_CIPHER_MODE_XTS: goto bad_cipher_mode; + default: + g_assert_not_reached(); } =20 ctx =3D g_new0(QCryptoNettleDES, 1); @@ -551,8 +553,10 @@ static QCryptoCipher *qcrypto_cipher_ctx_new(QCryptoCi= pherAlgorithm alg, case QCRYPTO_CIPHER_MODE_CTR: drv =3D &qcrypto_nettle_des3_driver_ctr; break; - default: + case QCRYPTO_CIPHER_MODE_XTS: goto bad_cipher_mode; + default: + g_assert_not_reached(); } =20 ctx =3D g_new0(QCryptoNettleDES3, 1); @@ -663,8 +667,10 @@ static QCryptoCipher *qcrypto_cipher_ctx_new(QCryptoCi= pherAlgorithm alg, case QCRYPTO_CIPHER_MODE_CTR: drv =3D &qcrypto_nettle_cast128_driver_ctr; break; - default: + case QCRYPTO_CIPHER_MODE_XTS: goto bad_cipher_mode; + default: + g_assert_not_reached(); } =20 ctx =3D g_new0(QCryptoNettleCAST128, 1); @@ -741,8 +747,12 @@ static QCryptoCipher *qcrypto_cipher_ctx_new(QCryptoCi= pherAlgorithm alg, case QCRYPTO_CIPHER_MODE_ECB: drv =3D &qcrypto_nettle_sm4_driver_ecb; break; - default: + case QCRYPTO_CIPHER_MODE_CBC: + case QCRYPTO_CIPHER_MODE_CTR: + case QCRYPTO_CIPHER_MODE_XTS: goto bad_cipher_mode; + default: + g_assert_not_reached(); } =20 ctx =3D g_new0(QCryptoNettleSm4, 1); --=20 2.45.2 From nobody Sun Nov 24 05:51:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1725891502; cv=none; d=zohomail.com; s=zohoarc; b=XPfkJaTdudl880dG6gRD1ih339MYCovREcqn/Cww5AoEuhKk1dOH3NxILuBfl4bjVsuQ5DjTT+lyci/2ZDyDbo4bNZfQ3vwq+3xXFFwO5iv+sGCD/2XhlYpJHPSkY8xJP9CfBZJLwPIl+ymAOD9x0ZQq6IsYcInkqy3vHwabbh0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725891502; 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=Cx43kZJQxvli9IxV/D9S1CP+gks4gZY+IOVuSazDV2k=; b=laIAGJPI+TROrj4kOVAtU669oO3nPKOGSS7ZsmYgg9BdC8+GZvjMiq4ylkFvAhNHIEeR9aj+d2mIfjCWWeMSHUCHZ0mvg0pMC/WG3LV+eTTfBPU/X15Lc/6astT2a99HRdpUeVA3aAChCAF5VaqmmPyYroc8BWDvLaIxpf9CvwM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1725891502546343.1486791312659; Mon, 9 Sep 2024 07:18:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snfD6-0001mP-Mg; Mon, 09 Sep 2024 10:17:49 -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 1snfCy-0001YH-Mb for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1snfCw-0003OV-9j for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:36 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-kzcwK9LPPwuO_h1VFEUxHg-1; Mon, 09 Sep 2024 10:17:29 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4BC121955EA2; Mon, 9 Sep 2024 14:17:28 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.212]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A46981955F45; Mon, 9 Sep 2024 14:17:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725891453; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Cx43kZJQxvli9IxV/D9S1CP+gks4gZY+IOVuSazDV2k=; b=dnfTnanPIKnmjcPr++8zpq/QetAdLNKpHcl9jaebaz4vpwJYzVKsfkidfqhq8aUhvuI/KE 2c493AJzOuaH1FLGSXeTAG9WqkaD8k3GqOq5SxiZPO3XZ+jvOP39EYx13pwR36lywGipnp fvqSCr93xMe3jm/TbVKXROjCrq41Hg4= X-MC-Unique: kzcwK9LPPwuO_h1VFEUxHg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hyman Huang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Hanna Reitz , qemu-block@nongnu.org, qemu-stable@nongnu.org, Laurent Vivier , Thomas Huth , Paolo Bonzini , Kevin Wolf , Markus Armbruster , Dorjoy Chowdhury Subject: [PULL 08/10] crypto: Define macros for hash algorithm digest lengths Date: Mon, 9 Sep 2024 15:16:33 +0100 Message-ID: <20240909141635.1459701-9-berrange@redhat.com> In-Reply-To: <20240909141635.1459701-1-berrange@redhat.com> References: <20240909141635.1459701-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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 @redhat.com) X-ZM-MESSAGEID: 1725891503487116600 From: Dorjoy Chowdhury Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Dorjoy Chowdhury Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/hash.c | 14 +++++++------- include/crypto/hash.h | 8 ++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/crypto/hash.c b/crypto/hash.c index b0f8228bdc..8087f5dae6 100644 --- a/crypto/hash.c +++ b/crypto/hash.c @@ -23,13 +23,13 @@ #include "hashpriv.h" =20 static size_t qcrypto_hash_alg_size[QCRYPTO_HASH_ALG__MAX] =3D { - [QCRYPTO_HASH_ALG_MD5] =3D 16, - [QCRYPTO_HASH_ALG_SHA1] =3D 20, - [QCRYPTO_HASH_ALG_SHA224] =3D 28, - [QCRYPTO_HASH_ALG_SHA256] =3D 32, - [QCRYPTO_HASH_ALG_SHA384] =3D 48, - [QCRYPTO_HASH_ALG_SHA512] =3D 64, - [QCRYPTO_HASH_ALG_RIPEMD160] =3D 20, + [QCRYPTO_HASH_ALG_MD5] =3D QCRYPTO_HASH_DIGEST_LEN_MD5, + [QCRYPTO_HASH_ALG_SHA1] =3D QCRYPTO_HASH_DIGEST_LEN_SHA1, + [QCRYPTO_HASH_ALG_SHA224] =3D QCRYPTO_HASH_DIGEST_LEN_SHA224, + [QCRYPTO_HASH_ALG_SHA256] =3D QCRYPTO_HASH_DIGEST_LEN_SHA256, + [QCRYPTO_HASH_ALG_SHA384] =3D QCRYPTO_HASH_DIGEST_LEN_SHA384, + [QCRYPTO_HASH_ALG_SHA512] =3D QCRYPTO_HASH_DIGEST_LEN_SHA512, + [QCRYPTO_HASH_ALG_RIPEMD160] =3D QCRYPTO_HASH_DIGEST_LEN_RIPEMD160, }; =20 size_t qcrypto_hash_digest_len(QCryptoHashAlgorithm alg) diff --git a/include/crypto/hash.h b/include/crypto/hash.h index 54d87aa2a1..a113cc3b04 100644 --- a/include/crypto/hash.h +++ b/include/crypto/hash.h @@ -23,6 +23,14 @@ =20 #include "qapi/qapi-types-crypto.h" =20 +#define QCRYPTO_HASH_DIGEST_LEN_MD5 16 +#define QCRYPTO_HASH_DIGEST_LEN_SHA1 20 +#define QCRYPTO_HASH_DIGEST_LEN_SHA224 28 +#define QCRYPTO_HASH_DIGEST_LEN_SHA256 32 +#define QCRYPTO_HASH_DIGEST_LEN_SHA384 48 +#define QCRYPTO_HASH_DIGEST_LEN_SHA512 64 +#define QCRYPTO_HASH_DIGEST_LEN_RIPEMD160 20 + /* See also "QCryptoHashAlgorithm" defined in qapi/crypto.json */ =20 /** --=20 2.45.2 From nobody Sun Nov 24 05:51:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1725891553; cv=none; d=zohomail.com; s=zohoarc; b=hIgS3D+AZERO6+TuGbCJ6wHPI00I8eFTVfR0qABVQ/wF0eHqcqCXf47KywYSq18/ffOh1oHjbFml1hUrN+YHXSZvQNDzglK9a8eo4MU6B39j58Hpx9LKxTb9/li2KAse8gdhsFFmoPliNo336KkgZU0FWqcFJCRnWHjI5snewjE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725891553; 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=DUnHB5hYXq96UzF2fv+RHZSEUfEeAvEnjgsMyw0Ich4=; b=lGEgoQc69esmzB0Rs7vbLcEmbN5pdkUiVEIGSioG6Lfle9SEgioO5gm8J+RqCIaXMeuVGiec7IRAtMIaeBuYjj8/GneEOyyYOC6xVrxpohFYRYosMgVahnDIdXlfIJhCLr+SRlLUhy4eMwYuWG4SikYn8ZfXRO4lg/+ra+GKDFY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1725891553406995.3491490579795; Mon, 9 Sep 2024 07:19:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snfDM-0003N1-2k; Mon, 09 Sep 2024 10:18:00 -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 1snfD5-00026O-IQ for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1snfD3-0003Pq-Lq for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:43 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-99-5nf3jvxNM86UxmSpfgiwFQ-1; Mon, 09 Sep 2024 10:17:36 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AD309195422B; Mon, 9 Sep 2024 14:17:34 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.212]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DF0E51956054; Mon, 9 Sep 2024 14:17:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725891461; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DUnHB5hYXq96UzF2fv+RHZSEUfEeAvEnjgsMyw0Ich4=; b=WwnY0O/CkvS78uTvLEJEt7vm/Q/531KuO/yQdq8DdQVJs3WShy7H7xOj86vGzm7pZr4Dix c/9l1MInpw0xM+E6sgC2qaa3PPlHsi6M7hwm58bnz8KaCd34YbcdSRB4T4GiDBeL8+TXO5 4ow3Wu8AigOimTeAPqIjrmuyiO6kFjw= X-MC-Unique: 5nf3jvxNM86UxmSpfgiwFQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hyman Huang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Hanna Reitz , qemu-block@nongnu.org, qemu-stable@nongnu.org, Laurent Vivier , Thomas Huth , Paolo Bonzini , Kevin Wolf , Markus Armbruster , Dorjoy Chowdhury Subject: [PULL 09/10] crypto: Support SHA384 hash when using glib Date: Mon, 9 Sep 2024 15:16:34 +0100 Message-ID: <20240909141635.1459701-10-berrange@redhat.com> In-Reply-To: <20240909141635.1459701-1-berrange@redhat.com> References: <20240909141635.1459701-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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 @redhat.com) X-ZM-MESSAGEID: 1725891553765116600 From: Dorjoy Chowdhury QEMU requires minimum glib version 2.66.0 as per the root meson.build file and per glib documentation[1] G_CHECKSUM_SHA384 is available since 2.51. [1] https://docs.gtk.org/glib/enum.ChecksumType.html Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Dorjoy Chowdhury Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/hash-glib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/hash-glib.c b/crypto/hash-glib.c index 82de9db705..18e64faa9c 100644 --- a/crypto/hash-glib.c +++ b/crypto/hash-glib.c @@ -29,7 +29,7 @@ static int qcrypto_hash_alg_map[QCRYPTO_HASH_ALG__MAX] = =3D { [QCRYPTO_HASH_ALG_SHA1] =3D G_CHECKSUM_SHA1, [QCRYPTO_HASH_ALG_SHA224] =3D -1, [QCRYPTO_HASH_ALG_SHA256] =3D G_CHECKSUM_SHA256, - [QCRYPTO_HASH_ALG_SHA384] =3D -1, + [QCRYPTO_HASH_ALG_SHA384] =3D G_CHECKSUM_SHA384, [QCRYPTO_HASH_ALG_SHA512] =3D G_CHECKSUM_SHA512, [QCRYPTO_HASH_ALG_RIPEMD160] =3D -1, }; --=20 2.45.2 From nobody Sun Nov 24 05:51:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1725891705; cv=none; d=zohomail.com; s=zohoarc; b=f/CtpdlB6Xp6ZZD8y2mhKFasb0rxHfc7TUx9ONpPorkOy/DSMqEQ3RgOhWLMMYCyx62+BYiKxWrGUVINZxI9ipq3m5tPDc6L0T6W01mfrBjg5oy2RblTcuaL3u+yfUCMWd2KTSqfjd5nzCOL3GPjEx6w7PAw9cQzEMYROOLQb8Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725891705; 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=k9/tGajAtWoDx1VNQGN8/qbY8n3LIiVuLQPmyt2WZLo=; b=P2bcLbNPJicUi7tP4/tMyxyDt5pMEKCvAq7+lX9faG42ywbd6CdYTXOKI02vvVU+Rn8MoDzOkrjbWlcyd6DJaHdPLbZZVvJeqfrgQeA8UC5EmOtAMKFfreP6lPzBloJl4AW6+5wXewdRfaoUmxJC1axXtEWxK5j5XukZgOJLNeQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172589170546115.251392551865592; Mon, 9 Sep 2024 07:21:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snfDP-0003xq-CN; Mon, 09 Sep 2024 10:18:03 -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 1snfDA-0002UN-RT for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1snfD7-0003QN-Lg for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:17:48 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-2-bD5Wy_wfMvKHV_gfFv0ShA-1; Mon, 09 Sep 2024 10:17:42 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B553E1977023; Mon, 9 Sep 2024 14:17:39 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.212]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 217AA1956054; Mon, 9 Sep 2024 14:17:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725891465; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k9/tGajAtWoDx1VNQGN8/qbY8n3LIiVuLQPmyt2WZLo=; b=YWrFlYSFzFtFQ57cggj9WUuCrwXNqe7G2RVti2AnnQwoVEa3sSV4bq+B0RVJ+1CZrr1jAG PjQ+mkzQxTf6cYJPGwVrwuTPyXnK9VzqfMtflCY/dJEwnW7YXabVU/s81pE4aZSgZ6D5oQ wHWaurCqbtlb9faV/g/38/8AxbOkn3c= X-MC-Unique: bD5Wy_wfMvKHV_gfFv0ShA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hyman Huang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Hanna Reitz , qemu-block@nongnu.org, qemu-stable@nongnu.org, Laurent Vivier , Thomas Huth , Paolo Bonzini , Kevin Wolf , Markus Armbruster , Dorjoy Chowdhury Subject: [PULL 10/10] crypto: Introduce x509 utils Date: Mon, 9 Sep 2024 15:16:35 +0100 Message-ID: <20240909141635.1459701-11-berrange@redhat.com> In-Reply-To: <20240909141635.1459701-1-berrange@redhat.com> References: <20240909141635.1459701-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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 @redhat.com) X-ZM-MESSAGEID: 1725891706586116600 From: Dorjoy Chowdhury An utility function for getting fingerprint from X.509 certificate has been introduced. Implementation only provided using gnutls. Signed-off-by: Dorjoy Chowdhury [DB: fixed missing gnutls_x509_crt_deinit in success path] Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/meson.build | 4 ++ crypto/x509-utils.c | 76 +++++++++++++++++++++++++++++++++++++ include/crypto/x509-utils.h | 22 +++++++++++ 3 files changed, 102 insertions(+) create mode 100644 crypto/x509-utils.c create mode 100644 include/crypto/x509-utils.h diff --git a/crypto/meson.build b/crypto/meson.build index c46f9c22a7..735635de1f 100644 --- a/crypto/meson.build +++ b/crypto/meson.build @@ -24,6 +24,10 @@ crypto_ss.add(files( 'rsakey.c', )) =20 +if gnutls.found() + crypto_ss.add(files('x509-utils.c')) +endif + if nettle.found() crypto_ss.add(nettle, files('hash-nettle.c', 'hmac-nettle.c', 'pbkdf-net= tle.c')) if hogweed.found() diff --git a/crypto/x509-utils.c b/crypto/x509-utils.c new file mode 100644 index 0000000000..6e157af76b --- /dev/null +++ b/crypto/x509-utils.c @@ -0,0 +1,76 @@ +/* + * X.509 certificate related helpers + * + * Copyright (c) 2024 Dorjoy Chowdhury + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * (at your option) any later version. See the COPYING file in the + * top-level directory. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "crypto/x509-utils.h" +#include +#include +#include + +static const int qcrypto_to_gnutls_hash_alg_map[QCRYPTO_HASH_ALG__MAX] =3D= { + [QCRYPTO_HASH_ALG_MD5] =3D GNUTLS_DIG_MD5, + [QCRYPTO_HASH_ALG_SHA1] =3D GNUTLS_DIG_SHA1, + [QCRYPTO_HASH_ALG_SHA224] =3D GNUTLS_DIG_SHA224, + [QCRYPTO_HASH_ALG_SHA256] =3D GNUTLS_DIG_SHA256, + [QCRYPTO_HASH_ALG_SHA384] =3D GNUTLS_DIG_SHA384, + [QCRYPTO_HASH_ALG_SHA512] =3D GNUTLS_DIG_SHA512, + [QCRYPTO_HASH_ALG_RIPEMD160] =3D GNUTLS_DIG_RMD160, +}; + +int qcrypto_get_x509_cert_fingerprint(uint8_t *cert, size_t size, + QCryptoHashAlgorithm alg, + uint8_t *result, + size_t *resultlen, + Error **errp) +{ + int ret =3D -1; + int hlen; + gnutls_x509_crt_t crt; + gnutls_datum_t datum =3D {.data =3D cert, .size =3D size}; + + if (alg >=3D G_N_ELEMENTS(qcrypto_to_gnutls_hash_alg_map)) { + error_setg(errp, "Unknown hash algorithm"); + return -1; + } + + if (result =3D=3D NULL) { + error_setg(errp, "No valid buffer given"); + return -1; + } + + gnutls_x509_crt_init(&crt); + + if (gnutls_x509_crt_import(crt, &datum, GNUTLS_X509_FMT_PEM) !=3D 0) { + error_setg(errp, "Failed to import certificate"); + goto cleanup; + } + + hlen =3D gnutls_hash_get_len(qcrypto_to_gnutls_hash_alg_map[alg]); + if (*resultlen < hlen) { + error_setg(errp, + "Result buffer size %zu is smaller than hash %d", + *resultlen, hlen); + goto cleanup; + } + + if (gnutls_x509_crt_get_fingerprint(crt, + qcrypto_to_gnutls_hash_alg_map[alg= ], + result, resultlen) !=3D 0) { + error_setg(errp, "Failed to get fingerprint from certificate"); + goto cleanup; + } + + ret =3D 0; + + cleanup: + gnutls_x509_crt_deinit(crt); + return ret; +} diff --git a/include/crypto/x509-utils.h b/include/crypto/x509-utils.h new file mode 100644 index 0000000000..4210dfbcfc --- /dev/null +++ b/include/crypto/x509-utils.h @@ -0,0 +1,22 @@ +/* + * X.509 certificate related helpers + * + * Copyright (c) 2024 Dorjoy Chowdhury + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * (at your option) any later version. See the COPYING file in the + * top-level directory. + */ + +#ifndef QCRYPTO_X509_UTILS_H +#define QCRYPTO_X509_UTILS_H + +#include "crypto/hash.h" + +int qcrypto_get_x509_cert_fingerprint(uint8_t *cert, size_t size, + QCryptoHashAlgorithm hash, + uint8_t *result, + size_t *resultlen, + Error **errp); + +#endif --=20 2.45.2