|
|
#include "global.h"
/ U. g3 U' @0 r) b1 S+ P#include "md5.h" 1 F; e, k6 o' e6 b
" @9 t* z: I$ W' f$ w& w" }/* Constants for MD5Transform routine. */ j& ?1 G, L+ j' n
|# w k( k* d9 W. ~) _
, W" T' C7 D q8 N+ Y#define S11 7
+ v4 [, l) V- @- d- W#define S12 12
D- i9 ^; f- i, d#define S13 17
6 r9 i% W- f, y B( l. b#define S14 22
: z9 O$ Q. ]4 r/ b; ^6 r8 e#define S21 5
( _; n- \7 Z. ^) L#define S22 9
5 ~9 H) w5 \7 I+ c/ u: [#define S23 14 & ]+ D8 ?1 i) t( G; X- |7 \1 P& \
#define S24 20 6 Z* i5 V E( h2 I
#define S31 4 ; \! f0 T2 b* F8 H8 F% c: \: S
#define S32 11 L/ z. `; Y0 c- x* \( @
#define S33 16 , x; b! o9 h1 _
#define S34 23 ; n. ~4 M2 M! O9 a3 p. L# [
#define S41 6 + a9 Z* M8 S. w( h0 K
#define S42 10
6 ^. E/ s( y* y- ^) z* a3 J$ O9 O#define S43 15 * M2 k/ C% C' s, m d
#define S44 21 . L6 J5 b+ T: r G
$ `: ^ B5 j, L, F8 g7 Mstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
0 j, q1 i; a+ {9 q( h7 dstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
! m0 u) ^( Y6 t" kstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); " h6 T1 E1 q1 T6 [9 F) d/ r0 c0 A* J
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); . H1 i- {& F+ J/ l* e; ~
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); - U' f+ W0 n$ v! Z# N
4 C0 v+ n2 j3 g. ~, Q. [% _( `
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
% V7 N5 Q+ M: g5 S}; $ J- o, [2 g. Y) {5 f
( Z5 X% v$ O; {2 ?
/* F, G, H and I are basic MD5 functions. */ 7 J, B2 @: ^* T% J3 C. M
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
) ~0 X. d! u+ ?0 m: c0 g' ?; y#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) , o) `! }" [2 E' F& `! m* }
#define H(x, y, z) ((x) ^ (y) ^ (z)) # P6 D* B- f* S# r5 H* r) ]; m
#define I(x, y, z) ((y) ^ ((x) | (~z))) 7 B$ K: O8 _3 @5 i% j
' O) O6 E- N2 F& B. k$ k
/* ROTATE_LEFT rotates x left n bits. */
$ F& ^6 j; y9 M. X#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
& L- M2 r7 s& g . V8 h ]5 D0 I
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 8 O' U+ ^0 h8 \7 T( c
Rotation is separate from addition to prevent recomputation. */ % y7 H) R. l4 W/ [9 F% @
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } / L/ w& Z% h" O0 z, B! 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); \ }
, y) H3 i) p' O: j#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 4 T o( |5 L7 ?6 {; A- W
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 0 O( ^# @' ^; E
" Z% T; X7 q2 S6 x) A8 [
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
F* k1 [# p8 s* Nvoid MD5Init (context) $ m; M K& @! H4 J& _) E* H
MD5_CTX *context; /* context */
) k% q& j. M4 E& O# e+ A# D{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 0 d0 S% _3 e% v1 f, L2 G* _
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; + W+ \6 X$ y$ b# m
}
# o6 {. B% z0 o. Y) D
) h! R" A% M5 c2 p7 `/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ % Z1 r. f$ v1 X: w
void MD5Update (context, input, inputLen)
) \9 O1 w9 j" h! }MD5_CTX *context; /* context */ 7 m+ K6 @, T% {$ t) X6 D
unsigned char *input; /* input block */
6 Q9 d2 \, \! T' h7 m- Y6 Uunsigned int inputLen; /* length of input block */
& ]5 T0 S. X) p{ unsigned int i, index, partLen; * j* u& O1 h$ j' m$ k) }, g
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); , q2 ^+ @5 i1 W4 x6 v$ g: A5 ^
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|