|
|
#include "global.h"
1 v6 x1 I5 Z% c6 F: u4 R2 }#include "md5.h"
& \' u8 F; p2 c3 y ! ^4 I C2 z; Y7 ^/ K
/* Constants for MD5Transform routine. */ * h' g0 @! C: y8 j; V0 y( [) Z
9 M3 l! H8 j4 A) ~! \. M& S- u
4 X3 U* m1 b+ |5 t#define S11 7
0 d9 ^. P# ?+ |; _2 o+ \#define S12 12 / i# o. M4 R ?5 L
#define S13 17 + f3 u8 N* ^$ S5 s; u& G4 L
#define S14 22 8 n) m0 ~3 @4 L Z8 u4 W a; X
#define S21 5 0 _- T! v) b. h" e
#define S22 9 ; U3 a; p+ x2 b0 h L# E- w
#define S23 14
! W) t/ }5 ]' Y#define S24 20 5 F7 i% u/ ?4 L9 d
#define S31 4 % \8 i6 I& K# u; F/ K
#define S32 11
" z0 [! k b0 E6 K/ ]" d( \. }! D#define S33 16 8 r Y2 ^" K, a( ~ y! v6 S( c
#define S34 23 - o/ m+ ]% ~+ l: {
#define S41 6
" W1 ]! r8 s! N8 c#define S42 10 , w( j, V% {. }; \# A' n7 f
#define S43 15 % B) M2 l8 X- |" O( f
#define S44 21
2 J) U3 n( d% L' z4 i. i |; w: z% r9 `( x; ]; W8 w
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
% ]3 s) n; M& |9 p" J. C7 ?* ]: U, Hstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
W' ]0 ]( \) istatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
% [& v" ~; }1 xstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
/ Q4 ]3 g8 t5 o0 l5 c7 Sstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 2 Y% @- H |- d( l$ u+ p$ K
% O' B. m- o, A3 f# Y4 Z& h+ S
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
. z# |$ u9 z$ Z7 I) l/ z}; : }9 V* D2 b. {! x6 n/ ]
/ F% @2 S7 L8 W9 C8 A3 w' _' z
/* F, G, H and I are basic MD5 functions. */
2 P8 M, d& M. I9 }#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
* u4 S/ i/ Z* b9 ?#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
0 [' E1 p1 O- C/ l% v# m#define H(x, y, z) ((x) ^ (y) ^ (z)) & T5 p3 R! A* T0 }! ^
#define I(x, y, z) ((y) ^ ((x) | (~z))) ' }1 U9 a: W: z& R1 L
Q' a6 v( M8 t6 x5 F9 V/* ROTATE_LEFT rotates x left n bits. */
+ d- _7 n* L+ p4 [& P#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 0 r& v7 d& y8 a! V
: _4 c% H3 Q% I' R& c/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
; o& l9 a' J- ]Rotation is separate from addition to prevent recomputation. */
8 ]3 C/ y' e/ b/ ]4 w) u# f#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ( R& Z$ r8 O8 ^# x
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
: }3 c$ Z/ U! j& s#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } C) U! O* C) V* b) Q/ F
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } & X" B2 _: \" k1 F
, @4 a" ]5 t( _' a, v
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ / v! j9 n: }1 C9 }; G3 S: M( [
void MD5Init (context)
* X6 p" W( K: k$ p- _MD5_CTX *context; /* context */ . _ v% [* z8 m* ~9 h9 u
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
5 d' P( B4 V4 t+ T1 _0 E: j7 b7 |*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 6 z) ]0 c$ d `; g( h) ^# u
}
; `4 V. k8 m7 \; u; \( X; i( ]+ d 3 Q: T$ C* h9 W: @. Y- i- z
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ - c3 W" @2 I, r
void MD5Update (context, input, inputLen)
* v4 `$ S' {' U6 [$ G, D' Z6 bMD5_CTX *context; /* context */
4 ^% V" S2 ~% n5 Xunsigned char *input; /* input block */ $ f' {0 J9 q, u( q0 H
unsigned int inputLen; /* length of input block */ 2 c8 v! J+ A8 O. O
{ unsigned int i, index, partLen;
1 r) C/ r6 k3 @ /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
& r+ g* @( \% ^& }9 G/ P6 B /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|