|
|
#include "global.h"
+ g) {& M4 F5 A4 o#include "md5.h" ( O, k7 c2 g; }( Q, ^& a
* i2 d Z' F, v5 r9 A1 m
/* Constants for MD5Transform routine. */ ! G% O' o) `9 b0 h) {: w
* [) H+ L$ P. B5 {1 X & M: d. ?( a; s- _) A2 g# _
#define S11 7 ' S7 ?; M9 n D$ G o6 u$ ?
#define S12 12
5 C# L! m: M- r$ `& p& p% f3 x#define S13 17 ; o. g9 ]( u! w2 B" Y* v# v
#define S14 22
, u6 C3 C: t$ J' A7 M$ f#define S21 5
2 q' J8 x0 U* }* q$ ?! A# l#define S22 9
5 k. z. w+ z& A% m. |/ V& `0 s#define S23 14
5 Z8 J& y9 i; i3 y( g" W$ y( ~" [. a#define S24 20 3 h; e* a) E' k: G' ~2 J
#define S31 4 ; H/ r7 O i5 j0 z3 @" `! P0 @
#define S32 11 : f1 m7 \2 t' e! q
#define S33 16 " A6 M- ~3 a" @" i8 N
#define S34 23
" l# b: b* S; t D9 r3 Y# s#define S41 6
5 Z% l- f* U7 P#define S42 10
, a9 s! s: J% j3 G' }#define S43 15 ! ^; s0 Z( ]# ? t$ B# ?- J
#define S44 21
d+ d# Z1 b8 N) G, g# i$ e
2 f3 L; z6 O0 q4 t9 a6 m2 xstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); , q3 L: x; A! T( {3 N
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
+ N% S( V& K% G( H) b) N8 zstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
: v8 w' q. `3 I* }static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 4 W- U/ x) g7 `( @3 U2 f
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 7 ]. l8 l" R4 u' c1 s
/ s: H0 ~8 a. h: R9 e: p& b9 @/ k
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 ; i) i/ o7 L& N& k6 R
};
) Q/ |* s7 t9 {3 c9 E0 @! I" g
+ g" ?5 Y$ S! j$ q/* F, G, H and I are basic MD5 functions. */ : u0 m z) f' w7 w& q8 W9 Q- Y
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
# N4 R5 C" t" e, H8 M, q/ d#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
2 W: Z& o/ \ u#define H(x, y, z) ((x) ^ (y) ^ (z))
, N |* \1 W2 [6 |- L#define I(x, y, z) ((y) ^ ((x) | (~z)))
. v8 }8 m+ a% O- D' Q
# h0 x0 Z x7 F" g' V+ |/ w/* ROTATE_LEFT rotates x left n bits. */ 0 }- I( W' ]! u+ R# w; @
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
2 l ]. q. j5 b) \2 r1 `0 X8 u
, L4 |( U* d/ t/ I/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 6 t- m0 N/ g& v' ~
Rotation is separate from addition to prevent recomputation. */ ; u% K9 l8 z D) k
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ( E: E. c4 Z1 Z
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } % t" S: d& d) E/ X4 K: D
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
, g+ b0 W8 {! U" j z: n#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 6 ~* N3 d2 P) n5 M, f* \# |( J
5 D' s$ E5 y; u8 p
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
* n P+ y4 N4 b5 f1 Y: Gvoid MD5Init (context)
6 O% a8 `* |8 M4 q- eMD5_CTX *context; /* context */
% X( H1 e6 M7 e9 C( _- N: L{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. - N, X- H5 d# h: A" M ^
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 4 _; h9 O/ Q+ X+ Y; |
}
- X) o/ w( Y g% A8 V$ q0 y4 `. T
F. f, Z7 N$ ^3 n5 {/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ ) |$ V3 ~' f5 z E8 f- S; g
void MD5Update (context, input, inputLen) * h" B, [) S1 }& J' A$ }+ g( y& {
MD5_CTX *context; /* context */ / E [+ N4 s) _4 ~8 r
unsigned char *input; /* input block */
0 O! ], F( \9 n- |' f8 Munsigned int inputLen; /* length of input block */
$ G! y& N) s8 g: c% z0 b% l. c{ unsigned int i, index, partLen;
. C0 B& a) ]( i2 `( A, M /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); - K4 C; a3 h1 L f# T6 ^
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|