Changeset 608 in 3DVCSoftware for trunk/source/Lib/libmd5/libmd5.c


Ignore:
Timestamp:
1 Sep 2013, 22:47:26 (11 years ago)
Author:
tech
Message:

Merged DEV-2.0-dev0@604.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/libmd5/libmd5.c

    r56 r608  
    2626# define byteReverse(buf, len)    /* Nothing */
    2727#else
    28 void byteReverse(unsigned char *buf, unsigned longs);
     28void byteReverse(uint32_t *buf, unsigned len);
    2929/*
    3030 * Note: this code is harmless on little-endian machines.
    3131 */
    32 void byteReverse(unsigned char *buf, unsigned longs)
     32void byteReverse(uint32_t *buf, unsigned len)
    3333{
    3434  uint32_t t;
    3535  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);
    4142}
    4243#endif
     
    7778
    7879  if (t) {
    79     unsigned char *p = (unsigned char *) ctx->in + t;
     80    unsigned char *p = ctx->in.b8 + t;
    8081
    8182    t = 64 - t;
     
    8586    }
    8687    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);
    8990    buf += t;
    9091    len -= t;
     
    9394
    9495  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);
    9899    buf += 64;
    99100    len -= 64;
     
    102103    /* Handle any remaining bytes of data. */
    103104
    104   memcpy(ctx->in, buf, len);
     105  memcpy(ctx->in.b8, buf, len);
    105106}
    106107
     
    119120  /* Set the first char of padding to 0x80.  This is safe since there is
    120121     always at least one byte free */
    121   p = ctx->in + count;
     122  p = ctx->in.b8 + count;
    122123  *p++ = 0x80;
    123124
     
    129130    /* Two lots of padding:  Pad the first block to 64 bytes */
    130131    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);
    133134
    134135    /* Now fill the next block with 56 bytes */
    135     memset(ctx->in, 0, 56);
     136    memset(ctx->in.b8, 0, 56);
    136137  } else {
    137138    /* Pad block to 56 bytes */
    138139    memset(p, 0, count - 8);
    139140  }
    140   byteReverse(ctx->in, 14);
     141  byteReverse(ctx->in.b32, 14);
    141142
    142143  /* 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((unsigned 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);
    148149  memcpy(digest, ctx->buf, 16);
    149150
Note: See TracChangeset for help on using the changeset viewer.