[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v1 1/2] crypto: use glib as fallback for hash al
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH v1 1/2] crypto: use glib as fallback for hash algorithm |
Date: |
Tue, 5 Jul 2016 09:03:26 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
On 07/05/2016 04:49 AM, Daniel P. Berrange wrote:
> GLib >= 2.16 provides GChecksum API which is good enough
> for md5, sha1, sha256 and sha512. Use this as a final
> fallback if neither nettle or gcrypt are available. This
> lets us remove the stub hash impl, and so callers can
> be sure those 4 algs are always available at compile
> time. They may still be disabled at runtime, so a check
> for qcrypto_hash_supports() is still best practice to
> report good error messages.
>
> Signed-off-by: Daniel P. Berrange <address@hidden>
> ---
> crypto/Makefile.objs | 2 +-
> crypto/hash-glib.c | 94
> ++++++++++++++++++++++++++++++++++++++++++++++++++++
> crypto/hash-stub.c | 41 -----------------------
> 3 files changed, 95 insertions(+), 42 deletions(-)
> create mode 100644 crypto/hash-glib.c
> delete mode 100644 crypto/hash-stub.c
>
> +gboolean qcrypto_hash_supports(QCryptoHashAlgorithm alg)
> +{
> + if (alg < G_N_ELEMENTS(qcrypto_hash_alg_map) &&
> + qcrypto_hash_alg_map[alg] != -1) {
> + return true;
> + }
> + return false;
> +}
> +
> +
> +int qcrypto_hash_bytesv(QCryptoHashAlgorithm alg,
> + const struct iovec *iov,
> + size_t niov,
> + uint8_t **result,
> + size_t *resultlen,
> + Error **errp)
> +{
> + int i, ret;
> + GChecksum *cs;
> +
> + if (alg >= G_N_ELEMENTS(qcrypto_hash_alg_map) ||
> + qcrypto_hash_alg_map[alg] == -1) {
Worth writing this as 'if (!gcrypto_hash_supports(alg)) {' ?
Otherwise,
Reviewed-by: Eric Blake <address@hidden>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature