|
|
#include "global.h"
- s3 C$ i5 E& @#include "md5.h"
3 z. W6 z# N+ y- S8 b
0 R. t6 s* O' T7 `/ `0 P/ v/* Constants for MD5Transform routine. */ 0 |/ N5 W/ v+ [! Y
( ]$ ]0 q! j& D- v5 b
/ ]' n/ w5 P( F; t- k$ Z#define S11 7 " g9 W2 J" b4 P
#define S12 12
) a, s5 G" t% G" l$ x' d6 s#define S13 17
4 V% `6 @6 y& d, q#define S14 22 / M$ Y$ ~( A/ m, P9 G
#define S21 5
* f8 q0 p `9 ^# y `+ A a9 S" ?# F#define S22 9 5 J5 b: ~# j; v# Y2 M1 ~ o- E
#define S23 14 & y1 B% Z( Q }9 l4 H
#define S24 20
3 p) G0 d7 J" I+ f5 H#define S31 4
4 b8 m' A% k. ~9 P4 ^7 r6 ~2 |) g#define S32 11 ' ]4 M( \& k% d4 d
#define S33 16 2 K2 T4 p' m# v
#define S34 23
5 c [3 P, T8 U. \#define S41 6
( Y% y& A% x4 I8 G9 K' I0 E& Z6 a1 d#define S42 10 9 z H" V9 b0 `& B8 L! v# ~0 @! u
#define S43 15
% w' R' ?6 D. ~- {#define S44 21
8 c" t# L3 I' @( a Q+ O h& \/ w. j8 \# h3 o& r6 M* I
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
) Y$ t( m# J* w$ sstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 2 E; E/ q& g# U. d
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
- L2 Q, \! s X; u2 a1 r& B, K9 I( }. ^static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
& G+ Y6 \( P( E `" R% X, ystatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 9 I0 J1 ]/ U7 a8 @' B7 Z
4 ]% J4 Y3 q$ X
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 8 y, o: \- o& s% M! `
}; * T, P" o6 i% d, J( M( s
( b3 u) C) k n; ~
/* F, G, H and I are basic MD5 functions. */ + z; f1 P8 q, r; M
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
' o8 r) R+ E* g+ b' c#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
8 g7 E' b+ |% v1 ^9 I#define H(x, y, z) ((x) ^ (y) ^ (z)) ! R8 l) w# C9 W' V
#define I(x, y, z) ((y) ^ ((x) | (~z))) 9 Q: E% C4 l: o4 W
5 h' W# W* d) p$ w F! [+ |; T/* ROTATE_LEFT rotates x left n bits. */ . b# _! ?( j- I$ L' Q; j# j
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
0 J6 r2 i9 e8 n( V5 l( p* H2 P5 n
/ _$ ~, w) ?8 E u/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
@1 D$ \# x3 E" [! C7 GRotation is separate from addition to prevent recomputation. */
7 _$ n0 h e( M2 j9 }0 b#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 0 p1 b4 Y' G$ Z, }4 e8 C
#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 l3 Q" J1 l8 V' s: {& B+ r#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
) ^5 ~" w4 _- c' W% a3 U9 I8 m2 j' S#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } & T; Y2 p t" O" j+ K2 [. |0 s" u
5 o' r! ~0 B! |0 |9 R
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
& l% x/ y/ r5 z+ y# V1 v, M8 J( ovoid MD5Init (context)
0 A- C5 y, d/ S* g/ Z5 C; \2 _MD5_CTX *context; /* context */ / Z/ s9 T8 D$ V0 j
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
( W8 ?4 U9 w+ j. |) _*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 7 ?) g3 \ m8 a+ q2 k
} & T' x" _3 {% N
& c3 n7 A( r6 |" e1 N$ U1 T
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ ! m; Q M' n0 b
void MD5Update (context, input, inputLen) 7 e* V! j' I+ O1 ~4 U! _
MD5_CTX *context; /* context */
) ?' z3 x; ]# V& f) Gunsigned char *input; /* input block */
1 l2 v1 t7 U* Y, ~* tunsigned int inputLen; /* length of input block */ ! M- N. T8 f% P: n
{ unsigned int i, index, partLen; * u# N8 Q2 x- B* E' S X, B( r
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
- j% {+ x* b U2 j7 e/ V3 \ /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|