|
|
#include "global.h" " n6 i' w. s# G
#include "md5.h" ) T( G! y& y7 m- s N- |3 j
# d( r+ a- j4 |& E( A/* Constants for MD5Transform routine. */
. D& X. t& I& u4 e4 S ' v, H- G+ k! H2 L
H7 v t4 r, I; s" c& z
#define S11 7 5 Y( |) J6 q5 g3 Q' H4 J n
#define S12 12 " g2 i& S y1 {* U/ n) b) e
#define S13 17
M6 _# n/ b5 \" _#define S14 22 / C) g4 |' D( y+ i
#define S21 5 $ \9 Z: g6 m w
#define S22 9 3 E6 B8 [( W7 @" m. a H) G
#define S23 14
7 r& N. T4 Z5 Y: p2 k f3 `#define S24 20
9 Y3 E& z ? f8 ~. ?" M#define S31 4 # H& c- J7 ~$ a" O) B! O3 ?1 x
#define S32 11 % {+ p5 `3 H0 ]1 I/ X* b0 p
#define S33 16 9 ^ m( l, E8 C% ~/ Y' @
#define S34 23
0 W c5 o) s/ t q#define S41 6 " Y: O* n J0 ]. z2 w
#define S42 10 9 F+ _& r: d% e0 {8 L& P
#define S43 15
$ B7 {& K; N4 T3 ~/ @( _4 Z+ h7 u#define S44 21 w; P5 B" B3 T3 D
% ~, }/ r1 a! n) d5 a: e% o$ qstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
( I8 p( a! m/ X6 }+ y% ]static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
! w' R& x! W: p* V- Gstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); $ P# o. m% L6 g$ `) i
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
& A4 i/ M9 a; Hstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); e; C% G$ o. y4 E
% c0 b4 y1 b! K) kstatic 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
) u1 P' J! x( y2 s};
& z- e/ E) x; \# ~- v " c! Z% ?8 C( g' k% q6 `
/* F, G, H and I are basic MD5 functions. */ ( N2 N/ i4 e5 c3 {4 O1 n
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
d: k0 {6 l7 u7 }#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) : U( P% h' S' ]* [; {" g7 r
#define H(x, y, z) ((x) ^ (y) ^ (z))
* L9 [5 ?9 W# w G* c, H#define I(x, y, z) ((y) ^ ((x) | (~z))) 8 v7 b1 b5 B+ Y9 e$ O
# `8 T; i4 y7 _ Y. Z0 g" Q/* ROTATE_LEFT rotates x left n bits. */
) s2 P$ a9 a; t1 f: r#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
% U5 Q6 p# I# b6 t0 e$ R
9 U3 z5 F! Z' X* `7 t* B5 ~6 p3 o4 W/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
0 P1 N y' d$ j! c9 V0 HRotation is separate from addition to prevent recomputation. */ * i- ?" h, h2 `- o/ l8 t
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } - q% L: I! P& ^, k! q. o( M
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 F8 U! g' u5 ?4 @( b# N
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ) d5 z( J: t. B3 }
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } $ g' _5 w- L0 l* I8 h# r* S1 i2 z
9 p" g) C. p0 V: L/* MD5 initialization. Begins an MD5 operation, writing a new context. */
+ A- ?0 ~5 s$ ^4 @- kvoid MD5Init (context) % ~! d" Y; f7 M8 S! M- {/ M
MD5_CTX *context; /* context */ ( D1 G8 P: P$ M3 Q) W, m% n
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 4 s8 t9 n3 \9 J# N& Y3 x
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
" I |# Z8 Q' N( }( p}
, B8 K+ y$ K0 G- }: j 3 D" x) R5 {$ z, A2 s0 m' e
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 4 ]) e- ]3 e: x2 n5 N) J R
void MD5Update (context, input, inputLen)
3 s$ i8 v3 Y* I) U0 `6 VMD5_CTX *context; /* context */ * T- I3 ^2 P; ?1 |) R' w
unsigned char *input; /* input block */ - o; u4 w" D8 p1 \
unsigned int inputLen; /* length of input block */ ; v8 z" i" g/ a' e
{ unsigned int i, index, partLen; 0 {4 n8 u! h6 L/ E% B
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
+ z0 Y5 {6 P8 c6 t$ F3 Q* q3 B2 s5 e5 U /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|