|
|
#include "global.h"
, `1 U: C+ e/ O- h#include "md5.h" $ O4 Q7 I. i* s% l; H+ i
* ?" `! E, ?! a: I/* Constants for MD5Transform routine. */
: r" O8 J# \; y0 ^+ O5 `
: l. U7 o1 `# I% M3 }9 }' A- V: b
( s" C2 Y3 \$ ]$ ]4 o0 U#define S11 7 , @# S1 e) z! d1 E- J2 G1 {
#define S12 12 / l" T' ]& \1 Y1 U" Q
#define S13 17
" e' k2 d( X6 b0 V; A; O; M#define S14 22
5 {) s$ T" k# l: T- Y#define S21 5
5 n$ t. ^% A ]3 }9 p" q#define S22 9
1 P e: s0 |; j( W#define S23 14 0 L G7 M+ X; L$ F: ~4 K% M& ~ w% D! w
#define S24 20
9 O" ]2 w' U& v" b9 y#define S31 4
/ i2 ^, b9 E6 a, a/ z+ l! @+ l#define S32 11 ! W9 U& [3 j# ?! m4 p/ M5 f
#define S33 16 " s( L$ d+ ^, m/ h, r, }
#define S34 23 + i8 D+ g# V) f5 X
#define S41 6
! _7 `$ m# ^, T1 B/ Y" `#define S42 10 6 L! ]: A6 M8 Y8 R7 ]8 q
#define S43 15 # l. u" @8 M9 |0 P
#define S44 21 1 Z, D2 m3 Z( V# ~
' Q* Y3 E8 B" g7 Z! u y9 Z/ R
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
. y. ]7 K4 O# {; x( }. Vstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
% } k+ b( K1 R9 F' F7 V% estatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ( s' Q" h. I! J3 r! t1 h
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
2 ]' ^* U @4 h c: R J" dstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); & P# z! m4 v$ A9 P3 M
/ I0 A3 {! k( U8 wstatic 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& Z# U2 o" p) H
};
6 W/ m& G+ _- x8 L + }" d5 {4 c% Z
/* F, G, H and I are basic MD5 functions. */ ' E4 D1 [' M# r9 M2 Z4 @1 b2 y" \9 E
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
/ m; l& U" ^1 O2 a#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) * _5 |, F" V, j2 j. `( w. z$ x5 @ I
#define H(x, y, z) ((x) ^ (y) ^ (z)) ; N+ e8 H! l) \9 |1 \
#define I(x, y, z) ((y) ^ ((x) | (~z)))
8 ~+ M) C0 D9 m ! i( o5 Z Z/ a$ @
/* ROTATE_LEFT rotates x left n bits. */
3 b6 Y: |; a3 x7 B" Z2 R+ U9 r" _) E#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
; ~ c6 u( \8 D' o4 H: o ' G' X0 t9 T+ g' D: P/ ~6 W& n
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. $ B# W2 B$ C) X
Rotation is separate from addition to prevent recomputation. */ , `5 T2 I$ L1 O) @. A7 ~7 _' R6 W
#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 G" }, K, {1 N9 a$ I8 Y7 z& e0 G" g#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( W! R6 v4 Q' y) @0 n: U#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
1 y8 s4 D* ]+ M3 J5 J#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } " q0 G6 T5 x D; R5 B
, p @+ W; O4 I, j
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 7 R' k/ P, S- a9 t8 A
void MD5Init (context)
% g0 M2 x6 e% N1 H, c9 f+ xMD5_CTX *context; /* context */ " B3 O0 R: d4 {/ j1 |7 W
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. : F1 w: G( P6 x2 a
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
, a2 Y- j0 f% X7 l}
, _- w) u$ b" b( U9 W7 P. C' `
# k+ e$ H9 X8 f' V/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
: l) i2 Q4 u1 h1 r; Mvoid MD5Update (context, input, inputLen) " {& Z G) m% C9 c' w
MD5_CTX *context; /* context */
9 L" F4 D) G1 Z1 u( i* V) uunsigned char *input; /* input block */ `, d/ O9 k; B3 K) W
unsigned int inputLen; /* length of input block */
5 D4 y+ ?1 {( ?. W3 v% n8 m{ unsigned int i, index, partLen; ! U+ ?7 ~0 i+ K2 O: P* \8 p3 v: c- P
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ' a" J4 T6 b+ T. N4 H
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|