From 6c6bbefdcf8a41dc71f9cbeca7ce972e2661fade Mon Sep 17 00:00:00 2001 From: Julien Cristau Date: Thu, 2 Apr 2009 02:34:49 +0200 Subject: [PATCH] Add libgcrypt as an option for sha1 --- configure.ac | 6 ++++++ include/dix-config.h.in | 3 +++ render/glyph.c | 12 ++++++++++++ 3 files changed, 21 insertions(+), 0 deletions(-) Index: xorg-server/configure.ac =================================================================== --- xorg-server.orig/configure.ac +++ xorg-server/configure.ac @@ -1108,6 +1108,12 @@ [Use libmd SHA1 functions instead of OpenSSL libcrypto])]) fi +if test "x$SHA1_LIB" = "x"; then + AC_CHECK_LIB([gcrypt], [gcry_md_open], [SHA1_LIB="-lgcrypt" + AC_DEFINE([HAVE_SHA1_IN_LIBGCRYPT], [1], + [Use libgcrypt SHA1 functions instead of OpenSSL libcrypto])]) +fi + if test "x$SHA1_LIB" = "x" ; then PKG_CHECK_EXISTS([OPENSSL], [openssl], [HAVE_OPENSSL_PKC=yes], [HAVE_OPENSSL_PKC=no]) Index: xorg-server/include/dix-config.h.in =================================================================== --- xorg-server.orig/include/dix-config.h.in +++ xorg-server/include/dix-config.h.in @@ -157,6 +157,9 @@ /* Define to use libmd SHA1 functions instead of OpenSSL libcrypto */ #undef HAVE_SHA1_IN_LIBMD +/* Define to use libgcrypt SHA1 functions instead of OpenSSL libcrypto */ +#undef HAVE_SHA1_IN_LIBGCRYPT + /* Define to 1 if you have the `shmctl64' function. */ #undef HAVE_SHMCTL64 Index: xorg-server/render/glyph.c =================================================================== --- xorg-server.orig/render/glyph.c +++ xorg-server/render/glyph.c @@ -28,6 +28,8 @@ #ifdef HAVE_SHA1_IN_LIBMD /* Use libmd for SHA1 */ # include +#elif defined(HAVE_SHA1_IN_LIBGCRYPT) +# include #else /* Use OpenSSL's libcrypto */ # include /* buggy openssl/sha.h wants size_t */ # include @@ -205,6 +207,26 @@ SHA1Update (&ctx, gi, sizeof (xGlyphInfo)); SHA1Update (&ctx, bits, size); SHA1Final (sha1, &ctx); +#elif defined(HAVE_SHA1_IN_LIBGCRYPT) /* Use libgcrypt for SHA1 */ + static int init; + gcry_md_hd_t h; + gcry_error_t err; + + if (!init) { + if (!gcry_check_version(NULL)) + return BadAlloc; + 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 BadAlloc; + gcry_md_write(h, gi, sizeof (xGlyphInfo)); + gcry_md_write(h, bits, size); + memcpy(sha1, gcry_md_read(h, GCRY_MD_SHA1), 20); + gcry_md_close(h); #else /* Use OpenSSL's libcrypto */ SHA_CTX ctx; int success;