|
#include "global.h" + g2 E; A6 ] v1 D
#include "md5.h"
* r4 U1 j3 ~- m, [5 ~: n7 t" ^& m / Y' ~- y2 k s- u1 s! B. ?
/* Constants for MD5Transform routine. */
) B1 O; i H) R/ h- t/ P$ P
+ N. {0 ^. O2 |& Y8 w* b: o5 G$ D
1 p/ Z1 K3 O5 F1 c#define S11 7 & J6 o4 Q+ L# \' M! r) H. J0 L
#define S12 12 1 ]+ @, r; [, | F
#define S13 17 5 _# C. ~1 C' w: g8 j2 K5 ?( }
#define S14 22 8 \% L9 A, V$ |- ~
#define S21 5
# H7 L# n# u* @" b6 X1 t#define S22 9
* s4 p( l* p8 @9 H. W' i9 Q#define S23 14 , y; z- S( a/ [+ {" r3 p& k
#define S24 20 1 | v: w+ a( C
#define S31 4 6 q1 E: C$ c- C& D0 ^" c4 [& T* J
#define S32 11 6 S: w; A# [3 k
#define S33 16
, r. a- W4 s- ?4 O#define S34 23 4 _& x! D7 S1 ]6 X" Z- d) T4 G' p) S& v
#define S41 6
: \* i4 D7 S, P( n#define S42 10
4 X9 S4 S% y% M4 h/ l# E#define S43 15
, _2 }9 J3 S. N#define S44 21 / K! O& _0 \, {$ Z$ e5 X, H8 g# ^
8 s& o- @7 [+ a6 rstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
8 ?3 ]! V, [1 C- I' p7 s/ O/ qstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 0 ^. I n2 K4 f, Q' ^+ B
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); : K/ x. I! C2 X! T; E8 \
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
! j3 T# l7 D8 ^static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
* a; X# V" s; Y$ A% U& R+ v* {. {& U
9 \* k7 c) [! [. r! h) L) }! \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
1 q/ O, h( D$ @6 P6 c};
9 D4 ?& n9 z% ` 3 Y& D' d. i( z
/* F, G, H and I are basic MD5 functions. */
: ?1 @! ]- q) Z8 u( i+ @1 @, K$ }#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 3 C0 v" `0 F& n
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
3 s7 S* z" W+ u( u* q' j+ y#define H(x, y, z) ((x) ^ (y) ^ (z))
2 ^. ^" N4 ~& S3 T* a& K% {#define I(x, y, z) ((y) ^ ((x) | (~z)))
( y8 [) R, \6 v4 [; \! g) z5 C
9 y4 G" p6 ~% m& J6 Q, y" V" O, c/* ROTATE_LEFT rotates x left n bits. */ 7 a4 s" l7 W: c9 M7 `1 [
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
! Z2 V7 L& ^- @9 A/ I3 M
& H) P) \5 X: J! \, ?" q1 X/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
+ y" ]6 f5 }8 ARotation is separate from addition to prevent recomputation. */
% r* X& I7 {' V4 X#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
' O# f" q i6 V" m#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } " f8 e/ b* S7 {9 h" b7 N& 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); \ } 3 h% X% p- M# O
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 2 U! w2 _" x1 D# H% {2 V
4 E+ N5 F% W6 z% l- e9 P/* MD5 initialization. Begins an MD5 operation, writing a new context. */
0 ~0 C' u7 V" h! P; Xvoid MD5Init (context) # C [" B9 D; v1 s
MD5_CTX *context; /* context */ : G3 U4 I F( G+ I0 }
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. + ~0 z" T( s# h' `" k
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
1 X0 _# @# T' r; D) y} + y" Z- ^ T5 J) n8 |+ Z8 p2 z
! |9 ]9 l5 _! R8 F
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
0 F/ C( }: q# ^! E7 ivoid MD5Update (context, input, inputLen)
1 S6 m, L: C% o5 R7 @5 GMD5_CTX *context; /* context */
+ t, \- u7 t3 O4 I# v3 Cunsigned char *input; /* input block */
4 `7 w$ B! r& F; {unsigned int inputLen; /* length of input block */ 0 H5 x* R3 u4 i# f# h
{ unsigned int i, index, partLen; O$ q* }( ^& m0 Z1 P5 c9 [2 B
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); , R6 Y; F w/ a% ?: p/ ]) g$ r, N9 P
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|