|
|
#include "global.h" 7 H& v b+ @' d W, ~, z
#include "md5.h" ; e+ n7 ?4 J: d6 u* o J# \6 ?9 z7 S
7 G/ x/ n" z) r. w# i/* Constants for MD5Transform routine. */ ! a' z( ~ b, m1 w' |
. E9 B$ p. w/ u7 t
* Y, t7 H) H. e1 t7 H# B
#define S11 7
) W( @! t9 P! r% e#define S12 12
" j; Q9 Q( K* I5 `! ~#define S13 17
" L0 b2 a" C% k; L' z2 E& u. a#define S14 22
9 p/ k2 x' f) z/ _0 F#define S21 5
) K5 X% ~0 R* {2 T#define S22 9 , t( X) M3 n% Q" l$ a; D
#define S23 14
( E1 o1 {, t5 M1 k0 k- J#define S24 20
& _2 v8 t4 Z0 ?#define S31 4 ' e3 e, ^) q5 W
#define S32 11
; i5 R6 z4 q& b! W: P/ P#define S33 16 3 L, a, q6 M9 S" O
#define S34 23
2 C/ i, z7 J3 N3 H+ L) `#define S41 6 " t7 V0 i( g- c+ `# p, k" c
#define S42 10
% B$ V$ w. ~0 G- x#define S43 15 ( H4 p% A+ b! |
#define S44 21
. B3 T% i% h: v* D, V, m4 I
) W7 Z( ?. D) Pstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
4 J3 S( K/ v% c, x8 [$ bstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
1 [1 y) C* |) ]) xstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 2 p8 J& l1 H5 i _
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
- x" v2 T( ?% Y, N, I' |, y1 f/ Gstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
$ i8 [. e3 \* ^9 h* n
1 @# [3 `- C5 h# |+ bstatic 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
0 g1 n2 b, k3 o};
6 b0 N$ D$ a% q* J * X3 F) I) E4 F2 ?/ g
/* F, G, H and I are basic MD5 functions. */ . u: D! _' T; p& e
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
" D5 \# s. s1 Y2 P# W) R#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 5 t; s0 E. j) K0 a3 ^9 A9 c% E* s
#define H(x, y, z) ((x) ^ (y) ^ (z))
: _: Z* z0 f* k, |: p#define I(x, y, z) ((y) ^ ((x) | (~z))) # u4 {$ b- E7 t; ~ q6 w
3 p6 R! w3 s5 t" e( P
/* ROTATE_LEFT rotates x left n bits. */
9 ]! a9 f4 J/ {4 X( G#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
/ G3 r ^( m& F w" @9 y5 h5 W. |+ L2 O z& P1 ~, t
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
+ a3 M3 t( e* `4 K# H7 HRotation is separate from addition to prevent recomputation. */
, {2 B( [) U9 D#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
) t! G5 q6 n ]' e1 f#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 _9 b* ?& T* {' o9 _/ j/ g#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 5 b! S4 r! _% K, d& _/ H9 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); \ } , T" u& p( D- H- r
- ~, u4 N; X; [8 G% J3 c- p/* MD5 initialization. Begins an MD5 operation, writing a new context. */ # r d' Q5 m0 S; }0 W
void MD5Init (context) " _; F @; s& Y p* Q
MD5_CTX *context; /* context */
- |+ E$ |# z6 z6 n; X3 }{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ( O3 T; J0 W3 k( H1 v3 ^/ L/ p
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; ; m' s: F/ G+ R/ d! q: T$ h C
}
* x5 Q# D M; ~" t. p 1 q8 m5 u# S1 Q
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
& |- f5 b$ j, |4 t. Pvoid MD5Update (context, input, inputLen) 7 x, P3 }9 n% i7 R) q3 i" M6 F
MD5_CTX *context; /* context */ % t& U, j% q# Q* C/ x: L- }+ e
unsigned char *input; /* input block */ # O! @# `) L$ \
unsigned int inputLen; /* length of input block */ " m. A! t1 l# `
{ unsigned int i, index, partLen;
0 p+ w' j$ E, r+ v* L /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
% j7 \& p! z* H6 K /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|