|
|
#include "global.h"
3 f; H% h/ Z. j5 y#include "md5.h"
6 x1 t; \! E3 d8 C, u1 o6 t& R, G4 j
4 E6 D0 f9 F+ b- P3 K& w, F+ [/* Constants for MD5Transform routine. */
G" X, Y% h& O v! e
$ s* m7 g9 _0 M/ D- o4 ^# V+ m0 s o/ J4 r9 H" w3 ?: S4 ~4 @
#define S11 7 & R) ]6 X. G$ h: F: | {
#define S12 12
% W- l# `! L8 h+ ?/ H- r: Z#define S13 17
2 l% B( K' v- p; L1 i) f, \+ s( ~#define S14 22
. Y$ H+ Q( |! e, H#define S21 5 ; o! g* _. I* _7 t! {+ `. e
#define S22 9
+ y9 B2 ^* X7 C" p9 h#define S23 14
: I! r' u. o N) S( W8 |- y: O6 a! R#define S24 20
3 N7 G A$ O" \3 l: }9 O( H" p5 ]( U9 j#define S31 4 ( ?$ ^: F9 ]* x9 t( a7 _
#define S32 11
% `0 {/ d, y4 _/ q/ K" K7 w7 k( B8 |#define S33 16 6 W0 Y* }+ }. f7 d6 A. c3 N
#define S34 23
1 P C1 {4 y, B! j% Y( ?% Q C+ U#define S41 6 1 d Q4 ]# s" I. i: q1 d$ Z
#define S42 10
& {7 D- m0 A) @0 [6 T! j2 g; V$ Z$ E#define S43 15 / o' I6 L1 A6 D% R, Y, e
#define S44 21
1 l& d5 A: V* r# a" ]( V9 N
* q/ G9 Y8 `' Hstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 6 R! C* i% J3 U# V
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
; q R7 T7 |& B. m& ~* s2 P* Fstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
7 {6 }: q O) Z& s( wstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 5 ~, J# y5 K# p; ]! h
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
2 U' o8 }! N" }0 u4 X. X
% F$ v2 U1 u* p! @* Dstatic 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 Y, h8 r: V3 ^! A' Z};
, [8 ]; c0 L# [1 h ( k: A/ M M* O7 R
/* F, G, H and I are basic MD5 functions. */ ; ?7 _- x: J* O: u( K2 G
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
( S* p- t4 W Y# f" J7 M#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 1 o5 m8 [4 [6 ]* J! X# r
#define H(x, y, z) ((x) ^ (y) ^ (z))
! o! k" |: \, P* i#define I(x, y, z) ((y) ^ ((x) | (~z)))
8 V% S" u: A& v& j) U' ^
1 E. C( @8 `/ h' r/* ROTATE_LEFT rotates x left n bits. */
2 P) g& G; S1 Z: P' T#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) * L Z' K# [/ K5 ?% v; W
! }8 A& k# G( E) F8 G/ C3 L/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
' b/ f4 \# M4 `/ @4 S8 h* GRotation is separate from addition to prevent recomputation. */
% t" t- l6 a3 o# H6 z#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 ?- o9 A) i( v( I#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
' h" L$ K# }* n% _9 K#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } * L' y" K3 b) k) Z8 N5 P' q
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 z* R8 H& b) E9 L3 l$ C
& T- `+ d. m0 q/* MD5 initialization. Begins an MD5 operation, writing a new context. */ : v+ s# j; o$ G. { s7 t% k9 ^
void MD5Init (context) $ U8 U; u* E/ k2 G7 p# V7 p% B5 \
MD5_CTX *context; /* context */
F0 p- ~8 ]) Z4 L W, U8 n- Q{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. + _. ^3 {9 W( P1 H3 `4 f
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
4 x, q( x/ G0 q! n: Z}
; b% t+ Q8 B1 ]0 J3 }3 A0 { . F0 A& x3 [" Q# ~& S
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
" {6 A) t/ P% x: d% r& Tvoid MD5Update (context, input, inputLen) 1 m- z9 n g8 V7 j% {, t
MD5_CTX *context; /* context */
# m3 @; G4 e* Xunsigned char *input; /* input block */
: v* \8 w, B+ r$ M7 q" kunsigned int inputLen; /* length of input block */ ! j( h# W/ ?4 s4 `& t6 O; M$ j
{ unsigned int i, index, partLen;
, v$ I' u L+ x+ V' S0 X /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
# r# ?4 w. {3 ^5 _% k /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|