|
|
#include "global.h" 1 U, z* i- y; o |6 g) W
#include "md5.h" K6 Q0 Z0 P V# g
7 G" ?5 C+ c, q( M" s$ P% M/* Constants for MD5Transform routine. */ 3 o% `0 V/ T5 v a# r# H; o
. x5 r" o& R+ ]7 V2 M O7 b: S8 y/ w, \, x3 L( [
#define S11 7
+ b0 g1 b6 ~4 Y$ }- z; ?#define S12 12
- L5 D& B0 |. h. n! R! n! I$ b#define S13 17 0 L5 W7 I2 G( P+ F4 J, j! _
#define S14 22 / k" U! g' }7 z( R4 V
#define S21 5
# [9 d7 W, f- r4 Y1 Q% a#define S22 9 * L' |) t i" q. M7 m! v
#define S23 14
0 ]+ w3 E* N8 \" y3 j& e. A#define S24 20
( i. G5 U* c2 H) }( j! [#define S31 4 ' F/ A; k) i: N! n8 r
#define S32 11
% G3 s2 }5 G0 t, S7 Y#define S33 16 " i% w5 n |+ j& m8 ^. f$ ~
#define S34 23 3 f$ H# H' u5 e( G9 \
#define S41 6 . P, s/ t1 A6 E. Z' K3 O
#define S42 10 $ S. F7 i: p* j8 y$ l! t
#define S43 15 2 f5 s8 X( h `4 i) m* J7 l6 u
#define S44 21 1 \% o- u) |% h6 z# G
. h1 W, y" l f9 pstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 8 q3 Q& T; b0 i! `+ J* N1 b
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
+ G9 H8 u/ q& {: [. U; ustatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
4 ~ t4 b0 E; x% U8 D8 {' cstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
: u3 s6 n s) ]- i3 U& A" w* Jstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
, Q9 x3 U9 X. N. J! ]) u
3 w% Q8 n/ f0 K, G4 y( xstatic 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 W) U' U6 O$ O5 N6 P
};
. [+ j5 _; V, u. n 9 Z& k' F, W8 k1 q9 ?9 ~ v
/* F, G, H and I are basic MD5 functions. */
$ ?+ v) t; u4 a8 Y% t3 N5 F#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 8 c- Z" Z3 n1 e6 P9 [+ @2 R# l
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
4 r2 R# J& H, l. p#define H(x, y, z) ((x) ^ (y) ^ (z))
) U; U6 O* a) B* B! u! J. S#define I(x, y, z) ((y) ^ ((x) | (~z)))
" Q# D* H9 G' d1 F8 d4 h( R2 v; h 6 O5 M" s8 n3 T# O9 H
/* ROTATE_LEFT rotates x left n bits. */ ; \1 o' L* p8 R8 ]7 d0 A
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) : R% m3 {9 ^. F4 }' {
7 u9 n1 J: s2 R T* ]
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
5 |# x1 P, h9 U1 R$ IRotation is separate from addition to prevent recomputation. */
6 e }; u2 s, C# g& i7 B2 @% @#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
5 }% {+ Q3 ^. N% F- w! o& b4 S#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
/ @1 \8 x8 C' [/ a, o, I6 K#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } * T# `5 ]: R( a+ v& e3 y* Q
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } e5 L% g8 U% o
& W7 r0 ~6 Q9 ]: o4 r/* MD5 initialization. Begins an MD5 operation, writing a new context. */ - ~$ Y3 g' \$ l
void MD5Init (context)
) S3 C7 ]$ Z/ @MD5_CTX *context; /* context */
$ ^5 Z+ U: U4 N) z. ]9 E{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 7 D# y/ D7 x1 d7 X
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; * |, A# Z" ` s9 T" U1 P; X
}
3 j' q% G% w! @5 a% w3 b
, z+ r, D3 p4 T/ m; W% g2 R% O w/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 5 @0 W, d @3 Q5 _( |: Z
void MD5Update (context, input, inputLen) 3 s. z0 @' N& W
MD5_CTX *context; /* context */ & I3 ?- f. a' _" L
unsigned char *input; /* input block */ ( }; g, O' X- p, v, ]. E- V8 X
unsigned int inputLen; /* length of input block */
3 C- y9 c' U2 y' ?{ unsigned int i, index, partLen;
: v. H( S/ I o# m) g4 x /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 3 p% @# A/ o3 P- {
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|