comparison src/md5.c @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 84b14dcb0985
children 0784d089fdc9
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
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 32 #include <limits.h>
33 #if defined HAVE_LIMITS_H || _LIBC
34 # include <limits.h>
35 #endif
36 33
37 /* The following contortions are an attempt to use the C preprocessor 34 /* The following contortions are an attempt to use the C preprocessor
38 to determine an unsigned integral type that is 32 bits wide. An 35 to determine an unsigned integral type that is 32 bits wide. An
39 alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but 36 alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but
40 doing that would require that the configure script compile and *run* 37 doing that would require that the configure script compile and *run*
108 /* This array contains the bytes used to pad the buffer to the next 105 /* This array contains the bytes used to pad the buffer to the next
109 64-byte boundary. (RFC 1321, 3.1: Step 1) */ 106 64-byte boundary. (RFC 1321, 3.1: Step 1) */
110 static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; 107 static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
111 108
112 109
113 static void md5_process_block (CONST void *, size_t, struct md5_ctx *); 110 static void md5_process_block (const void *, size_t, struct md5_ctx *);
114 111
115 112
116 /* Initialize structure containing state of computation. 113 /* Initialize structure containing state of computation.
117 (RFC 1321, 3.3: Step 3) */ 114 (RFC 1321, 3.3: Step 3) */
118 static void 115 static void
131 must be in little endian byte order. 128 must be in little endian byte order.
132 129
133 IMPORTANT: On some systems it is required that RESBUF is correctly 130 IMPORTANT: On some systems it is required that RESBUF is correctly
134 aligned for a 32 bits value. */ 131 aligned for a 32 bits value. */
135 static void * 132 static void *
136 md5_read_ctx (CONST struct md5_ctx *ctx, void *resbuf) 133 md5_read_ctx (const struct md5_ctx *ctx, void *resbuf)
137 { 134 {
138 ((md5_uint32 *) resbuf)[0] = SWAP (ctx->A); 135 ((md5_uint32 *) resbuf)[0] = SWAP (ctx->A);
139 ((md5_uint32 *) resbuf)[1] = SWAP (ctx->B); 136 ((md5_uint32 *) resbuf)[1] = SWAP (ctx->B);
140 ((md5_uint32 *) resbuf)[2] = SWAP (ctx->C); 137 ((md5_uint32 *) resbuf)[2] = SWAP (ctx->C);
141 ((md5_uint32 *) resbuf)[3] = SWAP (ctx->D); 138 ((md5_uint32 *) resbuf)[3] = SWAP (ctx->D);
249 } 246 }
250 #endif /* not emacs */ 247 #endif /* not emacs */
251 248
252 249
253 static void 250 static void
254 md5_process_bytes (CONST void *buffer, size_t len, struct md5_ctx *ctx) 251 md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx)
255 { 252 {
256 /* When we already have some bits in our internal buffer concatenate 253 /* When we already have some bits in our internal buffer concatenate
257 both inputs first. */ 254 both inputs first. */
258 if (ctx->buflen != 0) 255 if (ctx->buflen != 0)
259 { 256 {
304 301
305 /* Process LEN bytes of BUFFER, accumulating context into CTX. 302 /* Process LEN bytes of BUFFER, accumulating context into CTX.
306 It is assumed that LEN % 64 == 0. */ 303 It is assumed that LEN % 64 == 0. */
307 304
308 static void 305 static void
309 md5_process_block (CONST void *buffer, size_t len, struct md5_ctx *ctx) 306 md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx)
310 { 307 {
311 md5_uint32 correct_words[16]; 308 md5_uint32 correct_words[16];
312 const md5_uint32 *words = (const md5_uint32 *) buffer; 309 const md5_uint32 *words = (const md5_uint32 *) buffer;
313 size_t nwords = len / sizeof (md5_uint32); 310 size_t nwords = len / sizeof (md5_uint32);
314 const md5_uint32 *endp = words + nwords; 311 const md5_uint32 *endp = words + nwords;