|
|
#include "global.h" . _+ q1 d# {2 j2 v$ E: `4 N
#include "md5.h" 1 v3 Q2 r# p' S1 M2 B3 U
+ ~: w( E# H4 }6 ?
/* Constants for MD5Transform routine. */ 9 n- h7 X' v( H0 r
. F1 i1 T9 W7 X5 D, `% J' u4 n
/ `+ ?: ?% b3 K6 h+ K#define S11 7
5 @4 G) l: i ]7 i#define S12 12
- }# ~8 v X6 B#define S13 17 * j6 H' B# i) X! x
#define S14 22 % |# r2 q3 P4 }$ n
#define S21 5 2 H1 q/ K6 t( z5 k! E3 P4 ^2 o6 }% z0 e$ B
#define S22 9
. X/ T4 Q/ \' D- r. O& E#define S23 14 8 P$ R" G: Z+ \' g) P) C) ]2 r8 }
#define S24 20
4 ~4 y% `8 r; {1 n#define S31 4 7 u) h# u( j x8 T4 I' L1 T5 H
#define S32 11 & o9 }. u6 {* W) E
#define S33 16 / e5 \0 E( V6 H
#define S34 23 7 b6 ^, |, G0 p j
#define S41 6
' A# G! B" i9 t: \& e#define S42 10
- ^2 t1 N% p4 w: S V& b7 R. y% M#define S43 15
0 p U, G5 ?. `7 @#define S44 21
! L: H* M3 ~" [) w8 W7 R
" m! y8 M) o2 B. M! Xstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
7 T. w! p8 e( J. B$ v/ C" estatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ( D( Q$ J( G' `$ b
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
6 H" S+ B) P& N- Fstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
, ^ j0 \. S7 N/ B. G7 T3 w0 hstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
9 v+ x! g) T2 S4 \/ k. J
+ @$ Q9 E o) L: b- k& Ustatic 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 / K4 ^1 X8 \/ \+ {, l8 k4 w7 f( G
};
* V6 q) ^; y$ j. c) Z# ` 2 O0 O+ s0 t" U! \/ h
/* F, G, H and I are basic MD5 functions. */ 5 P/ T- w/ g1 V
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
" {- z; G: h3 Q+ `#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
( ?4 {: Z' O T0 Z( i#define H(x, y, z) ((x) ^ (y) ^ (z)) / X; D! Y' B' F$ i5 w
#define I(x, y, z) ((y) ^ ((x) | (~z)))
: i- w4 d$ X; R# {$ c6 [5 u % z7 t7 D" _" K3 q9 u, d! r
/* ROTATE_LEFT rotates x left n bits. */
; _6 t- V# q% }#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
# B$ R4 y1 c9 N6 A5 u0 i
& A* r: @% t# {# _/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
: U- J6 N9 b! A7 o2 }Rotation is separate from addition to prevent recomputation. */
6 z6 ^% k# K) F! I" C' h#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ d# D7 G0 Q9 { Y9 J- Y1 d#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
7 d, E6 A8 R) K5 {- x#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
2 o. D: B$ `5 f- R0 N#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
! e$ K& I& |! Z) D: `# q" D
! h* Q* S. _8 q: Z$ m9 e1 S/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 3 [3 |, a5 b+ T; B' }5 M
void MD5Init (context)
! T; V; G! ?* |2 Y# MMD5_CTX *context; /* context */
: s% }( v$ m' P, |2 E{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 6 k: Q6 v" N3 Z
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 5 ]- k' K) W0 ?4 `
}
( d/ r, U+ o B3 C9 F0 r4 L. s; O& b $ S V+ l' f* U3 b7 I% i6 K0 R
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
, f4 ]3 m1 E1 w1 u' x. mvoid MD5Update (context, input, inputLen)
& v- I. ]6 g1 KMD5_CTX *context; /* context */ ! O$ J3 { W! k$ n" t' r& w
unsigned char *input; /* input block */ ; H Z0 X2 P$ o8 [2 A. K
unsigned int inputLen; /* length of input block */
- C; r. [$ J1 q4 o{ unsigned int i, index, partLen; / K( |* H' p8 ^6 r! i% [4 r
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 3 \. y, g! N) q. M) l$ N
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|