Changeset 1761
- Timestamp:
- Feb 24, 2007, 6:37:46 PM (15 years ago)
- Location:
- zzuf/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
zzuf/trunk/configure.ac
r1760 r1761 28 28 AC_SUBST(DLL_LDFLAGS) 29 29 30 AC_CHECK_HEADERS(windows.h winsock2.h io.h process.h unistd.h inttypes.h stdint.h getopt.h libc.h malloc.h dlfcn.h regex.h sys/socket.h sys/uio.h aio.h sys/mman.h sys/wait.h sys/resource.h sys/time.h )30 AC_CHECK_HEADERS(windows.h winsock2.h io.h process.h unistd.h inttypes.h stdint.h getopt.h libc.h malloc.h dlfcn.h regex.h sys/socket.h sys/uio.h aio.h sys/mman.h sys/wait.h sys/resource.h sys/time.h endian.h) 31 31 32 32 AC_CHECK_FUNCS(setenv waitpid setrlimit gettimeofday fork kill pipe _pipe) -
zzuf/trunk/src/md5.c
r1623 r1761 25 25 # include <inttypes.h> 26 26 #endif 27 #if defined HAVE_ENDIAN_H 28 # include <endian.h> 29 #endif 27 30 #include <string.h> 28 31 #include <stdlib.h> … … 30 33 #include "md5.h" 31 34 32 struct md5 { 33 uint32_t buf[4]; 34 uint32_t bits[2]; 35 uint8_t in[64]; 35 struct md5 36 { 37 uint32_t buf[4]; 38 uint32_t bits[2]; 39 uint32_t in[64]; 36 40 }; 37 41 42 static void swapwords(uint32_t *buf, unsigned words); 38 43 static void transform(uint32_t buf[4], uint32_t in[16]); 39 40 #define HIGHFIRST41 #ifdef __i386__42 #undef HIGHFIRST43 #endif44 45 #ifndef HIGHFIRST46 #define swapbytes(buf, len) /* Nothing */47 #else48 /*49 * Note: this code is harmless on little-endian machines.50 */51 void swapbytes(uint8_t *buf, unsigned bytes)52 {53 uint32_t t;54 do55 {56 t = (uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 |57 ((unsigned) buf[1] << 8 | buf[0]);58 *(uint32_t *) buf = t;59 buf += 4;60 bytes -= 4;61 } while(bytes > 0);62 }63 #endif64 44 65 45 struct md5 *_zz_md5_init(void) … … 84 64 t = ctx->bits[0]; 85 65 if((ctx->bits[0] = t + ((uint32_t)len << 3)) < t) 86 66 ctx->bits[1]++; 87 67 ctx->bits[1] += len >> 29; 88 68 … … 91 71 if(t) 92 72 { 93 94 95 96 73 uint8_t *p = (uint8_t *)ctx->in + t; 74 75 t = 64 - t; 76 if(len < t) 97 77 { 98 99 100 101 102 swapbytes(ctx->in, 64);103 transform(ctx->buf, (uint32_t *)ctx->in);104 105 106 } 107 108 while 109 { 110 111 swapbytes(ctx->in, 64);112 transform(ctx->buf, (uint32_t *)ctx->in);113 114 78 memcpy(p, buf, len); 79 return; 80 } 81 memcpy(p, buf, t); 82 swapwords(ctx->in, 64 / 4); 83 transform(ctx->buf, ctx->in); 84 buf += t; 85 len -= t; 86 } 87 88 while(len >= 64) 89 { 90 memcpy(ctx->in, buf, 64); 91 swapwords(ctx->in, 64 / 4); 92 transform(ctx->buf, ctx->in); 93 buf += 64; 94 len -= 64; 115 95 } 116 96 … … 124 104 125 105 count = (ctx->bits[0] >> 3) & 0x3F; 126 p = ctx->in + count;106 p = (uint8_t *)ctx->in + count; 127 107 *p++ = 0x80; 128 108 … … 130 110 if(count < 8) 131 111 { 132 133 swapbytes(ctx->in, 64);134 transform(ctx->buf, (uint32_t *)ctx->in);135 112 memset(p, 0, count); 113 swapwords(ctx->in, 64 / 4); 114 transform(ctx->buf, ctx->in); 115 memset(ctx->in, 0, 56); 136 116 } 137 117 else 138 139 140 swap bytes(ctx->in, 56);141 memcpy(ctx->in + 56 , ctx->bits, 8);142 transform(ctx->buf, (uint32_t *)ctx->in);143 swap bytes((uint8_t *)ctx->buf, 16);118 memset(p, 0, count - 8); 119 120 swapwords(ctx->in, 56 / 4); 121 memcpy(ctx->in + 56 / 4, ctx->bits, 8); 122 transform(ctx->buf, ctx->in); 123 swapwords(ctx->buf, 16 / 4); 144 124 memcpy(digest, ctx->buf, 16); 145 125 free(ctx); 126 } 127 128 static void swapwords(uint32_t *buf, unsigned words) 129 { 130 /* XXX: no need to swap words on little endian machines */ 131 #if defined HAVE_ENDIAN_H 132 if(__BYTE_ORDER == __LITTLE_ENDIAN) 133 return; 134 #else 135 /* This is compile-time optimised with at least -O1 or -Os */ 136 uint32_t const tmp = 0x12345678; 137 if(*(uint8_t const *)&tmp == 0x78) 138 return; 139 #endif 140 141 while(words > 0) 142 { 143 uint8_t *b = (uint8_t *)buf; 144 *buf++ = (uint32_t)((unsigned) b[3] << 8 | b[2]) << 16 | 145 ((unsigned) b[1] << 8 | b[0]); 146 words--; 147 } 146 148 } 147 149 … … 153 155 154 156 #define MD5STEP(f, w, x, y, z, data, s) \ 155 ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x)157 (w += f(x, y, z) + data, w = w << s | w >> (32 - s), w += x) 156 158 157 159 static void transform(uint32_t buf[4], uint32_t in[16])
Note: See TracChangeset
for help on using the changeset viewer.