|
|
#include "global.h" * `+ z8 ~9 a& a5 T' T2 I, I
#include "md5.h"
: ]5 I9 y6 a! A8 t1 O: Z8 i' y
0 H: e: q: B w/* Constants for MD5Transform routine. */ ) Y1 e2 j( d+ ?/ M5 t
9 }* V1 v: T! B
, L/ \9 D, e; w- J7 I#define S11 7
# ~7 m \) K0 M7 w7 a) r I7 E#define S12 12 4 n1 {" {5 o" R: a) g& W
#define S13 17 0 _/ ^, H# R: C3 u! Y' l; L2 k
#define S14 22 . `* n# |& G8 j, r- k
#define S21 5 + K! b- o# o: f. L
#define S22 9
9 P! Z) [. L) V, Z1 O#define S23 14 ; _0 i2 e( [, g& w
#define S24 20 ( {4 P D4 d, K, S
#define S31 4 + f3 S4 B @. j/ c
#define S32 11 7 V, @0 b! E2 R, {" c
#define S33 16
3 i6 M( J" Z3 a2 R#define S34 23 7 M) F+ x) a& y4 Q9 }
#define S41 6
E+ R9 s B6 Q" \! x#define S42 10
H( P* M2 b1 @1 M- l1 s#define S43 15 # L: Z9 m( k3 K7 x' f8 w$ [
#define S44 21 ! Y3 j7 E) J3 ~/ V: |2 U
& f* X0 i+ Y0 j
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 4 N) b0 f! l5 ]) c2 i
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
s; R8 y/ Z0 O% {' Sstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
5 [/ d' t7 k5 J, _/ T1 F& N8 zstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); " f( T2 ^5 P3 r L+ v
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
5 H+ D7 v3 i, h1 ]
# Z! ]" b' ^5 n. a* L, Ustatic 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 ^+ a2 Y% |& a# U. x
}; 1 F5 [$ m* B/ b: b$ U% u$ K
/ b S& ~1 y# r/* F, G, H and I are basic MD5 functions. */
5 h: p0 i( A3 J* `#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
& q) z2 U5 O, t2 [8 j#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) / B" C- M% `" \9 l( j
#define H(x, y, z) ((x) ^ (y) ^ (z))
+ c/ k3 Z9 X, i, L; h8 N& d) s6 f#define I(x, y, z) ((y) ^ ((x) | (~z)))
2 U; Y5 B# y0 X0 n+ b, n
0 ~. j0 L1 _$ t# I1 K/* ROTATE_LEFT rotates x left n bits. */
. N: o$ W) f# V1 c#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 6 G. q7 ]% C# q; w- u, Y
+ z$ D: }$ P: @/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 0 I; L4 h% j* r: d% q( B
Rotation is separate from addition to prevent recomputation. */
/ E% |* C& X. F0 y6 h G- d#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 5 s% z' q" O! a# I. B
#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) B+ q4 s/ N, h# t' `
#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! f. Z( q0 @- A1 h3 R" I: j3 A- u
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ n1 k: A4 ?, Y
8 P8 @/ Z J6 u8 @6 u. U/ j/* MD5 initialization. Begins an MD5 operation, writing a new context. */
' M: Z+ p% C! U& f$ a( O5 e" kvoid MD5Init (context)
5 R# w* W2 |1 f, D7 ^MD5_CTX *context; /* context */ ; {8 F) k+ n7 T: A+ v u
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. $ C/ X% v$ y& x
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; % t, ]$ j2 l( w/ l0 Z
}
% }6 Q; j6 ~* w# A4 n6 J
* a% c, }2 m `9 |/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
5 L6 ^ I& K) P" |void MD5Update (context, input, inputLen)
- N! ]% n( X3 N! _# x4 wMD5_CTX *context; /* context */
+ E( R N/ C$ d/ f4 U1 w, z9 ~unsigned char *input; /* input block */ / k) \, C3 J* U7 i* m2 v) A
unsigned int inputLen; /* length of input block */ : K# s8 G& K/ d# h0 t. ?( S6 |- w
{ unsigned int i, index, partLen; . c! Z+ q# g) k+ X# D
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
" `7 g" b2 N5 Z$ P! r4 d /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|