From nobody Thu Apr 25 19:47:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1526053845983763.833172386314; Fri, 11 May 2018 08:50:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7A86E3001FB7; Fri, 11 May 2018 15:50:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4B950106223F; Fri, 11 May 2018 15:50:44 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 039664BB78; Fri, 11 May 2018 15:50:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4BFoKV3017711 for ; Fri, 11 May 2018 11:50:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 706F183B79; Fri, 11 May 2018 15:50:20 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14A0683B86 for ; Fri, 11 May 2018 15:50:19 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Fri, 11 May 2018 17:50:11 +0200 Message-Id: <7ab5ca05b726479fce59ea9588c0bafd6f2f1460.1526053739.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/5] vircrypto: provide constants for hash sizes X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 11 May 2018 15:50:45 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 The callers needing to know the size of the resulting digest rely on _DIGEST_SIZE constants from gnulib. Introduce VIR_CRYPTO_HASH_SIZE_ constants to remove the dependency. Signed-off-by: J=C3=A1n Tomko --- src/util/vircrypto.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/util/vircrypto.h b/src/util/vircrypto.h index 068602f5df..81743d2f74 100644 --- a/src/util/vircrypto.h +++ b/src/util/vircrypto.h @@ -23,6 +23,9 @@ =20 # include "internal.h" =20 +# define VIR_CRYPTO_HASH_SIZE_MD5 16 +# define VIR_CRYPTO_HASH_SIZE_SHA256 32 + typedef enum { VIR_CRYPTO_HASH_MD5, /* Don't use this except for historic compat */ VIR_CRYPTO_HASH_SHA256, --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 19:47:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15260538299787.74751381442411; Fri, 11 May 2018 08:50:29 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2A2F9641C7; Fri, 11 May 2018 15:50:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E1AA560BE5; Fri, 11 May 2018 15:50:27 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 95FE64CAB0; Fri, 11 May 2018 15:50:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4BFoL9X017719 for ; Fri, 11 May 2018 11:50:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 10CD87D55C; Fri, 11 May 2018 15:50:21 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id AA47383B7A for ; Fri, 11 May 2018 15:50:20 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Fri, 11 May 2018 17:50:12 +0200 Message-Id: <5819c3072adfb8f830cd02ef18523878ed621bad.1526053739.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/5] Introduce virCryptoHashBuf X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 11 May 2018 15:50:29 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 A function that keeps the hash in binary form instead of converting it to human-readable hexadecimal form. Signed-off-by: J=C3=A1n Tomko --- src/util/vircrypto.c | 31 +++++++++++++++++++++---------- src/util/vircrypto.h | 7 +++++++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/util/vircrypto.c b/src/util/vircrypto.c index 48b04fc8ce..1a2dcc28b7 100644 --- a/src/util/vircrypto.c +++ b/src/util/vircrypto.c @@ -54,28 +54,39 @@ struct virHashInfo { verify(ARRAY_CARDINALITY(hashinfo) =3D=3D VIR_CRYPTO_HASH_LAST); =20 int -virCryptoHashString(virCryptoHash hash, - const char *input, - char **output) +virCryptoHashBuf(virCryptoHash hash, + const char *input, + unsigned char *output) { - unsigned char buf[VIR_CRYPTO_LARGEST_DIGEST_SIZE]; - size_t hashstrlen; - size_t i; - if (hash >=3D VIR_CRYPTO_HASH_LAST) { virReportError(VIR_ERR_INVALID_ARG, _("Unknown crypto hash %d"), hash); return -1; } =20 - hashstrlen =3D (hashinfo[hash].hashlen * 2) + 1; - - if (!(hashinfo[hash].func(input, strlen(input), buf))) { + if (!(hashinfo[hash].func(input, strlen(input), output))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to compute hash of data")); return -1; } =20 + return 0; +} + +int +virCryptoHashString(virCryptoHash hash, + const char *input, + char **output) +{ + unsigned char buf[VIR_CRYPTO_LARGEST_DIGEST_SIZE]; + size_t hashstrlen; + size_t i; + + if (virCryptoHashBuf(hash, input, buf) < 0) + return -1; + + hashstrlen =3D (hashinfo[hash].hashlen * 2) + 1; + if (VIR_ALLOC_N(*output, hashstrlen) < 0) return -1; =20 diff --git a/src/util/vircrypto.h b/src/util/vircrypto.h index 81743d2f74..64984006be 100644 --- a/src/util/vircrypto.h +++ b/src/util/vircrypto.h @@ -41,6 +41,13 @@ typedef enum { VIR_CRYPTO_CIPHER_LAST } virCryptoCipher; =20 +int +virCryptoHashBuf(virCryptoHash hash, + const char *input, + unsigned char *output) + ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) + ATTRIBUTE_RETURN_CHECK; + int virCryptoHashString(virCryptoHash hash, const char *input, --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 19:47:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 152605383486546.819202211121706; Fri, 11 May 2018 08:50:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0386B30001E1; Fri, 11 May 2018 15:50:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B4C3860920; Fri, 11 May 2018 15:50:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6694B180B5B1; Fri, 11 May 2018 15:50:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4BFoM9l017728 for ; Fri, 11 May 2018 11:50:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 015C183B79; Fri, 11 May 2018 15:50:22 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B15F83B7A for ; Fri, 11 May 2018 15:50:21 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Fri, 11 May 2018 17:50:13 +0200 Message-Id: <096fa54847cf766078f60dd4496408f164a36387.1526053739.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/5] esx: use virCryptoHashBuf X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 11 May 2018 15:50:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Instead of using md5_buffer from gnulib directly. Signed-off-by: J=C3=A1n Tomko --- src/esx/esx_network_driver.c | 13 +++++++++---- src/esx/esx_storage_backend_iscsi.c | 19 +++++++++++++------ src/esx/esx_storage_backend_vmfs.c | 9 +++++---- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c index b19c06a4cb..7386efb0f5 100644 --- a/src/esx/esx_network_driver.c +++ b/src/esx/esx_network_driver.c @@ -33,6 +33,7 @@ #include "esx_vi.h" #include "esx_vi_methods.h" #include "esx_util.h" +#include "vircrypto.h" #include "virstring.h" =20 #define VIR_FROM_THIS VIR_FROM_ESX @@ -152,7 +153,8 @@ esxNetworkLookupByUUID(virConnectPtr conn, const unsign= ed char *uuid) =20 for (hostVirtualSwitch =3D hostVirtualSwitchList; hostVirtualSwitch; hostVirtualSwitch =3D hostVirtualSwitch->_next) { - md5_buffer(hostVirtualSwitch->key, strlen(hostVirtualSwitch->key),= md5); + if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, hostVirtualSwitch->key, = md5) < 0) + goto cleanup; =20 if (memcmp(uuid, md5, VIR_UUID_BUFLEN) =3D=3D 0) break; @@ -201,7 +203,8 @@ esxNetworkLookupByName(virConnectPtr conn, const char *= name) * The MD5 sum of the key can be used as UUID, assuming MD5 is conside= red * to be collision-free enough for this use case. */ - md5_buffer(hostVirtualSwitch->key, strlen(hostVirtualSwitch->key), md5= ); + if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, hostVirtualSwitch->key, md5)= < 0) + return NULL; =20 network =3D virGetNetwork(conn, hostVirtualSwitch->name, md5); =20 @@ -464,7 +467,8 @@ esxNetworkDefineXML(virConnectPtr conn, const char *xml) goto cleanup; } =20 - md5_buffer(hostVirtualSwitch->key, strlen(hostVirtualSwitch->key), md5= ); + if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, hostVirtualSwitch->key, md5)= < 0) + goto cleanup; =20 network =3D virGetNetwork(conn, hostVirtualSwitch->name, md5); =20 @@ -655,7 +659,8 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned i= nt flags) goto cleanup; } =20 - md5_buffer(hostVirtualSwitch->key, strlen(hostVirtualSwitch->key), def= ->uuid); + if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, hostVirtualSwitch->key, def-= >uuid) < 0) + goto cleanup; =20 if (VIR_STRDUP(def->name, hostVirtualSwitch->name) < 0) goto cleanup; diff --git a/src/esx/esx_storage_backend_iscsi.c b/src/esx/esx_storage_back= end_iscsi.c index b106c517e8..42b52214d1 100644 --- a/src/esx/esx_storage_backend_iscsi.c +++ b/src/esx/esx_storage_backend_iscsi.c @@ -37,6 +37,7 @@ #include "esx_vi.h" #include "esx_vi_methods.h" #include "esx_util.h" +#include "vircrypto.h" #include "virstring.h" =20 #define VIR_FROM_THIS VIR_FROM_ESX @@ -180,7 +181,8 @@ esxStoragePoolLookupByName(virConnectPtr conn, * but iScsiName (or widely known as IQN) is unique across the multiple * hosts, using it to compute key */ - md5_buffer(target->iScsiName, strlen(target->iScsiName), md5); + if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, target->iScsiName, md5) < 0) + goto cleanup; =20 pool =3D virGetStoragePool(conn, name, md5, &esxStorageBackendISCSI, N= ULL); =20 @@ -218,7 +220,8 @@ esxStoragePoolLookupByUUID(virConnectPtr conn, =20 for (target =3D hostInternetScsiHba->configuredStaticTarget; target; target =3D target->_next) { - md5_buffer(target->iScsiName, strlen(target->iScsiName), md5); + if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, target->iScsiName, md5) = < 0) + goto cleanup; =20 if (memcmp(uuid, md5, VIR_UUID_BUFLEN) =3D=3D 0) break; @@ -456,7 +459,8 @@ esxStorageVolLookupByName(virStoragePoolPtr pool, * compute MD5 hash to transform it to an acceptable * libvirt format */ - md5_buffer(scsiLun->uuid, strlen(scsiLun->uuid), md5); + if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, scsiLun->uuid, md5) = < 0) + goto cleanup; virUUIDFormat(md5, uuid_string); =20 /* @@ -507,7 +511,8 @@ esxStorageVolLookupByPath(virConnectPtr conn, const cha= r *path) goto cleanup; } =20 - md5_buffer(scsiLun->uuid, strlen(scsiLun->uuid), md5); + if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, scsiLun->uuid, md5) = < 0) + goto cleanup; virUUIDFormat(md5, uuid_string); =20 volume =3D virGetStorageVol(conn, poolName, path, uuid_string, @@ -549,7 +554,8 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char= *key) memset(uuid_string, '\0', sizeof(uuid_string)); memset(md5, '\0', sizeof(md5)); =20 - md5_buffer(scsiLun->uuid, strlen(scsiLun->uuid), md5); + if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, scsiLun->uuid, md5) < 0) + goto cleanup; virUUIDFormat(md5, uuid_string); =20 if (STREQ(key, uuid_string)) { @@ -697,7 +703,8 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume, =20 def.name =3D volume->name; =20 - md5_buffer(scsiLun->uuid, strlen(scsiLun->uuid), md5); + if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, scsiLun->uuid, md5) < 0) + goto cleanup; =20 virUUIDFormat(md5, uuid_string); =20 diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backe= nd_vmfs.c index 940e5d1f06..bf5093cf45 100644 --- a/src/esx/esx_storage_backend_vmfs.c +++ b/src/esx/esx_storage_backend_vmfs.c @@ -41,6 +41,7 @@ #include "esx_vi.h" #include "esx_vi_methods.h" #include "esx_util.h" +#include "vircrypto.h" #include "virstring.h" =20 #define VIR_FROM_THIS VIR_FROM_ESX @@ -236,8 +237,8 @@ esxStoragePoolLookupByName(virConnectPtr conn, goto cleanup; } =20 - md5_buffer(hostMount->mountInfo->path, - strlen(hostMount->mountInfo->path), md5); + if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, hostMount->mountInfo->path, = md5) < 0) + goto cleanup; =20 pool =3D virGetStoragePool(conn, name, md5, &esxStorageBackendVMFS, NU= LL); =20 @@ -289,8 +290,8 @@ esxStoragePoolLookupByUUID(virConnectPtr conn, goto cleanup; } =20 - md5_buffer(hostMount->mountInfo->path, - strlen(hostMount->mountInfo->path), md5); + if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, hostMount->mountInfo->pa= th, md5) < 0) + goto cleanup; =20 if (memcmp(uuid, md5, VIR_UUID_BUFLEN) =3D=3D 0) break; --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 19:47:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 152605382729854.08982315349192; Fri, 11 May 2018 08:50:27 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7FA423002EF8; Fri, 11 May 2018 15:50:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 505C01001F49; Fri, 11 May 2018 15:50:25 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0D3851801246; Fri, 11 May 2018 15:50:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4BFoMnF017737 for ; Fri, 11 May 2018 11:50:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9727783B7A; Fri, 11 May 2018 15:50:22 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3BA9D7D55C for ; Fri, 11 May 2018 15:50:22 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Fri, 11 May 2018 17:50:14 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/5] esx: Use VIR_CRYPTO_HASH_SIZE_MD5 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 11 May 2018 15:50:26 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Do not rely on gnulib's MD5_DIGEST_SIZE from md5.h. Include vircrypto.h and use VIR_CRYPTO_HASH_SIZE_MD5. Signed-off-by: J=C3=A1n Tomko --- src/esx/esx_network_driver.c | 9 ++++----- src/esx/esx_storage_backend_iscsi.c | 27 +++++++++++++-------------- src/esx/esx_storage_backend_vmfs.c | 11 +++++------ 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c index 7386efb0f5..b4f7f006d0 100644 --- a/src/esx/esx_network_driver.c +++ b/src/esx/esx_network_driver.c @@ -23,7 +23,6 @@ =20 #include =20 -#include "md5.h" #include "internal.h" #include "viralloc.h" #include "viruuid.h" @@ -42,7 +41,7 @@ * The UUID of a network is the MD5 sum of its key. Therefore, verify that * UUID and MD5 sum match in size, because we rely on that. */ -verify(MD5_DIGEST_SIZE =3D=3D VIR_UUID_BUFLEN); +verify(VIR_CRYPTO_HASH_SIZE_MD5 =3D=3D VIR_UUID_BUFLEN); =20 =20 static int @@ -142,7 +141,7 @@ esxNetworkLookupByUUID(virConnectPtr conn, const unsign= ed char *uuid) esxPrivate *priv =3D conn->privateData; esxVI_HostVirtualSwitch *hostVirtualSwitchList =3D NULL; esxVI_HostVirtualSwitch *hostVirtualSwitch =3D NULL; - unsigned char md5[MD5_DIGEST_SIZE]; /* MD5_DIGEST_SIZE =3D VIR_UUID_BU= FLEN =3D 16 */ + unsigned char md5[VIR_CRYPTO_HASH_SIZE_MD5]; /* VIR_CRYPTO_HASH_SIZE_M= D5 =3D VIR_UUID_BUFLEN =3D 16 */ char uuid_string[VIR_UUID_STRING_BUFLEN] =3D ""; =20 if (esxVI_EnsureSession(priv->primary) < 0 || @@ -186,7 +185,7 @@ esxNetworkLookupByName(virConnectPtr conn, const char *= name) virNetworkPtr network =3D NULL; esxPrivate *priv =3D conn->privateData; esxVI_HostVirtualSwitch *hostVirtualSwitch =3D NULL; - unsigned char md5[MD5_DIGEST_SIZE]; /* MD5_DIGEST_SIZE =3D VIR_UUID_BU= FLEN =3D 16 */ + unsigned char md5[VIR_CRYPTO_HASH_SIZE_MD5]; /* VIR_CRYPTO_HASH_SIZE_M= D5 =3D VIR_UUID_BUFLEN =3D 16 */ =20 if (esxVI_EnsureSession(priv->primary) < 0 || esxVI_LookupHostVirtualSwitchByName(priv->primary, name, @@ -296,7 +295,7 @@ esxNetworkDefineXML(virConnectPtr conn, const char *xml) esxVI_HostPortGroupSpec *hostPortGroupSpec =3D NULL; size_t i; =20 - unsigned char md5[MD5_DIGEST_SIZE]; /* MD5_DIGEST_SIZE =3D VIR_UUID_BU= FLEN =3D 16 */ + unsigned char md5[VIR_CRYPTO_HASH_SIZE_MD5]; /* VIR_CRYPTO_HASH_SIZE_M= D5 =3D VIR_UUID_BUFLEN =3D 16 */ =20 if (esxVI_EnsureSession(priv->primary) < 0) return NULL; diff --git a/src/esx/esx_storage_backend_iscsi.c b/src/esx/esx_storage_back= end_iscsi.c index 42b52214d1..fd0ace6fcb 100644 --- a/src/esx/esx_storage_backend_iscsi.c +++ b/src/esx/esx_storage_backend_iscsi.c @@ -27,7 +27,6 @@ #include =20 #include "internal.h" -#include "md5.h" #include "viralloc.h" #include "viruuid.h" #include "storage_conf.h" @@ -46,7 +45,7 @@ * The UUID of a storage pool is the MD5 sum of its mount path. Therefore, * verify that UUID and MD5 sum match in size, because we rely on that. */ -verify(MD5_DIGEST_SIZE =3D=3D VIR_UUID_BUFLEN); +verify(VIR_CRYPTO_HASH_SIZE_MD5 =3D=3D VIR_UUID_BUFLEN); =20 =20 =20 @@ -157,8 +156,8 @@ esxStoragePoolLookupByName(virConnectPtr conn, { esxPrivate *priv =3D conn->privateData; esxVI_HostInternetScsiHbaStaticTarget *target =3D NULL; - /* MD5_DIGEST_SIZE =3D VIR_UUID_BUFLEN =3D 16 */ - unsigned char md5[MD5_DIGEST_SIZE]; + /* VIR_CRYPTO_HASH_SIZE_MD5 =3D VIR_UUID_BUFLEN =3D 16 */ + unsigned char md5[VIR_CRYPTO_HASH_SIZE_MD5]; virStoragePoolPtr pool =3D NULL; =20 /* @@ -202,8 +201,8 @@ esxStoragePoolLookupByUUID(virConnectPtr conn, esxPrivate *priv =3D conn->privateData; esxVI_HostInternetScsiHba *hostInternetScsiHba =3D NULL; esxVI_HostInternetScsiHbaStaticTarget *target; - /* MD5_DIGEST_SIZE =3D VIR_UUID_BUFLEN =3D 16 */ - unsigned char md5[MD5_DIGEST_SIZE]; + /* VIR_CRYPTO_HASH_SIZE_MD5 =3D VIR_UUID_BUFLEN =3D 16 */ + unsigned char md5[VIR_CRYPTO_HASH_SIZE_MD5]; =20 if (esxVI_LookupHostInternetScsiHba(priv->primary, &hostInternetScsiHba) < 0) { @@ -443,8 +442,8 @@ esxStorageVolLookupByName(virStoragePoolPtr pool, esxPrivate *priv =3D pool->conn->privateData; esxVI_ScsiLun *scsiLunList =3D NULL; esxVI_ScsiLun *scsiLun; - /* MD5_DIGEST_SIZE =3D VIR_UUID_BUFLEN =3D 16 */ - unsigned char md5[MD5_DIGEST_SIZE]; + /* VIR_CRYPTO_HASH_SIZE_MD5 =3D VIR_UUID_BUFLEN =3D 16 */ + unsigned char md5[VIR_CRYPTO_HASH_SIZE_MD5]; char uuid_string[VIR_UUID_STRING_BUFLEN] =3D ""; =20 if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) @@ -491,8 +490,8 @@ esxStorageVolLookupByPath(virConnectPtr conn, const cha= r *path) esxVI_ScsiLun *scsiLun; esxVI_HostScsiDisk *hostScsiDisk =3D NULL; char *poolName =3D NULL; - /* MD5_DIGEST_SIZE =3D VIR_UUID_BUFLEN =3D 16 */ - unsigned char md5[MD5_DIGEST_SIZE]; + /* VIR_CRYPTO_HASH_SIZE_MD5 =3D VIR_UUID_BUFLEN =3D 16 */ + unsigned char md5[VIR_CRYPTO_HASH_SIZE_MD5]; char uuid_string[VIR_UUID_STRING_BUFLEN] =3D ""; =20 if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) @@ -538,8 +537,8 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char= *key) char *poolName =3D NULL; esxVI_ScsiLun *scsiLunList =3D NULL; esxVI_ScsiLun *scsiLun; - /* MD5_DIGEST_SIZE =3D VIR_UUID_BUFLEN =3D 16 */ - unsigned char md5[MD5_DIGEST_SIZE]; + /* VIR_CRYPTO_HASH_SIZE_MD5 =3D VIR_UUID_BUFLEN =3D 16 */ + unsigned char md5[VIR_CRYPTO_HASH_SIZE_MD5]; char uuid_string[VIR_UUID_STRING_BUFLEN] =3D ""; =20 /* key may be LUN device path */ @@ -671,8 +670,8 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume, esxVI_ScsiLun *scsiLun; esxVI_HostScsiDisk *hostScsiDisk =3D NULL; virStorageVolDef def; - /* MD5_DIGEST_SIZE =3D VIR_UUID_BUFLEN =3D 16 */ - unsigned char md5[MD5_DIGEST_SIZE]; + /* VIR_CRYPTO_HASH_SIZE_MD5 =3D VIR_UUID_BUFLEN =3D 16 */ + unsigned char md5[VIR_CRYPTO_HASH_SIZE_MD5]; char uuid_string[VIR_UUID_STRING_BUFLEN] =3D ""; =20 virCheckFlags(0, NULL); diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backe= nd_vmfs.c index bf5093cf45..630a6aa8c9 100644 --- a/src/esx/esx_storage_backend_vmfs.c +++ b/src/esx/esx_storage_backend_vmfs.c @@ -29,7 +29,6 @@ #include =20 #include "internal.h" -#include "md5.h" #include "viralloc.h" #include "virfile.h" #include "virlog.h" @@ -52,7 +51,7 @@ VIR_LOG_INIT("esx.esx_storage_backend_vmfs"); * The UUID of a storage pool is the MD5 sum of its mount path. Therefore, * verify that UUID and MD5 sum match in size, because we rely on that. */ -verify(MD5_DIGEST_SIZE =3D=3D VIR_UUID_BUFLEN); +verify(VIR_CRYPTO_HASH_SIZE_MD5 =3D=3D VIR_UUID_BUFLEN); =20 =20 =20 @@ -205,8 +204,8 @@ esxStoragePoolLookupByName(virConnectPtr conn, esxPrivate *priv =3D conn->privateData; esxVI_ObjectContent *datastore =3D NULL; esxVI_DatastoreHostMount *hostMount =3D NULL; - /* MD5_DIGEST_SIZE =3D VIR_UUID_BUFLEN =3D 16 */ - unsigned char md5[MD5_DIGEST_SIZE]; + /* VIR_CRYPTO_HASH_SIZE_MD5 =3D VIR_UUID_BUFLEN =3D 16 */ + unsigned char md5[VIR_CRYPTO_HASH_SIZE_MD5]; virStoragePoolPtr pool =3D NULL; =20 if (esxVI_LookupDatastoreByName(priv->primary, name, NULL, &datastore, @@ -260,8 +259,8 @@ esxStoragePoolLookupByUUID(virConnectPtr conn, esxVI_ObjectContent *datastoreList =3D NULL; esxVI_ObjectContent *datastore =3D NULL; esxVI_DatastoreHostMount *hostMount =3D NULL; - /* MD5_DIGEST_SIZE =3D VIR_UUID_BUFLEN =3D 16 */ - unsigned char md5[MD5_DIGEST_SIZE]; + /* VIR_CRYPTO_HASH_SIZE_MD5 =3D VIR_UUID_BUFLEN =3D 16 */ + unsigned char md5[VIR_CRYPTO_HASH_SIZE_MD5]; char *name =3D NULL; virStoragePoolPtr pool =3D NULL; =20 --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 19:47:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 152605385156238.80147213136968; Fri, 11 May 2018 08:50:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 300437E42B; Fri, 11 May 2018 15:50:50 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 01633100195A; Fri, 11 May 2018 15:50:49 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B176E3FAD8; Fri, 11 May 2018 15:50:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4BFoNY1017743 for ; Fri, 11 May 2018 11:50:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3824D7D55C; Fri, 11 May 2018 15:50:23 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id D155183B86 for ; Fri, 11 May 2018 15:50:22 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Fri, 11 May 2018 17:50:15 +0200 Message-Id: <1305bd5706523581c896b238e58a73861107a754.1526053739.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/5] vircrypto: Rely on GnuTLS for hash functions X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 11 May 2018 15:50:50 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Ditch the use of gnulib's digest functions in favor of GnuTLS, which might be more likely to get FIPS-certified. Signed-off-by: J=C3=A1n Tomko --- bootstrap.conf | 2 -- src/util/vircrypto.c | 32 +++++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 9559922fce..c4ef54ff13 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -37,8 +37,6 @@ connect configmake count-leading-zeros count-one-bits -crypto/md5 -crypto/sha256 dirname-lgpl environ execinfo diff --git a/src/util/vircrypto.c b/src/util/vircrypto.c index 1a2dcc28b7..62a027353b 100644 --- a/src/util/vircrypto.c +++ b/src/util/vircrypto.c @@ -26,8 +26,6 @@ #include "viralloc.h" #include "virrandom.h" =20 -#include "md5.h" -#include "sha256.h" #ifdef WITH_GNUTLS # include # if HAVE_GNUTLS_CRYPTO_H @@ -41,15 +39,18 @@ VIR_LOG_INIT("util.crypto"); =20 static const char hex[] =3D "0123456789abcdef"; =20 +#define VIR_CRYPTO_LARGEST_DIGEST_SIZE VIR_CRYPTO_HASH_SIZE_SHA256 + +#if WITH_GNUTLS + struct virHashInfo { - void *(*func)(const char *buf, size_t len, void *res); + gnutls_digest_algorithm_t algorithm; size_t hashlen; } hashinfo[] =3D { - { md5_buffer, MD5_DIGEST_SIZE }, - { sha256_buffer, SHA256_DIGEST_SIZE }, + { GNUTLS_DIG_MD5, VIR_CRYPTO_HASH_SIZE_MD5 }, + { GNUTLS_DIG_SHA256, VIR_CRYPTO_HASH_SIZE_SHA256 }, }; =20 -#define VIR_CRYPTO_LARGEST_DIGEST_SIZE SHA256_DIGEST_SIZE =20 verify(ARRAY_CARDINALITY(hashinfo) =3D=3D VIR_CRYPTO_HASH_LAST); =20 @@ -58,20 +59,33 @@ virCryptoHashBuf(virCryptoHash hash, const char *input, unsigned char *output) { + int rc; if (hash >=3D VIR_CRYPTO_HASH_LAST) { virReportError(VIR_ERR_INVALID_ARG, _("Unknown crypto hash %d"), hash); return -1; } =20 - if (!(hashinfo[hash].func(input, strlen(input), output))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to compute hash of data")); + rc =3D gnutls_hash_fast(hashinfo[hash].algorithm, input, strlen(input)= , output); + if (rc < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to compute hash of data: %s"), + gnutls_strerror(rc)); return -1; } =20 return 0; } +#else +int +virCryptoHashBuf(virCryptoHash hash, + const char *input ATTRIBUTE_UNUSED, + unsigned char *output ATTRIBUTE_UNUSED) +{ + virReportError(VIR_ERR_INVALID_ARG, + _("algorithm=3D%d is not supported"), hash); +} +#endif =20 int virCryptoHashString(virCryptoHash hash, --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list