|
|
#include "global.h"
* P! j8 E' |) g& X#include "md5.h" ' x8 } T: V `1 [0 S) a+ K9 y
# @. O, v6 z% o0 S7 W/* Constants for MD5Transform routine. */ ! X/ L# i8 q. }; l0 [# i: v
/ w7 `$ `% }( q( I1 Q7 M+ r
+ W/ ~' p5 W4 s
#define S11 7
2 M( x% v5 _! ]6 i& o#define S12 12 . Q( n" u* x+ J/ h! ~
#define S13 17
8 ~6 J7 T; X- }2 ~. D3 P#define S14 22
9 v& R1 q% P7 @4 Z3 z; s#define S21 5
p5 ~: J5 W9 r* }$ Q#define S22 9
9 V% ?+ e$ C" x4 z0 m6 g#define S23 14
/ W- p' `, W5 ?& O& n$ L% ~#define S24 20 $ M7 G7 I0 [0 W4 K2 D6 K- _( U
#define S31 4 1 w7 M5 ?+ J! Z/ q& }: N
#define S32 11 + f9 _7 x" z: I- Y3 k
#define S33 16 ! q8 x2 t0 J0 |' v
#define S34 23 0 P, G- J6 `1 H
#define S41 6
* u6 T9 ?/ b0 s) A( N#define S42 10 0 M* @' q( @5 m9 H1 M, |# j! O9 t1 s
#define S43 15 ! U) ^+ ` b$ t8 u2 G7 W
#define S44 21
- m- o: M' [4 M/ I9 j6 p3 W 1 A$ E4 r0 L' N7 r
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); , c/ b/ h& y& s: A$ S/ D1 b! ]
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); c4 F8 f4 e8 k3 ~0 X# _! r
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); $ `( Q; \* s# O& m C
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); " @9 C |; z8 \
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
7 b+ `" z( `9 W- i m& ^
L. x; l" O3 ystatic 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 ) H6 i9 A0 V5 w! }8 I! I. s
};
0 ^' S9 t* I4 N 7 {, O. o0 R3 `, x6 ~3 y
/* F, G, H and I are basic MD5 functions. */ - G: a* _0 u4 u
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
: D* C+ k3 r$ H; a#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
9 m! ?% `+ @+ L& }9 f! `#define H(x, y, z) ((x) ^ (y) ^ (z)) " Z r( B. X: q/ \& b6 F
#define I(x, y, z) ((y) ^ ((x) | (~z)))
, ?2 N1 w4 K& s# |4 r @
! M8 z8 n" W$ j6 U5 k/* ROTATE_LEFT rotates x left n bits. */
; ~" S& Q! Y( p% U#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
% E; E9 N" K" Z1 L 4 @ S, V0 U2 n
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. . n( n0 x( b7 x& V% J
Rotation is separate from addition to prevent recomputation. */ 8 d/ w8 V0 |. y( h" Q+ E
#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 J3 D9 F& Z$ V1 F0 f# [, M#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
2 O8 f7 _$ J4 w$ X# D. H: 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); \ }
]+ W+ |! |4 {" Z1 W- I" ?#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
; X6 c* q# {2 M- D; L7 I
7 h0 n. U4 j$ f5 F+ j, t/* MD5 initialization. Begins an MD5 operation, writing a new context. */
( P9 u4 K _! j0 \1 hvoid MD5Init (context) 6 K. L! y$ [# I! q% y( A' y) e
MD5_CTX *context; /* context */ ' a0 R* i. P% S
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ! d1 D+ s; C, [8 N( H: ?
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
9 Q) C+ I5 _" r9 Z3 N( {}
P, J5 B* m# p' a( {
/ d0 h$ H* |2 H9 H! ^; f9 ~! u- l/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
! k6 r% d7 U* A% ]% avoid MD5Update (context, input, inputLen)
8 ?# u5 R4 X% Z5 f+ HMD5_CTX *context; /* context */
0 a3 \: H/ D9 i) S0 Z: \! aunsigned char *input; /* input block */
Q1 o7 \/ {4 R9 U! O( a6 vunsigned int inputLen; /* length of input block */ ' d) G y1 J9 \; `$ _: A' j% ^0 Z2 K
{ unsigned int i, index, partLen; ! K+ A' _+ I1 K* Y
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 0 B* l1 D9 q0 a! F9 M. ^- ]! Y
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|