|
|
#include "global.h" & y$ g* T6 B+ }& g2 O/ b
#include "md5.h" 3 D. o* Y; }: d9 b3 L Z* j
' a% X. _! c4 c/* Constants for MD5Transform routine. */ # q! i9 J3 b2 F8 D$ I. Z: D: r+ k
: k/ D9 ]; t% S* s
5 y8 v3 }1 l. R) D& A; v+ n#define S11 7
, o( t+ V: m. l" u& X! Y#define S12 12
7 Q" c( j: H+ K u# M#define S13 17 ) k4 s2 ~8 h) U7 R+ Q h) d
#define S14 22 2 e0 g* }, R, N- Y- B Z& M r
#define S21 5 ' z( s# b2 t: `, z9 S
#define S22 9
9 T5 ~( j0 i, a" H w#define S23 14
. z0 k) K% }+ S- }7 r#define S24 20
! p6 {- b/ H# l( O#define S31 4 ( _) d- }2 Y( l# D
#define S32 11 ; _& ^8 G9 N; N; m4 P) l- \; y) |; y3 p
#define S33 16 - p: t. @5 ^$ [( j& P
#define S34 23
1 E5 ]6 `) A$ ^3 v2 h! \ e# r#define S41 6
, F; H- x7 @! T) \) G, K- m#define S42 10 H3 }5 Z1 } B4 ]
#define S43 15
0 k: |* j e% G$ ^( P#define S44 21 * z7 L: E) k R& s
: s5 t" k9 n! }static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
# @3 ^: x o) ^4 w! H! vstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 4 V' q U& `& k: o. U8 i# S
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 4 j$ E: [9 v& g. p
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); ; ^: o8 v# K2 N/ ], l
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ' K/ ?% R2 Q5 W f. Z3 v& g! t% }) I
0 I" x( u' t9 X4 W: L, astatic 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
8 n1 P- n0 T; ~" `: C};
- V, S1 g5 l. T! k+ j3 J2 ]& |# m9 S , K. y0 M, Q0 K9 {
/* F, G, H and I are basic MD5 functions. */
- h9 ^/ [8 [ F% B#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
* z' ?9 F$ e- D9 ]% H, M9 I" ]9 a; [#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) " K$ A1 R$ [0 u, l6 G0 _2 d2 x6 G
#define H(x, y, z) ((x) ^ (y) ^ (z)) & s3 k( N x; `# M5 x2 y9 H4 ?
#define I(x, y, z) ((y) ^ ((x) | (~z)))
: l( A; ~0 g O; J# L) u3 `% t n( T* e % q' v, T# C( g; i7 z
/* ROTATE_LEFT rotates x left n bits. */
& ?0 C. b. e4 U$ R#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 7 o2 H/ {" z1 U2 Z3 X+ Q2 F' ?
$ M2 u/ G$ {2 F8 |( W, U/ p/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
& r3 p4 F5 S" ~Rotation is separate from addition to prevent recomputation. */ - m' ` [8 Q$ ]
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
' d) `: |( _6 S8 r1 o#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
/ \! f4 n9 d+ U, z" a#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 |' z3 i+ ], F+ 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); \ }
( u; F" g6 @3 n8 C6 v 0 @0 m$ a& n8 b, [4 j5 [
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
7 O% s; M6 T. C' |: K p. Svoid MD5Init (context)
4 U( u( h- \" v+ e" wMD5_CTX *context; /* context */
% G3 d3 n4 i4 C3 g9 A{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
, _7 p) w3 S O/ M, m# u0 m2 @: A) D*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
5 a7 K$ d/ D3 O2 y6 `- F} 7 ]. C7 K( [. g2 Z. b
3 S- ?* T) c" D9 O* R, p' \4 _
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
! U% {3 ~6 \0 p" rvoid MD5Update (context, input, inputLen)
4 ]- N0 R" N7 r$ \3 Z8 o8 WMD5_CTX *context; /* context */ 4 k" R% c% a* }) t
unsigned char *input; /* input block */ ; G1 h. Y' m% A* O+ L0 Y, B7 V1 k5 u
unsigned int inputLen; /* length of input block */
+ \0 g/ n0 h4 {, }# X% \{ unsigned int i, index, partLen; ) d0 c- X* i C( h5 E
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 2 h: S) q: X( C* A
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|