In need of MD5 for C++
Results 1 to 6 of 6

Thread: In need of MD5 for C++

  1. #1
    Member
    Join Date
    Feb 2006
    Location
    Canada
    Posts
    58

    In need of MD5 for C++

    Ok the problem Is i am in search of a library for C++ that includes a MD5 generator.

    I found one Crypto++ that has a MD5, except that the hash is stored in a byte array of which I cannot determine how I would compare to a md5 I have stored in a string.

    I would love to get this one working actualy, then I can solve my problem. What do you think byte means?

    Code:
    byte const* pbData = ...;
     unsigned int nDataLen = ...;
     byte abDigest[SHA::DIGESTSIZE];
     
     SHA().CalculateDigest(abDigest, pbData, nDataLen);
     
     // abDigest now contains the hash of pbData
    
     ...
    
     if (!SHA().VerifyDigest(abDigest, pbData, nDataLen))
     	throw "abDigest does not contain the right hash";
    Actualy here I am instructed to replace SHA() with MD5() but the code is suposed to be the same.

    The situation is I have developed a program that generates posible keys (6 chars) and I have been told what the corect md5 checksum is, since there are so many possible matches, I need to now calculate the md5 for each possible match and compare to the md5 that was given to me.

    Any ideas, all I need is a MD5 function.
    MyBox:

    Asus P5VDC-MX
    Celeron 2.8GHz
    512MB DDR 400
    WD 250GB SATA
    DVD-ROM, CD-RW
    Thermaltake 430W PSU
    Netgear WGT624 Router

  2. #2
    Senior Member
    Join Date
    Mar 2004
    Posts
    557
    Hi

    I have used the RFC 1321[1]-compliant implementation by Christophe Devine[2].
    It is written in c, but that should not matter (an untested md5-implementation
    in c++ can be found here[3])

    If you want to "see" the actual hash, modify in the main-function the following
    Code:
    for( j = 0; j < 16; j++ )
    {
        sprintf( output + j * 2, "%02x", md5sum[j] );
        printf( "%02x", md5sum[j] ); // <-- new
    }

    Cheers


    /edit: the md5.h file seems missing. here you go:
    Code:
    #ifndef _MD5_H
    #define _MD5_H
    
    #ifndef uint8
    #define uint8  unsigned char
    #endif
    
    #ifndef uint32
    #define uint32 unsigned long int
    #endif
    
    typedef struct
    {
        uint32 total[2];
        uint32 state[4];
        uint8 buffer[64];
    }
    md5_context;
    
    void md5_starts( md5_context *ctx );
    void md5_update( md5_context *ctx, uint8 *input, uint32 length );
    void md5_finish( md5_context *ctx, uint8 digest[16] );
    
    #endif /* md5.h */
    
     #ifndef _MD5_H
    #define _MD5_H
    
    #ifndef uint8
    #define uint8  unsigned char
    #endif
    
    #ifndef uint32
    #define uint32 unsigned long int
    #endif
    
    typedef struct
    {
        uint32 total[2];
        uint32 state[4];
        uint8 buffer[64];
    }
    md5_context;
    
    void md5_starts( md5_context *ctx );
    void md5_update( md5_context *ctx, uint8 *input, uint32 length );
    void md5_finish( md5_context *ctx, uint8 digest[16] );
    
    #endif /* md5.h */


    [1] http://rfc.net/rfc1321.html
    [2] http://www.cse.ucsc.edu/~kent/src/unzipped/lib/md5.c
    [3] http://www.ntecs.de/old-hp/s-direktn...ctions/Md5.cpp
    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

  3. #3
    Member
    Join Date
    Feb 2006
    Location
    Canada
    Posts
    58
    You are wounderfull, thanks very much.

    /EDIT

    Ok finaly got the rfc1321 code to work, there were to bugs, and I was compileing with the g++ and not gcc
    MyBox:

    Asus P5VDC-MX
    Celeron 2.8GHz
    512MB DDR 400
    WD 250GB SATA
    DVD-ROM, CD-RW
    Thermaltake 430W PSU
    Netgear WGT624 Router

  4. #4
    I has been published the MD5 code for fr33dom web page:

    yo ca see that here:

    http://www.fr33d0m.net/ftopict-72.html

    and if you have question related about MD5 process or SHA polinterpolation ... i'm here...



    greetz



    AzRaEL
    [NuKE] high council

  5. #5
    OK OK for not sound "like a spam" in my post i decide publish the code and a little explanation here:


    Hello this a little MD5 functionally code in c++


    [md5.c]

    Code:
    #include <string.h>  
    #include "md5.h" 
    
    #ifndef HIGHFIRST 
    #define byteReverse(buf, len)    
    #else 
    void byteReverse(unsigned char *buf, unsigned longs); 
    
    #ifndef ASM_MD5 
    void byteReverse(unsigned char *buf, unsigned longs) 
    { 
        uint32 t; 
        do { 
       t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 | 
           ((unsigned) buf[1] << 8 | buf[0]); 
       *(uint32 *) buf = t; 
       buf += 4; 
        } while (--longs); 
    } 
    #endif 
    #endif 
    
    
    void MD5Init(struct MD5Context *ctx) 
    { 
        ctx->buf[0] = 0x67452301; 
        ctx->buf[1] = 0xefcdab89; 
        ctx->buf[2] = 0x98badcfe; 
        ctx->buf[3] = 0x10325476; 
    
        ctx->bits[0] = 0; 
        ctx->bits[1] = 0; 
    } 
    
    void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len) 
    { 
        uint32 t; 
    
      
        t = ctx->bits[0]; 
        if ((ctx->bits[0] = t + ((uint32) len << 3)) < t) 
       ctx->bits[1]++;      
        ctx->bits[1] += len >> 29; 
    
        t = (t >> 3) & 0x3f;  
    
       if (t) { 
       unsigned char *p = (unsigned char *) ctx->in + t; 
    
       t = 64 - t; 
       if (len < t) { 
           memcpy(p, buf, len); 
           return; 
       } 
       memcpy(p, buf, t); 
       byteReverse(ctx->in, 16); 
       MD5Transform(ctx->buf, (uint32 *) ctx->in); 
       buf += t; 
       len -= t; 
        } 
      
        while (len >= 64) { 
       memcpy(ctx->in, buf, 64); 
       byteReverse(ctx->in, 16); 
       MD5Transform(ctx->buf, (uint32 *) ctx->in); 
       buf += 64; 
       len -= 64; 
        } 
    
        memcpy(ctx->in, buf, len); 
    } 
    
    void MD5Final(unsigned char digest[16], struct MD5Context *ctx) 
    { 
        unsigned count; 
        unsigned char *p; 
    
        count = (ctx->bits[0] >> 3) & 0x3F; 
    
         p = ctx->in + count; 
        *p++ = 0x80; 
    
        count = 64 - 1 - count; 
    
        if (count <  { 
        memset(p, 0, count); 
       byteReverse(ctx->in, 16); 
       MD5Transform(ctx->buf, (uint32 *) ctx->in); 
    
        memset(ctx->in, 0, 56); 
        } else { 
        memset(p, 0, count - ; 
        } 
        byteReverse(ctx->in, 14); 
    
        ((uint32 *) ctx->in)[14] = ctx->bits[0]; 
        ((uint32 *) ctx->in)[15] = ctx->bits[1]; 
    
        MD5Transform(ctx->buf, (uint32 *) ctx->in); 
        byteReverse((unsigned char *) ctx->buf, 4); 
        memcpy(digest, ctx->buf, 16); 
        memset(ctx, 0, sizeof(ctx));    
    } 
    
    #ifndef ASM_MD5 
    
    #define F1(x, y, z) (z ^ (x & (y ^ z))) 
    #define F2(x, y, z) F1(z, x, y) 
    #define F3(x, y, z) (x ^ y ^ z) 
    #define F4(x, y, z) (y ^ (x | ~z)) 
    
    #ifdef __PUREC__ 
    #define MD5STEP(f, w, x, y, z, data, s) \ 
       ( w += f /*(x, y, z)*/ + data,  w = w<<s | w>>(32-s),  w += x ) 
    #else 
    #define MD5STEP(f, w, x, y, z, data, s) \ 
       ( w += f(x, y, z) + data,  w = w<<s | w>>(32-s),  w += x ) 
    #endif 
    
    void MD5Transform(uint32 buf[4], uint32 const in[16]) 
    { 
        register uint32 a, b, c, d; 
    
        a = buf[0]; 
        b = buf[1]; 
        c = buf[2]; 
        d = buf[3]; 
    
    #ifdef __PUREC__   /* __ASM__ */ 
        MD5STEP(F1(b,c,d), a, b, c, d, in[0] + 0xd76aa478L, 7); 
        MD5STEP(F1(a,b,c), d, a, b, c, in[1] + 0xe8c7b756L, 12); 
        MD5STEP(F1(d,a,b), c, d, a, b, in[2] + 0x242070dbL, 17); 
        MD5STEP(F1(c,d,a), b, c, d, a, in[3] + 0xc1bdceeeL, 22); 
        MD5STEP(F1(b,c,d), a, b, c, d, in[4] + 0xf57c0fafL, 7); 
        MD5STEP(F1(a,b,c), d, a, b, c, in[5] + 0x4787c62aL, 12); 
        MD5STEP(F1(d,a,b), c, d, a, b, in[6] + 0xa8304613L, 17); 
        MD5STEP(F1(c,d,a), b, c, d, a, in[7] + 0xfd469501L, 22); 
        MD5STEP(F1(b,c,d), a, b, c, d, in[8] + 0x698098d8L, 7); 
        MD5STEP(F1(a,b,c), d, a, b, c, in[9] + 0x8b44f7afL, 12); 
        MD5STEP(F1(d,a,b), c, d, a, b, in[10] + 0xffff5bb1L, 17); 
        MD5STEP(F1(c,d,a), b, c, d, a, in[11] + 0x895cd7beL, 22); 
        MD5STEP(F1(b,c,d), a, b, c, d, in[12] + 0x6b901122L, 7); 
        MD5STEP(F1(a,b,c), d, a, b, c, in[13] + 0xfd987193L, 12); 
        MD5STEP(F1(d,a,b), c, d, a, b, in[14] + 0xa679438eL, 17); 
        MD5STEP(F1(c,d,a), b, c, d, a, in[15] + 0x49b40821L, 22); 
    
        MD5STEP(F2(b,c,d), a, b, c, d, in[1] + 0xf61e2562L, 5); 
        MD5STEP(F2(a,b,c), d, a, b, c, in[6] + 0xc040b340L, 9); 
        MD5STEP(F2(d,a,b), c, d, a, b, in[11] + 0x265e5a51L, 14); 
        MD5STEP(F2(c,d,a), b, c, d, a, in[0] + 0xe9b6c7aaL, 20); 
        MD5STEP(F2(b,c,d), a, b, c, d, in[5] + 0xd62f105dL, 5); 
        MD5STEP(F2(a,b,c), d, a, b, c, in[10] + 0x02441453L, 9); 
        MD5STEP(F2(d,a,b), c, d, a, b, in[15] + 0xd8a1e681L, 14); 
        MD5STEP(F2(c,d,a), b, c, d, a, in[4] + 0xe7d3fbc8L, 20); 
        MD5STEP(F2(b,c,d), a, b, c, d, in[9] + 0x21e1cde6L, 5); 
        MD5STEP(F2(a,b,c), d, a, b, c, in[14] + 0xc33707d6L, 9); 
        MD5STEP(F2(d,a,b), c, d, a, b, in[3] + 0xf4d50d87L, 14); 
        MD5STEP(F2(c,d,a), b, c, d, a, in[8] + 0x455a14edL, 20); 
        MD5STEP(F2(b,c,d), a, b, c, d, in[13] + 0xa9e3e905L, 5); 
        MD5STEP(F2(a,b,c), d, a, b, c, in[2] + 0xfcefa3f8L, 9); 
        MD5STEP(F2(d,a,b), c, d, a, b, in[7] + 0x676f02d9L, 14); 
        MD5STEP(F2(c,d,a), b, c, d, a, in[12] + 0x8d2a4c8aL, 20); 
    
        MD5STEP(F3(b,c,d), a, b, c, d, in[5] + 0xfffa3942L, 4); 
        MD5STEP(F3(a,b,c), d, a, b, c, in[8] + 0x8771f681L, 11); 
        MD5STEP(F3(d,a,b), c, d, a, b, in[11] + 0x6d9d6122L, 16); 
        MD5STEP(F3(c,d,a), b, c, d, a, in[14] + 0xfde5380cL, 23); 
        MD5STEP(F3(b,c,d), a, b, c, d, in[1] + 0xa4beea44L, 4); 
        MD5STEP(F3(a,b,c), d, a, b, c, in[4] + 0x4bdecfa9L, 11); 
        MD5STEP(F3(d,a,b), c, d, a, b, in[7] + 0xf6bb4b60L, 16); 
        MD5STEP(F3(c,d,a), b, c, d, a, in[10] + 0xbebfbc70L, 23); 
        MD5STEP(F3(b,c,d), a, b, c, d, in[13] + 0x289b7ec6L, 4); 
        MD5STEP(F3(a,b,c), d, a, b, c, in[0] + 0xeaa127faL, 11); 
        MD5STEP(F3(d,a,b), c, d, a, b, in[3] + 0xd4ef3085L, 16); 
        MD5STEP(F3(c,d,a), b, c, d, a, in[6] + 0x04881d05L, 23); 
        MD5STEP(F3(b,c,d), a, b, c, d, in[9] + 0xd9d4d039L, 4); 
        MD5STEP(F3(a,b,c), d, a, b, c, in[12] + 0xe6db99e5L, 11); 
        MD5STEP(F3(d,a,b), c, d, a, b, in[15] + 0x1fa27cf8L, 16); 
        MD5STEP(F3(c,d,a), b, c, d, a, in[2] + 0xc4ac5665L, 23); 
    
        MD5STEP(F4(b,c,d), a, b, c, d, in[0] + 0xf4292244L, 6); 
        MD5STEP(F4(a,b,c), d, a, b, c, in[7] + 0x432aff97L, 10); 
        MD5STEP(F4(d,a,b), c, d, a, b, in[14] + 0xab9423a7L, 15); 
        MD5STEP(F4(c,d,a), b, c, d, a, in[5] + 0xfc93a039L, 21); 
        MD5STEP(F4(b,c,d), a, b, c, d, in[12] + 0x655b59c3L, 6); 
        MD5STEP(F4(a,b,c), d, a, b, c, in[3] + 0x8f0ccc92L, 10); 
        MD5STEP(F4(d,a,b), c, d, a, b, in[10] + 0xffeff47dL, 15); 
        MD5STEP(F4(c,d,a), b, c, d, a, in[1] + 0x85845dd1L, 21); 
        MD5STEP(F4(b,c,d), a, b, c, d, in[8] + 0x6fa87e4fL, 6); 
        MD5STEP(F4(a,b,c), d, a, b, c, in[15] + 0xfe2ce6e0L, 10); 
        MD5STEP(F4(d,a,b), c, d, a, b, in[6] + 0xa3014314L, 15); 
        MD5STEP(F4(c,d,a), b, c, d, a, in[13] + 0x4e0811a1L, 21); 
        MD5STEP(F4(b,c,d), a, b, c, d, in[4] + 0xf7537e82L, 6); 
        MD5STEP(F4(a,b,c), d, a, b, c, in[11] + 0xbd3af235L, 10); 
        MD5STEP(F4(d,a,b), c, d, a, b, in[2] + 0x2ad7d2bbL, 15); 
        MD5STEP(F4(c,d,a), b, c, d, a, in[9] + 0xeb86d391L, 21); 
    #else 
        MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); 
        MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); 
        MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); 
        MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); 
        MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); 
        MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); 
        MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); 
        MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); 
        MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); 
        MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); 
        MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); 
        MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); 
        MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); 
        MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); 
        MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); 
        MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); 
    
        MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); 
        MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); 
        MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); 
        MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); 
        MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); 
        MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); 
        MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); 
        MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); 
        MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); 
        MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); 
        MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); 
        MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); 
        MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); 
        MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); 
        MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); 
        MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); 
    
        MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); 
        MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); 
        MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); 
        MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); 
        MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); 
        MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); 
        MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); 
        MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); 
        MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); 
        MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); 
        MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); 
        MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); 
        MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); 
        MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); 
        MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); 
        MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); 
    
        MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); 
        MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); 
        MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); 
        MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); 
        MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); 
        MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); 
        MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); 
        MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); 
        MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); 
        MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); 
        MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); 
        MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); 
        MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); 
        MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); 
        MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); 
        MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); 
    #endif 
    
        buf[0] += a; 
        buf[1] += b; 
        buf[2] += c; 
        buf[3] += d; 
    } 
    
    --fin de md5.c 
    
    
    
    md5.h 
    
    #ifndef MD5_H 
    #define MD5_H 
    
    #ifdef __alpha 
    typedef unsigned int uint32; 
    #else 
    typedef unsigned long uint32; 
    #endif 
    
    struct MD5Context { 
       uint32 buf[4]; 
       uint32 bits[2]; 
       unsigned char in[64]; 
    }; 
    
    void MD5Init(struct MD5Context *context); 
    void MD5Update(struct MD5Context *context, unsigned char const *buf, 
              unsigned len); 
    void MD5Final(unsigned char digest[16], struct MD5Context *context); 
    void MD5Transform(uint32 buf[4], uint32 const in[16]); 
    
    typedef struct MD5Context MD5_CTX; 
    
    #endif

    And a little explanation of that:



    So, the MD5 process is a poliinterpolation process, you know, i still implement a "pure" MD5 implementation,
    but how it's works?

    You'll see MD process based on a interpolation very easy, take a minus length bit on each byte for the source
    string called "factor", interpolate each z factors (mathemathics) betwen a "probabilistical table" like a huffman process
    where take each char and take only 4 bits and distribute in the probabilistical table, the result is a y factor but with 2 bits.
    (compression method).

    MD process is the most fast machine for interpolate any text. the MD5 process implement the original taken z factoring,
    when the exchange process is run you can mix the MD process with another encryption method, not support strong methods
    like a RCs or vernnam military algoritms (only tested with 3DES, RC4 low, Rijndael, MD4, sha-1 carry).

    On the "passing through" on each interpolate z factors is necesary convert to base64 each char resultant value and cicling it
    on the MD process because MD reverse process not accept no printable chars because the length on minus z factors.

    the mix process on it is when MD process find the minus z factor and recombine with the probabilistical table:

    Code:
    #define GET_UINT32_LE(n,b,i)                    \ 
    {                                               \ 
        (n) = ( (uint32) (b)[(i)    ]       )       \ 
            | ( (uint32) (b)[(i) + 1] <<  8 )       \ 
            | ( (uint32) (b)[(i) + 2] << 16 )       \ 
            | ( (uint32) (b)[(i) + 3] << 24 );      \ 
    }
    Code:
    void md5_process( md5_context *ctx, uint8 data[64] ) 
    { 
        uint32 X[16], A, B, C, D; 
    
        GET_UINT32_LE( X[0],  data,  0 ); 
        GET_UINT32_LE( X[1],  data,  4 ); 
        GET_UINT32_LE( X[2],  data,  8 ); 
        GET_UINT32_LE( X[3],  data, 12 ); 
        GET_UINT32_LE( X[4],  data, 16 ); 
        GET_UINT32_LE( X[5],  data, 20 ); 
        GET_UINT32_LE( X[6],  data, 24 ); 
        GET_UINT32_LE( X[7],  data, 28 ); 
        GET_UINT32_LE( X[8],  data, 32 ); 
        GET_UINT32_LE( X[9],  data, 36 ); 
        GET_UINT32_LE( X[10], data, 40 ); 
        GET_UINT32_LE( X[11], data, 44 ); 
        GET_UINT32_LE( X[12], data, 48 ); 
        GET_UINT32_LE( X[13], data, 52 ); 
        GET_UINT32_LE( X[14], data, 56 ); 
        GET_UINT32_LE( X[15], data, 60 ); 
    
    #define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n))) 
    
    #define P(a,b,c,d,k,s,t)                                \ 
    {                                                       \ 
        a += F(b,c,d) + X[k] + t; a = S(a,s) + b;           \ 
    } 
    
        A = ctx->state[0]; 
        B = ctx->state[1]; 
        C = ctx->state[2]; 
        D = ctx->state[3]; 
    
    #define F(x,y,z) (z ^ (x & (y ^ z))) 
    
        P( A, B, C, D,  0,  7, 0xD76AA478 ); 
        P( D, A, B, C,  1, 12, 0xE8C7B756 ); 
        P( C, D, A, B,  2, 17, 0x242070DB ); 
        P( B, C, D, A,  3, 22, 0xC1BDCEEE ); 
        P( A, B, C, D,  4,  7, 0xF57C0FAF ); 
        P( D, A, B, C,  5, 12, 0x4787C62A ); 
        P( C, D, A, B,  6, 17, 0xA8304613 ); 
        P( B, C, D, A,  7, 22, 0xFD469501 ); 
        P( A, B, C, D,  8,  7, 0x698098D8 ); 
        P( D, A, B, C,  9, 12, 0x8B44F7AF ); 
        P( C, D, A, B, 10, 17, 0xFFFF5BB1 ); 
        P( B, C, D, A, 11, 22, 0x895CD7BE ); 
        P( A, B, C, D, 12,  7, 0x6B901122 ); 
        P( D, A, B, C, 13, 12, 0xFD987193 ); 
        P( C, D, A, B, 14, 17, 0xA679438E ); 
        P( B, C, D, A, 15, 22, 0x49B40821 ); 
    
    #undef F 
    
    #define F(x,y,z) (y ^ (z & (x ^ y))) 
    
        P( A, B, C, D,  1,  5, 0xF61E2562 ); 
        P( D, A, B, C,  6,  9, 0xC040B340 ); 
        P( C, D, A, B, 11, 14, 0x265E5A51 ); 
        P( B, C, D, A,  0, 20, 0xE9B6C7AA ); 
        P( A, B, C, D,  5,  5, 0xD62F105D ); 
        P( D, A, B, C, 10,  9, 0x02441453 ); 
        P( C, D, A, B, 15, 14, 0xD8A1E681 ); 
        P( B, C, D, A,  4, 20, 0xE7D3FBC8 ); 
        P( A, B, C, D,  9,  5, 0x21E1CDE6 ); 
        P( D, A, B, C, 14,  9, 0xC33707D6 ); 
        P( C, D, A, B,  3, 14, 0xF4D50D87 ); 
        P( B, C, D, A,  8, 20, 0x455A14ED ); 
        P( A, B, C, D, 13,  5, 0xA9E3E905 ); 
        P( D, A, B, C,  2,  9, 0xFCEFA3F8 ); 
        P( C, D, A, B,  7, 14, 0x676F02D9 ); 
        P( B, C, D, A, 12, 20, 0x8D2A4C8A ); 
    
    #undef F 
        
    #define F(x,y,z) (x ^ y ^ z) 
    
        P( A, B, C, D,  5,  4, 0xFFFA3942 ); 
        P( D, A, B, C,  8, 11, 0x8771F681 ); 
        P( C, D, A, B, 11, 16, 0x6D9D6122 ); 
        P( B, C, D, A, 14, 23, 0xFDE5380C ); 
        P( A, B, C, D,  1,  4, 0xA4BEEA44 ); 
        P( D, A, B, C,  4, 11, 0x4BDECFA9 ); 
        P( C, D, A, B,  7, 16, 0xF6BB4B60 ); 
        P( B, C, D, A, 10, 23, 0xBEBFBC70 ); 
        P( A, B, C, D, 13,  4, 0x289B7EC6 ); 
        P( D, A, B, C,  0, 11, 0xEAA127FA ); 
        P( C, D, A, B,  3, 16, 0xD4EF3085 ); 
        P( B, C, D, A,  6, 23, 0x04881D05 ); 
        P( A, B, C, D,  9,  4, 0xD9D4D039 ); 
        P( D, A, B, C, 12, 11, 0xE6DB99E5 ); 
        P( C, D, A, B, 15, 16, 0x1FA27CF8 ); 
        P( B, C, D, A,  2, 23, 0xC4AC5665 ); 
    
    #undef F 
    
    #define F(x,y,z) (y ^ (x | ~z)) 
    
        P( A, B, C, D,  0,  6, 0xF4292244 ); 
        P( D, A, B, C,  7, 10, 0x432AFF97 ); 
        P( C, D, A, B, 14, 15, 0xAB9423A7 ); 
        P( B, C, D, A,  5, 21, 0xFC93A039 ); 
        P( A, B, C, D, 12,  6, 0x655B59C3 ); 
        P( D, A, B, C,  3, 10, 0x8F0CCC92 ); 
        P( C, D, A, B, 10, 15, 0xFFEFF47D ); 
        P( B, C, D, A,  1, 21, 0x85845DD1 ); 
        P( A, B, C, D,  8,  6, 0x6FA87E4F ); 
        P( D, A, B, C, 15, 10, 0xFE2CE6E0 ); 
        P( C, D, A, B,  6, 15, 0xA3014314 ); 
        P( B, C, D, A, 13, 21, 0x4E0811A1 ); 
        P( A, B, C, D,  4,  6, 0xF7537E82 ); 
        P( D, A, B, C, 11, 10, 0xBD3AF235 ); 
        P( C, D, A, B,  2, 15, 0x2AD7D2BB ); 
        P( B, C, D, A,  9, 21, 0xEB86D391 ); 
    
    #undef F 
    
        ctx->state[0] += A; 
        ctx->state[1] += B; 
        ctx->state[2] += C; 
        ctx->state[3] += D; 
    }
    padder virtual table


    Code:
    static uint8 md5_padding[64] = 
    { 
     0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 
    };


    This is the interpolating process, is when mix process is start:

    Code:
    void sha1_starts( sha1_context *ctx ) 
    { 
        ctx->total[0] = 0; 
        ctx->total[1] = 0; 
    
        ctx->state[0] = 0x67452301; 
        ctx->state[1] = 0xEFCDAB89; 
        ctx->state[2] = 0x98BADCFE; 
        ctx->state[3] = 0x10325476; 
        ctx->state[4] = 0xC3D2E1F0; 
    } 
    
    void sha1_process( sha1_context *ctx, uint8 data[64] ) 
    { 
        uint32 temp, W[16], A, B, C, D, E; 
    
        GET_UINT32_BE( W[0],  data,  0 ); 
        GET_UINT32_BE( W[1],  data,  4 ); 
        GET_UINT32_BE( W[2],  data,  8 ); 
        GET_UINT32_BE( W[3],  data, 12 ); 
        GET_UINT32_BE( W[4],  data, 16 ); 
        GET_UINT32_BE( W[5],  data, 20 ); 
        GET_UINT32_BE( W[6],  data, 24 ); 
        GET_UINT32_BE( W[7],  data, 28 ); 
        GET_UINT32_BE( W[8],  data, 32 ); 
        GET_UINT32_BE( W[9],  data, 36 ); 
        GET_UINT32_BE( W[10], data, 40 ); 
        GET_UINT32_BE( W[11], data, 44 ); 
        GET_UINT32_BE( W[12], data, 48 ); 
        GET_UINT32_BE( W[13], data, 52 ); 
        GET_UINT32_BE( W[14], data, 56 ); 
        GET_UINT32_BE( W[15], data, 60 ); 
    
    #define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n))) 
    
    #define R(t)                                            \ 
    (                                                       \ 
        temp = W[(t -  3) & 0x0F] ^ W[(t - 8) & 0x0F] ^     \ 
               W[(t - 14) & 0x0F] ^ W[ t      & 0x0F],      \ 
        ( W[t & 0x0F] = S(temp,1) )                         \ 
    ) 
    
    #define P(a,b,c,d,e,x)                                  \ 
    {                                                       \ 
        e += S(a,5) + F(b,c,d) + K + x; b = S(b,30);        \ 
    } 
    
        A = ctx->state[0]; 
        B = ctx->state[1]; 
        C = ctx->state[2]; 
        D = ctx->state[3]; 
        E = ctx->state[4]; 
    
    #define F(x,y,z) (z ^ (x & (y ^ z))) 
    #define K 0x5A827999 
    
        P( A, B, C, D, E, W[0]  ); 
        P( E, A, B, C, D, W[1]  ); 
        P( D, E, A, B, C, W[2]  ); 
        P( C, D, E, A, B, W[3]  ); 
        P( B, C, D, E, A, W[4]  ); 
        P( A, B, C, D, E, W[5]  ); 
        P( E, A, B, C, D, W[6]  ); 
        P( D, E, A, B, C, W[7]  ); 
        P( C, D, E, A, B, W[8]  ); 
        P( B, C, D, E, A, W[9]  ); 
        P( A, B, C, D, E, W[10] ); 
        P( E, A, B, C, D, W[11] ); 
        P( D, E, A, B, C, W[12] ); 
        P( C, D, E, A, B, W[13] ); 
        P( B, C, D, E, A, W[14] ); 
        P( A, B, C, D, E, W[15] ); 
        P( E, A, B, C, D, R(16) ); 
        P( D, E, A, B, C, R(17) ); 
        P( C, D, E, A, B, R(18) ); 
        P( B, C, D, E, A, R(19) ); 
    
    #undef K 
    #undef F 
    
    #define F(x,y,z) (x ^ y ^ z) 
    #define K 0x6ED9EBA1 
    
        P( A, B, C, D, E, R(20) ); 
        P( E, A, B, C, D, R(21) ); 
        P( D, E, A, B, C, R(22) ); 
        P( C, D, E, A, B, R(23) ); 
        P( B, C, D, E, A, R(24) ); 
        P( A, B, C, D, E, R(25) ); 
        P( E, A, B, C, D, R(26) ); 
        P( D, E, A, B, C, R(27) ); 
        P( C, D, E, A, B, R(28) ); 
        P( B, C, D, E, A, R(29) ); 
        P( A, B, C, D, E, R(30) ); 
        P( E, A, B, C, D, R(31) ); 
        P( D, E, A, B, C, R(32) ); 
        P( C, D, E, A, B, R(33) ); 
        P( B, C, D, E, A, R(34) ); 
        P( A, B, C, D, E, R(35) ); 
        P( E, A, B, C, D, R(36) ); 
        P( D, E, A, B, C, R(37) ); 
        P( C, D, E, A, B, R(38) ); 
        P( B, C, D, E, A, R(39) ); 
    
    #undef K 
    #undef F 
    
    #define F(x,y,z) ((x & y) | (z & (x | y))) 
    #define K 0x8F1BBCDC 
    
        P( A, B, C, D, E, R(40) ); 
        P( E, A, B, C, D, R(41) ); 
        P( D, E, A, B, C, R(42) ); 
        P( C, D, E, A, B, R(43) ); 
        P( B, C, D, E, A, R(44) ); 
        P( A, B, C, D, E, R(45) ); 
        P( E, A, B, C, D, R(46) ); 
        P( D, E, A, B, C, R(47) ); 
        P( C, D, E, A, B, R(48) ); 
        P( B, C, D, E, A, R(49) ); 
        P( A, B, C, D, E, R(50) ); 
        P( E, A, B, C, D, R(51) ); 
        P( D, E, A, B, C, R(52) ); 
        P( C, D, E, A, B, R(53) ); 
        P( B, C, D, E, A, R(54) ); 
        P( A, B, C, D, E, R(55) ); 
        P( E, A, B, C, D, R(56) ); 
        P( D, E, A, B, C, R(57) ); 
        P( C, D, E, A, B, R(58) ); 
        P( B, C, D, E, A, R(59) ); 
    
    #undef K 
    #undef F 
    
    #define F(x,y,z) (x ^ y ^ z) 
    #define K 0xCA62C1D6 
    
        P( A, B, C, D, E, R(60) ); 
        P( E, A, B, C, D, R(61) ); 
        P( D, E, A, B, C, R(62) ); 
        P( C, D, E, A, B, R(63) ); 
        P( B, C, D, E, A, R(64) ); 
        P( A, B, C, D, E, R(65) ); 
        P( E, A, B, C, D, R(66) ); 
        P( D, E, A, B, C, R(67) ); 
        P( C, D, E, A, B, R(68) ); 
        P( B, C, D, E, A, R(69) ); 
        P( A, B, C, D, E, R(70) ); 
        P( E, A, B, C, D, R(71) ); 
        P( D, E, A, B, C, R(72) ); 
        P( C, D, E, A, B, R(73) ); 
        P( B, C, D, E, A, R(74) ); 
        P( A, B, C, D, E, R(75) ); 
        P( E, A, B, C, D, R(76) ); 
        P( D, E, A, B, C, R(77) ); 
        P( C, D, E, A, B, R(78) ); 
        P( B, C, D, E, A, R(79) ); 
    
    #undef K 
    #undef F 
    
        ctx->state[0] += A; 
        ctx->state[1] += B; 
        ctx->state[2] += C; 
        ctx->state[3] += D; 
        ctx->state[4] += E; 
    }

    Looks like huffman i repeat...

    The states for change the source string is determined for the MD process, is relative the "equal" codes generated for this
    process because the probabilistical table define each z factors. But, i read in black hat advertisments (http://www.blackhat.com/ ) the antitesis for MD process explaining for "cloning MD5 fingerprints" and i suppose this guys never read the material for the z factors algotithms and i disapointed with that.


    recently work i released an application for exchange information betwen mi girl and me, called Kira Communicator, this app use the MD5 code put in this post and combine with a Rijndael crypto algotithm, also communicator use a central cryptography using a secure channel betwen the operator and the receptor, a dedicated server who cypher finally the code sended and send for this channel the data transfered on it.

    this a screen shot for my tool:





    I still implement cryptography on all for my tools, and have a little experience with crated my own central cryptographic methods, this MD5 code is a "pure" MD5 no recombine with anyone crypto algorithm. If anyone can contribute with my work i appreciate that...



    Greetz

    AzRaEL
    [NuKE] high council

  6. #6
    Senior Member
    Join Date
    Mar 2004
    Posts
    557
    Hi

    Code:
     	I has been published the MD5 code for fr33dom web page:
    Hm. Is there a difference to the one presented in this
    lecture (german) by Prof. Schmidt[1]?

    ...apart from mistakes in your code (haven't compiled it, but
    should pop up immediately):

    e.g. in
    void MD5Final(unsigned char digest[16], struct MD5Context *ctx)

    Code:
    if (count &lt;  {  
    --&gt; should be --&gt;
    if (count &lt;  8) { 
    
    
    memset(p, 0, count - ; 
    --&gt; should be --&gt;
    memset(p, 0, count - 8) ;


    The main reason I am a bit irritated is your "explanation" ... "very easy" ...


    Could you give me a definition of interpolation?
    Could you give me a definition of Poly-interpolation?
    Could you then tell me why the MD5 process is a Poly-Interpolation process?
    Could you give me a definition of z-factoring? Is it something general or your wording,
    because the variable in MD5 is called "z"? I know two "z-factorisations", and
    none have to do anything with the "z-factorisation" we are dealing with here.


    And now please show me why the MD process is "very easy". Why does that procedure
    guarantee for "chaotic behaviour" (small changes in the input will result in a completely
    different output)? Why is it difficult to find collisions? I mention this, because
    there have been prototypes of "hash functions", which were believed to be safe (just
    because a few millions examples haven't produced a collision), yet with the correct
    approach, one could identify for a given element in the codomain y (the "hash")
    almost all elements in the domain where "f(x_i)=y" as soon as one solution x_1
    was known. 4 rounds of 16 operation is not a sufficient condition. Certainly, the
    choice for the function "F" is crucial...


    Just for completeness: Is it surprising that what you call the "probabilistical
    table" looks like a huffman code?


    Cheers


    [1] http://www.it.fht-esslingen.de/~schm...h/hash-14.html
    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •