qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PULL 00/17] Crypto fixes patches
@ 2024-10-10 16:20 Daniel P. Berrangé
  2024-10-10 16:20 ` [PULL 01/17] crypto: accumulative hashing API Daniel P. Berrangé
                   ` (17 more replies)
  0 siblings, 18 replies; 23+ messages in thread
From: Daniel P. Berrangé @ 2024-10-10 16:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kunwu, Cédric Le Goater, Daniel P. Berrangé

The following changes since commit 838fc0a8769d7cc6edfe50451ba4e3368395f5c1:

  Merge tag 'chr-pull-request' of https://gitlab.com/marcandre.lureau/qemu into staging (2024-10-09 15:06:56 +0100)

are available in the Git repository at:

  https://gitlab.com/berrange/qemu tags/crypto-fixes-pull-request

for you to fetch changes up to 08e702043fbee7b366d1d27c1b6682090c46c0d6:

  tests/unit: Add a assert for test_io_channel_unix_listen_cleanup (2024-10-10 13:41:45 +0100)

----------------------------------------------------------------
Introduce new cryptography hashing APIs

----------------------------------------------------------------

Alejandro Zeise (15):
  crypto: accumulative hashing API
  crypto/hash-glib: Implement new hash API
  crypto/hash-gcrypt: Implement new hash API
  crypto/hash-gnutls: Implement new hash API
  crypto/hash-nettle: Implement new hash API
  util/iov: Introduce iov_send_recv_with_flags()
  crypto/hash-afalg: Implement new hash API
  crypto/hash: Implement and use new hash API
  tests/unit/test-crypto-hash: accumulative hashing
  crypto/hash-glib: Remove old hash API functions
  crypto/hash-gcrypt: Remove old hash API functions
  crypto/hash-gnutls: Remove old hash API functions
  crypto/hash-nettle: Remove old hash API functions
  crypto/hash-afalg: Remove old hash API functions
  crypto/hashpriv: Remove old hash API function

Daniel P. Berrangé (1):
  crypto: drop obsolete back compat logic for old nettle

Kunwu (1):
  tests/unit: Add a assert for test_io_channel_unix_listen_cleanup

 crypto/hash-afalg.c                 | 167 ++++++++++++++++++++--------
 crypto/hash-gcrypt.c                | 112 ++++++++++---------
 crypto/hash-glib.c                  |  92 ++++++++-------
 crypto/hash-gnutls.c                |  97 ++++++++++------
 crypto/hash-nettle.c                |  94 ++++++++--------
 crypto/hash.c                       | 161 ++++++++++++++++++++++-----
 crypto/hashpriv.h                   |  13 ++-
 include/crypto/hash.h               | 119 ++++++++++++++++++++
 include/qemu/iov.h                  |  27 +++++
 tests/unit/test-crypto-hash.c       |  46 ++++++++
 tests/unit/test-io-channel-socket.c |   6 +-
 util/iov.c                          |  25 +++--
 12 files changed, 705 insertions(+), 254 deletions(-)

-- 
2.46.0



^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PULL 01/17] crypto: accumulative hashing API
  2024-10-10 16:20 [PULL 00/17] Crypto fixes patches Daniel P. Berrangé
@ 2024-10-10 16:20 ` Daniel P. Berrangé
  2024-10-10 16:20 ` [PULL 02/17] crypto/hash-glib: Implement new hash API Daniel P. Berrangé
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Daniel P. Berrangé @ 2024-10-10 16:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kunwu, Cédric Le Goater, Alejandro Zeise,
	Daniel P. Berrangé

From: Alejandro Zeise <alejandro.zeise@seagate.com>

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 <alejandro.zeise@seagate.com>
[ clg: - Changed documentation "non-zero on error" -> "-1 on error" ]
Signed-off-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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
 
+#include "crypto/hash.h"
+
 typedef struct QCryptoHashDriver QCryptoHashDriver;
 
 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);
 };
 
 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 @@
 
 /* See also "QCryptoHashAlgo" defined in qapi/crypto.json */
 
+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);
 
+/**
+ * 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 function.
+ * 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 function.
+ * The @base64 pointer will be filled with the base64 encoding of the computed
+ * 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 function.
+ * 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
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PULL 02/17] crypto/hash-glib: Implement new hash API
  2024-10-10 16:20 [PULL 00/17] Crypto fixes patches Daniel P. Berrangé
  2024-10-10 16:20 ` [PULL 01/17] crypto: accumulative hashing API Daniel P. Berrangé
@ 2024-10-10 16:20 ` Daniel P. Berrangé
  2024-10-10 16:20 ` [PULL 03/17] crypto/hash-gcrypt: " Daniel P. Berrangé
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Daniel P. Berrangé @ 2024-10-10 16:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kunwu, Cédric Le Goater, Alejandro Zeise,
	Daniel P. Berrangé

From: Alejandro Zeise <alejandro.zeise@seagate.com>

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 <alejandro.zeise@seagate.com>
[ 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édric Le Goater <clg@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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,
 }
 
 
+static
+QCryptoHash *qcrypto_glib_hash_new(QCryptoHashAlgo alg,
+                                   Error **errp)
+{
+    QCryptoHash *hash;
+
+    hash = g_new(QCryptoHash, 1);
+    hash->alg = alg;
+    hash->opaque = 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 = hash->opaque;
+
+    for (int i = 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 = hash->opaque;
+
+    ret = g_checksum_type_get_length(qcrypto_hash_alg_map[hash->alg]);
+    if (ret < 0) {
+        error_setg(errp, "Unable to get hash length");
+        *result_len = 0;
+        return -1;
+    }
+
+    *result_len = ret;
+    *result = g_new(uint8_t, *result_len);
+
+    g_checksum_get_digest(ctx, *result, result_len);
+    return 0;
+}
+
 QCryptoHashDriver qcrypto_hash_lib_driver = {
     .hash_bytesv = qcrypto_glib_hash_bytesv,
+    .hash_new      = qcrypto_glib_hash_new,
+    .hash_update   = qcrypto_glib_hash_update,
+    .hash_finalize = qcrypto_glib_hash_finalize,
+    .hash_free     = qcrypto_glib_hash_free,
 };
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PULL 03/17] crypto/hash-gcrypt: Implement new hash API
  2024-10-10 16:20 [PULL 00/17] Crypto fixes patches Daniel P. Berrangé
  2024-10-10 16:20 ` [PULL 01/17] crypto: accumulative hashing API Daniel P. Berrangé
  2024-10-10 16:20 ` [PULL 02/17] crypto/hash-glib: Implement new hash API Daniel P. Berrangé
@ 2024-10-10 16:20 ` Daniel P. Berrangé
  2024-10-10 16:20 ` [PULL 04/17] crypto/hash-gnutls: " Daniel P. Berrangé
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Daniel P. Berrangé @ 2024-10-10 16:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kunwu, Cédric Le Goater, Alejandro Zeise,
	Daniel P. Berrangé

From: Alejandro Zeise <alejandro.zeise@seagate.com>

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 <alejandro.zeise@seagate.com>
[ 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édric Le Goater <clg@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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;
 }
 
+static
+QCryptoHash *qcrypto_gcrypt_hash_new(QCryptoHashAlgo alg, Error **errp)
+{
+    QCryptoHash *hash;
+    int ret;
+
+    hash = g_new(QCryptoHash, 1);
+    hash->alg = alg;
+    hash->opaque = g_new(gcry_md_hd_t, 1);
+
+    ret = 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 = 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 = hash->opaque;
+
+    for (int i = 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 = hash->opaque;
+
+    *result_len = gcry_md_get_algo_dlen(qcrypto_hash_alg_map[hash->alg]);
+    if (*result_len == 0) {
+        error_setg(errp, "Unable to get hash length");
+        return -1;
+    }
+
+    *result = g_new(uint8_t, *result_len);
+
+    /* Digest is freed by gcry_md_close(), copy it */
+    digest = gcry_md_read(*ctx, 0);
+    memcpy(*result, digest, *result_len);
+    return 0;
+}
 
 QCryptoHashDriver qcrypto_hash_lib_driver = {
     .hash_bytesv = qcrypto_gcrypt_hash_bytesv,
+    .hash_new      = qcrypto_gcrypt_hash_new,
+    .hash_update   = qcrypto_gcrypt_hash_update,
+    .hash_finalize = qcrypto_gcrypt_hash_finalize,
+    .hash_free     = qcrypto_gcrypt_hash_free,
 };
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PULL 04/17] crypto/hash-gnutls: Implement new hash API
  2024-10-10 16:20 [PULL 00/17] Crypto fixes patches Daniel P. Berrangé
                   ` (2 preceding siblings ...)
  2024-10-10 16:20 ` [PULL 03/17] crypto/hash-gcrypt: " Daniel P. Berrangé
@ 2024-10-10 16:20 ` Daniel P. Berrangé
  2024-10-10 16:20 ` [PULL 05/17] crypto/hash-nettle: " Daniel P. Berrangé
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Daniel P. Berrangé @ 2024-10-10 16:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kunwu, Cédric Le Goater, Alejandro Zeise,
	Daniel P. Berrangé

From: Alejandro Zeise <alejandro.zeise@seagate.com>

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 <alejandro.zeise@seagate.com>
[ 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édric Le Goater <clg@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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;
 }
 
+static
+QCryptoHash *qcrypto_gnutls_hash_new(QCryptoHashAlgo alg, Error **errp)
+{
+    QCryptoHash *hash;
+    int ret;
+
+    hash = g_new(QCryptoHash, 1);
+    hash->alg = alg;
+    hash->opaque = g_new(gnutls_hash_hd_t, 1);
+
+    ret = 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 = 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 = 0;
+    gnutls_hash_hd_t *ctx = hash->opaque;
+
+    for (int i = 0; i < niov; i++) {
+        ret = gnutls_hash(*ctx, iov[i].iov_base, iov[i].iov_len);
+        if (ret != 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 = hash->opaque;
+
+    *result_len = gnutls_hash_get_len(qcrypto_hash_alg_map[hash->alg]);
+    if (*result_len == 0) {
+        error_setg(errp, "Unable to get hash length");
+        return -1;
+    }
+
+    *result = g_new(uint8_t, *result_len);
+    gnutls_hash_output(*ctx, *result);
+    return 0;
+}
 
 QCryptoHashDriver qcrypto_hash_lib_driver = {
     .hash_bytesv = qcrypto_gnutls_hash_bytesv,
+    .hash_new      = qcrypto_gnutls_hash_new,
+    .hash_update   = qcrypto_gnutls_hash_update,
+    .hash_finalize = qcrypto_gnutls_hash_finalize,
+    .hash_free     = qcrypto_gnutls_hash_free,
 };
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PULL 05/17] crypto/hash-nettle: Implement new hash API
  2024-10-10 16:20 [PULL 00/17] Crypto fixes patches Daniel P. Berrangé
                   ` (3 preceding siblings ...)
  2024-10-10 16:20 ` [PULL 04/17] crypto/hash-gnutls: " Daniel P. Berrangé
@ 2024-10-10 16:20 ` Daniel P. Berrangé
  2024-10-10 16:20 ` [PULL 06/17] util/iov: Introduce iov_send_recv_with_flags() Daniel P. Berrangé
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Daniel P. Berrangé @ 2024-10-10 16:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kunwu, Cédric Le Goater, Alejandro Zeise,
	Daniel P. Berrangé

From: Alejandro Zeise <alejandro.zeise@seagate.com>

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 <alejandro.zeise@seagate.com>
[ clg: - Dropped qcrypto_hash_supports() in qcrypto_nettle_hash_new() ]
Signed-off-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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;
 }
 
+static
+QCryptoHash *qcrypto_nettle_hash_new(QCryptoHashAlgo alg, Error **errp)
+{
+    QCryptoHash *hash;
+
+    hash = g_new(QCryptoHash, 1);
+    hash->alg = alg;
+    hash->opaque = 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 = 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 = hash->opaque;
+
+    for (int i = 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 = iov[i].iov_len;
+        uint8_t *base = iov[i].iov_base;
+        while (len) {
+            size_t shortlen = MIN(len, UINT_MAX);
+            qcrypto_hash_alg_map[hash->alg].write(ctx, len, base);
+            len -= shortlen;
+            base += 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 = hash->opaque;
+
+    *result_len = qcrypto_hash_alg_map[hash->alg].len;
+    *result = g_new(uint8_t, *result_len);
+
+    qcrypto_hash_alg_map[hash->alg].result(ctx, *result_len, *result);
+
+    return 0;
+}
 
 QCryptoHashDriver qcrypto_hash_lib_driver = {
     .hash_bytesv = qcrypto_nettle_hash_bytesv,
+    .hash_new      = qcrypto_nettle_hash_new,
+    .hash_update   = qcrypto_nettle_hash_update,
+    .hash_finalize = qcrypto_nettle_hash_finalize,
+    .hash_free     = qcrypto_nettle_hash_free,
 };
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PULL 06/17] util/iov: Introduce iov_send_recv_with_flags()
  2024-10-10 16:20 [PULL 00/17] Crypto fixes patches Daniel P. Berrangé
                   ` (4 preceding siblings ...)
  2024-10-10 16:20 ` [PULL 05/17] crypto/hash-nettle: " Daniel P. Berrangé
@ 2024-10-10 16:20 ` Daniel P. Berrangé
  2024-10-10 16:20 ` [PULL 07/17] crypto/hash-afalg: Implement new hash API Daniel P. Berrangé
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Daniel P. Berrangé @ 2024-10-10 16:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kunwu, Cédric Le Goater, Alejandro Zeise,
	Daniel P. Berrangé

From: Alejandro Zeise <alejandro.zeise@seagate.com>

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 <alejandro.zeise@seagate.com>
[ clg: - Split iov changes from original patch
       - Checkpatch fixes ]
Signed-off-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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 iov_cnt,
 size_t iov_memset(const struct iovec *iov, const unsigned int iov_cnt,
                   size_t offset, int fillc, size_t bytes);
 
+/*
+ * 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 = iov_send_recv_with_flags(sockfd, sockflags, iov, iovcnt,
+ *                                offset, bytes, true);
+ *
+ * is logically equivalent to
+ *
+ *   char *buf = malloc(bytes);
+ *   iov_to_buf(iov, iovcnt, offset, buf, bytes);
+ *   r = 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 <aliguori@us.ibm.com>
@@ -92,7 +93,8 @@ size_t iov_size(const struct iovec *iov, const unsigned int iov_cnt)
 
 /* 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 iov_cnt, bool do_send)
     msg.msg_iovlen = iov_cnt;
     do {
         ret = do_send
-            ? sendmsg(sockfd, &msg, 0)
-            : recvmsg(sockfd, &msg, 0);
+            ? sendmsg(sockfd, &msg, flags)
+            : recvmsg(sockfd, &msg, flags);
     } while (ret < 0 && errno == EINTR);
     return ret;
 #else
@@ -114,8 +116,8 @@ do_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, bool do_send)
     ssize_t off = 0;
     while (i < iov_cnt) {
         ssize_t r = 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, flags)
+            : recv(sockfd, iov[i].iov_base + off, iov[i].iov_len - off, flags);
         if (r > 0) {
             ret += r;
             off += r;
@@ -144,6 +146,15 @@ do_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, bool do_send)
 ssize_t iov_send_recv(int sockfd, const struct iovec *_iov, unsigned iov_cnt,
                       size_t offset, size_t bytes,
                       bool do_send)
+{
+    return iov_send_recv_with_flags(sockfd, 0, _iov, iov_cnt, offset, bytes,
+                                    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 = 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 = iov[niov].iov_len;
             iov[niov++].iov_len = tail;
-            ret = do_send_recv(sockfd, iov, niov, do_send);
+            ret = do_send_recv(sockfd, sockflags, iov, niov, do_send);
             /* Undo the changes above before checking for errors */
             iov[niov-1].iov_len = orig_len;
         } else {
-            ret = do_send_recv(sockfd, iov, niov, do_send);
+            ret = do_send_recv(sockfd, sockflags, iov, niov, do_send);
         }
         if (offset) {
             iov[0].iov_base -= offset;
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PULL 07/17] crypto/hash-afalg: Implement new hash API
  2024-10-10 16:20 [PULL 00/17] Crypto fixes patches Daniel P. Berrangé
                   ` (5 preceding siblings ...)
  2024-10-10 16:20 ` [PULL 06/17] util/iov: Introduce iov_send_recv_with_flags() Daniel P. Berrangé
@ 2024-10-10 16:20 ` Daniel P. Berrangé
  2024-10-17  6:34   ` Markus Armbruster
  2024-10-10 16:20 ` [PULL 08/17] crypto/hash: Implement and use " Daniel P. Berrangé
                   ` (10 subsequent siblings)
  17 siblings, 1 reply; 23+ messages in thread
From: Daniel P. Berrangé @ 2024-10-10 16:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kunwu, Cédric Le Goater, Alejandro Zeise,
	Daniel P. Berrangé

From: Alejandro Zeise <alejandro.zeise@seagate.com>

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 <alejandro.zeise@seagate.com>
[ 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édric Le Goater <clg@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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);
 }
 
+static
+QCryptoHash *qcrypto_afalg_hash_new(QCryptoHashAlgo alg, Error **errp)
+{
+    /* Check if hash algorithm is supported */
+    char *alg_name = qcrypto_afalg_hash_format_name(alg, false, NULL);
+    QCryptoHash *hash;
+
+    if (alg_name == NULL) {
+        error_setg(errp, "Unknown hash algorithm %d", alg);
+        return NULL;
+    }
+
+    g_free(alg_name);
+
+    hash = g_new(QCryptoHash, 1);
+    hash->alg = alg;
+    hash->opaque = 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 = 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 = 0;
+    int flags = (more_data ? MSG_MORE : 0);
+
+    /* send data to kernel's crypto core */
+    ret = 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 = -1;
+    } else {
+        /* No error, so return 0 */
+        ret = 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 = qcrypto_hash_digest_len(alg);
+
+    if (*result_len == 0) {
+        *result_len = expected_len;
+        *result = g_new0(uint8_t, *result_len);
+    } else if (*result_len != 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 = *result;
+    outv.iov_len = *result_len;
+    ret = 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, errp);
+}
+
 static int
 qcrypto_afalg_hash_hmac_bytesv(QCryptoAFAlgo *hmac,
                                QCryptoHashAlgo alg,
@@ -205,6 +328,10 @@ static void qcrypto_afalg_hmac_ctx_free(QCryptoHmac *hmac)
 
 QCryptoHashDriver qcrypto_hash_afalg_driver = {
     .hash_bytesv = qcrypto_afalg_hash_bytesv,
+    .hash_new      = qcrypto_afalg_hash_new,
+    .hash_free     = qcrypto_afalg_hash_free,
+    .hash_update   = qcrypto_afalg_hash_update,
+    .hash_finalize = qcrypto_afalg_hash_finalize
 };
 
 QCryptoHmacDriver qcrypto_hmac_afalg_driver = {
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PULL 08/17] crypto/hash: Implement and use new hash API
  2024-10-10 16:20 [PULL 00/17] Crypto fixes patches Daniel P. Berrangé
                   ` (6 preceding siblings ...)
  2024-10-10 16:20 ` [PULL 07/17] crypto/hash-afalg: Implement new hash API Daniel P. Berrangé
@ 2024-10-10 16:20 ` Daniel P. Berrangé
  2024-10-22 19:10   ` Thomas Huth
  2024-10-10 16:20 ` [PULL 09/17] tests/unit/test-crypto-hash: accumulative hashing Daniel P. Berrangé
                   ` (9 subsequent siblings)
  17 siblings, 1 reply; 23+ messages in thread
From: Daniel P. Berrangé @ 2024-10-10 16:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kunwu, Cédric Le Goater, Alejandro Zeise,
	Daniel P. Berrangé

From: Alejandro Zeise <alejandro.zeise@seagate.com>

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 <alejandro.zeise@seagate.com>
[ 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édric Le Goater <clg@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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 @@
  */
 
 #include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qapi-types-crypto.h"
 #include "crypto/hash.h"
 #include "hashpriv.h"
 
@@ -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 = qcrypto_hash_afalg_driver.hash_bytesv(alg, iov, niov,
-                                                result, resultlen,
-                                                NULL);
-    if (ret == 0) {
-        return ret;
+    g_autoptr(QCryptoHash) ctx = 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
 
-    return qcrypto_hash_lib_driver.hash_bytesv(alg, iov, niov,
-                                               result, resultlen,
-                                               errp);
+    return 0;
 }
 
 
@@ -77,29 +75,130 @@ int qcrypto_hash_bytes(QCryptoHashAlgo alg,
     return qcrypto_hash_bytesv(alg, &iov, 1, result, resultlen, errp);
 }
 
+int qcrypto_hash_updatev(QCryptoHash *hash,
+                         const struct iovec *iov,
+                         size_t niov,
+                         Error **errp)
+{
+    QCryptoHashDriver *drv = 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 = { .iov_base = (char *)buf, .iov_len = len };
+
+    return qcrypto_hash_updatev(hash, &iov, 1, errp);
+}
+
+QCryptoHash *qcrypto_hash_new(QCryptoHashAlgo alg, Error **errp)
+{
+    QCryptoHash *hash = NULL;
+
+    if (!qcrypto_hash_supports(alg)) {
+        error_setg(errp, "Unsupported hash algorithm %s",
+                   QCryptoHashAlgo_str(alg));
+        return NULL;
+   }
+
+#ifdef CONFIG_AF_ALG
+    hash = qcrypto_hash_afalg_driver.hash_new(alg, NULL);
+    if (hash) {
+        hash->driver = &qcrypto_hash_afalg_driver;
+        return hash;
+    }
+#endif
+
+    hash = qcrypto_hash_lib_driver.hash_new(alg, errp);
+    if (!hash) {
+        return NULL;
+    }
+
+    hash->driver = &qcrypto_hash_lib_driver;
+    return hash;
+}
+
+void qcrypto_hash_free(QCryptoHash *hash)
+{
+   QCryptoHashDriver *drv;
+
+    if (hash) {
+        drv = hash->driver;
+        drv->hash_free(hash);
+    }
+}
+
+int qcrypto_hash_finalize_bytes(QCryptoHash *hash,
+                                uint8_t **result,
+                                size_t *result_len,
+                                Error **errp)
+{
+    QCryptoHashDriver *drv = hash->driver;
+
+    return drv->hash_finalize(hash, result, result_len, errp);
+}
+
 static const char hex[] = "0123456789abcdef";
 
+int qcrypto_hash_finalize_digest(QCryptoHash *hash,
+                                 char **digest,
+                                 Error **errp)
+{
+    int ret;
+    g_autofree uint8_t *result = NULL;
+    size_t resultlen = 0;
+    size_t i;
+
+    ret = qcrypto_hash_finalize_bytes(hash, &result, &resultlen, errp);
+    if (ret == 0) {
+        *digest = g_new0(char, (resultlen * 2) + 1);
+        for (i = 0 ; i < resultlen ; i++) {
+            (*digest)[(i * 2)] = hex[(result[i] >> 4) & 0xf];
+            (*digest)[(i * 2) + 1] = hex[result[i] & 0xf];
+        }
+        (*digest)[resultlen * 2] = '\0';
+    }
+
+    return ret;
+}
+
+int qcrypto_hash_finalize_base64(QCryptoHash *hash,
+                                 char **base64,
+                                 Error **errp)
+{
+    int ret;
+    g_autofree uint8_t *result = NULL;
+    size_t resultlen = 0;
+
+    ret = qcrypto_hash_finalize_bytes(hash, &result, &resultlen, errp);
+    if (ret == 0) {
+        *base64 = 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 = NULL;
-    size_t resultlen = 0;
-    size_t i;
+    g_autoptr(QCryptoHash) ctx = qcrypto_hash_new(alg, errp);
 
-    if (qcrypto_hash_bytesv(alg, iov, niov, &result, &resultlen, errp) < 0) {
+    if (!ctx) {
         return -1;
     }
 
-    *digest = g_new0(char, (resultlen * 2) + 1);
-    for (i = 0 ; i < resultlen ; i++) {
-        (*digest)[(i * 2)] = hex[(result[i] >> 4) & 0xf];
-        (*digest)[(i * 2) + 1] = 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] = '\0';
-    g_free(result);
+
     return 0;
 }
 
@@ -120,15 +219,17 @@ int qcrypto_hash_base64v(QCryptoHashAlgo alg,
                          char **base64,
                          Error **errp)
 {
-    uint8_t *result = NULL;
-    size_t resultlen = 0;
+    g_autoptr(QCryptoHash) ctx = qcrypto_hash_new(alg, errp);
+
+    if (!ctx) {
+        return -1;
+    }
 
-    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;
     }
 
-    *base64 = g_base64_encode(result, resultlen);
-    g_free(result);
     return 0;
 }
 
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PULL 09/17] tests/unit/test-crypto-hash: accumulative hashing
  2024-10-10 16:20 [PULL 00/17] Crypto fixes patches Daniel P. Berrangé
                   ` (7 preceding siblings ...)
  2024-10-10 16:20 ` [PULL 08/17] crypto/hash: Implement and use " Daniel P. Berrangé
@ 2024-10-10 16:20 ` Daniel P. Berrangé
  2024-10-10 16:20 ` [PULL 10/17] crypto/hash-glib: Remove old hash API functions Daniel P. Berrangé
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Daniel P. Berrangé @ 2024-10-10 16:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kunwu, Cédric Le Goater, Alejandro Zeise,
	Daniel P. Berrangé

From: Alejandro Zeise <alejandro.zeise@seagate.com>

Added an accumulative hashing test. Checks for functionality of
the new hash create, update, finalize and free functions.

Signed-off-by: Alejandro Zeise <alejandro.zeise@seagate.com>
[ clg: - Improved test_hash_accumulate() with g_autofree variables ]
Signed-off-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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)
     }
 }
 
+static void test_hash_accumulate(void)
+{
+    size_t i;
+
+    for (i = 0; i < G_N_ELEMENTS(expected_outputs) ; i++) {
+        g_autoptr(QCryptoHash) hash = NULL;
+        struct iovec iov[] = {
+            { .iov_base = (char *)INPUT_TEXT1, .iov_len = strlen(INPUT_TEXT1) },
+            { .iov_base = (char *)INPUT_TEXT2, .iov_len = strlen(INPUT_TEXT2) },
+            { .iov_base = (char *)INPUT_TEXT3, .iov_len = strlen(INPUT_TEXT3) },
+        };
+        g_autofree uint8_t *result = NULL;
+        size_t resultlen = 0;
+        int ret;
+        size_t j;
+
+        if (!qcrypto_hash_supports(i)) {
+            continue;
+        }
+
+        hash = qcrypto_hash_new(i, &error_fatal);
+        g_assert(hash != NULL);
+
+        /* Add each iovec to the hash context separately */
+        for (j = 0; j < G_N_ELEMENTS(iov); j++) {
+            ret = qcrypto_hash_updatev(hash,
+                                      &iov[j], 1,
+                                      &error_fatal);
+
+            g_assert(ret == 0);
+        }
+
+        ret = qcrypto_hash_finalize_bytes(hash, &result, &resultlen,
+                                          &error_fatal);
+
+        g_assert(ret == 0);
+        g_assert(resultlen == expected_lens[i]);
+        for (j = 0; j < resultlen; j++) {
+            g_assert(expected_outputs[i][j * 2] == hex[(result[j] >> 4) & 0xf]);
+            g_assert(expected_outputs[i][j * 2 + 1] == hex[result[j] & 0xf]);
+        }
+    }
+}
+
 int main(int argc, char **argv)
 {
     int ret = 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();
 }
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PULL 10/17] crypto/hash-glib: Remove old hash API functions
  2024-10-10 16:20 [PULL 00/17] Crypto fixes patches Daniel P. Berrangé
                   ` (8 preceding siblings ...)
  2024-10-10 16:20 ` [PULL 09/17] tests/unit/test-crypto-hash: accumulative hashing Daniel P. Berrangé
@ 2024-10-10 16:20 ` Daniel P. Berrangé
  2024-10-10 16:20 ` [PULL 11/17] crypto/hash-gcrypt: " Daniel P. Berrangé
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Daniel P. Berrangé @ 2024-10-10 16:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kunwu, Cédric Le Goater, Alejandro Zeise,
	Daniel P. Berrangé

From: Alejandro Zeise <alejandro.zeise@seagate.com>

Removes old hash implement-ion in the GLib hash driver.

Signed-off-by: Alejandro Zeise <alejandro.zeise@seagate.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
[ clg: - Fixed spelling in commit log ]
Signed-off-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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;
 }
 
-
-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 = g_checksum_new(qcrypto_hash_alg_map[alg]);
-
-    for (i = 0; i < niov; i++) {
-        g_checksum_update(cs, iov[i].iov_base, iov[i].iov_len);
-    }
-
-    ret = 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 == 0) {
-        *resultlen = ret;
-        *result = g_new0(uint8_t, *resultlen);
-    } else if (*resultlen != 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,
 }
 
 QCryptoHashDriver qcrypto_hash_lib_driver = {
-    .hash_bytesv = qcrypto_glib_hash_bytesv,
     .hash_new      = qcrypto_glib_hash_new,
     .hash_update   = qcrypto_glib_hash_update,
     .hash_finalize = qcrypto_glib_hash_finalize,
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PULL 11/17] crypto/hash-gcrypt: Remove old hash API functions
  2024-10-10 16:20 [PULL 00/17] Crypto fixes patches Daniel P. Berrangé
                   ` (9 preceding siblings ...)
  2024-10-10 16:20 ` [PULL 10/17] crypto/hash-glib: Remove old hash API functions Daniel P. Berrangé
@ 2024-10-10 16:20 ` Daniel P. Berrangé
  2024-10-10 16:20 ` [PULL 12/17] crypto/hash-gnutls: " Daniel P. Berrangé
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Daniel P. Berrangé @ 2024-10-10 16:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kunwu, Cédric Le Goater, Alejandro Zeise,
	Daniel P. Berrangé

From: Alejandro Zeise <alejandro.zeise@seagate.com>

Removes old hash implementation in the gcrypt hash driver.

Signed-off-by: Alejandro Zeise <alejandro.zeise@seagate.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
[ clg: - Fixed spelling in commit log ]
Signed-off-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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;
 }
 
-
-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 = 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 = 0; i < niov; i++) {
-        gcry_md_write(md, iov[i].iov_base, iov[i].iov_len);
-    }
-
-    ret = gcry_md_get_algo_dlen(qcrypto_hash_alg_map[alg]);
-    if (ret <= 0) {
-        error_setg(errp,
-                   "Unable to get hash length: %s",
-                   gcry_strerror(ret));
-        goto error;
-    }
-    if (*resultlen == 0) {
-        *resultlen = ret;
-        *result = g_new0(uint8_t, *resultlen);
-    } else if (*resultlen != ret) {
-        error_setg(errp,
-                   "Result buffer size %zu is smaller than hash %d",
-                   *resultlen, ret);
-        goto error;
-    }
-
-    digest = 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,
 }
 
 QCryptoHashDriver qcrypto_hash_lib_driver = {
-    .hash_bytesv = qcrypto_gcrypt_hash_bytesv,
     .hash_new      = qcrypto_gcrypt_hash_new,
     .hash_update   = qcrypto_gcrypt_hash_update,
     .hash_finalize = qcrypto_gcrypt_hash_finalize,
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PULL 12/17] crypto/hash-gnutls: Remove old hash API functions
  2024-10-10 16:20 [PULL 00/17] Crypto fixes patches Daniel P. Berrangé
                   ` (10 preceding siblings ...)
  2024-10-10 16:20 ` [PULL 11/17] crypto/hash-gcrypt: " Daniel P. Berrangé
@ 2024-10-10 16:20 ` Daniel P. Berrangé
  2024-10-10 16:20 ` [PULL 13/17] crypto/hash-nettle: " Daniel P. Berrangé
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Daniel P. Berrangé @ 2024-10-10 16:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kunwu, Cédric Le Goater, Alejandro Zeise,
	Daniel P. Berrangé

From: Alejandro Zeise <alejandro.zeise@seagate.com>

Removes old hash implementation in the gnutls hash driver.

Signed-off-by: Alejandro Zeise <alejandro.zeise@seagate.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
[ clg: - Fixed spelling in commit log ]
Signed-off-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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;
 }
 
-
-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 = gnutls_hash_get_len(qcrypto_hash_alg_map[alg]);
-    if (*resultlen == 0) {
-        *resultlen = ret;
-        *result = g_new0(uint8_t, *resultlen);
-    } else if (*resultlen != ret) {
-        error_setg(errp,
-                   "Result buffer size %zu is smaller than hash %d",
-                   *resultlen, ret);
-        return -1;
-    }
-
-    ret = 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 = 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,
 }
 
 QCryptoHashDriver qcrypto_hash_lib_driver = {
-    .hash_bytesv = qcrypto_gnutls_hash_bytesv,
     .hash_new      = qcrypto_gnutls_hash_new,
     .hash_update   = qcrypto_gnutls_hash_update,
     .hash_finalize = qcrypto_gnutls_hash_finalize,
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PULL 13/17] crypto/hash-nettle: Remove old hash API functions
  2024-10-10 16:20 [PULL 00/17] Crypto fixes patches Daniel P. Berrangé
                   ` (11 preceding siblings ...)
  2024-10-10 16:20 ` [PULL 12/17] crypto/hash-gnutls: " Daniel P. Berrangé
@ 2024-10-10 16:20 ` Daniel P. Berrangé
  2024-10-10 16:20 ` [PULL 14/17] crypto/hash-afalg: " Daniel P. Berrangé
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Daniel P. Berrangé @ 2024-10-10 16:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kunwu, Cédric Le Goater, Alejandro Zeise,
	Daniel P. Berrangé

From: Alejandro Zeise <alejandro.zeise@seagate.com>

Removes old hash implementation in the nettle hash driver.

Signed-off-by: Alejandro Zeise <alejandro.zeise@seagate.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
[ clg: - Fixed spelling in commit log ]
Signed-off-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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;
 }
 
-
-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 = 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 = iov[i].iov_len;
-        uint8_t *base = iov[i].iov_base;
-        while (len) {
-            size_t shortlen = MIN(len, UINT_MAX);
-            qcrypto_hash_alg_map[alg].write(&ctx, len, base);
-            len -= shortlen;
-            base += len;
-        }
-    }
-
-    if (*resultlen == 0) {
-        *resultlen = qcrypto_hash_alg_map[alg].len;
-        *result = g_new0(uint8_t, *resultlen);
-    } else if (*resultlen != 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,
 }
 
 QCryptoHashDriver qcrypto_hash_lib_driver = {
-    .hash_bytesv = qcrypto_nettle_hash_bytesv,
     .hash_new      = qcrypto_nettle_hash_new,
     .hash_update   = qcrypto_nettle_hash_update,
     .hash_finalize = qcrypto_nettle_hash_finalize,
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PULL 14/17] crypto/hash-afalg: Remove old hash API functions
  2024-10-10 16:20 [PULL 00/17] Crypto fixes patches Daniel P. Berrangé
                   ` (12 preceding siblings ...)
  2024-10-10 16:20 ` [PULL 13/17] crypto/hash-nettle: " Daniel P. Berrangé
@ 2024-10-10 16:20 ` Daniel P. Berrangé
  2024-10-10 16:20 ` [PULL 15/17] crypto/hashpriv: Remove old hash API function Daniel P. Berrangé
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Daniel P. Berrangé @ 2024-10-10 16:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kunwu, Cédric Le Goater, Alejandro Zeise,
	Daniel P. Berrangé

From: Alejandro Zeise <alejandro.zeise@seagate.com>

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 <alejandro.zeise@seagate.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
[ clg: - Checkpatch fixes ]
Signed-off-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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 = 0;
-    bool is_hmac = (hmac != NULL) ? true : false;
-    const int expect_len = qcrypto_hash_digest_len(alg);
-
-    if (*resultlen == 0) {
-        *resultlen = expect_len;
-        *result = g_new0(uint8_t, *resultlen);
-    } else if (*resultlen != expect_len) {
-        error_setg(errp,
-                   "Result buffer size %zu is not match hash %d",
-                   *resultlen, expect_len);
-        return -1;
-    }
-
-    if (is_hmac) {
-        afalg = hmac;
-    } else {
-        afalg = qcrypto_afalg_hash_ctx_new(alg, errp);
-        if (!afalg) {
-            return -1;
-        }
-    }
-
-    /* send data to kernel's crypto core */
-    ret = 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;
-    }
 
-    /* hash && get result */
-    outv.iov_base = *result;
-    outv.iov_len = *resultlen;
-    ret = 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 = 0;
+    ret = qcrypto_afalg_send_to_kernel(hmac, iov, niov, false, errp);
+    if (ret == 0) {
+        ret = qcrypto_afalg_recv_from_kernel(hmac, alg, result,
+                                             resultlen, errp);
     }
 
-out:
-    if (!is_hmac) {
-        qcrypto_afalg_comm_free(afalg);
-    }
     return ret;
 }
 
-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 *hmac)
 }
 
 QCryptoHashDriver qcrypto_hash_afalg_driver = {
-    .hash_bytesv = qcrypto_afalg_hash_bytesv,
     .hash_new      = qcrypto_afalg_hash_new,
     .hash_free     = qcrypto_afalg_hash_free,
     .hash_update   = qcrypto_afalg_hash_update,
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PULL 15/17] crypto/hashpriv: Remove old hash API function
  2024-10-10 16:20 [PULL 00/17] Crypto fixes patches Daniel P. Berrangé
                   ` (13 preceding siblings ...)
  2024-10-10 16:20 ` [PULL 14/17] crypto/hash-afalg: " Daniel P. Berrangé
@ 2024-10-10 16:20 ` Daniel P. Berrangé
  2024-10-10 16:20 ` [PULL 16/17] crypto: drop obsolete back compat logic for old nettle Daniel P. Berrangé
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Daniel P. Berrangé @ 2024-10-10 16:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kunwu, Cédric Le Goater, Alejandro Zeise,
	Daniel P. Berrangé

From: Alejandro Zeise <alejandro.zeise@seagate.com>

Remove old hash_bytesv function, as it was replaced by the 4
new functions.

Signed-off-by: Alejandro Zeise <alejandro.zeise@seagate.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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;
 
 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,
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PULL 16/17] crypto: drop obsolete back compat logic for old nettle
  2024-10-10 16:20 [PULL 00/17] Crypto fixes patches Daniel P. Berrangé
                   ` (14 preceding siblings ...)
  2024-10-10 16:20 ` [PULL 15/17] crypto/hashpriv: Remove old hash API function Daniel P. Berrangé
@ 2024-10-10 16:20 ` Daniel P. Berrangé
  2024-10-10 16:48   ` Philippe Mathieu-Daudé
  2024-10-10 16:20 ` [PULL 17/17] tests/unit: Add a assert for test_io_channel_unix_listen_cleanup Daniel P. Berrangé
  2024-10-11 17:19 ` [PULL 00/17] Crypto fixes patches Peter Maydell
  17 siblings, 1 reply; 23+ messages in thread
From: Daniel P. Berrangé @ 2024-10-10 16:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kunwu, Cédric Le Goater, Daniel P. Berrangé

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édric Le Goater <clg@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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 = hash->opaque;
 
     for (int i = 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 = iov[i].iov_len;
-        uint8_t *base = iov[i].iov_base;
-        while (len) {
-            size_t shortlen = MIN(len, UINT_MAX);
-            qcrypto_hash_alg_map[hash->alg].write(ctx, len, base);
-            len -= shortlen;
-            base += len;
-        }
+        qcrypto_hash_alg_map[hash->alg].write(ctx,
+                                              iov[i].iov_len,
+                                              iov[i].iov_base);
     }
 
     return 0;
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PULL 17/17] tests/unit: Add a assert for test_io_channel_unix_listen_cleanup
  2024-10-10 16:20 [PULL 00/17] Crypto fixes patches Daniel P. Berrangé
                   ` (15 preceding siblings ...)
  2024-10-10 16:20 ` [PULL 16/17] crypto: drop obsolete back compat logic for old nettle Daniel P. Berrangé
@ 2024-10-10 16:20 ` Daniel P. Berrangé
  2024-10-11 17:19 ` [PULL 00/17] Crypto fixes patches Peter Maydell
  17 siblings, 0 replies; 23+ messages in thread
From: Daniel P. Berrangé @ 2024-10-10 16:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kunwu, Cédric Le Goater, Daniel P. Berrangé

From: Kunwu <chentao@kylinos.cn>

Calling bind without checking return value. Add a assert for it.

Signed-off-by: Kunwu <chentao@kylinos.cn>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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-channel-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 = 0;
 
 #define TEST_SOCKET "test-io-channel-socket.sock"
 
@@ -519,7 +519,9 @@ static void test_io_channel_unix_listen_cleanup(void)
     un.sun_family = AF_UNIX;
     snprintf(un.sun_path, sizeof(un.sun_path), "%s", TEST_SOCKET);
     unlink(TEST_SOCKET);
-    bind(sock, (struct sockaddr *)&un, sizeof(un));
+    ret = bind(sock, (struct sockaddr *)&un, sizeof(un));
+    g_assert_cmpint(ret, ==, 0);
+
     ioc->fd = sock;
     ioc->localAddrLen = sizeof(ioc->localAddr);
     getsockname(sock, (struct sockaddr *)&ioc->localAddr,
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PULL 16/17] crypto: drop obsolete back compat logic for old nettle
  2024-10-10 16:20 ` [PULL 16/17] crypto: drop obsolete back compat logic for old nettle Daniel P. Berrangé
@ 2024-10-10 16:48   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 23+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-10 16:48 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel; +Cc: Kunwu, Cédric Le Goater

On 10/10/24 13:20, Daniel P. Berrangé wrote:
> 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édric Le Goater <clg@redhat.com>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   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 = hash->opaque;
>   
>       for (int i = 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 = iov[i].iov_len;
> -        uint8_t *base = iov[i].iov_base;
> -        while (len) {
> -            size_t shortlen = MIN(len, UINT_MAX);
> -            qcrypto_hash_alg_map[hash->alg].write(ctx, len, base);
> -            len -= shortlen;
> -            base += len;
> -        }
> +        qcrypto_hash_alg_map[hash->alg].write(ctx,
> +                                              iov[i].iov_len,
> +                                              iov[i].iov_base);

Yay!



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PULL 00/17] Crypto fixes patches
  2024-10-10 16:20 [PULL 00/17] Crypto fixes patches Daniel P. Berrangé
                   ` (16 preceding siblings ...)
  2024-10-10 16:20 ` [PULL 17/17] tests/unit: Add a assert for test_io_channel_unix_listen_cleanup Daniel P. Berrangé
@ 2024-10-11 17:19 ` Peter Maydell
  17 siblings, 0 replies; 23+ messages in thread
From: Peter Maydell @ 2024-10-11 17:19 UTC (permalink / raw)
  To: Daniel P. Berrangé; +Cc: qemu-devel, Kunwu, Cédric Le Goater

On Thu, 10 Oct 2024 at 17:24, Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> The following changes since commit 838fc0a8769d7cc6edfe50451ba4e3368395f5c1:
>
>   Merge tag 'chr-pull-request' of https://gitlab.com/marcandre.lureau/qemu into staging (2024-10-09 15:06:56 +0100)
>
> are available in the Git repository at:
>
>   https://gitlab.com/berrange/qemu tags/crypto-fixes-pull-request
>
> for you to fetch changes up to 08e702043fbee7b366d1d27c1b6682090c46c0d6:
>
>   tests/unit: Add a assert for test_io_channel_unix_listen_cleanup (2024-10-10 13:41:45 +0100)
>
> ----------------------------------------------------------------
> Introduce new cryptography hashing APIs
>
> ----------------------------------------------------------------


Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/9.2
for any user-visible changes.

-- PMM


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PULL 07/17] crypto/hash-afalg: Implement new hash API
  2024-10-10 16:20 ` [PULL 07/17] crypto/hash-afalg: Implement new hash API Daniel P. Berrangé
@ 2024-10-17  6:34   ` Markus Armbruster
  0 siblings, 0 replies; 23+ messages in thread
From: Markus Armbruster @ 2024-10-17  6:34 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Kunwu, Cédric Le Goater, Alejandro Zeise

Daniel P. Berrangé <berrange@redhat.com> writes:

> From: Alejandro Zeise <alejandro.zeise@seagate.com>
>
> 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 <alejandro.zeise@seagate.com>
> [ 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édric Le Goater <clg@redhat.com>
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Semantic conflict with commit 8f525028bc6 broke the build:

    ../crypto/hash-afalg.c: In function ‘qcrypto_afalg_hash_free’:
    ../crypto/hash-afalg.c:145:5: error: unknown type name ‘QCryptoAFAlg’; did you mean ‘QCryptoAFAlgo’?
      145 |     QCryptoAFAlg *ctx = hash->opaque;
          |     ^~~~~~~~~~~~
          |     QCryptoAFAlgo


and more of the same.  I'll post a patch.



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PULL 08/17] crypto/hash: Implement and use new hash API
  2024-10-10 16:20 ` [PULL 08/17] crypto/hash: Implement and use " Daniel P. Berrangé
@ 2024-10-22 19:10   ` Thomas Huth
  2024-10-23  8:15     ` Daniel P. Berrangé
  0 siblings, 1 reply; 23+ messages in thread
From: Thomas Huth @ 2024-10-22 19:10 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel, Cédric Le Goater,
	Alejandro Zeise
  Cc: Kunwu

On 10/10/2024 18.20, Daniel P. Berrangé wrote:
> From: Alejandro Zeise <alejandro.zeise@seagate.com>
> 
> 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 <alejandro.zeise@seagate.com>
> [ 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édric Le Goater <clg@redhat.com>
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   crypto/hash.c | 161 ++++++++++++++++++++++++++++++++++++++++----------
>   1 file changed, 131 insertions(+), 30 deletions(-)

  Hi,

something recently broke qemu-iotest 081 in raw mode and bisecting it 
pointed me to this commit here.

cd tests/qemu-iotests/ ; ./check -raw 081 ; cd ../../
[...]
081   fail       [21:07:40] [21:07:42]   1.4s   (last: 1.4s)  output 
mismatch (see 
/home/thuth/tmp/qemu-build/tests/qemu-iotests/scratch/raw-file-081/081.out.bad)
--- /home/thuth/devel/qemu/tests/qemu-iotests/081.out
+++ 
/home/thuth/tmp/qemu-build/tests/qemu-iotests/scratch/raw-file-081/081.out.bad
@@ -31,7 +31,6 @@
  {"return": {}}
  {"return": {}}
  {"return": {}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": 
"QUORUM_REPORT_BAD", "data": {"node-name": "drive2", "sectors-count": 20480, 
"sector-num": 0, "type": "read"}}
  read 10485760/10485760 bytes at offset 0
  10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
  {"return": ""}
@@ -44,6 +43,7 @@
  10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)

  == checking that quorum has corrected the corrupted file ==
+Pattern verification failed at offset 0, 10485760 bytes
  read 10485760/10485760 bytes at offset 0
  10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)

@@ -63,7 +63,6 @@
      } -device virtio-scsi,id=scsi -device 
scsi-hd,id=quorum-drive,bus=scsi.0,drive=quorum
  QMP_VERSION
  {"return": {}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": 
"QUORUM_REPORT_BAD", "data": {"node-name": "file2", "sectors-count": 20480, 
"sector-num": 0, "type": "read"}}
  read 10485760/10485760 bytes at offset 0
  10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
  {"return": ""}
@@ -71,6 +70,7 @@
  {"return": {}}

  -- checking that the image has been corrected --
+Pattern verification failed at offset 0, 10485760 bytes
  read 10485760/10485760 bytes at offset 0
  10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)

@@ -81,7 +81,9 @@
  10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)

  == checking that quorum is broken ==
-read failed: Input/output error
+Pattern verification failed at offset 0, 10485760 bytes
+read 10485760/10485760 bytes at offset 0
+10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)

  == checking the blkverify mode with broken content ==
  quorum: offset=0 bytes=10485760 contents mismatch at offset 0
Failures: 081
Failed 1 of 1 iotests

Could you please have a look?

  Thanks,
   Thomas



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PULL 08/17] crypto/hash: Implement and use new hash API
  2024-10-22 19:10   ` Thomas Huth
@ 2024-10-23  8:15     ` Daniel P. Berrangé
  0 siblings, 0 replies; 23+ messages in thread
From: Daniel P. Berrangé @ 2024-10-23  8:15 UTC (permalink / raw)
  To: Thomas Huth; +Cc: qemu-devel, Cédric Le Goater, Alejandro Zeise, Kunwu

On Tue, Oct 22, 2024 at 09:10:50PM +0200, Thomas Huth wrote:
> On 10/10/2024 18.20, Daniel P. Berrangé wrote:
> > From: Alejandro Zeise <alejandro.zeise@seagate.com>
> > 
> > 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 <alejandro.zeise@seagate.com>
> > [ 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édric Le Goater <clg@redhat.com>
> > Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >   crypto/hash.c | 161 ++++++++++++++++++++++++++++++++++++++++----------
> >   1 file changed, 131 insertions(+), 30 deletions(-)
> 
>  Hi,
> 
> something recently broke qemu-iotest 081 in raw mode and bisecting it
> pointed me to this commit here.

snip

> Could you please have a look?

This is fixed by my current pending pull request


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2024-10-23  8:16 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-10 16:20 [PULL 00/17] Crypto fixes patches Daniel P. Berrangé
2024-10-10 16:20 ` [PULL 01/17] crypto: accumulative hashing API Daniel P. Berrangé
2024-10-10 16:20 ` [PULL 02/17] crypto/hash-glib: Implement new hash API Daniel P. Berrangé
2024-10-10 16:20 ` [PULL 03/17] crypto/hash-gcrypt: " Daniel P. Berrangé
2024-10-10 16:20 ` [PULL 04/17] crypto/hash-gnutls: " Daniel P. Berrangé
2024-10-10 16:20 ` [PULL 05/17] crypto/hash-nettle: " Daniel P. Berrangé
2024-10-10 16:20 ` [PULL 06/17] util/iov: Introduce iov_send_recv_with_flags() Daniel P. Berrangé
2024-10-10 16:20 ` [PULL 07/17] crypto/hash-afalg: Implement new hash API Daniel P. Berrangé
2024-10-17  6:34   ` Markus Armbruster
2024-10-10 16:20 ` [PULL 08/17] crypto/hash: Implement and use " Daniel P. Berrangé
2024-10-22 19:10   ` Thomas Huth
2024-10-23  8:15     ` Daniel P. Berrangé
2024-10-10 16:20 ` [PULL 09/17] tests/unit/test-crypto-hash: accumulative hashing Daniel P. Berrangé
2024-10-10 16:20 ` [PULL 10/17] crypto/hash-glib: Remove old hash API functions Daniel P. Berrangé
2024-10-10 16:20 ` [PULL 11/17] crypto/hash-gcrypt: " Daniel P. Berrangé
2024-10-10 16:20 ` [PULL 12/17] crypto/hash-gnutls: " Daniel P. Berrangé
2024-10-10 16:20 ` [PULL 13/17] crypto/hash-nettle: " Daniel P. Berrangé
2024-10-10 16:20 ` [PULL 14/17] crypto/hash-afalg: " Daniel P. Berrangé
2024-10-10 16:20 ` [PULL 15/17] crypto/hashpriv: Remove old hash API function Daniel P. Berrangé
2024-10-10 16:20 ` [PULL 16/17] crypto: drop obsolete back compat logic for old nettle Daniel P. Berrangé
2024-10-10 16:48   ` Philippe Mathieu-Daudé
2024-10-10 16:20 ` [PULL 17/17] tests/unit: Add a assert for test_io_channel_unix_listen_cleanup Daniel P. Berrangé
2024-10-11 17:19 ` [PULL 00/17] Crypto fixes patches Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).