Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

md4.c File Reference

#include <string.h>

Include dependency graph for md4.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  MD4_CTX

Defines

#define F(x, y, z)   (((x) & (y)) | ((~x) & (z)))
#define FF(a, b, c, d, x, s)   {(a) += F ((b), (c), (d)) + (x); (a) = ROTATE_LEFT ((a), (s));}
#define G(x, y, z)   (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
#define GG(a, b, c, d, x, s)   {(a) += G ((b), (c), (d)) + (x) + (UINT4)0x5a827999; (a) = ROTATE_LEFT ((a), (s));}
#define H(x, y, z)   ((x) ^ (y) ^ (z))
#define HH(a, b, c, d, x, s)
#define ROTATE_LEFT(x, n)   (((x) << (n)) | ((x) >> (32-(n))))
#define S11   3
#define S12   7
#define S13   11
#define S14   19
#define S21   3
#define S22   5
#define S23   9
#define S24   13
#define S31   3
#define S32   9
#define S33   11
#define S34   15

Typedefs

typedef unsigned char * POINTER
typedef unsigned short int UINT2
typedef unsigned long int UINT4

Functions

unsigned Com_BlockChecksum (void *buffer, int length)
void Decode (UINT4 *, unsigned char *, unsigned int)
void Encode (unsigned char *, UINT4 *, unsigned int)
void MD4_memcpy (POINTER, POINTER, unsigned int)
void MD4_memset (POINTER, int, unsigned int)
void MD4Final (unsigned char[16], MD4_CTX *)
void MD4Init (MD4_CTX *)
void MD4Transform (UINT4[4], unsigned char[64])
void MD4Update (MD4_CTX *, unsigned char *, unsigned int)

Variables

unsigned char PADDING [64]


Define Documentation

#define F x,
y,
z   )     (((x) & (y)) | ((~x) & (z)))
 

Definition at line 79 of file md4.c.

#define FF a,
b,
c,
d,
x,
 )     {(a) += F ((b), (c), (d)) + (x); (a) = ROTATE_LEFT ((a), (s));}
 

Definition at line 88 of file md4.c.

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

Definition at line 80 of file md4.c.

#define GG a,
b,
c,
d,
x,
 )     {(a) += G ((b), (c), (d)) + (x) + (UINT4)0x5a827999; (a) = ROTATE_LEFT ((a), (s));}
 

Definition at line 90 of file md4.c.

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

Definition at line 81 of file md4.c.

#define HH a,
b,
c,
d,
x,
 ) 
 

Value:

{(a) += H ((b), (c), (d)) + (x) + (UINT4)0x6ed9eba1; (a) = \
ROTATE_LEFT ((a), (s)); }

Definition at line 92 of file md4.c.

#define ROTATE_LEFT x,
n   )     (((x) << (n)) | ((x) >> (32-(n))))
 

Definition at line 84 of file md4.c.

#define S11   3
 

Definition at line 55 of file md4.c.

#define S12   7
 

Definition at line 56 of file md4.c.

#define S13   11
 

Definition at line 57 of file md4.c.

#define S14   19
 

Definition at line 58 of file md4.c.

#define S21   3
 

Definition at line 59 of file md4.c.

#define S22   5
 

Definition at line 60 of file md4.c.

#define S23   9
 

Definition at line 61 of file md4.c.

#define S24   13
 

Definition at line 62 of file md4.c.

#define S31   3
 

Definition at line 63 of file md4.c.

#define S32   9
 

Definition at line 64 of file md4.c.

#define S33   11
 

Definition at line 65 of file md4.c.

#define S34   15
 

Definition at line 66 of file md4.c.


Typedef Documentation

typedef unsigned char* POINTER
 

Definition at line 6 of file md4.c.

typedef unsigned short int UINT2
 

Definition at line 9 of file md4.c.

typedef unsigned long int UINT4
 

Definition at line 12 of file md4.c.


Function Documentation

unsigned Com_BlockChecksum void *  buffer,
int  length
 

Definition at line 264 of file md4.c.

References buffer, length(), MD4Final(), MD4Init(), and MD4Update().

Referenced by CM_Checksum(), and FS_LoadZipFile().

00265 {
00266     int         digest[4];
00267     unsigned    val;
00268     MD4_CTX     ctx;
00269 
00270     MD4Init (&ctx);
00271     MD4Update (&ctx, (unsigned char *)buffer, length);
00272     MD4Final ( (unsigned char *)digest, &ctx);
00273     
00274     val = digest[0] ^ digest[1] ^ digest[2] ^ digest[3];
00275 
00276     return val;
00277 }

Here is the call graph for this function:

void Decode UINT4 ,
unsigned char *  ,
unsigned  int
[static]
 

Definition at line 254 of file md4.c.

References i, input, j, and output.

Referenced by MD4Transform().

00255 {
00256 unsigned int i, j;
00257 
00258 for (i = 0, j = 0; j < len; i++, j += 4)
00259     output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
00260 }

void Encode unsigned char *  ,
UINT4 ,
unsigned  int
[static]
 

Definition at line 240 of file md4.c.

References i, input, j, and output.

Referenced by MD4Final().

00241 {
00242     unsigned int i, j;
00243 
00244     for (i = 0, j = 0; j < len; i++, j += 4) {
00245         output[j] = (unsigned char)(input[i] & 0xff);
00246         output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
00247         output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
00248         output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
00249     }
00250 }

void MD4_memcpy POINTER  ,
POINTER  ,
unsigned  int
[static]
 

void MD4_memset POINTER  ,
int  ,
unsigned  int
[static]
 

void MD4Final unsigned  char[16],
MD4_CTX
 

Referenced by Com_BlockChecksum(), and Com_BlockChecksumKey().

void MD4Init MD4_CTX  ) 
 

Referenced by Com_BlockChecksum(), and Com_BlockChecksumKey().

void MD4Transform UINT4  [4],
unsigned  char[64]
[static]
 

Definition at line 169 of file md4.c.

References a, b, c, d, Decode(), FF, GG, HH, memset(), POINTER, S11, S12, S13, S14, S21, S22, S23, S24, S31, S32, S33, S34, state, UINT4, and x.

Referenced by MD4Update().

00170 {
00171     UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
00172 
00173     Decode (x, block, 64);
00174 
00175 /* Round 1 */
00176 FF (a, b, c, d, x[ 0], S11);                /* 1 */
00177 FF (d, a, b, c, x[ 1], S12);                /* 2 */
00178 FF (c, d, a, b, x[ 2], S13);                /* 3 */
00179 FF (b, c, d, a, x[ 3], S14);                /* 4 */
00180 FF (a, b, c, d, x[ 4], S11);                /* 5 */
00181 FF (d, a, b, c, x[ 5], S12);                /* 6 */
00182 FF (c, d, a, b, x[ 6], S13);                /* 7 */
00183 FF (b, c, d, a, x[ 7], S14);                /* 8 */
00184 FF (a, b, c, d, x[ 8], S11);                /* 9 */
00185 FF (d, a, b, c, x[ 9], S12);                /* 10 */
00186 FF (c, d, a, b, x[10], S13);            /* 11 */
00187 FF (b, c, d, a, x[11], S14);            /* 12 */
00188 FF (a, b, c, d, x[12], S11);            /* 13 */
00189 FF (d, a, b, c, x[13], S12);            /* 14 */
00190 FF (c, d, a, b, x[14], S13);            /* 15 */
00191 FF (b, c, d, a, x[15], S14);            /* 16 */
00192 
00193 /* Round 2 */
00194 GG (a, b, c, d, x[ 0], S21);            /* 17 */
00195 GG (d, a, b, c, x[ 4], S22);            /* 18 */
00196 GG (c, d, a, b, x[ 8], S23);            /* 19 */
00197 GG (b, c, d, a, x[12], S24);            /* 20 */
00198 GG (a, b, c, d, x[ 1], S21);            /* 21 */
00199 GG (d, a, b, c, x[ 5], S22);            /* 22 */
00200 GG (c, d, a, b, x[ 9], S23);            /* 23 */
00201 GG (b, c, d, a, x[13], S24);            /* 24 */
00202 GG (a, b, c, d, x[ 2], S21);            /* 25 */
00203 GG (d, a, b, c, x[ 6], S22);            /* 26 */
00204 GG (c, d, a, b, x[10], S23);            /* 27 */
00205 GG (b, c, d, a, x[14], S24);            /* 28 */
00206 GG (a, b, c, d, x[ 3], S21);            /* 29 */
00207 GG (d, a, b, c, x[ 7], S22);            /* 30 */
00208 GG (c, d, a, b, x[11], S23);            /* 31 */
00209 GG (b, c, d, a, x[15], S24);            /* 32 */
00210 
00211 /* Round 3 */
00212 HH (a, b, c, d, x[ 0], S31);                /* 33 */
00213 HH (d, a, b, c, x[ 8], S32);            /* 34 */
00214 HH (c, d, a, b, x[ 4], S33);            /* 35 */
00215 HH (b, c, d, a, x[12], S34);            /* 36 */
00216 HH (a, b, c, d, x[ 2], S31);            /* 37 */
00217 HH (d, a, b, c, x[10], S32);            /* 38 */
00218 HH (c, d, a, b, x[ 6], S33);            /* 39 */
00219 HH (b, c, d, a, x[14], S34);            /* 40 */
00220 HH (a, b, c, d, x[ 1], S31);            /* 41 */
00221 HH (d, a, b, c, x[ 9], S32);            /* 42 */
00222 HH (c, d, a, b, x[ 5], S33);            /* 43 */
00223 HH (b, c, d, a, x[13], S34);            /* 44 */
00224 HH (a, b, c, d, x[ 3], S31);            /* 45 */
00225 HH (d, a, b, c, x[11], S32);            /* 46 */
00226 HH (c, d, a, b, x[ 7], S33);            /* 47 */
00227 HH (b, c, d, a, x[15], S34);            /* 48 */
00228 
00229 state[0] += a;
00230 state[1] += b;
00231 state[2] += c;
00232 state[3] += d;
00233 
00234     /* Zeroize sensitive information.*/
00235     memset ((POINTER)x, 0, sizeof (x));
00236 }

Here is the call graph for this function:

void MD4Update MD4_CTX ,
unsigned char *  ,
unsigned  int
 

Definition at line 109 of file md4.c.

References MD4_CTX::buffer, MD4_CTX::count, i, input, MD4Transform(), memcpy(), POINTER, and MD4_CTX::state.

Referenced by Com_BlockChecksum(), Com_BlockChecksumKey(), and MD4Final().

00110 {
00111     unsigned int i, index, partLen;
00112 
00113     /* Compute number of bytes mod 64 */
00114     index = (unsigned int)((context->count[0] >> 3) & 0x3F);
00115 
00116     /* Update number of bits */
00117     if ((context->count[0] += ((UINT4)inputLen << 3))< ((UINT4)inputLen << 3))
00118         context->count[1]++;
00119 
00120     context->count[1] += ((UINT4)inputLen >> 29);
00121 
00122     partLen = 64 - index;
00123 
00124     /* Transform as many times as possible.*/
00125     if (inputLen >= partLen)
00126     {
00127         memcpy((POINTER)&context->buffer[index], (POINTER)input, partLen);
00128         MD4Transform (context->state, context->buffer);
00129 
00130         for (i = partLen; i + 63 < inputLen; i += 64)
00131             MD4Transform (context->state, &input[i]);
00132 
00133         index = 0;
00134     }
00135     else
00136         i = 0;
00137 
00138     /* Buffer remaining input */
00139     memcpy ((POINTER)&context->buffer[index], (POINTER)&input[i], inputLen-i);
00140 }

Here is the call graph for this function:


Variable Documentation

unsigned char PADDING[64] [static]
 

Initial value:

 {
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
}

Definition at line 74 of file md4.c.


Generated on Thu Aug 25 14:43:29 2005 for Quake III Arena by  doxygen 1.3.9.1