|
|
#include "global.h" ' L: A1 {- o/ q: @- V1 b
#include "md5.h" 8 [8 N/ G$ U; p/ Q: f: E& g
7 K% x, D- }% g6 u7 P* d" r" A/* Constants for MD5Transform routine. */
) a* v2 m5 X K' O/ x ) x+ H( O1 S1 Q7 H
) S/ I& @ ^1 V& c6 P* X8 M& i' C
#define S11 7 6 x5 P/ K; S& p* f
#define S12 12 , ^" z% B; A( G/ ~ y) v
#define S13 17 ! D; x! P( M% k& [2 I
#define S14 22
* P: D6 u/ \. h' I6 L; I' U' G#define S21 5
p3 i2 m+ g3 F) v2 ]9 O) ^#define S22 9 - o" ?! ~7 S# M A# H
#define S23 14
- ?1 m: S5 H; _7 a7 D5 L#define S24 20
& A6 D' [. O( N/ @( b& R) |#define S31 4
" B& [# _0 @8 W6 B7 s$ P#define S32 11
2 G; j8 R3 Q0 _) U( t) v# H# q }4 D! Q& [#define S33 16 1 Z$ \3 _# z: q) T' C7 }
#define S34 23
3 A# c* ?+ I3 K! S3 L, x$ T3 ^#define S41 6
% `0 }) r2 i6 }+ t+ m) c#define S42 10 5 \8 i) L1 N& m8 H" h
#define S43 15
5 n* s: a; B6 N" L3 S#define S44 21 8 D9 ?* c3 a5 M% t$ o
* z. D) O) l0 n% ]4 @9 A0 jstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); " b9 _' d# F! [$ W
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); d7 Q4 z# [# e. X" j9 P" n% S9 a
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
6 t1 i& X# y, A0 L/ z( N, F! mstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
a5 G; M i* a1 u( {. J- estatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 7 y" v$ J8 r. [
9 r' [$ W+ G) P, M: u4 |
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
8 r- U8 S- n& i9 E};
* ]9 e \4 z& ~8 Y, l
3 D: S w! G4 a c/* F, G, H and I are basic MD5 functions. */
; u( v* i& Y* V. m" D#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 1 B9 `3 {7 }. G' |! V! I
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
. [. s9 h5 s8 k: o6 G% o# f#define H(x, y, z) ((x) ^ (y) ^ (z)) ; _$ C* ?4 U1 }3 u. i( i
#define I(x, y, z) ((y) ^ ((x) | (~z)))
) u' i) y$ _; B7 v) ]+ x % Q9 z- H7 y: K m
/* ROTATE_LEFT rotates x left n bits. */ . u4 W" |2 L6 y
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
( e7 b7 _: ?, W0 j- o
4 _8 \ _1 v) U1 S: x/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 5 h, P* r1 V; ?( T" f. @! u! ~3 b
Rotation is separate from addition to prevent recomputation. */ / _( n! B9 v" n8 S( G4 K& n% L
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" y" B8 j ]# R3 y6 u#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } / K4 x) {2 E) j$ q5 Z2 u
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
4 T' }. R5 q N7 R6 R" p, i7 b+ h#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
2 Y1 l0 F9 a2 l, m/ k" ]4 @8 O( ~
+ h# @4 X. i3 r1 S0 k/* MD5 initialization. Begins an MD5 operation, writing a new context. */
5 m G+ Z/ a8 s8 K' x* s( dvoid MD5Init (context) 0 M! o& n2 M- d5 g1 @
MD5_CTX *context; /* context */
7 a' i: ]- F: u* C{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
6 Z: e$ b7 T/ K. \+ x3 \ Q*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 3 u/ h$ U% \" z/ q
}
1 t) y9 ~" E0 c; c - Z: |* B# H1 Z
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ " p/ f' L V$ ~7 g( z
void MD5Update (context, input, inputLen) |9 b# B5 a& q0 j# u
MD5_CTX *context; /* context */ 5 f8 G9 G5 N9 N2 L3 ~( t
unsigned char *input; /* input block */
\4 a! j' e: w2 e6 i. Qunsigned int inputLen; /* length of input block */
$ D5 Y( V* C- O! W0 C! P D{ unsigned int i, index, partLen; K! f7 a8 o$ w" ~/ i# b
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
% s1 Z' A! e: K6 m E- ?0 o /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|