|
|
#include "global.h" + m7 p, l3 {( A" E! ^3 I; i$ l* L
#include "md5.h" 5 }1 m3 L! k* x' ^$ B* o
0 t% k) c6 U) k% a% ?4 T
/* Constants for MD5Transform routine. */ ( a" ]8 p* j& }
! a/ X3 T0 ?5 a7 [" ?# F8 z2 d) D
0 v: b1 u' t: P8 b3 h0 _( R#define S11 7
0 U/ G7 `% F% T) }#define S12 12 I" T* `( M/ L- ?8 V* j) p$ \$ A
#define S13 17
& g4 R# w: z( M! b2 ^#define S14 22 / C, F7 C0 C; L* z0 v# m
#define S21 5
3 m4 o; X& w. Q) I* w& X1 Y* w$ G#define S22 9 ) I& O8 ~0 _. U M. F0 X- l; T- O0 g
#define S23 14 * p1 f5 P6 o5 S! ]
#define S24 20
, a/ {7 I& g7 i5 e* l#define S31 4 # `, u( |. n7 |: `, ]. [3 i
#define S32 11
' R: q6 s4 c7 M0 x( f, V#define S33 16 - Q4 {* p, y/ e8 k8 J
#define S34 23
% b) |& T2 u4 k% [1 F/ Y) T; Q#define S41 6
) {: D+ }" O* V! [#define S42 10
! j( E9 x; P9 Z( ~% R% c6 a% e#define S43 15 3 k/ c! E% ^( F
#define S44 21
; s4 Q6 N- f0 M& }( z5 Y, O
$ U ^% R% A( q! U- I' [0 m- Jstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); : @* `! ^8 L) i' `& u1 j
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); % _2 m- }6 u1 D
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
/ o/ O/ R q$ {: L! f8 X) sstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
, a" M% D, v! T( U( ~; pstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); - ^/ e4 G7 k( G
. o, K6 j% U* }: u4 j" W# d2 s! 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
; Z( w O8 f* f3 ]}; 9 {4 A# t8 Y& w. c. _2 I/ p
5 _$ M% z9 k8 n* D/* F, G, H and I are basic MD5 functions. */
, w/ b6 d2 C& N7 S4 \' H; ?! v#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 2 {& v. Y: y8 W1 ^
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+ a1 G+ [* B) G#define H(x, y, z) ((x) ^ (y) ^ (z))
0 E- f: f8 g) [) K4 X( P- T6 r#define I(x, y, z) ((y) ^ ((x) | (~z)))
2 ~. k2 T5 w% U/ {: S 2 T+ S; O0 s" c& [4 j/ I
/* ROTATE_LEFT rotates x left n bits. */ ; O7 P' V6 D1 e/ ]" D1 a
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
; W# D- x& `+ r0 I 7 B8 p+ Y3 n5 V9 M W! \2 C
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
; f3 D, x/ i1 W! b6 URotation is separate from addition to prevent recomputation. */
/ k, |9 v( u7 e6 v. p#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 3 f- N0 O3 y' d2 f/ A; s
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
l2 C3 R B% M8 B, _! ^#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 0 z2 l' I8 V6 B* l3 v+ K
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 5 R- u* I, c' X8 \
( Z" M0 p# U! ]3 r& |0 W4 i' K* v
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ U4 e& h8 A5 ~ R
void MD5Init (context) ' s' } t6 D1 @3 [) r9 y2 q* N
MD5_CTX *context; /* context */
9 ] n" U) C# ]{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 0 n. E9 Y& A& e) Y
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 1 @8 G0 m% a6 e o; ?, H
} 6 C6 N6 G; ^5 u
# f0 O; e' c. q8 P
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
5 Q$ X2 L% T$ N; b# C- g) D( t4 f; Vvoid MD5Update (context, input, inputLen) " o a" a$ Y# ]
MD5_CTX *context; /* context */
% ^' c, V y+ o4 ] X0 f" Z2 Iunsigned char *input; /* input block */ * `( {& B" H. A( i p; f9 D
unsigned int inputLen; /* length of input block */ , `1 V% x& ^: b) m( h& L+ L' \
{ unsigned int i, index, partLen;
9 G% B9 ?0 _* k; k /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); $ b/ S' F% M& t
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|