|
|
#include "global.h"
1 ~. s! g9 |; C/ ?' g) [4 j' G#include "md5.h"
( M# S4 E6 v+ @2 c1 g9 t: D4 @
. K7 B; x* @! ]5 N* |$ Y/* Constants for MD5Transform routine. */ 0 r6 \3 f% D) _2 C6 } J
% J0 V6 L, q. R1 n
+ B7 ^$ L1 o+ K& }1 Q* a3 _#define S11 7
* s+ q8 P) P/ t7 }9 Y#define S12 12 4 e3 {6 y/ w6 C6 c* ^/ C! f: t
#define S13 17
$ J1 b$ e7 k6 z; ?( ]#define S14 22 ! ?, n' M& Z" D; R
#define S21 5 ) @, f* `7 q4 ]2 \0 ~/ t" x- g
#define S22 9
Z. b, u4 S. W8 B/ E- a/ _#define S23 14 2 D U$ |2 @, m
#define S24 20 0 ]' @2 g& U5 [# j
#define S31 4
& L3 ]' j/ q! w& y#define S32 11
3 M; ?, w" `& s3 v8 ?7 a#define S33 16
2 `' D% X& x' e& B3 `9 ]#define S34 23 3 p2 `$ i r2 D2 u" H
#define S41 6
" P( l4 u8 J- T; ?0 [/ c#define S42 10 7 E8 `3 i; E+ w& j0 Z) S) _5 X
#define S43 15 & k3 u! f$ y; k$ I" [. r0 d& i0 `# P
#define S44 21 f3 }8 M1 ^# H/ O0 c4 D0 H
( U5 q5 d% Y& p$ x
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 2 u" D8 O7 H+ L9 c1 w2 Q* Z
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ) d, Z, _4 L: _3 |
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 9 H. ^2 q- |: p
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); , Y) D- I1 f# Q; s4 H
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 5 I& u; b5 P T! ^4 {
, a; \1 n( B: J4 T5 r) W4 ^3 ~. Q( ?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
3 x8 v& W1 L% d1 B};
% f% e; p; A U1 y% ~ 9 [8 |6 A+ h# x; L
/* F, G, H and I are basic MD5 functions. */ 7 L. }+ N/ r% y! \
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 0 J1 M* b& \; g0 N
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
% ]. `* Q$ O5 i- J#define H(x, y, z) ((x) ^ (y) ^ (z))
# S5 J! w) h5 G3 ^/ f" }; }#define I(x, y, z) ((y) ^ ((x) | (~z)))
3 {7 G/ q! r' x, R $ z8 B5 U( k; [! n( J
/* ROTATE_LEFT rotates x left n bits. */ B: p, j0 t [/ S' @) ]) w2 i
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ( ]- }3 U! r; v f4 v
1 U1 j# Z, i% c; J
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
2 U5 r7 e$ {0 a. f+ W+ fRotation is separate from addition to prevent recomputation. */ 3 M+ D# T$ Z9 y* N. ]/ A
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
* {2 [. k$ s! ?5 m1 \! x4 B#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
; g v! c& a7 h# R; o#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" Z; b4 [8 S) N* 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); \ }
0 E' ~" H6 K: x- P/ E5 { 8 }3 |+ n: _- f$ ?5 N6 ?
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
: o- l. G& s* m0 Kvoid MD5Init (context)
# s+ v, i( r" r4 r- YMD5_CTX *context; /* context */ ! ^$ C8 x7 v9 ~6 d9 p; Y
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 9 ?3 G7 N7 W" V6 F( n
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; : T# j! V; U2 H. {
}
1 z& u, f& O- k' \# @+ ]5 h/ g
1 U, ]0 s6 S" A! U2 h5 u1 |/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ / x+ \! R1 K5 {) Q. r P
void MD5Update (context, input, inputLen) 0 r& u, v+ m: V0 d4 Q; g4 x
MD5_CTX *context; /* context */ . H% H5 |: Q4 ?6 q* Y$ u' e! s; m% l
unsigned char *input; /* input block */ 0 E4 W- Y: n0 f- r+ n
unsigned int inputLen; /* length of input block */ 7 s) b2 \) c) ?" y5 ~
{ unsigned int i, index, partLen; 4 a2 m' w9 I& M. S2 ?* _. h, X
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); : V9 e! E3 @; o% x
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|