|
|
#include "global.h" 3 I- |# H- u4 a0 G# a, O7 k U
#include "md5.h" , a( G9 L# P1 ^) p0 m3 o
L; }) X1 @1 K$ S6 s8 K- b# V B1 O/* Constants for MD5Transform routine. */
[2 n* [( X/ V3 v0 P" Y 6 A7 T, `+ i: S+ w) w# p" F
6 U2 ]8 u p0 L% \2 {
#define S11 7
% j& N' p- A- Q6 m( N: c8 @#define S12 12 . h- |1 C' b6 O) U( ^
#define S13 17 x$ |( ^/ ]" k
#define S14 22
- ~& {0 b! M9 } B#define S21 5 5 L. T# i3 s# ?. D1 R! h
#define S22 9
8 T4 Q$ z3 }* l+ @/ I#define S23 14 + e* }. A9 j, p0 P
#define S24 20
7 w7 R/ q, ~1 e/ c' `5 ]#define S31 4
0 I6 x( s' S) U b" y" b#define S32 11
0 Q3 O% {1 I' W) c# H+ }4 m#define S33 16
) z' f4 T o4 Z2 o, e: a( f#define S34 23
( W5 h% U" Q* s: J4 t* q; h#define S41 6 / }! i$ ]% P! |) S( H7 E" j
#define S42 10 6 Q8 A& H/ c* G" h) d" Z: t* K
#define S43 15 1 q" R' f9 Z Y0 A6 ~" X
#define S44 21
) T+ t( {8 |& e5 I# c6 L 4 g" ]3 z% b5 ^
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 9 u+ }: F `" }( x) [$ f
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 2 |1 t; n2 r$ Z1 t/ W
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ' z9 p' F1 i( E0 ]6 s9 x" m
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
* p6 C: H ~3 ~9 nstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); $ L, F9 u G6 H7 q) J
0 N/ n9 D0 q5 y* O: A; h/ h: P istatic 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 T% }5 L( F0 d% x( j
}; 6 ?2 h8 \1 m9 B4 f
1 t. p' B% t$ m9 E1 N3 U) X/* F, G, H and I are basic MD5 functions. */
2 G, G# u( G7 U5 |- N. y#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 7 O; r6 i. r4 f+ |* t/ X* j
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
% t6 U& X; z8 ?/ H! t#define H(x, y, z) ((x) ^ (y) ^ (z))
6 y: k. W4 z6 J, O#define I(x, y, z) ((y) ^ ((x) | (~z)))
7 U* b7 V/ F) U5 ` G( u/ Q T ; u1 R/ Y9 u. `" A6 d: V
/* ROTATE_LEFT rotates x left n bits. */ , V: n& S( @ i4 C0 P6 b' E
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
8 A! a' R) a* A' u5 J( @ F 7 C0 F& [: [: y* V N
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 6 [6 d" H% C z7 y/ Z
Rotation is separate from addition to prevent recomputation. */ : x5 q# R5 N8 p" o
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } $ `& A# h, l& w1 C% B9 o
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
: a$ q" D! v& E4 u: D+ k3 H#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 5 @# r/ Z! I+ h
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ) k+ x5 ]: b, m% }& h: s' u- x
7 O9 y6 h% H$ N4 h+ R) p. {7 Y
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
C l6 m2 N( O% }. S0 R8 D$ f8 ivoid MD5Init (context)
% z5 e* D& C; V' o: JMD5_CTX *context; /* context */
" a8 o( x7 O$ V# z9 [{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
/ C4 z$ d; A/ u' B! }*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
; g3 ]. K0 V5 w* V. d8 m" x1 a5 y+ y. c2 M} 1 ]+ T7 } T3 y, F$ C$ L
1 y8 z! J& r( M8 Z; u
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 4 }* @3 o% y' A9 k
void MD5Update (context, input, inputLen)
2 s' I6 c3 v* CMD5_CTX *context; /* context */
- e9 g. S3 g, v( c0 e( e* i: m( Yunsigned char *input; /* input block */ 4 g. D0 p# C, v- }
unsigned int inputLen; /* length of input block */
! P( g# G$ Q; A! x4 S" M+ g: c{ unsigned int i, index, partLen; # r4 y6 s; ?- F4 w
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); I3 G1 N; K" |# n R
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|