|
|
#include "global.h"
9 S* x6 g ^7 w: L$ e4 w- E#include "md5.h" - V4 H; y; ?$ |6 n, X
$ e: \. A# s3 t' W
/* Constants for MD5Transform routine. */
5 C% s7 @/ N/ K8 W# V
: r) a& P9 m& S5 b& ~/ Y7 i
4 l* s( `1 A) V4 O#define S11 7
5 W% R& G3 o- I) V9 M9 ?3 s#define S12 12 ; h% \( k' q* s* F4 O0 n3 w
#define S13 17 / p2 y1 y O' d; Z. a, j* U
#define S14 22 0 ]* X' B$ J8 @8 E7 l
#define S21 5
4 u: E/ o1 i! F4 u" U8 C5 c#define S22 9 6 l2 ]* G' i$ W0 H# _% l$ w8 V
#define S23 14
% B0 ` b8 J5 ~0 d2 P#define S24 20
$ N) R# @8 v) u#define S31 4 5 |$ C/ k) I/ w( y5 U8 @- b) G0 h
#define S32 11
- u, |# @1 i: k9 ~. Q! ^! }; i% \#define S33 16 % y5 Y2 }5 {9 F. G+ f5 V8 o, Q
#define S34 23
1 k8 U% c/ d7 U# s( X: L% w! ~% A#define S41 6
4 v" V- h! [) f3 [' G/ @4 O#define S42 10
# o* |* K0 T/ h: i( |* F#define S43 15 0 @) r; i+ V6 D
#define S44 21
+ _7 }, O: q7 d" ]9 I6 \2 e& T0 U
+ X$ y: {, f% i c5 vstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 5 f/ Y& e8 L/ C2 O& O
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
8 U& E8 J i$ ^( s2 l3 F- Y( ?static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 4 |) r+ T$ k% S$ m* U
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 3 n2 G1 q' p6 B# M
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 8 u9 N0 k3 U( ~! d, Q
1 I# U, i. _8 r: A) g- l
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 + T& k9 X: ?' f" y4 l
};
7 X/ V/ Z, @; E; {2 X0 K 3 B5 r% k; H3 \; l: T
/* F, G, H and I are basic MD5 functions. */ & ]6 z! M. ~1 ?1 S- S8 K
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
! |2 X4 ]/ h5 S' ~0 r. Z; Y#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) " J F2 \& S0 q
#define H(x, y, z) ((x) ^ (y) ^ (z)) 7 I( K+ G1 m# ?% L! v, W
#define I(x, y, z) ((y) ^ ((x) | (~z))) 0 m; l+ q& w- z% c( v O
" L( v; h' g# m( a& j5 I
/* ROTATE_LEFT rotates x left n bits. */
" P8 N& E5 f3 N. ~( ^" s8 T" G#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
: q j* T/ `, C2 P & C0 H5 v4 }8 [2 m
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
9 L& _/ `2 s2 }' J" Q9 |1 L* |Rotation is separate from addition to prevent recomputation. */ $ g; H/ _' G0 g' X+ e1 P# [ |
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ( }$ y7 ?0 N+ Q- d0 A; u, _
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
; [: D4 K( f2 V8 B* G, G#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% @1 J4 s' c/ r ~#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } + ^2 k, J% a9 M2 A7 a! U4 |
/ @: I6 k. J. X" b; b/* MD5 initialization. Begins an MD5 operation, writing a new context. */
* J! \$ k i+ c- Dvoid MD5Init (context) , Q- j8 x+ z5 M9 s6 u! ^
MD5_CTX *context; /* context */
& _8 k8 o8 y9 z7 g0 [{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. $ S. J8 n# u; ]: S# p. p
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 5 k. p/ j# l( I" X t
}
- ]- z" P) ^8 { a7 Q8 t ' d+ c6 ^6 u7 I* N- y4 t0 l2 a- ^9 l
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ . x" J4 {* P0 o: x9 |5 w
void MD5Update (context, input, inputLen)
! i E4 C. S- Q) f; bMD5_CTX *context; /* context */ 9 u' I# ]& f! R
unsigned char *input; /* input block */
! H. o& p* c! }unsigned int inputLen; /* length of input block */
- F7 v6 d& b( |) w{ unsigned int i, index, partLen;
. c' o2 z, q w9 | O }- J /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 1 h+ O8 C- v3 b! \
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|