|
|
#include "global.h"
+ J: _/ j/ k1 p1 O, u+ f' V. V#include "md5.h"
/ l! \) v' U" f2 `% d - G/ Z) T0 o; X/ U) Y6 y
/* Constants for MD5Transform routine. */
. A4 w8 _. l* Y8 B* K& @" u
* _$ k7 C/ L5 q% }" y% F; z: m) P+ E " @7 ^. ?. J& R e
#define S11 7 3 @" B M5 ~2 g2 e E+ ?% ?
#define S12 12 % t! M, E6 f% P1 ~& s/ e- W A) M
#define S13 17 * J: v& K# B# F% q- d9 i; j
#define S14 22 " O; C3 O7 Y" A: V! Y) F& d
#define S21 5
, x1 {5 U4 K1 {#define S22 9 - i1 k6 t+ k9 @. m' A
#define S23 14 : o, T) m8 I A* g+ s
#define S24 20 & J$ n4 D) N$ \# J( j8 E
#define S31 4 7 `% P) E$ n! e& A2 C
#define S32 11
% Y, o: D1 |" ]6 ]; L#define S33 16
6 S$ O4 Z! _9 x) I8 H0 ]$ t. _#define S34 23 ; Y( Z% a; M* O$ U" u4 k
#define S41 6
# T& m5 R, T5 {- D5 q" U#define S42 10 4 U0 ?* _' \( d/ M8 ?5 T
#define S43 15 $ ]4 q7 V# K: d
#define S44 21
8 y1 g& T; n/ G$ G& ~" I! @
/ q( \/ f) m" W) j& v/ Xstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
! B& E# p9 Q0 Lstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
& o% V6 A& j0 Z! [ y. a' kstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); / Z) o8 T2 M3 \+ S B9 n
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 4 n' U2 \) e/ ?+ k P
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
' y! e- S( g$ Y8 q. O# x+ C% g/ j6 ? 4 @* A) G: F4 u8 e* i' J! B
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
5 l6 E5 L0 d4 X};
" n! z9 i' l# P8 {/ L* |8 M" U
4 [' K5 i$ J' k5 X/* F, G, H and I are basic MD5 functions. */
) f m! Z7 P% D! [#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 3 k' T9 A" x$ `
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
) O, C/ l+ M* z. V+ x: l" F. o#define H(x, y, z) ((x) ^ (y) ^ (z))
% _/ X. B& T3 ]3 j: }#define I(x, y, z) ((y) ^ ((x) | (~z)))
" `* w4 v) |$ f7 f0 @; q; l+ V& }
6 j; Y- a' V9 m8 I- K/* ROTATE_LEFT rotates x left n bits. */ # t7 i# \* T# B% \' T! q, l6 D
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ' w2 p+ e1 m$ _8 O
" P6 ?: v- N/ r: E; Z/ b/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. * T6 P: l" C2 O8 w1 D
Rotation is separate from addition to prevent recomputation. */
7 u: k Z, ^" p, t# A* G$ _#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& L8 I% t" z2 ~3 F#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
: d2 Z: p+ \4 K3 @1 f: G& E/ 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); \ }
/ f J3 C( N. v/ u#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
0 F. o0 A1 Y g# C ! P' \2 A0 F; Q0 P
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ - t \3 w6 a! S
void MD5Init (context)
3 ^, @: k# k! ]+ ^! Z. EMD5_CTX *context; /* context */
% u6 l) x: I* T6 _{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. . [5 }4 a% [6 G( N1 ?. ^4 X
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
9 R2 X' @4 h9 D; s- ~6 h} ; @4 j: Z0 D3 J' J
% T/ ]- Q5 w: C+ N, O/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
5 V, a; s4 F, p/ m' v7 Yvoid MD5Update (context, input, inputLen) ; }. K$ s& C6 t; W7 e
MD5_CTX *context; /* context */ " i/ e9 U* a# D1 j2 x! l) |) Q* d
unsigned char *input; /* input block */
( F2 ~) q) q9 ~2 Z/ ounsigned int inputLen; /* length of input block */
& N) d: m4 n0 y{ unsigned int i, index, partLen;
2 U+ ~' J- A) a' }" }+ l5 N /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); - K4 U! h) w; s, _' i# r' `( z! I* r
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|