|
|
#include "global.h" # ?2 |/ v7 z7 m" D5 V9 M
#include "md5.h"
2 ?6 f: V# p/ u5 }$ f) S+ K ( k# l3 Z( q8 {
/* Constants for MD5Transform routine. */
% G4 d- u& b" F6 G5 R/ R6 W: h 5 m! s! m- `/ Y/ A
- v8 b: B1 c0 H#define S11 7
# {: l% S8 `6 w2 ^0 o1 W#define S12 12
5 G& L2 K5 s" O# z#define S13 17
5 q3 e: s! G% y# o: T0 K#define S14 22
7 ]8 n: l7 r$ V" s ~- m#define S21 5 ' T( [$ [% o n) x* s5 S
#define S22 9 4 t4 @; q9 p' P
#define S23 14 : m( `* M- v( d6 a/ v! a3 y
#define S24 20
1 }* m( l5 x) Y: w+ \: ~#define S31 4
6 I6 }7 s6 t/ D a3 a#define S32 11
( J. D) o* R8 Z8 a* |0 O' e: P#define S33 16
2 A1 V2 p E6 T* Z#define S34 23
* W3 h& ]; J( ?#define S41 6 ! m" r! z5 ?7 P, R
#define S42 10 9 W' g8 \% K) Z. p7 @4 v
#define S43 15 0 @+ t c& o* a2 j. x. N1 L/ Q
#define S44 21 ) e* b& U/ I5 i$ Y
, x0 d( _1 o k1 q; x: B' `8 a
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); . |8 q) b1 p+ ~9 e% q" n
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 1 @! }8 E- { v
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
* ?& g# H4 f5 b+ istatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); + Z. J* r3 Q7 `' y6 O1 u8 |
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ! v# X& {5 e* [ z5 T. } J, D
+ c, s! l0 c% D3 r8 b8 |5 M+ d
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
: E+ @3 W, y' J$ T7 R9 E ^}; ! o1 K: ^% l6 \" ]" N
. O7 z( M* z+ h8 T8 c9 P
/* F, G, H and I are basic MD5 functions. */ - H2 Y3 B. e/ J' l2 [" ], S& C9 V
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ) Q h' S0 J; X0 a+ n7 i- ?
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
# b. y. r- N5 n' s3 [; x#define H(x, y, z) ((x) ^ (y) ^ (z))
" _7 P, _4 H* z& W2 A#define I(x, y, z) ((y) ^ ((x) | (~z))) 1 A& \" u, p I) V3 n( Q( ~; d- n
8 d1 Y" B$ X6 P% S7 V# e
/* ROTATE_LEFT rotates x left n bits. */ , I& ~, y$ Y: x0 m2 Z& U: j R
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
" U4 r7 Z9 N) W! C+ r$ X
X2 w" T/ p! y2 y/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. " x2 k6 z/ ?& N4 G9 l
Rotation is separate from addition to prevent recomputation. */
( U) }7 m7 p4 \0 E; d#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 T% @: S' P4 Z3 O! V9 K
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 Z' A! t3 ?9 w' 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); \ }
( ?$ ]. K7 Z- o. x3 i* 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); \ }
, l7 V5 @6 g7 L' I/ A9 V$ a 3 T- C/ _. ^- }# q) |
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 5 w3 x, ]1 [3 H0 i( K# \3 \- u
void MD5Init (context) ' Y6 b% {* R) U) w
MD5_CTX *context; /* context */ ' j' i# R3 U. A$ c; S
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
0 Q7 B8 E1 v& h" x4 |2 \: h*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
: t! `# L m$ O, b4 v" w* F}
' l! l) c" `. D9 e( Q; @% _
2 `$ n1 z$ E5 F' S. W! u/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 3 h* g. }! m$ B: ]2 b
void MD5Update (context, input, inputLen)
& g8 N b2 Y% ]( w+ y/ }MD5_CTX *context; /* context */ 9 G) m$ |: [! ]
unsigned char *input; /* input block */ $ U, q6 t1 x `/ q
unsigned int inputLen; /* length of input block */
# l) D9 c1 A3 n1 e{ unsigned int i, index, partLen;
' o2 T# Q2 s! z9 g1 H/ k /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
, D5 G0 I& i0 _: `4 `, d /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|