src/md5/md5c.c File Reference

#include <string.h>
#include "md5.h"
#include "compat/compat.h"
Include dependency graph for md5c.c:

Go to the source code of this file.

Defines

#define F(x, y, z)   ((z) ^ ((x) & ((y) ^ (z))))
#define G(x, y, z)   ((y) ^ ((z) & ((x) ^ (y))))
#define H(x, y, z)   ((x) ^ (y) ^ (z))
#define I(x, y, z)   ((y) ^ ((x) | ~(z)))
#define STEP(f, a, b, c, d, x, t, s)
#define SET(n)
#define GET(n)   (ctx->block[(n)])

Functions

static void * body (MD5_CTX *ctx, void *data, unsigned long size)
void MD5_Init (MD5_CTX *ctx)
void MD5_Update (MD5_CTX *ctx, void *data, unsigned long size)
void MD5_Final (unsigned char *result, MD5_CTX *ctx)

Define Documentation

#define F ( x,
y,
 )     ((z) ^ ((x) & ((y) ^ (z))))

Definition at line 29 of file md5c.c.

Referenced by body().

#define G ( x,
y,
 )     ((y) ^ ((z) & ((x) ^ (y))))

Definition at line 30 of file md5c.c.

Referenced by body().

#define GET (  )     (ctx->block[(n)])

Definition at line 62 of file md5c.c.

Referenced by body().

#define H ( x,
y,
 )     ((x) ^ (y) ^ (z))

Definition at line 31 of file md5c.c.

Referenced by body().

#define I ( x,
y,
 )     ((y) ^ ((x) | ~(z)))

Definition at line 32 of file md5c.c.

Referenced by body().

#define SET (  ) 
Value:
(ctx->block[(n)] = \
    (MD5_u32plus)ptr[(n) * 4] | \
    ((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
    ((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
    ((MD5_u32plus)ptr[(n) * 4 + 3] << 24))

Definition at line 56 of file md5c.c.

Referenced by body().

#define STEP ( f,
a,
b,
c,
d,
x,
t,
 ) 
Value:
(a) += f((b), (c), (d)) + (x) + (t); \
    (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
    (a) += (b);

Definition at line 37 of file md5c.c.

Referenced by body().


Function Documentation

static void* body ( MD5_CTX ctx,
void *  data,
unsigned long  size 
) [static]

Definition at line 70 of file md5c.c.

References MD5_CTX::a, MD5_CTX::b, MD5_CTX::c, MD5_CTX::d, F, G, GET, H, I, SET, and STEP.

Referenced by MD5_Final(), and MD5_Update().

00071 {
00072     unsigned char *ptr;
00073     MD5_u32plus a, b, c, d;
00074     MD5_u32plus saved_a, saved_b, saved_c, saved_d;
00075 
00076     ptr = data;
00077 
00078     a = ctx->a;
00079     b = ctx->b;
00080     c = ctx->c;
00081     d = ctx->d;
00082 
00083     do {
00084         saved_a = a;
00085         saved_b = b;
00086         saved_c = c;
00087         saved_d = d;
00088 
00089 /* Round 1 */
00090         STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7)
00091         STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12)
00092         STEP(F, c, d, a, b, SET(2), 0x242070db, 17)
00093         STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22)
00094         STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7)
00095         STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12)
00096         STEP(F, c, d, a, b, SET(6), 0xa8304613, 17)
00097         STEP(F, b, c, d, a, SET(7), 0xfd469501, 22)
00098         STEP(F, a, b, c, d, SET(8), 0x698098d8, 7)
00099         STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12)
00100         STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17)
00101         STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22)
00102         STEP(F, a, b, c, d, SET(12), 0x6b901122, 7)
00103         STEP(F, d, a, b, c, SET(13), 0xfd987193, 12)
00104         STEP(F, c, d, a, b, SET(14), 0xa679438e, 17)
00105         STEP(F, b, c, d, a, SET(15), 0x49b40821, 22)
00106 
00107 /* Round 2 */
00108         STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5)
00109         STEP(G, d, a, b, c, GET(6), 0xc040b340, 9)
00110         STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14)
00111         STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20)
00112         STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5)
00113         STEP(G, d, a, b, c, GET(10), 0x02441453, 9)
00114         STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14)
00115         STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20)
00116         STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5)
00117         STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9)
00118         STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14)
00119         STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20)
00120         STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5)
00121         STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9)
00122         STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14)
00123         STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20)
00124 
00125 /* Round 3 */
00126         STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
00127         STEP(H, d, a, b, c, GET(8), 0x8771f681, 11)
00128         STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
00129         STEP(H, b, c, d, a, GET(14), 0xfde5380c, 23)
00130         STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)
00131         STEP(H, d, a, b, c, GET(4), 0x4bdecfa9, 11)
00132         STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)
00133         STEP(H, b, c, d, a, GET(10), 0xbebfbc70, 23)
00134         STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)
00135         STEP(H, d, a, b, c, GET(0), 0xeaa127fa, 11)
00136         STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)
00137         STEP(H, b, c, d, a, GET(6), 0x04881d05, 23)
00138         STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)
00139         STEP(H, d, a, b, c, GET(12), 0xe6db99e5, 11)
00140         STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
00141         STEP(H, b, c, d, a, GET(2), 0xc4ac5665, 23)
00142 
00143 /* Round 4 */
00144         STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
00145         STEP(I, d, a, b, c, GET(7), 0x432aff97, 10)
00146         STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15)
00147         STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21)
00148         STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6)
00149         STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10)
00150         STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15)
00151         STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21)
00152         STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6)
00153         STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10)
00154         STEP(I, c, d, a, b, GET(6), 0xa3014314, 15)
00155         STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21)
00156         STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6)
00157         STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10)
00158         STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15)
00159         STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21)
00160 
00161         a += saved_a;
00162         b += saved_b;
00163         c += saved_c;
00164         d += saved_d;
00165 
00166         ptr += 64;
00167     } while (size -= 64);
00168 
00169     ctx->a = a;
00170     ctx->b = b;
00171     ctx->c = c;
00172     ctx->d = d;
00173 
00174     return ptr;
00175 }

Here is the caller graph for this function:

void MD5_Final ( unsigned char *  result,
MD5_CTX ctx 
)

Definition at line 222 of file md5c.c.

References MD5_CTX::a, MD5_CTX::b, body(), MD5_CTX::buffer, MD5_CTX::c, MD5_CTX::d, egg_memset, free, MD5_CTX::hi, and MD5_CTX::lo.

00223 {
00224     unsigned long used, free;
00225 
00226     used = ctx->lo & 0x3f;
00227 
00228     ctx->buffer[used++] = 0x80;
00229 
00230     free = 64 - used;
00231 
00232     if (free < 8) {
00233         egg_memset(&ctx->buffer[used], 0, free);
00234         body(ctx, ctx->buffer, 64);
00235         used = 0;
00236         free = 64;
00237     }
00238 
00239     egg_memset(&ctx->buffer[used], 0, free - 8);
00240 
00241     ctx->lo <<= 3;
00242     ctx->buffer[56] = ctx->lo;
00243     ctx->buffer[57] = ctx->lo >> 8;
00244     ctx->buffer[58] = ctx->lo >> 16;
00245     ctx->buffer[59] = ctx->lo >> 24;
00246     ctx->buffer[60] = ctx->hi;
00247     ctx->buffer[61] = ctx->hi >> 8;
00248     ctx->buffer[62] = ctx->hi >> 16;
00249     ctx->buffer[63] = ctx->hi >> 24;
00250 
00251     body(ctx, ctx->buffer, 64);
00252 
00253     result[0] = ctx->a;
00254     result[1] = ctx->a >> 8;
00255     result[2] = ctx->a >> 16;
00256     result[3] = ctx->a >> 24;
00257     result[4] = ctx->b;
00258     result[5] = ctx->b >> 8;
00259     result[6] = ctx->b >> 16;
00260     result[7] = ctx->b >> 24;
00261     result[8] = ctx->c;
00262     result[9] = ctx->c >> 8;
00263     result[10] = ctx->c >> 16;
00264     result[11] = ctx->c >> 24;
00265     result[12] = ctx->d;
00266     result[13] = ctx->d >> 8;
00267     result[14] = ctx->d >> 16;
00268     result[15] = ctx->d >> 24;
00269 
00270     egg_memset(ctx, 0, sizeof(ctx));
00271 }

Here is the call graph for this function:

void MD5_Init ( MD5_CTX ctx  ) 

Definition at line 177 of file md5c.c.

References MD5_CTX::a, MD5_CTX::b, MD5_CTX::c, MD5_CTX::d, MD5_CTX::hi, and MD5_CTX::lo.

00178 {
00179     ctx->a = 0x67452301;
00180     ctx->b = 0xefcdab89;
00181     ctx->c = 0x98badcfe;
00182     ctx->d = 0x10325476;
00183 
00184     ctx->lo = 0;
00185     ctx->hi = 0;
00186 }

void MD5_Update ( MD5_CTX ctx,
void *  data,
unsigned long  size 
)

Definition at line 188 of file md5c.c.

References body(), MD5_CTX::buffer, egg_memcpy(), free, MD5_CTX::hi, and MD5_CTX::lo.

00189 {
00190     MD5_u32plus saved_lo;
00191     unsigned long used, free;
00192 
00193     saved_lo = ctx->lo;
00194     if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
00195         ctx->hi++;
00196     ctx->hi += size >> 29;
00197 
00198     used = saved_lo & 0x3f;
00199 
00200     if (used) {
00201         free = 64 - used;
00202 
00203         if (size < free) {
00204             egg_memcpy(&ctx->buffer[used], data, size);
00205             return;
00206         }
00207 
00208         egg_memcpy(&ctx->buffer[used], data, free);
00209         data = ((unsigned char *)data) + free;
00210         size -= free;
00211         body(ctx, ctx->buffer, 64);
00212     }
00213 
00214     if (size >= 64) {
00215         data = body(ctx, data, size & ~(unsigned long)0x3f);
00216         size &= 0x3f;
00217     }
00218 
00219     egg_memcpy(ctx->buffer, data, size);
00220 }

Here is the call graph for this function:


Generated on 7 Sep 2016 for Eggdrop by  doxygen 1.6.1