|
|
#include "global.h"
5 ^; W7 V) \$ B. I- ]6 J* w#include "md5.h" $ h0 h! ?2 C- H' G
7 i- _/ \' Q/ K6 Y9 Q; _: S/* Constants for MD5Transform routine. */ + R9 f5 \- B ^5 g& ]) I- P
! V: R. z3 c+ X) D$ ^
6 o- O, h+ |, {1 v( r1 F#define S11 7
8 u! I. G; R( P( B- R3 `#define S12 12 * y# O9 o* h3 ?' r
#define S13 17
R$ z# G2 |8 Y3 I#define S14 22
1 P& i) `& f$ K9 O#define S21 5
& V5 m1 t2 ?9 d' F7 O- N! Q#define S22 9 ' g, j% o- H4 m9 z' a) g
#define S23 14 / e& a1 k E+ x9 `
#define S24 20
; f$ |7 b" ? k#define S31 4 6 E' t8 ?0 D' b1 o U
#define S32 11
1 V4 N: Z6 |& R& @0 [, }. e S" a#define S33 16 1 }' ^ e% f5 }1 @: H$ X
#define S34 23 # F1 H# `9 n; D& ?) N: }5 z
#define S41 6 0 Z. w) A; x. x$ i3 v
#define S42 10 : G, J. i# M9 S; N( \
#define S43 15
1 D& E, {0 N# U1 ?#define S44 21 . c; \1 @' i" W+ I% Z6 e {6 ?3 i
+ W# t- M/ ^/ s. S' ^
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
6 |8 R. d5 Y: T$ v" rstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); # j6 ?2 d/ s& f
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 6 C! _9 E% _. R- n" s/ t
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
- G, @: A1 Y) v4 M) l# ^9 sstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); % A6 y0 l% Q- x- C% Z' _
. }& I" ^7 H. m7 l" Z/ ystatic 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 P( a2 u! C4 Y) e% {; S2 P
};
$ K7 E2 N. t4 Z, P9 ?( p ( n* f& A2 H5 }* T$ K) _0 R, B
/* F, G, H and I are basic MD5 functions. */ 7 B2 ?. v9 a7 @* Q5 {% Y1 B7 Y
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ) @. x9 O, x& |' Z- Q
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
1 I' H8 t5 Y, S2 l3 t( s5 D. K#define H(x, y, z) ((x) ^ (y) ^ (z))
+ Q# _" V7 h2 x* a% c#define I(x, y, z) ((y) ^ ((x) | (~z)))
( O* B; x0 H$ k2 x6 X. A! q , ^5 n8 y+ l' ~
/* ROTATE_LEFT rotates x left n bits. */ + K. a2 n& r. }0 v' g4 U& ?
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) - \% q* S1 |9 I
' x( F( Y( x3 \' l
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 6 V1 U% e( [% g/ x: h
Rotation is separate from addition to prevent recomputation. */
) _; z0 o1 N: C1 A#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 4 ^! `: W0 G8 H9 k4 |. S) i
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
4 P2 L, e) H4 s2 R- E#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
/ Z6 c" t, x+ J) M3 ^# O: |6 q#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
# q( F8 @& _' m1 M, C 7 v! F! o7 G. l
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
: O# [ D& }- O& Jvoid MD5Init (context)
$ H% g' o6 Y/ D4 l4 r8 NMD5_CTX *context; /* context */
5 d3 F5 q/ k& u/ q. B; @{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. / d9 d2 {& a7 y, x
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
+ y8 I, u u1 R2 u} * Z, f( o& E2 v( ?+ w
3 i6 c% r+ r3 ~! q# b
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ ! j; A3 s. U! J8 I) ~
void MD5Update (context, input, inputLen) ; b. A+ j6 `8 I; n- w+ P
MD5_CTX *context; /* context */
# k7 o2 q( A0 ^& Vunsigned char *input; /* input block */ & o8 c: |! f# q9 ^2 b$ Y+ a" Z
unsigned int inputLen; /* length of input block */
% p" b3 Z8 Q+ t% C5 w" Q{ unsigned int i, index, partLen; & _1 I& E- n$ S1 m; x
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); % f$ n8 s+ d5 ]; Z& f {
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|