|
|
#include "global.h" 2 r: l. p3 ~% l: C
#include "md5.h" 5 A `3 s6 J- T: r# y" P/ Q
; H! p% H8 L1 O: H9 a' K5 l* g
/* Constants for MD5Transform routine. */ ' ^8 u7 l; Y3 W% c6 _3 e! a
" U; E0 ?% l/ O% ^/ |
1 k; o/ r9 W/ t. `, X' L
#define S11 7 9 V0 ~* L& Y4 w' ~0 r5 e j
#define S12 12
& h+ p# \* E- p" u#define S13 17 T# n! Z" d/ n4 q5 O. z# L2 X$ K
#define S14 22
# V. S' u, @; f9 z: Y8 T R#define S21 5
+ y' B0 h" P0 X& ?#define S22 9 , M- t- p$ c; T ?! X
#define S23 14 9 ^; N" O4 F; r
#define S24 20
/ ?4 q* N$ i) M" n& J) N#define S31 4 ( }% H/ g( E/ a) N
#define S32 11 / b7 N5 e( ?; e$ w0 C
#define S33 16
5 Q* F" @2 K/ G6 `#define S34 23 8 y+ a) v- q5 \( h m
#define S41 6 1 t- v; Q4 P( Q6 X' i* [
#define S42 10 , I6 R7 u' D" x. V' F6 h8 P8 `4 S2 @
#define S43 15
2 I' d1 L C8 \4 _3 O#define S44 21
4 a7 z9 Q1 ^2 [( Q$ o
) i4 v2 q3 E8 _ N+ C1 J1 U! Istatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
1 ]. @, C) n0 T. v6 i# hstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); & G: h6 S- s3 ]2 I8 r
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
- {! K3 g, l% u. A9 fstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
d7 R9 o. C5 @ K8 R1 C* z9 fstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
; R' ~; a; X5 j* e" l+ j 3 b1 H; k6 X1 s' K
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 6 s: t a# A7 u U: @. {
}; , K& s8 N, I0 i9 Z/ m% O
8 r' G) P0 \/ l- I: E& i' j+ d4 P/* F, G, H and I are basic MD5 functions. */ 5 q( I2 n( k+ ]" y/ ~
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 7 \( `2 B* y7 n0 G6 O9 I" W3 ~
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) - G6 e) W2 O/ r: D4 o& H) T# `
#define H(x, y, z) ((x) ^ (y) ^ (z)) 3 Q1 l9 W2 x8 L0 b" S7 s5 t
#define I(x, y, z) ((y) ^ ((x) | (~z))) : K1 `. v' G( W/ O, @2 Z* ]
0 @) n7 A% M1 V2 l' h
/* ROTATE_LEFT rotates x left n bits. */
8 q' @% B3 n' N$ l% n# P#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) * ` u) v F( a0 [
! Y) `/ `- x) f
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. + H4 u: X' w2 d6 x2 t# Q; L9 z7 q
Rotation is separate from addition to prevent recomputation. */
! H( S2 h. {! [& 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); \ }
4 q3 O( g, i9 g" d! q0 |( l- M#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
9 U8 A z* d" T+ s5 e, _% ^2 S1 M#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } : p( v; {( X6 s3 J3 ~+ f
#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/ e9 S
+ c5 q& _4 D, Y: c* D+ Y3 o/* MD5 initialization. Begins an MD5 operation, writing a new context. */
2 S0 V# W$ D% j% E! ?# xvoid MD5Init (context) 3 D5 N4 X' O, p( E: a; Q
MD5_CTX *context; /* context */ * }6 Z6 g. E4 [; d. P, Z
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
% O' d! o- b- ^. [5 b$ j*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 0 T8 g: X7 J+ f, |# Q
}
9 v) V9 V- |: p1 ~& S& Z9 }4 |! @
7 ^" y9 l2 q; H0 Y/ `/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 4 P, W( H1 o2 R c: T
void MD5Update (context, input, inputLen) ' D! E1 P& T. U- g! p4 N9 V
MD5_CTX *context; /* context */
. n) q1 p' ]( `# B2 M) \unsigned char *input; /* input block */
4 x, \9 @6 p7 ?# q5 o1 {unsigned int inputLen; /* length of input block */
6 T! x* F$ s& c9 c( m{ unsigned int i, index, partLen;
) `+ z8 x9 V2 ]' }- e# _ /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
1 \9 |, f& N1 G% U /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|