|
#include "global.h" 5 U. ^) P9 c- y5 }3 c, c
#include "md5.h" ! R; O+ W0 O, D. s6 S8 Q8 E
* n% g* S' Y" N8 h/* Constants for MD5Transform routine. */ 2 q4 M% d( n' V, h! P
! I5 n1 R4 X" y0 [2 W% x0 ]# I8 X - s% y. w b6 L' Q" d
#define S11 7 8 q9 B8 p, O/ }2 x: {
#define S12 12 " @3 Q8 |% U9 |; d6 B6 i
#define S13 17 8 g3 n$ H( l0 T4 C7 F3 C; q0 j
#define S14 22
3 ~" @0 @9 U, y( v4 H, Z#define S21 5
9 b7 X# J3 @5 R: {#define S22 9 ! H8 ~( y$ T7 X
#define S23 14 5 [3 ?" c9 {( w' ]; G. i
#define S24 20 $ I: S1 q" e: D2 X3 ]
#define S31 4
* p1 c( t( d8 U% H#define S32 11 7 v% j0 g6 B5 g2 `7 i
#define S33 16 , Y- P" E# u$ w0 Q. Q
#define S34 23 : X5 ^$ q i: B, f# r9 W" S7 B
#define S41 6 $ z! R2 m! O/ o. o {
#define S42 10 9 v5 X* P1 W# I4 T
#define S43 15
& O% V2 a% o2 ~1 l. U#define S44 21 ) h. A# q' E, i, m" ?% o
v3 w# v; ~- l# @* t8 U; E2 w, `9 istatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
. s$ T' n6 V- g5 Wstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
4 i" s5 S% I5 j0 Gstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); : C1 b! X% o( U: ^$ v
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
& e' c, [! |2 D: }: s$ estatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
* u0 u E) `- Y# G8 K! g2 l- f$ e
$ r1 W2 A1 l- o7 W6 I8 v Fstatic 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 # _) G% P! ~* Y% t; v" p
}; & F2 n: W& Y1 P% d9 @/ m+ D; }
7 F# s+ q4 B( n: B/* F, G, H and I are basic MD5 functions. */
0 X0 s a4 D& S' Q; R( F6 U% e#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ) u, ?' Q8 @7 @6 @1 q; ] o; c
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
6 E( `* q4 A0 N T. T#define H(x, y, z) ((x) ^ (y) ^ (z)) " m5 u! r1 i! I- Z' R; d+ x! P) m
#define I(x, y, z) ((y) ^ ((x) | (~z))) # P6 ~) \/ D! ?, ] A
0 U K. P. \9 ?3 ^4 x& s/* ROTATE_LEFT rotates x left n bits. */ 4 A2 c/ u2 U1 S5 I6 X/ _" }. K7 E) n: C
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) # {/ f0 L0 W6 S6 W P3 ~
0 b9 u" A( z0 y9 W* Z4 a0 i
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
) Z6 n$ n0 Y) T3 v- y, ^/ lRotation is separate from addition to prevent recomputation. */
. ~7 L" I# z) x) c9 R4 m#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
; J7 }( L2 ?/ j#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 5 d, a+ e9 u, a1 r8 [5 C. Z
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
2 D6 k8 q0 k' |: F" h5 `#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } , d! A9 }- S2 j7 }
: o$ W4 S. s9 x) ]# B( K. U; x8 ]/* MD5 initialization. Begins an MD5 operation, writing a new context. */ % R' c8 p* q0 U k( B' Y6 q! ^
void MD5Init (context) / ^3 |8 s/ l, o9 ~8 Y- Z
MD5_CTX *context; /* context */ ' {1 M M1 K6 p5 I4 j
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
7 ^- O- |5 o" }2 v n( \8 J6 V*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
/ K( ?; c& p" f" b$ H4 t} 7 r/ M$ l4 N( E; I
5 P3 x9 e! K2 x f1 t) f/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
& ^! z8 ^: ^9 x2 S8 Pvoid MD5Update (context, input, inputLen)
6 N; P1 b! X% e3 fMD5_CTX *context; /* context */
, G b* m5 E5 s3 B4 d9 w, punsigned char *input; /* input block */ % m; | j# F5 i& c" S5 A# d$ C
unsigned int inputLen; /* length of input block */
) ]! R( @2 a8 U% e& c( r{ unsigned int i, index, partLen; 0 c1 q1 L! }5 R& t. q! y
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); & y% u1 r6 f/ y1 D( @7 _+ ~- D! L
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|