|
|
#include "global.h"
' ~8 d7 n' ^! Q }, U( i7 b- ~#include "md5.h"
- U' `, F, ]3 ~! G
' G% V- G5 m7 }, U0 {. {, Z/* Constants for MD5Transform routine. */
' p/ u6 q. ~" |' g" ?6 x9 o
; g# h: t) u3 ]$ p$ {' E& ?5 J
! b7 O: f0 P8 Y# k3 n& v. v#define S11 7
! v# c2 ~. N2 x0 M3 P# M9 x#define S12 12 + Q5 @) ?9 N6 O* k" z
#define S13 17
$ j9 P7 f9 V+ j# {6 R#define S14 22
7 P- {- k8 m1 `6 H#define S21 5 4 H4 O: t e) ^7 ^5 T: T! n2 D
#define S22 9
1 y+ f; b+ `0 K3 t#define S23 14
% ~' C4 d& I+ a! z. D1 j# m6 X#define S24 20
6 {4 z- t* a0 P# ~2 u, w( C#define S31 4 0 C, g. [) H) P) s8 h% P/ W( O
#define S32 11 - L, i. B1 l# t* z( x: ?6 N( p
#define S33 16
3 \# z, P, `" R% q#define S34 23
. e3 Z# p! d- R9 I6 o#define S41 6
! Y1 |! E$ M. b9 e7 ^2 e& h#define S42 10
/ Z( Q% t; S$ O9 h#define S43 15
C# T" ]( n# G% A9 n: _: ?: Z#define S44 21
( p0 F" Z+ i, `# X! Z( J C 7 Y8 n5 `4 v2 _( ]) C
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
9 L, r8 S" N; L, astatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); + P: n5 i4 ?% V
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ; M) U$ S/ B% Z [ z; A
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 4 T5 [% `( O+ e- S- A% @7 B
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
^; M2 f1 I) _6 W1 o
( ]! K; N; K2 D2 v8 S0 v' w9 Zstatic 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 . j: r$ {/ v( H' u2 n
}; 2 Y9 }$ c( P$ ~0 _8 J" G, R! W
; q" F% j& B; n$ r
/* F, G, H and I are basic MD5 functions. */ ) X$ |" C# N/ ]9 G# s- ^) R* _
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
! w: o7 K# |2 h" x#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
8 x' `* q1 Q2 E+ ?: l#define H(x, y, z) ((x) ^ (y) ^ (z))
% O0 z4 p2 d; p$ l* B#define I(x, y, z) ((y) ^ ((x) | (~z))) 1 _' q2 m6 N" u# ~9 N3 m3 i
7 b! a& `" ^- }/* ROTATE_LEFT rotates x left n bits. */ % t1 E; L/ U* ]# v9 p
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) * }0 M. ?; q7 {! C* y
( f) O. _; ]1 S# Y% P7 X
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 2 z+ b0 P% v# f8 o
Rotation is separate from addition to prevent recomputation. */
" E$ V/ r. c4 i" j+ T#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 0 D0 y9 J8 X2 Z* k( z( G% V0 t7 a
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% ~9 h! G8 D- Y#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& b4 g# g8 { 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. Q n! n- Q( R1 m ' L5 M- B! t! K2 i Z# b
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
( ^ A* y% u, y; M/ X1 jvoid MD5Init (context) . a6 n! X4 o {+ T
MD5_CTX *context; /* context */
# M: D$ c5 N) z4 ~{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ' p0 w+ w% e! W& t( b! o
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 1 O- N3 G$ S+ Q7 x: h# H( y4 R
}
1 s' m% u$ O! P0 P 1 P$ a+ `2 a' h+ J/ K$ D
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ ( a* D& F6 p' S- i8 N
void MD5Update (context, input, inputLen) # x7 U' b6 j4 g) G0 A0 e3 i
MD5_CTX *context; /* context */
8 W& J+ A0 i4 W: k' |unsigned char *input; /* input block */ 8 D% _- d7 D0 j! e/ k( X( Y
unsigned int inputLen; /* length of input block */ 5 k O, Y, l( W# Q8 Z) X7 `
{ unsigned int i, index, partLen;
$ b( R5 n* T' t0 S% g" _) ?" J /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); - v1 x6 M+ X- P! H3 V6 A
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|