|
|
#include "global.h" 5 W) t! B6 s4 |' I9 Z9 T
#include "md5.h"
0 y8 r4 V+ p& j4 m! q! K / `% m) O/ C* g* G% E, @
/* Constants for MD5Transform routine. */ ! ~2 P5 \8 m. [! \
7 l, k- o! c% g- O
+ A6 U) w2 ]! n- }. S& d- F& }
#define S11 7 % X4 ~; d( S5 W' r( s
#define S12 12
+ X( y' B1 T! h$ g' s# Q, _#define S13 17 7 ]: K" L) t9 t' j. k% [7 \
#define S14 22 # J, S8 S, S) }/ X
#define S21 5
* m( p: ]' }% A) l% P& N#define S22 9 8 d3 r' m% L1 O) A" V
#define S23 14 . q& {3 T) p7 F/ j
#define S24 20 $ s# r1 d8 ~0 U4 g) V: V( S. m
#define S31 4
3 M0 ^. h4 r) G8 g M& `! `7 [#define S32 11
8 \4 A% K" d5 ~) E( o#define S33 16
. T% A8 P- A+ `% j. o#define S34 23 0 @6 |; |& N+ R0 |9 M6 J
#define S41 6
- t1 n+ r8 p: e2 Q2 ?$ B#define S42 10
5 n: u b. `9 E$ [' C#define S43 15 , a) s! c5 q. \2 ~, I1 v, l
#define S44 21 2 E- N8 Y3 z$ C% w4 q! N) M: V
0 E, q) Z, c& p- T/ s# X2 xstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); & {5 @2 `& q7 r: n
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
. @/ V R% T( [5 z' [: wstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); $ Q* E; ~8 C8 b5 `1 O
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
9 z1 p0 W- s' R" J' a0 Ystatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
1 h' g/ w7 t" q; a6 @. e$ a2 z % f+ t! q# c, n- d) ^8 ]
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
: e+ q! p! u9 \8 X* V$ y) C: S};
) S- h8 G! E4 g0 `# @" f ( M% b- R" P2 O n
/* F, G, H and I are basic MD5 functions. */ 0 \) n3 E9 N" v# b/ U" H
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ) o' P& q! f! T% J2 m7 z2 U" y
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
n& V! ?& Z4 g, n q#define H(x, y, z) ((x) ^ (y) ^ (z))
1 o/ l6 I% M. h" E0 V4 A#define I(x, y, z) ((y) ^ ((x) | (~z)))
* B- V U9 J: S) O8 I! U: Q 4 G& `$ a4 _7 ^4 P% }
/* ROTATE_LEFT rotates x left n bits. */ 8 }; ?9 K9 x; x5 m$ ~; Z% g
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
% h4 x6 ^% [+ r, z8 t
0 B8 V! h7 ^) J* e/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
8 e. H e& c+ Z R4 u# @Rotation is separate from addition to prevent recomputation. */ / M' A6 Q) k7 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); \ } 3 f$ @8 w4 r# q% a! U) q# s! l4 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); \ } * z9 z# [8 X9 [4 y- J
#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 o% o# u& t* S0 S6 M. W3 [2 G9 ~#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
$ F3 R. V7 M% q9 d- _
2 o6 ~( |6 L: q5 x$ c/* MD5 initialization. Begins an MD5 operation, writing a new context. */
7 w: L- j% n- ^2 |5 l Svoid MD5Init (context) 9 D6 Q6 e5 ~+ q( U
MD5_CTX *context; /* context */
* k0 K3 y: B+ K% h{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
% x3 m6 s$ s: a: V; S*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; , ~6 n6 r/ r( J9 k, M# A. d" a* c
} 2 I" u) _/ w5 S) {, S, P
: ?; y+ M7 Y8 ]4 s/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
' Q) u5 _$ p2 z& k5 G9 y1 y( O0 P, @& evoid MD5Update (context, input, inputLen)
, {4 S! q T/ s5 C& [1 ?; r2 F6 m1 OMD5_CTX *context; /* context */
- Z4 z/ z) \& L& L7 ?8 Gunsigned char *input; /* input block */ 4 ]" i9 w( S( y" p. f5 r
unsigned int inputLen; /* length of input block */
) d& L8 d: A1 t0 D5 F{ unsigned int i, index, partLen; P! J! e0 E2 G( d8 D- O* @" ?
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
$ J; l$ s/ ^5 [) }1 D /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|