|
|
#include "global.h"
' }9 q4 {5 R. w#include "md5.h"
9 d; K9 N" Q V1 p/ h/ x: m5 p5 l
4 I8 F, D/ u) Y% x/* Constants for MD5Transform routine. */
/ k8 {# B7 O$ S4 x& v
+ S" A4 c6 d1 Y% e$ f! L
. E Z% c* v9 V( s8 K/ E. h! K#define S11 7
) e+ p7 r9 h1 y! G; L9 j#define S12 12 5 v2 A+ `( j( C ~7 H& w, X; z' s' A
#define S13 17
9 ?$ v3 V. j/ v; w- t* h D( J#define S14 22 6 {- \8 U4 x7 T1 V9 I
#define S21 5
2 c. w8 J, ^ n) r0 t9 N#define S22 9 + f) y9 n! i& f. D9 |- m, i
#define S23 14 . k& E, A* D6 `
#define S24 20 ( L) ?8 k" T# |
#define S31 4 8 M$ F4 Z f; E" @' `
#define S32 11
' `9 h7 m" R4 a* \#define S33 16
4 F* g9 I3 X. v) W' |7 l. k#define S34 23
+ C5 I; ?, B( t! w. \, t#define S41 6
' [: {, X& a) _& ?0 _& y#define S42 10 * t3 P: P4 w, F" ]0 m* }
#define S43 15
& J, H( D4 F5 G9 l#define S44 21 2 n* X5 d7 d% W4 X# e
* o$ H1 J% C3 D- L$ m) f" V4 V
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
2 L: x( t) \* a" ]/ r! z9 hstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
2 T+ w. p; ?- \; Istatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 8 s. Q! V M8 {3 e- H l' o
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 5 Y) l4 v2 u3 V H+ z8 E
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 3 v7 o+ Y( W! O/ S/ B! f. K6 h
! k+ Q3 t- r! U' Astatic 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 . A" b5 }5 S4 K
};
9 p2 y/ Z& C+ O* j' Q & j5 _& `4 U$ e8 _- q
/* F, G, H and I are basic MD5 functions. */
) w2 y( g& ? M. m' n1 ?& s#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) % U& E) T3 j/ b! t$ K# j- X
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) % q& I2 k: Y) a0 _6 e8 Y( g" U
#define H(x, y, z) ((x) ^ (y) ^ (z)) # t R8 P5 r* y8 n4 u
#define I(x, y, z) ((y) ^ ((x) | (~z)))
6 f8 V/ s" h- d3 [8 f" \
8 { i7 U' p/ ]: k/ S, z1 I& h V# x6 L/* ROTATE_LEFT rotates x left n bits. */ 3 j5 _ l& R+ Y) G; U" v
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
0 C7 l+ } g3 l2 m1 K4 { 1 a, z: T- H$ D/ u8 R
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
! u: ]0 x+ H) a: u0 u, vRotation is separate from addition to prevent recomputation. */ 5 k+ W" `: R0 Z" f' n6 {
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
4 k: v- _2 }" n A, ~#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
m6 e4 m4 Z, O( d2 h, ?( x3 S#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
( H, e, X. ^2 K; x( R2 g* q, x# y5 c#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } : s" N r. Y8 X! K; |- I. y( X- Z
" G5 ?1 m& {2 U0 B) V) i2 n4 V
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 9 E: m: }! t5 S2 D
void MD5Init (context) % y$ E; L @5 p) c" i
MD5_CTX *context; /* context */ `+ l" P$ z5 U
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. # A# I" S' q' s' D, g- f) E
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
: K7 Y5 r! s. A6 ^6 C9 m} & [6 d- c( }5 \: h, T
9 R& F9 P9 m0 m- `
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
2 M: f* M( o( H4 G# t9 C wvoid MD5Update (context, input, inputLen)
% k1 G/ B' p" B: ]6 ~MD5_CTX *context; /* context */ # ^, {0 ^. N5 k3 m% E
unsigned char *input; /* input block */
, k& b9 D/ ~& A$ tunsigned int inputLen; /* length of input block */
5 U& F( g5 |3 q7 ^& O- E{ unsigned int i, index, partLen; D }5 s- T% A h
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 2 q4 |7 u+ B" E" t
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|