-From 3fbec7d4db59bbd24a9a768182000a1d004c5bc5 Mon Sep 17 00:00:00 2001
-From: Tiago Vignatti <tiago.vignatti@nokia.com>
-Date: Wed, 24 Mar 2010 17:27:43 +0200
-Subject: [PATCH] Revert "Revert "Render: Use built-in SHA1 library""
-
-This reverts commit a39377cbcbd3091095efbeab25bec18ae520147e.
-
-Conflicts:
-
- configure.ac
- include/dix-config.h.in
- render/glyph.c
-
-
-Ok ok ok, it's the revert of a revert! Buhhh...
-
-Once upon a time, back in 2007, Carl Worth was trying to boost render
-(4c6abe1c). He prefered to use a "strong hash" to compare glyphs (19b3b1fd)
-and used openssl library for this. Further, for the same purpose, people
-started to set other SHA1 implementations in autoconf. And a lot of
-alternatives appeared - six, to be precise. In the mean time, John Tapsell
-commit a builtin implementation of SHA1. In the same day, Keith Packard
-reverted, stating "X.org should not be providing a custom SHA1
-implementation." (a39377cb). Now, users ended up with Xorg setting the default
-as the openssl's one (libcrypto), which takes 88 kB of xserver's private RSS.
-Besides that, we have a ridiculous "configure dot fucking ac stanza to work
-out which lib to use is almost as long as sha1.c was", to quote daniels.
-
-My simple argument against Keith's decision is simple: we can save 316 kB of
-RSS in a standalone Xorg call. Therefore, I'm in favor to keep our own very
-simple and shiny SHA1 implementation.
-
----
-I'm not comfortable yet to send this patch around without see if there's any
-regressions on render or eventually get some ack from Carl.
-
-
- configure.ac | 89 +------------------------
- include/dix-config.h.in | 15 ----
- os/Makefile.am | 1 -
- os/xsha1.c | 168 ---------------------------------------------
- render/Makefile.am | 3 +
- render/glyph.c | 25 ++-----
- render/sha1.c | 173 +++++++++++++++++++++++++++++++++++++++++++++++
- render/sha1.h | 63 +++++++++++++++++
- 8 files changed, 248 insertions(+), 289 deletions(-)
- delete mode 100644 os/xsha1.c
- create mode 100644 render/sha1.c
- create mode 100644 render/sha1.h
-
-diff --git a/configure.ac b/configure.ac
-index 3e8ea10..ef21aa0 100644
---- a/configure.ac
-+++ b/configure.ac
-@@ -1305,7 +1305,7 @@ AC_DEFINE(BIGREQS, 1, [Support BigRequests extension])
+diff -urN xorg-server-1.17.0.org/configure.ac xorg-server-1.17.0/configure.ac
+--- xorg-server-1.17.0.org/configure.ac 2015-02-02 07:40:17.000000000 +0100
++++ xorg-server-1.17.0/configure.ac 2015-02-04 19:34:23.458568095 +0100
+@@ -1544,7 +1544,7 @@
if test "x$SPECIAL_DTRACE_OBJECTS" = "xyes" ; then
DIX_LIB='$(top_builddir)/dix/dix.O'
-- OS_LIB='$(top_builddir)/os/os.O $(SHA1_LIBS)'
-+ OS_LIB='$(top_builddir)/os/os.O'
+- OS_LIB='$(top_builddir)/os/os.O $(SHA1_LIBS) $(DLOPEN_LIBS) $(LIBUNWIND_LIBS)'
++ OS_LIB='$(top_builddir)/os/os.O $(DLOPEN_LIBS) $(LIBUNWIND_LIBS)'
else
DIX_LIB='$(top_builddir)/dix/libdix.la'
OS_LIB='$(top_builddir)/os/libos.la'
-@@ -1349,99 +1349,6 @@
- MIEXT_SHADOW_LIB='$(top_builddir)/miext/shadow/libshadow.la'
+@@ -1566,124 +1566,6 @@
+ MIEXT_SYNC_LIB='$(top_builddir)/miext/sync/libsync.la'
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|CommonCrypto],
+- [AS_HELP_STRING([--with-sha1=libc|libmd|libnettle|libgcrypt|libcrypto|libsha1|CommonCrypto|CryptoAPI],
- [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
- [Use CommonCrypto SHA1 functions])
- SHA1_LIBS=""
-fi
+-dnl stdcall functions cannot be tested with AC_CHECK_LIB
+-AC_CHECK_HEADER([wincrypt.h], [HAVE_SHA1_IN_CRYPTOAPI=yes], [], [#include <windows.h>])
+-if test "x$with_sha1" = x && test "x$HAVE_SHA1_IN_CRYPTOAPI" = xyes; then
+- with_sha1=CryptoAPI
+-fi
+-if test "x$with_sha1" = xCryptoAPI && test "x$HAVE_SHA1_IN_CRYPTOAPI" != xyes; then
+- AC_MSG_ERROR([CryptoAPI requested but not found])
+-fi
+-if test "x$with_sha1" = xCryptoAPI; then
+- AC_DEFINE([HAVE_SHA1_IN_CRYPTOAPI], [1],
+- [Use CryptoAPI 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
- [Use libmd SHA1 functions])
- SHA1_LIBS=-lmd
-fi
--AC_CHECK_LIB([sha1], [sha1_begin], [HAVE_LIBSHA1=yes])
+-PKG_CHECK_MODULES([LIBSHA1], [libsha1], [HAVE_LIBSHA1=yes], [HAVE_LIBSHA1=no])
-if test "x$with_sha1" = x && test "x$HAVE_LIBSHA1" = xyes; then
- with_sha1=libsha1
-fi
- [Use libsha1 for SHA1])
- SHA1_LIBS=-lsha1
-fi
+-AC_CHECK_LIB([nettle], [nettle_sha1_init], [HAVE_LIBNETTLE=yes])
+-if test "x$with_sha1" = x && test "x$HAVE_LIBNETTLE" = xyes; then
+- with_sha1=libnettle
+-fi
+-if test "x$with_sha1" = xlibnettle && test "x$HAVE_LIBNETTLE" != xyes; then
+- AC_MSG_ERROR([libnettle requested but not found])
+-fi
+-if test "x$with_sha1" = xlibnettle; then
+- AC_DEFINE([HAVE_SHA1_IN_LIBNETTLE], [1],
+- [Use libnettle SHA1 functions])
+- SHA1_LIBS=-lnettle
+-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
PKG_CHECK_MODULES([XSERVERCFLAGS], [$REQUIRED_MODULES $REQUIRED_LIBS])
PKG_CHECK_MODULES([XSERVERLIBS], [$REQUIRED_LIBS])
-diff --git a/include/dix-config.h.in b/include/dix-config.h.in
-index 058c8fd..d6e99a5 100644
---- a/include/dix-config.h.in
-+++ b/include/dix-config.h.in
-@@ -160,21 +160,6 @@
+diff -urN xorg-server-1.17.0.org/include/dix-config.h.in xorg-server-1.17.0/include/dix-config.h.in
+--- xorg-server-1.17.0.org/include/dix-config.h.in 2014-10-09 14:15:31.000000000 +0200
++++ xorg-server-1.17.0/include/dix-config.h.in 2015-02-04 19:34:23.455234679 +0100
+@@ -152,27 +152,6 @@
/* Define to 1 if you have the <rpcsvc/dbm.h> header file. */
#undef HAVE_RPCSVC_DBM_H
-/* Define to use CommonCrypto SHA1 functions */
-#undef HAVE_SHA1_IN_COMMONCRYPTO
-
+-/* Define to use CryptoAPI SHA1 functions */
+-#undef HAVE_SHA1_IN_CRYPTOAPI
+-
-/* Define to use libmd SHA1 functions */
-#undef HAVE_SHA1_IN_LIBMD
-
-/* Define to use libgcrypt SHA1 functions */
-#undef HAVE_SHA1_IN_LIBGCRYPT
-
+-/* Define to use libnettle SHA1 functions */
+-#undef HAVE_SHA1_IN_LIBNETTLE
+-
-/* 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/Makefile.am b/os/Makefile.am
-index 66a4a0f..b8c1636 100644
---- a/os/Makefile.am
-+++ b/os/Makefile.am
-@@ -22,7 +22,6 @@ libos_la_SOURCES = \
- strcasecmp.c \
- strcasestr.c \
+diff -urN xorg-server-1.17.0.org/os/Makefile.am xorg-server-1.17.0/os/Makefile.am
+--- xorg-server-1.17.0.org/os/Makefile.am 2013-11-12 00:15:00.000000000 +0100
++++ xorg-server-1.17.0/os/Makefile.am 2015-02-04 19:34:23.455234679 +0100
+@@ -21,7 +21,6 @@
+ osinit.c \
+ utils.c \
xdmauth.c \
- xsha1.c \
xstrans.c \
xprintf.c \
$(XORG_SRCS)
-diff --git a/os/xsha1.c b/os/xsha1.c
-deleted file mode 100644
-index 355862f..0000000
---- a/os/xsha1.c
-+++ /dev/null
-@@ -1,168 +0,0 @@
+diff -urN xorg-server-1.17.0.org/os/xsha1.c xorg-server-1.17.0/os/xsha1.c
+--- xorg-server-1.17.0.org/os/xsha1.c 2015-01-18 00:42:52.000000000 +0100
++++ xorg-server-1.17.0/os/xsha1.c 2015-02-04 19:34:23.455234679 +0100
+@@ -23,270 +23,3 @@
+ * DEALINGS IN THE SOFTWARE.
+ */
+
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-#include "xsha1.h"
-
-#if defined(HAVE_SHA1_IN_LIBMD) /* Use libmd for SHA1 */ \
-- || defined(HAVE_SHA1_IN_LIBC) /* Use libc for SHA1 */
+- || defined(HAVE_SHA1_IN_LIBC) /* Use libc for SHA1 */
-
--# include <sha1.h>
+-#include <sha1.h>
-
--void *x_sha1_init(void)
+-void *
+-x_sha1_init(void)
-{
-- SHA1_CTX *ctx = xalloc(sizeof(*ctx));
+- SHA1_CTX *ctx = malloc(sizeof(*ctx));
+-
- if (!ctx)
- return NULL;
- SHA1Init(ctx);
- return ctx;
-}
-
--int x_sha1_update(void *ctx, void *data, int size)
+-int
+-x_sha1_update(void *ctx, void *data, int size)
-{
- SHA1_CTX *sha1_ctx = ctx;
+-
- SHA1Update(sha1_ctx, data, size);
- return 1;
-}
-
--int x_sha1_final(void *ctx, unsigned char result[20])
+-int
+-x_sha1_final(void *ctx, unsigned char result[20])
-{
- SHA1_CTX *sha1_ctx = ctx;
+-
- SHA1Final(result, sha1_ctx);
-- xfree(sha1_ctx);
+- free(sha1_ctx);
- return 1;
-}
-
--#elif defined(HAVE_SHA1_IN_COMMONCRYPTO) /* Use CommonCrypto for SHA1 */
+-#elif defined(HAVE_SHA1_IN_COMMONCRYPTO) /* Use CommonCrypto for SHA1 */
-
-#include <CommonCrypto/CommonDigest.h>
-
--void *x_sha1_init(void)
+-void *
+-x_sha1_init(void)
-{
-- CC_SHA1_CTX *ctx = xalloc(sizeof(*ctx));
+- CC_SHA1_CTX *ctx = malloc(sizeof(*ctx));
+-
- if (!ctx)
- return NULL;
- CC_SHA1_Init(ctx);
- return ctx;
-}
-
--int x_sha1_update(void *ctx, void *data, int size)
+-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])
+-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);
+- free(sha1_ctx);
+- return 1;
+-}
+-
+-#elif defined(HAVE_SHA1_IN_CRYPTOAPI) /* Use CryptoAPI for SHA1 */
+-
+-#define WIN32_LEAN_AND_MEAN
+-#include <X11/Xwindows.h>
+-#include <wincrypt.h>
+-
+-static HCRYPTPROV hProv;
+-
+-void *
+-x_sha1_init(void)
+-{
+- HCRYPTHASH *ctx = malloc(sizeof(*ctx));
+-
+- if (!ctx)
+- return NULL;
+- CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
+- CryptCreateHash(hProv, CALG_SHA1, 0, 0, ctx);
+- return ctx;
+-}
+-
+-int
+-x_sha1_update(void *ctx, void *data, int size)
+-{
+- HCRYPTHASH *hHash = ctx;
+-
+- CryptHashData(*hHash, data, size, 0);
+- return 1;
+-}
+-
+-int
+-x_sha1_final(void *ctx, unsigned char result[20])
+-{
+- HCRYPTHASH *hHash = ctx;
+- DWORD len = 20;
+-
+- CryptGetHashParam(*hHash, HP_HASHVAL, result, &len, 0);
+- CryptDestroyHash(*hHash);
+- CryptReleaseContext(hProv, 0);
+- free(ctx);
+- return 1;
+-}
+-
+-#elif defined(HAVE_SHA1_IN_LIBNETTLE) /* Use libnettle for SHA1 */
+-
+-#include <nettle/sha.h>
+-
+-void *
+-x_sha1_init(void)
+-{
+- struct sha1_ctx *ctx = malloc(sizeof(*ctx));
+-
+- if (!ctx)
+- return NULL;
+- sha1_init(ctx);
+- return ctx;
+-}
+-
+-int
+-x_sha1_update(void *ctx, void *data, int size)
+-{
+- sha1_update(ctx, size, data);
+- return 1;
+-}
+-
+-int
+-x_sha1_final(void *ctx, unsigned char result[20])
+-{
+- sha1_digest(ctx, 20, result);
+- free(ctx);
- return 1;
-}
-
--#elif defined(HAVE_SHA1_IN_LIBGCRYPT) /* Use libgcrypt for SHA1 */
+-#elif defined(HAVE_SHA1_IN_LIBGCRYPT) /* Use libgcrypt for SHA1 */
-
--# include <gcrypt.h>
+-#include <gcrypt.h>
-
--void *x_sha1_init(void)
+-void *
+-x_sha1_init(void)
-{
- static int init;
- gcry_md_hd_t h;
- return h;
-}
-
--int x_sha1_update(void *ctx, void *data, int size)
+-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])
+-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;
-}
-
--#elif defined(HAVE_SHA1_IN_LIBSHA1) /* Use libsha1 */
+-#elif defined(HAVE_SHA1_IN_LIBSHA1) /* Use libsha1 */
-
--# include <libsha1.h>
+-#include <libsha1.h>
-
--void *x_sha1_init(void)
+-void *
+-x_sha1_init(void)
-{
-- sha1_ctx *ctx = xalloc(sizeof(*ctx));
-- if(!ctx)
+- sha1_ctx *ctx = malloc(sizeof(*ctx));
+-
+- if (!ctx)
- return NULL;
- sha1_begin(ctx);
- return ctx;
-}
-
--int x_sha1_update(void *ctx, void *data, int size)
+-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])
+-int
+-x_sha1_final(void *ctx, unsigned char result[20])
-{
- sha1_end(result, ctx);
-- xfree(ctx);
+- free(ctx);
- return 1;
-}
-
--#else /* Use OpenSSL's libcrypto */
+-#else /* Use OpenSSL's libcrypto */
-
--# include <stddef.h> /* buggy openssl/sha.h wants size_t */
--# include <openssl/sha.h>
+-#include <stddef.h> /* buggy openssl/sha.h wants size_t */
+-#include <openssl/sha.h>
-
--void *x_sha1_init(void)
+-void *
+-x_sha1_init(void)
-{
- int ret;
-- SHA_CTX *ctx = xalloc(sizeof(*ctx));
+- SHA_CTX *ctx = malloc(sizeof(*ctx));
+-
- if (!ctx)
- return NULL;
- ret = SHA1_Init(ctx);
- if (!ret) {
-- xfree(ctx);
+- free(ctx);
- return NULL;
- }
- return ctx;
-}
-
--int x_sha1_update(void *ctx, void *data, int size)
+-int
+-x_sha1_update(void *ctx, void *data, int size)
-{
- int ret;
- SHA_CTX *sha_ctx = ctx;
+-
- ret = SHA1_Update(sha_ctx, data, size);
- if (!ret)
-- xfree(sha_ctx);
+- free(sha_ctx);
- return ret;
-}
-
--int x_sha1_final(void *ctx, unsigned char result[20])
+-int
+-x_sha1_final(void *ctx, unsigned char result[20])
-{
- int ret;
- SHA_CTX *sha_ctx = ctx;
+-
- ret = SHA1_Final(result, sha_ctx);
-- xfree(sha_ctx);
+- free(sha_ctx);
- return ret;
-}
-
-#endif
-diff --git a/render/Makefile.am b/render/Makefile.am
-index 216c613..bb46702 100644
---- a/render/Makefile.am
-+++ b/render/Makefile.am
-@@ -14,8 +14,11 @@ librender_la_SOURCES = \
- mitri.c \
- picture.c \
- render.c \
-+ sha1.c \
- renderedge.c
-
- if XORG
- sdk_HEADERS = picture.h mipict.h glyphstr.h picturestr.h renderedge.h
- endif
-+
-+EXTRA_DIST = sha1.h
-diff --git a/render/glyph.c b/render/glyph.c
-index 0b864ad..e14530a 100644
---- a/render/glyph.c
-+++ b/render/glyph.c
+diff -urN xorg-server-1.17.0.org/render/glyph.c xorg-server-1.17.0/render/glyph.c
+--- xorg-server-1.17.0.org/render/glyph.c 2015-01-18 00:42:52.000000000 +0100
++++ xorg-server-1.17.0/render/glyph.c 2015-02-04 19:34:23.458568095 +0100
@@ -26,8 +26,7 @@
#include <dix-config.h>
#endif
#include "misc.h"
#include "scrnintstr.h"
#include "os.h"
-@@ -193,21 +192,13 @@ HashGlyph (xGlyphInfo *gi,
- unsigned long size,
- unsigned char sha1[20])
+@@ -165,21 +164,13 @@
+ HashGlyph(xGlyphInfo * gi,
+ CARD8 *bits, unsigned long size, unsigned char sha1[20])
{
- void *ctx = x_sha1_init();
- int success;
--
++ SHA1_CTX ctx;
+
- if (!ctx)
-- return BadAlloc;
--
+- return BadAlloc;
++ SHA1Init (&ctx);
++ SHA1Update (&ctx, gi, sizeof (xGlyphInfo));
++ SHA1Update (&ctx, bits, size);
++ SHA1Final (sha1, &ctx);
+
- success = x_sha1_update(ctx, gi, sizeof(xGlyphInfo));
- if (!success)
-- return BadAlloc;
+- return BadAlloc;
- success = x_sha1_update(ctx, bits, size);
- if (!success)
-- return BadAlloc;
+- return BadAlloc;
- success = x_sha1_final(ctx, sha1);
- if (!success)
-- return BadAlloc;
-+ SHA1_CTX ctx;
-+
-+ SHA1Init (&ctx);
-+ SHA1Update (&ctx, gi, sizeof (xGlyphInfo));
-+ SHA1Update (&ctx, bits, size);
-+ SHA1Final (sha1, &ctx);
-+
+- return BadAlloc;
return Success;
}
-diff --git a/render/sha1.c b/render/sha1.c
-new file mode 100644
-index 0000000..820eb2a
---- /dev/null
-+++ b/render/sha1.c
+diff -urN xorg-server-1.17.0.org/render/Makefile.am xorg-server-1.17.0/render/Makefile.am
+--- xorg-server-1.17.0.org/render/Makefile.am 2013-06-18 18:03:42.000000000 +0200
++++ xorg-server-1.17.0/render/Makefile.am 2015-02-04 19:34:23.455234679 +0100
+@@ -13,8 +13,11 @@
+ mitrap.c \
+ mitri.c \
+ picture.c \
++ sha1.c \
+ render.c
+
+ if XORG
+ sdk_HEADERS = picture.h mipict.h glyphstr.h picturestr.h
+ endif
++
++EXTRA_DIST = sha1.h
+diff -urN xorg-server-1.17.0.org/render/sha1.c xorg-server-1.17.0/render/sha1.c
+--- xorg-server-1.17.0.org/render/sha1.c 1970-01-01 01:00:00.000000000 +0100
++++ xorg-server-1.17.0/render/sha1.c 2015-02-04 19:34:23.458568095 +0100
@@ -0,0 +1,173 @@
+/*
+ * SHA-1 in C
+ }
+}
+
-diff --git a/render/sha1.h b/render/sha1.h
-new file mode 100644
-index 0000000..ace7d97
---- /dev/null
-+++ b/render/sha1.h
+diff -urN xorg-server-1.17.0.org/render/sha1.h xorg-server-1.17.0/render/sha1.h
+--- xorg-server-1.17.0.org/render/sha1.h 1970-01-01 01:00:00.000000000 +0100
++++ xorg-server-1.17.0/render/sha1.h 2015-02-04 19:34:23.458568095 +0100
@@ -0,0 +1,63 @@
+/*
+ * SHA-1 in C
+
+#endif /* _SHA1_H */
+
---
-1.6.0.4
-