On Tue, Jul 06, 2021 at 10:59:21AM +0100, Daniel P. Berrangé wrote:
> This adds support for using gnutls as a provider of the crypto
> hash APIs.
> 
> Signed-off-by: Daniel P. Berrangé <berra...@redhat.com>
> ---
>  crypto/hash-gnutls.c | 104 +++++++++++++++++++++++++++++++++++++++++++
>  crypto/meson.build   |   2 +
>  2 files changed, 106 insertions(+)
>  create mode 100644 crypto/hash-gnutls.c
> 
> diff --git a/crypto/hash-gnutls.c b/crypto/hash-gnutls.c
> new file mode 100644
> index 0000000000..f88db71f00
> --- /dev/null
> +++ b/crypto/hash-gnutls.c
> @@ -0,0 +1,104 @@
> +/*
> + * QEMU Crypto hash algorithms
> + *
> + * Copyright (c) 2016 Red Hat, Inc.

Want to add 2021 here?

> +static int
> +qcrypto_gnutls_hash_bytesv(QCryptoHashAlgorithm alg,
> +                           const struct iovec *iov,
> +                           size_t niov,
> +                           uint8_t **result,
> +                           size_t *resultlen,
> +                           Error **errp)
> +{

> +
> +    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);

Is there any speed penalty for creating a new gnutls_hash object for
each call to qcrypto_gnutls_hash_bytesv(), compared to creating a hash
object just once and using gnutls_hash_output() to grab results and
reset it for reuse?  But that can be a later patch (if it even works -
I may have mis-read gnutls docs), so it doesn't affect review of this
patch.

Reviewed-by: Eric Blake <ebl...@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org


Reply via email to