Changeset 6495 for trunk/licq
- Timestamp:
- 08/24/08 21:13:04 (3 months ago)
- Location:
- trunk/licq
- Files:
-
- 2 modified
-
include/licq_md5.h (modified) (1 diff)
-
src/md5.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/licq/include/licq_md5.h
r6493 r6495 10 10 #define MD5_H 11 11 12 #include <stddef.h> 13 #include <stdint.h> 14 12 15 #define MD5_DIGEST_LENGTH 16 13 16 14 #define UINT8 unsigned char 15 #define UINT32 unsigned int 17 void md5(const uint8_t* buf, size_t len, uint8_t* digest); 16 18 17 void md5(const UINT8* buf, unsigned int len, UINT8* digest); 18 19 struct MD5Context { 20 UINT32 buf[4]; 21 UINT32 bytes[2]; 22 UINT32 in[16]; 19 struct MD5Context 20 { 21 uint32_t buf[4]; 22 uint32_t bytes[2]; 23 uint32_t in[16]; 23 24 }; 24 25 25 26 void MD5Init(struct MD5Context *context); 26 void MD5Update(struct MD5Context *context, UINT8 const *buf, unsignedlen);27 void MD5Update(struct MD5Context* context, uint8_t const* buf, size_t len); 27 28 void MD5Final(unsigned char digest[16], struct MD5Context *context); 28 void MD5Transform( UINT32 buf[4], UINT32 const in[16]);29 void MD5Transform(uint32_t buf[4], const uint32_t in[16]); 29 30 30 void byteSwap( UINT32* buf, unsigned words);31 void byteSwap(uint32_t* buf, unsigned words); 31 32 32 33 #endif /* !MD5_H */ -
trunk/licq/src/md5.cpp
r6492 r6495 23 23 #include "licq_md5.h" 24 24 25 void md5(const UINT8* buf, unsigned int len, UINT8* digest)25 void md5(const uint8_t* buf, size_t len, uint8_t* digest) 26 26 { 27 27 MD5Context context; … … 35 35 * Note: this code is harmless but does nothing on little-endian machines. 36 36 */ 37 void byteSwap(UINT32 * buf, unsigned words) 38 { 39 UINT8 *p = (UINT8 *) buf; 40 41 do { 42 *buf++ = (UINT32) ((unsigned) p[3] << 8 | p[2]) << 16 | 43 ((unsigned) p[1] << 8 | p[0]); 44 p += 4; 45 } while (--words); 37 void byteSwap(uint32_t* buf, unsigned words) 38 { 39 for ( ; words > 0; --words) 40 { 41 uint8_t* p = (uint8_t*)buf; 42 *buf++ = (uint32_t)p[3] << 24 | (uint32_t)p[2] << 16 | (uint32_t)p[1] << 8 | p[0]; 43 } 46 44 } 47 45 … … 64 62 * of bytes. 65 63 */ 66 void MD5Update(struct MD5Context *ctx, UINT8 const *buf, unsigned len) 67 { 68 UINT32 t; 69 70 /* Update byte count */ 71 72 t = ctx->bytes[0]; 64 void MD5Update(struct MD5Context* ctx, uint8_t const* buf, size_t len) 65 { 66 /* Update byte count */ 67 uint32_t t = ctx->bytes[0]; 73 68 if ((ctx->bytes[0] = t + len) < t) 74 69 ctx->bytes[1]++; /* Carry from low to high */ … … 76 71 t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */ 77 72 if (t > len) { 78 memcpy((UINT8 *)ctx->in + 64 - t, buf, len);73 memcpy((uint8_t*)ctx->in + 64 - t, buf, len); 79 74 return; 80 75 } 81 76 /* First chunk is an odd size */ 82 memcpy((UINT8 *)ctx->in + 64 - t, buf, t);77 memcpy((uint8_t*)ctx->in + 64 - t, buf, t); 83 78 byteSwap(ctx->in, 16); 84 79 MD5Transform(ctx->buf, ctx->in); … … 103 98 * 1 0* (64-bit count of bits processed, MSB-first) 104 99 */ 105 void MD5Final( UINT8digest[16], struct MD5Context *ctx)100 void MD5Final(uint8_t digest[16], struct MD5Context *ctx) 106 101 { 107 102 int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */ 108 UINT8 *p = (UINT8 *)ctx->in + count;103 uint8_t* p = (uint8_t*)ctx->in + count; 109 104 110 105 /* Set the first char of padding to 0x80. There is always room. */ … … 118 113 byteSwap(ctx->in, 16); 119 114 MD5Transform(ctx->buf, ctx->in); 120 p = (UINT8 *)ctx->in;115 p = (uint8_t*)ctx->in; 121 116 count = 56; 122 117 } … … 153 148 * the data and converts bytes into longwords for this routine. 154 149 */ 155 void MD5Transform( UINT32 buf[4], UINT32 const in[16])156 { 157 register UINT32a, b, c, d;150 void MD5Transform(uint32_t buf[4], const uint32_t in[16]) 151 { 152 register uint32_t a, b, c, d; 158 153 159 154 a = buf[0];
