|
|
#include "global.h"
4 V6 @. h' }% B% s1 }+ f#include "md5.h"
# u. n- |5 x2 F0 x8 P, w7 k p
4 q$ z( u( c/ z; Y, _/* Constants for MD5Transform routine. */ $ B9 M5 m8 j% l9 }7 N+ C& i
& E- _/ ^9 Y4 n+ A ! d2 a) \1 _7 [
#define S11 7 ) n. v8 S# h( T9 H8 `) z
#define S12 12
3 @; E5 X4 ~- }3 W#define S13 17
) l U2 y8 d" ?# c7 a5 ]#define S14 22 4 k" v) |3 a. Z X# `3 r
#define S21 5
! z- m3 r" p7 q b#define S22 9 , h9 i% Y0 o l8 @) {, S
#define S23 14
7 N0 [, F- L' S* u2 b' l& e# V#define S24 20 4 M0 L5 t& `) E" `
#define S31 4 $ n4 g. L9 Q0 O' e8 D! @
#define S32 11
( Y5 Z7 n3 v% u0 d8 S#define S33 16 2 q r: V5 D! c- X& a+ X
#define S34 23 & x3 @ Q* K) ^2 |2 m
#define S41 6
4 S4 r) ?4 U% `- `- G# B#define S42 10 0 M2 m' P0 U% m! T1 z# m2 {
#define S43 15 5 l$ R# h% R6 i# Y: w& q
#define S44 21 ) R/ q% c4 Q' ^5 [; n+ g3 G" R# f
7 l& ]# m; a N, x- [4 L
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); - _! n5 m9 y+ ]
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ( W* |( P& e" |7 D% J' A* w B2 U
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
) H. I: X9 ^8 y% X) M* Istatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 0 S4 x. [' X- e& ?, I& `
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); & L7 p2 u0 ?; x+ T0 |
/ S& i* z0 y" Y& r/ ?# Q. t: _7 Y! _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 / E0 m# \6 v1 ~
}; % \' x) _8 H+ }8 u# I3 N! ]" u
5 w6 `% K! q- r: m1 j" F3 L/* F, G, H and I are basic MD5 functions. */ n1 |2 i5 T; T! [
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+ a& q; P7 z* X#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
( ^7 ~% d) u* U3 Y9 W# Q#define H(x, y, z) ((x) ^ (y) ^ (z))
9 \" e( R5 `& E+ @1 O#define I(x, y, z) ((y) ^ ((x) | (~z)))
' \" I: A z* M0 v/ P0 i
+ b7 g7 ]: q( Y6 A j6 `/* ROTATE_LEFT rotates x left n bits. */ $ \( v- j# b3 M, K
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
/ |' ?, Y3 U" k6 K 8 E+ s8 q2 c4 O
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
( j1 }4 j# w# |6 t, k$ cRotation is separate from addition to prevent recomputation. */
" N3 A# _' i$ ^ c#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
) Y2 Y! n: v$ \#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
4 A" `2 x# x1 e- v#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } + {; U5 w1 G! Z) O) [8 L2 _
#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 [. i/ N1 O0 A1 Z9 ^
+ y, |0 e$ s8 l1 B. M/ H7 J' E/* MD5 initialization. Begins an MD5 operation, writing a new context. */
8 D; \1 o& t8 Svoid MD5Init (context) 6 M% S8 C: F+ S: b& k" n
MD5_CTX *context; /* context */
2 [! Y* h* J# y{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
: D) i( a. P- o*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
: p3 |0 X) Q, J; q# w4 O7 |}
|% ]$ [! m, B, B8 f 5 A# d9 j1 r: C1 R
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
3 S8 h5 h: ^- D% kvoid MD5Update (context, input, inputLen) * F- \- L: g% [8 w
MD5_CTX *context; /* context */
! e% l. b% d$ T3 _: Bunsigned char *input; /* input block */ 4 J0 R+ U' A! x1 q
unsigned int inputLen; /* length of input block */ 8 E% p" T( }6 J1 `' y! u8 W
{ unsigned int i, index, partLen; # f; a1 y2 o+ e& F7 q6 J
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); / h0 L. a o" v/ w \5 ?! C0 V
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|