|
#include "global.h" 3 E, Y0 d& s( v9 G z8 F; W8 d
#include "md5.h" 5 ^- a* Z! X7 ?$ j; V
1 w; {: i0 O( G/ O' q8 N/* Constants for MD5Transform routine. */ 0 J* F: L- g- g' W7 e6 Q& _
* q0 [' l6 ^. R. x" K L& b
9 [0 f9 l/ c2 y+ b5 `#define S11 7 & p- L3 u5 _$ h& p4 Y# y
#define S12 12
, u" O4 }* i2 x4 P4 g; h% F#define S13 17
; I/ Y' ~& b# U$ V+ |$ v#define S14 22
2 P2 L# o- L% U. l- ]4 M- p#define S21 5
4 C/ X! m6 ]; a( c- J: K$ H& {#define S22 9
: \# _7 r. A. d% }0 }#define S23 14
: L0 n( }* ^2 b#define S24 20
8 I; P" E9 u8 s8 i' ^9 `) }#define S31 4 8 m+ u# h3 _) S& |% o3 V5 C
#define S32 11 ! i/ k8 `' n- T0 |
#define S33 16 3 ^# p% `: c# v4 p6 G& e
#define S34 23 ! W2 j/ h2 j( E4 i- G, w5 a8 Z0 v
#define S41 6 ! m3 a/ Z5 D I0 Z5 m! c( ]/ d
#define S42 10 ( f/ ?- y2 i- Y2 }; y
#define S43 15
, Q ^9 C1 J- e3 ^* n( U# A#define S44 21 9 e6 D) a+ R/ }5 \; V; O( w
6 y. g1 m$ S+ V4 z: k5 H
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
" T1 D0 ~3 @/ N& H! Astatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
8 @- c, [( V, ^$ m9 X3 f% _static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
m* a$ N/ H0 f' n! Q6 pstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
& m, W' Q! W& M; Tstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); - S& r& P6 ~. |9 S0 R
0 C6 g7 X$ ?* m: z7 T5 {
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
- V+ Y) j& H* z+ P4 F% u% _. G}; ; t7 |, R- Z. @- R
4 w) U4 M$ @6 Q7 F/ F" B/* F, G, H and I are basic MD5 functions. */
7 H! ^. l2 Q1 o* e3 f#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) , ^5 A3 U [% e3 V6 m4 L9 c8 I0 P/ v
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
' @; v( `0 ?5 O) m: b$ l5 @% M8 g#define H(x, y, z) ((x) ^ (y) ^ (z)) 4 i- |3 L0 M/ a6 ~
#define I(x, y, z) ((y) ^ ((x) | (~z))) S& ] {" F/ F
1 G& [2 E4 h/ R7 z, V/ R6 t/ t/* ROTATE_LEFT rotates x left n bits. */ 5 R& Q9 \! B" m) J/ \) y
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) u& E- v b+ n2 y( r( X
5 y X# c# f6 R% p7 v/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. . P! k: D% p% F8 [0 Z! O* j
Rotation is separate from addition to prevent recomputation. */ $ v8 V$ P F0 u6 h+ 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); \ } 5 h8 {8 H; J: Y: X2 e$ W% A
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } , h' G0 x# y/ }# `' B- ~4 P# @
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ {/ L' A2 X$ W( J1 ^#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
# ~! q9 b: a5 y / M1 O* C) i3 Z0 V
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ , L; H( K3 [' @/ d5 V) M( ]" @+ p
void MD5Init (context)
& Z! Q5 N: q; w$ o* O8 @MD5_CTX *context; /* context */ * h8 u% u& }- M- B5 L! y/ C& `! E2 b
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
. U! ~! ?" V% J9 O. B. D: k! P8 s3 M*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
+ `6 B) ?7 K+ G. C8 m" j, Z! T& E}
% X6 R/ \) b* H3 S
( r0 N* O# V6 l+ F/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
. y2 @4 e/ M6 C- V) l8 ovoid MD5Update (context, input, inputLen) ( r, k2 {% a& A1 y3 `
MD5_CTX *context; /* context */ 3 t, q* M5 a$ j6 ^) Q) ^% S
unsigned char *input; /* input block */ + |/ T3 a) ?7 X6 C0 M
unsigned int inputLen; /* length of input block */
2 v1 ]- P- E1 L5 U{ unsigned int i, index, partLen; 3 a2 I2 @ M( U
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 1 f3 w. t* | x8 M9 W: X7 i
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|