|
|
#include "global.h"
8 y- ^7 g5 c# e$ t% Z7 X; [* Q#include "md5.h"
6 C4 K% k0 Q( d3 Y b& F+ `# {% L3 x! P( V. x% ?$ S
/* Constants for MD5Transform routine. */
4 _+ y" [9 g7 s1 P. r
& p' G% N) K5 u3 e- Q
7 }1 {; `: X: {# s; k#define S11 7
6 g3 O6 F& i+ _- N- ]- I6 q#define S12 12 / K" I' B2 Y1 V; r
#define S13 17
/ z8 v) k- S+ p6 R4 u8 r#define S14 22
3 x. T" N2 g. B+ e#define S21 5
3 f5 H; y: k, u#define S22 9 , h" P- |4 g3 |( Y; N
#define S23 14 7 K) L6 O- f3 o1 E. _0 f
#define S24 20 * w( l5 z2 J, `0 \0 N! p
#define S31 4
$ d! X+ Z; f4 U1 [#define S32 11 9 X( c6 E4 Z, E6 a
#define S33 16
& m' r( |7 g; a8 R#define S34 23
" j) S0 D( b% \7 B#define S41 6 , R) l8 F# R/ b- X0 Y- e/ D
#define S42 10 * f7 O" h- m$ K& R
#define S43 15
& r2 B! A `# F7 u/ ?/ `: [#define S44 21 6 G4 b1 \4 K# a" t. a/ D' N
7 T$ ~, C3 r, r1 R$ `% astatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 5 U0 j/ Z# j- f' ^4 P. Z2 k
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
% ]( a) `4 ?& N. b* kstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ' T( O. A5 c/ f0 n6 W) K% n3 r
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); . {5 U: Q8 d% |! i
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
2 n3 W! Q( ^) w- D* L2 }$ Z1 c , f. U9 K8 a( `7 B, n
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 : n# e! Z, O, n6 Q B& e6 X
}; 8 L! w- L6 M5 {$ S) _# f% s8 U# }" l
+ r3 c; O" H9 c% ?6 G0 t1 c
/* F, G, H and I are basic MD5 functions. */ 0 L- b$ l* v+ s$ O( h% J4 x
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) - T- p/ P! e& k& ^" f
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
. ]/ Q" G2 k5 ~9 @ O$ J#define H(x, y, z) ((x) ^ (y) ^ (z))
/ S! }- d/ v; r" E1 s#define I(x, y, z) ((y) ^ ((x) | (~z)))
/ V! V7 {- t$ H$ i
J% o2 J) U% M4 G. ]- l/* ROTATE_LEFT rotates x left n bits. */
9 _+ C4 S/ v' h! n2 R* h#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
. B1 i: F3 l+ Y( D1 j) ]2 m 0 S( w1 S" D/ u! Q
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
8 w9 @8 d' T% j* u$ m; yRotation is separate from addition to prevent recomputation. */ 3 A" F! A# ~3 j/ X' u
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } $ F! H" ~ m5 ^
#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 |( c; n. ^+ g3 O#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } , X5 ^: C5 c, T6 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); \ }
$ V, T' @( \( d9 W5 P& d ! R( `- k* Q% A6 p8 e; D' ?
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
/ ~8 E' L9 W) t# q. Vvoid MD5Init (context)
9 m$ D) u& C) i6 {: dMD5_CTX *context; /* context */ ( n( k- C5 T' |/ r
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. . i) T0 {& k6 n
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
. B( B/ C8 N9 d/ N! I} * C* B: E1 z; k$ n6 y
8 V0 _, A( S, j/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
6 h2 @0 M# X3 {; W4 X+ qvoid MD5Update (context, input, inputLen)
0 k3 X0 h9 w+ J* A: u! h. [MD5_CTX *context; /* context */
0 y5 \. y: U" [6 [9 c% ]9 Dunsigned char *input; /* input block */ ; e8 b/ a& k$ P$ K8 e
unsigned int inputLen; /* length of input block */
d u- h; D5 u{ unsigned int i, index, partLen;
0 s* `( W5 b+ G$ @ /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); , @; a( Z& x2 W+ i
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|