|
|
#include "global.h" : H8 i* U, y1 B$ P. _
#include "md5.h"
" w. i- u* b. _' q- v8 j ) ^4 s- C: P" P% W1 A. n6 M
/* Constants for MD5Transform routine. */ ; V4 X: p# |4 w# O0 A" m! g1 z/ P9 o
/ P% k% U- \% J9 a1 ]% p( v
5 ^: l Z. n2 ?1 V2 Q#define S11 7
% ]$ C8 |' p: V- d#define S12 12
" B( M- F# I6 A& |4 O3 ^#define S13 17
$ d% n1 N: j4 w x. d4 e#define S14 22 % ~2 k+ D0 p( p% U+ f7 d
#define S21 5 & ~ J. n, M. p! ^ H& ~* J+ c
#define S22 9 ) ?, T% i! O$ L$ J/ V
#define S23 14 " A, l: a! d, H1 N' F7 C. B. s
#define S24 20 / I$ {3 d! ?( n& y9 _
#define S31 4 9 V* G! [* x! u: t5 ^
#define S32 11 * L* z# o' Q8 |
#define S33 16
+ J8 W) `0 W& S#define S34 23 7 [6 A4 w% v) q1 k$ u
#define S41 6 5 \3 c: w# I( D' A& u
#define S42 10
; T# B3 u( B* P+ I) O" h2 n#define S43 15 ' X% B6 q* E" v7 f$ m$ p `3 ~
#define S44 21
; N2 ]: n2 R ~ x/ y3 g8 M: V3 _
( b" f; @8 y3 _4 w$ Ustatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
$ o' V% p$ J! f9 P" wstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
. j' l" S- ^ \! j6 S& Sstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ' |- h$ P& ]+ {8 Z! m7 a
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); ! ?7 b( t$ V/ M5 p# x1 ~6 N; N" ~ o
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
_& B4 s" S' n( f$ Y, r u
& d( T5 L+ t* t# t* c' r* Vstatic 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
2 J2 d' x ?- N% u& [( ]};
! l+ R' A1 I2 V- F. u6 Q5 s 4 x- q8 M9 B' \8 E4 C% ^
/* F, G, H and I are basic MD5 functions. */
% Q O" l. s$ g6 A#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
* ^# L/ h% |' F( J) c& r! z#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 5 j& _7 @: H% a+ s
#define H(x, y, z) ((x) ^ (y) ^ (z)) ( f4 b, {9 h6 Z
#define I(x, y, z) ((y) ^ ((x) | (~z)))
# m& W/ h* i. ?6 R 5 R9 O. t4 H& z. @6 T% e% r( @& c' \3 b
/* ROTATE_LEFT rotates x left n bits. */
7 Y: d2 D1 W& g, V6 ?# z9 K#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
5 l+ O8 ^8 _- e, P+ m
1 ^4 o( @$ {- \* d4 x7 l1 }/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
" N& ~1 f0 f1 C0 X5 c' {Rotation is separate from addition to prevent recomputation. */ # T. J0 n: J8 X* T7 G
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
) T$ ^* o) q' }% \#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
0 g' N6 s7 x \8 _* r) j5 g#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
) F5 l) D8 D- g#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
/ l5 e, v5 e8 P1 A 0 o' S) r3 u4 h3 U/ i
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
6 ^1 x( l# \0 x$ f$ evoid MD5Init (context)
- j8 E4 A$ h$ g) rMD5_CTX *context; /* context */ , r7 }2 F+ t9 ]4 u( Q+ I
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
7 L0 f" R- J# Z7 W; e& F. d*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; % I5 E7 h3 w) f4 x2 ^
}
1 p \$ Y! h! p$ M 9 \7 s8 X# a' F5 U/ z! h
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
+ \: U _; Z; ?- C7 ~void MD5Update (context, input, inputLen)
# z' {+ n! N! {: ~1 w" d: e% |* ZMD5_CTX *context; /* context */
( D/ U3 j f2 p# ]" P0 Kunsigned char *input; /* input block */
; X1 g, U' ~' E- i& ^8 S9 b" tunsigned int inputLen; /* length of input block */
; |' g+ t6 E- ]{ unsigned int i, index, partLen; ) Y" l t- u, n" h8 c
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); * \, N. ^: H. d1 ]$ h ^9 w6 `) z+ i
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|