From nobody Wed Dec 17 04:18:35 2025 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 1526385845464282.8759134262399; Tue, 15 May 2018 05:04:05 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2759D3158BCD; Tue, 15 May 2018 12:04:02 +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 DE04D30B2002; Tue, 15 May 2018 12:04:01 +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 7862914B1B; Tue, 15 May 2018 12:04:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4FC3v57024758 for ; Tue, 15 May 2018 08:03:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id EA94C2024CAB; Tue, 15 May 2018 12:03:56 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FFDF2024CBA for ; Tue, 15 May 2018 12:03:56 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Tue, 15 May 2018 14:03:47 +0200 Message-Id: <2674be5d126c401e85c9903b059972bc8767ab8d.1526385621.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/8] virCryptoHashBuf: return the length of the hash in bytes 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.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 15 May 2018 12:04:04 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 virCryptoHashString also needs to know the size of the returned hash. Return it if the hash conversion succeeded so the caller does not need to access the hashinfo array. This should make virCryptoHashString build without gnutls. Also fixes the missing return value for the virCryptoHashBuf stub. Signed-off-by: J=C3=A1n Tomko Suggested-by: Stefan Berger --- src/util/vircrypto.c | 14 ++++++++------ src/util/vircrypto.h | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/util/vircrypto.c b/src/util/vircrypto.c index 62a027353b..d110adfe59 100644 --- a/src/util/vircrypto.c +++ b/src/util/vircrypto.c @@ -54,7 +54,7 @@ struct virHashInfo { =20 verify(ARRAY_CARDINALITY(hashinfo) =3D=3D VIR_CRYPTO_HASH_LAST); =20 -int +ssize_t virCryptoHashBuf(virCryptoHash hash, const char *input, unsigned char *output) @@ -74,16 +74,17 @@ virCryptoHashBuf(virCryptoHash hash, return -1; } =20 - return 0; + return hashinfo[hash].hashlen; } #else -int +ssize_t 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); + return -1; } #endif =20 @@ -93,18 +94,19 @@ virCryptoHashString(virCryptoHash hash, char **output) { unsigned char buf[VIR_CRYPTO_LARGEST_DIGEST_SIZE]; + ssize_t rc; size_t hashstrlen; size_t i; =20 - if (virCryptoHashBuf(hash, input, buf) < 0) + if ((rc =3D virCryptoHashBuf(hash, input, buf)) < 0) return -1; =20 - hashstrlen =3D (hashinfo[hash].hashlen * 2) + 1; + hashstrlen =3D (rc * 2) + 1; =20 if (VIR_ALLOC_N(*output, hashstrlen) < 0) return -1; =20 - for (i =3D 0; i < hashinfo[hash].hashlen; i++) { + for (i =3D 0; i < rc; i++) { (*output)[i * 2] =3D hex[(buf[i] >> 4) & 0xf]; (*output)[(i * 2) + 1] =3D hex[buf[i] & 0xf]; } diff --git a/src/util/vircrypto.h b/src/util/vircrypto.h index 64984006be..9b5dada53d 100644 --- a/src/util/vircrypto.h +++ b/src/util/vircrypto.h @@ -41,7 +41,7 @@ typedef enum { VIR_CRYPTO_CIPHER_LAST } virCryptoCipher; =20 -int +ssize_t virCryptoHashBuf(virCryptoHash hash, const char *input, unsigned char *output) --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list