|
|
#include "global.h"
+ f7 j; O9 o- w5 e8 l0 o" \, H#include "md5.h" 1 q# b( a# i1 I6 z( ]1 c
+ E$ \( m' L/ A" h8 q- @2 Y( U+ O) R
/* Constants for MD5Transform routine. */ ; R$ V! }: N A9 Y1 S
; ^$ {$ o* j9 ^6 I$ p
" l0 q/ j+ v5 V8 q0 ]/ x% H w#define S11 7
8 d* F, G. y$ p! I% \4 x#define S12 12 ( U& v5 j0 w, v( E. P
#define S13 17
F8 _9 w* ]* H; D2 K' T/ `7 l#define S14 22 ! h; l/ r" E( N' E1 U( c
#define S21 5
' m, g% @$ p1 `#define S22 9
5 k4 [. ?' [! a; b#define S23 14 j( p) w+ g: l- r
#define S24 20 3 i' |- ^9 \ F8 q
#define S31 4 - [% w9 f$ w* `5 g2 R
#define S32 11 / J/ L) H7 ?* K" E
#define S33 16 8 y: [( F% J2 ?' }8 Z
#define S34 23
0 P* B2 P9 }4 T$ K#define S41 6 , A) i/ \2 k- m5 C7 J- Q+ p& E
#define S42 10
9 f6 i6 S2 i9 I% y' Z% J#define S43 15
3 g+ e9 i4 ]( G" i. P+ o0 w#define S44 21
& y% w1 V* T4 Y % Z7 E3 b0 }6 a
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 1 K; V8 p2 B4 d
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); & \' n/ q M; a2 y% h% s
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
3 ]7 ]4 x$ E$ rstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 2 ?# B* x6 I: o4 G z
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
5 S; z; W. J# m4 z0 P) Q- n ' ^# @$ P, C- R% y
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 L5 |8 e8 h! |% J}; % J) y9 v3 D0 c2 ]
0 O! J' w! R( X5 |, C/* F, G, H and I are basic MD5 functions. */ 5 c$ V$ U6 i5 W4 N. Q
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) g* `5 ~9 j$ E. C6 ?* Y4 k
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
# N3 {5 i: G# G/ B0 |- I#define H(x, y, z) ((x) ^ (y) ^ (z))
8 u; \) m; n- b* l7 |#define I(x, y, z) ((y) ^ ((x) | (~z))) " t$ K: m* o: k
# q/ H$ |& m) W6 V( E/* ROTATE_LEFT rotates x left n bits. */ : F. Z8 @& j8 G% ^
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
, k7 K" t L& o( B 4 D% J- n: I' |$ X8 X, L
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
3 S- e/ T" A$ m1 z6 x* cRotation is separate from addition to prevent recomputation. */ ! }& P4 y1 e4 F$ O* S Z
#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 e( ~1 g0 T+ G; {, J#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
/ {2 T7 M0 I1 B#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
# U3 B0 e+ |( N#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
) Q- E- k( `/ p6 n
3 v4 e% K+ h1 T' o: Q. s/* MD5 initialization. Begins an MD5 operation, writing a new context. */ # @. A! a: e3 ~% Q
void MD5Init (context)
3 Z. V P1 ~3 }9 o2 SMD5_CTX *context; /* context */ 5 y: z1 u( W: b+ G U7 ]
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
) a3 L2 X, ~. v0 W/ s! K, o4 E*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 3 P' K; U3 g- ?
} , c+ ~* e' q, [
" s$ {6 w4 @5 o
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
" j. i" W+ K' Z& _7 b. S' Zvoid MD5Update (context, input, inputLen) & I e2 {* K. E$ r! w7 t4 p
MD5_CTX *context; /* context */
6 r ]: P* t* Junsigned char *input; /* input block */
$ S1 Z: t5 t& yunsigned int inputLen; /* length of input block */
# }3 A9 ^7 L5 l. F3 \1 e{ unsigned int i, index, partLen; # `+ q5 h0 ], }
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 5 x. x2 c) l. F; r4 H
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|