|
|
#include "global.h" + g( Y$ }7 H4 y- V- B0 j
#include "md5.h"
- M3 m) \$ C0 q7 G / h+ p: p/ p: o+ E4 v
/* Constants for MD5Transform routine. */
/ O9 \* n' y$ e7 N, U x 5 l; ?& J9 _0 g R
5 |; A) U9 J, }% M9 `/ |% g
#define S11 7
7 W( ~) @, L9 R6 _/ M3 M& D#define S12 12 $ L8 z5 B; Y6 E
#define S13 17
* a4 U% o1 ]# z( P7 y3 u4 a#define S14 22 , Z8 a( \ Z* E2 |0 I5 T
#define S21 5 6 `& @/ w6 H$ d4 ~ l0 U
#define S22 9 ) A: J8 J3 T3 M) l: o( `* [7 n
#define S23 14
8 K& X" m. ]9 q; Q. a/ I" J#define S24 20 0 N1 ~" @: g: F' q
#define S31 4 9 l" Y2 {3 |, R& @
#define S32 11
+ h: p3 ~: H' _2 D#define S33 16 " o1 T$ B$ n; J6 `6 |4 @) C: o
#define S34 23 " g; e; n9 ^$ |- j( E; {
#define S41 6
/ h; c% s" R* z7 |6 D/ i' |#define S42 10 ! ~# ?7 {2 A, B% E4 G9 u( l
#define S43 15
3 t5 `+ {* G; {1 X+ m#define S44 21 + d; M% }+ W# T6 V* l2 z
$ Q. e$ l/ v& J: {9 r7 [
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); - z/ m! z; a* D }' B: r; l
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
% E: Q, r% i7 |( g; L9 \! Bstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
/ X T. a8 s. ?) J |% _# Astatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); : \6 }+ z# u4 d2 _2 {
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 5 ^6 X0 D# z8 B) C( V
3 g! @9 q2 I X! E- C/ r x) s
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
% K5 e* M- p+ k! M/ a$ Q}; 6 }9 c3 Z% V- }2 l* b
5 r! h5 Y( \/ ]( x+ p; B- X9 v" v
/* F, G, H and I are basic MD5 functions. */
8 ?5 |. A8 ?1 M# g: ?. h) P) I: U0 v7 S#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ! w! S j; t- p6 W' ]0 W% ~
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) . `; P$ c4 S' h9 K
#define H(x, y, z) ((x) ^ (y) ^ (z))
/ W4 h _) S \# ?#define I(x, y, z) ((y) ^ ((x) | (~z)))
' T$ T3 ]- P! [$ t% S. ?" N u4 g
6 p2 f% H. w) V) P! e/* ROTATE_LEFT rotates x left n bits. */ 1 ^" E# s* x2 G' O
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
8 r/ L: r d- b+ T2 H( T# U
3 t: b% e/ Q! [+ n2 s8 p9 d( v/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. : B+ }7 P8 e- P
Rotation is separate from addition to prevent recomputation. */
! \) [6 Z* w& B' c#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ ~0 X4 n$ }% a- ^4 v#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& p( P d i) C( f0 C3 @" 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); \ } 7 e1 J5 w. N8 W" K4 E! \
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 5 e$ A2 D, F3 D( T
- n* @5 |# U! ]% J5 v: o$ l2 e
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 3 _* N7 x8 D s! d0 g9 X4 U
void MD5Init (context)
' f, J( K7 l/ a/ P( j) k. MMD5_CTX *context; /* context */
% h) O5 Y, A# _$ D0 ?0 } V{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
+ g" e0 j1 F" q0 @- p& y*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
" w! B3 v) D! U}
0 P- h8 ^! W; f, [$ k" j 9 q A' ^6 Z( Z8 T# Z
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
4 O0 k& e; e" A. M' Xvoid MD5Update (context, input, inputLen)
# L" Z! C. a' d% }4 J2 YMD5_CTX *context; /* context */ # c; }4 ^( a4 Q, {: q# }( z
unsigned char *input; /* input block */ s+ @" u, P, c' V- C
unsigned int inputLen; /* length of input block */ ' r o' p+ J7 U2 v- m, l6 Q
{ unsigned int i, index, partLen;
% u8 M2 Q8 k+ j+ v! }" Y/ ^6 Y /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
/ o: g4 D/ B: J0 E6 b /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|