Mercurial > hg > xemacs-beta
comparison src/md5.c @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | b8cc9ab3f761 |
children |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
27 #endif | 27 #endif |
28 | 28 |
29 #include <sys/types.h> | 29 #include <sys/types.h> |
30 #include <string.h> | 30 #include <string.h> |
31 #include <stdio.h> | 31 #include <stdio.h> |
32 #include <limits.h> | 32 |
33 #if defined HAVE_LIMITS_H || _LIBC | |
34 # include <limits.h> | |
35 #endif | |
33 | 36 |
34 /* The following contortions are an attempt to use the C preprocessor | 37 /* The following contortions are an attempt to use the C preprocessor |
35 to determine an unsigned integral type that is 32 bits wide. An | 38 to determine an unsigned integral type that is 32 bits wide. An |
36 alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but | 39 alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but |
37 doing that would require that the configure script compile and *run* | 40 doing that would require that the configure script compile and *run* |
105 /* This array contains the bytes used to pad the buffer to the next | 108 /* This array contains the bytes used to pad the buffer to the next |
106 64-byte boundary. (RFC 1321, 3.1: Step 1) */ | 109 64-byte boundary. (RFC 1321, 3.1: Step 1) */ |
107 static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; | 110 static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; |
108 | 111 |
109 | 112 |
110 static void md5_process_block (const void *, size_t, struct md5_ctx *); | 113 static void md5_process_block (CONST void *, size_t, struct md5_ctx *); |
111 | 114 |
112 | 115 |
113 /* Initialize structure containing state of computation. | 116 /* Initialize structure containing state of computation. |
114 (RFC 1321, 3.3: Step 3) */ | 117 (RFC 1321, 3.3: Step 3) */ |
115 static void | 118 static void |
128 must be in little endian byte order. | 131 must be in little endian byte order. |
129 | 132 |
130 IMPORTANT: On some systems it is required that RESBUF is correctly | 133 IMPORTANT: On some systems it is required that RESBUF is correctly |
131 aligned for a 32 bits value. */ | 134 aligned for a 32 bits value. */ |
132 static void * | 135 static void * |
133 md5_read_ctx (const struct md5_ctx *ctx, void *resbuf) | 136 md5_read_ctx (CONST struct md5_ctx *ctx, void *resbuf) |
134 { | 137 { |
135 ((md5_uint32 *) resbuf)[0] = SWAP (ctx->A); | 138 ((md5_uint32 *) resbuf)[0] = SWAP (ctx->A); |
136 ((md5_uint32 *) resbuf)[1] = SWAP (ctx->B); | 139 ((md5_uint32 *) resbuf)[1] = SWAP (ctx->B); |
137 ((md5_uint32 *) resbuf)[2] = SWAP (ctx->C); | 140 ((md5_uint32 *) resbuf)[2] = SWAP (ctx->C); |
138 ((md5_uint32 *) resbuf)[3] = SWAP (ctx->D); | 141 ((md5_uint32 *) resbuf)[3] = SWAP (ctx->D); |
246 } | 249 } |
247 #endif /* not emacs */ | 250 #endif /* not emacs */ |
248 | 251 |
249 | 252 |
250 static void | 253 static void |
251 md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx) | 254 md5_process_bytes (CONST void *buffer, size_t len, struct md5_ctx *ctx) |
252 { | 255 { |
253 /* When we already have some bits in our internal buffer concatenate | 256 /* When we already have some bits in our internal buffer concatenate |
254 both inputs first. */ | 257 both inputs first. */ |
255 if (ctx->buflen != 0) | 258 if (ctx->buflen != 0) |
256 { | 259 { |
301 | 304 |
302 /* Process LEN bytes of BUFFER, accumulating context into CTX. | 305 /* Process LEN bytes of BUFFER, accumulating context into CTX. |
303 It is assumed that LEN % 64 == 0. */ | 306 It is assumed that LEN % 64 == 0. */ |
304 | 307 |
305 static void | 308 static void |
306 md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx) | 309 md5_process_block (CONST void *buffer, size_t len, struct md5_ctx *ctx) |
307 { | 310 { |
308 md5_uint32 correct_words[16]; | 311 md5_uint32 correct_words[16]; |
309 const md5_uint32 *words = (const md5_uint32 *) buffer; | 312 const md5_uint32 *words = (const md5_uint32 *) buffer; |
310 size_t nwords = len / sizeof (md5_uint32); | 313 size_t nwords = len / sizeof (md5_uint32); |
311 const md5_uint32 *endp = words + nwords; | 314 const md5_uint32 *endp = words + nwords; |
477 } | 480 } |
478 else | 481 else |
479 { | 482 { |
480 /* Attempt to autodetect the coding of the string. This is | 483 /* Attempt to autodetect the coding of the string. This is |
481 VERY hit-and-miss. */ | 484 VERY hit-and-miss. */ |
482 eol_type_t eol = EOL_AUTODETECT; | 485 enum eol_type eol = EOL_AUTODETECT; |
483 coding_system = Fget_coding_system (Qundecided); | 486 coding_system = Fget_coding_system (Qundecided); |
484 determine_real_coding_system (XLSTREAM (istream), | 487 determine_real_coding_system (XLSTREAM (istream), |
485 &coding_system, &eol); | 488 &coding_system, &eol); |
486 } | 489 } |
487 if (NILP (coding_system)) | 490 if (NILP (coding_system)) |
577 | 580 |
578 /* Get the data while doing the conversion. */ | 581 /* Get the data while doing the conversion. */ |
579 while (1) | 582 while (1) |
580 { | 583 { |
581 Bufbyte tempbuf[1024]; /* some random amount */ | 584 Bufbyte tempbuf[1024]; /* some random amount */ |
582 ssize_t size_in_bytes = | 585 int size_in_bytes = Lstream_read (XLSTREAM (instream), |
583 Lstream_read (XLSTREAM (instream), tempbuf, sizeof (tempbuf)); | 586 tempbuf, sizeof (tempbuf)); |
584 if (!size_in_bytes) | 587 if (!size_in_bytes) |
585 break; | 588 break; |
586 | 589 |
587 /* Process the bytes. */ | 590 /* Process the bytes. */ |
588 md5_process_bytes (tempbuf, size_in_bytes, &ctx); | 591 md5_process_bytes (tempbuf, size_in_bytes, &ctx); |