|
|
#include "global.h" 7 d) G9 q7 w; L. b3 o% u4 v
#include "md5.h"
3 O2 {# h8 a) l& A) p
# Q) a$ [& b5 J; t( [/* Constants for MD5Transform routine. */
5 K6 E. L# a7 A$ J9 P0 { 5 ~" E# W' w+ v) ~
0 U- m- u9 O6 G4 a u1 F7 O& @
#define S11 7 1 C6 |, K6 d2 H! q
#define S12 12 / T; `' s. B+ @$ Y T/ Z* P) K4 k
#define S13 17 6 ^) a3 }* @/ f
#define S14 22 # j; V; M" j: a G! i5 F# I
#define S21 5 ; `' u% p; L F. {' b3 \7 r/ K/ x
#define S22 9 % u1 Y8 G) f* F+ Q. [
#define S23 14
, V& h/ s/ g: K#define S24 20 3 s; \$ T e" v" ]1 f' j
#define S31 4
/ N& @/ Z% h/ ^2 Y% L+ K4 @#define S32 11
3 b; I. T6 C9 ?#define S33 16 ) T8 e! ?6 t+ y9 M1 K
#define S34 23
6 s& D7 f2 z. |! h* `/ I#define S41 6
/ b# ^$ r6 s4 f" z) o% Q#define S42 10 2 ^' |$ y. Q; z6 t8 j# |, C
#define S43 15
2 G& R x, ~" i. D0 E; i+ I3 p#define S44 21 0 p0 \4 L' F$ G8 `0 }4 T) W
& Z4 q. V4 l* |$ N7 ?' g# `8 Gstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); # \! [: R" W4 t! F ~
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
! i3 H8 ^6 X: l% S. @0 Nstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); * n9 t. V$ W: O' O% a7 i- m R% g
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
. H" C' l0 ]! y4 F: V5 tstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ' g+ m$ c/ y( c" K/ P
6 D2 v7 ]! p$ R3 ~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
F# V* x; G: h% d};
3 j8 @. C* j4 O$ N ) w5 s) { I3 y
/* F, G, H and I are basic MD5 functions. */ 5 Z, C8 p9 u1 B- O) N
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
9 T; v+ b* x: N, I, ?9 }; J#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 1 h6 N( d/ B, [) ~9 B1 }
#define H(x, y, z) ((x) ^ (y) ^ (z)) # F: v3 _( x- e8 m9 ~
#define I(x, y, z) ((y) ^ ((x) | (~z))) 3 a& L9 J F; N- z
3 `3 V& v) A* l4 w5 G8 ?7 }
/* ROTATE_LEFT rotates x left n bits. */ % ^7 ?) J9 e8 e
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
1 b3 B) @! m7 k9 i4 e ! l. h8 K3 e7 p1 Q% ~# F
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
9 @& R, J* d8 p% ~Rotation is separate from addition to prevent recomputation. */ " `, j2 G I3 ^- W- @6 |
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
, x6 N; g% k( ]: _( y! u#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ; w! M6 o0 W6 {8 m
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } / ?& W( l" O9 I' Q) `; `" e. ~ ]
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
# y" Y- M+ ]0 |, f# L% m7 |# O) }
& |& b' R$ C7 D1 R2 ^3 |7 D/* MD5 initialization. Begins an MD5 operation, writing a new context. */
1 c9 f5 Q& p2 f* p* f7 B. V0 Q2 pvoid MD5Init (context)
% W6 j( g5 j2 Z4 t% n$ @$ \MD5_CTX *context; /* context */ : j. \1 G1 U3 B) F
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
" B( F5 L( x1 N3 Z1 d*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; " C7 Z. r% ]% p/ N7 C5 h, x
}
9 ^% E- n' i. v" `# e0 p9 ^ * y* r' @- k8 \* i! ?' E7 `
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ . x7 G3 S; y4 K+ a- N
void MD5Update (context, input, inputLen)
; Y }' i0 C$ s2 f+ E8 s# H/ ^2 n3 sMD5_CTX *context; /* context */
( y5 M. ?0 ?6 a4 v+ ?unsigned char *input; /* input block */
- ~8 q, e: x% u! y( Q6 ?unsigned int inputLen; /* length of input block */
( q2 N% e& r$ N9 c1 u# y7 p& J{ unsigned int i, index, partLen; 5 h; ?" p( q8 d% _! Z/ f: s
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); + j$ G7 W1 G& ?: {
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|