|
|
#include "global.h" ; Y( U: N) D. j! D* Y# L: w& t
#include "md5.h" ) L2 X0 S) L5 L, r7 W' J
. p# K5 _3 ?. r n- ?) }1 M
/* Constants for MD5Transform routine. */
* r2 I6 D* ]4 A$ y, b/ q- v& ?
- a; |& z$ @/ l& @( p+ Z . U% u5 t" }; N. L* s7 P
#define S11 7
$ P9 Y3 Y5 s. b- \/ x#define S12 12 * e% n: F( x8 C1 w( x
#define S13 17
9 [9 z8 c6 o E$ F5 `#define S14 22
. H5 Q: L, S& z4 ~; D#define S21 5
' a, y0 F+ }9 e$ h#define S22 9
6 M( @! U7 n4 v8 w1 R2 T#define S23 14
% {6 Z' d+ k9 z6 e$ X+ n. v#define S24 20 . J; [0 e$ F, C+ G
#define S31 4 0 V) I2 H& E7 }
#define S32 11
- L. @. g8 |2 b* U) I& b3 |) g#define S33 16
: l5 h; w& x3 g" e- g2 m8 @( G#define S34 23
% R0 r/ G4 Q5 z D2 _. j0 g#define S41 6 6 e! R5 O3 l2 X& y+ F
#define S42 10 7 _& k0 l4 V( u$ H t% X3 _! o5 v
#define S43 15
* C: U7 d3 [: S#define S44 21
( L t0 J) e& N% ^+ F; X! r
" G3 A2 F4 }- U* zstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
5 V, F' Z! k& b7 M, [% Y$ ?- rstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
8 `' ^) h( ], b$ ?& \# W1 astatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
$ h1 L. s. h) l/ H- Cstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
. M' F% g9 ~1 X. gstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
6 T6 m/ u N% e0 R
; `7 R$ Q; g# Y& @; [% tstatic 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 % P% ]2 r5 l3 d- M" Y7 ?
};
D f a- _# v% `4 m$ z & g' c( p% W5 y" I1 C; p# w
/* F, G, H and I are basic MD5 functions. */ * L3 q C7 t) b) V0 _, j
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) # K( e8 R- Y$ |9 j" C
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
7 w6 l5 R; v. x* }+ |8 Y#define H(x, y, z) ((x) ^ (y) ^ (z)) , y: G7 x3 V# X/ a1 p- r3 V9 q
#define I(x, y, z) ((y) ^ ((x) | (~z))) 4 n9 p1 r0 L# }6 U" X4 `
; o8 x& @7 m' M, m
/* ROTATE_LEFT rotates x left n bits. */
- c& F. B+ v _- R! a w4 h/ r#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ; R1 {3 B! j. ` u8 H
0 {" |8 z* f- k) [8 T! {# J
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. & W) |( G5 g$ z& |& u8 A# U
Rotation is separate from addition to prevent recomputation. */ ' p6 a+ C3 y3 z0 v% ^) M
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ { U( ~) y7 X4 @ p#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ) S3 p4 i7 |" w
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 6 a3 F- V- \' A% [! T4 ^3 t
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
- d& Z$ j; X/ X0 R' p q
7 C# P" S. ~$ E3 m# O, y# Z/* MD5 initialization. Begins an MD5 operation, writing a new context. */ + T8 r: Y/ B6 ^
void MD5Init (context) 9 z7 @7 d" T9 W! g
MD5_CTX *context; /* context */ % N; r3 A" q# {
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 1 Q/ b5 `7 l; E$ ~* X" w
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
3 c4 f- d* r8 }+ o: b} % W% }7 a1 Q z# A1 a) d0 b% a
( a e ~0 i9 {& T3 u: G# }
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ ( P( S9 U) F. g% P7 x+ e1 [
void MD5Update (context, input, inputLen)
9 b( d# A) i+ c2 C, }MD5_CTX *context; /* context */ $ K/ }3 L2 {- k: E" L
unsigned char *input; /* input block */ 8 l) ?) r8 ~- W+ F# B( k& W
unsigned int inputLen; /* length of input block */
! ?' Y$ E1 G' x{ unsigned int i, index, partLen; * Q8 x, J3 f; m8 J! ^4 M* Q- B
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); / \' d& X' K/ D# U* ?# G& H* c
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|