[libvirt] [PATCH 1/4] Add helper APIs for generating cryptographic hashes

Eric Blake eblake at redhat.com
Wed Mar 5 22:48:00 UTC 2014


On 03/05/2014 10:53 AM, Daniel P. Berrange wrote:
> GNULIB provides APIs for calculating md5 and sha256 hashes,
> but these APIs only return you raw byte arrays. Most users
> in libvirt want the hash in printable string format. Add
> some helper APIs in util/vircrypto.{c,h} for doing this.
> 
> Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
> ---
>  .gitignore                  |  1 +
>  include/libvirt/virterror.h |  1 +
>  po/POTFILES.in              |  1 +
>  src/Makefile.am             |  1 +
>  src/libvirt_private.syms    |  4 ++
>  src/util/vircrypto.c        | 80 ++++++++++++++++++++++++++++++++++++++++
>  src/util/vircrypto.h        | 40 ++++++++++++++++++++
>  src/util/virerror.c         |  1 +
>  tests/Makefile.am           |  5 +++
>  tests/vircryptotest.c       | 90 +++++++++++++++++++++++++++++++++++++++++++++
>  10 files changed, 224 insertions(+)
>  create mode 100644 src/util/vircrypto.c
>  create mode 100644 src/util/vircrypto.h
>  create mode 100644 tests/vircryptotest.c
> 

> +#define VIR_FROM_THIS VIR_FROM_CRYPTO
> +
> +static const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7',
> +                            '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

Why not the more compact:

static const char hex[] = "0123456789abcdef";

virbuffer.c and virsystemd.c also have variants of this table.


> +
> +    for (i = 0; i < hashinfo[hash].hashlen; i++) {
> +        (*output)[i*2] = hex[(buf[i] >> 4) & 0xf];
> +        (*output)[(i*2)+1] = hex[buf[i] & 0xf];

Spaces around operators * and +

ACK.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140305/0bb7e1c4/attachment-0001.sig>


More information about the libvir-list mailing list