[xserver] os: Add libsha1 as a choice of SHA1 implementation
Mikhail Gusarov
dottedmag at dottedmag.net
Wed Oct 28 11:40:27 PDT 2009
There are small systems which don't need OpenSSL or gcrypt.
Add libsha1 (http://github.com/dottedmag/libsha1) as an alternative
small SHA1 implementation.
Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>
---
configure.ac | 13 +++++++++++--
hw/kdrive/linux/evdev.c | 2 +-
include/dix-config.h.in | 3 +++
os/xsha1.c | 26 ++++++++++++++++++++++++++
4 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/configure.ac b/configure.ac
index e7d8a4b..02e9146 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1286,7 +1286,7 @@ CORE_INCS='-I$(top_srcdir)/include -I$(top_builddir)/include'
# SHA1 hashing
AC_ARG_WITH([sha1],
- [AS_HELP_STRING([--with-sha1=libmd|libgcrypt|libcrypto],
+ [AS_HELP_STRING([--with-sha1=libmd|libgcrypt|libcrypto|libsha1],
[choose SHA1 implementation])])
AC_CHECK_LIB([md], [SHA1Init], [HAVE_LIBMD=yes])
if test "x$with_sha1" = x && test "x$HAVE_LIBMD" = xyes; then
@@ -1309,6 +1309,15 @@ if test "x$with_sha1" = xlibgcrypt; then
[Use libgcrypt SHA1 functions])
SHA1_LIBS=-lgcrypt
fi
+AC_CHECK_LIB([sha1], [sha1_begin], [HAVE_LIBSHA1=yes])
+if test "x$with_sha1" = x && test "x$HAVE_LIBSHA1" = xyes; then
+ with_sha1=libsha1
+fi
+if test "x$with_sha1" = xlibsha1; then
+ AC_DEFINE([HAVE_SHA1_IN_LIBSHA1], [1],
+ [Use libsha1 for SHA1])
+ SHA1_LIBS=-lsha1
+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],
@@ -1979,7 +1988,7 @@ if test "$KDRIVE" = yes; then
KDRIVE_LOCAL_LIBS="$MAIN_LIB $DIX_LIB $KDRIVE_LIB $KDRIVE_STUB_LIB $CONFIG_LIB"
KDRIVE_LOCAL_LIBS="$KDRIVE_LOCAL_LIBS $FB_LIB $MI_LIB $KDRIVE_PURE_LIBS"
KDRIVE_LOCAL_LIBS="$KDRIVE_LOCAL_LIBS $KDRIVE_OS_LIB $OS_LIB"
- KDRIVE_LIBS="$TSLIB_LIBS $KDRIVE_LOCAL_LIBS $XSERVER_SYS_LIBS $GLX_SYS_LIBS"
+ KDRIVE_LIBS="$TSLIB_LIBS $KDRIVE_LOCAL_LIBS $XSERVER_SYS_LIBS $GLX_SYS_LIBS $DLOPEN_LIBS"
AC_SUBST([XEPHYR_LIBS])
AC_SUBST([XEPHYR_INCS])
diff --git a/hw/kdrive/linux/evdev.c b/hw/kdrive/linux/evdev.c
index b48302b..096a2dd 100644
--- a/hw/kdrive/linux/evdev.c
+++ b/hw/kdrive/linux/evdev.c
@@ -506,7 +506,7 @@ EvdevKbdDisable (KdKeyboardInfo *ki)
KdUnregisterFd (ki, ke->fd, TRUE);
- if (ioctl (fd, EVIOCGRAB, 0) < 0)
+ if (ioctl (ke->fd, EVIOCGRAB, 0) < 0)
perror ("Ungrabbing evdev keyboard device failed");
xfree (ke);
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 7f1fb18..ebf3733 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -166,6 +166,9 @@
/* Define to use libgcrypt SHA1 functions */
#undef HAVE_SHA1_IN_LIBGCRYPT
+/* Define to use libsha1 for SHA1 */
+#undef HAVE_SHA1_IN_LIBSHA1
+
/* Define to 1 if you have the `shmctl64' function. */
#undef HAVE_SHMCTL64
diff --git a/os/xsha1.c b/os/xsha1.c
index 723521e..94092ca 100644
--- a/os/xsha1.c
+++ b/os/xsha1.c
@@ -72,6 +72,32 @@ int x_sha1_final(void *ctx, unsigned char result[20])
return 1;
}
+#elif defined(HAVE_SHA1_IN_LIBSHA1) /* Use libsha1 */
+
+# include <libsha1.h>
+
+void *x_sha1_init(void)
+{
+ sha1_ctx *ctx = xalloc(sizeof(*ctx));
+ if(!ctx)
+ return NULL;
+ sha1_begin(ctx);
+ return ctx;
+}
+
+int x_sha1_update(void *ctx, void *data, int size)
+{
+ sha1_hash(data, size, ctx);
+ return 1;
+}
+
+int x_sha1_final(void *ctx, unsigned char result[20])
+{
+ sha1_end(result, ctx);
+ xfree(ctx);
+ return 1;
+}
+
#else /* Use OpenSSL's libcrypto */
# include <stddef.h> /* buggy openssl/sha.h wants size_t */
--
1.6.5
More information about the xorg-devel
mailing list