|
|
#include "global.h" 7 J/ z/ x9 F3 b" ^; t' S) J
#include "md5.h"
* o! r# F/ m/ S, q: H$ F2 ?
7 ^" }7 R! Z7 `/* Constants for MD5Transform routine. */
8 R! Q. J; R& p
' Z& k9 o' J1 v, V9 b! w/ ] . M* X! b/ Q0 }1 s3 [$ }2 |; x2 E
#define S11 7 2 V; {) G# G4 T/ [4 ~& Q
#define S12 12 0 B! ]0 @" i3 \9 p+ a7 q! e* }
#define S13 17 4 s) Y' H9 p4 l5 K7 X" p
#define S14 22 1 t0 F6 Y9 ~* N/ b) ]
#define S21 5
& x* f9 t0 A3 I6 G' X#define S22 9 ; `" _4 `2 W4 U/ v
#define S23 14 % U* ?$ w' N4 f( g
#define S24 20 # R2 p$ v. ^; \# f
#define S31 4
$ Q8 z0 H3 t/ X# B" h#define S32 11 9 l0 N: G F# N0 t! S4 |8 A5 Z8 y
#define S33 16 9 w/ U% ~: p6 B9 }8 E# T& ]7 g
#define S34 23 1 [3 \, o( B) \9 e
#define S41 6 % w" b2 X9 R; B
#define S42 10
, G" L/ X u4 j6 m% P#define S43 15 4 `* V5 |# \8 v l
#define S44 21
+ {' E5 _- X( A7 k; X
) [6 `! Z5 l) w4 K+ Vstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); ( L3 G( \! q J" j& ]1 Q c
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
2 }- {' F/ I& k0 F: n2 I( istatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
9 ^/ x4 E f, S, g5 b$ ?static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); / t1 _" f: {) n" ]; \
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
6 L/ t b8 w2 x* g& T4 }
- h8 q, t; X% h7 H9 _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 & R" {; D2 s' q6 l& Q7 e) @
};
( R0 i; A6 W% M: f$ } L% y9 k
+ i& m' A. w' F) q( F9 Q/* F, G, H and I are basic MD5 functions. */ ) i+ w: k3 ~8 B6 v$ G
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ( [- z! z( J, X h
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
3 W$ C# l, `3 e( e% ^& O( i+ Z#define H(x, y, z) ((x) ^ (y) ^ (z)) ( i! |5 _. Z5 R& d
#define I(x, y, z) ((y) ^ ((x) | (~z)))
1 ?$ t- E% S2 ]: C. p' f
^* x. p; t, `2 T/* ROTATE_LEFT rotates x left n bits. */
$ }6 _5 k# H6 K! S9 d1 z#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 9 |4 r/ J1 V7 x; Z, b
$ r `+ w/ M, [' l; n# s4 p/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
$ c5 _& G. W* X0 v ~- o' LRotation is separate from addition to prevent recomputation. */
1 O0 v2 r q8 m( F! 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); \ } 2 H- k! t8 c/ r# |8 b4 [
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 4 a1 `5 `5 I. g- r- s* t- p) m# B8 N
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } - A4 y5 ^) C# z( `" T- U
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
$ G& q/ V" J. l5 r: p8 H 3 a" A1 @0 n. ^- }
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
2 j c! L' l z- V4 {5 y8 _! b; Dvoid MD5Init (context) - J# G$ C: h! V& _: }
MD5_CTX *context; /* context */ - A" O; _( s& w4 L; Z b7 I) E% Q
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
# a" ~8 h# c3 J. i3 J @*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
7 r, W; B7 Z N+ T- S: ~* j}
2 y& a3 v5 G j, B+ |- T
* {- n1 ^) v& k/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
! c9 ~7 ]: X: j0 S$ Ivoid MD5Update (context, input, inputLen)
v6 [+ ?4 X) QMD5_CTX *context; /* context */ 3 K$ T4 _ L7 h* o8 B, V% K
unsigned char *input; /* input block */ 8 |/ q6 @, X7 J) R
unsigned int inputLen; /* length of input block */ : r6 @/ I0 F8 W$ q* r F
{ unsigned int i, index, partLen; 0 J2 y8 B4 l7 p; L |2 [
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
: ?# e4 @* G. H /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|