Add libgcrypt as an option for SHA1

Signed-off-by: Julien Cristau <jcristau@debian.org>
Reviewed-by: Rémi Cardona <remi@gentoo.org>
This commit is contained in:
Julien Cristau 2009-10-14 23:51:22 +02:00
parent d2a6a39543
commit a60e676f1f
3 changed files with 52 additions and 1 deletions

View File

@ -1282,7 +1282,7 @@ CORE_INCS='-I$(top_srcdir)/include -I$(top_builddir)/include'
# SHA1 hashing
AC_ARG_WITH([sha1],
[AS_HELP_STRING([--with-sha1=libmd|libcrypto],
[AS_HELP_STRING([--with-sha1=libmd|libgcrypt|libcrypto],
[choose SHA1 implementation])])
AC_CHECK_LIB([md], [SHA1Init], [HAVE_LIBMD=yes])
if test "x$with_sha1" = x && test "x$HAVE_LIBMD" = xyes; then
@ -1296,6 +1296,15 @@ if test "x$with_sha1" = xlibmd; then
[Use libmd SHA1 functions])
SHA1_LIBS=-lmd
fi
AC_CHECK_LIB([gcrypt], [gcry_md_open], [HAVE_LIBGCRYPT=yes])
if test "x$with_sha1" = x && test "x$HAVE_LIBGCRYPT" = xyes; then
with_sha1=libgcrypt
fi
if test "x$with_sha1" = xlibgcrypt; then
AC_DEFINE([HAVE_SHA1_IN_LIBGCRYPT], [1],
[Use libgcrypt SHA1 functions])
SHA1_LIBS=-lgcrypt
fi
# We don't need all of the OpenSSL libraries, just libcrypto
AC_CHECK_LIB([crypto], [SHA1_Init], [HAVE_LIBCRYPTO=yes])
PKG_CHECK_MODULES([OPENSSL], [openssl], [HAVE_OPENSSL_PKC=yes],

View File

@ -163,6 +163,9 @@
/* Define to use libmd SHA1 functions */
#undef HAVE_SHA1_IN_LIBMD
/* Define to use libgcrypt SHA1 functions */
#undef HAVE_SHA1_IN_LIBGCRYPT
/* Define to 1 if you have the `shmctl64' function. */
#undef HAVE_SHMCTL64

View File

@ -33,6 +33,45 @@ int x_sha1_final(void *ctx, unsigned char result[20])
return 1;
}
#elif defined(HAVE_SHA1_IN_LIBGCRYPT) /* Use libgcrypt for SHA1 */
# include <gcrypt.h>
void *x_sha1_init(void)
{
static int init;
gcry_md_hd_t h;
gcry_error_t err;
if (!init) {
if (!gcry_check_version(NULL))
return NULL;
gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
init = 1;
}
err = gcry_md_open(&h, GCRY_MD_SHA1, 0);
if (err)
return NULL;
return h;
}
int x_sha1_update(void *ctx, void *data, int size)
{
gcry_md_hd_t h = ctx;
gcry_md_write(h, data, size);
return 1;
}
int x_sha1_final(void *ctx, unsigned char result[20])
{
gcry_md_hd_t h = ctx;
memcpy(result, gcry_md_read(h, GCRY_MD_SHA1), 20);
gcry_md_close(h);
return 1;
}
#else /* Use OpenSSL's libcrypto */
# include <stddef.h> /* buggy openssl/sha.h wants size_t */