[PATCH 3/3] Add libgcrypt as an option for SHA1

Julien Cristau jcristau at debian.org
Wed Oct 14 14:51:22 PDT 2009


---
 configure.ac            |   11 ++++++++++-
 include/dix-config.h.in |    3 +++
 os/xsha1.c              |   39 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index 082f67d..9888528 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 a19c3c7..7f1fb18 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 2016980..723521e 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 */
-- 
1.6.4.3


--opJtzjQTFsWo+cga--


More information about the xorg-devel mailing list