|
|
#include "global.h"
' {1 X" C( B j) G* _5 K#include "md5.h"
$ D# B k* k/ i1 ?5 i N7 V& ]/ x
0 S, `$ ?* U( t* [/* Constants for MD5Transform routine. */ 9 g4 b% V4 I7 d8 i7 x
) E: Q% H( T2 L7 _
9 f# D, i: F% v. M#define S11 7 & ?& z4 A$ ~: |/ g/ }/ d5 Y
#define S12 12
3 F, Z1 A* ]8 ~# u' ?* E) u: B4 ], r#define S13 17
* L& p8 \" l, e2 D#define S14 22
( _' \6 V0 S) D6 U. b4 O#define S21 5
3 h; w; K7 ^2 S; M$ ^#define S22 9 0 W9 C7 J* z! w4 ~4 _; p; Q
#define S23 14 8 a0 Q9 O3 j$ N7 a$ ]
#define S24 20
# _1 Z- j7 u) [. l/ a+ ?#define S31 4
* I @; ~8 l1 L7 }: \#define S32 11 : ~$ w0 X; t! L% i- y2 u
#define S33 16 6 G: r" j# d" h1 D" W0 h
#define S34 23 ; x u8 ]7 L" X# p1 D5 J/ H
#define S41 6
) }( t/ d' ~* _1 T# c4 D ]( t#define S42 10 : `$ v( M3 w$ Q+ L, P/ r; {
#define S43 15 ) F; H: x2 i, N2 b
#define S44 21
' L: {) R' S% i8 P$ P 3 [/ u% s7 H8 a8 q8 [( i
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
2 `% d2 a& Y# r8 ~$ ~static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); + }' ~0 `0 r" p# S/ v) L# k, l
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ( ~4 f- T5 [; x6 {
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 7 b2 T, p# k4 |
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ( e/ d+ M% S% Q$ ]7 N3 ?
9 H( N1 a8 U; J9 i0 g
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 h7 \. N+ I* [8 @8 |" Z3 E n9 T* n
};
! I# P7 z9 W1 Z0 k1 i6 E* I7 a7 l
0 m/ u! I6 j. `3 c) T/* F, G, H and I are basic MD5 functions. */
0 B4 U2 v; Z8 g3 R#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
1 K1 W( J$ g. G1 N0 r1 I#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
2 i5 D' g, K- Q- s. t#define H(x, y, z) ((x) ^ (y) ^ (z))
( f, @! X: Y2 ?+ T4 a. E5 a) ?4 x#define I(x, y, z) ((y) ^ ((x) | (~z)))
6 x$ c& h" D. R5 Q( k" k 6 m7 G8 `' o) l8 _) e# i
/* ROTATE_LEFT rotates x left n bits. */
7 K# \- u$ h! C b#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+ y3 N [3 l, d" { ! l& m0 \# A- o- W* Q
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ; K! v- W8 C3 W$ y' _( m
Rotation is separate from addition to prevent recomputation. */
- P8 K3 D( s. A. I5 Q# L#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } . N5 J' g. q+ Q( D
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& u. z2 w; I, J8 i- \, k2 ^9 \" X#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
) X. Q! j& m, i# m) s#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 Z$ o1 s4 G5 k" C8 I+ C u 2 r1 V# L' z8 P" G1 k9 s
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ! q+ w( V. `2 d- }4 [% P
void MD5Init (context)
1 q$ |; b" L, Q4 T$ I- w- xMD5_CTX *context; /* context */
& c3 r$ E0 D/ k' Z{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 3 x3 m2 P: Z A. n3 f9 |2 O
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; & V5 {8 c" c. f( U" z, j
} 2 B k: c) D, L0 {0 a# K0 \* [$ G
, i1 e }, @1 d/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 2 \9 q; f0 Z5 H
void MD5Update (context, input, inputLen) g. c! K- Q3 o( U5 c) A0 p
MD5_CTX *context; /* context */ & v1 M p/ V' e( L" V+ F& W
unsigned char *input; /* input block */
+ ^/ i" k9 l5 Xunsigned int inputLen; /* length of input block */
5 S! ?4 E2 q6 V6 r$ R2 R( m{ unsigned int i, index, partLen; : ~5 D8 y% I6 m" v& q
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
; L9 l- g, W4 E /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|