|
|
#include "global.h" 5 F5 f# l3 b' |, Q
#include "md5.h" : j; P! j& G n9 h& j
, C: z- H& b; X0 f6 s+ B4 o" |
/* Constants for MD5Transform routine. */ ( l. N m. [7 Y/ P+ k5 d5 U6 O
7 r$ s! x# a9 v8 x
: j6 k* s' |' C: E; S" H; t#define S11 7 & ^' N) ~" X8 L: x+ g
#define S12 12 x/ X9 |1 Z$ g2 O" u
#define S13 17
/ X5 |5 \, _2 y% H# M0 y9 ?#define S14 22
9 F$ y& _1 {) w$ m0 ?) J2 X; S7 Z#define S21 5
! V6 }7 e0 M- ?% N#define S22 9 * R F$ t3 k8 ~+ h5 E$ b/ W( e
#define S23 14
! z$ _" j1 W8 J6 d @1 U3 W8 u#define S24 20
9 ^+ M" U) ?( |#define S31 4
% A J j$ x& d" V#define S32 11 # n2 d& c _+ Z8 j! i
#define S33 16
, F; H$ l) x- |: Z3 s0 _#define S34 23
4 P! d# w* Y* c X1 @#define S41 6 7 x) T9 g2 z/ g7 T
#define S42 10 # }) C+ _, m/ R2 X3 e
#define S43 15 6 e v, R( c M7 F
#define S44 21
% A2 d! m# `, F# G( u4 ]* z
2 D& B' \' c/ l, A' Zstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
$ o. ~. N0 `: S' k) e: Xstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); % p' y$ U+ p3 U
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
! r c5 D7 g/ Rstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
$ U; z, F0 V( o7 P9 i' Dstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 5 @* \& o( d0 x4 e
6 X$ R; a: Z" k' f+ jstatic 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 2 E4 T: x9 u7 V6 Y
}; 4 k6 j5 }/ b& j N* L# y4 H
) o6 d: E+ @! F/ n- D/ u
/* F, G, H and I are basic MD5 functions. */
; M5 Y$ t5 Q% p" _#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) U: m* v& s* p- Y" P
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
9 E6 \5 w- q# ?1 A; E#define H(x, y, z) ((x) ^ (y) ^ (z))
# E8 N4 x5 @; Q3 d1 Y#define I(x, y, z) ((y) ^ ((x) | (~z)))
$ W% u1 O- j% n' d: R * g/ e( b) o2 u7 L% @ s% ^+ R" P
/* ROTATE_LEFT rotates x left n bits. */ + b! b4 ^% o/ b' L3 Q
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ! G6 e4 |8 {8 {% o: o1 ~! h& g3 ~
$ X2 o& ^9 B: P: D: y. K6 C" H
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
, ^ R# F2 `/ H. @+ [$ r; cRotation is separate from addition to prevent recomputation. */ 9 S# G. M( e9 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); \ } 0 ^- ~6 h! X8 t u$ G) 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); \ }
8 A3 ^: o9 Y. A+ S#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& B1 h5 D. M5 v z+ h! t4 o, g#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% x' C4 g9 \" Y; F* A
7 J3 N. A7 y# E# J. q/* MD5 initialization. Begins an MD5 operation, writing a new context. */ # I: j, k) S) r4 I. z+ G% i8 T
void MD5Init (context) 9 ?$ A+ E& F" c+ e9 T
MD5_CTX *context; /* context */
% ?: z- b: d/ g) L6 c6 J+ p{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. # r% ^; y; ~: s) Z( n
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
) r" J" y6 J0 h2 I; F}
4 G8 _' v6 |0 k6 e' q2 Q& ^ ! P: A# R: I4 ]; V
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
' I- y0 Q- n- k/ c; fvoid MD5Update (context, input, inputLen)
; m" D9 }1 I, w0 ]/ gMD5_CTX *context; /* context */
# @1 x8 m4 ^4 h" z0 Funsigned char *input; /* input block */ ' I+ Z- @4 a5 X
unsigned int inputLen; /* length of input block */ 9 p7 Z# v1 O3 Y8 e. Y! Q
{ unsigned int i, index, partLen;
- r* Z8 r/ ^- e1 n1 h% v3 j6 S8 G /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
7 _: } t7 F0 j: E+ K /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|