]>
Commit | Line | Data |
---|---|---|
be68129d JR |
1 | From 3fbec7d4db59bbd24a9a768182000a1d004c5bc5 Mon Sep 17 00:00:00 2001 |
2 | From: Tiago Vignatti <tiago.vignatti@nokia.com> | |
3 | Date: Wed, 24 Mar 2010 17:27:43 +0200 | |
4 | Subject: [PATCH] Revert "Revert "Render: Use built-in SHA1 library"" | |
5 | ||
6 | This reverts commit a39377cbcbd3091095efbeab25bec18ae520147e. | |
7 | ||
8 | Conflicts: | |
9 | ||
10 | configure.ac | |
11 | include/dix-config.h.in | |
12 | render/glyph.c | |
13 | ||
14 | ||
15 | Ok ok ok, it's the revert of a revert! Buhhh... | |
16 | ||
17 | Once upon a time, back in 2007, Carl Worth was trying to boost render | |
18 | (4c6abe1c). He prefered to use a "strong hash" to compare glyphs (19b3b1fd) | |
19 | and used openssl library for this. Further, for the same purpose, people | |
20 | started to set other SHA1 implementations in autoconf. And a lot of | |
21 | alternatives appeared - six, to be precise. In the mean time, John Tapsell | |
22 | commit a builtin implementation of SHA1. In the same day, Keith Packard | |
23 | reverted, stating "X.org should not be providing a custom SHA1 | |
24 | implementation." (a39377cb). Now, users ended up with Xorg setting the default | |
25 | as the openssl's one (libcrypto), which takes 88 kB of xserver's private RSS. | |
26 | Besides that, we have a ridiculous "configure dot fucking ac stanza to work | |
27 | out which lib to use is almost as long as sha1.c was", to quote daniels. | |
28 | ||
29 | My simple argument against Keith's decision is simple: we can save 316 kB of | |
30 | RSS in a standalone Xorg call. Therefore, I'm in favor to keep our own very | |
31 | simple and shiny SHA1 implementation. | |
32 | ||
33 | --- | |
34 | I'm not comfortable yet to send this patch around without see if there's any | |
35 | regressions on render or eventually get some ack from Carl. | |
36 | ||
37 | ||
38 | configure.ac | 89 +------------------------ | |
39 | include/dix-config.h.in | 15 ---- | |
40 | os/Makefile.am | 1 - | |
41 | os/xsha1.c | 168 --------------------------------------------- | |
42 | render/Makefile.am | 3 + | |
43 | render/glyph.c | 25 ++----- | |
44 | render/sha1.c | 173 +++++++++++++++++++++++++++++++++++++++++++++++ | |
45 | render/sha1.h | 63 +++++++++++++++++ | |
46 | 8 files changed, 248 insertions(+), 289 deletions(-) | |
47 | delete mode 100644 os/xsha1.c | |
48 | create mode 100644 render/sha1.c | |
49 | create mode 100644 render/sha1.h | |
50 | ||
be68129d JR |
51 | diff --git a/include/dix-config.h.in b/include/dix-config.h.in |
52 | index 058c8fd..d6e99a5 100644 | |
53 | --- a/include/dix-config.h.in | |
54 | +++ b/include/dix-config.h.in | |
c113a98d | 55 | @@ -142,24 +142,6 @@ |
be68129d JR |
56 | /* Define to 1 if you have the <rpcsvc/dbm.h> header file. */ |
57 | #undef HAVE_RPCSVC_DBM_H | |
58 | ||
59 | -/* Define to use libc SHA1 functions */ | |
60 | -#undef HAVE_SHA1_IN_LIBC | |
61 | - | |
62 | -/* Define to use CommonCrypto SHA1 functions */ | |
63 | -#undef HAVE_SHA1_IN_COMMONCRYPTO | |
64 | - | |
c113a98d AM |
65 | -/* Define to use CryptoAPI SHA1 functions */ |
66 | -#undef HAVE_SHA1_IN_CRYPTOAPI | |
67 | - | |
be68129d JR |
68 | -/* Define to use libmd SHA1 functions */ |
69 | -#undef HAVE_SHA1_IN_LIBMD | |
70 | - | |
71 | -/* Define to use libgcrypt SHA1 functions */ | |
72 | -#undef HAVE_SHA1_IN_LIBGCRYPT | |
73 | - | |
74 | -/* Define to use libsha1 for SHA1 */ | |
75 | -#undef HAVE_SHA1_IN_LIBSHA1 | |
76 | - | |
77 | /* Define to 1 if you have the `shmctl64' function. */ | |
78 | #undef HAVE_SHMCTL64 | |
79 | ||
80 | diff --git a/os/Makefile.am b/os/Makefile.am | |
81 | index 66a4a0f..b8c1636 100644 | |
82 | --- a/os/Makefile.am | |
83 | +++ b/os/Makefile.am | |
84 | @@ -22,7 +22,6 @@ libos_la_SOURCES = \ | |
85 | strcasecmp.c \ | |
86 | strcasestr.c \ | |
87 | xdmauth.c \ | |
88 | - xsha1.c \ | |
89 | xstrans.c \ | |
90 | xprintf.c \ | |
91 | $(XORG_SRCS) | |
5ef960ab AM |
92 | --- a/os/xsha1.c 2012-03-30 04:57:28.000000000 +0200 |
93 | +++ /dev/null 2011-06-01 08:46:43.490033582 +0200 | |
c113a98d | 94 | @@ -1,237 +0,0 @@ |
be68129d JR |
95 | -#ifdef HAVE_DIX_CONFIG_H |
96 | -#include <dix-config.h> | |
97 | -#endif | |
98 | - | |
99 | -#include "os.h" | |
100 | -#include "xsha1.h" | |
101 | - | |
102 | -#if defined(HAVE_SHA1_IN_LIBMD) /* Use libmd for SHA1 */ \ | |
5ef960ab | 103 | - || defined(HAVE_SHA1_IN_LIBC) /* Use libc for SHA1 */ |
be68129d | 104 | - |
5ef960ab | 105 | -#include <sha1.h> |
be68129d | 106 | - |
5ef960ab AM |
107 | -void * |
108 | -x_sha1_init(void) | |
be68129d | 109 | -{ |
156d8c26 | 110 | - SHA1_CTX *ctx = malloc(sizeof(*ctx)); |
5ef960ab | 111 | - |
be68129d JR |
112 | - if (!ctx) |
113 | - return NULL; | |
114 | - SHA1Init(ctx); | |
115 | - return ctx; | |
116 | -} | |
117 | - | |
5ef960ab AM |
118 | -int |
119 | -x_sha1_update(void *ctx, void *data, int size) | |
be68129d JR |
120 | -{ |
121 | - SHA1_CTX *sha1_ctx = ctx; | |
5ef960ab | 122 | - |
be68129d JR |
123 | - SHA1Update(sha1_ctx, data, size); |
124 | - return 1; | |
125 | -} | |
126 | - | |
5ef960ab AM |
127 | -int |
128 | -x_sha1_final(void *ctx, unsigned char result[20]) | |
be68129d JR |
129 | -{ |
130 | - SHA1_CTX *sha1_ctx = ctx; | |
5ef960ab | 131 | - |
be68129d | 132 | - SHA1Final(result, sha1_ctx); |
156d8c26 | 133 | - free(sha1_ctx); |
be68129d JR |
134 | - return 1; |
135 | -} | |
136 | - | |
5ef960ab | 137 | -#elif defined(HAVE_SHA1_IN_COMMONCRYPTO) /* Use CommonCrypto for SHA1 */ |
be68129d JR |
138 | - |
139 | -#include <CommonCrypto/CommonDigest.h> | |
140 | - | |
5ef960ab AM |
141 | -void * |
142 | -x_sha1_init(void) | |
be68129d | 143 | -{ |
156d8c26 | 144 | - CC_SHA1_CTX *ctx = malloc(sizeof(*ctx)); |
5ef960ab | 145 | - |
be68129d JR |
146 | - if (!ctx) |
147 | - return NULL; | |
148 | - CC_SHA1_Init(ctx); | |
149 | - return ctx; | |
150 | -} | |
151 | - | |
5ef960ab AM |
152 | -int |
153 | -x_sha1_update(void *ctx, void *data, int size) | |
be68129d JR |
154 | -{ |
155 | - CC_SHA1_CTX *sha1_ctx = ctx; | |
5ef960ab | 156 | - |
be68129d JR |
157 | - CC_SHA1_Update(sha1_ctx, data, size); |
158 | - return 1; | |
159 | -} | |
160 | - | |
5ef960ab AM |
161 | -int |
162 | -x_sha1_final(void *ctx, unsigned char result[20]) | |
be68129d JR |
163 | -{ |
164 | - CC_SHA1_CTX *sha1_ctx = ctx; | |
5ef960ab | 165 | - |
be68129d | 166 | - CC_SHA1_Final(result, sha1_ctx); |
156d8c26 | 167 | - free(sha1_ctx); |
be68129d JR |
168 | - return 1; |
169 | -} | |
170 | - | |
c113a98d AM |
171 | -#elif defined(HAVE_SHA1_IN_CRYPTOAPI) /* Use CryptoAPI for SHA1 */ |
172 | - | |
173 | -#define WIN32_LEAN_AND_MEAN | |
174 | -#include <X11/Xwindows.h> | |
175 | -#include <wincrypt.h> | |
176 | - | |
177 | -static HCRYPTPROV hProv; | |
178 | - | |
179 | -void * | |
180 | -x_sha1_init(void) | |
181 | -{ | |
182 | - HCRYPTHASH *ctx = malloc(sizeof(*ctx)); | |
183 | - | |
184 | - if (!ctx) | |
185 | - return NULL; | |
186 | - CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); | |
187 | - CryptCreateHash(hProv, CALG_SHA1, 0, 0, ctx); | |
188 | - return ctx; | |
189 | -} | |
190 | - | |
191 | -int | |
192 | -x_sha1_update(void *ctx, void *data, int size) | |
193 | -{ | |
194 | - HCRYPTHASH *hHash = ctx; | |
195 | - | |
196 | - CryptHashData(*hHash, data, size, 0); | |
197 | - return 1; | |
198 | -} | |
199 | - | |
200 | -int | |
201 | -x_sha1_final(void *ctx, unsigned char result[20]) | |
202 | -{ | |
203 | - HCRYPTHASH *hHash = ctx; | |
204 | - DWORD len = 20; | |
205 | - | |
206 | - CryptGetHashParam(*hHash, HP_HASHVAL, result, &len, 0); | |
207 | - CryptDestroyHash(*hHash); | |
208 | - CryptReleaseContext(hProv, 0); | |
209 | - free(ctx); | |
210 | - return 1; | |
211 | -} | |
212 | - | |
5ef960ab | 213 | -#elif defined(HAVE_SHA1_IN_LIBGCRYPT) /* Use libgcrypt for SHA1 */ |
be68129d | 214 | - |
5ef960ab | 215 | -#include <gcrypt.h> |
be68129d | 216 | - |
5ef960ab AM |
217 | -void * |
218 | -x_sha1_init(void) | |
be68129d JR |
219 | -{ |
220 | - static int init; | |
221 | - gcry_md_hd_t h; | |
222 | - gcry_error_t err; | |
223 | - | |
224 | - if (!init) { | |
225 | - if (!gcry_check_version(NULL)) | |
226 | - return NULL; | |
227 | - gcry_control(GCRYCTL_DISABLE_SECMEM, 0); | |
228 | - gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0); | |
229 | - init = 1; | |
230 | - } | |
231 | - | |
232 | - err = gcry_md_open(&h, GCRY_MD_SHA1, 0); | |
233 | - if (err) | |
234 | - return NULL; | |
235 | - return h; | |
236 | -} | |
237 | - | |
5ef960ab AM |
238 | -int |
239 | -x_sha1_update(void *ctx, void *data, int size) | |
be68129d JR |
240 | -{ |
241 | - gcry_md_hd_t h = ctx; | |
5ef960ab | 242 | - |
be68129d JR |
243 | - gcry_md_write(h, data, size); |
244 | - return 1; | |
245 | -} | |
246 | - | |
5ef960ab AM |
247 | -int |
248 | -x_sha1_final(void *ctx, unsigned char result[20]) | |
be68129d JR |
249 | -{ |
250 | - gcry_md_hd_t h = ctx; | |
5ef960ab | 251 | - |
be68129d JR |
252 | - memcpy(result, gcry_md_read(h, GCRY_MD_SHA1), 20); |
253 | - gcry_md_close(h); | |
254 | - return 1; | |
255 | -} | |
256 | - | |
5ef960ab | 257 | -#elif defined(HAVE_SHA1_IN_LIBSHA1) /* Use libsha1 */ |
be68129d | 258 | - |
5ef960ab | 259 | -#include <libsha1.h> |
be68129d | 260 | - |
5ef960ab AM |
261 | -void * |
262 | -x_sha1_init(void) | |
be68129d | 263 | -{ |
156d8c26 | 264 | - sha1_ctx *ctx = malloc(sizeof(*ctx)); |
5ef960ab AM |
265 | - |
266 | - if (!ctx) | |
be68129d JR |
267 | - return NULL; |
268 | - sha1_begin(ctx); | |
269 | - return ctx; | |
270 | -} | |
271 | - | |
5ef960ab AM |
272 | -int |
273 | -x_sha1_update(void *ctx, void *data, int size) | |
be68129d JR |
274 | -{ |
275 | - sha1_hash(data, size, ctx); | |
276 | - return 1; | |
277 | -} | |
278 | - | |
5ef960ab AM |
279 | -int |
280 | -x_sha1_final(void *ctx, unsigned char result[20]) | |
be68129d JR |
281 | -{ |
282 | - sha1_end(result, ctx); | |
156d8c26 | 283 | - free(ctx); |
be68129d JR |
284 | - return 1; |
285 | -} | |
286 | - | |
5ef960ab | 287 | -#else /* Use OpenSSL's libcrypto */ |
be68129d | 288 | - |
5ef960ab AM |
289 | -#include <stddef.h> /* buggy openssl/sha.h wants size_t */ |
290 | -#include <openssl/sha.h> | |
be68129d | 291 | - |
5ef960ab AM |
292 | -void * |
293 | -x_sha1_init(void) | |
be68129d JR |
294 | -{ |
295 | - int ret; | |
156d8c26 | 296 | - SHA_CTX *ctx = malloc(sizeof(*ctx)); |
5ef960ab | 297 | - |
be68129d JR |
298 | - if (!ctx) |
299 | - return NULL; | |
300 | - ret = SHA1_Init(ctx); | |
301 | - if (!ret) { | |
156d8c26 | 302 | - free(ctx); |
be68129d JR |
303 | - return NULL; |
304 | - } | |
305 | - return ctx; | |
306 | -} | |
307 | - | |
5ef960ab AM |
308 | -int |
309 | -x_sha1_update(void *ctx, void *data, int size) | |
be68129d JR |
310 | -{ |
311 | - int ret; | |
312 | - SHA_CTX *sha_ctx = ctx; | |
5ef960ab | 313 | - |
be68129d JR |
314 | - ret = SHA1_Update(sha_ctx, data, size); |
315 | - if (!ret) | |
156d8c26 | 316 | - free(sha_ctx); |
be68129d JR |
317 | - return ret; |
318 | -} | |
319 | - | |
5ef960ab AM |
320 | -int |
321 | -x_sha1_final(void *ctx, unsigned char result[20]) | |
be68129d JR |
322 | -{ |
323 | - int ret; | |
324 | - SHA_CTX *sha_ctx = ctx; | |
5ef960ab | 325 | - |
be68129d | 326 | - ret = SHA1_Final(result, sha_ctx); |
156d8c26 | 327 | - free(sha_ctx); |
be68129d JR |
328 | - return ret; |
329 | -} | |
330 | - | |
331 | -#endif | |
332 | diff --git a/render/Makefile.am b/render/Makefile.am | |
333 | index 216c613..bb46702 100644 | |
334 | --- a/render/Makefile.am | |
335 | +++ b/render/Makefile.am | |
631db884 AM |
336 | @@ -13,8 +13,11 @@ librender_la_SOURCES = \ |
337 | mitrap.c \ | |
be68129d JR |
338 | mitri.c \ |
339 | picture.c \ | |
be68129d | 340 | + sha1.c \ |
631db884 | 341 | render.c |
be68129d JR |
342 | |
343 | if XORG | |
631db884 | 344 | sdk_HEADERS = picture.h mipict.h glyphstr.h picturestr.h |
be68129d JR |
345 | endif |
346 | + | |
347 | +EXTRA_DIST = sha1.h | |
348 | diff --git a/render/glyph.c b/render/glyph.c | |
349 | index 0b864ad..e14530a 100644 | |
350 | --- a/render/glyph.c | |
351 | +++ b/render/glyph.c | |
352 | @@ -26,8 +26,7 @@ | |
353 | #include <dix-config.h> | |
354 | #endif | |
355 | ||
356 | -#include "xsha1.h" | |
357 | - | |
358 | +#include "sha1.h" | |
359 | #include "misc.h" | |
360 | #include "scrnintstr.h" | |
361 | #include "os.h" | |
5ef960ab AM |
362 | @@ -167,21 +167,13 @@ int |
363 | HashGlyph(xGlyphInfo * gi, | |
364 | CARD8 *bits, unsigned long size, unsigned char sha1[20]) | |
be68129d JR |
365 | { |
366 | - void *ctx = x_sha1_init(); | |
367 | - int success; | |
5ef960ab AM |
368 | + SHA1_CTX ctx; |
369 | ||
be68129d | 370 | - if (!ctx) |
5ef960ab AM |
371 | - return BadAlloc; |
372 | + SHA1Init (&ctx); | |
373 | + SHA1Update (&ctx, gi, sizeof (xGlyphInfo)); | |
374 | + SHA1Update (&ctx, bits, size); | |
375 | + SHA1Final (sha1, &ctx); | |
376 | ||
be68129d JR |
377 | - success = x_sha1_update(ctx, gi, sizeof(xGlyphInfo)); |
378 | - if (!success) | |
5ef960ab | 379 | - return BadAlloc; |
be68129d JR |
380 | - success = x_sha1_update(ctx, bits, size); |
381 | - if (!success) | |
5ef960ab | 382 | - return BadAlloc; |
be68129d JR |
383 | - success = x_sha1_final(ctx, sha1); |
384 | - if (!success) | |
5ef960ab | 385 | - return BadAlloc; |
be68129d JR |
386 | return Success; |
387 | } | |
388 | ||
389 | diff --git a/render/sha1.c b/render/sha1.c | |
390 | new file mode 100644 | |
391 | index 0000000..820eb2a | |
392 | --- /dev/null | |
393 | +++ b/render/sha1.c | |
394 | @@ -0,0 +1,173 @@ | |
395 | +/* | |
396 | + * SHA-1 in C | |
397 | + * By Steve Reid <steve@edmweb.com> | |
398 | + * 100% Public Domain | |
399 | + * | |
400 | + * Test Vectors (from FIPS PUB 180-1) | |
401 | + * "abc" | |
402 | + * A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D | |
403 | + * "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" | |
404 | + * 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 | |
405 | + * A million repetitions of "a" | |
406 | + * 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F | |
407 | + */ | |
408 | + | |
409 | +#include <sys/param.h> | |
410 | +#include <string.h> | |
411 | +#include <sha1.h> | |
412 | + | |
413 | +#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) | |
414 | + | |
415 | +/* | |
416 | + * blk0() and blk() perform the initial expand. | |
417 | + * I got the idea of expanding during the round function from SSLeay | |
418 | + */ | |
419 | +#if BYTE_ORDER == LITTLE_ENDIAN | |
420 | +# define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \ | |
421 | + |(rol(block->l[i],8)&0x00FF00FF)) | |
422 | +#else | |
423 | +# define blk0(i) block->l[i] | |
424 | +#endif | |
425 | +#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ | |
426 | + ^block->l[(i+2)&15]^block->l[i&15],1)) | |
427 | + | |
428 | +/* | |
429 | + * (R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1 | |
430 | + */ | |
431 | +#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); | |
432 | +#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30); | |
433 | +#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); | |
434 | +#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); | |
435 | +#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); | |
436 | + | |
437 | +/* | |
438 | + * Hash a single 512-bit block. This is the core of the algorithm. | |
439 | + */ | |
440 | +void | |
441 | +SHA1Transform(uint32_t state[5], const uint8_t buffer[SHA1_BLOCK_LENGTH]) | |
442 | +{ | |
443 | + uint32_t a, b, c, d, e; | |
444 | + uint8_t workspace[SHA1_BLOCK_LENGTH]; | |
445 | + typedef union { | |
446 | + uint8_t c[64]; | |
447 | + uint32_t l[16]; | |
448 | + } CHAR64LONG16; | |
449 | + CHAR64LONG16 *block = (CHAR64LONG16 *)workspace; | |
450 | + | |
451 | + (void)memcpy(block, buffer, SHA1_BLOCK_LENGTH); | |
452 | + | |
453 | + /* Copy context->state[] to working vars */ | |
454 | + a = state[0]; | |
455 | + b = state[1]; | |
456 | + c = state[2]; | |
457 | + d = state[3]; | |
458 | + e = state[4]; | |
459 | + | |
460 | + /* 4 rounds of 20 operations each. Loop unrolled. */ | |
461 | + 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); | |
462 | + 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); | |
463 | + 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); | |
464 | + 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); | |
465 | + 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); | |
466 | + 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); | |
467 | + 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); | |
468 | + 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); | |
469 | + 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); | |
470 | + 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); | |
471 | + 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); | |
472 | + 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); | |
473 | + 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); | |
474 | + 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); | |
475 | + 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); | |
476 | + 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); | |
477 | + 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); | |
478 | + 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); | |
479 | + 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); | |
480 | + 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); | |
481 | + | |
482 | + /* Add the working vars back into context.state[] */ | |
483 | + state[0] += a; | |
484 | + state[1] += b; | |
485 | + state[2] += c; | |
486 | + state[3] += d; | |
487 | + state[4] += e; | |
488 | + | |
489 | + /* Wipe variables */ | |
490 | + a = b = c = d = e = 0; | |
491 | +} | |
492 | + | |
493 | + | |
494 | +/* | |
495 | + * SHA1Init - Initialize new context | |
496 | + */ | |
497 | +void | |
498 | +SHA1Init(SHA1_CTX *context) | |
499 | +{ | |
500 | + | |
501 | + /* SHA1 initialization constants */ | |
502 | + context->count = 0; | |
503 | + context->state[0] = 0x67452301; | |
504 | + context->state[1] = 0xEFCDAB89; | |
505 | + context->state[2] = 0x98BADCFE; | |
506 | + context->state[3] = 0x10325476; | |
507 | + context->state[4] = 0xC3D2E1F0; | |
508 | +} | |
509 | + | |
510 | + | |
511 | +/* | |
512 | + * Run your data through this. | |
513 | + */ | |
514 | +void | |
515 | +SHA1Update(SHA1_CTX *context, const uint8_t *data, size_t len) | |
516 | +{ | |
517 | + size_t i, j; | |
518 | + | |
519 | + j = (size_t)((context->count >> 3) & 63); | |
520 | + context->count += (len << 3); | |
521 | + if ((j + len) > 63) { | |
522 | + (void)memcpy(&context->buffer[j], data, (i = 64-j)); | |
523 | + SHA1Transform(context->state, context->buffer); | |
524 | + for ( ; i + 63 < len; i += 64) | |
525 | + SHA1Transform(context->state, (uint8_t *)&data[i]); | |
526 | + j = 0; | |
527 | + } else { | |
528 | + i = 0; | |
529 | + } | |
530 | + (void)memcpy(&context->buffer[j], &data[i], len - i); | |
531 | +} | |
532 | + | |
533 | + | |
534 | +/* | |
535 | + * Add padding and return the message digest. | |
536 | + */ | |
537 | +void | |
538 | +SHA1Pad(SHA1_CTX *context) | |
539 | +{ | |
540 | + uint8_t finalcount[8]; | |
541 | + uint i; | |
542 | + | |
543 | + for (i = 0; i < 8; i++) { | |
544 | + finalcount[i] = (uint8_t)((context->count >> | |
545 | + ((7 - (i & 7)) * 8)) & 255); /* Endian independent */ | |
546 | + } | |
547 | + SHA1Update(context, (uint8_t *)"\200", 1); | |
548 | + while ((context->count & 504) != 448) | |
549 | + SHA1Update(context, (uint8_t *)"\0", 1); | |
550 | + SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */ | |
551 | +} | |
552 | + | |
553 | +void | |
554 | +SHA1Final(uint8_t digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context) | |
555 | +{ | |
556 | + uint i; | |
557 | + | |
558 | + SHA1Pad(context); | |
559 | + if (digest) { | |
560 | + for (i = 0; i < SHA1_DIGEST_LENGTH; i++) { | |
561 | + digest[i] = (uint8_t) | |
562 | + ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255); | |
563 | + } | |
564 | + memset(context, 0, sizeof(*context)); | |
565 | + } | |
566 | +} | |
567 | + | |
568 | diff --git a/render/sha1.h b/render/sha1.h | |
569 | new file mode 100644 | |
570 | index 0000000..ace7d97 | |
571 | --- /dev/null | |
572 | +++ b/render/sha1.h | |
573 | @@ -0,0 +1,63 @@ | |
574 | +/* | |
575 | + * SHA-1 in C | |
576 | + * By Steve Reid <steve@edmweb.com> | |
577 | + * 100% Public Domain | |
578 | + */ | |
579 | + | |
580 | +#ifndef _SHA1_H | |
581 | +#define _SHA1_H | |
582 | + | |
583 | +#include <stdint.h> | |
584 | +#include <stddef.h> | |
585 | +#include <unistd.h> | |
586 | + | |
587 | + | |
588 | +#define SHA1_BLOCK_LENGTH 64 | |
589 | +#define SHA1_DIGEST_LENGTH 20 | |
590 | +#define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1) | |
591 | + | |
592 | +typedef struct { | |
593 | + uint32_t state[5]; | |
594 | + uint64_t count; | |
595 | + uint8_t buffer[SHA1_BLOCK_LENGTH]; | |
596 | +} SHA1_CTX; | |
597 | + | |
598 | +#include <sys/cdefs.h> | |
599 | + | |
600 | +__BEGIN_DECLS | |
601 | +void SHA1Init(SHA1_CTX *); | |
602 | +void SHA1Pad(SHA1_CTX *); | |
603 | +void SHA1Transform(uint32_t [5], const uint8_t [SHA1_BLOCK_LENGTH]) | |
604 | + __attribute__((__bounded__(__minbytes__,1,5))) | |
605 | + __attribute__((__bounded__(__minbytes__,2,SHA1_BLOCK_LENGTH))); | |
606 | +void SHA1Update(SHA1_CTX *, const uint8_t *, size_t) | |
607 | + __attribute__((__bounded__(__string__,2,3))); | |
608 | +void SHA1Final(uint8_t [SHA1_DIGEST_LENGTH], SHA1_CTX *) | |
609 | + __attribute__((__bounded__(__minbytes__,1,SHA1_DIGEST_LENGTH))); | |
610 | +char *SHA1End(SHA1_CTX *, char *) | |
611 | + __attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH))); | |
612 | +char *SHA1File(const char *, char *) | |
613 | + __attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH))); | |
614 | +char *SHA1FileChunk(const char *, char *, off_t, off_t) | |
615 | + __attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH))); | |
616 | +char *SHA1Data(const uint8_t *, size_t, char *) | |
617 | + __attribute__((__bounded__(__string__,1,2))) | |
618 | + __attribute__((__bounded__(__minbytes__,3,SHA1_DIGEST_STRING_LENGTH))); | |
619 | +__END_DECLS | |
620 | + | |
621 | +#define HTONDIGEST(x) do { \ | |
622 | + x[0] = htonl(x[0]); \ | |
623 | + x[1] = htonl(x[1]); \ | |
624 | + x[2] = htonl(x[2]); \ | |
625 | + x[3] = htonl(x[3]); \ | |
626 | + x[4] = htonl(x[4]); } while (0) | |
627 | + | |
628 | +#define NTOHDIGEST(x) do { \ | |
629 | + x[0] = ntohl(x[0]); \ | |
630 | + x[1] = ntohl(x[1]); \ | |
631 | + x[2] = ntohl(x[2]); \ | |
632 | + x[3] = ntohl(x[3]); \ | |
633 | + x[4] = ntohl(x[4]); } while (0) | |
634 | + | |
635 | +#endif /* _SHA1_H */ | |
636 | + | |
637 | -- | |
638 | 1.6.0.4 | |
639 | ||
c986a814 | 640 | --- xorg-server-1.9.2.902/configure.ac.orig 2010-12-04 06:56:52.000000000 +0100 |
641 | +++ xorg-server-1.9.2.902/configure.ac 2010-12-07 19:16:06.420296250 +0100 | |
642 | @@ -1338,7 +1338,7 @@ | |
643 | ||
644 | if test "x$SPECIAL_DTRACE_OBJECTS" = "xyes" ; then | |
645 | DIX_LIB='$(top_builddir)/dix/dix.O' | |
646 | - OS_LIB='$(top_builddir)/os/os.O $(SHA1_LIBS) $(DLOPEN_LIBS)' | |
647 | + OS_LIB='$(top_builddir)/os/os.O $(DLOPEN_LIBS)' | |
648 | else | |
649 | DIX_LIB='$(top_builddir)/dix/libdix.la' | |
650 | OS_LIB='$(top_builddir)/os/libos.la' | |
c113a98d AM |
651 | @@ -1358,112 +1358,6 @@ |
652 | MIEXT_SYNC_LIB='$(top_builddir)/miext/sync/libsync.la' | |
c986a814 | 653 | CORE_INCS='-I$(top_srcdir)/include -I$(top_builddir)/include' |
654 | ||
655 | -# SHA1 hashing | |
656 | -AC_ARG_WITH([sha1], | |
c113a98d | 657 | - [AS_HELP_STRING([--with-sha1=libc|libmd|libgcrypt|libcrypto|libsha1|CommonCrypto|CryptoAPI], |
c986a814 | 658 | - [choose SHA1 implementation])]) |
659 | -AC_CHECK_FUNC([SHA1Init], [HAVE_SHA1_IN_LIBC=yes]) | |
660 | -if test "x$with_sha1" = x && test "x$HAVE_SHA1_IN_LIBC" = xyes; then | |
661 | - with_sha1=libc | |
662 | -fi | |
663 | -if test "x$with_sha1" = xlibc && test "x$HAVE_SHA1_IN_LIBC" != xyes; then | |
664 | - AC_MSG_ERROR([libc requested but not found]) | |
665 | -fi | |
666 | -if test "x$with_sha1" = xlibc; then | |
667 | - AC_DEFINE([HAVE_SHA1_IN_LIBC], [1], | |
668 | - [Use libc SHA1 functions]) | |
669 | - SHA1_LIBS="" | |
670 | -fi | |
671 | -AC_CHECK_FUNC([CC_SHA1_Init], [HAVE_SHA1_IN_COMMONCRYPTO=yes]) | |
672 | -if test "x$with_sha1" = x && test "x$HAVE_SHA1_IN_COMMONCRYPTO" = xyes; then | |
673 | - with_sha1=CommonCrypto | |
674 | -fi | |
675 | -if test "x$with_sha1" = xCommonCrypto && test "x$HAVE_SHA1_IN_COMMONCRYPTO" != xyes; then | |
676 | - AC_MSG_ERROR([CommonCrypto requested but not found]) | |
677 | -fi | |
678 | -if test "x$with_sha1" = xCommonCrypto; then | |
679 | - AC_DEFINE([HAVE_SHA1_IN_COMMONCRYPTO], [1], | |
680 | - [Use CommonCrypto SHA1 functions]) | |
681 | - SHA1_LIBS="" | |
682 | -fi | |
c113a98d AM |
683 | -dnl stdcall functions cannot be tested with AC_CHECK_LIB |
684 | -AC_CHECK_HEADER([wincrypt.h], [HAVE_SHA1_IN_CRYPTOAPI=yes], [], [#include <windows.h>]) | |
685 | -if test "x$with_sha1" = x && test "x$HAVE_SHA1_IN_CRYPTOAPI" = xyes; then | |
686 | - with_sha1=CryptoAPI | |
687 | -fi | |
688 | -if test "x$with_sha1" = xCryptoAPI && test "x$HAVE_SHA1_IN_CRYPTOAPI" != xyes; then | |
689 | - AC_MSG_ERROR([CryptoAPI requested but not found]) | |
690 | -fi | |
691 | -if test "x$with_sha1" = xCryptoAPI; then | |
692 | - AC_DEFINE([HAVE_SHA1_IN_CRYPTOAPI], [1], | |
693 | - [Use CryptoAPI SHA1 functions]) | |
694 | - SHA1_LIBS="" | |
695 | -fi | |
c986a814 | 696 | -AC_CHECK_LIB([md], [SHA1Init], [HAVE_LIBMD=yes]) |
697 | -if test "x$with_sha1" = x && test "x$HAVE_LIBMD" = xyes; then | |
698 | - with_sha1=libmd | |
699 | -fi | |
700 | -if test "x$with_sha1" = xlibmd && test "x$HAVE_LIBMD" != xyes; then | |
701 | - AC_MSG_ERROR([libmd requested but not found]) | |
702 | -fi | |
703 | -if test "x$with_sha1" = xlibmd; then | |
704 | - AC_DEFINE([HAVE_SHA1_IN_LIBMD], [1], | |
705 | - [Use libmd SHA1 functions]) | |
706 | - SHA1_LIBS=-lmd | |
707 | -fi | |
708 | -PKG_CHECK_MODULES([LIBSHA1], [libsha1], [HAVE_LIBSHA1=yes], [HAVE_LIBSHA1=no]) | |
709 | -if test "x$with_sha1" = x && test "x$HAVE_LIBSHA1" = xyes; then | |
710 | - with_sha1=libsha1 | |
711 | -fi | |
712 | -if test "x$with_sha1" = xlibsha1 && test "x$HAVE_LIBSHA1" != xyes; then | |
713 | - AC_MSG_ERROR([libsha1 requested but not found]) | |
714 | -fi | |
715 | -if test "x$with_sha1" = xlibsha1; then | |
716 | - AC_DEFINE([HAVE_SHA1_IN_LIBSHA1], [1], | |
717 | - [Use libsha1 for SHA1]) | |
718 | - SHA1_LIBS=-lsha1 | |
719 | -fi | |
720 | -AC_CHECK_LIB([gcrypt], [gcry_md_open], [HAVE_LIBGCRYPT=yes]) | |
721 | -if test "x$with_sha1" = x && test "x$HAVE_LIBGCRYPT" = xyes; then | |
722 | - with_sha1=libgcrypt | |
723 | -fi | |
724 | -if test "x$with_sha1" = xlibgcrypt && test "x$HAVE_LIBGCRYPT" != xyes; then | |
725 | - AC_MSG_ERROR([libgcrypt requested but not found]) | |
726 | -fi | |
727 | -if test "x$with_sha1" = xlibgcrypt; then | |
728 | - AC_DEFINE([HAVE_SHA1_IN_LIBGCRYPT], [1], | |
729 | - [Use libgcrypt SHA1 functions]) | |
730 | - SHA1_LIBS=-lgcrypt | |
731 | -fi | |
732 | -# We don't need all of the OpenSSL libraries, just libcrypto | |
733 | -AC_CHECK_LIB([crypto], [SHA1_Init], [HAVE_LIBCRYPTO=yes]) | |
734 | -PKG_CHECK_MODULES([OPENSSL], [openssl], [HAVE_OPENSSL_PKC=yes], | |
735 | - [HAVE_OPENSSL_PKC=no]) | |
736 | -if test "x$HAVE_LIBCRYPTO" = xyes || test "x$HAVE_OPENSSL_PKC" = xyes; then | |
737 | - if test "x$with_sha1" = x; then | |
738 | - with_sha1=libcrypto | |
739 | - fi | |
740 | -else | |
741 | - if test "x$with_sha1" = xlibcrypto; then | |
742 | - AC_MSG_ERROR([OpenSSL libcrypto requested but not found]) | |
743 | - fi | |
744 | -fi | |
745 | -if test "x$with_sha1" = xlibcrypto; then | |
746 | - if test "x$HAVE_LIBCRYPTO" = xyes; then | |
747 | - SHA1_LIBS=-lcrypto | |
748 | - else | |
749 | - SHA1_LIBS="$OPENSSL_LIBS" | |
750 | - SHA1_CFLAGS="$OPENSSL_CFLAGS" | |
751 | - fi | |
752 | -fi | |
753 | -AC_MSG_CHECKING([for SHA1 implementation]) | |
754 | -if test "x$with_sha1" = x; then | |
755 | - AC_MSG_ERROR([No suitable SHA1 implementation found]) | |
756 | -fi | |
757 | -AC_MSG_RESULT([$with_sha1]) | |
758 | -AC_SUBST(SHA1_LIBS) | |
759 | -AC_SUBST(SHA1_CFLAGS) | |
760 | - | |
761 | PKG_CHECK_MODULES([XSERVERCFLAGS], [$REQUIRED_MODULES $REQUIRED_LIBS]) | |
762 | PKG_CHECK_MODULES([XSERVERLIBS], [$REQUIRED_LIBS]) | |
c113a98d AM |
763 | |
764 |