|
#include "global.h" . |. B; C* O4 {( a; C4 d
#include "md5.h" 8 J/ p! u' h& R) V: s' [( e4 x
0 R5 c% g' W6 @9 p4 w( t% M0 r/ Q/* Constants for MD5Transform routine. */
* g" a) d* H1 r, [4 Z, N# Q7 y
( {9 I1 O/ F. x7 [% _ - t* [- B0 p3 r2 Y
#define S11 7
+ i6 b8 s8 n' k7 W$ W$ k7 H#define S12 12
" c) I& i- b; d% A* o. F0 s#define S13 17 2 K1 e& Q) Y& _+ U: x- s
#define S14 22 6 n) A( t/ H6 E; {4 |5 ]
#define S21 5
! ?, E. O' t' ~9 z* F# b#define S22 9
) Q5 V. l. _. d& j0 f7 \#define S23 14
) [- c3 D# R1 k) f#define S24 20 ' A1 [! M2 U8 l) D J/ D
#define S31 4 ) i/ g" C6 H' E) A
#define S32 11 6 X1 M: U) _* l0 j
#define S33 16 : V$ _2 F7 J* g
#define S34 23 7 _( e/ d. I* m2 `! u
#define S41 6
* T6 m; o- r2 ?6 W( i0 X" `' l: t#define S42 10 7 P6 Y3 y3 O3 a. V/ @
#define S43 15 8 C( ~3 X5 z( C9 I# V* |4 a1 ?8 x( {
#define S44 21
: `' s, @% c6 {: z
* F- r' A, ~. k C/ ]1 S0 ?static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
. S) ?5 k" @. j O3 s! r' ^static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
" f; u+ P- J& \0 z3 u- ]) C1 q. ^static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 5 R% f) e( V& U5 } k) }3 j8 f
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
& H' {: {+ t9 L1 e+ b) b' N: qstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ! i: O/ V. m1 U G6 g
1 P. O6 a( Z6 v4 I2 l9 Sstatic 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
7 T! V' `- I# [};
# R1 c4 f; r' n& f! S& U1 \! M
; n. V9 A5 [) j: v: y/* F, G, H and I are basic MD5 functions. */ 9 C1 s( N/ K' m! T
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 7 x0 v, T2 i2 Q5 |, ~, {9 I
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) ( G. Z# c# K; K) N
#define H(x, y, z) ((x) ^ (y) ^ (z))
1 F: x# [, w1 _' z4 I5 @#define I(x, y, z) ((y) ^ ((x) | (~z)))
; }' [; [! e$ p) Y, v& n( o$ O7 M 7 |4 {9 t: U7 G& ~# a
/* ROTATE_LEFT rotates x left n bits. */
9 Z- ? l' D. P- d% d5 f$ b2 {#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
6 `# s! x& w- e. h% X
2 T2 G" _/ I5 u0 {" q6 C/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 2 h+ j# }/ E) e4 c h( y! C# f
Rotation is separate from addition to prevent recomputation. */
; M& v4 u- o6 p: ^, \- K0 i#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 w7 F+ C1 r' F/ G7 O1 O$ 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); \ } : v2 w4 y2 k( N0 d8 d7 ?6 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); \ }
k( S }8 M; J! t( D7 P#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 7 N8 b9 I# G2 s% M+ P( k" E
" ?! {. m4 H/ P) U. w
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
" P' r* [8 }! X9 ~void MD5Init (context)
" k; T0 m( H; e5 ~. j9 \MD5_CTX *context; /* context */
, e# p9 \5 h$ e/ ]{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
+ z% `: E3 p) r$ O; y9 X9 r) m*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
! J: e5 t! Z U3 F}
# V( y, n! q! _/ W, f6 G0 Z
' H, |) Q( T" Q9 {) u! y* D, F/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ k8 `8 Y$ |& K- s7 k* Q6 W
void MD5Update (context, input, inputLen)
4 \4 D: l# o: b1 f! c" @' U& x( U! \MD5_CTX *context; /* context */
# a6 D D( Y+ d8 o- |, h# e; |unsigned char *input; /* input block */
6 E4 K$ L% k/ Z3 L7 T% D+ z4 dunsigned int inputLen; /* length of input block */ 5 P" Y3 D- a8 y$ q+ `1 H8 V2 A
{ unsigned int i, index, partLen; / s# o( V, z y0 c: X4 o% g
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); " u2 s* G& i: ]3 h1 K% ] {9 Z
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|