|
|
#include "global.h"
' v4 |; e1 r3 G: ?& T: T#include "md5.h"
# R8 V# g& }9 Y/ D 1 l% Q$ _! q6 P- h. o
/* Constants for MD5Transform routine. */ 3 v! G: X- l9 L' F
' l4 s5 q0 v& C: M
' n. o M9 B. o0 O7 b#define S11 7 8 ]/ U# I+ |" ^# I) |# R
#define S12 12
! Q& O# O1 ?; p5 \#define S13 17
. I7 j/ h2 n/ M0 |) O* y- X' q#define S14 22
5 ?: r& F; e K% ^* b* o! m, \6 Q#define S21 5
9 v1 C! v, A0 [8 O#define S22 9 & C: P" ?+ K5 V' `( ^
#define S23 14
- k9 o o$ ` z5 I#define S24 20
# ?# c* R% u. t; X; A#define S31 4 $ F2 ]$ E5 \% u# Z5 Z
#define S32 11
" \- _, H- L* [2 Z#define S33 16 ( I) u M8 q$ C; y$ a
#define S34 23
8 j( A% t# J1 L& [& j7 P) f! l% ?#define S41 6
6 n& G& G+ M, S5 I; s2 d# @#define S42 10 ' k& o' e k/ x8 p* S0 L
#define S43 15 1 `% r1 v9 ]2 {. u8 a
#define S44 21 0 J ^, a. |% o# \! n8 S6 K
% Q) \' W W3 U( Y/ B0 h
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
) U+ @9 H0 z$ ?static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ) l3 S# o, s" m. C" \# @
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
7 L* x4 `5 c1 r; P$ bstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 9 `* X/ i8 w$ C" Y, u
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 1 H) M; m9 B/ g( T* F* J% c1 `
* Y E9 G2 m* m8 }5 u0 Q) Astatic 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
1 t- B9 I0 B( {2 ]/ ^) X7 E0 c0 H};
4 m" B5 j, [- J2 a- u$ l/ B ; V! J \( G4 J$ |
/* F, G, H and I are basic MD5 functions. */
$ B, S( ~1 L. ?9 b#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
' W! ?$ Z8 T5 Z' L#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
# M4 \7 I( H$ F% A#define H(x, y, z) ((x) ^ (y) ^ (z))
0 N4 S P- L, E" j, }% [ x) c#define I(x, y, z) ((y) ^ ((x) | (~z)))
- P: a( p) ~, z9 `& T
1 k$ f& Z k$ D! _/* ROTATE_LEFT rotates x left n bits. */
/ x: ^/ s3 F: I ^/ X5 _: M0 S#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) & E. d1 w o1 Z3 _% l
7 b8 ?# w9 r( n t; g
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ' _; p$ H4 H& x6 _
Rotation is separate from addition to prevent recomputation. */ ! G9 I! b. \: Z# A9 N+ n" W" Y
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
/ Z7 {; ]8 M( w# h! A8 j/ s#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ' b" j" E! x- h4 P* h3 u0 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); \ } ; W. n6 M! @. W4 ~' f. d
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ! o: {" E' \% F/ S; O4 p! k
8 E5 u2 |3 I6 y! R5 `1 r
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 1 w( ] ]+ z' N. D( C; I- h$ d
void MD5Init (context) 5 u& f9 q; V: ]2 j5 \6 }. ?
MD5_CTX *context; /* context */ 9 Y6 _% ]& X! ^: n+ r2 r
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ; W( q/ W0 c) ?8 d, A, a
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
% [! X# Z% H2 ]! W; r% k: ~0 A. {} $ z8 q8 B0 E8 A
7 X7 h5 c" F2 h' C! s0 }/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 9 P: m: z% |. z
void MD5Update (context, input, inputLen)
! W4 K* u n- z1 i* CMD5_CTX *context; /* context */
2 M- X2 C9 ^) [: U, t) p6 Nunsigned char *input; /* input block */ 7 u H& x2 \* p4 ^, V
unsigned int inputLen; /* length of input block */ 6 B5 o: u' K9 N. C6 s& h6 t0 ~" F9 @
{ unsigned int i, index, partLen;
; E B9 _5 \. _ /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); / L' R/ j1 ~! v |
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|