From 24aa46946349529bf36d3569796a28917d3e756f Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Wed, 9 Aug 2017 18:55:37 +0200 Subject: build, lib, ipcpd, irmd: Add support for libgcrypt This adds support for libgcrypt. If at least version 1.7.0 of libgcrypt is present, it may be used for secure random number generation and is used for hashing in the irmd/ipcp. The hash definitions are moved to the internal hash.h header, and defined independently of the hashes that are defined as part of the directory policy for the normal IPCP. The translation is moved from the IRMd to ipcpd/ipcp.h. The bootstrap call from the IRMd expects the IPCP to return the correct hash algorithm with a dif_info struct, which is in line with the behavior of the enroll call. This also improves how some platform checks in the build system are handled. --- src/lib/hash.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/lib/hash.c') diff --git a/src/lib/hash.c b/src/lib/hash.c index 9db3a276..088d43cd 100644 --- a/src/lib/hash.c +++ b/src/lib/hash.c @@ -27,12 +27,22 @@ #include #include +#ifndef HAVE_LIBGCRYPT +#include +#include +#include +#else +#include +#endif #include #include #include uint16_t hash_len(enum hash_algo algo) { +#ifdef HAVE_LIBGCRYPT + return (uint16_t) gcry_md_get_algo_dlen(algo); +#else switch (algo) { case HASH_CRC32: return CRC32_HASH_LEN; @@ -52,12 +62,16 @@ uint16_t hash_len(enum hash_algo algo) } return 0; +#endif } void str_hash(enum hash_algo algo, void * buf, const char * str) { +#ifdef HAVE_LIBGCRYPT + gcry_md_hash_buffer(algo, buf, str, strlen(str)); +#else struct sha3_ctx sha3_ctx; struct md5_ctx md5_ctx; @@ -95,4 +109,5 @@ void str_hash(enum hash_algo algo, assert(false); break; } +#endif } -- cgit v1.2.3