Changeset 608 in 3DVCSoftware for trunk/source/Lib/libmd5/libmd5.c
- Timestamp:
- 1 Sep 2013, 22:47:26 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/libmd5/libmd5.c
r56 r608 26 26 # define byteReverse(buf, len) /* Nothing */ 27 27 #else 28 void byteReverse(u nsigned char *buf, unsigned longs);28 void byteReverse(uint32_t *buf, unsigned len); 29 29 /* 30 30 * Note: this code is harmless on little-endian machines. 31 31 */ 32 void byteReverse(u nsigned char *buf, unsigned longs)32 void byteReverse(uint32_t *buf, unsigned len) 33 33 { 34 34 uint32_t t; 35 35 do { 36 t = (uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 | 37 ((unsigned) buf[1] << 8 | buf[0]); 38 *(uint32_t *) buf = t; 39 buf += 4; 40 } while (--longs); 36 char* bytes = (char *) buf; 37 t = ((unsigned) bytes[3] << 8 | bytes[2]) << 16 | 38 ((unsigned) bytes[1] << 8 | bytes[0]); 39 *buf = t; 40 buf++; 41 } while (--len); 41 42 } 42 43 #endif … … 77 78 78 79 if (t) { 79 unsigned char *p = (unsigned char *) ctx->in+ t;80 unsigned char *p = ctx->in.b8 + t; 80 81 81 82 t = 64 - t; … … 85 86 } 86 87 memcpy(p, buf, t); 87 byteReverse(ctx->in , 16);88 MD5Transform(ctx->buf, (uint32_t *) ctx->in);88 byteReverse(ctx->in.b32, 16); 89 MD5Transform(ctx->buf, ctx->in.b32); 89 90 buf += t; 90 91 len -= t; … … 93 94 94 95 while (len >= 64) { 95 memcpy(ctx->in , buf, 64);96 byteReverse(ctx->in , 16);97 MD5Transform(ctx->buf, (uint32_t *) ctx->in);96 memcpy(ctx->in.b8, buf, 64); 97 byteReverse(ctx->in.b32, 16); 98 MD5Transform(ctx->buf, ctx->in.b32); 98 99 buf += 64; 99 100 len -= 64; … … 102 103 /* Handle any remaining bytes of data. */ 103 104 104 memcpy(ctx->in , buf, len);105 memcpy(ctx->in.b8, buf, len); 105 106 } 106 107 … … 119 120 /* Set the first char of padding to 0x80. This is safe since there is 120 121 always at least one byte free */ 121 p = ctx->in + count;122 p = ctx->in.b8 + count; 122 123 *p++ = 0x80; 123 124 … … 129 130 /* Two lots of padding: Pad the first block to 64 bytes */ 130 131 memset(p, 0, count); 131 byteReverse(ctx->in , 16);132 MD5Transform(ctx->buf, (uint32_t *) ctx->in);132 byteReverse(ctx->in.b32, 16); 133 MD5Transform(ctx->buf, ctx->in.b32); 133 134 134 135 /* Now fill the next block with 56 bytes */ 135 memset(ctx->in , 0, 56);136 memset(ctx->in.b8, 0, 56); 136 137 } else { 137 138 /* Pad block to 56 bytes */ 138 139 memset(p, 0, count - 8); 139 140 } 140 byteReverse(ctx->in , 14);141 byteReverse(ctx->in.b32, 14); 141 142 142 143 /* Append length in bits and transform */ 143 ((uint32_t *) ctx->in)[14] = ctx->bits[0];144 ((uint32_t *) ctx->in)[15] = ctx->bits[1];145 146 MD5Transform(ctx->buf, (uint32_t *) ctx->in);147 byteReverse((u nsigned char*) ctx->buf, 4);144 ctx->in.b32[14] = ctx->bits[0]; 145 ctx->in.b32[15] = ctx->bits[1]; 146 147 MD5Transform(ctx->buf, ctx->in.b32); 148 byteReverse((uint32_t *) ctx->buf, 4); 148 149 memcpy(digest, ctx->buf, 16); 149 150
Note: See TracChangeset for help on using the changeset viewer.