|
|
#include "global.h" 7 e& E# k1 E7 c
#include "md5.h" 4 J8 W1 S1 E; c, u m
6 z( y4 ?1 @/ X" f. K+ _
/* Constants for MD5Transform routine. */ # }6 { y9 p, s f! Q& I+ f( x0 q8 U
9 k; [/ X) b+ b& S1 j0 s5 @+ A 8 u/ Y; ]9 n j2 y% I! b
#define S11 7 1 B) a* W% w( C0 z
#define S12 12
* Q3 t. r; e1 A+ v/ K$ ~! B#define S13 17 E, j4 ?0 F3 ~# d1 J
#define S14 22 + u7 _) Y3 a4 S; K, C% k2 g8 v3 S
#define S21 5
& ^( i7 x1 \: p6 ?3 A9 ]4 C#define S22 9 " E8 s' Y- X# b6 A' j
#define S23 14
& K9 F( b4 e) V2 x0 Y#define S24 20
+ ? T* S8 Q3 q! [#define S31 4 ! x7 U# A1 x! V% b' [
#define S32 11 5 w" R( t* X& u* m7 h* u
#define S33 16 9 o- _& K( _! Z- q1 _
#define S34 23 * T/ h6 R4 J. x' |. I
#define S41 6
+ S$ P8 A9 p, J" Y1 ~' [6 h#define S42 10
& |( D: J0 g, |; e. X9 B/ C#define S43 15
* |4 N7 W! C/ S# U#define S44 21
0 z4 o+ a; D! i& H' g i
' b9 Y* O. b# S" c5 O3 Zstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
* L; ~" j" a! c# w" B) _' mstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ' s; H' o) g7 @ {2 F' i
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
5 P; R1 l& N- L2 m) Z1 lstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
% j1 ?' L$ m0 W6 T& sstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ) x! x% p5 y- J7 J Z
& y; E. J+ h( o0 a; o H( cstatic 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
6 a4 F- b9 y, Y5 `+ ~3 k}; 8 S, v% ?5 [7 w" e* ?6 l
7 z% {/ S) J5 L1 E5 K
/* F, G, H and I are basic MD5 functions. */ : _) w: L7 H9 q0 k0 W" N: {; ]
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
% ~' L# a$ e3 I9 t8 v* D#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) ; x% ^: b- v [
#define H(x, y, z) ((x) ^ (y) ^ (z))
& h4 O! o2 I8 R Y3 a#define I(x, y, z) ((y) ^ ((x) | (~z))) 5 x3 z! E$ I0 ~ ^
, C5 r) N! O6 e9 ~8 V/* ROTATE_LEFT rotates x left n bits. */ & m+ u6 \. O+ B) W: \0 ?3 t
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
. y2 p6 k5 g" U9 p1 _ 0 g. Q/ J2 n" K: b/ {& c
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
$ p; j! ^* f, BRotation is separate from addition to prevent recomputation. */
Y4 p' F3 i; _# N1 m#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" ?. n5 G q, M8 B# H$ E* I/ e#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ; u8 t8 A1 Z. i) z
#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 c r; m) n- O0 |
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
c* Y& E( |9 k& ?1 S
0 w7 m, w1 B2 Y' M/ a- ^) O% C% H* _/* MD5 initialization. Begins an MD5 operation, writing a new context. */
) D5 c; C4 q, Uvoid MD5Init (context) 7 t0 D$ P t* k
MD5_CTX *context; /* context */ 5 L: q7 A# d8 F1 Q8 J, m
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. & d2 o& |# }5 u* Y {
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
6 w4 k9 @5 H9 B9 ^* ^' c1 B( v}
+ O' w0 Y {# @' W; ]3 u
3 t3 W0 P- F) q# t' I% z/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 6 l% y; }9 `/ u2 l/ j1 Y% J7 k3 k
void MD5Update (context, input, inputLen)
) B. i+ Y m$ O3 c5 L2 }) l9 G" h0 bMD5_CTX *context; /* context */
; h+ x0 d; M; x I5 E" Wunsigned char *input; /* input block */
2 T1 {- p; E% ~" n5 Bunsigned int inputLen; /* length of input block */ # _( T' A4 I5 o* T, k& w1 u
{ unsigned int i, index, partLen; ; `) h6 g0 v" @- {! x% d8 E
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); , @0 L$ T0 [. C5 N8 x
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|