|
#include "global.h"
$ d0 G5 C8 e0 t! g) w. G: F#include "md5.h"
. V6 z0 Z& p6 J; K 1 Z4 I) X; Z0 _* T1 c- o
/* Constants for MD5Transform routine. */
0 D5 T, _& R8 T( n3 L3 H. L Q4 i' ? $ g* u* m3 J/ |' R
$ I( z; T0 J6 C M) i. q8 [; ^' P. t
#define S11 7
& q8 F; m {8 S$ @) m0 V0 _5 k" |#define S12 12 6 q. J- T n+ @4 J+ q+ q
#define S13 17 , Q; D! H7 S! j, t
#define S14 22 8 o: J6 n9 h9 X* H
#define S21 5 " K, Y6 W* g! c' K5 i6 A
#define S22 9 0 o: c' m. j2 L0 M; X/ L8 K
#define S23 14
4 N/ i6 [# o) A, s9 s#define S24 20
4 [- G1 B( T% \, \4 J& X" k9 W#define S31 4
4 d9 a) B: [3 L5 j/ U#define S32 11
' `! C- R5 T9 v/ {+ ]6 j#define S33 16
0 Y% W) Z3 M3 |2 h/ D4 c' I#define S34 23
& p [. `% v3 E" B1 A: ~#define S41 6 ; R/ y# K: E# E# a4 s4 e
#define S42 10 % k. @" C: N$ x2 a- P
#define S43 15 , b4 x% P2 R5 l" n4 j/ V3 Z; {* y
#define S44 21
- i. {7 U( w5 r5 n( @3 v
# i3 d+ r2 I, d8 H' ystatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
4 T v" i! G( f* e" T% w4 V) V3 hstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); + [5 D1 X0 |! n4 u9 h
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
5 o7 s; Z8 c& A: Wstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
3 u$ s: a/ N6 ?0 wstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
2 W* _7 e- t0 ]8 u0 ~) t: ?; E1 G- l& Y1 H : z2 `% s! @- [9 w% v
static unsigned char 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
/ ^% d* |) H' b+ G}; {4 [: d2 P" | L1 m5 y; d
" v% N K" |$ L$ T. K& P( Y, h0 x& ?' }/* F, G, H and I are basic MD5 functions. */
3 m4 k+ F8 H% b8 }$ t#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 3 Y5 N2 |' e: k2 @1 x8 N6 S
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 0 z9 W+ ^, Q% a4 N$ t
#define H(x, y, z) ((x) ^ (y) ^ (z)) 4 t- @4 ?: Y/ H) L; G
#define I(x, y, z) ((y) ^ ((x) | (~z))) ) z7 n) x+ y$ y, Q
5 x& l' c5 \; x" _3 t$ \# u/* ROTATE_LEFT rotates x left n bits. */ * I5 V( E& K+ K. a$ K5 @
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) |3 O* [5 ?( e8 B3 d. t7 M
3 l3 n: S; H! W; K+ ]/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
# r* V) [4 m. z, B$ DRotation is separate from addition to prevent recomputation. */
* Y. O3 ]! z0 O#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
) ^+ k- a- y9 E& `#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 5 k( i' K6 X6 G! G8 I6 J: A
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 7 \ t! A( j, W! C( I& I) S3 [' j
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } * `2 {) c. p" z- l5 i) v
3 u- `. C4 |' ~/ j# A, O5 _+ G
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 3 O/ z2 p# K# c2 ?
void MD5Init (context) , ~3 @. x' P) x. o1 v& y) x" W
MD5_CTX *context; /* context */ ; ^3 X9 `1 J _# K, t2 [
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ; W5 A/ m* i" F5 G% W4 {: E! g+ }
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; - E, d! w. q: b. M
}
: L% t, [! G6 f: N4 ^) o5 G+ @$ h 2 X* c8 R7 x [0 x1 @( Y
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 7 G# l$ n+ G$ _ G% T
void MD5Update (context, input, inputLen)
) f" u7 }9 E" C jMD5_CTX *context; /* context */ / J% B2 a" c, M- m
unsigned char *input; /* input block */ 9 S* v. M0 d+ N+ R
unsigned int inputLen; /* length of input block */
7 y- W! h0 e/ Q. k$ Y$ s{ unsigned int i, index, partLen; ) L i5 S9 f2 _1 I$ D
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
' `! H& P8 M4 L& |- I /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|