|
|
#include "global.h" % B0 A/ y7 n7 P( z
#include "md5.h" 9 g4 Q7 u2 ` A
! W' E: T3 H `6 B5 R' {
/* Constants for MD5Transform routine. */
9 f. |+ Y+ x# m8 i# i6 I6 u; A8 P ?) j1 C: i1 b* Z- T
& E/ l# E7 ]4 e" \3 {9 C
#define S11 7 # k9 \! J% W, S% x9 A {& w. n
#define S12 12 8 Y$ ]$ ]3 k# y* w: I
#define S13 17 ! U) `" W ]/ {
#define S14 22 , |' t( E! D" l# Z5 o
#define S21 5 2 a% e5 W/ Z' V8 C5 O
#define S22 9
" F9 b3 G; S( V( {0 E1 Q9 k#define S23 14 / z% ~& z- X$ G
#define S24 20
6 I' r+ z3 d& A#define S31 4
- K. J( J* R' e#define S32 11
6 b: @7 o3 w6 x# c. f" B#define S33 16
! J/ ? L/ S- t#define S34 23 + ]! _* W& X. o8 Z, h- h
#define S41 6
3 I1 y+ ]' G& g1 G8 b' ~: X* g#define S42 10
9 R8 s i1 ?& E2 b/ O' q#define S43 15 8 {' _% V9 \, }: V+ G8 l; R; O
#define S44 21
0 ?: [, v7 K' y9 p8 x( }$ c ) V; ?! @4 }! ~6 n% `
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
& b1 a! l5 d# a+ n; fstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); G3 l; N y% Q+ j) B7 f
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); " }! t4 R$ M5 I/ a0 f+ Y0 \# M
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 5 J, l+ `2 ?+ ^- _
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
8 {0 z9 O/ P. P, h1 d & u: i4 i; ~* N0 m, e. ^
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
( Y- H- \/ g% [% V, H- A};
* u5 z" ^! F0 X3 g) l. B
: k& b5 q- z2 `6 x: a. X6 `& k1 L/* F, G, H and I are basic MD5 functions. */
! o. W7 b$ k1 n) Y6 a& b#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 6 l6 X# J; X4 G5 {; d# Y
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
4 x6 \9 c" i% y* s#define H(x, y, z) ((x) ^ (y) ^ (z)) % e: |! q# o- t5 [7 _& n
#define I(x, y, z) ((y) ^ ((x) | (~z)))
$ `5 ^8 ~) x* g* j & c/ z$ q# ^. U, W' C
/* ROTATE_LEFT rotates x left n bits. */ 2 ^- u$ r3 q3 u) w6 f/ r! L
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 6 e% n$ w$ Z L
% o9 G) ~7 X1 F9 ]6 I" T/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. $ [! ?; a* c. G5 P
Rotation is separate from addition to prevent recomputation. */
% o; }% X6 v" E$ A# H5 \/ _#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
/ n; H r5 X ?; w#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
9 W6 L I9 o6 t#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 8 ~. v2 J, g; m e* {8 l7 }
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } / ]/ I7 V- z/ X
4 j/ w2 c1 I) s4 R- _8 w0 ~3 H/* MD5 initialization. Begins an MD5 operation, writing a new context. */
. Y+ [- e: x7 G# Svoid MD5Init (context)
, R; l7 E4 S+ e% hMD5_CTX *context; /* context */ ; O" W/ I( f" g; X* @% E2 `" k# f4 V
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. / @. Y$ }6 V; o/ C; M0 }
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
" a, i. K) _' G$ |% n$ h: \* {. ?}
( P/ S, F e! r Q3 @ 6 S) o( j% B8 x) k& r0 k
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
: e8 I; t7 {6 [6 Svoid MD5Update (context, input, inputLen) + k- Q9 r/ u) ~3 t9 B$ W0 e
MD5_CTX *context; /* context */
# t/ {& m+ S7 O9 x! |5 Runsigned char *input; /* input block */ " o' g# z$ ]) a7 F9 v6 I( s
unsigned int inputLen; /* length of input block */
( Y6 @, T" ~# }' }{ unsigned int i, index, partLen;
3 {# t8 B1 `3 `6 j1 G( S /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); , u9 _2 T' l) ]+ s
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|