|
|
#include "global.h" : N4 o/ k/ R, N$ a
#include "md5.h" ) H5 q7 R, d9 O1 ^+ s
: z& q2 c& }5 n2 ?, t% f8 Y) U K
/* Constants for MD5Transform routine. */ ) J$ |, Q+ F' B
3 v6 o5 x, h1 n" b2 r( _
) g& A* o7 A2 c#define S11 7 3 r! R9 g& o" }% Y0 K& B% \
#define S12 12 s. j P, p" i | d, Q
#define S13 17
+ \; N$ \" v; f/ y z#define S14 22 & @! T+ l$ r6 H$ p% z* d; `5 v
#define S21 5
- J% F7 G( v5 {- k; w7 b. c6 B f1 `#define S22 9
# \+ U9 b) v; T' r7 Y! b#define S23 14
2 c$ \8 |# D0 N#define S24 20 / h# [3 h5 r& |
#define S31 4 $ Y+ M% M8 T* N, B: i5 J
#define S32 11 ; G% o" ^2 ^) a* C: A9 t9 k
#define S33 16
" h1 [- S, k c: ~4 L" A. t#define S34 23 " T) V) N! l7 j/ ^2 L, w
#define S41 6 7 z+ c+ [! k0 I# ?
#define S42 10 5 h, [4 `& o$ Z. f7 Z) b
#define S43 15
2 R3 v. M) E1 b0 Q! Q8 M; _# `#define S44 21
( U' ~) u/ q) o4 g, H0 A
. J- v* U2 M& K, Ostatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 9 H# ]9 A& O P' g
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 5 W% C/ g9 H0 h- a o
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); / ~9 _5 [: v( p& E
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
5 [( R# F% i4 w/ o" X/ b6 rstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); % Z/ p7 z* t2 Y& |/ x9 i
2 s# R0 s% ^3 ]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 & X, {/ F5 ^# |' ~
};
* \ w" R: l1 F. G) F7 S
7 P9 n6 A' {% p$ B3 h8 P3 w/* F, G, H and I are basic MD5 functions. */ : o5 e; E" `. ?( V: k
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
% _; O; w7 [* N$ B( d#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+ x4 |% p% e6 v2 E6 v#define H(x, y, z) ((x) ^ (y) ^ (z))
+ ]- y7 Y+ P9 ]#define I(x, y, z) ((y) ^ ((x) | (~z)))
; S8 B- }/ T/ y# }' H2 J8 I0 n
( @5 v6 }" N1 J3 g7 z* i( {/* ROTATE_LEFT rotates x left n bits. */
, c3 A- M6 [0 V9 m' f* Y. O* E) A#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
; S; L- D$ I( W6 N6 K
. m; ?# U: i5 G8 e& |3 {1 }0 Q; L/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
. n8 G8 S0 e- j; c* C/ X. ^Rotation is separate from addition to prevent recomputation. */ 9 o* T- e" ^1 d1 r) L
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } / ^& j8 Z" x1 B! y7 Y
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" K. w% u. |* W2 b1 [ i" 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); \ } 7 X+ C' c* }! {2 B# s4 G7 @$ y
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } , V4 s8 X9 Z6 L& _% A5 A3 r. [$ p4 |
4 r% O1 T g7 m, J3 S/* MD5 initialization. Begins an MD5 operation, writing a new context. */
7 K" v! S2 C( Z/ Avoid MD5Init (context) ! B8 |- m6 y9 ` v2 F
MD5_CTX *context; /* context */
' h. o/ e2 P, a{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
/ ~: r% v) n6 Z; X9 m*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 3 }4 P% B# \( h p' R& ~
} 2 a+ s9 d ^7 q$ K) m# m+ W" V; z, Q0 p" z
4 Z1 {/ B& q1 ]% L. z5 j E2 i+ F/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
- f# x* N1 J. t+ R5 \9 nvoid MD5Update (context, input, inputLen) 5 Z1 n+ ~1 d+ E9 y7 n$ W
MD5_CTX *context; /* context */ 4 j) m3 w9 i& L) Z. f* c! E$ I# `
unsigned char *input; /* input block */ ; q/ R2 K+ r8 Q3 D0 c2 R8 }
unsigned int inputLen; /* length of input block */ 5 N+ m6 Y9 D; K
{ unsigned int i, index, partLen; 6 K* v( Q1 e& g& D* C, K
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
7 f/ _; N5 }+ Y8 A: G2 l /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|