|
#include "global.h"
! k7 f: {- L. a" m#include "md5.h" + y( }5 _0 C5 i, {
4 m) m, A. |/ m% g/* Constants for MD5Transform routine. */ ; Y9 o. K( l6 z
5 z0 Q* @+ _% J# K+ ?$ V. f. {& V c1 E1 m % a. R/ p6 c) r3 Z9 I g3 h5 c
#define S11 7
/ z) n5 B# e/ I [# X#define S12 12 : m" w( h1 _" Y: R+ p$ [/ B
#define S13 17
' o+ M5 @! N5 c0 w8 C3 w#define S14 22
! v, M% R; y7 y" n9 ^#define S21 5
0 u. ]4 n8 r' u: | N#define S22 9
+ u! q) v3 g- L* a$ ~% z+ s5 E#define S23 14 / F9 I- i/ ^3 H4 L; O6 d
#define S24 20
6 b/ H4 F8 ~ v$ H2 X+ b#define S31 4
& i; L# t5 ^5 ?- O#define S32 11
0 l( ]" V) M, y0 K#define S33 16 . B3 ]* c1 B) s* X# M
#define S34 23
9 l: }0 Q3 r! M4 H#define S41 6 2 S% s! r; w" \
#define S42 10 # D! A6 u5 q7 t9 Q [- P$ f/ l
#define S43 15
# f1 Y) m; I# W: P; n#define S44 21 ; v- L6 F9 o1 @ m( Y9 h
' F4 G# Y* p# C: ?' r8 Nstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
8 B! B9 ?/ _ Z$ _. |( sstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ! H# X8 x- ` @8 u5 f8 K+ w
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 6 X3 ]+ a8 h) |; M# R3 \
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); - |% q6 P6 M: o% h o
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
) a) Z. W x [
- f y! |# b- m2 u6 R4 C' A. ]. Wstatic 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
5 T& y" X$ Q3 }4 V2 B+ L- F+ i};
7 k" P; ]0 T# q% ~ }- F+ ^
) A) [3 H0 H% ^3 E6 Y% Z1 q$ @/* F, G, H and I are basic MD5 functions. */ & J& J5 x" k% N4 P3 G
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
7 r7 s* O, f9 c" `# U9 Y' O#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
1 t/ {1 u* a! E9 p2 Z' Q#define H(x, y, z) ((x) ^ (y) ^ (z))
$ \9 x. w; j, w3 ?) L( o#define I(x, y, z) ((y) ^ ((x) | (~z)))
( J4 X5 |/ \1 ~# T c! y( e8 F- L6 O
/* ROTATE_LEFT rotates x left n bits. */
' `4 f4 l. E1 ? s N#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
, I3 i5 t" |5 e% A) S# t/ E5 \
3 q: H+ H- K6 X8 z5 M/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 9 V* f; ?; y$ G6 v, z
Rotation is separate from addition to prevent recomputation. */
" g" l! Q# @1 X7 f- Y#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 M x) Q- z% k3 r# g4 x8 n#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } : y# W( U/ r3 G3 c. T6 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); \ } q* G0 F5 q K3 v ~
#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' b% d# O/ M5 ~" E) _; W( g& R9 S 3 u1 @; e. Q( ` x& z& _' \
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
) d) y$ d. q' d; @, E+ Y* @void MD5Init (context)
3 ~* t. T+ i8 Q4 cMD5_CTX *context; /* context */
" c( Q: Y. B2 E8 G. ?* Y7 K{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. , n' r& o, M; J3 X
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; ' p; K+ X7 X3 S/ @' E
}
1 v; `! Y- u" P* E( [
1 i: D9 B9 d3 g1 r3 k6 U: U/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 2 E& Z' Y H2 S
void MD5Update (context, input, inputLen)
# o" M W i3 V& d2 D, \MD5_CTX *context; /* context */ 1 T# V3 U+ x# R' j# P: G( o& j
unsigned char *input; /* input block */
: N+ B: Y1 E' ?' h2 ]& ^6 w* vunsigned int inputLen; /* length of input block */ 3 i% _4 k( O; b/ y! `" F
{ unsigned int i, index, partLen;
% q; N* }" v4 b. ^ /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
6 E: m0 c! Z2 M, H /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|