Changeset 6496 for trunk/licq

Show
Ignore:
Timestamp:
08/24/08 22:40:12 (3 months ago)
Author:
flynd
Message:

Don't use two 32 bit vars for a 64 bit counter. Compiler can handle this for 32 bit systems.

Location:
trunk/licq
Files:
2 modified

Legend:

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

    r6495 r6496  
    2020{ 
    2121  uint32_t buf[4]; 
    22   uint32_t bytes[2]; 
     22  uint64_t bytes; 
    2323  uint32_t in[16]; 
    2424}; 
  • trunk/licq/src/md5.cpp

    r6495 r6496  
    5454    ctx->buf[2]     = 0x98badcfe; 
    5555    ctx->buf[3]     = 0x10325476; 
    56     ctx->bytes[0]   = 0; 
    57     ctx->bytes[1]   = 0; 
     56  ctx->bytes = 0; 
    5857} 
    5958 
     
    6463void MD5Update(struct MD5Context* ctx, uint8_t const* buf, size_t len) 
    6564{ 
     65  /* Space available in ctx->in (at least 1) */ 
     66  uint32_t t = 64 - (ctx->bytes & 0x3f); 
     67 
    6668  /* Update byte count */ 
    67   uint32_t t = ctx->bytes[0]; 
    68     if ((ctx->bytes[0] = t + len) < t) 
    69         ctx->bytes[1]++;    /* Carry from low to high */ 
    70  
    71     t = 64 - (t & 0x3f);    /* Space available in ctx->in (at least 1) */ 
     69  ctx->bytes += len; 
     70 
    7271    if (t > len) { 
    7372    memcpy((uint8_t*)ctx->in + 64 - t, buf, len); 
     
    10099void MD5Final(uint8_t digest[16], struct MD5Context *ctx) 
    101100{ 
    102     int     count = ctx->bytes[0] & 0x3f;   /* Number of bytes in ctx->in */ 
     101  int count = ctx->bytes & 0x3f; /* Number of bytes in ctx->in */ 
    103102  uint8_t* p = (uint8_t*)ctx->in + count; 
    104103 
     
    120119 
    121120    /* Append length in bits and transform */ 
    122     ctx->in[14] = ctx->bytes[0] << 3; 
    123     ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29; 
     121  ctx->in[14] = ctx->bytes << 3; 
     122  ctx->in[15] = ctx->bytes >> 29; 
    124123    MD5Transform(ctx->buf, ctx->in); 
    125124