Skip to content

Commit

Permalink
use BLAKE2B and BLAKE2S from libgcrypt (if available)
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanheaven committed Jan 21, 2018
1 parent 08478c4 commit 6295b25
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
29 changes: 26 additions & 3 deletions configure.ac
Expand Up @@ -126,9 +126,23 @@ AC_MSG_RESULT([${enable_gcrypt}])
AM_CONDITIONAL([ENABLE_GCRYPT], [test "${enable_gcrypt}" = "yes"])
AC_DEFINE([ENABLE_GCRYPT], [0], [Use Libgcrypt])

gcrypt_funcs=

if test "${enable_gcrypt}" = "yes" ; then
AM_PATH_LIBGCRYPT([1.7.0], [:], [AC_MSG_ERROR([Libgcrypt not found])])
AC_DEFINE([ENABLE_GCRYPT], [1])

ac_save_CFLAGS="${CFLAGS}"
CFLAGS="${CFLAGS} ${LIBGCRYPT_CFLAGS} ${LIBGCRYPT_LIBS}"

AC_CHECK_DECL([GCRY_MD_BLAKE2B_512],
[gcrypt_funcs="${gcrypt_funcs} BLAKE2b"], [:],
[#include <gcrypt.h>])
AC_CHECK_DECL([GCRY_MD_BLAKE2S_256],
[gcrypt_funcs="${gcrypt_funcs} BLAKE2s"], [:],
[#include <gcrypt.h>])

CFLAGS="${ac_save_CFLAGS}"
fi
# }}}

Expand Down Expand Up @@ -397,7 +411,7 @@ echo " gtkhash-thunar: ${enable_thunar}"

blake2_funcs="
BLAKE2b BLAKE2s BLAKE2bp BLAKE2sp"
gcrypt_funcs="
gcrypt_funcs="${gcrypt_funcs}
GOST
MD4
MD5
Expand Down Expand Up @@ -465,7 +479,7 @@ zlib_funcs="
CRC32"

echo
echo "Supported Hash Functions:"
printf "%-20s%s\n" "Hash Function" "Preferred Implementation"

have_libs=""

Expand All @@ -488,7 +502,7 @@ for func in \
TIGER192 \
WHIRLPOOL
do
printf " %-14s" "${func}"
printf " %-20s" "${func}"
enabled=""
# Matches preferred order from src/hash/hash-lib.c
for lib in \
Expand All @@ -512,11 +526,20 @@ do
printf "${lib}"
enabled="yes"
have_libs="yes"

test "${lib}" = "linux_crypto" && printf "*"
fi
done
test -n "${enabled}" && echo || echo "_"
done

if test "${enable_linux_crypto}" = "yes" ; then
echo
echo "* linux_crypto support depends on kernel module availability - check /proc/crypto"
fi

echo

test -z "${have_libs}" && AC_MSG_ERROR([No hash libraries enabled])

# Exit status
Expand Down
4 changes: 4 additions & 0 deletions src/hash/hash-lib-gcrypt.c
Expand Up @@ -43,6 +43,10 @@ static bool gtkhash_hash_lib_gcrypt_set_algo(const enum hash_func_e id,
int *algo)
{
switch (id) {
#if ((GCRYPT_VERSION_NUMBER) >= 0x010800)
case HASH_FUNC_BLAKE2B: *algo = GCRY_MD_BLAKE2B_512; break;
case HASH_FUNC_BLAKE2S: *algo = GCRY_MD_BLAKE2S_256; break;
#endif
case HASH_FUNC_GOST: *algo = GCRY_MD_GOSTR3411_94; break;
case HASH_FUNC_MD4: *algo = GCRY_MD_MD4; break;
case HASH_FUNC_MD5: *algo = GCRY_MD_MD5; break;
Expand Down

0 comments on commit 6295b25

Please sign in to comment.