|
|
#include "global.h" 0 N8 ?8 C, B2 i" \7 y
#include "md5.h" ( w6 h5 ~% ]1 [) [' ~2 w* a
+ h% a, k) S" S/* Constants for MD5Transform routine. */
% i9 M0 s# R0 e" K4 O6 ?
! c' e: ^/ ~1 K/ i8 o
% Z7 R0 ]7 B. K. x a' R3 y: s#define S11 7 % j b+ A9 N" j. t
#define S12 12
& ]' Q. a. V7 k8 d3 j6 f#define S13 17 9 y' W: I7 I1 \! V
#define S14 22
/ S% C, G5 T$ y S#define S21 5
" \* L# p& b/ g& A+ }#define S22 9
5 \* O* A0 \& I6 y% c5 q/ g8 E#define S23 14 6 j1 y4 d. ~# y; M
#define S24 20
$ N/ j- g5 G+ G: h4 t. `#define S31 4 7 C6 T* Q* _2 R3 ^# y9 Z
#define S32 11
. `4 X/ |# b0 P#define S33 16 & ]- A$ ~& m) v
#define S34 23
! g. [! F) K2 l8 Z# M, \#define S41 6 $ ~% a I* y' z# m& E
#define S42 10
* J$ d, T6 V0 h" e/ W6 I, m( d R! M#define S43 15
+ ^1 p& m* P( K' p#define S44 21 * O2 ~0 m1 Y2 f# {" P
( X1 T# c/ w0 E. h: g8 P% i) fstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
9 p% w- k+ X( s3 J5 Ustatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
3 L( G( ^ }' Z' S3 R& ~static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
$ ?! t, @5 A6 L. s: xstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 2 K N: E3 G. ^: U
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 5 _2 e4 O9 d/ o, I2 k3 G
5 ^3 ^1 ~* I$ f* E- G& G
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
0 Z+ F* `" K9 V* t; ~};
0 V4 r. k& O" \5 p
8 _! ^ o$ \8 e% M4 ^/* F, G, H and I are basic MD5 functions. */
: c; k7 C2 j, Q% ]; H# h6 s#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
# J; C% @0 F }- V8 B5 \#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) , P- t7 z7 c2 j6 }1 e. l7 Z
#define H(x, y, z) ((x) ^ (y) ^ (z))
. r& k, B# y/ b#define I(x, y, z) ((y) ^ ((x) | (~z))) 6 a+ g& B4 D. Y" x6 ]) ~
h6 ^+ s5 [; g
/* ROTATE_LEFT rotates x left n bits. */ 1 r" V6 ?5 g9 t' s$ h! ^6 i
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
1 j. {: v$ Y3 l6 S4 ]/ X ) n- y' k) ^& L/ ^& P( P7 S
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
; U% H; S4 r; y7 @Rotation is separate from addition to prevent recomputation. */ . h( B- w7 o8 ~
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } $ H7 k$ w0 W$ W. G+ @5 v* t- a5 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); \ } # z: y* q1 R3 L6 \: i
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ) A0 v; G; r0 `$ [. ~7 e
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ j) ~/ q3 p5 d$ M
4 h X; d. G0 t6 E# p/* MD5 initialization. Begins an MD5 operation, writing a new context. */ - r% L6 x/ `+ z) C% o3 z4 C
void MD5Init (context) 2 b- ^; M5 a9 P$ V/ ^& j
MD5_CTX *context; /* context */
) s7 q/ T6 s4 C/ G{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
0 E- X2 O- C0 i4 p/ L$ j*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; : j2 D6 d* f7 A" ]7 C2 N
} ! D7 l+ n( `& ^ Q X
" K& ]; B5 r) Z* s2 A/ d2 s5 N# ~
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
$ H4 C9 R4 m" B% t2 O4 r d1 `void MD5Update (context, input, inputLen) & @$ D. d; V: z3 U
MD5_CTX *context; /* context */
. q& k4 d H0 [unsigned char *input; /* input block */ ; ?) e6 Y- Y1 Q/ g5 v
unsigned int inputLen; /* length of input block */
1 M4 I* J2 y' ]' u* ~. m{ unsigned int i, index, partLen;
: B$ ]5 Y, m8 _! [ /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ) }* u$ s6 j% @4 j
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|