icculus quake2 doxygen  1.0 dev
md4.c File Reference
#include <inttypes.h>

Go to the source code of this file.

Macros

#define ROTATELEFT32(x, s)   (((x)<<(s))|((x)>>(32-(s))))
 
#define F(X, Y, Z)   (((X)&(Y)) | ((~X)&(Z)))
 
#define G(X, Y, Z)   (((X)&(Y)) | ((X)&(Z)) | ((Y)&(Z)))
 
#define H(X, Y, Z)   ((X) ^ (Y) ^ (Z))
 
#define S(a, b, c, d, k, s)
 
#define T(a, b, c, d, k, s)
 
#define U(a, b, c, d, k, s)
 

Functions

static void DoMD4 ()
 
static void PerformMD4 (const unsigned char *buf, int length, unsigned char *digest)
 
unsigned Com_BlockChecksum (void *buffer, int length)
 

Variables

static uint32_t X [16]
 
static uint32_t A
 
static uint32_t AA
 
static uint32_t B
 
static uint32_t BB
 
static uint32_t C
 
static uint32_t CC
 
static uint32_t D
 
static uint32_t DD
 

Macro Definition Documentation

◆ F

#define F (   X,
  Y,
 
)    (((X)&(Y)) | ((~X)&(Z)))

Definition at line 13 of file md4.c.

◆ G

#define G (   X,
  Y,
 
)    (((X)&(Y)) | ((X)&(Z)) | ((Y)&(Z)))

Definition at line 14 of file md4.c.

◆ H

#define H (   X,
  Y,
 
)    ((X) ^ (Y) ^ (Z))

Definition at line 15 of file md4.c.

◆ ROTATELEFT32

#define ROTATELEFT32 (   x,
 
)    (((x)<<(s))|((x)>>(32-(s))))

Definition at line 11 of file md4.c.

◆ S

#define S (   a,
  b,
  c,
  d,
  k,
 
)
Value:
{ \
a += (F((b), (c), (d)) + X[(k)]); \
a = ROTATELEFT32(a, s); \
}

Definition at line 17 of file md4.c.

◆ T

#define T (   a,
  b,
  c,
  d,
  k,
 
)
Value:
{ \
a += (G((b), (c), (d)) + X[(k)] + 0x5A827999); \
a = ROTATELEFT32(a, s); \
}

Definition at line 21 of file md4.c.

◆ U

#define U (   a,
  b,
  c,
  d,
  k,
 
)
Value:
{ \
a += (H((b), (c), (d)) + X[(k)] + 0x6ED9EBA1); \
a = ROTATELEFT32(a, s); \
}

Definition at line 25 of file md4.c.

Function Documentation

◆ Com_BlockChecksum()

unsigned Com_BlockChecksum ( void buffer,
int  length 
)

Definition at line 165 of file md4.c.

166 {
167  uint32_t digest[4];
168  unsigned val;
169 
170  PerformMD4((unsigned char *)buffer, length, (unsigned char *)digest);
171 
172  val = digest[0] ^ digest[1] ^ digest[2] ^ digest[3];
173 
174  return val;
175 }

Referenced by CM_LoadMap(), COM_BlockSequenceCheckByte(), and FS_LoadPackFile().

◆ DoMD4()

static void DoMD4 ( )
static

Definition at line 36 of file md4.c.

37 {
38  AA = A;
39  BB = B;
40  CC = C;
41  DD = D;
42 
43  S(A, B, C, D, 0, 3); S(D, A, B, C, 1, 7); S(C, D, A, B, 2, 11); S(B, C, D, A, 3, 19);
44  S(A, B, C, D, 4, 3); S(D, A, B, C, 5, 7); S(C, D, A, B, 6, 11); S(B, C, D, A, 7, 19);
45  S(A, B, C, D, 8, 3); S(D, A, B, C, 9, 7); S(C, D, A, B, 10, 11); S(B, C, D, A, 11, 19);
46  S(A, B, C, D, 12, 3); S(D, A, B, C, 13, 7); S(C, D, A, B, 14, 11); S(B, C, D, A, 15, 19);
47 
48  T(A, B, C, D, 0, 3); T(D, A, B, C, 4, 5); T(C, D, A, B, 8, 9); T(B, C, D, A, 12, 13);
49  T(A, B, C, D, 1, 3); T(D, A, B, C, 5, 5); T(C, D, A, B, 9, 9); T(B, C, D, A, 13, 13);
50  T(A, B, C, D, 2, 3); T(D, A, B, C, 6, 5); T(C, D, A, B, 10, 9); T(B, C, D, A, 14, 13);
51  T(A, B, C, D, 3, 3); T(D, A, B, C, 7, 5); T(C, D, A, B, 11, 9); T(B, C, D, A, 15, 13);
52 
53  U(A, B, C, D, 0, 3); U(D, A, B, C, 8, 9); U(C, D, A, B, 4, 11); U(B, C, D, A, 12, 15);
54  U(A, B, C, D, 2, 3); U(D, A, B, C, 10, 9); U(C, D, A, B, 6, 11); U(B, C, D, A, 14, 15);
55  U(A, B, C, D, 1, 3); U(D, A, B, C, 9, 9); U(C, D, A, B, 5, 11); U(B, C, D, A, 13, 15);
56  U(A, B, C, D, 3, 3); U(D, A, B, C, 11, 9); U(C, D, A, B, 7, 11); U(B, C, D, A, 15, 15);
57 
58  A += AA;
59  B += BB;
60  C += CC;
61  D += DD;
62 }

Referenced by PerformMD4().

◆ PerformMD4()

static void PerformMD4 ( const unsigned char *  buf,
int  length,
unsigned char *  digest 
)
static

Definition at line 65 of file md4.c.

69 {
70  int len = length / 64; /* number of full blocks */
71  int rem = length % 64; /* number of left over bytes */
72 
73  int i, j;
74  const unsigned char *ptr = buf;
75 
76  /* initialize the MD buffer */
77  A = 0x67452301;
78  B = 0xEFCDAB89;
79  C = 0x98BADCFE;
80  D = 0x10325476;
81 
82  for (i = 0; i < len; i++) {
83  for (j = 0; j < 16; j++) {
84  X[j] = ((ptr[0]<< 0)|(ptr[1]<< 8)|
85  (ptr[2]<<16)|(ptr[3]<<24));
86 
87  ptr += 4;
88  }
89 
90  DoMD4();
91  }
92 
93  i = rem / 4;
94  for (j = 0; j < i; j++) {
95  X[j] = ((ptr[0]<< 0)|(ptr[1]<< 8)|
96  (ptr[2]<<16)|(ptr[3]<<24));
97 
98  ptr += 4;
99  }
100 
101  switch(rem % 4) {
102  case 0:
103  X[j] = 0x80U;
104  break;
105  case 1:
106  X[j] = ((ptr[0]<< 0)|((0x80U)<< 8));
107  break;
108  case 2:
109  X[j] = ((ptr[0]<< 0)|(ptr[1]<< 8)|((0x80U)<<16));
110  break;
111  case 3:
112  X[j] = ((ptr[0]<< 0)|(ptr[1]<< 8)|(ptr[2]<<16)|((0x80U)<<24));
113  break;
114  }
115  j++;
116 
117  if (j > 14) {
118  for (; j < 16; j++)
119  X[j] = 0;
120  DoMD4();
121 
122  j = 0;
123  }
124 
125  for (; j < 14; j++)
126  X[j] = 0;
127  X[14] = (length & 0x1FFFFFFF) << 3;
128  X[15] = (length & ~0x1FFFFFFF) >> 29;
129 
130  DoMD4();
131 
132 #if 1
133  digest[ 0] = (A & 0x000000FF) >> 0;
134  digest[ 1] = (A & 0x0000FF00) >> 8;
135  digest[ 2] = (A & 0x00FF0000) >> 16;
136  digest[ 3] = (A & 0xFF000000) >> 24;
137  digest[ 4] = (B & 0x000000FF) >> 0;
138  digest[ 5] = (B & 0x0000FF00) >> 8;
139  digest[ 6] = (B & 0x00FF0000) >> 16;
140  digest[ 7] = (B & 0xFF000000) >> 24;
141  digest[ 8] = (C & 0x000000FF) >> 0;
142  digest[ 9] = (C & 0x0000FF00) >> 8;
143  digest[10] = (C & 0x00FF0000) >> 16;
144  digest[11] = (C & 0xFF000000) >> 24;
145  digest[12] = (D & 0x000000FF) >> 0;
146  digest[13] = (D & 0x0000FF00) >> 8;
147  digest[14] = (D & 0x00FF0000) >> 16;
148  digest[15] = (D & 0xFF000000) >> 24;
149 #else
150  digest[0] = SWAPLSB(A);
151  digest[1] = SWAPLSB(B);
152  digest[2] = SWAPLSB(C);
153  digest[3] = SWAPLSB(D);
154 #endif
155 
156  A = AA = 0;
157  B = BB = 0;
158  C = CC = 0;
159  D = DD = 0;
160  for (j = 0; j < 16; j++)
161  X[j] = 0;
162 }

Referenced by Com_BlockChecksum().

Variable Documentation

◆ A

uint32_t A
static

Definition at line 31 of file md4.c.

Referenced by DoMD4(), and PerformMD4().

◆ AA

uint32_t AA
static

Definition at line 31 of file md4.c.

Referenced by DoMD4(), and PerformMD4().

◆ B

uint32_t B
static

Definition at line 32 of file md4.c.

Referenced by DoMD4(), and PerformMD4().

◆ BB

uint32_t BB
static

Definition at line 32 of file md4.c.

Referenced by DoMD4(), and PerformMD4().

◆ C

uint32_t C
static

Definition at line 33 of file md4.c.

Referenced by DoMD4(), and PerformMD4().

◆ CC

uint32_t CC
static

Definition at line 33 of file md4.c.

Referenced by DoMD4(), and PerformMD4().

◆ D

uint32_t D
static

Definition at line 34 of file md4.c.

Referenced by DoMD4(), and PerformMD4().

◆ DD

uint32_t DD
static

Definition at line 34 of file md4.c.

Referenced by DoMD4(), and PerformMD4().

◆ X

uint32_t X[16]
static

Definition at line 30 of file md4.c.

Referenced by PerformMD4().

DoMD4
static void DoMD4()
Definition: md4.c:36
C
static uint32_t C
Definition: md4.c:33
X
static uint32_t X[16]
Definition: md4.c:30
T
#define T(a, b, c, d, k, s)
Definition: md4.c:21
S
#define S(a, b, c, d, k, s)
Definition: md4.c:17
U
#define U(a, b, c, d, k, s)
Definition: md4.c:25
i
int i
Definition: q_shared.c:305
D
static uint32_t D
Definition: md4.c:34
A
static uint32_t A
Definition: md4.c:31
buffer
GLenum GLfloat * buffer
Definition: qgl_win.c:151
G
#define G(X, Y, Z)
Definition: md4.c:14
H
#define H(X, Y, Z)
Definition: md4.c:15
j
GLint j
Definition: qgl_win.c:150
B
static uint32_t B
Definition: md4.c:32
CC
static uint32_t CC
Definition: md4.c:33
ROTATELEFT32
#define ROTATELEFT32(x, s)
Definition: md4.c:11
F
#define F(X, Y, Z)
Definition: md4.c:13
DD
static uint32_t DD
Definition: md4.c:34
PerformMD4
static void PerformMD4(const unsigned char *buf, int length, unsigned char *digest)
Definition: md4.c:65
BB
static uint32_t BB
Definition: md4.c:32
AA
static uint32_t AA
Definition: md4.c:31