|
|
#include "global.h"
* }1 `9 A6 }# X, x) b0 K#include "md5.h" + `- ~, j5 n w9 M
9 p4 f7 `8 e% |0 s/* Constants for MD5Transform routine. */
, O* Z9 g$ h5 T$ U - |- s1 n2 U, v0 i
: Z" E9 f6 B2 D: o3 N
#define S11 7 0 o! y& `: \! }- A1 K/ n: \- x
#define S12 12 ! k) o! j# a' D
#define S13 17
( p2 O F9 I7 ~' a6 V#define S14 22
% `! L5 E$ w2 A- n( O#define S21 5
X0 F; y1 Z- M; D* p% r1 D#define S22 9 " A+ K h, [' Y$ m" N$ Z% n: |( M. u
#define S23 14
7 r7 |: K$ R+ w#define S24 20 ( ?4 }, ]6 [& V6 a O+ D, P
#define S31 4
9 v' g& t3 j+ y7 [- ^( }; d: r/ D#define S32 11 ) r' Y" [- a7 W7 w0 H. w, [% \
#define S33 16
: ], p" e, w# ]( S#define S34 23 ) g- D) J8 p! |0 i& o
#define S41 6
3 b" C9 [; Q7 k" l. D) S) c3 {3 r#define S42 10 ! c: D$ R2 `+ e
#define S43 15
" p# R& ]/ q* i/ r#define S44 21 6 D3 d+ T$ Y: p4 Y3 R
( @' S# k+ H( k6 v( }9 q; Bstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); * X- [0 j( S1 F: e: o
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
9 z t7 E/ ~5 z( R+ x# Ystatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
8 ?. _4 x0 e7 a; Istatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); ' O ?" Q1 E* w
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
4 d7 M/ H( R- n! g! B( t 5 ~9 w& P5 N" s/ h3 d* i
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 0 u# S; B" p0 `/ U9 n
};
8 Z; M: u/ w0 ~" S - O: K* D t* r% ?& `: k N+ J
/* F, G, H and I are basic MD5 functions. */
/ { _* D; n0 H#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 6 J! A6 Z) v6 o. B8 ?9 z* O
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
0 q% ~1 I5 |# A7 ?#define H(x, y, z) ((x) ^ (y) ^ (z))
" R# w. b/ s# F9 @8 K+ z#define I(x, y, z) ((y) ^ ((x) | (~z))) + `% {0 I* a2 J. h: P
% f/ D& e# ]; u* a6 n+ i% F! I
/* ROTATE_LEFT rotates x left n bits. */ & P& `. O! l/ I' H$ o
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
7 \# ~& Y) \+ E
* F& e, E1 y& j" @. l/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
* _1 ]) \, ^, t! i1 k. \8 LRotation is separate from addition to prevent recomputation. */
i( q5 b+ k; N8 ^" q5 m#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 N: H' }! V8 ^* o! x6 {: c/ l#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 R+ S( k1 l! r4 X- J# B( W* F
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
$ M5 j9 W2 S, \3 O#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 4 H4 W5 E8 m) u3 m6 h- f2 H$ D, R
7 b- Q# K6 }+ L; M3 G( u/* MD5 initialization. Begins an MD5 operation, writing a new context. */ - K& Z: k5 W- F+ `: g/ Z. y; t: y% l
void MD5Init (context) + B4 Q$ Y* c" F) e4 m& p' B
MD5_CTX *context; /* context */ : r- F" S, R7 l2 T" k% |
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
% v( T2 |6 |) i2 G b! \*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; # ^$ M! p {* _, S# A3 a0 ^, u
} & _2 }; b! b- u" E& z
0 x9 Z0 ^, K" c4 L ?1 H
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
9 F( ]/ y( W: \$ }; _9 xvoid MD5Update (context, input, inputLen) ! b2 T1 o4 l# p5 i% J# n
MD5_CTX *context; /* context */
" E1 S7 j- Y! z3 d$ w$ munsigned char *input; /* input block */ % D( H g5 O. r# I& u2 E' N
unsigned int inputLen; /* length of input block */ $ W. X! Q/ r9 s: L0 i
{ unsigned int i, index, partLen; ' ?8 }% N! a# l3 d+ q
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 4 \/ B% V; c5 C
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|