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