|
|
#include "global.h" 2 ^, P0 _0 v: C" V
#include "md5.h" 1 J6 y2 m A u
4 O) y% K) N# v2 ~) M& p/* Constants for MD5Transform routine. */
% V, [, C- Q" U; _# T 1 [: X k3 X4 o6 o5 z
2 g! V2 q2 T; y1 O) U, j#define S11 7
) ~9 U+ J3 Q/ t) H2 K: |2 W2 {! B#define S12 12 6 Z$ M3 h# I w% T$ D7 E" U
#define S13 17 : X6 L+ V8 g4 k4 x2 D) ]* _: O& m
#define S14 22 2 ^& b3 T- |4 P W# d2 U
#define S21 5 ! T- W9 a" E. ^4 F# U' z
#define S22 9 ) ]3 k1 i) _1 t- e& j
#define S23 14
, D6 N2 C' e2 c! X* Q+ X* t$ J#define S24 20
" F: C& c9 t0 p' N* Y9 k* q#define S31 4 2 { [2 Z! g0 e C! _# h$ t
#define S32 11
/ H) Y% @ K8 s2 c#define S33 16
+ _! [; b7 ^) q#define S34 23 9 q" {7 r5 I) z# V( ~5 U
#define S41 6 ; y2 n8 a& K- j# s; |9 N. T6 v$ O
#define S42 10
6 q5 y* e8 ~: k% Q* N$ Z' r$ m#define S43 15
% E, I; A, D5 X$ K2 X#define S44 21
1 ^7 p _- r, D5 s, Z. E : }1 I4 M% Q0 z6 E
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); $ s0 n+ o0 V8 i- p& w2 v
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 9 x# O c6 M* i" y T
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
+ b* N+ Q- u* X. ~; kstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
9 K/ J+ M. O3 cstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
6 G# G8 B8 H! H; i) n5 H& d2 s : H0 W3 X5 ~' x+ { s- O& f
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 * A( {$ y- t( @- [
}; + a6 l' } y% J2 B7 m* S i
/ L0 S) `7 h1 L! Q/* F, G, H and I are basic MD5 functions. */
1 J' e+ d9 z. f" `3 ^2 h# a# S#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
( [; w8 c7 U. L! E9 v g' \#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
$ R/ n& ?3 {' g+ q#define H(x, y, z) ((x) ^ (y) ^ (z)) " e6 \, ]2 t7 e$ m0 f* _$ m7 C# v
#define I(x, y, z) ((y) ^ ((x) | (~z)))
1 ?0 k2 B) b/ @- g& v6 N
" f+ P8 X' f2 p/* ROTATE_LEFT rotates x left n bits. */
2 R6 w4 P/ i J, ^" z+ f, |4 D#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) : L. X9 J t% q
5 R5 P+ h2 u: S1 F. Q/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ( w0 I( X5 b/ E, G* l; q% d
Rotation is separate from addition to prevent recomputation. */ 8 s1 \% A$ ]1 Y! i( o' O& J
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } " P: d$ i9 V/ \6 U( Q: q
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
1 D# \7 Z4 c5 ]! W; v; b, h#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
5 H! }( Z. U$ ?1 h/ e- N2 i2 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% w% C: C! z v# @! z. d
& O( q( M" {5 q8 P& F/* MD5 initialization. Begins an MD5 operation, writing a new context. */ h( J/ Z5 k/ z G- z8 P
void MD5Init (context) * v3 o% v+ p: j% w
MD5_CTX *context; /* context */ . Y, H" R: `# d# r+ C; @
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
2 g/ u G# f- U# k*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
: |0 O! S3 ]2 s( n& N! K% n' o9 U}
1 G& t! H; V, R9 d9 } + `$ q/ C) g/ B8 R8 p
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 3 d9 @% C3 h+ _7 x0 L
void MD5Update (context, input, inputLen)
5 m8 X( K- e" h: \" u- OMD5_CTX *context; /* context */
+ ^) v9 H1 }) F/ R/ T. |( Tunsigned char *input; /* input block */ 8 V' V- [$ \+ m& D4 K# o1 K( q
unsigned int inputLen; /* length of input block */
( t$ H2 I+ l, }8 L( Y1 L: m{ unsigned int i, index, partLen;
2 q7 ]% {; n6 y: k/ [6 S /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ! Y$ K: X0 E* O& c/ _+ f% |1 e
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|