|
#include "global.h"
0 O2 ^# m8 Y% I S" F* f1 }+ M#include "md5.h"
. ]' j2 x1 {. q' |8 m . K. \, D) `( [- f- s
/* Constants for MD5Transform routine. */ 2 j1 p ]. G! W _2 _7 P6 H$ U
2 C6 |% \/ O/ V" t( D7 _( I @ " x+ v9 g% E8 P2 p5 Q
#define S11 7
/ d7 m$ x% j. e, i: {6 p#define S12 12 , v/ Y' S" {. {2 B6 ^
#define S13 17
% d: u# |% p+ j3 H: [! \#define S14 22 2 {, G J9 F/ s- c
#define S21 5 , X* Q7 z0 h6 d8 l9 C
#define S22 9
[7 U0 I9 }/ @, I#define S23 14
. U. h7 F" D; h6 [" W% }#define S24 20 6 Z6 n% @1 `: l; a; ?1 G0 H
#define S31 4 9 G7 k3 {' m0 e1 J
#define S32 11
0 k- p4 Y7 A5 G, c#define S33 16
4 j1 I# I+ q$ v' P6 W4 W#define S34 23 $ ^/ b, H7 J& o+ d4 C# g
#define S41 6
! F |. Z4 s6 R3 x2 ]% R/ A#define S42 10
9 a+ h1 H1 t% R+ y! A#define S43 15
. W8 T+ { f3 u; s4 n9 I#define S44 21 # B1 D* x4 H# \2 n5 t
. f7 R7 a5 r% r+ [9 C* Dstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
# ^) }; n0 W& y. x9 qstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
2 P# ~! m8 p1 K2 U5 ^% jstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); # {/ H" F: x- X+ L# V5 d& d
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
/ `% j& {) \. g* q: z3 \static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
s) ~! Z9 V/ v ; ^( x: j/ v; K
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
# H$ [! T6 r6 L! C6 o}; 7 s* ]1 I( h4 Z7 @4 h4 g0 p
$ C6 l% m9 e! s: U6 ^9 E- o }" c/* F, G, H and I are basic MD5 functions. */ - t. t s2 \6 O4 D
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
C/ z* n C) \$ Q#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
1 f1 O) {; D/ Q#define H(x, y, z) ((x) ^ (y) ^ (z)) - ]/ G/ G* H; y
#define I(x, y, z) ((y) ^ ((x) | (~z)))
5 z* M% g* p7 ?+ z, K/ h: W
, X' D8 e/ Y. R1 t# ~% l7 d6 U. {/* ROTATE_LEFT rotates x left n bits. */ 5 _+ s- S+ E8 Z
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ~/ M" H; y9 @' b
I6 c) k# b4 t+ T
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. $ i, \7 ]( y7 n) O
Rotation is separate from addition to prevent recomputation. */ ( {0 S% S1 O! I6 F; M
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
. [* y* P( q- x U#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
2 m% @; g1 d+ \- X#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
! I6 X$ G g5 E7 j3 W; L#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 u, i+ j7 P$ s9 j" P
0 e# O9 `+ a+ y
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
% ], t: @7 }! \ a7 E2 m ? ^void MD5Init (context) . S) R1 P1 ?5 ^- {
MD5_CTX *context; /* context */
) a5 {1 ^, W( K: z8 n; r{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. " U: V8 n% A) i' w3 N* a
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
2 H1 m( v4 t8 N) m k3 i}
9 C6 v! D. K% ?- H& I* J* [ ; Z1 }1 o/ d0 L+ p5 L& N* J6 H; P. u
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ * c0 h: D; y& ~' P2 I3 ^+ m6 {7 T
void MD5Update (context, input, inputLen)
3 r, ]7 ~, F& S- O$ ]; n* u; tMD5_CTX *context; /* context */ # B' x! `, k# `
unsigned char *input; /* input block */
6 N2 f9 J6 p0 L1 Gunsigned int inputLen; /* length of input block */ " x# D: \4 w7 W: c
{ unsigned int i, index, partLen; - {. u' e* n- K1 J
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
3 Z8 I: k8 r& w) ? /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|