diff options
author | Julien Cristau <jcristau@debian.org> | 2009-10-14 23:51:22 +0200 |
---|---|---|
committer | Julien Cristau <jcristau@debian.org> | 2009-10-15 01:18:03 +0200 |
commit | a60e676f1fd243c78859440b87652f523d3f2ec1 (patch) | |
tree | ddcb30f7c447e3ae420057ab1eef9351ff24da3a | |
parent | d2a6a395435919aff8943285f9cbfe6569a9728f (diff) |
Add libgcrypt as an option for SHA1
Signed-off-by: Julien Cristau <jcristau@debian.org>
Reviewed-by: RĂ©mi Cardona <remi@gentoo.org>
-rw-r--r-- | configure.ac | 11 | ||||
-rw-r--r-- | include/dix-config.h.in | 3 | ||||
-rw-r--r-- | os/xsha1.c | 39 |
3 files changed, 52 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index 082f67de2..9888528b2 100644 --- a/configure.ac +++ b/configure.ac @@ -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], diff --git a/include/dix-config.h.in b/include/dix-config.h.in index a19c3c7b8..7f1fb1836 100644 --- a/include/dix-config.h.in +++ b/include/dix-config.h.in @@ -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 diff --git a/os/xsha1.c b/os/xsha1.c index 20169807e..723521e05 100644 --- a/os/xsha1.c +++ b/os/xsha1.c @@ -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 */ |