|
|
#include "global.h" - u% v0 ]4 Z3 f% W
#include "md5.h" 0 u Y; q% r' ?2 p7 Y: T2 R) \8 }' D
1 t5 O! V$ W+ Y/* Constants for MD5Transform routine. */ ( l' c: g0 ], L! H7 J1 d- W" T
- z0 t4 p/ [( b$ o" V8 ?
U& n+ u( Q- _3 m4 Q5 b
#define S11 7
; s1 W0 K% d' q+ | y#define S12 12 & a5 @* N& H& k6 c" w4 ?/ w. @5 B `
#define S13 17
5 F8 V% S1 b6 T; r, \#define S14 22
7 n0 z& W- D4 }! N% f& m6 [# h#define S21 5
* D! X* G3 v/ ]8 ^#define S22 9
3 R) a# F0 ~; }$ W#define S23 14 9 w7 x! c g& H. k- i% {1 a! G
#define S24 20 / J) h( v, F* q" w( y2 O
#define S31 4
3 d2 _1 H- r: P$ |#define S32 11
0 G1 v" ~4 p# O#define S33 16
7 e) |: L) N G* l5 l7 j#define S34 23
# C* z+ z- l- g8 w4 ?' d#define S41 6 6 E( Y7 T! `' l- U: \! |$ p7 c
#define S42 10
7 T$ |! \4 y6 m' w#define S43 15 2 r0 h" C+ X5 {5 \; b
#define S44 21 ( a k7 d$ q( z2 X! y* `
$ w# L6 s+ b. V/ N( Ystatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); % Q Y/ K0 d9 R8 R) j
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); $ u; U' E8 u, ~. I: d
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); , o$ V7 _' G q, a
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
" V/ D* d( a5 z4 h; s+ estatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
. w1 T+ z- p* ~3 H8 M. Y; V$ ^8 k0 Y - g- J' x: ~; `( y
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 + w/ c& U0 |, u3 x5 J
}; : j" m2 m/ e o# A
+ Z% h5 h' ~/ y$ h
/* F, G, H and I are basic MD5 functions. */
" ~6 C% |: z: B6 w# a" Z- n+ c#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
, c5 m4 p+ B! i! Z#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) ! L8 v' g) A5 E; ]" `$ f
#define H(x, y, z) ((x) ^ (y) ^ (z))
% s; r. Q6 i! p6 ?, ?# R#define I(x, y, z) ((y) ^ ((x) | (~z))) ' P5 K' H+ z, c. b& ?3 r; d
0 `( ]- _& u O8 i4 C8 b v& y/* ROTATE_LEFT rotates x left n bits. */ ! A# G, n. s7 L& b$ J, |2 {
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
# m" @6 s3 e# P w' g
2 S1 ~* V' Q( B, q& X8 T& `6 o/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. & L9 u, Q; s9 `6 l& k5 u4 u h" |
Rotation is separate from addition to prevent recomputation. */
! `0 _- r+ t6 }4 w) @#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } & V( g& c& T Y* p, H
#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# M0 ^0 b( r) ]& J, O4 O6 F; D#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 6 N4 E* [8 u) o/ |$ ?
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
: j" f, o9 B8 M
" [( d' k* e4 x8 O8 \( M$ ]2 N7 y/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ( K, I. P# u, g/ B! L+ m* ]7 `+ W7 s
void MD5Init (context)
9 e* f3 q7 a0 e( hMD5_CTX *context; /* context */ ) V, M0 {1 \6 z
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ! l9 Q5 r3 P6 a5 ]
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; * x7 h \4 Y( A7 \! k
} ! i2 O$ @9 Z5 E% Y- j m4 q
# _0 O" o8 O+ d+ k
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ $ c! |, w+ t% j- V
void MD5Update (context, input, inputLen) * y% n# z* y1 t) @7 N* H
MD5_CTX *context; /* context */
/ z$ U$ S6 N( s6 B% @unsigned char *input; /* input block */ + b( D9 e; s/ P% V, S8 r% Q! Y* {$ _
unsigned int inputLen; /* length of input block */
) n: @7 j% \* d: F) p" y8 U8 M{ unsigned int i, index, partLen; $ Q0 x8 X1 {2 J+ A( S, f8 k
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
: n- l* K. k- D; Z8 y$ m2 K8 S' R /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|