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


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

Merged DEV-2.0-dev0@604.

Location:
trunk/source/Lib/libmd5
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/libmd5/MD5.h

    r56 r608  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3737//! \{
    3838
    39 class MD5 {
     39class MD5
     40{
    4041public:
    4142  /**
     
    6869};
    6970
     71
    7072/**
    71  * Produce an ascii(hex) representation of the 128bit digest.
     73 * Produce an ascii(hex) representation of picture digest.
    7274 *
    7375 * Returns: a statically allocated null-terminated string.  DO NOT FREE.
    7476 */
    7577inline const char*
    76 digestToString(unsigned char digest[16])
     78digestToString(const unsigned char digest[3][16], int numChar)
    7779{
    7880  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++)
    8184  {
    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++] = ',';
    8491  }
     92
     93  string[cnt-1] = '\0';
    8594  return string;
    8695}
  • 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
  • trunk/source/Lib/libmd5/libmd5.h

    r56 r608  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    4040  uint32_t buf[4];
    4141  uint32_t bits[2];
    42   unsigned char in[64];
     42  union {
     43    unsigned char b8[64];
     44    uint32_t b32[16];
     45  } in;
    4346} context_md5_t;
    4447
Note: See TracChangeset for help on using the changeset viewer.