|
|
#include "global.h" ( Y# q8 B9 t! w+ |$ o1 U y R
#include "md5.h"
O9 F H' h: e5 m' x: E+ i; \ ; T5 m+ m. ^5 m* W+ W& E1 z
/* Constants for MD5Transform routine. */
' L/ K3 r. ]4 c2 m1 }; U9 ?) k
" D* g# \5 ]5 B* g) g
: ]# o" c0 Y3 y6 N#define S11 7 : ~" ]& Y6 H; d
#define S12 12 , t( q% E# r1 t2 b+ Z# E+ f8 [- P
#define S13 17
1 g' \" z o3 `- f2 j) C#define S14 22 5 U: r: \) W& q# F* [4 w7 A
#define S21 5 " J" G/ d: P1 } o/ I+ p
#define S22 9
5 k/ {/ }" f9 p#define S23 14 / [# O8 P& N( s: }3 J; q
#define S24 20 + P w! \" v. D
#define S31 4 5 @0 Y+ _7 Y. [; M* [% Q
#define S32 11
: B7 M% e, ~" m2 p, N#define S33 16 1 b5 M- P: d4 I6 k& M$ v
#define S34 23 5 T! m! e6 U" e+ U" e) \3 |
#define S41 6
* p, o+ a* z" @1 Z9 V#define S42 10
# d2 O" y, d1 T6 m, {0 i, }# `! a#define S43 15
' D9 {! D/ y5 H' S, G, I#define S44 21 ' k. {/ X2 h3 c: A% f! S
8 W" v* c h: P
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
8 K/ C Y5 a4 G! b+ z: a+ |3 Wstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 0 g: _: x! c/ N7 @& j: ^
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
8 y1 i* F/ C1 B) x7 qstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
3 G, Q- r" F4 h7 g4 Wstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ; M3 D* m+ w2 \$ _
. J( M1 x" i5 O: C( nstatic 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 & T" @3 Z, z9 c$ T* _
};
; t9 W* Y2 \" q# h+ ? $ ?+ t' _7 g. X- T
/* F, G, H and I are basic MD5 functions. */
" s, `; m8 k7 [- m, S#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
& x) k& D% J& i" U4 \. v#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) * e# L% K! q. w+ ~( ?
#define H(x, y, z) ((x) ^ (y) ^ (z))
( O/ L. R" R9 q+ z0 J% f#define I(x, y, z) ((y) ^ ((x) | (~z)))
1 z- H. z- G: z( }; P. |
* ~% L* _) `' [! n4 r/* ROTATE_LEFT rotates x left n bits. */ 4 C" Y! _7 z. Q& l
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ) m1 E( \. i. U5 ?+ F X# d
: Z" i; n; h. o8 A
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
$ `1 e, x6 b* R& N/ \6 [# d2 a8 x# ^Rotation is separate from addition to prevent recomputation. */
' t* a) h7 _% q6 v4 ?#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ) `+ J* i5 f: }2 ^- H
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
, o, P# h, I3 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); \ }
1 k: O5 C! t; r$ |' _#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } & r- w9 l) |0 c( }
+ M+ @! p; }: a7 A8 c$ ]' ]4 y; ?/* MD5 initialization. Begins an MD5 operation, writing a new context. */
l9 X2 D" j: _! U a$ L. N% E1 Zvoid MD5Init (context) 0 {, K8 ?/ E6 ^: o
MD5_CTX *context; /* context */ ) _. A" b5 |( [. e4 F! o
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 8 J' U; p7 H) y' b
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; ) T* v, [& R. M% j- i2 g
} + H; b7 ~1 A$ x3 H
: T! I5 o2 L$ E- X
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
1 N8 l- _, s; M1 ^0 nvoid MD5Update (context, input, inputLen) 7 g2 N7 D1 J) f |' i- v' V
MD5_CTX *context; /* context */
5 v# p! {# V$ c) X. Z/ ?; S" X* kunsigned char *input; /* input block */
- @% o6 F& c# j% Q" qunsigned int inputLen; /* length of input block */
$ a+ q0 @- P8 v: V9 Y& L3 ^& U% Y6 _{ unsigned int i, index, partLen;
3 f0 {( L) h# p. R( i1 e5 ` /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); $ Y* [* o6 f( U1 ?# u
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|