|
|
#include "global.h" + k, U3 v$ ?7 L4 k! Q
#include "md5.h" 4 |; o7 c1 _+ g1 k
( t. U$ c) ^+ @6 l% i0 D
/* Constants for MD5Transform routine. */ - j( R$ N3 t5 _, \/ V! G, `
( ]) @/ N* S' a1 e3 P5 K
, c5 y7 Y3 S" S3 J+ E#define S11 7
: t! v. B2 j2 l e# m2 s8 O#define S12 12 & l5 @1 H$ E& Y8 a7 V3 j; }' E
#define S13 17 9 U8 {) O8 c4 C* B* J! E/ [; f: f
#define S14 22
, \" [. g6 {$ @#define S21 5 & R D/ i$ \% e; Q. n! y1 k
#define S22 9 $ z6 E& T9 b$ ~8 p6 w F! n0 ^3 R
#define S23 14
* f& t7 C3 @8 o1 a: K# V/ r5 ]! D#define S24 20
% `1 l% r: R7 _ T#define S31 4
& Y/ Q3 f/ Z. {2 R* W# R#define S32 11
! K1 s2 D; M* s7 ~4 F" ?#define S33 16 - {+ a$ y( L1 h9 g3 @& Y
#define S34 23
% F: k) H) L, l& R#define S41 6
1 }/ y, W& O- p( [2 {, @( r* i#define S42 10 % E& t, `; V$ J3 j
#define S43 15 . Y2 I* [5 t/ Z5 B
#define S44 21
# }- I/ n4 j7 G5 M+ r5 o/ L% e ! J( H0 }- n$ {/ y1 k
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 4 ?# q3 V% a, q7 U! M( l
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
* y7 P, ?( o7 ]" P* w8 k; |( Xstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 4 v3 P: i" L3 Z, V+ W
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); ; f% W; t7 }. n, o
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
$ E9 A; X, a# ]% {- X* L ! L4 ?5 T: h; N9 F' \) \% L5 p; g
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
* j7 D: l1 L. b* {& H9 @( H J};
8 N ?5 O1 M \) i7 v9 J9 e# L . W0 ?0 A: ~4 {
/* F, G, H and I are basic MD5 functions. */ ; O# Y7 o* f8 Q! K$ n
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ; g) G$ x( ~' O0 X% t5 d: s
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) ' G8 i: H; Z8 t" D2 S1 }$ O
#define H(x, y, z) ((x) ^ (y) ^ (z))
/ E9 L4 ]9 M a2 G a+ U! s#define I(x, y, z) ((y) ^ ((x) | (~z))) * j/ T* v4 u* G' B, N) y
' F# W& {2 B) l/ q1 H* r: z/* ROTATE_LEFT rotates x left n bits. */
" b- a: k, F' @/ o#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ) V: X$ ~# E L' f0 S2 p
1 }. J: K2 X1 Y0 A9 a2 H/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
* U2 t& u, S U0 E* s& U: h2 rRotation is separate from addition to prevent recomputation. */ ) E! P- _9 M! D9 U* 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); \ }
- U1 m q7 A+ n3 @. x: 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 a0 j1 H% S4 Y5 a5 W: u
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
: ?" q0 R5 V! I, O6 U+ Y#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } / Z) N# E1 y0 t2 M4 t0 P( q
1 E9 D! r$ Y, G2 X8 T# j
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 4 k3 m( p' B4 K R
void MD5Init (context) 0 ` }4 G5 o. o& J4 |4 j7 R
MD5_CTX *context; /* context */
2 e2 h- L6 u" F$ o/ v' M* ?. S1 i{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ) E7 W& d: u5 c1 |
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
1 P! o6 s& s: [6 R/ A}
, M. \# m Q' t5 F5 M
4 N" D, G; w( [2 |/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
8 @" x4 j2 g1 G8 X) U1 O, q4 Avoid MD5Update (context, input, inputLen) 8 b0 | A! c6 S7 o p
MD5_CTX *context; /* context */ , c9 U$ [! k F7 V( X0 o
unsigned char *input; /* input block */ : o% i& ~4 Y% U" C
unsigned int inputLen; /* length of input block */
4 d1 ?" V. b$ P2 T{ unsigned int i, index, partLen; ( \8 n' Z9 Z, d% @
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
9 v8 t+ b: v& Q. |( b; q1 Z) A' Y, H /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|