|
|
#include "global.h" ' `# k" U3 n7 z2 Z+ R. y
#include "md5.h" % `: a- P" w. C ?! ]
. w4 @/ f( A9 z& C/* Constants for MD5Transform routine. */ ) e1 [7 K! l; f/ j
4 a# [- d% F1 y: L
& l: t9 y1 L9 `#define S11 7
# Z/ l( c f# _" G6 b, c#define S12 12 : v4 ], v) V7 h7 S, d
#define S13 17 ; D, F# |: C$ [; k \( j
#define S14 22
6 y' L1 U. X3 Q- F! I#define S21 5 0 q, i6 o/ ^- f9 p8 q2 t2 q5 l
#define S22 9
4 T8 J% S0 Q. o% G( b#define S23 14
6 U1 F' t3 `- s, }1 a2 A8 k#define S24 20
1 d$ E) A! L% J7 `- j L#define S31 4 7 X0 ^; S% q, e
#define S32 11
2 _# D8 Q( n* z#define S33 16
' e+ u6 X j- X1 u$ W) s8 A' S#define S34 23 2 Q' h& ^* N0 E3 L6 `/ j
#define S41 6
# g3 C( G5 t9 Y0 a#define S42 10 & e6 a* x/ b. D
#define S43 15
# v* N% }9 z; k6 m" {& l# Z* V8 w2 f#define S44 21
# H- Q! @8 }- V3 M 1 P: t" g) Z1 z% ?3 m/ f
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
: Q. n( c3 K; M9 zstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
! ?" d1 l) j" z7 \% f. Qstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
( m6 W5 @% Z/ ^. j8 R3 A8 Y1 ~static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
2 F& q: w( u; s; cstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 8 T; I5 F3 T7 }: g; q
- D: z4 i2 w8 I: W
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
- e7 _: o& H) W6 t) ^& w% M+ t}; 5 |3 h5 A5 h7 t) T$ Y7 l9 z
" |$ n8 n v- F T
/* F, G, H and I are basic MD5 functions. */
: V" h; K1 f8 D& m$ U#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
/ D" \' r, l4 v#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+ {* P7 `1 G' O#define H(x, y, z) ((x) ^ (y) ^ (z)) 5 Z% O2 Q! l% c$ F, z4 _/ B5 Z
#define I(x, y, z) ((y) ^ ((x) | (~z))) 3 ^9 ^4 A; Z1 C
2 E+ D/ L, _, s/* ROTATE_LEFT rotates x left n bits. */
. _+ M. g. S5 G0 K#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
' d1 f/ I6 x' w {$ `7 y$ L% C" g7 j 1 w; y$ R; n# f4 C" m* m! @/ [# F1 K
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. F4 {/ q/ z) k0 ~2 n% q; A
Rotation is separate from addition to prevent recomputation. */ 1 l' [" r; e3 ]" I) @4 T2 V: d5 U% C
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
! N. } O0 `9 F( R#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
2 m+ y. t8 K! n3 R#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } $ c' B/ G) N! ^5 q: D1 y
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
* A. D, T; k+ q, d( Q' f- s1 |, C , h$ m1 W* E9 z3 P/ e1 S
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 6 d/ R: L5 I+ `4 X: C
void MD5Init (context)
# M' B9 H F% w1 x$ P- }MD5_CTX *context; /* context */ " Q" w8 X& y5 B# O: p+ H8 g# }
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 6 i9 X8 [0 _6 m; T( |. R
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; * B% Q$ @2 J4 l- w) `
}
# O6 ?- u! h# n 0 {3 n$ \$ j: o& e
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
6 l0 K- {' p* h0 G) x, ~void MD5Update (context, input, inputLen)
! L' U" B0 F: c j. L. zMD5_CTX *context; /* context */
J1 P5 n4 Y, u5 y$ f r+ S7 [% cunsigned char *input; /* input block */
2 c# {- ~7 r9 a& }; k f0 x# vunsigned int inputLen; /* length of input block */ 0 n+ @# K- s" i2 C3 }
{ unsigned int i, index, partLen; 8 l5 R$ T1 E) |/ ]* |
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
! d# p6 C, u, f) ]+ D /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|