メインページ | アルファベット順一覧 | 構成 | ファイル一覧 | 構成メンバ | ファイルメンバ | 関連ページ

md_misc.h

説明を見る。
00001 
00007 #ifndef DKUTIL_C_MD_MISC_H
00008 #define DKUTIL_C_MD_MISC_H
00009 
00010 #include "dkcOSIndependent.h"
00011 
00012 enum edkcMessageDigestFlag{
00014     edkcMD_Finalized = 1,
00016     edkcMD_ByteReverse = 2,
00018     edkcMD_Optimize = 4,
00019 };
00020 
00021 typedef void (*DKC_MD_TRANSFORM_F_TYPE)(uint32 buf[4],uint32 const in[16]);
00022 
00024 typedef struct{
00025     uint32 count[2];
00026     uint32 abcd[4];
00027     /*union{
00028         uint64 a64[8];
00029         uint32 a32[16];
00030         uint16 a16[32];
00031         uint8  a8[64];
00032     }u_store;*/
00033     uint8 a8[64];
00034     uint8 flags;
00035 }DKC_MD5,DKC_MD4;
00036 
00040 DKC_INLINE void dkcMD_ByteReverse(uint8 buf[64], uint32 longs)
00041 {
00042   uint32 t;
00043   do 
00044     {
00045       t = (uint32) ((uint32) buf[3] << 8 | buf[2]) << 16 |
00046           ((uint32) buf[1] << 8 | buf[0]);
00047       *(uint32 *) buf = t;
00048       buf += 4;
00049     } 
00050   while (--longs);
00051 }
00052 
00057 DKC_INLINE void dkcMD_Update(DKC_MD5 *p, uint8 const *buf, uint32 len,DKC_MD_TRANSFORM_F_TYPE transform)
00058 {
00059   uint32 t;
00060 
00061   /* Update bitcount */
00062 
00063   t = p->count[0];
00064   if ((p->count[0] = t + ((uint32) len << 3)) < t)
00065     p->count[1]++;      /* Carry from low to high */
00066   p->count[1] += len >> 29;
00067 
00068   t = (t >> 3) & 0x3f;  /* Bytes already in shsInfo->data */
00069 
00070   /* Handle any leading odd-sized chunks */
00071 
00072   if (t) 
00073     {
00074       //uint8 *p = (uint8 *) p->a8 + t;
00075             uint8 *pc = (uint8 *)&(p->a8[t]);
00076       t = 64 - t;
00077       if (len < t) 
00078         {
00079           memmove(pc, buf, len);
00080           return;
00081     }
00082       memmove(pc, buf, t);
00083       if ((p->flags) & edkcMD_ByteReverse)
00084         dkcMD_ByteReverse(p->a8, 16);
00085       //MD5Transform(p->abcd, (uint32 *) p->a8);
00086             transform(p->abcd,(uint32 *) p->a8);
00087       buf += t;
00088       len -= t;
00089     }
00090   /* Process data in 64-byte chunks */
00091 
00092   while (len >= 64) 
00093     {
00094       memmove(p->a8, buf, 64);
00095       if ((p->flags) & edkcMD_ByteReverse)
00096         dkcMD_ByteReverse(p->a8, 16);
00097       //MD5Transform(p->abcd, (uint32 *) p->a8);
00098             transform(p->abcd,(uint32 *) p->a8);
00099       buf += 64;
00100       len -= 64;
00101     }
00102 
00103   /* Handle any remaining bytes of data. */
00104 
00105   memmove(p->a8, buf, len);
00106 }
00107 
00112 DKC_INLINE void dkcMD_Final( DKC_MD5 *ctx,DKC_MD_TRANSFORM_F_TYPE transform)
00113 {
00114   uint32 count;
00115   uint8 *p;
00116 
00117   /* Compute number of bytes mod 64 */
00118   count = (ctx->count[0] >> 3) & 0x3F;
00119 
00120   /* Set the first char of padding to 0x80.  This is safe since there is
00121      always at least one byte free */
00122   p = ctx->a8 + count;
00123   *p++ = 0x80;
00124 
00125   /* Bytes of padding needed to make 64 bytes */
00126   count = 64 - 1 - count;
00127 
00128   /* Pad out to 56 mod 64 */
00129   if (count < 8) 
00130     {
00131     /* Two lots of padding:  Pad the first block to 64 bytes */
00132       memset(p, 0, count);
00133       if ((ctx->flags) & edkcMD_ByteReverse)
00134         dkcMD_ByteReverse(ctx->a8, 16);
00135       //MD5Transform(ctx->abcd, (uint32 *) ctx->a8);
00136             transform(ctx->abcd,(uint32 *) ctx->a8);
00137       /* Now fill the next block with 56 bytes */
00138       memset(ctx->a8, 0, 56);
00139     } 
00140   else 
00141     {
00142       /* Pad block to 56 bytes */
00143       memset(p, 0, count - 8);
00144     }
00145   if ((ctx->flags) & edkcMD_ByteReverse)
00146     dkcMD_ByteReverse(ctx->a8, 14);
00147 
00148   /* Append length in bits and transform */
00149   ((uint32 *) ctx->a8)[14] = ctx->count[0];
00150   ((uint32 *) ctx->a8)[15] = ctx->count[1];
00151 
00152   //MD5Transform(ctx->abcd, (uint32 *) ctx->a8);
00153     transform(ctx->abcd,(uint32 *) ctx->a8);
00154   if ((ctx->flags) & edkcMD_ByteReverse)
00155     dkcMD_ByteReverse((uint8 *) ctx->abcd, 4);
00156   //memmove(digest, ctx->abcd, 16);
00157   //memset(ctx, 0, sizeof(ctx));    /* In case it's sensitive */
00158 }
00159 
00160 #endif 

dkutil_cに対してMon Jan 16 00:39:54 2006に生成されました。  doxygen 1.4.4