|
|
#include "global.h" + ?3 c9 P' t8 @
#include "md5.h" # o% F6 H( A, L2 r5 L" L
/ z: z e1 X% L
/* Constants for MD5Transform routine. */ * S, q, F) a1 E. `
- u; T2 k1 E& [ 9 q: q& b6 [$ ~' L
#define S11 7
* T2 H* y4 {7 L" _ U, Z$ @' f! Z#define S12 12 4 W x/ P. L8 }7 P8 \ c
#define S13 17 5 W3 \/ j8 h4 H" g
#define S14 22
: C* v7 o1 d. q- x/ y' X: x( I5 O6 B#define S21 5
2 Y7 T# z+ J' c* ~4 F9 ^#define S22 9 ! M7 D8 I! W( F4 S3 ^
#define S23 14 4 {: T& R5 C3 g& p! Q: W
#define S24 20
; O/ N$ l: q3 P#define S31 4
5 n. s6 e$ s! I/ D#define S32 11
8 d% Q- l2 f1 z5 C3 a#define S33 16
0 {9 _6 ~9 x& M9 P1 v% g#define S34 23 # n# P* j5 O3 Q* M
#define S41 6 % U: `7 _" n/ N+ N
#define S42 10
$ Z* W5 g# L/ N B& m- ?6 s#define S43 15 # \0 D' C( ]6 b, t. D/ o
#define S44 21 f* I) x1 B/ o) _# [' ]
7 o/ o) v/ U) Q$ H; h8 W8 x
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); + k6 y2 b% A- P' P; _
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); & D1 c d: u2 q# M1 h( @
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
+ b" T5 t% O! q& Dstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 9 {& ^8 p9 u u; F* {/ V
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
5 ?7 V8 _2 y; p0 x4 \
0 t, j8 o% r; K9 I% C, r/ sstatic 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 ; p. G3 x6 b: {; [, |+ z
};
0 ~, L$ f+ r7 K+ v! Z' n . ]; T; I6 q1 }
/* F, G, H and I are basic MD5 functions. */ 7 X2 O. A P" K
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
" d" r& w# P+ E+ b7 V4 n#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
: o3 L z- C: _7 N& S% H; Y#define H(x, y, z) ((x) ^ (y) ^ (z)) ! |" ^- `+ \" N0 C' P
#define I(x, y, z) ((y) ^ ((x) | (~z)))
- i0 ~ `3 }6 f* n
- O5 _1 Q5 k/ a6 F" `/* ROTATE_LEFT rotates x left n bits. */ $ T& T, @" x2 U3 h3 h, v
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+ J2 o5 l' J2 m3 V+ b) l8 J
- Y) R3 f* l* v8 r3 k/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ! q1 C6 m0 z2 e+ O/ Q: f+ e7 W
Rotation is separate from addition to prevent recomputation. */ ' w6 P* Q" Z+ E0 r' G0 p# [+ ]
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
9 u6 i! `! q2 h. w& Z#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 Y- b4 ~; t. x( F r5 T8 E5 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); \ }
$ i6 @1 e1 W! h+ j2 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); \ } , Y3 h z3 `; k5 S' j
. c5 e1 G9 f7 F; R' v( E% q% {, W/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ' K% M3 f( X5 v( \; M
void MD5Init (context) - S8 c1 u, r0 j. @3 V
MD5_CTX *context; /* context */
1 e& b" E1 m. C/ o( o: a# G{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 6 I' L% t' M% W2 T/ h
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; + i5 G z: d1 I+ ^
} 1 f# |/ |" C) i# O+ o% \ _
2 Q# ?* @' a b4 h- }6 t/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ , Q% Z! E, Y$ ^7 g* P6 F' I M
void MD5Update (context, input, inputLen)
+ F+ s; K( b7 \0 [4 _+ C* VMD5_CTX *context; /* context */
4 ~* k% j% d$ f( Q% ?unsigned char *input; /* input block */ - ~$ d' y8 i, K2 P9 S
unsigned int inputLen; /* length of input block */ ! [1 |* J r. @, a2 E! V! Y* W' I
{ unsigned int i, index, partLen;
: q. ]/ E9 a) ~- m, i /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); & V0 I& P2 }4 B: z# ^+ c
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|