|
|
#include "global.h"
|9 K9 [( q( k; N#include "md5.h"
9 o2 {4 H4 C/ T$ R 7 u+ L% o) i* S* _
/* Constants for MD5Transform routine. */ " w0 i! _0 f) B8 n/ `9 `
7 A0 f$ B5 }4 D8 B! |5 {
) h! y9 l" q. }: U, X" Y0 W#define S11 7
N0 E9 }) c1 {3 o#define S12 12 " e" J( O0 e5 {0 a5 ^
#define S13 17
- H F$ m! O U% }#define S14 22 : r& c$ b- Q/ V; o* a( b
#define S21 5 % K. ^2 r T1 e! q" Q& b
#define S22 9 " O: S; K! z! V+ o. s* [5 \' M4 ^
#define S23 14 5 o2 F- M0 B1 `. u8 Y
#define S24 20 0 k. M' p3 ?; I& s; e7 M4 r
#define S31 4 - @2 V7 u4 _8 H- c0 K9 ^9 D
#define S32 11
: J2 ^, d8 k) {- o& D) W8 {, e#define S33 16 $ j. m# d) z' L2 B7 o- \" z0 j
#define S34 23
( J8 V9 Q' z; B: y& [* Z z#define S41 6
, S& A8 w6 Q R5 z! |#define S42 10
/ ~. _6 a7 y" t; Y! p#define S43 15
: w, }# H; q5 Q. l$ q#define S44 21 5 p* |; @; J' r3 O6 J+ B' K
3 Y7 v+ m8 l* A j* G; J- Tstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
% X" D2 y% c% r4 P5 |8 W, tstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ) J6 A5 P/ t/ W' d
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); * o: P/ q) D9 X$ z+ A
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
0 t& p! S2 s: m$ R6 [& O: ?static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
! Z0 O ?, Y# i . \! G3 r2 D+ 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 ' ~ {- U' w! j% v! c5 L, ^
};
2 U" F& S9 `- H# i
* l' G( l1 G; L. c( `: Q, j8 p/* F, G, H and I are basic MD5 functions. */ - u, [! [' S! N& R5 N
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) * E6 I" O8 N$ l2 I; q5 j
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 2 P% `! ?1 ?, a+ i
#define H(x, y, z) ((x) ^ (y) ^ (z))
/ G: U+ f. L: N#define I(x, y, z) ((y) ^ ((x) | (~z))) 6 H2 Y) B! ~! y9 O* x T) k m8 X- f
( i- Q4 q+ N* u) e- E
/* ROTATE_LEFT rotates x left n bits. */ % J# p& u1 ?+ t1 e$ S
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
4 @& [ P' d; Q/ C5 ] 6 c: b# p2 w4 q' f
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ( `, D8 t. F; T/ v) d% f
Rotation is separate from addition to prevent recomputation. */ 3 o* S' g6 I$ H9 n2 T' E# i2 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); \ } : k& ?, J) N+ I# N8 f( s
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ) o# r& F% Q7 [6 u% a- i6 ~
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
$ }3 }+ L w5 _. ^#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ; t% h7 O* G4 ~3 _3 |* O
+ P5 n# p( i4 B& `2 `% \
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 5 Z, h& w4 T& g- x/ a: P7 {9 \
void MD5Init (context)
' I( M4 T7 B8 U. V7 yMD5_CTX *context; /* context */ K: Z: @- B5 \# U! _
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
, i" u% \, P W% ^( Q6 v*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
# m: J& \* `; f} & H0 ^9 u O; X. M$ q1 l
/ y3 |8 h0 \) m
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 9 R6 j: }3 C; B3 Y+ Z$ V
void MD5Update (context, input, inputLen) 3 r2 p) J" O& X1 Q+ a
MD5_CTX *context; /* context */ ' y( m( L' ?# b: W1 s
unsigned char *input; /* input block */ 8 z+ |% ^3 b& c. N
unsigned int inputLen; /* length of input block */
7 i( I4 j9 R) p3 D5 r) n{ unsigned int i, index, partLen; & Y0 z" u+ l: t, j
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
- i8 P* K$ ^ z$ V /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|