|
|
#include "global.h"
& f* ?1 j5 E T# A# B#include "md5.h"
0 }) f- C* L) m
& _1 J! l$ }! W/* Constants for MD5Transform routine. */
* X0 q5 r% k. `) G% g; M0 i - X: e: b w& f/ x' _* _0 |
0 F' H9 I6 N& v& r2 X#define S11 7 8 u6 W) U T/ l0 Y
#define S12 12 + v+ j+ e" M/ B1 a. A
#define S13 17 S2 x1 _5 ^; E) F
#define S14 22 6 Z* }& V9 C1 ]7 U: y: ?% n
#define S21 5 8 |7 e. z7 z P5 n0 f
#define S22 9 + X6 ], J n, z, j% s! J
#define S23 14
+ r# r+ u" f: M. A5 ~( H5 C7 O#define S24 20 2 p, C5 n. {0 G/ \/ N
#define S31 4 " p6 ^% d! r. T2 \) E+ F
#define S32 11
9 q4 t$ v5 P& X1 R0 P#define S33 16
$ k6 W$ G4 k# H7 E. g/ u#define S34 23 , H( y, r& v5 _5 T* }
#define S41 6
" U# w9 I: j. D#define S42 10
$ t r$ l7 I; i v( I, ?6 ]# ~6 P% n#define S43 15 + _9 c7 A5 z3 e: a; w( R: m& q2 x; B& X
#define S44 21 / b' C' u# j; o% N/ ?, z
2 Q" P/ a2 z' z; J0 W
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
) l4 c! c* L/ k! p' S+ _7 \: w# Sstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
+ X1 T8 ]% }0 @6 O3 E# r {4 b4 Mstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
I9 J; `4 P& l5 }# u% `8 Tstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
! W- T" ]. e5 Istatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); , E% [- Y3 C* {: H! K
~) ?. C: ^1 M2 ?' z U# l
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
6 c9 x: X" @# ^% A};
, E& @# p3 R+ ]0 u. k/ x ~& e. h$ P/ \' w+ H* R
/* F, G, H and I are basic MD5 functions. */
. I& ?, ^) x7 ]& |* C/ v6 I4 J#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
0 Q4 J" K2 i" P& Z+ x9 Q0 D#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 3 O; ~6 Q0 `$ S( @7 V( M
#define H(x, y, z) ((x) ^ (y) ^ (z)) 8 v8 q! a6 W8 w' j0 n- N
#define I(x, y, z) ((y) ^ ((x) | (~z)))
' m, C/ h2 ^3 \8 f 8 d" B5 m! z4 A6 V
/* ROTATE_LEFT rotates x left n bits. */ & i* R. p& ? W
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ! B( ~" H% U' P- L
5 `$ M" h+ @- r: Q c$ u7 @/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
: n, j! B2 }1 k3 V; C: b/ U# F+ ORotation is separate from addition to prevent recomputation. */
5 f7 g; z( K4 i#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
7 W- U- l8 G% a5 H7 R#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
6 v f/ B5 q H( v4 a5 c# K1 @2 v#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
# n. j1 W- v3 h& s L6 N, J3 h( B#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
$ L' I# W1 t$ ^0 o Z J8 s
# x% o1 T) S: z; E" y$ j1 a4 W/* MD5 initialization. Begins an MD5 operation, writing a new context. */
3 [& X( R4 V9 S/ P9 f( E Bvoid MD5Init (context)
9 s1 b' i, `6 \$ uMD5_CTX *context; /* context */ , b* Z* x# Y* Y5 a
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. . q( s0 Q5 a& Z. M7 `& F+ N% {, v
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
3 S7 ?$ I- Y2 c% S; R! r} 2 ^: g p2 p$ H) a- Y- a3 c/ U
h2 S. i9 ^: p% w) ?" V
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
) L# y9 c, t' p7 T5 dvoid MD5Update (context, input, inputLen) ) {. _) o' k; V: e' p0 i; O
MD5_CTX *context; /* context */ % Q) u- g2 P: ^& u
unsigned char *input; /* input block */ 6 ~ P; E/ N) F( ^% l% K
unsigned int inputLen; /* length of input block */
G" D# T: K% X! S{ unsigned int i, index, partLen; / u1 M% |, o2 j n7 j
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
5 f; k+ n6 a% D$ e& D /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|