Changeset 6495 for trunk/licq

Show
Ignore:
Timestamp:
08/24/08 21:13:04 (3 months ago)
Author:
flynd
Message:

Use portable integer types from stdint.h instead of defining our own.

Location:
trunk/licq
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/licq/include/licq_md5.h

    r6493 r6495  
    1010#define MD5_H 
    1111 
     12#include <stddef.h> 
     13#include <stdint.h> 
     14 
    1215#define MD5_DIGEST_LENGTH 16 
    1316 
    14 #define UINT8 unsigned char 
    15 #define UINT32 unsigned int 
     17void md5(const uint8_t* buf, size_t len, uint8_t* digest); 
    1618 
    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]; 
     19struct MD5Context 
     20{ 
     21  uint32_t buf[4]; 
     22  uint32_t bytes[2]; 
     23  uint32_t in[16]; 
    2324}; 
    2425 
    2526void MD5Init(struct MD5Context *context); 
    26 void MD5Update(struct MD5Context *context, UINT8 const *buf, unsigned len); 
     27void MD5Update(struct MD5Context* context, uint8_t const* buf, size_t len); 
    2728void MD5Final(unsigned char digest[16], struct MD5Context *context); 
    28 void MD5Transform(UINT32 buf[4], UINT32 const in[16]); 
     29void MD5Transform(uint32_t buf[4], const uint32_t in[16]); 
    2930 
    30 void byteSwap(UINT32 * buf, unsigned words); 
     31void byteSwap(uint32_t* buf, unsigned words); 
    3132 
    3233#endif              /* !MD5_H */ 
  • trunk/licq/src/md5.cpp

    r6492 r6495  
    2323#include "licq_md5.h" 
    2424 
    25 void md5(const UINT8* buf, unsigned int len, UINT8* digest) 
     25void md5(const uint8_t* buf, size_t len, uint8_t* digest) 
    2626{ 
    2727  MD5Context context; 
     
    3535 * Note: this code is harmless but does nothing on little-endian machines. 
    3636 */ 
    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); 
     37void 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  } 
    4644} 
    4745 
     
    6462 * of bytes. 
    6563 */ 
    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]; 
     64void MD5Update(struct MD5Context* ctx, uint8_t const* buf, size_t len) 
     65{ 
     66  /* Update byte count */ 
     67  uint32_t t = ctx->bytes[0]; 
    7368    if ((ctx->bytes[0] = t + len) < t) 
    7469        ctx->bytes[1]++;    /* Carry from low to high */ 
     
    7671    t = 64 - (t & 0x3f);    /* Space available in ctx->in (at least 1) */ 
    7772    if (t > len) { 
    78         memcpy((UINT8 *) ctx->in + 64 - t, buf, len); 
     73    memcpy((uint8_t*)ctx->in + 64 - t, buf, len); 
    7974        return; 
    8075    } 
    8176    /* 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); 
    8378    byteSwap(ctx->in, 16); 
    8479    MD5Transform(ctx->buf, ctx->in); 
     
    10398 * 1 0* (64-bit count of bits processed, MSB-first) 
    10499 */ 
    105 void MD5Final(UINT8 digest[16], struct MD5Context *ctx) 
     100void MD5Final(uint8_t digest[16], struct MD5Context *ctx) 
    106101{ 
    107102    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; 
    109104 
    110105    /* Set the first char of padding to 0x80.  There is always room. */ 
     
    118113        byteSwap(ctx->in, 16); 
    119114        MD5Transform(ctx->buf, ctx->in); 
    120         p = (UINT8 *) ctx->in; 
     115    p = (uint8_t*)ctx->in; 
    121116        count = 56; 
    122117    } 
     
    153148 * the data and converts bytes into longwords for this routine. 
    154149 */ 
    155 void MD5Transform(UINT32 buf[4], UINT32 const in[16]) 
    156 { 
    157     register UINT32 a, b, c, d; 
     150void MD5Transform(uint32_t buf[4], const uint32_t in[16]) 
     151{ 
     152  register uint32_t a, b, c, d; 
    158153 
    159154    a = buf[0];