|
|
#include "global.h"
* t' y" Q1 e3 F: k#include "md5.h"
2 T, }. ]! n& k# }- b. ~' p4 T $ Y6 r7 }3 b1 M) S* O6 U
/* Constants for MD5Transform routine. */
3 d3 q) @" g2 i) W3 S$ J2 v6 P
+ d5 K& G' k$ x3 \ 5 {1 ~9 m$ O* F( @2 N7 z
#define S11 7 , t4 V! e f! a' c, O. Z
#define S12 12 ( V1 _2 R( }, S3 E
#define S13 17 0 J" ]) }4 Z% O- I6 [
#define S14 22
O6 r% b' q4 `- g#define S21 5 : q' u' ^1 ?7 L1 T
#define S22 9 , Q- _; M$ \; p: X1 B6 L/ C! C
#define S23 14
" h) J* @- _. x' c7 W' L#define S24 20
; \. H- d$ q. \& v+ R6 A9 U- @, L6 w#define S31 4
8 a# j. D2 z9 O* F& g: J0 m#define S32 11 % ]& X3 _7 W, k3 V" J% b# d
#define S33 16
1 E, o$ h2 m* s# I$ i; I o#define S34 23 ! N% v% q" _- m6 [& s0 J9 U
#define S41 6
- R" x8 w: |$ m0 P% U#define S42 10 # o$ D5 c7 t/ V+ q% D ^: i
#define S43 15
4 @2 G- O" d7 b#define S44 21
' ` N" H( l) I5 Q8 \ \' s + V# u$ B* l+ \; h
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
3 M6 P% ` \7 w& gstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
" ]% `2 u6 I; qstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
6 Q6 y z' Z/ P) Y0 Rstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
, A0 L, E. e1 C; U: O1 P5 |) estatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
4 J2 ], x# x2 {" ` 7 [+ S" M) X1 ]! Z1 O7 t4 V
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
1 z9 l7 v/ Q! c1 Y8 p4 z};
/ x2 ~# i; q' K6 Z* V T( x/ y3 X
, v b" l" {( N( ?# u% `" x/* F, G, H and I are basic MD5 functions. */ 8 F0 H2 e4 [* E6 b8 N: G0 k# \
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) & S+ q: C5 v+ P3 t* ?* W$ h
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
3 P* A) I3 V! P: v$ O0 I#define H(x, y, z) ((x) ^ (y) ^ (z)) : A4 W* }" H2 f3 l* O
#define I(x, y, z) ((y) ^ ((x) | (~z))) , L2 j9 E, O7 `* q* z! n2 @
/ p3 l% x$ S/ w2 Z
/* ROTATE_LEFT rotates x left n bits. */
# m+ n& ]/ A9 x. E E. l) X#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
% r# Y+ N: _; p& Q/ {) u ) @# I- n" P6 ^0 {& H) {
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
" i( m1 u1 I8 N( t5 ^Rotation is separate from addition to prevent recomputation. */
: F. ^$ Q4 K: w, y1 q* w9 @6 D! S#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
# Q5 n5 F# I4 g* `#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
; y$ G5 v5 F7 n/ U( `" 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); \ }
7 g: d$ U* |! x#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% d3 m. w- M, Q. ?7 j" v$ F6 [7 h
0 M, D a8 u r) _- I7 f/* MD5 initialization. Begins an MD5 operation, writing a new context. */ " T! V3 [3 L9 [& n( M0 n% W
void MD5Init (context) 3 m- s. u# R4 Q0 u, o2 t
MD5_CTX *context; /* context */ : C" ~6 p; E9 x z* y4 k. i
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. % s F2 }) S9 m# s" d- @" I$ l
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
, z0 G3 v. p$ ?7 m} " l$ C _# c0 t `/ U4 ~
& S9 K6 v$ ^5 L. x/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 1 Q! P5 c& x* O
void MD5Update (context, input, inputLen) + t9 j* q) U; J9 E7 k2 l8 }3 D
MD5_CTX *context; /* context */
$ z* |, f& x; e! Z. I/ L6 dunsigned char *input; /* input block */
- A; e4 z- N& {- ^0 t' Uunsigned int inputLen; /* length of input block */
6 {3 h. H/ K4 L- i. g' |7 n0 H{ unsigned int i, index, partLen;
9 @, N$ M% a) a( \; k5 m /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
! j# I5 y3 U3 G' c /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|