|
|
#include "global.h" [' _2 K: f. J$ C- t0 ?$ }
#include "md5.h" ! |! O7 ~- P/ L1 {1 w# c
3 M/ x! Z( _$ `) E7 P/ d# f' X
/* Constants for MD5Transform routine. */ 8 Y; n& M6 v2 A6 I' ^# O
+ ~5 p4 e* U: k% S . A9 _6 v7 e( ?. L+ Q( ]% ?' J* ]
#define S11 7 T1 _3 G9 i S, l& D1 \/ k) u+ h
#define S12 12
0 x& r3 |: I p Z. T#define S13 17
y4 I! N; }! ]9 s#define S14 22 2 E2 H3 R0 M- H3 N' A& A
#define S21 5 & Y: r3 G7 j) U
#define S22 9
% Q8 Y. ~1 I% Q5 c- \#define S23 14 9 d/ }' }) P; t. N7 P. _
#define S24 20 : o) V0 f F4 F' p O0 w
#define S31 4 + H- Q$ b$ K+ Q1 I0 e( S$ m9 ^3 |
#define S32 11
- `5 I5 }7 C- X4 a#define S33 16
X0 \- F O" B0 U#define S34 23
) f' u5 n F4 y- v9 Z#define S41 6 7 a1 o; X9 m" B
#define S42 10 " T/ ?2 z, w5 Q: L$ a, A& H' ^
#define S43 15 ) |& V5 [# i6 }' S$ [
#define S44 21
/ q% u; o' a3 Q& B4 X% Q$ a
( Y$ V6 J9 t4 ~( V$ c- z& j$ P' L0 @static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); ' O- g4 s& p) s' D# ]
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
" |2 K; M o; S) ~/ M6 T& l+ \static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
9 Z1 Y1 M- Z3 O! Dstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); . ?( `# g$ @8 G( V- a
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); - e1 n# ~* u R% R
/ H% i S3 h. E4 Rstatic 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
6 A* r% x, H/ S& N};
, c- H6 n$ }! h 5 ?0 _% n, K/ M! h% ^
/* F, G, H and I are basic MD5 functions. */
0 Y) ~8 j: B$ [4 O! W#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) , S: c8 M$ j2 y% A% A8 W2 I
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 1 n, M2 x% |2 t5 c5 b
#define H(x, y, z) ((x) ^ (y) ^ (z)) t1 V8 ^/ Y9 [) ?+ x4 K
#define I(x, y, z) ((y) ^ ((x) | (~z))) 2 K" u. W7 F! k4 g* Y( D
7 Z: M, R* k( V( ]8 Q7 F' |
/* ROTATE_LEFT rotates x left n bits. */
, {. P2 u* f5 t% g#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
( b' z" g. u7 v6 l3 k
* X! Y6 D3 g7 F6 c9 D! a& X/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
0 Q2 g, B- U/ B9 BRotation is separate from addition to prevent recomputation. */ - t6 S9 V" e1 {/ H
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 o+ n# N: N! v
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 7 F' ?5 E q1 z. f
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } * Q7 o; g8 z: H; _7 `$ q
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 X( J2 a; G. U3 w* F- L
: `; p' Q2 h3 _& Z
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
2 W; |2 c/ L4 d5 L0 i5 H# ?void MD5Init (context)
[1 N- } ?: tMD5_CTX *context; /* context */ 9 C# m$ u' d. ~* y$ Q3 ^
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. & Z% ~$ y* y- d7 E3 Z
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
9 Z# }; ^7 [2 T; s4 P% y( F D}
/ ~% S0 S5 r3 K8 p* L& P. [
+ `) j- n7 P1 A/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
+ a% D% s2 y' D2 V7 V7 q# M9 }2 ~4 Ovoid MD5Update (context, input, inputLen) & m' f1 d! h6 B8 Y
MD5_CTX *context; /* context */ % E8 y! d5 T+ H, o }8 m# W1 ]2 p( y
unsigned char *input; /* input block */ 5 ~7 A1 m5 }+ K- {) A' [8 M" H
unsigned int inputLen; /* length of input block */
3 ?9 d( b. ^. e8 l{ unsigned int i, index, partLen;
0 [& X4 @ S/ U2 Q /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); - \/ f3 ]5 V% l4 w L; y
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|