Changeset 608 in 3DVCSoftware for trunk/source/Lib/libmd5
- Timestamp:
- 1 Sep 2013, 22:47:26 (11 years ago)
- Location:
- trunk/source/Lib/libmd5
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/libmd5/MD5.h
r56 r608 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2013, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 37 37 //! \{ 38 38 39 class MD5 { 39 class MD5 40 { 40 41 public: 41 42 /** … … 68 69 }; 69 70 71 70 72 /** 71 * Produce an ascii(hex) representation of the 128bitdigest.73 * Produce an ascii(hex) representation of picture digest. 72 74 * 73 75 * Returns: a statically allocated null-terminated string. DO NOT FREE. 74 76 */ 75 77 inline const char* 76 digestToString( unsigned char digest[16])78 digestToString(const unsigned char digest[3][16], int numChar) 77 79 { 78 80 const char* hex = "0123456789abcdef"; 79 static char string[33]; 80 for (int i = 0; i < 16; i++) 81 static char string[99]; 82 int cnt=0; 83 for(int yuvIdx=0; yuvIdx<3; yuvIdx++) 81 84 { 82 string[i*2+0] = hex[digest[i] >> 4]; 83 string[i*2+1] = hex[digest[i] & 0xf]; 85 for (int i = 0; i < numChar; i++) 86 { 87 string[cnt++] = hex[digest[yuvIdx][i] >> 4]; 88 string[cnt++] = hex[digest[yuvIdx][i] & 0xf]; 89 } 90 string[cnt++] = ','; 84 91 } 92 93 string[cnt-1] = '\0'; 85 94 return string; 86 95 } -
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 -
trunk/source/Lib/libmd5/libmd5.h
r56 r608 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2013, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 40 40 uint32_t buf[4]; 41 41 uint32_t bits[2]; 42 unsigned char in[64]; 42 union { 43 unsigned char b8[64]; 44 uint32_t b32[16]; 45 } in; 43 46 } context_md5_t; 44 47
Note: See TracChangeset for help on using the changeset viewer.