From nobody Sat Nov 23 23:57:28 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=1728577382; cv=none; d=zohomail.com; s=zohoarc; b=N+wt5WeO1DI2QXuMOs0G8aICMvBEVEg7WfNg0Qt/CBJpmD4f5w8hdG8z+tQEo4oohQV7gNTZnQMDXrqdo6NCysnN5kuBlIVGylFyElPI5sDmGTUd56w/0XQbBdOQ6XVjPlf9rrCJbLW/f+VWRfFxTnZr0kqL75NH0mdsyY/TRqE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728577382; 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=3/Ujk28h3t0U7aG40LPkW3Li5ZxLrwJpIzHS8qO4M5I=; b=N1oYDK3HfjQ+4du3e4PgEVVWxeCjGJf/kcTwhe2tkLZGvq3nYSPyfTQ+Rd9Z+w6UB0BdHb7oRwSE53lDaeu2U5Pq1uvJdzYaAUlXvKX9tLRYaK2Ii3joNd6ZBjxePDbdaXxezru/seLASqYyEO+sj1vrw8kp7Yfv0IvAi+Y8x1k= 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 1728577382827367.88896343129556; Thu, 10 Oct 2024 09:23:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syvvP-0006sp-Nj; Thu, 10 Oct 2024 12:22: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 1syvvO-0006s0-UZ for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:02 -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 1syvvL-0004N3-2U for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:01 -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-599-9l0WdswoMhmbcM3ici8Adg-1; Thu, 10 Oct 2024 12:21:56 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 2CFCD1954B07; Thu, 10 Oct 2024 16:21:55 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.110]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0CB8830001A2; Thu, 10 Oct 2024 16:21:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728577317; 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=3/Ujk28h3t0U7aG40LPkW3Li5ZxLrwJpIzHS8qO4M5I=; b=Agfc7XpyzWsQotxSbj3QrKjEOn2aaJk61QWHJz+T5W1owqDwnYmjuVg8RmgsBItp8BJuyN 33Vkp9CHHiDSypHkRVreSzMd3EjkckEMTa2doskkYoSAa1sT6RBeaBfD7S68j6wD0qHQPX 6BUIDLi4EFgkSpCGSNiqq0pin9cGyT8= X-MC-Unique: 9l0WdswoMhmbcM3ici8Adg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Kunwu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Alejandro Zeise , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 01/17] crypto: accumulative hashing API Date: Thu, 10 Oct 2024 17:20:08 +0100 Message-ID: <20241010162024.988284-2-berrange@redhat.com> In-Reply-To: <20241010162024.988284-1-berrange@redhat.com> References: <20241010162024.988284-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.4.1 on 10.30.177.4 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.149, 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 1728577385220116600 From: Alejandro Zeise Changes the hash API to support accumulative hashing. Hash objects are created with "qcrypto_hash_new", updated with data with "qcrypto_hash_update", and the hash obtained with "qcrypto_hash_finalize". These changes bring the hashing API more in line with the hmac API. Signed-off-by: Alejandro Zeise [ clg: - Changed documentation "non-zero on error" -> "-1 on error" ] Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/hashpriv.h | 13 +++++ include/crypto/hash.h | 119 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) diff --git a/crypto/hashpriv.h b/crypto/hashpriv.h index 47daec3f7a..dcb3ba6cfb 100644 --- a/crypto/hashpriv.h +++ b/crypto/hashpriv.h @@ -1,6 +1,7 @@ /* * QEMU Crypto hash driver supports * + * Copyright (c) 2024 Seagate Technology LLC and/or its Affiliates * Copyright (c) 2017 HUAWEI TECHNOLOGIES CO., LTD. * * Authors: @@ -15,6 +16,8 @@ #ifndef QCRYPTO_HASHPRIV_H #define QCRYPTO_HASHPRIV_H =20 +#include "crypto/hash.h" + typedef struct QCryptoHashDriver QCryptoHashDriver; =20 struct QCryptoHashDriver { @@ -24,6 +27,16 @@ struct QCryptoHashDriver { uint8_t **result, size_t *resultlen, Error **errp); + QCryptoHash *(*hash_new)(QCryptoHashAlgo alg, Error **errp); + int (*hash_update)(QCryptoHash *hash, + const struct iovec *iov, + size_t niov, + Error **errp); + int (*hash_finalize)(QCryptoHash *hash, + uint8_t **result, + size_t *resultlen, + Error **errp); + void (*hash_free)(QCryptoHash *hash); }; =20 extern QCryptoHashDriver qcrypto_hash_lib_driver; diff --git a/include/crypto/hash.h b/include/crypto/hash.h index 6038a52d0e..b791ca92a4 100644 --- a/include/crypto/hash.h +++ b/include/crypto/hash.h @@ -1,6 +1,7 @@ /* * QEMU Crypto hash algorithms * + * Copyright (c) 2024 Seagate Technology LLC and/or its Affiliates * Copyright (c) 2015 Red Hat, Inc. * * This library is free software; you can redistribute it and/or @@ -33,6 +34,13 @@ =20 /* See also "QCryptoHashAlgo" defined in qapi/crypto.json */ =20 +typedef struct QCryptoHash QCryptoHash; +struct QCryptoHash { + QCryptoHashAlgo alg; + void *opaque; + void *driver; +}; + /** * qcrypto_hash_supports: * @alg: the hash algorithm @@ -128,6 +136,117 @@ int qcrypto_hash_digestv(QCryptoHashAlgo alg, char **digest, Error **errp); =20 +/** + * qcrypto_hash_updatev: + * @hash: hash object from qcrypto_hash_new + * @iov: the array of memory regions to hash + * @niov: the length of @iov + * @errp: pointer to a NULL-initialized error object + * + * Updates the given hash object with all the memory regions + * present in @iov. + * + * Returns: 0 on success, -1 on error + */ +int qcrypto_hash_updatev(QCryptoHash *hash, + const struct iovec *iov, + size_t niov, + Error **errp); +/** + * qcrypto_hash_update: + * @hash: hash object from qcrypto_hash_new + * @buf: the memory region to hash + * @len: the length of @buf + * @errp: pointer to a NULL-initialized error object + * + * Updates the given hash object with the data from + * the given buffer. + * + * Returns: 0 on success, -1 on error + */ +int qcrypto_hash_update(QCryptoHash *hash, + const char *buf, + size_t len, + Error **errp); + +/** + * qcrypto_hash_finalize_digest: + * @hash: the hash object to finalize + * @digest: pointer to hold output hash + * @errp: pointer to a NULL-initialized error object + * + * Computes the hash from the given hash object. Hash object + * is expected to have its data updated from the qcrypto_hash_update funct= ion. + * The @digest pointer will be filled with the printable hex digest of the + * computed hash, which will be terminated by '\0'. The memory pointer + * in @digest must be released with a call to g_free() when + * no longer required. + * + * Returns: 0 on success, -1 on error + */ +int qcrypto_hash_finalize_digest(QCryptoHash *hash, + char **digest, + Error **errp); + +/** + * qcrypto_hash_finalize_base64: + * @hash_ctx: hash object to finalize + * @base64: pointer to store the hash result in + * @errp: pointer to a NULL-initialized error object + * + * Computes the hash from the given hash object. Hash object + * is expected to have it's data updated from the qcrypto_hash_update func= tion. + * The @base64 pointer will be filled with the base64 encoding of the comp= uted + * hash, which will be terminated by '\0'. The memory pointer in @base64 + * must be released with a call to g_free() when no longer required. + * + * Returns: 0 on success, -1 on error + */ +int qcrypto_hash_finalize_base64(QCryptoHash *hash, + char **base64, + Error **errp); + +/** + * qcrypto_hash_finalize_bytes: + * @hash_ctx: hash object to finalize + * @result: pointer to store the hash result in + * @result_len: Pointer to store the length of the result in + * @errp: pointer to a NULL-initialized error object + * + * Computes the hash from the given hash object. Hash object + * is expected to have it's data updated from the qcrypto_hash_update func= tion. + * The memory pointer in @result must be released with a call to g_free() + * when no longer required. + * + * Returns: 0 on success, -1 on error + */ +int qcrypto_hash_finalize_bytes(QCryptoHash *hash, + uint8_t **result, + size_t *result_len, + Error **errp); + +/** + * qcrypto_hash_new: + * @alg: the hash algorithm + * @errp: pointer to a NULL-initialized error object + * + * Creates a new hashing context for the chosen algorithm for + * usage with qcrypto_hash_update. + * + * Returns: New hash object with the given algorithm, or NULL on error. + */ +QCryptoHash *qcrypto_hash_new(QCryptoHashAlgo alg, Error **errp); + +/** + * qcrypto_hash_free: + * @hash: hash object to free + * + * Frees a hashing context for the chosen algorithm. + */ +void qcrypto_hash_free(QCryptoHash *hash); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoHash, qcrypto_hash_free) + /** * qcrypto_hash_digest: * @alg: the hash algorithm --=20 2.46.0 From nobody Sat Nov 23 23:57:28 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=1728577419; cv=none; d=zohomail.com; s=zohoarc; b=HcCCmhoh7Uaq7TxFZ7vESWbtHBDK2IBctNhKgFaMbGaCpYkqqi8vkNS/Cm9u0bwpPZExsLnvujGritwLG1ySVm0xl8F06bygfbtf0BDZAVMD5xZKbrR8Qbm4xkHIpUJ9MrUETT1oVZM0Y5vmrP58h1AoLNSilv4fmw7vSWatsZs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728577419; 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=YpwiYJ3ZLO7kpZscaCRsl7Q4vjEbbQmMK9aN6p9w8H8=; b=EvFVENZ7rbix3n0ACRUkS6Amhp6vi3ToFXXJ2mFZDyD0zVdyh2QssxLI12zeX9AesfAoDiJtF+WHcFOzmfywWPM7Kgp/EgjeaJ11HJwdepslV4qR+9XEi4RJvpoJWuc0dgXHs3Nl+/MJiQg4Y5su3Suski6NNSE2VIWQn7xJxb8= 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 1728577419205683.2359207725746; Thu, 10 Oct 2024 09:23:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syvva-0006we-W4; Thu, 10 Oct 2024 12:22:15 -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 1syvvU-0006uP-Np for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:10 -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 1syvvM-0004NS-Pn for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:08 -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-665-qcXeTvuGORqDueWITSV8gg-1; Thu, 10 Oct 2024 12:21:58 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 838631955F25; Thu, 10 Oct 2024 16:21:57 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.110]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AC0E0300019E; Thu, 10 Oct 2024 16:21:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728577320; 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=YpwiYJ3ZLO7kpZscaCRsl7Q4vjEbbQmMK9aN6p9w8H8=; b=bY+8TksV2JPb2sHIQx7QELMJTIobDgEvrTVIEeBLK+Q+s4gBYpuv1diqxTKtN+/3dTApEA bYXZwnGjwgFC+SyCUGl4z2iyjdX7+rEUkoeq6PSoOugPTjaoPPML0UD32E8DtXQ9DF9wKe m3/4cW9HsEEsrJbqw+A4/P9G8mFYy1E= X-MC-Unique: qcXeTvuGORqDueWITSV8gg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Kunwu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Alejandro Zeise , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 02/17] crypto/hash-glib: Implement new hash API Date: Thu, 10 Oct 2024 17:20:09 +0100 Message-ID: <20241010162024.988284-3-berrange@redhat.com> In-Reply-To: <20241010162024.988284-1-berrange@redhat.com> References: <20241010162024.988284-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.4.1 on 10.30.177.4 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.149, 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 1728577419680116600 From: Alejandro Zeise Implements the new hashing API in the GLib hash driver. Supports creating/destroying a context, updating the context with input data and obtaining an output hash. Signed-off-by: Alejandro Zeise [ clg: - Dropped qcrypto_hash_supports() in qcrypto_glib_hash_new() - Removed superfluous cast (GChecksum *) in qcrypto_glib_hash_free() - Reworked qcrypto_glib_hash_finalize() ] Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/hash-glib.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/crypto/hash-glib.c b/crypto/hash-glib.c index a5a2949333..783283facc 100644 --- a/crypto/hash-glib.c +++ b/crypto/hash-glib.c @@ -1,6 +1,7 @@ /* * QEMU Crypto hash algorithms * + * Copyright (c) 2024 Seagate Technology LLC and/or its Affiliates * Copyright (c) 2016 Red Hat, Inc. * * This library is free software; you can redistribute it and/or @@ -95,6 +96,72 @@ qcrypto_glib_hash_bytesv(QCryptoHashAlgo alg, } =20 =20 +static +QCryptoHash *qcrypto_glib_hash_new(QCryptoHashAlgo alg, + Error **errp) +{ + QCryptoHash *hash; + + hash =3D g_new(QCryptoHash, 1); + hash->alg =3D alg; + hash->opaque =3D g_checksum_new(qcrypto_hash_alg_map[alg]); + + return hash; +} + +static +void qcrypto_glib_hash_free(QCryptoHash *hash) +{ + if (hash->opaque) { + g_checksum_free(hash->opaque); + } + + g_free(hash); +} + + +static +int qcrypto_glib_hash_update(QCryptoHash *hash, + const struct iovec *iov, + size_t niov, + Error **errp) +{ + GChecksum *ctx =3D hash->opaque; + + for (int i =3D 0; i < niov; i++) { + g_checksum_update(ctx, iov[i].iov_base, iov[i].iov_len); + } + + return 0; +} + +static +int qcrypto_glib_hash_finalize(QCryptoHash *hash, + uint8_t **result, + size_t *result_len, + Error **errp) +{ + int ret; + GChecksum *ctx =3D hash->opaque; + + ret =3D g_checksum_type_get_length(qcrypto_hash_alg_map[hash->alg]); + if (ret < 0) { + error_setg(errp, "Unable to get hash length"); + *result_len =3D 0; + return -1; + } + + *result_len =3D ret; + *result =3D g_new(uint8_t, *result_len); + + g_checksum_get_digest(ctx, *result, result_len); + return 0; +} + QCryptoHashDriver qcrypto_hash_lib_driver =3D { .hash_bytesv =3D qcrypto_glib_hash_bytesv, + .hash_new =3D qcrypto_glib_hash_new, + .hash_update =3D qcrypto_glib_hash_update, + .hash_finalize =3D qcrypto_glib_hash_finalize, + .hash_free =3D qcrypto_glib_hash_free, }; --=20 2.46.0 From nobody Sat Nov 23 23:57:28 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=1728577410; cv=none; d=zohomail.com; s=zohoarc; b=jAR+kr3aHvMKTOZtfCcJLhTqfdMVLLMAwBJA5Nl32AeuOkX3+vVKRzYmp5umZCaA3dAmUiRPwcLAmkw9ChC0TTm0Hg8zHE8Z1pp4NuBsf7HFwKHcoLX7Cl4PWXA9TE2kZWfwLAGJn0jb3JaaDOtnzHbOylS2/G/wajwc7SJ6/CI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728577410; 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=oP4mwUwHo8YYRkKGlsP9N9J66wpRHP0vgChE7dU6Ox0=; b=TGHhSImwic5gBecu9XQnk+Tcw6z2C5jP3x/uqk9teOzIboS3cXrTzSn5+H9Xa5kPwyXUEQYZwWncaCy44e6V6/t/hb2wPWGn50aA1k1bXpjmF2ZaLzPsn2CVZuIWXBISTKUfN9BgfBFrx/nGf3dRxxsXvVrN5bR9Qt3X1FQ6NcY= 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 1728577410824494.192331499288; Thu, 10 Oct 2024 09:23:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syvvX-0006vF-KF; Thu, 10 Oct 2024 12:22:11 -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 1syvvT-0006td-9S for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:08 -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 1syvvQ-0004Ns-6s for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:06 -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-418-DHPo3TwvMA21WN8PBqroTQ-1; Thu, 10 Oct 2024 12:22:01 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 CBAA91955EA8; Thu, 10 Oct 2024 16:21:59 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.110]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1E75930001A3; Thu, 10 Oct 2024 16:21:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728577322; 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=oP4mwUwHo8YYRkKGlsP9N9J66wpRHP0vgChE7dU6Ox0=; b=PVLcVzfT2Nv/OYKAu2Fnz/dyypl4NB922aYAS/D0gjjeQkowqpT5WumF8fnX2/q16K1cGR o/ZUt1AVeHlUc4PbojAVridbU3n1k4Bc3PYNLAWOKLieUSEPADrOErmxZ1rLHZ5IWCuOYY FxUJA4kB9XpRW6PnSuG2GstgfA0hvbw= X-MC-Unique: DHPo3TwvMA21WN8PBqroTQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Kunwu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Alejandro Zeise , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 03/17] crypto/hash-gcrypt: Implement new hash API Date: Thu, 10 Oct 2024 17:20:10 +0100 Message-ID: <20241010162024.988284-4-berrange@redhat.com> In-Reply-To: <20241010162024.988284-1-berrange@redhat.com> References: <20241010162024.988284-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.4.1 on 10.30.177.4 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.149, 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 1728577412081116600 From: Alejandro Zeise Implements the new hashing API in the gcrypt hash driver. Supports creating/destroying a context, updating the context with input data and obtaining an output hash. Signed-off-by: Alejandro Zeise [ clg: - Dropped qcrypto_hash_supports() in qcrypto_gcrypt_hash_new() - Reworked qcrypto_gcrypt_hash_finalize() - Handled gcry_md_open() errors in qcrypto_gcrypt_hash_new() - Checkpatch fixes ] Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/hash-gcrypt.c | 79 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/crypto/hash-gcrypt.c b/crypto/hash-gcrypt.c index 0973cc0d93..cb2cb37f25 100644 --- a/crypto/hash-gcrypt.c +++ b/crypto/hash-gcrypt.c @@ -1,6 +1,7 @@ /* * QEMU Crypto hash algorithms * + * Copyright (c) 2024 Seagate Technology LLC and/or its Affiliates * Copyright (c) 2016 Red Hat, Inc. * * This library is free software; you can redistribute it and/or @@ -110,7 +111,85 @@ qcrypto_gcrypt_hash_bytesv(QCryptoHashAlgo alg, return -1; } =20 +static +QCryptoHash *qcrypto_gcrypt_hash_new(QCryptoHashAlgo alg, Error **errp) +{ + QCryptoHash *hash; + int ret; + + hash =3D g_new(QCryptoHash, 1); + hash->alg =3D alg; + hash->opaque =3D g_new(gcry_md_hd_t, 1); + + ret =3D gcry_md_open((gcry_md_hd_t *) hash->opaque, + qcrypto_hash_alg_map[alg], 0); + if (ret < 0) { + error_setg(errp, + "Unable to initialize hash algorithm: %s", + gcry_strerror(ret)); + g_free(hash->opaque); + g_free(hash); + return NULL; + } + return hash; +} + +static +void qcrypto_gcrypt_hash_free(QCryptoHash *hash) +{ + gcry_md_hd_t *ctx =3D hash->opaque; + + if (ctx) { + gcry_md_close(*ctx); + g_free(ctx); + } + + g_free(hash); +} + + +static +int qcrypto_gcrypt_hash_update(QCryptoHash *hash, + const struct iovec *iov, + size_t niov, + Error **errp) +{ + gcry_md_hd_t *ctx =3D hash->opaque; + + for (int i =3D 0; i < niov; i++) { + gcry_md_write(*ctx, iov[i].iov_base, iov[i].iov_len); + } + + return 0; +} + +static +int qcrypto_gcrypt_hash_finalize(QCryptoHash *hash, + uint8_t **result, + size_t *result_len, + Error **errp) +{ + unsigned char *digest; + gcry_md_hd_t *ctx =3D hash->opaque; + + *result_len =3D gcry_md_get_algo_dlen(qcrypto_hash_alg_map[hash->alg]); + if (*result_len =3D=3D 0) { + error_setg(errp, "Unable to get hash length"); + return -1; + } + + *result =3D g_new(uint8_t, *result_len); + + /* Digest is freed by gcry_md_close(), copy it */ + digest =3D gcry_md_read(*ctx, 0); + memcpy(*result, digest, *result_len); + return 0; +} =20 QCryptoHashDriver qcrypto_hash_lib_driver =3D { .hash_bytesv =3D qcrypto_gcrypt_hash_bytesv, + .hash_new =3D qcrypto_gcrypt_hash_new, + .hash_update =3D qcrypto_gcrypt_hash_update, + .hash_finalize =3D qcrypto_gcrypt_hash_finalize, + .hash_free =3D qcrypto_gcrypt_hash_free, }; --=20 2.46.0 From nobody Sat Nov 23 23:57:28 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=1728577447; cv=none; d=zohomail.com; s=zohoarc; b=Z2IB/qRHJhLDkWW6fzEsi+dm6c0hioKxFOhNBchJw+ZHW4ilJMHe1r7WzagtLBGWy5nnOv68IwNjIm10XNPKdCFxcGNWzd6kPn1urFZgRx07aZEmnUasbnMQ6cCVPeYFUJxVZoXOqwkqdHG4QYwYULg+cZeboPPl+lPMpAzcnVI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728577447; 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=omtKFT3mUYD/TH7ylKueaUmwdDCn6wMEZBZS4+DeSFI=; b=N6aBeGLkaDRhhNZMCRj8xsnzdCwuw+/kH7ac8q5DRvbd+VWR5ilFE6OhxEqPlDbNDUA++tzFDQmrcTQUkmutHFWsfvhRmwv/YkYXK4hr852OakuB5clddKYTQ3q2qoCwiRe4pbu/rfsoT4Wxa885Vl5+G/PBbeQKFQIKRuqS918= 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 1728577447186741.5710551144163; Thu, 10 Oct 2024 09:24:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syvva-0006wE-Ci; Thu, 10 Oct 2024 12:22:14 -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 1syvvU-0006uO-MG for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:10 -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 1syvvT-0004PC-3A for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:08 -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-643-F1l7ed75PFei3uXMk-dLMw-1; Thu, 10 Oct 2024 12:22:03 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 427541955E80; Thu, 10 Oct 2024 16:22:02 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.110]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 37F4C300019E; Thu, 10 Oct 2024 16:22:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728577326; 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=omtKFT3mUYD/TH7ylKueaUmwdDCn6wMEZBZS4+DeSFI=; b=W8JVRgGDcOJ04Nsv6Bz0xLvGlwvhzl18MM0MY/fLSCsYQD+QnZVs2r1tsfFWmeVX7bXM4d gT9TOX87Zt3IscgxZsGZpRJEvwkxwiSrqX/mZvz6PvWpUNF6aK/C+Zwx4IQSv4Lrv6b25M z1vCNob6ELEVCvaBAAEqNURhgCm+dDY= X-MC-Unique: F1l7ed75PFei3uXMk-dLMw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Kunwu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Alejandro Zeise , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 04/17] crypto/hash-gnutls: Implement new hash API Date: Thu, 10 Oct 2024 17:20:11 +0100 Message-ID: <20241010162024.988284-5-berrange@redhat.com> In-Reply-To: <20241010162024.988284-1-berrange@redhat.com> References: <20241010162024.988284-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.4.1 on 10.30.177.4 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.149, 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 1728577447808116600 From: Alejandro Zeise Implements the new hashing API in the gnutls hash driver. Supports creating/destroying a context, updating the context with input data and obtaining an output hash. Signed-off-by: Alejandro Zeise [ clg: - Dropped qcrypto_hash_supports() in qcrypto_gnutls_hash_new() - Reworked qcrypto_gnutls_hash_finalize() - Handled gnutls_hash_init() errors in qcrypto_gnutls_hash_new() - Replaced gnutls_hash_deinit() by gnutls_hash_output() in qcrypto_gnutls_hash_finalize() - Freed resources with gnutls_hash_deinit() in qcrypto_gnutls_hash_free() ] Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/hash-gnutls.c | 78 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/crypto/hash-gnutls.c b/crypto/hash-gnutls.c index 0636c0727a..8b0327be82 100644 --- a/crypto/hash-gnutls.c +++ b/crypto/hash-gnutls.c @@ -1,6 +1,7 @@ /* * QEMU Crypto hash algorithms * + * Copyright (c) 2024 Seagate Technology LLC and/or its Affiliates * Copyright (c) 2021 Red Hat, Inc. * * This library is free software; you can redistribute it and/or @@ -98,7 +99,84 @@ qcrypto_gnutls_hash_bytesv(QCryptoHashAlgo alg, return 0; } =20 +static +QCryptoHash *qcrypto_gnutls_hash_new(QCryptoHashAlgo alg, Error **errp) +{ + QCryptoHash *hash; + int ret; + + hash =3D g_new(QCryptoHash, 1); + hash->alg =3D alg; + hash->opaque =3D g_new(gnutls_hash_hd_t, 1); + + ret =3D gnutls_hash_init(hash->opaque, qcrypto_hash_alg_map[alg]); + if (ret < 0) { + error_setg(errp, + "Unable to initialize hash algorithm: %s", + gnutls_strerror(ret)); + g_free(hash->opaque); + g_free(hash); + return NULL; + } + + return hash; +} + +static +void qcrypto_gnutls_hash_free(QCryptoHash *hash) +{ + gnutls_hash_hd_t *ctx =3D hash->opaque; + + gnutls_hash_deinit(*ctx, NULL); + g_free(ctx); + g_free(hash); +} + + +static +int qcrypto_gnutls_hash_update(QCryptoHash *hash, + const struct iovec *iov, + size_t niov, + Error **errp) +{ + int ret =3D 0; + gnutls_hash_hd_t *ctx =3D hash->opaque; + + for (int i =3D 0; i < niov; i++) { + ret =3D gnutls_hash(*ctx, iov[i].iov_base, iov[i].iov_len); + if (ret !=3D 0) { + error_setg(errp, "Failed to hash data: %s", + gnutls_strerror(ret)); + return -1; + } + } + + return 0; +} + +static +int qcrypto_gnutls_hash_finalize(QCryptoHash *hash, + uint8_t **result, + size_t *result_len, + Error **errp) +{ + gnutls_hash_hd_t *ctx =3D hash->opaque; + + *result_len =3D gnutls_hash_get_len(qcrypto_hash_alg_map[hash->alg]); + if (*result_len =3D=3D 0) { + error_setg(errp, "Unable to get hash length"); + return -1; + } + + *result =3D g_new(uint8_t, *result_len); + gnutls_hash_output(*ctx, *result); + return 0; +} =20 QCryptoHashDriver qcrypto_hash_lib_driver =3D { .hash_bytesv =3D qcrypto_gnutls_hash_bytesv, + .hash_new =3D qcrypto_gnutls_hash_new, + .hash_update =3D qcrypto_gnutls_hash_update, + .hash_finalize =3D qcrypto_gnutls_hash_finalize, + .hash_free =3D qcrypto_gnutls_hash_free, }; --=20 2.46.0 From nobody Sat Nov 23 23:57:28 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=1728577482; cv=none; d=zohomail.com; s=zohoarc; b=KoOhOLBJpGt390nK4xyQfMVWzTFE9xiQzG0MIc1txKdPR5VBRn+ZLw6NMQCI+T1appX0BNzdn3DPpYfWf3XZ0hnlJAzNDR6EBR5foX6fh1+ft//0Os5scTOPQ5WpN/DNf0X/x9jeFXSyzIjhi5jo36TXWqZrS8uDLwQdD9Ws2TM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728577482; 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=bhhdFqpAPQXyEI0DSJUUVq7n++aiHimBFeKo9MfvBfo=; b=cou75x46nAmLjH/d6xkSbS+2YWY4pF9pVsFMoXdGJ01/WNdASzkpsKJC2VIEpNOX1UYg/pGkYDF8x1WZF+CjOkJDoneiY504ev5Jf33HASPo7ynsQkiVrwj3+YcVgHXe/4dMntI0//fNszkzz9WgjvMoI773c0ev3PCqTsf7BNI= 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 1728577482824603.5129545033685; Thu, 10 Oct 2024 09:24:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syvvb-0006wx-H3; Thu, 10 Oct 2024 12:22:15 -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 1syvva-0006wc-O0 for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:14 -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 1syvvZ-0004QE-7P for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:14 -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-317-pAejfRpWNByIE0SR3njnuw-1; Thu, 10 Oct 2024 12:22:10 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 1D8141955F29; Thu, 10 Oct 2024 16:22:04 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.110]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 830CD300019E; Thu, 10 Oct 2024 16:22:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728577331; 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=bhhdFqpAPQXyEI0DSJUUVq7n++aiHimBFeKo9MfvBfo=; b=QEWyOIQDBPibq7+JyBhgEhnnRbDXPQC/LodD9YGY8pexuy6/MVfVX8Xo3udyRGYuewuMZI 6surL6usczLzf0rcSucPxiG8vO3QaR+Log+R23k7zb+U3Y+jzyDPJslIvgR3QW9EWsn2IS +KuUz0VrSn9gRqYO8GTLgClIJSDzXlE= X-MC-Unique: pAejfRpWNByIE0SR3njnuw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Kunwu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Alejandro Zeise , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 05/17] crypto/hash-nettle: Implement new hash API Date: Thu, 10 Oct 2024 17:20:12 +0100 Message-ID: <20241010162024.988284-6-berrange@redhat.com> In-Reply-To: <20241010162024.988284-1-berrange@redhat.com> References: <20241010162024.988284-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.4.1 on 10.30.177.4 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.149, 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 1728577484172116600 From: Alejandro Zeise Implements the new hashing API in the nettle hash driver. Supports creating/destroying a context, updating the context with input data and obtaining an output hash. Signed-off-by: Alejandro Zeise [ clg: - Dropped qcrypto_hash_supports() in qcrypto_nettle_hash_new() ] Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/hash-nettle.c | 70 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/crypto/hash-nettle.c b/crypto/hash-nettle.c index 8b08a9c675..07e18ce26c 100644 --- a/crypto/hash-nettle.c +++ b/crypto/hash-nettle.c @@ -1,6 +1,7 @@ /* * QEMU Crypto hash algorithms * + * Copyright (c) 2024 Seagate Technology LLC and/or its Affiliates * Copyright (c) 2016 Red Hat, Inc. * * This library is free software; you can redistribute it and/or @@ -155,7 +156,76 @@ qcrypto_nettle_hash_bytesv(QCryptoHashAlgo alg, return 0; } =20 +static +QCryptoHash *qcrypto_nettle_hash_new(QCryptoHashAlgo alg, Error **errp) +{ + QCryptoHash *hash; + + hash =3D g_new(QCryptoHash, 1); + hash->alg =3D alg; + hash->opaque =3D g_new(union qcrypto_hash_ctx, 1); + + qcrypto_hash_alg_map[alg].init(hash->opaque); + return hash; +} + +static +void qcrypto_nettle_hash_free(QCryptoHash *hash) +{ + union qcrypto_hash_ctx *ctx =3D hash->opaque; + + g_free(ctx); + g_free(hash); +} + +static +int qcrypto_nettle_hash_update(QCryptoHash *hash, + const struct iovec *iov, + size_t niov, + Error **errp) +{ + union qcrypto_hash_ctx *ctx =3D hash->opaque; + + for (int i =3D 0; i < niov; i++) { + /* + * Some versions of nettle have functions + * declared with 'int' instead of 'size_t' + * so to be safe avoid writing more than + * UINT_MAX bytes at a time + */ + size_t len =3D iov[i].iov_len; + uint8_t *base =3D iov[i].iov_base; + while (len) { + size_t shortlen =3D MIN(len, UINT_MAX); + qcrypto_hash_alg_map[hash->alg].write(ctx, len, base); + len -=3D shortlen; + base +=3D len; + } + } + + return 0; +} + +static +int qcrypto_nettle_hash_finalize(QCryptoHash *hash, + uint8_t **result, + size_t *result_len, + Error **errp) +{ + union qcrypto_hash_ctx *ctx =3D hash->opaque; + + *result_len =3D qcrypto_hash_alg_map[hash->alg].len; + *result =3D g_new(uint8_t, *result_len); + + qcrypto_hash_alg_map[hash->alg].result(ctx, *result_len, *result); + + return 0; +} =20 QCryptoHashDriver qcrypto_hash_lib_driver =3D { .hash_bytesv =3D qcrypto_nettle_hash_bytesv, + .hash_new =3D qcrypto_nettle_hash_new, + .hash_update =3D qcrypto_nettle_hash_update, + .hash_finalize =3D qcrypto_nettle_hash_finalize, + .hash_free =3D qcrypto_nettle_hash_free, }; --=20 2.46.0 From nobody Sat Nov 23 23:57:28 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=1728577455; cv=none; d=zohomail.com; s=zohoarc; b=jOPXAWGIK9ZGMiwubyoDXQN5owjbqG9LEKpfTr2NnmqcHJ11QupntNfgQa92Z6V8tR2LtJZt3kKWxlhOw7+p9yEn8iLcRjhJ8+sgXA3K2kOSv7042k/PbzkeEZaNCK/AQII8/hvfUaQUVlcsAo7FmYuKouiT1jbmxoYAFDtURaU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728577455; 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=tlcye8U6lIEWR6s8iqREBL6HF/0bNUW/INWT6JsYYlA=; b=nFeqn4ANl5aEHRsKs/KB+Ok6CIxl3KzHc1M8y4sr8nBI+VRrr7ArGulrlRlEtzxuemPiKlhWzcjVWl5ZdjvkSo9GoOe84m+pHqWRLjmeRQ9fAejdVhGyh8o4fxW4Le6/Q3WJAw/RWvYy0ob7jmYHkQgA2oPQglAkaqrXlvJYGXw= 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 1728577455152840.4025209499774; Thu, 10 Oct 2024 09:24:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syvvc-0006x0-7y; Thu, 10 Oct 2024 12:22:16 -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 1syvvb-0006wm-7M for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:15 -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 1syvvZ-0004QH-HD for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:15 -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-47-wSnt-zyxMXqh5QKm8jNJFQ-1; Thu, 10 Oct 2024 12:22:07 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 B91C41977307; Thu, 10 Oct 2024 16:22:06 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.110]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8D15130001A3; Thu, 10 Oct 2024 16:22:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728577332; 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=tlcye8U6lIEWR6s8iqREBL6HF/0bNUW/INWT6JsYYlA=; b=ZSEW7qcaX7SPtcO0UuYJ/KkTQrJEZKBaEkIJgP6Nz1rNbEtpHlJAZATxUEBHXqnij5RRC3 34fQj1+AC5u84msgFBgJ8r57xiNggrNitjpINeVKsNdMTe+9VuJaOnXT6yTPppUwtVrOMJ w3vQDKCSoeB5MOn/7iVu7f+YckCAZWY= X-MC-Unique: wSnt-zyxMXqh5QKm8jNJFQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Kunwu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Alejandro Zeise , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 06/17] util/iov: Introduce iov_send_recv_with_flags() Date: Thu, 10 Oct 2024 17:20:13 +0100 Message-ID: <20241010162024.988284-7-berrange@redhat.com> In-Reply-To: <20241010162024.988284-1-berrange@redhat.com> References: <20241010162024.988284-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.4.1 on 10.30.177.4 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.149, 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 1728577456140116600 From: Alejandro Zeise In order to support a new update function, a flag needs to be passed to the kernel via the socket send call (MSG_MORE) to notify it that more data is to be expected to calculate the hash correctly. Add a new iov helper for this purpose. Signed-off-by: Alejandro Zeise [ clg: - Split iov changes from original patch - Checkpatch fixes ] Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- include/qemu/iov.h | 27 +++++++++++++++++++++++++++ util/iov.c | 25 ++++++++++++++++++------- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/include/qemu/iov.h b/include/qemu/iov.h index 63a1c01965..44f9db5cee 100644 --- a/include/qemu/iov.h +++ b/include/qemu/iov.h @@ -1,6 +1,7 @@ /* * Helpers for using (partial) iovecs. * + * Copyright (c) 2024 Seagate Technology LLC and/or its Affiliates * Copyright (C) 2010 Red Hat, Inc. * * Author(s): @@ -75,6 +76,32 @@ iov_to_buf(const struct iovec *iov, const unsigned int i= ov_cnt, size_t iov_memset(const struct iovec *iov, const unsigned int iov_cnt, size_t offset, int fillc, size_t bytes); =20 +/* + * Send/recv data from/to iovec buffers directly, with the provided + * socket flags. + * + * `offset' bytes in the beginning of iovec buffer are skipped and + * next `bytes' bytes are used, which must be within data of iovec. + * + * r =3D iov_send_recv_with_flags(sockfd, sockflags, iov, iovcnt, + * offset, bytes, true); + * + * is logically equivalent to + * + * char *buf =3D malloc(bytes); + * iov_to_buf(iov, iovcnt, offset, buf, bytes); + * r =3D send(sockfd, buf, bytes, sockflags); + * free(buf); + * + * For iov_send_recv_with_flags() _whole_ area being sent or received + * should be within the iovec, not only beginning of it. + */ +ssize_t iov_send_recv_with_flags(int sockfd, int sockflags, + const struct iovec *iov, + unsigned iov_cnt, size_t offset, + size_t bytes, + bool do_send); + /* * Send/recv data from/to iovec buffers directly * diff --git a/util/iov.c b/util/iov.c index 7e73948f5e..7777116123 100644 --- a/util/iov.c +++ b/util/iov.c @@ -3,6 +3,7 @@ * * Copyright IBM, Corp. 2007, 2008 * Copyright (C) 2010 Red Hat, Inc. + * Copyright (c) 2024 Seagate Technology LLC and/or its Affiliates * * Author(s): * Anthony Liguori @@ -92,7 +93,8 @@ size_t iov_size(const struct iovec *iov, const unsigned i= nt iov_cnt) =20 /* helper function for iov_send_recv() */ static ssize_t -do_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, bool do_send) +do_send_recv(int sockfd, int flags, struct iovec *iov, unsigned iov_cnt, + bool do_send) { #ifdef CONFIG_POSIX ssize_t ret; @@ -102,8 +104,8 @@ do_send_recv(int sockfd, struct iovec *iov, unsigned io= v_cnt, bool do_send) msg.msg_iovlen =3D iov_cnt; do { ret =3D do_send - ? sendmsg(sockfd, &msg, 0) - : recvmsg(sockfd, &msg, 0); + ? sendmsg(sockfd, &msg, flags) + : recvmsg(sockfd, &msg, flags); } while (ret < 0 && errno =3D=3D EINTR); return ret; #else @@ -114,8 +116,8 @@ do_send_recv(int sockfd, struct iovec *iov, unsigned io= v_cnt, bool do_send) ssize_t off =3D 0; while (i < iov_cnt) { ssize_t r =3D do_send - ? send(sockfd, iov[i].iov_base + off, iov[i].iov_len - off, 0) - : recv(sockfd, iov[i].iov_base + off, iov[i].iov_len - off, 0); + ? send(sockfd, iov[i].iov_base + off, iov[i].iov_len - off, fl= ags) + : recv(sockfd, iov[i].iov_base + off, iov[i].iov_len - off, fl= ags); if (r > 0) { ret +=3D r; off +=3D r; @@ -144,6 +146,15 @@ do_send_recv(int sockfd, struct iovec *iov, unsigned i= ov_cnt, bool do_send) ssize_t iov_send_recv(int sockfd, const struct iovec *_iov, unsigned iov_c= nt, size_t offset, size_t bytes, bool do_send) +{ + return iov_send_recv_with_flags(sockfd, 0, _iov, iov_cnt, offset, byte= s, + do_send); +} + +ssize_t iov_send_recv_with_flags(int sockfd, int sockflags, + const struct iovec *_iov, + unsigned iov_cnt, size_t offset, + size_t bytes, bool do_send) { ssize_t total =3D 0; ssize_t ret; @@ -192,11 +203,11 @@ ssize_t iov_send_recv(int sockfd, const struct iovec = *_iov, unsigned iov_cnt, assert(iov[niov].iov_len > tail); orig_len =3D iov[niov].iov_len; iov[niov++].iov_len =3D tail; - ret =3D do_send_recv(sockfd, iov, niov, do_send); + ret =3D do_send_recv(sockfd, sockflags, iov, niov, do_send); /* Undo the changes above before checking for errors */ iov[niov-1].iov_len =3D orig_len; } else { - ret =3D do_send_recv(sockfd, iov, niov, do_send); + ret =3D do_send_recv(sockfd, sockflags, iov, niov, do_send); } if (offset) { iov[0].iov_base -=3D offset; --=20 2.46.0 From nobody Sat Nov 23 23:57:28 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=1728577404; cv=none; d=zohomail.com; s=zohoarc; b=TYiXTrqXh5TWwlwvDbDOE03vSXvRDvzLOW9W/Pvqc1CLu6XOAW932FQfMPiQZW076lUSH8rlyfd+7tMxFgFqmRy49mqSL60/9tzHmEiHkJQmwA5Qmm3rlG2T0+9TLOhxIfFsoahrpmWoLThnFYdIBVkacueX+PuTjDCuFQFZTOc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728577404; 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=XCLt6K70QI6XZ5GYqlrLy86nLHuHSEEZZ9EYnzlkffs=; b=dpJUuoeb0wKlJarcyJq0QaoHw5rXs8iL68UveUQHaeIl68a9hjwJ5MSuSinBegrituVle2PC1Y6DhYbLXkEa+9MLyGfNVoSu3S4KmH4q9QjXMdE6jry6R6M6++4MEiZH/IivOCl++OEblHOgCYbVBEAlQW40gN9GhzgNL6Kc6lw= 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 1728577404962938.5104052015095; Thu, 10 Oct 2024 09:23:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syvve-0006y2-6R; Thu, 10 Oct 2024 12:22:18 -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 1syvvc-0006wz-71 for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:16 -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 1syvvZ-0004QM-Vu for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:15 -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-61-vlagQ8dzO_6aKUZJQwrdqw-1; Thu, 10 Oct 2024 12:22:10 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 33DAE1956096; Thu, 10 Oct 2024 16:22:09 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.110]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 237E530001A6; Thu, 10 Oct 2024 16:22:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728577333; 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=XCLt6K70QI6XZ5GYqlrLy86nLHuHSEEZZ9EYnzlkffs=; b=I0xsM1MuhG4uNasTG+/C6YgaCoblNF8wELfe04eg0UjxYEiJwC+Aq4O+XkWS1158TZ/aWL ghafjxzVXr+yGdSrdSc88Kx7gY+Lv0tiqHg5QhyPUcafmv/Qm4+tlZhNvfaULPe3tXWcMc R2/Pbv/t9/X6F8GTnbZbWminhST7mys= X-MC-Unique: vlagQ8dzO_6aKUZJQwrdqw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Kunwu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Alejandro Zeise , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 07/17] crypto/hash-afalg: Implement new hash API Date: Thu, 10 Oct 2024 17:20:14 +0100 Message-ID: <20241010162024.988284-8-berrange@redhat.com> In-Reply-To: <20241010162024.988284-1-berrange@redhat.com> References: <20241010162024.988284-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.4.1 on 10.30.177.4 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.149, 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 1728577406040116600 From: Alejandro Zeise Updates the afalg hash driver to support the new accumulative hashing changes as part of the patch series. Implements opening/closing of contexts, updating hash data and finalizing the hash digest. In order to support the update function, a flag needs to be passed to the kernel via the socket send call (MSG_MORE) to notify it that more data is to be expected to calculate the hash correctly. As a result, a new function was added to the iov helper utils to allow passing a flag to the socket send call. Signed-off-by: Alejandro Zeise [ clg: - Handled qcrypto_afalg_hash_ctx_new() errors in qcrypto_afalg_hash_new() - Freed alg_name in qcrypto_afalg_hash_new() - Reworked qcrypto_afalg_recv_from_kernel() - Split iov changes from original patch ] Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/hash-afalg.c | 127 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/crypto/hash-afalg.c b/crypto/hash-afalg.c index 28ab899b18..5fbbee288e 100644 --- a/crypto/hash-afalg.c +++ b/crypto/hash-afalg.c @@ -1,6 +1,7 @@ /* * QEMU Crypto af_alg-backend hash/hmac support * + * Copyright (c) 2024 Seagate Technology LLC and/or its Affiliates * Copyright (c) 2017 HUAWEI TECHNOLOGIES CO., LTD. * * Authors: @@ -113,6 +114,128 @@ qcrypto_afalg_hmac_ctx_new(QCryptoHashAlgo alg, return qcrypto_afalg_hash_hmac_ctx_new(alg, key, nkey, true, errp); } =20 +static +QCryptoHash *qcrypto_afalg_hash_new(QCryptoHashAlgo alg, Error **errp) +{ + /* Check if hash algorithm is supported */ + char *alg_name =3D qcrypto_afalg_hash_format_name(alg, false, NULL); + QCryptoHash *hash; + + if (alg_name =3D=3D NULL) { + error_setg(errp, "Unknown hash algorithm %d", alg); + return NULL; + } + + g_free(alg_name); + + hash =3D g_new(QCryptoHash, 1); + hash->alg =3D alg; + hash->opaque =3D qcrypto_afalg_hash_ctx_new(alg, errp); + if (!hash->opaque) { + free(hash); + return NULL; + } + + return hash; +} + +static +void qcrypto_afalg_hash_free(QCryptoHash *hash) +{ + QCryptoAFAlg *ctx =3D hash->opaque; + + if (ctx) { + qcrypto_afalg_comm_free(ctx); + } + + g_free(hash); +} + +/** + * Send data to the kernel's crypto core. + * + * The more_data parameter is used to notify the crypto engine + * that this is an "update" operation, and that more data will + * be provided to calculate the final hash. + */ +static +int qcrypto_afalg_send_to_kernel(QCryptoAFAlg *afalg, + const struct iovec *iov, + size_t niov, + bool more_data, + Error **errp) +{ + int ret =3D 0; + int flags =3D (more_data ? MSG_MORE : 0); + + /* send data to kernel's crypto core */ + ret =3D iov_send_recv_with_flags(afalg->opfd, flags, iov, niov, + 0, iov_size(iov, niov), true); + if (ret < 0) { + error_setg_errno(errp, errno, "Send data to afalg-core failed"); + ret =3D -1; + } else { + /* No error, so return 0 */ + ret =3D 0; + } + + return ret; +} + +static +int qcrypto_afalg_recv_from_kernel(QCryptoAFAlg *afalg, + QCryptoHashAlgo alg, + uint8_t **result, + size_t *result_len, + Error **errp) +{ + struct iovec outv; + int ret; + const int expected_len =3D qcrypto_hash_digest_len(alg); + + if (*result_len =3D=3D 0) { + *result_len =3D expected_len; + *result =3D g_new0(uint8_t, *result_len); + } else if (*result_len !=3D expected_len) { + error_setg(errp, + "Result buffer size %zu is not match hash %d", + *result_len, expected_len); + return -1; + } + + /* hash && get result */ + outv.iov_base =3D *result; + outv.iov_len =3D *result_len; + ret =3D iov_send_recv(afalg->opfd, &outv, 1, + 0, iov_size(&outv, 1), false); + if (ret < 0) { + error_setg_errno(errp, errno, "Recv result from afalg-core failed"= ); + return -1; + } + + return 0; +} + +static +int qcrypto_afalg_hash_update(QCryptoHash *hash, + const struct iovec *iov, + size_t niov, + Error **errp) +{ + return qcrypto_afalg_send_to_kernel((QCryptoAFAlg *) hash->opaque, + iov, niov, true, errp); +} + +static +int qcrypto_afalg_hash_finalize(QCryptoHash *hash, + uint8_t **result, + size_t *result_len, + Error **errp) +{ + return qcrypto_afalg_recv_from_kernel((QCryptoAFAlg *) hash->opaque, + hash->alg, result, result_len, e= rrp); +} + static int qcrypto_afalg_hash_hmac_bytesv(QCryptoAFAlgo *hmac, QCryptoHashAlgo alg, @@ -205,6 +328,10 @@ static void qcrypto_afalg_hmac_ctx_free(QCryptoHmac *h= mac) =20 QCryptoHashDriver qcrypto_hash_afalg_driver =3D { .hash_bytesv =3D qcrypto_afalg_hash_bytesv, + .hash_new =3D qcrypto_afalg_hash_new, + .hash_free =3D qcrypto_afalg_hash_free, + .hash_update =3D qcrypto_afalg_hash_update, + .hash_finalize =3D qcrypto_afalg_hash_finalize }; =20 QCryptoHmacDriver qcrypto_hmac_afalg_driver =3D { --=20 2.46.0 From nobody Sat Nov 23 23:57:28 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=1728577468; cv=none; d=zohomail.com; s=zohoarc; b=agGqRIBUC5Jx4/bGj6t2m1AiYBwBYc4l8oZ9tswZE5ztMQr6Zk3oRvTrgzSDLBgi/A+Q/N1OEquRimNnx4qj9+ZzOL05fu5mrwA7aTsRD4l3lG8+tqiCdkDNt5JWG4JmFQ3eBepJ6wEtUL7oZFs/gOUOJhMZaj8lLIvkCyhYDo8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728577468; 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=T1r7GMIhVKgSZMZfmMxHoAmL/6vMk4PksaNooyNGPyY=; b=hrZGqO4QieRZWlCfRSZxXD3d4u538S4t4EafLpOuGsHN7O6ZQKy1AP4rnbVFQeomPyVyDOF7CbozJu0Hw97kpQNCOpRRPdlaxcGuVoa0FwdWs31S4SZj8Tp7rLEZ3nTV8tZmKjarUaFi3mL7T8WBcLUb3nWAJc1uQFzaIAqy2ys= 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 172857746827373.14153446314424; Thu, 10 Oct 2024 09:24:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syvvg-00071L-Ai; Thu, 10 Oct 2024 12:22:20 -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 1syvve-0006y4-DD for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:18 -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 1syvvc-0004Qg-C2 for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:18 -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-660-sRwN5x_ROnOsZO8pbJfQ9A-1; Thu, 10 Oct 2024 12:22:12 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 58DFD1955F29; Thu, 10 Oct 2024 16:22:11 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.110]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 927ED30001A0; Thu, 10 Oct 2024 16:22:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728577335; 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=T1r7GMIhVKgSZMZfmMxHoAmL/6vMk4PksaNooyNGPyY=; b=M1zCGt4VpzYdkh6ltmX6M0pKwT17ECNaxVe28ImunIyOtkjKgKfeXDgWFRX40gilY85G0A XrFCv46e5isAcrdi0051d7LbShuUd4bJiZhrKLQgea8C6PjxtaI1k61kFDJLwYnhglfTdw xFvlmdx4g0auCSg8Mx64+pmx2U59z5k= X-MC-Unique: sRwN5x_ROnOsZO8pbJfQ9A-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Kunwu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Alejandro Zeise , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 08/17] crypto/hash: Implement and use new hash API Date: Thu, 10 Oct 2024 17:20:15 +0100 Message-ID: <20241010162024.988284-9-berrange@redhat.com> In-Reply-To: <20241010162024.988284-1-berrange@redhat.com> References: <20241010162024.988284-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.4.1 on 10.30.177.4 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.149, 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 1728577470040116600 From: Alejandro Zeise Changes the public hash API implementation to support accumulative hashing. Implementations for the public functions are added to call the new driver functions that implement context creation, updating, finalization, and destruction. Additionally changes the "shortcut" functions to use these 4 new core functions. Signed-off-by: Alejandro Zeise [ clg: - Reworked qcrypto_hash_bytesv() error handling - Used hash->driver int qcrypto_hash_new(), qcrypto_hash_free() qcrypto_hash_updatev() - Introduced qcrypto_hash_supports() check in qcrypto_hash_new() - Introduced g_autofree variables in qcrypto_hash_finalize_digest() and qcrypto_hash_finalize_base64() - Re-arrranged code in qcrypto_hash_digestv() and qcrypto_hash_digest() - Checkpatch fixes ] Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/hash.c | 161 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 131 insertions(+), 30 deletions(-) diff --git a/crypto/hash.c b/crypto/hash.c index 4a265582b8..0c8548c568 100644 --- a/crypto/hash.c +++ b/crypto/hash.c @@ -1,6 +1,7 @@ /* * QEMU Crypto hash algorithms * + * Copyright (c) 2024 Seagate Technology LLC and/or its Affiliates * Copyright (c) 2015 Red Hat, Inc. * * This library is free software; you can redistribute it and/or @@ -19,6 +20,8 @@ */ =20 #include "qemu/osdep.h" +#include "qapi/error.h" +#include "qapi-types-crypto.h" #include "crypto/hash.h" #include "hashpriv.h" =20 @@ -45,23 +48,18 @@ int qcrypto_hash_bytesv(QCryptoHashAlgo alg, size_t *resultlen, Error **errp) { -#ifdef CONFIG_AF_ALG - int ret; - /* - * TODO: - * Maybe we should treat some afalg errors as fatal - */ - ret =3D qcrypto_hash_afalg_driver.hash_bytesv(alg, iov, niov, - result, resultlen, - NULL); - if (ret =3D=3D 0) { - return ret; + g_autoptr(QCryptoHash) ctx =3D qcrypto_hash_new(alg, errp); + + if (!ctx) { + return -1; + } + + if (qcrypto_hash_updatev(ctx, iov, niov, errp) < 0 || + qcrypto_hash_finalize_bytes(ctx, result, resultlen, errp) < 0) { + return -1; } -#endif =20 - return qcrypto_hash_lib_driver.hash_bytesv(alg, iov, niov, - result, resultlen, - errp); + return 0; } =20 =20 @@ -77,29 +75,130 @@ int qcrypto_hash_bytes(QCryptoHashAlgo alg, return qcrypto_hash_bytesv(alg, &iov, 1, result, resultlen, errp); } =20 +int qcrypto_hash_updatev(QCryptoHash *hash, + const struct iovec *iov, + size_t niov, + Error **errp) +{ + QCryptoHashDriver *drv =3D hash->driver; + + return drv->hash_update(hash, iov, niov, errp); +} + +int qcrypto_hash_update(QCryptoHash *hash, + const char *buf, + size_t len, + Error **errp) +{ + struct iovec iov =3D { .iov_base =3D (char *)buf, .iov_len =3D len }; + + return qcrypto_hash_updatev(hash, &iov, 1, errp); +} + +QCryptoHash *qcrypto_hash_new(QCryptoHashAlgo alg, Error **errp) +{ + QCryptoHash *hash =3D NULL; + + if (!qcrypto_hash_supports(alg)) { + error_setg(errp, "Unsupported hash algorithm %s", + QCryptoHashAlgo_str(alg)); + return NULL; + } + +#ifdef CONFIG_AF_ALG + hash =3D qcrypto_hash_afalg_driver.hash_new(alg, NULL); + if (hash) { + hash->driver =3D &qcrypto_hash_afalg_driver; + return hash; + } +#endif + + hash =3D qcrypto_hash_lib_driver.hash_new(alg, errp); + if (!hash) { + return NULL; + } + + hash->driver =3D &qcrypto_hash_lib_driver; + return hash; +} + +void qcrypto_hash_free(QCryptoHash *hash) +{ + QCryptoHashDriver *drv; + + if (hash) { + drv =3D hash->driver; + drv->hash_free(hash); + } +} + +int qcrypto_hash_finalize_bytes(QCryptoHash *hash, + uint8_t **result, + size_t *result_len, + Error **errp) +{ + QCryptoHashDriver *drv =3D hash->driver; + + return drv->hash_finalize(hash, result, result_len, errp); +} + static const char hex[] =3D "0123456789abcdef"; =20 +int qcrypto_hash_finalize_digest(QCryptoHash *hash, + char **digest, + Error **errp) +{ + int ret; + g_autofree uint8_t *result =3D NULL; + size_t resultlen =3D 0; + size_t i; + + ret =3D qcrypto_hash_finalize_bytes(hash, &result, &resultlen, errp); + if (ret =3D=3D 0) { + *digest =3D g_new0(char, (resultlen * 2) + 1); + for (i =3D 0 ; i < resultlen ; i++) { + (*digest)[(i * 2)] =3D hex[(result[i] >> 4) & 0xf]; + (*digest)[(i * 2) + 1] =3D hex[result[i] & 0xf]; + } + (*digest)[resultlen * 2] =3D '\0'; + } + + return ret; +} + +int qcrypto_hash_finalize_base64(QCryptoHash *hash, + char **base64, + Error **errp) +{ + int ret; + g_autofree uint8_t *result =3D NULL; + size_t resultlen =3D 0; + + ret =3D qcrypto_hash_finalize_bytes(hash, &result, &resultlen, errp); + if (ret =3D=3D 0) { + *base64 =3D g_base64_encode(result, resultlen); + } + + return ret; +} + int qcrypto_hash_digestv(QCryptoHashAlgo alg, const struct iovec *iov, size_t niov, char **digest, Error **errp) { - uint8_t *result =3D NULL; - size_t resultlen =3D 0; - size_t i; + g_autoptr(QCryptoHash) ctx =3D qcrypto_hash_new(alg, errp); =20 - if (qcrypto_hash_bytesv(alg, iov, niov, &result, &resultlen, errp) < 0= ) { + if (!ctx) { return -1; } =20 - *digest =3D g_new0(char, (resultlen * 2) + 1); - for (i =3D 0 ; i < resultlen ; i++) { - (*digest)[(i * 2)] =3D hex[(result[i] >> 4) & 0xf]; - (*digest)[(i * 2) + 1] =3D hex[result[i] & 0xf]; + if (qcrypto_hash_updatev(ctx, iov, niov, errp) < 0 || + qcrypto_hash_finalize_digest(ctx, digest, errp) < 0) { + return -1; } - (*digest)[resultlen * 2] =3D '\0'; - g_free(result); + return 0; } =20 @@ -120,15 +219,17 @@ int qcrypto_hash_base64v(QCryptoHashAlgo alg, char **base64, Error **errp) { - uint8_t *result =3D NULL; - size_t resultlen =3D 0; + g_autoptr(QCryptoHash) ctx =3D qcrypto_hash_new(alg, errp); + + if (!ctx) { + return -1; + } =20 - if (qcrypto_hash_bytesv(alg, iov, niov, &result, &resultlen, errp) < 0= ) { + if (qcrypto_hash_updatev(ctx, iov, niov, errp) < 0 || + qcrypto_hash_finalize_base64(ctx, base64, errp) < 0) { return -1; } =20 - *base64 =3D g_base64_encode(result, resultlen); - g_free(result); return 0; } =20 --=20 2.46.0 From nobody Sat Nov 23 23:57:28 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=1728577489; cv=none; d=zohomail.com; s=zohoarc; b=aB5T50GsyLDZQ2LFeIXUaCfA+9SKvuApEJ4gUK1fmCKZK0Zuuri25V1IsSjRZVhOwLOFZgjvQgF3ItIixgTPVaGSMr0cH/EcLlvylT415YL8XRMKm5keGxKPzYni3dwfa3XNXc23yihxfKwyZvzkYovFCWBP4PcssdlcH3nYuGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728577489; 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=6VE2N7b3gnGCDPqBULYRlMyPOe+yJdysz1T9lis10fY=; b=b+68BAZP40+7WrBfvhalocGtVt6glllAzIrQIdCzHs/TfZsKLaHBiHH9MYr2KKm+t2dkYSZpXdUOz42Ns2PGAMMQgf8t3SX6pTwnEQ+Vn82vV78aKWvhX0FvslxbTJK5L7DvO3NjIbt5Io+MBXVaJXUey8W3+TCOEEYef0VG3Nk= 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 1728577489592944.82566305703; Thu, 10 Oct 2024 09:24:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syvvi-00072a-G3; Thu, 10 Oct 2024 12:22:22 -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 1syvvg-00071T-Cx for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:20 -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 1syvve-0004Qx-PX for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:20 -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-253-Xk0LsqpYNbi9qRNdTJUJgg-1; Thu, 10 Oct 2024 12:22:14 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 B5E2C1955BCF; Thu, 10 Oct 2024 16:22:13 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.110]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CD32D30001A2; Thu, 10 Oct 2024 16:22:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728577338; 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=6VE2N7b3gnGCDPqBULYRlMyPOe+yJdysz1T9lis10fY=; b=d4cGfJXpa1fp4XUljrvZtJ6MjCYc4MDU2UgV0fFJctPYguhYqXIOVYWsB2eGcVJukjAL43 c5epqJ5EXNSTo++DC45f6+oP0XVEHhzbycAERZY38/UAgpyTT+tzucJT7hFNn52psUsq8O 9ZTYAJnOsm9/yNk6LaEnEAvzOWUDhjo= X-MC-Unique: Xk0LsqpYNbi9qRNdTJUJgg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Kunwu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Alejandro Zeise , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 09/17] tests/unit/test-crypto-hash: accumulative hashing Date: Thu, 10 Oct 2024 17:20:16 +0100 Message-ID: <20241010162024.988284-10-berrange@redhat.com> In-Reply-To: <20241010162024.988284-1-berrange@redhat.com> References: <20241010162024.988284-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.4.1 on 10.30.177.4 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.149, 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 1728577489963116600 From: Alejandro Zeise Added an accumulative hashing test. Checks for functionality of the new hash create, update, finalize and free functions. Signed-off-by: Alejandro Zeise [ clg: - Improved test_hash_accumulate() with g_autofree variables ] Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/unit/test-crypto-hash.c | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/unit/test-crypto-hash.c b/tests/unit/test-crypto-hash.c index 124d204485..e5829ca766 100644 --- a/tests/unit/test-crypto-hash.c +++ b/tests/unit/test-crypto-hash.c @@ -1,6 +1,7 @@ /* * QEMU Crypto hash algorithms * + * Copyright (c) 2024 Seagate Technology LLC and/or its Affiliates * Copyright (c) 2015 Red Hat, Inc. * * This library is free software; you can redistribute it and/or @@ -241,6 +242,50 @@ static void test_hash_base64(void) } } =20 +static void test_hash_accumulate(void) +{ + size_t i; + + for (i =3D 0; i < G_N_ELEMENTS(expected_outputs) ; i++) { + g_autoptr(QCryptoHash) hash =3D NULL; + struct iovec iov[] =3D { + { .iov_base =3D (char *)INPUT_TEXT1, .iov_len =3D strlen(INPUT= _TEXT1) }, + { .iov_base =3D (char *)INPUT_TEXT2, .iov_len =3D strlen(INPUT= _TEXT2) }, + { .iov_base =3D (char *)INPUT_TEXT3, .iov_len =3D strlen(INPUT= _TEXT3) }, + }; + g_autofree uint8_t *result =3D NULL; + size_t resultlen =3D 0; + int ret; + size_t j; + + if (!qcrypto_hash_supports(i)) { + continue; + } + + hash =3D qcrypto_hash_new(i, &error_fatal); + g_assert(hash !=3D NULL); + + /* Add each iovec to the hash context separately */ + for (j =3D 0; j < G_N_ELEMENTS(iov); j++) { + ret =3D qcrypto_hash_updatev(hash, + &iov[j], 1, + &error_fatal); + + g_assert(ret =3D=3D 0); + } + + ret =3D qcrypto_hash_finalize_bytes(hash, &result, &resultlen, + &error_fatal); + + g_assert(ret =3D=3D 0); + g_assert(resultlen =3D=3D expected_lens[i]); + for (j =3D 0; j < resultlen; j++) { + g_assert(expected_outputs[i][j * 2] =3D=3D hex[(result[j] >> 4= ) & 0xf]); + g_assert(expected_outputs[i][j * 2 + 1] =3D=3D hex[result[j] &= 0xf]); + } + } +} + int main(int argc, char **argv) { int ret =3D qcrypto_init(&error_fatal); @@ -252,5 +297,6 @@ int main(int argc, char **argv) g_test_add_func("/crypto/hash/prealloc", test_hash_prealloc); g_test_add_func("/crypto/hash/digest", test_hash_digest); g_test_add_func("/crypto/hash/base64", test_hash_base64); + g_test_add_func("/crypto/hash/accumulate", test_hash_accumulate); return g_test_run(); } --=20 2.46.0 From nobody Sat Nov 23 23:57:28 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=1728577410; cv=none; d=zohomail.com; s=zohoarc; b=iFFK7BcNiNqGsJkF8hB1WK+bOmtuzLZHRTXHhhzT038YkAAXncn1D23F3Q8bAx0TZi983w45AVW5lmldR+iywN8QK5tQA9TCgkgTtWOSz8HuQxIqFukkp5oI+jBjgFtQE8EcgJWIjR06P4Q5xC5DvPX+9hOtEqhpw0twZANcyXk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728577410; 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=TPFSRzGNJjnEKqcriP1dWRJwKWCmt7CdpH9nc6BP1+w=; b=kxxpGxoqfvdus0okMYJ0mtZ3/w3T9DoiKrcMJ283zLl2QrXckuJOp9XE5lkQ7+cqdAi9KW3cFKr12cHzWkPxstscC4Sj+PJd52gB/bS+dOfC09QDIIt4NvCOf0fHYvN+mwL5udB4S8F82KjiJkpMd53y8vNKV+kBQNzMgqmlF8k= 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 1728577410752577.8596517035506; Thu, 10 Oct 2024 09:23:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syvvk-00075b-5Y; Thu, 10 Oct 2024 12:22:24 -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 1syvvi-00072Z-Ev for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:22 -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 1syvvg-0004R8-RX for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22: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-211-XLdMcoiIP3GYTQt4gWf7Dw-1; Thu, 10 Oct 2024 12:22:16 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 132941955E85; Thu, 10 Oct 2024 16:22:16 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.110]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3BE9B300019E; Thu, 10 Oct 2024 16:22:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728577340; 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=TPFSRzGNJjnEKqcriP1dWRJwKWCmt7CdpH9nc6BP1+w=; b=PYYMFzrm4bTHtIejNoEf4Qiz1C4YtqxGGHskHToT5MATrLaJTKMI5qLkx2DtTOhlPJKzDs EXkwQMdUQqBGRNSa0QTEb+WEuBSCSYsdOiUVKXZJJrsaWTEIz+hn69ECvMFHx26LsBfY2F Sj/EHZO6Q9KLS+e9NRSpgNGCkXlkmpQ= X-MC-Unique: XLdMcoiIP3GYTQt4gWf7Dw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Kunwu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Alejandro Zeise , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 10/17] crypto/hash-glib: Remove old hash API functions Date: Thu, 10 Oct 2024 17:20:17 +0100 Message-ID: <20241010162024.988284-11-berrange@redhat.com> In-Reply-To: <20241010162024.988284-1-berrange@redhat.com> References: <20241010162024.988284-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.4.1 on 10.30.177.4 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.149, 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 1728577412081116601 From: Alejandro Zeise Removes old hash implement-ion in the GLib hash driver. Signed-off-by: Alejandro Zeise Reviewed-by: Daniel P. Berrang=C3=A9 [ clg: - Fixed spelling in commit log ] Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/hash-glib.c | 53 ---------------------------------------------- 1 file changed, 53 deletions(-) diff --git a/crypto/hash-glib.c b/crypto/hash-glib.c index 783283facc..02a6ec1edf 100644 --- a/crypto/hash-glib.c +++ b/crypto/hash-glib.c @@ -44,58 +44,6 @@ gboolean qcrypto_hash_supports(QCryptoHashAlgo alg) return false; } =20 - -static int -qcrypto_glib_hash_bytesv(QCryptoHashAlgo alg, - const struct iovec *iov, - size_t niov, - uint8_t **result, - size_t *resultlen, - Error **errp) -{ - int i, ret; - GChecksum *cs; - - if (!qcrypto_hash_supports(alg)) { - error_setg(errp, - "Unknown hash algorithm %d", - alg); - return -1; - } - - cs =3D g_checksum_new(qcrypto_hash_alg_map[alg]); - - for (i =3D 0; i < niov; i++) { - g_checksum_update(cs, iov[i].iov_base, iov[i].iov_len); - } - - ret =3D g_checksum_type_get_length(qcrypto_hash_alg_map[alg]); - if (ret < 0) { - error_setg(errp, "%s", - "Unable to get hash length"); - goto error; - } - if (*resultlen =3D=3D 0) { - *resultlen =3D ret; - *result =3D g_new0(uint8_t, *resultlen); - } else if (*resultlen !=3D ret) { - error_setg(errp, - "Result buffer size %zu is smaller than hash %d", - *resultlen, ret); - goto error; - } - - g_checksum_get_digest(cs, *result, resultlen); - - g_checksum_free(cs); - return 0; - - error: - g_checksum_free(cs); - return -1; -} - - static QCryptoHash *qcrypto_glib_hash_new(QCryptoHashAlgo alg, Error **errp) @@ -159,7 +107,6 @@ int qcrypto_glib_hash_finalize(QCryptoHash *hash, } =20 QCryptoHashDriver qcrypto_hash_lib_driver =3D { - .hash_bytesv =3D qcrypto_glib_hash_bytesv, .hash_new =3D qcrypto_glib_hash_new, .hash_update =3D qcrypto_glib_hash_update, .hash_finalize =3D qcrypto_glib_hash_finalize, --=20 2.46.0 From nobody Sat Nov 23 23:57:28 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=1728577487; cv=none; d=zohomail.com; s=zohoarc; b=emTIgFZXjs9oBP5MimbtWaI1ns6Apox6Ze+UwS3TqEAsGeBD75BcQZCu9Q/NulWSl0D+t2qf4YUop17j55VRrT4/Ay3RevLygYvWcgrduVG3p0qpgUoqGFw62asblb3cNH7MR5GIi6nRVB76wxR085zC7wu5rMWRgw4jwFns920= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728577487; 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=adXzG8LvJe6dfbUFZPglKn+WyDHmdoM9AgG+JuUeA0Y=; b=EQiCFOHPecpNEhEVmLhjD3uMAncRFidmuRMrNuUtBWDUzDfZez2K6cllYxKOLphyD6TzPC7hkoV2Jy7bYaR+SbwqNA07bu2fweR6FhXThVVaMaoIxNRfy2un+P728iFR7uPwB9RPe+D68JzY62mpNZxv97t2Nhs0v/PPSqVDlU0= 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 1728577487762494.9005093492036; Thu, 10 Oct 2024 09:24:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syvvo-00078a-2E; Thu, 10 Oct 2024 12:22:28 -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 1syvvm-00077k-G4 for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22: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 1syvvk-0004RS-5t for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:26 -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-199-UBE_IU-dO0WTc4IhZJr41w-1; Thu, 10 Oct 2024 12:22:19 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 3C6B31955F0B; Thu, 10 Oct 2024 16:22:18 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.110]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7BBA8300019E; Thu, 10 Oct 2024 16:22:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728577343; 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=adXzG8LvJe6dfbUFZPglKn+WyDHmdoM9AgG+JuUeA0Y=; b=dcFC11lWjg7jlT9kSJeCfENfjdXHw18H74DbzhxFtbOGdzNG/QRMJ9MLanMwRaDazG6whu vxAI2vw1vtbWmPjmt6lLX76r4PJRFfNBcwPLkwKq80lQe1H/Ce8IGP3ykwvCi86Cwo6i0Q 8a9RTK1UCfDMU0jj2iR87+YZ3V+LFqg= X-MC-Unique: UBE_IU-dO0WTc4IhZJr41w-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Kunwu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Alejandro Zeise , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 11/17] crypto/hash-gcrypt: Remove old hash API functions Date: Thu, 10 Oct 2024 17:20:18 +0100 Message-ID: <20241010162024.988284-12-berrange@redhat.com> In-Reply-To: <20241010162024.988284-1-berrange@redhat.com> References: <20241010162024.988284-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.4.1 on 10.30.177.4 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.149, 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 1728577487982116600 From: Alejandro Zeise Removes old hash implementation in the gcrypt hash driver. Signed-off-by: Alejandro Zeise Reviewed-by: Daniel P. Berrang=C3=A9 [ clg: - Fixed spelling in commit log ] Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/hash-gcrypt.c | 67 -------------------------------------------- 1 file changed, 67 deletions(-) diff --git a/crypto/hash-gcrypt.c b/crypto/hash-gcrypt.c index cb2cb37f25..ccc3cce3f8 100644 --- a/crypto/hash-gcrypt.c +++ b/crypto/hash-gcrypt.c @@ -45,72 +45,6 @@ gboolean qcrypto_hash_supports(QCryptoHashAlgo alg) return false; } =20 - -static int -qcrypto_gcrypt_hash_bytesv(QCryptoHashAlgo alg, - const struct iovec *iov, - size_t niov, - uint8_t **result, - size_t *resultlen, - Error **errp) -{ - int i, ret; - gcry_md_hd_t md; - unsigned char *digest; - - if (!qcrypto_hash_supports(alg)) { - error_setg(errp, - "Unknown hash algorithm %d", - alg); - return -1; - } - - ret =3D gcry_md_open(&md, qcrypto_hash_alg_map[alg], 0); - - if (ret < 0) { - error_setg(errp, - "Unable to initialize hash algorithm: %s", - gcry_strerror(ret)); - return -1; - } - - for (i =3D 0; i < niov; i++) { - gcry_md_write(md, iov[i].iov_base, iov[i].iov_len); - } - - ret =3D gcry_md_get_algo_dlen(qcrypto_hash_alg_map[alg]); - if (ret <=3D 0) { - error_setg(errp, - "Unable to get hash length: %s", - gcry_strerror(ret)); - goto error; - } - if (*resultlen =3D=3D 0) { - *resultlen =3D ret; - *result =3D g_new0(uint8_t, *resultlen); - } else if (*resultlen !=3D ret) { - error_setg(errp, - "Result buffer size %zu is smaller than hash %d", - *resultlen, ret); - goto error; - } - - digest =3D gcry_md_read(md, 0); - if (!digest) { - error_setg(errp, - "No digest produced"); - goto error; - } - memcpy(*result, digest, *resultlen); - - gcry_md_close(md); - return 0; - - error: - gcry_md_close(md); - return -1; -} - static QCryptoHash *qcrypto_gcrypt_hash_new(QCryptoHashAlgo alg, Error **errp) { @@ -187,7 +121,6 @@ int qcrypto_gcrypt_hash_finalize(QCryptoHash *hash, } =20 QCryptoHashDriver qcrypto_hash_lib_driver =3D { - .hash_bytesv =3D qcrypto_gcrypt_hash_bytesv, .hash_new =3D qcrypto_gcrypt_hash_new, .hash_update =3D qcrypto_gcrypt_hash_update, .hash_finalize =3D qcrypto_gcrypt_hash_finalize, --=20 2.46.0 From nobody Sat Nov 23 23:57:28 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=1728577383; cv=none; d=zohomail.com; s=zohoarc; b=ZlZHBeJZRrEUn+6Ja70cU9meMnC9J/z3B9ZQZE0KR2UTTiESPomUX0bBcz17iXAi+YfG5kImSeOPnQ4Z3ewPhTVIocUb3B91/vyXITb2iPwjBu2RUK/JKLOyE+0nKr48YVuVKry9jjxhuz/s/QLZunjSABUDu7axFWG5oF5pgJ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728577383; 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=aqrLAoI0oWR58BMTXMMQ4v/EEoL70QVPqpiPrfkJN/c=; b=jb+uLRAxlXTNCDpTiy1AGZb3QtmmB/rOwVjgX1qsdBsuVW+Ip8euJ7a/6G6e3RczsviKzyLu00/4f5/FbUvJ+WboetBxV6aeRqqcu2/ZEESqoekecsVTcA/bGqdUm9xYqdaOUQw1CcBSLMksEWPYq4j/dXYYKU8aJIz/P4ht06Q= 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 1728577383779920.7367496305217; Thu, 10 Oct 2024 09:23:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syvvn-00078N-2j; Thu, 10 Oct 2024 12:22:27 -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 1syvvl-000779-C9 for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:25 -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 1syvvj-0004RP-S9 for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:25 -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-32-7l7Hg11VOk64ByP9PesDyQ-1; Thu, 10 Oct 2024 12:22:21 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 198E31955F3C; Thu, 10 Oct 2024 16:22:20 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.110]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9AD83300019E; Thu, 10 Oct 2024 16:22:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728577343; 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=aqrLAoI0oWR58BMTXMMQ4v/EEoL70QVPqpiPrfkJN/c=; b=DYvH5SPqw68ycWn4KkZIH1RSsEDVxLIRwIZIMOpAghE0LNZgyW88VBk5HGX5IzjTatusHs z2e9UDyHnqU+zhjh3bzuBAXBnSYKz3PTz4LjPG+7lnBa/ofhXHN4PJGQM8rW2Vbc4CQxxO B069iJQj+VKfKkcwcswS+ZdbwgJKItI= X-MC-Unique: 7l7Hg11VOk64ByP9PesDyQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Kunwu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Alejandro Zeise , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 12/17] crypto/hash-gnutls: Remove old hash API functions Date: Thu, 10 Oct 2024 17:20:19 +0100 Message-ID: <20241010162024.988284-13-berrange@redhat.com> In-Reply-To: <20241010162024.988284-1-berrange@redhat.com> References: <20241010162024.988284-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.4.1 on 10.30.177.4 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.149, 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 1728577385477116600 From: Alejandro Zeise Removes old hash implementation in the gnutls hash driver. Signed-off-by: Alejandro Zeise Reviewed-by: Daniel P. Berrang=C3=A9 [ clg: - Fixed spelling in commit log ] Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/hash-gnutls.c | 47 -------------------------------------------- 1 file changed, 47 deletions(-) diff --git a/crypto/hash-gnutls.c b/crypto/hash-gnutls.c index 8b0327be82..34a63994c9 100644 --- a/crypto/hash-gnutls.c +++ b/crypto/hash-gnutls.c @@ -53,52 +53,6 @@ gboolean qcrypto_hash_supports(QCryptoHashAlgo alg) return false; } =20 - -static int -qcrypto_gnutls_hash_bytesv(QCryptoHashAlgo alg, - const struct iovec *iov, - size_t niov, - uint8_t **result, - size_t *resultlen, - Error **errp) -{ - int i, ret; - gnutls_hash_hd_t hash; - - if (!qcrypto_hash_supports(alg)) { - error_setg(errp, - "Unknown hash algorithm %d", - alg); - return -1; - } - - ret =3D gnutls_hash_get_len(qcrypto_hash_alg_map[alg]); - if (*resultlen =3D=3D 0) { - *resultlen =3D ret; - *result =3D g_new0(uint8_t, *resultlen); - } else if (*resultlen !=3D ret) { - error_setg(errp, - "Result buffer size %zu is smaller than hash %d", - *resultlen, ret); - return -1; - } - - ret =3D gnutls_hash_init(&hash, qcrypto_hash_alg_map[alg]); - if (ret < 0) { - error_setg(errp, - "Unable to initialize hash algorithm: %s", - gnutls_strerror(ret)); - return -1; - } - - for (i =3D 0; i < niov; i++) { - gnutls_hash(hash, iov[i].iov_base, iov[i].iov_len); - } - - gnutls_hash_deinit(hash, *result); - return 0; -} - static QCryptoHash *qcrypto_gnutls_hash_new(QCryptoHashAlgo alg, Error **errp) { @@ -174,7 +128,6 @@ int qcrypto_gnutls_hash_finalize(QCryptoHash *hash, } =20 QCryptoHashDriver qcrypto_hash_lib_driver =3D { - .hash_bytesv =3D qcrypto_gnutls_hash_bytesv, .hash_new =3D qcrypto_gnutls_hash_new, .hash_update =3D qcrypto_gnutls_hash_update, .hash_finalize =3D qcrypto_gnutls_hash_finalize, --=20 2.46.0 From nobody Sat Nov 23 23:57:28 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=1728577410; cv=none; d=zohomail.com; s=zohoarc; b=hO4kEhLJyJ8KhL/UJqFuYTjs1NdRtH259Y4EGwoYyc9+HZIDfG4CGw6BCF/f4KKXvo9e3425/iKr5fSvN+rxeInZBx4XkODxPBVFxyWfvtHAqPYfaH8ya9shNMRyDe/J7S1Zemrew7tqCaFY5PwUI8k6ScoLC4EBmgB1ioRQTyA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728577410; 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=kT3aGvUcuMqLA9BKCOREUSBudqYFPF5d/C7lc+Fqp0o=; b=Uv2V0Ig4ltbTe0FrBwdtZa0Vzmu2NDClRx+PQNzTb41dfliwZH1UtHrV40zvkxHnxBjxHNbBvD2W/STn6kQZy1c4lmkvxBb2Ohsl3habu87U7o3APulP/U3nHAI6X4i8FAAS8037DSyPMC+rvP+vL6Yeb1wY+IkAISTRLQEVAhk= 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 1728577410754277.9283392729252; Thu, 10 Oct 2024 09:23:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syvvp-00078w-0c; Thu, 10 Oct 2024 12:22: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 1syvvm-00077u-Pc for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22: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 1syvvl-0004Rb-Ct for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:26 -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-593-iXU3l2z-MROoYD5EzBg5GQ-1; Thu, 10 Oct 2024 12:22:23 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 7EDC11955DD4; Thu, 10 Oct 2024 16:22:22 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.110]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 85DD8300019E; Thu, 10 Oct 2024 16:22:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728577344; 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=kT3aGvUcuMqLA9BKCOREUSBudqYFPF5d/C7lc+Fqp0o=; b=I1fRd8lN3FalBSSXQC4feNDr0OgBLwVz2w+CGRVKaXPrFaRFKgoicTkDcGF2kTWQCmo9wD 0VbbchiILxFtxjNiq2VBFYNIGz+R4gOWcQ3wfojtrMxJQlALSvvhO4QQKkOu/wtL2BUDsD iJNznpZIR/P3pW5zWboNcRCbfYgEUPQ= X-MC-Unique: iXU3l2z-MROoYD5EzBg5GQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Kunwu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Alejandro Zeise , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 13/17] crypto/hash-nettle: Remove old hash API functions Date: Thu, 10 Oct 2024 17:20:20 +0100 Message-ID: <20241010162024.988284-14-berrange@redhat.com> In-Reply-To: <20241010162024.988284-1-berrange@redhat.com> References: <20241010162024.988284-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.4.1 on 10.30.177.4 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.149, 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 1728577412069116600 From: Alejandro Zeise Removes old hash implementation in the nettle hash driver. Signed-off-by: Alejandro Zeise Reviewed-by: Daniel P. Berrang=C3=A9 [ clg: - Fixed spelling in commit log ] Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/hash-nettle.c | 53 -------------------------------------------- 1 file changed, 53 deletions(-) diff --git a/crypto/hash-nettle.c b/crypto/hash-nettle.c index 07e18ce26c..570ce8a645 100644 --- a/crypto/hash-nettle.c +++ b/crypto/hash-nettle.c @@ -104,58 +104,6 @@ gboolean qcrypto_hash_supports(QCryptoHashAlgo alg) return false; } =20 - -static int -qcrypto_nettle_hash_bytesv(QCryptoHashAlgo alg, - const struct iovec *iov, - size_t niov, - uint8_t **result, - size_t *resultlen, - Error **errp) -{ - size_t i; - union qcrypto_hash_ctx ctx; - - if (!qcrypto_hash_supports(alg)) { - error_setg(errp, - "Unknown hash algorithm %d", - alg); - return -1; - } - - qcrypto_hash_alg_map[alg].init(&ctx); - - for (i =3D 0; i < niov; i++) { - /* Some versions of nettle have functions - * declared with 'int' instead of 'size_t' - * so to be safe avoid writing more than - * UINT_MAX bytes at a time - */ - size_t len =3D iov[i].iov_len; - uint8_t *base =3D iov[i].iov_base; - while (len) { - size_t shortlen =3D MIN(len, UINT_MAX); - qcrypto_hash_alg_map[alg].write(&ctx, len, base); - len -=3D shortlen; - base +=3D len; - } - } - - if (*resultlen =3D=3D 0) { - *resultlen =3D qcrypto_hash_alg_map[alg].len; - *result =3D g_new0(uint8_t, *resultlen); - } else if (*resultlen !=3D qcrypto_hash_alg_map[alg].len) { - error_setg(errp, - "Result buffer size %zu is smaller than hash %zu", - *resultlen, qcrypto_hash_alg_map[alg].len); - return -1; - } - - qcrypto_hash_alg_map[alg].result(&ctx, *resultlen, *result); - - return 0; -} - static QCryptoHash *qcrypto_nettle_hash_new(QCryptoHashAlgo alg, Error **errp) { @@ -223,7 +171,6 @@ int qcrypto_nettle_hash_finalize(QCryptoHash *hash, } =20 QCryptoHashDriver qcrypto_hash_lib_driver =3D { - .hash_bytesv =3D qcrypto_nettle_hash_bytesv, .hash_new =3D qcrypto_nettle_hash_new, .hash_update =3D qcrypto_nettle_hash_update, .hash_finalize =3D qcrypto_nettle_hash_finalize, --=20 2.46.0 From nobody Sat Nov 23 23:57:28 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=1728577419; cv=none; d=zohomail.com; s=zohoarc; b=EXpDvp0TYw8qdfJLpdWCemmLAVFho2LqS7dD7/E/7eF7MKiLZFEhCjY/yctnCq36lZR84qvJHd8r1wWTWKgzCcLCk2FdIwG8bBjMEcuZMj+paGUSUplsD1RhASPA5wdlByaPiwGZGZhe3Dkyeh/x4iXfh9tB072r/wjrrlplhtw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728577419; 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=gwgRKz6GHLRqIlZYfi0xf71cuEfn8qqoNVSC9DtzHd8=; b=iJkoVtKy+Y1NUUO3xp7RKZqyOei82n78NQknROmeAJBUxppnd9xhsJfEi30voGgkF8P6Pt12Gy20kzZoZp76eUsWi1ng3bI1XLqQ3Dfds17SHQz5kmLFzh/NIS2u35fSPSrRB+W6VUOa+cANxpB3BFQ2Ujjcc2jkvzGUTQL+6Qs= 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 1728577419198821.3270047583408; Thu, 10 Oct 2024 09:23:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syvvr-00079g-OZ; Thu, 10 Oct 2024 12:22:31 -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 1syvvq-00079P-F6 for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:30 -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 1syvvo-0004SK-JK for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:30 -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-85-of6Ce9JiPGWsLlfE6-Wtsw-1; Thu, 10 Oct 2024 12:22:26 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 AB20919560B8; Thu, 10 Oct 2024 16:22:25 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.110]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 19AD5300019E; Thu, 10 Oct 2024 16:22:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728577347; 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=gwgRKz6GHLRqIlZYfi0xf71cuEfn8qqoNVSC9DtzHd8=; b=JlsQ9TKBzrpa3IZaNnUYoBYQJqnDo0xpZSu4wPfQB0cvKnSf/+jLYd4iqFlrwCQTbhspDB WN58Q89yf64GvHVpZmLBJmtSHFpk2Bwbe+B/GKPQCcL57paINEFpe5EZ8ysnUxVQ2KZtvm +qiu3r1IgUEUGQf0Mr0eJCOpv6fheVw= X-MC-Unique: of6Ce9JiPGWsLlfE6-Wtsw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Kunwu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Alejandro Zeise , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 14/17] crypto/hash-afalg: Remove old hash API functions Date: Thu, 10 Oct 2024 17:20:21 +0100 Message-ID: <20241010162024.988284-15-berrange@redhat.com> In-Reply-To: <20241010162024.988284-1-berrange@redhat.com> References: <20241010162024.988284-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.4.1 on 10.30.177.4 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.149, 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 1728577419676116600 From: Alejandro Zeise Removes the old hash API functions in the afalg driver, and modifies the hmac function to use the new helper functions. Signed-off-by: Alejandro Zeise Reviewed-by: Daniel P. Berrang=C3=A9 [ clg: - Checkpatch fixes ] Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/hash-afalg.c | 60 +++------------------------------------------ 1 file changed, 4 insertions(+), 56 deletions(-) diff --git a/crypto/hash-afalg.c b/crypto/hash-afalg.c index 5fbbee288e..06e1e4699c 100644 --- a/crypto/hash-afalg.c +++ b/crypto/hash-afalg.c @@ -244,68 +244,17 @@ qcrypto_afalg_hash_hmac_bytesv(QCryptoAFAlgo *hmac, size_t *resultlen, Error **errp) { - QCryptoAFAlgo *afalg; - struct iovec outv; int ret =3D 0; - bool is_hmac =3D (hmac !=3D NULL) ? true : false; - const int expect_len =3D qcrypto_hash_digest_len(alg); - - if (*resultlen =3D=3D 0) { - *resultlen =3D expect_len; - *result =3D g_new0(uint8_t, *resultlen); - } else if (*resultlen !=3D expect_len) { - error_setg(errp, - "Result buffer size %zu is not match hash %d", - *resultlen, expect_len); - return -1; - } - - if (is_hmac) { - afalg =3D hmac; - } else { - afalg =3D qcrypto_afalg_hash_ctx_new(alg, errp); - if (!afalg) { - return -1; - } - } - - /* send data to kernel's crypto core */ - ret =3D iov_send_recv(afalg->opfd, iov, niov, - 0, iov_size(iov, niov), true); - if (ret < 0) { - error_setg_errno(errp, errno, "Send data to afalg-core failed"); - goto out; - } =20 - /* hash && get result */ - outv.iov_base =3D *result; - outv.iov_len =3D *resultlen; - ret =3D iov_send_recv(afalg->opfd, &outv, 1, - 0, iov_size(&outv, 1), false); - if (ret < 0) { - error_setg_errno(errp, errno, "Recv result from afalg-core failed"= ); - } else { - ret =3D 0; + ret =3D qcrypto_afalg_send_to_kernel(hmac, iov, niov, false, errp); + if (ret =3D=3D 0) { + ret =3D qcrypto_afalg_recv_from_kernel(hmac, alg, result, + resultlen, errp); } =20 -out: - if (!is_hmac) { - qcrypto_afalg_comm_free(afalg); - } return ret; } =20 -static int -qcrypto_afalg_hash_bytesv(QCryptoHashAlgo alg, - const struct iovec *iov, - size_t niov, uint8_t **result, - size_t *resultlen, - Error **errp) -{ - return qcrypto_afalg_hash_hmac_bytesv(NULL, alg, iov, niov, result, - resultlen, errp); -} - static int qcrypto_afalg_hmac_bytesv(QCryptoHmac *hmac, const struct iovec *iov, @@ -327,7 +276,6 @@ static void qcrypto_afalg_hmac_ctx_free(QCryptoHmac *hm= ac) } =20 QCryptoHashDriver qcrypto_hash_afalg_driver =3D { - .hash_bytesv =3D qcrypto_afalg_hash_bytesv, .hash_new =3D qcrypto_afalg_hash_new, .hash_free =3D qcrypto_afalg_hash_free, .hash_update =3D qcrypto_afalg_hash_update, --=20 2.46.0 From nobody Sat Nov 23 23:57:28 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=1728577382; cv=none; d=zohomail.com; s=zohoarc; b=HBhS/dZq3UFhSEia5xOruGmil7g9HC+s46kCODeK/of3JurGIYw/DoTNWsM8+541Y3cKqR5owGzaRiXm2WOqh0k6uI+GeQ+XC8Rcca0zUUZxn0C7NFTiAWSFhGDaWa5IMfpklmfsKuknQRszG3HhDwk1eYNmhrUAVcalQyup1OM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728577382; 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=wF9QRPEGMuhdilvkPb9bzFPO8tFf47gNOLwZa6JJpyU=; b=ORN6CSU1BLQsU8PXBsS2drRi4FEadVXqbADGCeVPAPuGilSdkPi03FDYZ5L3YWrq9vqwSzC7CVutq9na+/PNvnaGL0ABTb7JDQyefvNcddYOEXG1vXymEG7stAf5n+NMFvAA5yDWMs3oPNV9GvNWE0cHDqYaxBoNkC1cdOc6llw= 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 1728577382902978.1468344152954; Thu, 10 Oct 2024 09:23:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syvvu-0007Ii-M2; Thu, 10 Oct 2024 12:22:34 -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 1syvvt-0007C8-5K for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:33 -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 1syvvr-0004SX-Oo for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:32 -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-58-pWxbUVomPD6nTlZ2ooxzjQ-1; Thu, 10 Oct 2024 12:22:29 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 5B6D01955D5D; Thu, 10 Oct 2024 16:22:28 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.110]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2B83B300019E; Thu, 10 Oct 2024 16:22:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728577350; 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=wF9QRPEGMuhdilvkPb9bzFPO8tFf47gNOLwZa6JJpyU=; b=USxSnNdXB79SSYxXRCmdODPdOUd5KHBwmUh7FzWIbi8bwWDdEFAmKKqUTY+H60hSGEjGAT 5lkx0L288QOwBMLs69YYwdymsXrWMpBhhlcijt5g4Yy5Dc0A6UMFX03cVkUbKDUUVYWaTg Rfm7kYqHQkSQM9McuUOdvNtd9vKZB/s= X-MC-Unique: pWxbUVomPD6nTlZ2ooxzjQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Kunwu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Alejandro Zeise , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 15/17] crypto/hashpriv: Remove old hash API function Date: Thu, 10 Oct 2024 17:20:22 +0100 Message-ID: <20241010162024.988284-16-berrange@redhat.com> In-Reply-To: <20241010162024.988284-1-berrange@redhat.com> References: <20241010162024.988284-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.4.1 on 10.30.177.4 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.149, 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 1728577385119116600 From: Alejandro Zeise Remove old hash_bytesv function, as it was replaced by the 4 new functions. Signed-off-by: Alejandro Zeise Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/hashpriv.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/crypto/hashpriv.h b/crypto/hashpriv.h index dcb3ba6cfb..83b9256886 100644 --- a/crypto/hashpriv.h +++ b/crypto/hashpriv.h @@ -21,12 +21,6 @@ typedef struct QCryptoHashDriver QCryptoHashDriver; =20 struct QCryptoHashDriver { - int (*hash_bytesv)(QCryptoHashAlgo alg, - const struct iovec *iov, - size_t niov, - uint8_t **result, - size_t *resultlen, - Error **errp); QCryptoHash *(*hash_new)(QCryptoHashAlgo alg, Error **errp); int (*hash_update)(QCryptoHash *hash, const struct iovec *iov, --=20 2.46.0 From nobody Sat Nov 23 23:57:28 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=1728577497; cv=none; d=zohomail.com; s=zohoarc; b=nufBZLPlJsGF9JERU5DWfj/Xy3P0pDFRKDad3+PCemDVtJU6xT8eh0a+RF0ezyrye3HH0lxQGzzmeEVa4VnFRsS0Ry4Xm94KRYuuGvJnHw2LWp+nti3c4L1Ovl2hvoMFCxwWiqsqRkM4AFbkQgfoVL9cPRLkmk2wMX7nVD3930c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728577497; 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=71uaZAVxed2j73esQn+ELmkq4ReV6bG/nUPeWerSj+A=; b=ZhbOeZinqJrRYIq2/41xwqrzR3K2onsSsLWqE8I93sth8JreN2yUcFQmpOm3BVLaw8gDmQItnF+vL7kLP729zHCCCiebsVAyFdx/436o8fyh7ObywyWo+XEunCs7ATF14hzSMdsMozmZMtHSHqVe7tUViAMaZGKCgd1pKCFq/V8= 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 1728577497758999.5488978780253; Thu, 10 Oct 2024 09:24:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syvvy-0007RU-NY; Thu, 10 Oct 2024 12:22:38 -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 1syvvw-0007NP-DX for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22: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 1syvvv-0004Sj-0E for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:36 -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-435-_NB2KSWcPVeNu2L2ES5-9Q-1; Thu, 10 Oct 2024 12:22:31 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 97BDB1955F40; Thu, 10 Oct 2024 16:22:30 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.110]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CFB0930001A2; Thu, 10 Oct 2024 16:22:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728577353; 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=71uaZAVxed2j73esQn+ELmkq4ReV6bG/nUPeWerSj+A=; b=a2vHr1UeHoRSYYC35pl9BuwgtHvzrZNFQatr9rixGReIX/8eybkTuyKv+kL6c0ruJyoFhO 8jdTNGL9xp4vSEECrOeZYPP9oR1yL++NRaGEuNF8dceNQHDDFnM87Dx3hPgRKPPF5HJ9g5 HBpikwLrlhM+BgRtwkwVhTUmmFhiUWY= X-MC-Unique: _NB2KSWcPVeNu2L2ES5-9Q-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Kunwu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 16/17] crypto: drop obsolete back compat logic for old nettle Date: Thu, 10 Oct 2024 17:20:23 +0100 Message-ID: <20241010162024.988284-17-berrange@redhat.com> In-Reply-To: <20241010162024.988284-1-berrange@redhat.com> References: <20241010162024.988284-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.4.1 on 10.30.177.4 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.149, 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 1728577497984116600 The nettle 2.x series declared all the hash functions with 'int' for the data size. Since we dropped support for anything older than 3.4 we can assume nettle is using 'size_t' and thus avoid the back compat looping logic. Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/hash-nettle.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/crypto/hash-nettle.c b/crypto/hash-nettle.c index 570ce8a645..3b847aa60e 100644 --- a/crypto/hash-nettle.c +++ b/crypto/hash-nettle.c @@ -135,20 +135,9 @@ int qcrypto_nettle_hash_update(QCryptoHash *hash, union qcrypto_hash_ctx *ctx =3D hash->opaque; =20 for (int i =3D 0; i < niov; i++) { - /* - * Some versions of nettle have functions - * declared with 'int' instead of 'size_t' - * so to be safe avoid writing more than - * UINT_MAX bytes at a time - */ - size_t len =3D iov[i].iov_len; - uint8_t *base =3D iov[i].iov_base; - while (len) { - size_t shortlen =3D MIN(len, UINT_MAX); - qcrypto_hash_alg_map[hash->alg].write(ctx, len, base); - len -=3D shortlen; - base +=3D len; - } + qcrypto_hash_alg_map[hash->alg].write(ctx, + iov[i].iov_len, + iov[i].iov_base); } =20 return 0; --=20 2.46.0 From nobody Sat Nov 23 23:57:28 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=1728577461; cv=none; d=zohomail.com; s=zohoarc; b=LI/M5InAdFzdjuZqWPrRPdu89aX5gGlZw5tl+RQJFUsnjcsAT2J6Ha6bvc/9KV2V4vwCLJrdnAnFtoIppuI6xKXQRdvkU53qLXiNy6073Cyi5RnEgr845JB3gLKimBWZz42O0wktsY7iOnqo+gc4vASH8qhMKPOoRSG7LOoLUMw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728577461; 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=5VWloR28x5LlrrjeHXM5rNK/TmM9ut1vbut5rV1y9TI=; b=YPRLuxptEjnS9SuZoAodTBUXjtuHOh4TtPwpCHwgBEjaPYFgIVSMwvM+lz76NdgwGNXnsgFAD+YtLChqW5aWcu7dcVx0ezmX8UrVoNjdzE4nOERz3H5vCk6iZQHjg5/ex/U1TnAkDXCBdFRSxvIYlk4jW+OoncA/UHmO5wsCWzE= 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 172857746128752.57550784461853; Thu, 10 Oct 2024 09:24:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syvvz-0007Rq-1S; Thu, 10 Oct 2024 12:22:39 -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 1syvvy-0007Qu-1l for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:38 -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 1syvvw-0004T4-L1 for qemu-devel@nongnu.org; Thu, 10 Oct 2024 12:22:37 -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-74-TO1zahhzMzK7hEhE_eXDrw-1; Thu, 10 Oct 2024 12:22:33 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 D3DF51955BC9; Thu, 10 Oct 2024 16:22:32 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.110]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 17D4D300019E; Thu, 10 Oct 2024 16:22:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728577356; 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=5VWloR28x5LlrrjeHXM5rNK/TmM9ut1vbut5rV1y9TI=; b=E+hjDdcU+nhaXIXhjuIGmU67scS7djBMVLwdO4oLZck7teiOkj/RHAyYwDMIaWIp2+Q/mP WLkH98nfDLu3CnGhlpWk68XTG69rES0G4o6pWDqp6yynMEnW6AX3CeGwdIVOTW7srOhkQh vXBSV8DIt7ySMBnLQ1wnqY6NiwKrd6g= X-MC-Unique: TO1zahhzMzK7hEhE_eXDrw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Kunwu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 17/17] tests/unit: Add a assert for test_io_channel_unix_listen_cleanup Date: Thu, 10 Oct 2024 17:20:24 +0100 Message-ID: <20241010162024.988284-18-berrange@redhat.com> In-Reply-To: <20241010162024.988284-1-berrange@redhat.com> References: <20241010162024.988284-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.4.1 on 10.30.177.4 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.149, 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 1728577461858116600 From: Kunwu Calling bind without checking return value. Add a assert for it. Signed-off-by: Kunwu Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/unit/test-io-channel-socket.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/unit/test-io-channel-socket.c b/tests/unit/test-io-chann= el-socket.c index b964bb202d..dc7be96e9c 100644 --- a/tests/unit/test-io-channel-socket.c +++ b/tests/unit/test-io-channel-socket.c @@ -506,7 +506,7 @@ static void test_io_channel_unix_listen_cleanup(void) { QIOChannelSocket *ioc; struct sockaddr_un un; - int sock; + int sock, ret =3D 0; =20 #define TEST_SOCKET "test-io-channel-socket.sock" =20 @@ -519,7 +519,9 @@ static void test_io_channel_unix_listen_cleanup(void) un.sun_family =3D AF_UNIX; snprintf(un.sun_path, sizeof(un.sun_path), "%s", TEST_SOCKET); unlink(TEST_SOCKET); - bind(sock, (struct sockaddr *)&un, sizeof(un)); + ret =3D bind(sock, (struct sockaddr *)&un, sizeof(un)); + g_assert_cmpint(ret, =3D=3D, 0); + ioc->fd =3D sock; ioc->localAddrLen =3D sizeof(ioc->localAddr); getsockname(sock, (struct sockaddr *)&ioc->localAddr, --=20 2.46.0