|
|
#include "global.h" ' L- L1 Y8 H% V
#include "md5.h" / l2 h' J6 |7 w; o- Q' a) p
2 a* p& J4 v; T% O. y& f
/* Constants for MD5Transform routine. */
* z: d7 }" Z' m; I ( J }1 P& h- O1 m, z
1 z' ~$ O$ D3 d7 t, ]9 W
#define S11 7
% H5 H# g3 o! i) q, D#define S12 12
+ ^: ]5 ^2 s# C: y#define S13 17 / c6 o N" N" i6 h$ N- G
#define S14 22
3 e+ |$ ]1 f0 a" g9 {7 C; u; j2 g1 Z#define S21 5
- r1 @. t3 c3 ?* _$ U. f, o: Z- d- w) H#define S22 9 + i- g: K# o/ U9 H- m! O d: }
#define S23 14 5 V6 ?/ m& z0 W0 g# m" K
#define S24 20 . B- y/ f6 Z! z# M, j
#define S31 4
* V, v, P0 b% d+ l1 i" o) q4 m5 v$ O#define S32 11
" G& ^' k& D( w6 i% F6 z" a* u#define S33 16
9 O$ D$ @- o" a0 ~4 m+ e#define S34 23
+ V' G0 W) J+ R0 J#define S41 6
; Q) R: d7 e+ ?3 M2 f9 q; V#define S42 10 % ]8 C& N$ `1 r
#define S43 15
) Z; J( d! x6 x$ E#define S44 21 . b. [% y# |* i! G" g
' p) Z5 D" A# _) p1 W* X9 @9 v; v
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
: Y0 a( p; ? {( H* \" b/ Sstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); : ]7 i* q G- D* ^4 {& q- w; w( b
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
5 r# A& }) v, _* s; {static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
; ]+ d' `) a7 e: y) K, L! L) m; Estatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); - r, Q- J+ |4 q# \
; t0 F6 M1 I! {! u
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
9 `9 D5 c3 U4 b: y& x}; & a+ Q( P; ^% Z3 w& c# ?6 J
# B+ @) N5 g8 s! C+ Z' _ P/* F, G, H and I are basic MD5 functions. */
0 M E4 H* |6 s+ r0 G* \#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
5 F' z: e. p' b& {) X#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
; J: T3 \7 y* k) l#define H(x, y, z) ((x) ^ (y) ^ (z)) $ y' ~# x5 U$ O* w% p4 J& z; h
#define I(x, y, z) ((y) ^ ((x) | (~z))) $ r& c5 t! s- m4 X
S, P6 [5 \4 n: f B! j
/* ROTATE_LEFT rotates x left n bits. */ 1 U# a6 W+ h% \* w' E
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
2 P! D) z8 f6 U. S1 e6 ~' _
9 V- Y$ I1 d. Q, r9 {9 r5 X/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. / K. H, a6 v: D! f
Rotation is separate from addition to prevent recomputation. */
- G* @( z t' A9 j( \#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 X, z' [" E( Q! Z5 d8 p% o- O5 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); \ } 6 U w3 P1 Z, {9 a: Y
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } / i4 z7 V" Y: Z
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ( B2 S/ e% K( C$ y* Z# l" e
1 @, U6 g8 K' T" c9 U5 b: e/* MD5 initialization. Begins an MD5 operation, writing a new context. */
& f6 c: H. m% e; C( `2 bvoid MD5Init (context)
) e& ^" \9 j: h, B; IMD5_CTX *context; /* context */ |- Z5 A2 l8 C) F' b
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 9 D7 x2 e( S" q6 E2 Y# [, [
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
3 K* I4 P* P, o1 X. O4 s# o}
7 {( @3 b- R& _# s2 u ( _+ m1 c- |% n7 x9 f
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
$ a7 [ A4 l) e1 ^$ ~# Zvoid MD5Update (context, input, inputLen)
* l0 Y N9 e7 p# y& v7 G7 xMD5_CTX *context; /* context */ 6 S& j }+ N1 X# h1 b: P
unsigned char *input; /* input block */ 0 K! ~- y( b+ T. f/ N1 M
unsigned int inputLen; /* length of input block */ 3 T( t8 S0 r( x
{ unsigned int i, index, partLen; / U* L: s! e3 m7 P7 J* n
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
9 O, c) Z, L' g /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|