|
#include "global.h" 3 N; r( J, b6 _$ H; q. c" v' t) o6 |
#include "md5.h" , i. E1 E' d9 j
" r: l$ _ E- V9 w( H2 u6 L6 k/* Constants for MD5Transform routine. */
# n" H: D- A! o
0 G' ]9 ]! M% |9 i" G( V y+ i! n9 K $ A8 _9 ?! ]; p
#define S11 7 0 r0 `8 \5 s8 C" a2 H: i
#define S12 12 & s1 W1 J# X9 n3 v) f" V: K( _8 `
#define S13 17 & K, R( V5 x: } u/ i
#define S14 22 ; T1 |' b- H" C) m0 j) x2 ?
#define S21 5 5 Z# J5 J" l+ ?& L! A
#define S22 9
. {3 b+ L0 B) h# j. X% A& o#define S23 14 6 ?2 n2 I/ W6 ^3 O$ U
#define S24 20 & b2 y. O% w5 F0 e
#define S31 4 . m+ T! f. T/ T) K
#define S32 11 4 d1 N! L% P2 C( ~9 K L
#define S33 16 0 t; q& E) b* W6 x: Z! B! r" F, Y
#define S34 23 " c; |9 q* d- H, e
#define S41 6 6 r- y2 z+ k g8 p5 x; m. v
#define S42 10 z- e" x+ J& g; ]+ B0 B0 [
#define S43 15 : d. d; s6 g6 a: ?3 {
#define S44 21
! ?! f+ i: Y8 v( k O. {- J" Q' z
8 y3 _# X1 h2 ~! V5 D/ zstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 9 w0 Y. ~8 {, n/ o- W! I0 I
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
/ T3 P( v/ w1 s* `static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ! z5 T, E& k, V" ~. O% \" Y
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
2 u$ t/ p! |7 ?5 Y( M+ k3 Ustatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
% v& Q4 J) d7 a7 G
* u$ B2 L( l, G1 P/ P7 w2 Istatic 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 7 P9 K( L- u$ l6 P4 w5 t
}; 0 Y/ ~6 ?; H- p/ B1 L2 D; }5 _& ?. Z, z
2 @( E1 I0 [2 {6 q* G/* F, G, H and I are basic MD5 functions. */ ' H- X! V) B9 g
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
0 O; e; Q; ?" _7 Z8 y! n#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
1 i3 X7 I* T! L#define H(x, y, z) ((x) ^ (y) ^ (z)) 4 x" V. E9 h1 r* I8 l
#define I(x, y, z) ((y) ^ ((x) | (~z))) + q5 E% u, S4 Z2 W3 K0 b8 K4 |
8 [8 H) Z6 y4 k
/* ROTATE_LEFT rotates x left n bits. */
& r* S* R5 i9 q$ c#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
- K3 v. B) S5 X- w8 }# N 4 }' N. n8 L3 F
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 6 ]/ q, }9 }) @, J4 @
Rotation is separate from addition to prevent recomputation. */ 8 s1 r4 e9 h _' q
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 6 X7 Y f: u8 T) 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); \ }
' v( Y- O7 E7 A% Z3 P% }7 q#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
R" h7 h& G+ u- i+ X4 k#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
/ L. Z7 W0 c- p
* ?. R5 ?3 i( j. s8 X5 k/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ! r& W& Z9 W4 e6 @! n
void MD5Init (context) ( t) n$ J# Y: S0 f! @; F
MD5_CTX *context; /* context */ 4 S: Q: B4 Z: E
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
3 m& b; u+ I. L& N: F% k*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
1 ^; L6 z6 H& L- V' M+ @, A}
$ D# X2 l3 n8 t8 D) L3 o 9 D# r% h# Z$ V% C& e
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
! O3 Y3 S- ?% U2 v: fvoid MD5Update (context, input, inputLen)
' r3 `8 c3 N) A6 L) LMD5_CTX *context; /* context */
6 D+ f' s( f9 S; P6 R! p) x( bunsigned char *input; /* input block */ / c* Q& i% g; z4 Y& {6 P& {
unsigned int inputLen; /* length of input block */ 9 b( c/ t5 C- H
{ unsigned int i, index, partLen; . U+ _' k8 Y+ c& l: ?1 D) j
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
: ^: u5 q j' z) G /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|