summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremyhu@freedesktop.org>2009-11-05 18:13:07 -0800
committerJeremy Huddleston <jeremyhu@freedesktop.org>2009-11-05 18:34:50 -0800
commit6b109919f6e1593b27b0760bb56a65b43fb86ea4 (patch)
treeb028f2271413bf86a50880600e7be99be8378a52
parent840a68dc5e3b4d285894f86df2a8c41fca5a4bec (diff)
SHA1: Add support for Common Crypto
libSystem on darwin can handle SHA1 computation without needing to pull in OpenSSL. See CC_crypto(3) Signed-off-by: Jeremy Huddleston <jeremyhu@freedesktop.org>
-rw-r--r--configure.ac14
-rw-r--r--include/dix-config.h.in3
-rw-r--r--os/xsha1.c28
3 files changed, 44 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index de58f2133..f8dc55b98 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1287,7 +1287,7 @@ CORE_INCS='-I$(top_srcdir)/include -I$(top_builddir)/include'
# SHA1 hashing
AC_ARG_WITH([sha1],
- [AS_HELP_STRING([--with-sha1=libc|libmd|libgcrypt|libcrypto|libsha1],
+ [AS_HELP_STRING([--with-sha1=libc|libmd|libgcrypt|libcrypto|libsha1|CommonCrypto],
[choose SHA1 implementation])])
AC_CHECK_FUNC([SHA1Init], [HAVE_SHA1_IN_LIBC=yes])
if test "x$with_sha1" = x && test "x$HAVE_SHA1_IN_LIBC" = xyes; then
@@ -1301,6 +1301,18 @@ if test "x$with_sha1" = xlibc; then
[Use libc SHA1 functions])
SHA1_LIBS=""
fi
+AC_CHECK_FUNC([CC_SHA1_Init], [HAVE_SHA1_IN_COMMONCRYPTO=yes])
+if test "x$with_sha1" = x && test "x$HAVE_SHA1_IN_COMMONCRYPTO" = xyes; then
+ with_sha1=CommonCrypto
+fi
+if test "x$with_sha1" = xCommonCrypto && test "x$HAVE_SHA1_IN_COMMONCRYPTO" != xyes; then
+ AC_MSG_ERROR([CommonCrypto requested but not found])
+fi
+if test "x$with_sha1" = xCommonCrypto; then
+ AC_DEFINE([HAVE_SHA1_IN_COMMONCRYPTO], [1],
+ [Use CommonCrypto SHA1 functions])
+ SHA1_LIBS=""
+fi
AC_CHECK_LIB([md], [SHA1Init], [HAVE_LIBMD=yes])
if test "x$with_sha1" = x && test "x$HAVE_LIBMD" = xyes; then
with_sha1=libmd
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 274ce89f9..109637115 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -163,6 +163,9 @@
/* Define to use libc SHA1 functions */
#undef HAVE_SHA1_IN_LIBC
+/* Define to use CommonCrypto SHA1 functions */
+#undef HAVE_SHA1_IN_COMMONCRYPTO
+
/* Define to use libmd SHA1 functions */
#undef HAVE_SHA1_IN_LIBMD
diff --git a/os/xsha1.c b/os/xsha1.c
index 229ce896d..355862fb1 100644
--- a/os/xsha1.c
+++ b/os/xsha1.c
@@ -34,6 +34,34 @@ int x_sha1_final(void *ctx, unsigned char result[20])
return 1;
}
+#elif defined(HAVE_SHA1_IN_COMMONCRYPTO) /* Use CommonCrypto for SHA1 */
+
+#include <CommonCrypto/CommonDigest.h>
+
+void *x_sha1_init(void)
+{
+ CC_SHA1_CTX *ctx = xalloc(sizeof(*ctx));
+ if (!ctx)
+ return NULL;
+ CC_SHA1_Init(ctx);
+ return ctx;
+}
+
+int x_sha1_update(void *ctx, void *data, int size)
+{
+ CC_SHA1_CTX *sha1_ctx = ctx;
+ CC_SHA1_Update(sha1_ctx, data, size);
+ return 1;
+}
+
+int x_sha1_final(void *ctx, unsigned char result[20])
+{
+ CC_SHA1_CTX *sha1_ctx = ctx;
+ CC_SHA1_Final(result, sha1_ctx);
+ xfree(sha1_ctx);
+ return 1;
+}
+
#elif defined(HAVE_SHA1_IN_LIBGCRYPT) /* Use libgcrypt for SHA1 */
# include <gcrypt.h>