summaryrefslogtreecommitdiff
path: root/src/lib/hash.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-08-09 19:41:57 +0000
committerSander Vrijders <sander.vrijders@ugent.be>2017-08-09 19:41:57 +0000
commitafc4342532225fb86d11729ddb783095cb62686a (patch)
tree58ef8a40142323771eecbd8ce6c2eaea409bc138 /src/lib/hash.c
parentc1d7ff1e1bd44e1a38af8a1b498c68f3378fa342 (diff)
parent24aa46946349529bf36d3569796a28917d3e756f (diff)
downloadouroboros-afc4342532225fb86d11729ddb783095cb62686a.tar.gz
ouroboros-afc4342532225fb86d11729ddb783095cb62686a.zip
Merged in dstaesse/ouroboros/be-libgcrypt (pull request #544)
build, lib, ipcpd, irmd: Add support for libgcrypt
Diffstat (limited to 'src/lib/hash.c')
-rw-r--r--src/lib/hash.c15
1 files changed, 15 insertions, 0 deletions
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 <ouroboros/config.h>
#include <ouroboros/hash.h>
+#ifndef HAVE_LIBGCRYPT
+#include <ouroboros/crc32.h>
+#include <ouroboros/md5.h>
+#include <ouroboros/sha3.h>
+#else
+#include <gcrypt.h>
+#endif
#include <string.h>
#include <assert.h>
#include <stdbool.h>
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
}