]> git.pld-linux.org Git - packages/xorg-xserver-server.git/blame - xorg-xserver-server-builtin-SHA1.patch
- allow building with current headers and libs
[packages/xorg-xserver-server.git] / xorg-xserver-server-builtin-SHA1.patch
CommitLineData
99b5f9cb
JR
1This patch is a backport of the following:
2
d2f7eaa2 3From 3fbec7d4db59bbd24a9a768182000a1d004c5bc5 Mon Sep 17 00:00:00 2001
4From: Tiago Vignatti <tiago.vignatti@nokia.com>
5Date: Wed, 24 Mar 2010 17:27:43 +0200
6Subject: [PATCH] Revert "Revert "Render: Use built-in SHA1 library""
7
8This reverts commit a39377cbcbd3091095efbeab25bec18ae520147e.
9
10Conflicts:
11
12 configure.ac
13 include/dix-config.h.in
14 render/glyph.c
15
16
17Ok ok ok, it's the revert of a revert! Buhhh...
18
19Once upon a time, back in 2007, Carl Worth was trying to boost render
20(4c6abe1c). He prefered to use a "strong hash" to compare glyphs (19b3b1fd)
21and used openssl library for this. Further, for the same purpose, people
22started to set other SHA1 implementations in autoconf. And a lot of
23alternatives appeared - six, to be precise. In the mean time, John Tapsell
24commit a builtin implementation of SHA1. In the same day, Keith Packard
25reverted, stating "X.org should not be providing a custom SHA1
26implementation." (a39377cb). Now, users ended up with Xorg setting the default
27as the openssl's one (libcrypto), which takes 88 kB of xserver's private RSS.
28Besides that, we have a ridiculous "configure dot fucking ac stanza to work
29out which lib to use is almost as long as sha1.c was", to quote daniels.
30
31My simple argument against Keith's decision is simple: we can save 316 kB of
32RSS in a standalone Xorg call. Therefore, I'm in favor to keep our own very
33simple and shiny SHA1 implementation.
34
35---
36I'm not comfortable yet to send this patch around without see if there's any
37regressions on render or eventually get some ack from Carl.
38
39
99b5f9cb
JR
40diff -urN xorg-server-1.6.5/configure.ac xorg-server-1.6.5-sha1/configure.ac
41--- xorg-server-1.6.5/configure.ac 2010-04-29 12:45:59.279129860 +0200
42+++ xorg-server-1.6.5-sha1/configure.ac 2010-04-29 12:41:28.611190310 +0200
43@@ -1098,27 +1098,6 @@
d2f7eaa2 44 MIEXT_SHADOW_LIB='$(top_builddir)/miext/shadow/libshadow.la'
45 CORE_INCS='-I$(top_srcdir)/include -I$(top_builddir)/include'
46
99b5f9cb
JR
47-# OpenSSL used for SHA1 hashing in render/glyph.c, but we don't need all of
48-# the OpenSSL libraries, just libcrypto
49-# Some systems have matching functionality in the smaller/simpler libmd
50-# Builders who want to force a choice can set SHA1_LIB and SHA1_CFLAGS
51-if test "x$SHA1_LIB" = "x" ; then
52- AC_CHECK_LIB([md], [SHA1Init], [SHA1_LIB="-lmd"
53- AC_DEFINE([HAVE_SHA1_IN_LIBMD], [1],
54- [Use libmd SHA1 functions instead of OpenSSL libcrypto])])
d2f7eaa2 55-fi
99b5f9cb
JR
56-
57-if test "x$SHA1_LIB" = "x" ; then
58- PKG_CHECK_EXISTS([OPENSSL], [openssl], [HAVE_OPENSSL_PKC=yes],
59- [HAVE_OPENSSL_PKC=no])
60- if test "x$HAVE_OPENSSL_PKC" = xyes; then
61- REQUIRED_LIBS="$REQUIRED_LIBS openssl"
62- else
63- AC_CHECK_LIB([crypto], [SHA1_Init], [SHA1_LIB="-lcrypto"],
64- [AC_MSG_ERROR([OpenSSL must be installed in order to build the X server.])])
65- fi
d2f7eaa2 66-fi
d2f7eaa2 67-
68 PKG_CHECK_MODULES([XSERVERCFLAGS], [$REQUIRED_MODULES $REQUIRED_LIBS])
69 PKG_CHECK_MODULES([XSERVERLIBS], [$REQUIRED_LIBS])
70
99b5f9cb
JR
71@@ -1137,9 +1116,9 @@
72 # XSERVER_SYS_LIBS is the set of out-of-tree libraries which all servers
73 # require.
74 #
75-XSERVER_CFLAGS="${XSERVERCFLAGS_CFLAGS} ${SHA1_CFLAGS}"
76+XSERVER_CFLAGS="${XSERVERCFLAGS_CFLAGS}"
77 XSERVER_LIBS="$DIX_LIB $CONFIG_LIB $MI_LIB $OS_LIB"
78-XSERVER_SYS_LIBS="${XSERVERLIBS_LIBS} ${SYS_LIBS} ${LIBS} ${SHA1_LIB}"
79+XSERVER_SYS_LIBS="${XSERVERLIBS_LIBS} ${SYS_LIBS} ${LIBS}"
80 AC_SUBST([XSERVER_LIBS])
81 AC_SUBST([XSERVER_SYS_LIBS])
82
83diff -urN xorg-server-1.6.5/include/dix-config.h.in xorg-server-1.6.5-sha1/include/dix-config.h.in
84--- xorg-server-1.6.5/include/dix-config.h.in 2009-10-12 04:52:40.000000000 +0200
85+++ xorg-server-1.6.5-sha1/include/dix-config.h.in 2010-04-29 12:43:23.344249866 +0200
86@@ -154,9 +154,6 @@
d2f7eaa2 87 /* Define to 1 if you have the <rpcsvc/dbm.h> header file. */
88 #undef HAVE_RPCSVC_DBM_H
89
99b5f9cb 90-/* Define to use libmd SHA1 functions instead of OpenSSL libcrypto */
d2f7eaa2 91-#undef HAVE_SHA1_IN_LIBMD
d2f7eaa2 92-
93 /* Define to 1 if you have the `shmctl64' function. */
94 #undef HAVE_SHMCTL64
95
99b5f9cb
JR
96diff -urN xorg-server-1.6.5/render/glyph.c xorg-server-1.6.5-sha1/render/glyph.c
97--- xorg-server-1.6.5/render/glyph.c 2009-10-12 04:52:40.000000000 +0200
98+++ xorg-server-1.6.5-sha1/render/glyph.c 2010-04-29 12:45:06.342124084 +0200
99@@ -26,13 +26,7 @@
100 #include <dix-config.h>
101 #endif
102
103-#ifdef HAVE_SHA1_IN_LIBMD /* Use libmd for SHA1 */
d2f7eaa2 104-# include <sha1.h>
d2f7eaa2 105-#else /* Use OpenSSL's libcrypto */
d2f7eaa2 106-# include <stddef.h> /* buggy openssl/sha.h wants size_t */
107-# include <openssl/sha.h>
d2f7eaa2 108-#endif
d2f7eaa2 109-
110+#include "sha1.h"
111 #include "misc.h"
112 #include "scrnintstr.h"
113 #include "os.h"
99b5f9cb 114@@ -198,33 +192,12 @@
d2f7eaa2 115 unsigned long size,
116 unsigned char sha1[20])
117 {
99b5f9cb
JR
118-#ifdef HAVE_SHA1_IN_LIBMD /* Use libmd for SHA1 */
119 SHA1_CTX ctx;
120
121 SHA1Init (&ctx);
122 SHA1Update (&ctx, gi, sizeof (xGlyphInfo));
123 SHA1Update (&ctx, bits, size);
124 SHA1Final (sha1, &ctx);
125-#else /* Use OpenSSL's libcrypto */
126- SHA_CTX ctx;
d2f7eaa2 127- int success;
128-
99b5f9cb
JR
129- success = SHA1_Init (&ctx);
130- if (! success)
d2f7eaa2 131- return BadAlloc;
132-
99b5f9cb
JR
133- success = SHA1_Update (&ctx, gi, sizeof (xGlyphInfo));
134- if (! success)
d2f7eaa2 135- return BadAlloc;
99b5f9cb
JR
136-
137- success = SHA1_Update (&ctx, bits, size);
138- if (! success)
d2f7eaa2 139- return BadAlloc;
99b5f9cb
JR
140-
141- success = SHA1_Final (sha1, &ctx);
142- if (! success)
d2f7eaa2 143- return BadAlloc;
99b5f9cb
JR
144-#endif
145
d2f7eaa2 146 return Success;
147 }
99b5f9cb
JR
148diff -urN xorg-server-1.6.5/render/Makefile.am xorg-server-1.6.5-sha1/render/Makefile.am
149--- xorg-server-1.6.5/render/Makefile.am 2008-11-24 22:24:35.000000000 +0100
150+++ xorg-server-1.6.5-sha1/render/Makefile.am 2010-04-29 12:39:49.187124726 +0200
151@@ -14,8 +14,11 @@
152 mitri.c \
153 picture.c \
154 render.c \
155+ sha1.c \
156 renderedge.c
d2f7eaa2 157
99b5f9cb
JR
158 if XORG
159 sdk_HEADERS = picture.h mipict.h glyphstr.h picturestr.h renderedge.h
160 endif
161+
162+EXTRA_DIST = sha1.h
163diff -urN xorg-server-1.6.5/render/sha1.c xorg-server-1.6.5-sha1/render/sha1.c
164--- xorg-server-1.6.5/render/sha1.c 1970-01-01 01:00:00.000000000 +0100
165+++ xorg-server-1.6.5-sha1/render/sha1.c 2010-04-29 12:39:49.191124529 +0200
d2f7eaa2 166@@ -0,0 +1,173 @@
167+/*
168+ * SHA-1 in C
169+ * By Steve Reid <steve@edmweb.com>
170+ * 100% Public Domain
171+ *
172+ * Test Vectors (from FIPS PUB 180-1)
173+ * "abc"
174+ * A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
175+ * "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
176+ * 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
177+ * A million repetitions of "a"
178+ * 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
179+ */
180+
181+#include <sys/param.h>
182+#include <string.h>
183+#include <sha1.h>
184+
185+#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
186+
187+/*
188+ * blk0() and blk() perform the initial expand.
189+ * I got the idea of expanding during the round function from SSLeay
190+ */
191+#if BYTE_ORDER == LITTLE_ENDIAN
192+# define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
193+ |(rol(block->l[i],8)&0x00FF00FF))
194+#else
195+# define blk0(i) block->l[i]
196+#endif
197+#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
198+ ^block->l[(i+2)&15]^block->l[i&15],1))
199+
200+/*
201+ * (R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1
202+ */
203+#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
204+#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
205+#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
206+#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
207+#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
208+
209+/*
210+ * Hash a single 512-bit block. This is the core of the algorithm.
211+ */
212+void
213+SHA1Transform(uint32_t state[5], const uint8_t buffer[SHA1_BLOCK_LENGTH])
214+{
215+ uint32_t a, b, c, d, e;
216+ uint8_t workspace[SHA1_BLOCK_LENGTH];
217+ typedef union {
218+ uint8_t c[64];
219+ uint32_t l[16];
220+ } CHAR64LONG16;
221+ CHAR64LONG16 *block = (CHAR64LONG16 *)workspace;
222+
223+ (void)memcpy(block, buffer, SHA1_BLOCK_LENGTH);
224+
225+ /* Copy context->state[] to working vars */
226+ a = state[0];
227+ b = state[1];
228+ c = state[2];
229+ d = state[3];
230+ e = state[4];
231+
232+ /* 4 rounds of 20 operations each. Loop unrolled. */
233+ R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
234+ R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
235+ R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
236+ R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
237+ R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
238+ R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
239+ R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
240+ R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
241+ R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
242+ R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
243+ R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
244+ R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
245+ R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
246+ R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
247+ R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
248+ R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
249+ R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
250+ R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
251+ R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
252+ R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
253+
254+ /* Add the working vars back into context.state[] */
255+ state[0] += a;
256+ state[1] += b;
257+ state[2] += c;
258+ state[3] += d;
259+ state[4] += e;
260+
261+ /* Wipe variables */
262+ a = b = c = d = e = 0;
263+}
264+
265+
266+/*
267+ * SHA1Init - Initialize new context
268+ */
269+void
270+SHA1Init(SHA1_CTX *context)
271+{
272+
273+ /* SHA1 initialization constants */
274+ context->count = 0;
275+ context->state[0] = 0x67452301;
276+ context->state[1] = 0xEFCDAB89;
277+ context->state[2] = 0x98BADCFE;
278+ context->state[3] = 0x10325476;
279+ context->state[4] = 0xC3D2E1F0;
280+}
281+
282+
283+/*
284+ * Run your data through this.
285+ */
286+void
287+SHA1Update(SHA1_CTX *context, const uint8_t *data, size_t len)
288+{
289+ size_t i, j;
290+
291+ j = (size_t)((context->count >> 3) & 63);
292+ context->count += (len << 3);
293+ if ((j + len) > 63) {
294+ (void)memcpy(&context->buffer[j], data, (i = 64-j));
295+ SHA1Transform(context->state, context->buffer);
296+ for ( ; i + 63 < len; i += 64)
297+ SHA1Transform(context->state, (uint8_t *)&data[i]);
298+ j = 0;
299+ } else {
300+ i = 0;
301+ }
302+ (void)memcpy(&context->buffer[j], &data[i], len - i);
303+}
304+
305+
306+/*
307+ * Add padding and return the message digest.
308+ */
309+void
310+SHA1Pad(SHA1_CTX *context)
311+{
312+ uint8_t finalcount[8];
313+ uint i;
314+
315+ for (i = 0; i < 8; i++) {
316+ finalcount[i] = (uint8_t)((context->count >>
317+ ((7 - (i & 7)) * 8)) & 255); /* Endian independent */
318+ }
319+ SHA1Update(context, (uint8_t *)"\200", 1);
320+ while ((context->count & 504) != 448)
321+ SHA1Update(context, (uint8_t *)"\0", 1);
322+ SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
323+}
324+
325+void
326+SHA1Final(uint8_t digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context)
327+{
328+ uint i;
329+
330+ SHA1Pad(context);
331+ if (digest) {
332+ for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
333+ digest[i] = (uint8_t)
334+ ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
335+ }
336+ memset(context, 0, sizeof(*context));
337+ }
338+}
339+
99b5f9cb
JR
340diff -urN xorg-server-1.6.5/render/sha1.h xorg-server-1.6.5-sha1/render/sha1.h
341--- xorg-server-1.6.5/render/sha1.h 1970-01-01 01:00:00.000000000 +0100
342+++ xorg-server-1.6.5-sha1/render/sha1.h 2010-04-29 12:39:49.195125150 +0200
d2f7eaa2 343@@ -0,0 +1,63 @@
344+/*
345+ * SHA-1 in C
346+ * By Steve Reid <steve@edmweb.com>
347+ * 100% Public Domain
348+ */
349+
350+#ifndef _SHA1_H
351+#define _SHA1_H
352+
353+#include <stdint.h>
354+#include <stddef.h>
355+#include <unistd.h>
356+
357+
358+#define SHA1_BLOCK_LENGTH 64
359+#define SHA1_DIGEST_LENGTH 20
360+#define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1)
361+
362+typedef struct {
363+ uint32_t state[5];
364+ uint64_t count;
365+ uint8_t buffer[SHA1_BLOCK_LENGTH];
366+} SHA1_CTX;
367+
368+#include <sys/cdefs.h>
369+
370+__BEGIN_DECLS
371+void SHA1Init(SHA1_CTX *);
372+void SHA1Pad(SHA1_CTX *);
373+void SHA1Transform(uint32_t [5], const uint8_t [SHA1_BLOCK_LENGTH])
374+ __attribute__((__bounded__(__minbytes__,1,5)))
375+ __attribute__((__bounded__(__minbytes__,2,SHA1_BLOCK_LENGTH)));
376+void SHA1Update(SHA1_CTX *, const uint8_t *, size_t)
377+ __attribute__((__bounded__(__string__,2,3)));
378+void SHA1Final(uint8_t [SHA1_DIGEST_LENGTH], SHA1_CTX *)
379+ __attribute__((__bounded__(__minbytes__,1,SHA1_DIGEST_LENGTH)));
380+char *SHA1End(SHA1_CTX *, char *)
381+ __attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
382+char *SHA1File(const char *, char *)
383+ __attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
384+char *SHA1FileChunk(const char *, char *, off_t, off_t)
385+ __attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
386+char *SHA1Data(const uint8_t *, size_t, char *)
387+ __attribute__((__bounded__(__string__,1,2)))
388+ __attribute__((__bounded__(__minbytes__,3,SHA1_DIGEST_STRING_LENGTH)));
389+__END_DECLS
390+
391+#define HTONDIGEST(x) do { \
392+ x[0] = htonl(x[0]); \
393+ x[1] = htonl(x[1]); \
394+ x[2] = htonl(x[2]); \
395+ x[3] = htonl(x[3]); \
396+ x[4] = htonl(x[4]); } while (0)
397+
398+#define NTOHDIGEST(x) do { \
399+ x[0] = ntohl(x[0]); \
400+ x[1] = ntohl(x[1]); \
401+ x[2] = ntohl(x[2]); \
402+ x[3] = ntohl(x[3]); \
403+ x[4] = ntohl(x[4]); } while (0)
404+
405+#endif /* _SHA1_H */
406+
This page took 0.135918 seconds and 4 git commands to generate.