|
#include "global.h" ( t& P `5 G X
#include "md5.h"
" T H, ^8 @. q9 m, K- Q3 U % R3 [1 k/ a% d6 h0 n S5 ?
/* Constants for MD5Transform routine. */ + W: s$ _) i- G0 l! D4 w6 g
' ^7 c5 _$ i) b1 n# d! w
4 T+ z& [# d1 Z
#define S11 7
: [* {% ^: u6 _1 H. [#define S12 12
* t) m" r. J9 t) d, `% b/ ^5 @#define S13 17
5 O' \0 } C8 {0 [4 W6 b( P% l& b/ X#define S14 22
9 q% U- f9 T; e#define S21 5 8 ^" q: f4 Z+ |% z! I: c9 s
#define S22 9 # }" ~' j) q. ~
#define S23 14 ; A6 \! b, F& Z$ W7 b K- a: F
#define S24 20
# H1 y+ r0 p! t; Q#define S31 4
" q8 i! O3 W9 u+ k#define S32 11
! b0 t! B4 o) z) Y5 V#define S33 16
}# h. J4 Z" ~# w `#define S34 23
! w8 O8 e2 Z6 w5 ]#define S41 6 $ Q6 ?5 X9 A8 Y+ V
#define S42 10 4 ?& ?& o7 v) V2 n2 k4 P) o. f
#define S43 15 ! }& ~& G% Y1 r7 L |1 F8 H
#define S44 21 * E- E* k4 ]) }& e; n% s0 D" e
# N- g Q5 @# M2 K! i7 d* {+ [
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); ! f: g/ z* O5 s5 m0 E. [# N
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 5 w% ]" I6 V: U( q. H6 I: @5 q
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
' X4 r/ c& q% K. {" U/ x gstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
8 ]. D, M/ L& |) L# Istatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
8 \: P* L! v; u4 a 4 W9 @$ O: ^2 c9 g I) J6 }0 t
static 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 ; ^& P3 w" q+ ~. p; m: o. l
};
3 ^7 Z7 U% f) _+ t* Z : p3 p9 d7 m0 t: U" G# |/ h) c6 F6 k
/* F, G, H and I are basic MD5 functions. */ 1 H/ U2 `0 }" A5 l9 u! i0 l
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
2 a( Z3 X0 T y5 C6 H: ?#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) , N4 i+ O: J6 i7 \' @: T$ Z
#define H(x, y, z) ((x) ^ (y) ^ (z))
M: B# I: l3 v4 x#define I(x, y, z) ((y) ^ ((x) | (~z))) + W. z4 F8 y) ^! c& T; ~( K
* m& E! Z2 k# X6 X" i
/* ROTATE_LEFT rotates x left n bits. */
- F z j" \, d#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
; h, x. R& R1 u0 v. n
' Z3 `/ G$ K# P2 H0 v5 I/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
# V7 n+ p0 a7 W9 w: FRotation is separate from addition to prevent recomputation. */ * x0 K+ v t/ J* F
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ; r/ L. l5 Q" y( c- X9 w/ 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); \ } ; \* K. w' A8 M0 w$ X
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } z6 w+ D; J& w+ B2 f
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
, V6 g; a0 M: o6 @
) E' b1 l3 y1 A! [/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 6 B7 I: h- f/ E' @3 [, ? I
void MD5Init (context)
% q% `3 W) a( [; d: j6 LMD5_CTX *context; /* context */
' `. r- ~2 @' \, c2 ~1 h( U# c{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 1 @, e1 D' B5 z+ \
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; , p9 y& c- B" Z/ c# {, o9 K+ w
}
+ y6 m- M2 a b) X
' w4 N! M) g" N; b6 W6 U/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
; y. |; {- P( V& O0 Qvoid MD5Update (context, input, inputLen) $ k/ K, W+ A) n. g1 l4 S4 @
MD5_CTX *context; /* context */ 5 J8 E2 J$ Y; e$ o3 s3 h( G
unsigned char *input; /* input block */ % a; S6 l1 a# J6 P& f5 N1 }
unsigned int inputLen; /* length of input block */
+ d3 U- u) k, E% o1 I{ unsigned int i, index, partLen;
. Y3 r1 Q" S8 s2 E6 ~$ O# e /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); * r8 `4 Q( T4 Z! U2 P) y3 x
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|