|
|
#include "global.h"
; b8 Y8 Y: H1 S8 x; p#include "md5.h" 4 w( e0 y, a ~. X
- _. A0 S9 d; V' ]3 l/* Constants for MD5Transform routine. */ , @3 F P# ^4 V: y u* L
5 y h8 i. J8 o6 ]0 }8 q7 Y $ n7 n$ K0 `0 D- @
#define S11 7 + i R( Q# G# M2 r2 C
#define S12 12 2 N G& ]2 _/ @. I" C
#define S13 17 7 ?1 U0 q- C5 U3 U
#define S14 22 # \; z) Q3 f0 b9 Y) t
#define S21 5
2 g+ g3 w( @) d; N#define S22 9
3 ^& i* \4 g$ O2 B" R: q/ b# {#define S23 14 f) Z }7 @: U; T# j- Y
#define S24 20 $ e) F( e% a6 Q2 O+ G2 A+ e
#define S31 4
& a: F* D1 A- I. [1 w, a3 s3 T2 Q#define S32 11 0 w1 d1 u# M4 f) Y* l( f9 Z
#define S33 16
4 |0 N2 ]8 j$ Z/ R: j#define S34 23
0 k# ^ Q; _' j+ e#define S41 6 ! Y! n& z, Q- j( }8 l8 I- H( F
#define S42 10
6 R4 N# |2 r0 W. G$ m. N) G6 v3 S#define S43 15
/ K5 h N5 }9 I9 S5 T#define S44 21 : s- K q# a0 ]2 [6 b
7 D4 c6 X+ i6 I( b3 m( @, u \ A
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
) A) r% {! c# s) s! E2 Astatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
. i* s* A2 l3 r, }static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
5 S0 W+ }9 A( Ustatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
, I, d6 ?, w, U0 `/ Z2 C: C- jstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
7 N- n+ K0 q4 z& x3 J' O
3 s/ z) T+ ]3 b/ T$ z) zstatic 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
0 `" ?) K3 J0 f' p/ ?6 S- X% N}; / J* k y8 w1 j) V: @6 X9 v1 ^4 t
5 u, k z& h6 h
/* F, G, H and I are basic MD5 functions. */ ^: i7 Q# B0 ?/ z) E
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
}0 C5 ?# Q$ Z, s+ d#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
1 }8 ^' S' Y( x& Z* V( N4 O#define H(x, y, z) ((x) ^ (y) ^ (z)) 5 r" f4 {! ]# d
#define I(x, y, z) ((y) ^ ((x) | (~z)))
1 e! o/ H" P5 r( C! m$ S
- t; R* D# [9 w. u, Y( G/* ROTATE_LEFT rotates x left n bits. */
^" U S: [& w# X#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
( a: N+ |, ?+ n8 H/ O* r' \ . R6 I3 e" |( o
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
9 p8 \/ ~" a8 q9 w; kRotation is separate from addition to prevent recomputation. */
6 A0 {9 y; B- ]2 A2 t+ H#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } & f: m2 K! ?" J2 @& f4 i) g
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% q! F; h! x6 {" B#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% @: h! l6 u' z; ^3 ^#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } # m8 {+ O5 t( z5 ^9 G/ G- _" f* |
( Q9 A, x4 r" _4 y0 l
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ $ k( _! i( `0 p N$ @2 i
void MD5Init (context) 0 J7 R. y) n' Y* J% _; q
MD5_CTX *context; /* context */ ; j- h2 }+ @* ?9 Z: v! [
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 9 B+ l/ R3 d( ~. u' i) l+ A
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
! p8 ?* x$ i1 d) k3 n} % E( I, S$ m/ z4 u" P! {
. t+ f2 l2 L5 c. w+ O
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ . q; Q4 Z8 ^, e4 o
void MD5Update (context, input, inputLen)
7 o$ d6 m X/ k( }+ ]MD5_CTX *context; /* context */
3 T) Y$ S& ]; }) n" O) X6 y8 lunsigned char *input; /* input block */
A5 {/ t" b4 m: x% ?- Runsigned int inputLen; /* length of input block */
9 c& _5 o r- a. W{ unsigned int i, index, partLen;
# U7 `' S$ }3 D% Q, z /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
/ f( J/ p4 v8 K# O9 Z' q /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|