|
|
#include "global.h" " O" g, B% {4 R m
#include "md5.h" 8 Y9 S# l) j% N6 q
7 K& M g) `& q5 k# `" p, m& x
/* Constants for MD5Transform routine. */
; H$ p/ L7 T8 I! v. ^0 N, p8 A 7 C S, ?6 y! @4 L' }. @
% ]) u3 l1 p0 u, I5 T
#define S11 7 Z9 m: R& v/ o* [) @
#define S12 12
9 X. E- }. p+ M I% q" h; s#define S13 17 ! x5 w+ D) b% d
#define S14 22 9 P, b9 O. Y: C& e5 N
#define S21 5 1 U, M& r3 v* J+ N6 F3 @1 w& ]
#define S22 9 ! [; e/ J {9 l$ u( o" ]
#define S23 14
' n# q6 l/ J1 I# R0 Z* _#define S24 20
7 N7 g u( Q' }# u* c( O3 Z( x#define S31 4 - D4 j0 h8 R, M3 m6 f
#define S32 11
; M% @5 D/ _$ Q5 F. I0 h3 u#define S33 16 ; g: g2 u+ W, D: f. }; U# o; n) a! `
#define S34 23 & d$ }1 O: A; k& J
#define S41 6 1 p) h" O' E$ _/ S. M
#define S42 10 ) ?+ U9 U+ [1 z( V
#define S43 15 3 }% t: x1 g' S3 j, K1 J8 T5 h8 S
#define S44 21 ' U, R& x( w) l1 l' T
* O& ? a9 X, L
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
4 e2 o4 Y; d3 P0 Dstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); " ?! d" r( B" R5 }* ~
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); . U3 k* x7 I9 h7 j+ X, P
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
5 U1 v- J( b& Istatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ( T1 c5 r, B1 f8 r
9 Q3 R, q5 x1 G! G3 l6 U0 Q' 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 * i8 h/ b! o4 u2 ^& N& d
}; 0 p# H. y) K' H$ h( N4 P
6 n% D$ d5 l# w& J8 }8 l
/* F, G, H and I are basic MD5 functions. */
9 R! ], g. F: a b7 J1 i! c- ?+ M% u#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ( K; w4 c0 ?4 z% w" ~/ ]
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 0 s7 O6 l# a% D$ ]- s4 Z9 y" h
#define H(x, y, z) ((x) ^ (y) ^ (z)) $ f" ]- ~2 X% Y
#define I(x, y, z) ((y) ^ ((x) | (~z))) % t2 v* S- u J& V" C
, J# `' T9 x& u; l) u/* ROTATE_LEFT rotates x left n bits. */
% v& @3 i3 b. |6 r1 u#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 9 G6 j+ v' x2 _) p9 a
1 d0 |, E9 d1 G( T. J* e+ q/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 8 @2 i; ]( [8 B; ]8 U& o# I
Rotation is separate from addition to prevent recomputation. */
+ v- s3 h) x9 o* f' h: L#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } $ j+ ]- w( U+ y: 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); \ }
$ I. `. m4 Z4 D+ O3 ]0 ^) |#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
, e- s6 s9 w p; v/ V#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% y: T# X$ H) I3 |
! z& r, F1 B0 ^2 p* e6 W/* MD5 initialization. Begins an MD5 operation, writing a new context. */
. j+ ~+ w) W2 B3 b, J: Gvoid MD5Init (context)
6 ?* T: F5 _' ~6 Z9 r2 S: q$ q( wMD5_CTX *context; /* context */
+ i) T: {- h4 K{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
% i/ ~( H* W0 R. D. V) a# E*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; - u& O5 Y: d+ I- r# _; Q- R
}
. k2 C/ g, O k2 @" q. e. m 0 O5 A/ c' h% G
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ ) a0 ?5 \6 \) E
void MD5Update (context, input, inputLen) $ J4 f7 i: ]8 @/ W5 [; d
MD5_CTX *context; /* context */ % V. v8 e+ ^* ?' D1 r, _# O2 d2 e* C
unsigned char *input; /* input block */
* { ^7 H2 X1 [. w0 lunsigned int inputLen; /* length of input block */
" f+ j3 o# |* o8 e4 ?; e1 t* s6 ~# {{ unsigned int i, index, partLen; ; A; f% ^4 l8 o0 D
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 1 Q# s3 a% O6 s5 X
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|