|
#include "global.h"
) d1 k+ @" E7 W5 H#include "md5.h"
! i' n) w; P$ b3 ]1 {9 F% f4 J 7 l4 o" n- j* @
/* Constants for MD5Transform routine. */
E( `9 t) L+ @- a
. f$ s. e3 q' Z, W6 Y
$ {% D7 u4 b! p1 f#define S11 7 4 c: e1 b& S0 j0 Y
#define S12 12
% [" C+ i( D) q, t1 ~#define S13 17
/ Y( O3 G4 ]* i. V5 r6 @#define S14 22
* S! q) f, k4 h* y' B! X#define S21 5
0 q/ a2 u6 q, L#define S22 9
3 {, ~4 @3 h5 l9 z M2 P7 Q#define S23 14
( L3 O3 ]: D7 \. I0 p#define S24 20
7 ?2 C3 A, |0 |! b2 f#define S31 4
9 f H2 d' y7 W& M Z#define S32 11
! n6 l' {" q) E6 ?0 ~#define S33 16 * ^' \: P8 W2 Z. [4 p6 l0 V% g
#define S34 23
% C: E! N# B/ b4 F#define S41 6 5 A5 U# p8 w& N
#define S42 10
- A) k! f3 ^; Q3 m. v' l#define S43 15 ) P" h/ G+ n/ P4 Q
#define S44 21 ; G8 T) t, }' n8 H
! `% v+ g+ l4 R+ `7 k
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
' M" D! ]* q3 ^( [" Xstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
) I' K; L0 F. lstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
# V& C8 L) e6 s/ j) E1 Ustatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
|; Q/ I3 i f7 s4 @static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 4 [$ h) ?5 \' f+ H# g4 ^
. p1 ?, j. j+ x" A7 e& S, hstatic 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
& a6 Z9 n. v% K Y2 e}; ( R2 P3 G w+ |- @
6 Q! D2 h" N/ H8 v: t1 \7 Z
/* F, G, H and I are basic MD5 functions. */ * L- l8 n1 o6 _2 ^# _
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
* J$ S0 ^" a( R5 s) E$ r! k#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 2 E; z( s3 i5 \- y3 H8 ^0 `7 |
#define H(x, y, z) ((x) ^ (y) ^ (z))
8 w) ]% k" a1 @ a: \+ X#define I(x, y, z) ((y) ^ ((x) | (~z)))
( b8 I6 j8 P1 Y" ? 0 x, @1 P3 l3 R- X9 X% C
/* ROTATE_LEFT rotates x left n bits. */ 2 B( \$ p1 Z4 }8 z4 J8 G, D
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ; [: ]" ]5 [( X% u) g7 W& d
& l# B- }8 T+ G, v
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 3 C& v# z2 D* G* }' i; N- f4 R; I
Rotation is separate from addition to prevent recomputation. */
: z% m" i7 V5 ]6 o; ?#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 9 F) ]5 ?# `9 x5 Y 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); \ }
& r* X# `) ?9 P9 c9 W#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ' j5 V6 U+ ` ?5 f" e7 C
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 6 t( Q; n: g8 q/ ? p' o' `
& ^- L+ q% y5 R) x4 N
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ! v- t1 F8 J9 ~( a
void MD5Init (context)
1 a9 A* M* p' |4 RMD5_CTX *context; /* context */
5 N" I c v" X9 V8 k) a{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
$ Z0 s' u- F- A*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
1 r, {9 s3 C" e/ f( K B} * s1 h0 {: r" G
# a$ q" \4 u, W1 o
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
2 Q5 E0 |6 M' A. e$ H+ K: s/ yvoid MD5Update (context, input, inputLen)
$ H1 J5 p, L- `3 MMD5_CTX *context; /* context */
/ d' z; f9 c1 {8 V$ Aunsigned char *input; /* input block */
# L3 {5 D0 J/ vunsigned int inputLen; /* length of input block */
# {) i* Q: Z0 w{ unsigned int i, index, partLen; 0 r& a. X, D u! `# [: s
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 3 V+ z: ^! B0 C* x" R
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|