From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55853) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKRsw-0001tF-Qt for qemu-devel@nongnu.org; Tue, 05 Jul 2016 11:03:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKRsu-0004BI-NR for qemu-devel@nongnu.org; Tue, 05 Jul 2016 11:03:37 -0400 References: <1467715800-20379-1-git-send-email-berrange@redhat.com> <1467715800-20379-2-git-send-email-berrange@redhat.com> From: Eric Blake Message-ID: <577BCC3E.2000807@redhat.com> Date: Tue, 5 Jul 2016 09:03:26 -0600 MIME-Version: 1.0 In-Reply-To: <1467715800-20379-2-git-send-email-berrange@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="PojA1Si6tWcdoFQA3rpl3knuKbTR0Qb0o" Subject: Re: [Qemu-devel] [PATCH v1 1/2] crypto: use glib as fallback for hash algorithm List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" , qemu-devel@nongnu.org Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Max Reitz , Alberto Garcia This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --PojA1Si6tWcdoFQA3rpl3knuKbTR0Qb0o From: Eric Blake To: "Daniel P. Berrange" , qemu-devel@nongnu.org Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Max Reitz , Alberto Garcia Message-ID: <577BCC3E.2000807@redhat.com> Subject: Re: [Qemu-devel] [PATCH v1 1/2] crypto: use glib as fallback for hash algorithm References: <1467715800-20379-1-git-send-email-berrange@redhat.com> <1467715800-20379-2-git-send-email-berrange@redhat.com> In-Reply-To: <1467715800-20379-2-git-send-email-berrange@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 07/05/2016 04:49 AM, Daniel P. Berrange wrote: > GLib >=3D 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. >=20 > Signed-off-by: Daniel P. Berrange > --- > 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 >=20 > +gboolean qcrypto_hash_supports(QCryptoHashAlgorithm alg) > +{ > + if (alg < G_N_ELEMENTS(qcrypto_hash_alg_map) && > + qcrypto_hash_alg_map[alg] !=3D -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 >=3D G_N_ELEMENTS(qcrypto_hash_alg_map) || > + qcrypto_hash_alg_map[alg] =3D=3D -1) { Worth writing this as 'if (!gcrypto_hash_supports(alg)) {' ? Otherwise, Reviewed-by: Eric Blake --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --PojA1Si6tWcdoFQA3rpl3knuKbTR0Qb0o Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJXe8w+AAoJEKeha0olJ0NqNG8IAKSvELiDokYYzSe4eeL8n6rs Dwzq/cjSsffUeppK9HOc6KJbvZD59c4oTUxICU9+r1qgtJb9xU0ibxR0r3uKni3Y YRvqR7U3+6JKkD5cYXo59eHLY55GuLo8l6PtZ0xeCjaSe3mxe7gqX0/5TXJgf2vU 2WdR9yTAoApuJG/VZlU6NsX+yBuYbcq0NEQsUrmeFFuGvdKvBb0Y780JW/x3lDv+ AI/MsCQ5P6MMDjkferC73TFEkLmhvuebiIhTyoTbYrdNNL1FRKPWl+bMZ20M5Tq+ VmfR9cqjTk05KbfT4Cfu1p5sW6/WaAkfPjevX7+GSHvIix4Nd7sy1bDTONAjMrE= =xD7y -----END PGP SIGNATURE----- --PojA1Si6tWcdoFQA3rpl3knuKbTR0Qb0o--