|
|
#include "global.h" 8 C/ S7 [9 p$ i' i& K+ w
#include "md5.h" / }8 W4 w1 o ]& V: G& [9 D7 h. H
- | m# J. r6 O( S/* Constants for MD5Transform routine. */
4 Q0 |$ C/ ?% a0 @% d
! c& r8 ]9 b7 X# b0 X/ \ 5 `' w$ V }8 W
#define S11 7 ; u( i( F$ M) ^# k; x! e
#define S12 12
V# Z' T0 r2 B; r |; N3 i+ Q#define S13 17
/ Z3 b5 N( z7 x& ~3 B#define S14 22 p5 \, I1 {, {; }, D0 K
#define S21 5 5 X' x* S, F$ c- K) @& p
#define S22 9
3 ^4 I; @: ]2 O+ J) c: ?/ f#define S23 14 1 ^7 [* q% Q2 m' ]; V; \
#define S24 20 : R6 o9 A7 R3 Q
#define S31 4 3 {, X- H0 j+ Q( h9 z% s- {+ ]
#define S32 11
1 v2 N( c& R6 S5 r. Q1 _#define S33 16 # h0 B0 e. `9 H0 M2 K- z9 C! q
#define S34 23 ! o" j, D: {1 \2 g9 t. t% y$ }" g! u
#define S41 6
) e$ N0 O9 G: n$ u1 c#define S42 10 5 x% P) u; ~$ k8 B }. m
#define S43 15 : }' P( B" q* t6 ^4 ]2 E
#define S44 21
& B; u4 F0 f3 k
: v" W0 w8 W/ R: M, ystatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 2 ]0 i9 t9 W5 B: j0 G
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 0 n4 E( w6 r+ k! N% z6 D& z s
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
$ [* P# C+ p7 f) J7 Jstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
. j. l0 I$ m( \' V. u& @. |static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 1 `3 k$ [% ]* d/ F
& C- _3 Q8 n1 i1 y0 R' G8 C
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 + |/ U1 g/ e2 T* x. h
}; & D: v$ k- z; U# C& r. ]( B
5 Y6 S" U' T6 Y4 C. \8 F5 i/* F, G, H and I are basic MD5 functions. */ 3 c. e3 b; ]" f7 W: x
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
% y2 a1 t% T) Q! I7 @% q z O7 W#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
( v9 ?0 }" p- q#define H(x, y, z) ((x) ^ (y) ^ (z))
/ z# T1 V( K$ W* y" u5 p#define I(x, y, z) ((y) ^ ((x) | (~z))) & }# k) v$ O. f& [8 o j) g
+ \% n* d7 r) E/ ~" s8 h- J- e/* ROTATE_LEFT rotates x left n bits. */
4 J$ y6 H. g6 P( c$ m9 p#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ' z! l" z) Y% ?: w3 a
3 D, V( }2 e, ]$ I2 \7 ~+ O
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
% S6 L3 u( a7 q# qRotation is separate from addition to prevent recomputation. */
' \) f# U. l7 W#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 4 N% B% s/ C4 w c" 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); \ }
2 w O, o1 {0 ], 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); \ }
5 s1 s% F5 d- R- K0 w#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 V% K( V, C7 f0 z
& S! }4 \: P ]2 E7 L* v) x/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 7 k0 a) R$ M* R
void MD5Init (context)
9 O; G& @ p/ M3 q% ]% xMD5_CTX *context; /* context */ ' R1 Q3 K: @8 A) f
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. : L% a3 U2 k6 J6 S% Y7 @
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
7 b8 o5 U, D' @0 x s+ o- K} 7 J$ I+ S" z( e$ K5 i) n% ~2 Z
4 m6 L# l& N& K, s# I- y/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 6 y4 G; I" l T M8 h# P
void MD5Update (context, input, inputLen) 4 H5 W; G/ f+ E
MD5_CTX *context; /* context */ 6 v9 Q% W% J9 V) m/ L U) B7 R
unsigned char *input; /* input block */ ) G+ ]" ~6 ^- z8 c* y5 E
unsigned int inputLen; /* length of input block */
+ F+ z2 J/ g" z: h# M5 Z3 H+ R{ unsigned int i, index, partLen;
1 |" r( U% F) F O: | d9 B8 s /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
- K. z* Y, z2 g6 A9 X /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|