|
|
#include "global.h"
" N; c" T& W& X( A/ W5 r#include "md5.h"
/ ~3 H9 i$ e4 g1 Q
: J: Q7 g4 z1 b7 I( E% I/* Constants for MD5Transform routine. */ # J T8 I, u3 ~9 Q
7 Q( N$ R2 ^% n( ]9 F
' F' A8 I' G+ a, v4 y0 J
#define S11 7 W: a$ ^5 n# D7 [; [2 Z
#define S12 12 : d5 m( N* L8 i$ V* s& P
#define S13 17 , b2 H7 Y& Q% |( @: Q- q
#define S14 22
. j/ a" y. Y# o#define S21 5 " t# |( R5 B f" k" `% W3 V$ u& W
#define S22 9 4 M" d9 r* \4 _
#define S23 14
: J* Q1 D0 P* q#define S24 20
3 L6 C- z: l8 R#define S31 4 . o) ?4 f& P- S7 n1 h
#define S32 11
7 d7 K6 J7 s7 _% [#define S33 16 ( d4 t) f# b. A9 {7 @
#define S34 23
' X* }+ G, ]- i: D* q& W3 } g#define S41 6
8 B, d7 G1 x9 X, S. A' Q, i#define S42 10
7 K, t( J! ^. I* Y- E- y#define S43 15
$ D( ^4 \, M# J* v4 m8 W7 B9 W$ j#define S44 21
5 @! E2 q) [) {$ B, `
* D* I2 W0 Q0 {0 u0 r5 Pstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
4 h/ E+ b$ [; a* |static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 5 ^1 C5 i$ B1 k
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 4 T0 B$ I. I3 L' e: p3 B4 k
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
- `5 n! @- J x7 wstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
# I' j: _9 e* V& ~) Z0 C. T + T* P8 c, ~6 A
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
- s* G, e, K) p}; 3 T' z) h3 ]& p, n1 v4 t
6 T3 e% d9 Q% J0 P2 Q/* F, G, H and I are basic MD5 functions. */ 2 I+ G* N4 @) r6 E- d+ I7 n* R
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 2 j$ E% q. a) X
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) - e# E9 F. m+ ^5 y" N
#define H(x, y, z) ((x) ^ (y) ^ (z))
+ d: }* R- J5 m#define I(x, y, z) ((y) ^ ((x) | (~z)))
# q* |" `* x* M7 A! P( y- E a+ i " j7 [* M, E6 ^: u8 Y+ q; q4 b
/* ROTATE_LEFT rotates x left n bits. */
+ m& N1 ?( m& T; w1 ^3 I1 J. V#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
$ m( t: y3 \: q" N * o ^6 ^6 H& W3 d
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
& z& T" C& X+ G" ~6 h- ^6 C( E8 rRotation is separate from addition to prevent recomputation. */ 0 u; v) G& s5 z8 u" b% \
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
, _% V6 F6 C1 ?7 C7 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); \ } 0 U5 j$ I. \* S' @
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } * d6 G: h8 M5 `2 r5 v( ?# Y
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
# u( U0 l; w( M9 \ @& A
' Z6 H$ d! @& b9 u/* MD5 initialization. Begins an MD5 operation, writing a new context. */
% }. y ?& F, m& nvoid MD5Init (context)
3 Q% ?8 ?0 \5 |' V6 ZMD5_CTX *context; /* context */ " M( f( k9 i {8 n
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. $ b6 f) a- E$ r: u/ {. c) ]
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
* E- \; G/ }$ a! a' s) X}
! ]3 z4 m5 N0 k * {' k% ~) m0 d' I
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ * O M# ^5 O$ w5 T6 d- S
void MD5Update (context, input, inputLen)
8 F* D3 o) i$ T" W% K8 RMD5_CTX *context; /* context */ # k( C* z) S) F1 v0 E
unsigned char *input; /* input block */
+ u1 k' N i! d5 H$ H$ ~unsigned int inputLen; /* length of input block */
. Q, Z) Y7 {* Y{ unsigned int i, index, partLen; ( e. V6 ^5 g" ?& Z
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
7 X) L5 W# d1 s2 F* u; D# R, d /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|