|
|
#include "global.h" $ t* @$ Z! N, F8 I @
#include "md5.h"
1 k+ {% o- \! b$ w8 X
& M" t. S) N+ G$ s b; r. C/* Constants for MD5Transform routine. */
- s$ a, v) E. @$ D $ q4 ~4 Q! U4 w5 p- v: e ]4 l
/ E! g f. C, U: U#define S11 7
% ]4 }6 E; D: }/ e#define S12 12
5 n0 o, |& ]- p4 X2 f* s7 N1 I+ g#define S13 17
! c, @8 v* ~6 v$ U#define S14 22 7 R6 U. X' O5 G) j
#define S21 5
7 L/ W+ U; ^ h% B/ O" j* z#define S22 9 . ^' P8 y8 h- P5 n; v2 D- E# }
#define S23 14
6 ~7 n# q; ^( X4 v#define S24 20
5 g6 B0 h y7 D3 ~#define S31 4 4 `9 v+ r R, c& r; N2 j
#define S32 11 / q0 l! W# Y8 v9 u3 V9 L
#define S33 16
$ |; k6 K' _5 J1 n( L, |) X8 r: w#define S34 23
: d# ?0 \. b0 c- q9 k3 Q#define S41 6 1 H, N- |. h9 G
#define S42 10
t' V- g# {& }! L#define S43 15
6 x7 v6 m( Q& W! K7 T/ `* u#define S44 21
g- Z2 z' C r* w , [# F/ X+ N8 X0 b2 D
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
2 f- y9 R& q" D: Istatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ' v& ~( R6 @& R; w# c9 e
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); / m/ E# M7 P8 H# A/ m
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
/ s* L3 q# A) n1 D' V$ f2 g9 \static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ' J" B* f$ P" Y" O1 U* S: ~+ v* g" c
' Q. @% M% G7 Wstatic 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
2 ~. Z3 o" _4 W" E1 l1 [6 E, k};
) E9 X$ S5 z S" ?6 I6 ~/ c( ? 6 j: T3 Y0 Y6 b7 ]
/* F, G, H and I are basic MD5 functions. */
( s) \8 l9 h6 ^( r0 x: F7 F#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
2 `' \) `) ^+ d; h" i2 b5 T#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 1 W% C, B5 o& Z: z( a! }
#define H(x, y, z) ((x) ^ (y) ^ (z))
# I7 S# `- @3 E7 t#define I(x, y, z) ((y) ^ ((x) | (~z)))
) Q; E% M; o$ U- C
( V, M/ I; ?, b9 v; G/* ROTATE_LEFT rotates x left n bits. */
: f+ L( O( c6 B* d9 j9 K#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 0 |& h. C7 d( v9 ^% F& U9 y
& c! N: b+ u2 c$ d: t0 m/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. $ d9 C" w1 i9 ?+ O
Rotation is separate from addition to prevent recomputation. */ / P' O1 Y2 ]0 _ O3 ?" M4 y& \
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
$ I5 M$ Q. w5 D# o% L#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } : Q: F5 K& L2 e4 F$ I" K
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
6 v5 R+ ]3 l! G. F4 I# @#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
3 ]) e1 H+ X- K
' e+ D. x1 d$ F5 a& [" S0 T/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ' O1 A) y- u$ d7 I1 F
void MD5Init (context) - u9 u* d$ H+ f* U( O+ O5 }" {
MD5_CTX *context; /* context */ , u3 T6 u% {% F4 ~5 f( V2 P1 V
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. " @4 ~7 B$ z1 N0 P9 v3 @) l
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
# g$ I% b( B1 `, w* ]( h}
3 F3 C! @7 \9 _: Z" |: R 9 v x, \: `9 n( |4 w7 T9 @
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 8 O6 a; f- R5 g) o
void MD5Update (context, input, inputLen) 6 C% ^$ z# z* c7 j
MD5_CTX *context; /* context */ 5 @5 b7 e" u/ ]
unsigned char *input; /* input block */ ' {8 b3 B' K6 b. [: @7 W
unsigned int inputLen; /* length of input block */
3 d2 E8 C5 e9 i* s. t1 L5 e{ unsigned int i, index, partLen; : c1 U. f; K$ u9 I* N
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
; Q3 R8 W3 f: p& }# m1 J# O2 B /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|