|
|
#include "global.h" + T' F( m) C3 Y* x7 ]6 [
#include "md5.h" 0 u6 O0 c+ v' L8 z0 o9 m
- c* A/ j* |) x8 Y2 @+ J' @1 M/* Constants for MD5Transform routine. */ * e2 {3 `# _1 I! i9 l' ~, R. D
9 f& `) l- p8 I9 l% O$ y
5 y& D& `" i! [, E' \8 ^' |
#define S11 7 ; y3 l% N" R$ q/ r3 M; [
#define S12 12 8 F$ B" @" p5 l o
#define S13 17
- V) t; g( e% s) i' d#define S14 22 4 A0 i- c; D( t/ J4 b+ A
#define S21 5 , g0 P/ G$ U# v6 p
#define S22 9
, K* F: M7 p8 ]# l+ A#define S23 14 / l# P3 t' c4 u
#define S24 20 8 c% S' W9 E3 q. W
#define S31 4
* {3 I0 e- s S7 ~9 R; v#define S32 11 T& t% H( J' h$ X D8 v
#define S33 16 , U+ w; a" n. c" O+ M
#define S34 23 / y; b: l" [! G9 w* c; ], a2 ^
#define S41 6
# S) \, l B. V- ^4 L' k% s: l: v#define S42 10 , H0 J0 S. F0 I
#define S43 15 7 x2 `6 v- |$ y, O4 J' [5 @8 G: l1 i
#define S44 21
2 R# |7 d% {* l3 R% ] 8 j1 c' o) s# o' v2 H2 E' o4 C
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); + l+ o" E( X0 f* {( G( |
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); & Q1 H# u( S1 d/ m; o3 I
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); " c$ o' G3 v" \6 N4 n& y) f7 K
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); - d) A U4 P9 U2 W3 S0 L
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); p. U8 G( k% X+ c
* A6 d/ z; w3 r
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
0 Z1 }$ Q* t5 g7 j};
3 c$ Z. y/ b8 C, |* Q K6 B" J1 Q+ Z
/* F, G, H and I are basic MD5 functions. */ : K! F: m p i+ T0 z
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
# b' h- I6 ]- K4 \& x. {' k#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
% t. K2 |% [6 f6 P# ^1 w& e#define H(x, y, z) ((x) ^ (y) ^ (z)) 2 s2 A7 I( H# X& h" Z* Y& X9 k" I
#define I(x, y, z) ((y) ^ ((x) | (~z)))
/ t" H- ]& Q4 T* ]6 S P! t& B
. \: U4 ~( {& F' X# }, j/* ROTATE_LEFT rotates x left n bits. */ 8 C; n( R) D" y. x3 ^
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 3 r. a+ X4 `6 R5 j
2 M- W' z! f2 ~. N. w
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
1 \0 v, J2 ]$ j) r8 _/ ?3 R' JRotation is separate from addition to prevent recomputation. */
! j6 k5 I; R+ N4 U#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 q0 e; U5 f) v2 c( {, f- R#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } : V8 n" Z) }# s6 b
#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 H. N% J) M+ d. E1 U) V* ]#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
, \& O* u5 C- t, s0 Y5 O: Y, f
& V V! X5 C2 Z. {% f/* MD5 initialization. Begins an MD5 operation, writing a new context. */
9 e) D0 ?5 ?3 {void MD5Init (context) % r0 X0 j; m/ d( e9 ^3 g# a5 ?
MD5_CTX *context; /* context */ + P; o/ `- e1 X, e
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
) M/ z- k1 Q7 a: z. u*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
1 n* B" r% O8 \/ a}
9 U R$ b7 H7 u
$ V$ y/ v1 M- U. y7 u" i/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
R( [4 g' f5 |. n! v0 [void MD5Update (context, input, inputLen)
0 G! U3 H! m, c9 _! KMD5_CTX *context; /* context */ + ?# o& J$ h. V2 E4 U) `( n
unsigned char *input; /* input block */
5 y2 ?8 k) L$ lunsigned int inputLen; /* length of input block */
2 d5 R X1 D# z" o, K{ unsigned int i, index, partLen;
0 F k4 N: K% w+ d2 S' T% x /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 7 }& {+ b- l; n. j
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|