|
|
#include "global.h"
2 u& D, A, y" w$ v. _* q; s) K/ t* Y#include "md5.h"
) T; K( b8 V' \$ i& t% o" B " Q0 t% d: d6 k) b% V
/* Constants for MD5Transform routine. */ 2 q' I$ f7 x6 W! U( L; C+ ^- c
2 J I$ P6 T, s2 F
4 v6 V: ^$ D% @: [3 t! {5 }#define S11 7
0 Y1 \" S9 @3 d: ?#define S12 12 4 W0 s7 x4 O* {& w ^. ?8 v: d8 @
#define S13 17 8 D# k" u; _+ W7 e$ e% |9 ^
#define S14 22 4 A' O$ |7 `& r
#define S21 5
6 b! D9 K5 G2 `$ H9 I7 @' O#define S22 9 ) n4 r$ x; l0 q/ S. @6 y
#define S23 14 3 N7 I) ^6 H! j; i) m; n
#define S24 20
* h/ A8 h9 u4 C* u#define S31 4
% }, X+ @% A; f& i( P* U#define S32 11 * u" P( p3 o" i4 j
#define S33 16
: {4 A1 w2 O# ]; Y( ^#define S34 23 * f. Y8 [7 { t
#define S41 6 4 L9 I& z1 J% X
#define S42 10
/ _/ M; M, f" V+ K6 {& X8 r#define S43 15
5 D! |4 E/ b" r) Y K" G: n9 y#define S44 21
. L' \% M a. t" f4 _" K" v
; S2 [0 i$ h! T8 |2 k4 w+ P' i% Qstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
% T% b- X) `0 n; [2 a" Hstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
4 W- F. q- t$ o8 p. V9 Nstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); . n' z7 [# L8 T
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
$ L \2 X1 f# l. rstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); & t+ F+ c5 C. n C2 t
. R) E/ D! t* X6 N5 W, w2 \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 ; ^5 T- B4 ~. q
};
, ]. B: b4 N P% X! t3 e 4 W! X) o% ^: H" \
/* F, G, H and I are basic MD5 functions. */
9 e- j0 f5 ~# B#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 0 R. H* P! r1 a
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) G3 j, j2 Y6 j% x
#define H(x, y, z) ((x) ^ (y) ^ (z)) 7 C4 u- N5 [' n) r% l
#define I(x, y, z) ((y) ^ ((x) | (~z)))
" v- u# \- Q) B3 `. w8 o2 _
% B, J5 J. k1 J( {/* ROTATE_LEFT rotates x left n bits. */ 7 J6 X. r: t0 z7 a$ O
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) * [. v6 n: H$ a
2 S/ }8 _ @5 S$ j" S4 G" W
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
; n5 M: w% H8 @; {Rotation is separate from addition to prevent recomputation. */
5 z4 A( n9 B/ U9 t#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
4 c5 j* h$ H/ V1 X! |' @/ X$ \: b#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
6 r, g7 [2 X, a#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ) s# o8 q. `( f+ [. F X1 S
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
* M' ?; r, y J3 D 7 i5 w% G! V4 a& l4 N5 ` n) w% o
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
Y5 T4 c k" j% ]% t/ m# ?; ~void MD5Init (context)
- ?( @: G/ P f, R1 pMD5_CTX *context; /* context */ 5 c- u* @, V, s w% s C2 {# m1 W
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
+ y3 x) F# {) [6 P* X! \*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
, S8 K/ J& r% V: r$ t0 a; v}
' e* M }' o9 y0 R$ j 8 K3 e1 ~2 t( h' @
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
- b$ `3 p9 L c. jvoid MD5Update (context, input, inputLen) 7 K8 [, V! z1 z) L
MD5_CTX *context; /* context */
5 F# R$ g% z% gunsigned char *input; /* input block */
- J7 r% F- G; w" I. y; ~unsigned int inputLen; /* length of input block */ # h; Q4 ^0 {1 v! ?0 x
{ unsigned int i, index, partLen;
% \3 I2 i7 t# ~1 J+ [ /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); " h) |5 J2 j2 u. [
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|