|
|
#include "global.h" 4 B' j5 { Y; \2 U3 h+ g
#include "md5.h"
& A$ M$ M& E8 ]2 a. [# I
: ]& r$ n* u5 W5 k$ [" Q/* Constants for MD5Transform routine. */
0 w$ \5 n8 Z/ W$ d6 c; D U/ Z
* q3 }! E9 E+ A" M" n- e & w8 Z+ w4 a8 Y, \0 n# n
#define S11 7 " x1 S {. A. b1 a' U- O$ G: k9 S
#define S12 12 $ R3 Y, f$ ~9 L; _2 r- A
#define S13 17 % k. N2 w3 s2 U2 P- X
#define S14 22
E3 Q8 P. M0 @$ o#define S21 5 7 A! a9 a9 g+ |: G z
#define S22 9
8 I( H5 Y/ P3 P2 d! _3 P- {" |3 d Q#define S23 14 F, b0 ^/ o4 u7 d+ j
#define S24 20
& G5 K8 h( e0 h6 q b0 p3 G* H#define S31 4
0 L( ?/ L& x, h. u1 x) F5 T, s8 P#define S32 11
, t* ~3 y7 B* W; ~#define S33 16
- a7 G9 w7 m4 `" z#define S34 23
8 @1 T9 t6 ]3 s$ ]#define S41 6
% U3 T* `+ _" K4 D$ ~5 y2 p" x, J#define S42 10 ) J6 D; v+ x) C m, _5 {1 k
#define S43 15 ) U$ T4 m+ u' K1 f% a
#define S44 21 0 u9 c) d" ~5 s
/ F; |5 ]$ Z. K; Y" f7 |4 s
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); % ^3 {5 G. N1 x- x
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); A F2 Z4 m$ \" U
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
d) G- R* H4 e. e6 ~. Cstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
( n7 o! j" L# x1 a) L: N( _static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
+ p( e- z8 g+ H2 A3 `/ n
9 K" q2 C* P. X5 @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
" h3 [+ j0 `' r( l% [# B2 X}; " W: g" p) x) o; r; j
( U6 H; ]" t9 o3 J. h" k. Z
/* F, G, H and I are basic MD5 functions. */ % }; T$ Q* F0 W2 Q8 I
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 4 c2 j+ `: f3 V
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
2 k$ n6 `" L! F2 y#define H(x, y, z) ((x) ^ (y) ^ (z)) 2 u5 r4 I3 l5 E, @3 Z* ^6 s8 E
#define I(x, y, z) ((y) ^ ((x) | (~z)))
4 ^ z I. p( A4 E* l6 i9 v
- n% B) N: q! ]/ E0 L5 E/* ROTATE_LEFT rotates x left n bits. */
) C8 {/ Z! ~1 N% F3 t& U8 V! S#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
$ T7 j* P4 W( l p0 T
1 E: q: H% Z' [/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ) t5 S$ z+ M+ w! B7 ]
Rotation is separate from addition to prevent recomputation. */
& S3 j7 \, i( K1 I#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
# X; Y; e+ Y: x. I& T# w9 ?#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 7 N% e1 C$ |" z% [' C1 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); \ } $ t# k0 z) m2 Z8 ? 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+ q( m% j; a! a
1 H, j8 ~# ?, o( m; Y% f/* MD5 initialization. Begins an MD5 operation, writing a new context. */ $ F4 a, a. p3 G4 S$ g8 h4 @8 ] v
void MD5Init (context) ! M5 U6 G/ n0 A0 O! _+ o
MD5_CTX *context; /* context */
% \& ?8 Q. e* }: ?: u{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 4 m8 }9 A$ A p. ]. {# L1 b4 r
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
! [* C. O% Y6 D} $ Z% w" H& m5 h: s* F
) s7 [6 f3 ^/ T" H9 b {/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
1 @3 N- q3 p3 a6 N2 Z* cvoid MD5Update (context, input, inputLen)
4 w0 }1 C4 |- {8 K V9 B0 dMD5_CTX *context; /* context */ 4 d# D& p+ J- r9 V
unsigned char *input; /* input block */ - r' a* S k3 M c0 ^0 l# ]* \1 @' v
unsigned int inputLen; /* length of input block */ * n; b1 ]4 w4 ]+ ~" g1 X
{ unsigned int i, index, partLen; * \; R5 g' A' C: ?; x
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 4 c# n: N1 Z5 {- U; d
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|