|
#include "global.h" 7 p. R% x2 |, K: m$ J3 E
#include "md5.h"
1 D+ t _: ] \6 t* ?
, g; w( ?" ], O+ b# s, }; l5 R/* Constants for MD5Transform routine. */ s6 o" j j, ~1 B
3 v, ^5 Z1 N# A+ f6 N
5 O% U) ^; }1 b$ r1 A' c#define S11 7 : w% Q6 \5 q$ c$ a! p$ ?
#define S12 12 6 @1 |7 |0 @$ a
#define S13 17 & I; {* O$ @( E
#define S14 22
0 ?! M' d" `. l+ l1 b; n#define S21 5
+ ^' N: n2 C8 d' ?* k7 v0 q9 k#define S22 9 ' f; d6 Q4 F: O+ |/ t! B
#define S23 14 ' X7 E, J D) ~2 s5 z% \! u v2 i
#define S24 20
6 j6 `' c }( @! R8 r1 B4 N. F4 E#define S31 4
; N! K5 z, O4 W9 m$ H" Y#define S32 11 3 }, F0 G3 g# g7 t# u
#define S33 16 2 t4 z" g1 B$ j4 {
#define S34 23
" N5 x8 n# P; ]& q) S; H#define S41 6 / p3 l- L4 Y. ?2 U
#define S42 10
* {; Z$ _2 w1 g% U- M6 u n: I& a, N#define S43 15 8 w7 p. V" o( V0 b' B
#define S44 21 2 z1 |& I6 R4 F: Y3 @
% J( |% {9 z2 u% Y! _static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
$ J' F+ ]9 s0 D, Dstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
$ x$ J7 [) k& l( v9 ^static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
. }7 Q8 j7 \8 z* o4 Astatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
% T. v$ I3 `" I9 I9 _, Rstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 7 z. E/ _3 s/ m2 u
- y- ~. E. Z; S7 Q& p6 e' a- p
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
# Z: O0 w, h5 L}; 7 }. Y9 g z9 q& R5 W5 U: L) B+ B6 r
2 f4 u- x f: h. I. C+ H
/* F, G, H and I are basic MD5 functions. */
8 A; O/ ^9 j3 p5 f `& g0 ~#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
* F! X( I/ D* J [! I% d#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) # A+ }( Y+ J; N; @1 e
#define H(x, y, z) ((x) ^ (y) ^ (z)) + p- e1 ~0 l3 n8 q, V6 o6 z8 G
#define I(x, y, z) ((y) ^ ((x) | (~z))) 0 P M3 Y! [, m( z
" L* J! ?+ G9 C4 d& `; c" d
/* ROTATE_LEFT rotates x left n bits. */ K( [) o* t7 d, \0 L% P* x( h
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
5 p$ e0 c% h9 Q& z3 o
) O k- `9 ~$ z6 A$ ~/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 8 V$ q2 [. b* i$ u7 r% D8 K$ v Y* y
Rotation is separate from addition to prevent recomputation. */
9 {) Q2 e y% t( ~8 a$ H0 x#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
5 i. p( ~& \ l" ?' D5 w#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
, D: |: z1 Q! O4 u3 x#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } / Q N) N& i- w4 C) n- W' z+ H1 \
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
6 F/ e1 S8 l/ ^, B, k! H% P ' D& p8 g: U- C/ `$ R0 a" S
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ & n- }4 c- V9 }. Y0 c! P
void MD5Init (context) ( b- f, ?6 Q% b. h# U1 j
MD5_CTX *context; /* context */ 2 e" v6 S9 \. q3 `) V
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. + q: ]; [! @( A% L
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; # U5 y8 g( R; m. b, W
}
' ~. J( m) X& S& O2 E % e' V0 T: n* ^1 Y) Z% t
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
9 U9 U, _" E& E ~( f0 ]3 C. d! Svoid MD5Update (context, input, inputLen) % {* z* f3 D `3 W& p
MD5_CTX *context; /* context */ ( L9 j c+ V. G% Z. h$ i3 ^( \
unsigned char *input; /* input block */
7 [ A0 ^+ Q: F6 Qunsigned int inputLen; /* length of input block */
2 s( Y& S6 N- \ T) ^+ \& P{ unsigned int i, index, partLen;
! ] F0 W$ ?# m/ W. y/ R /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); # t# L& v5 J3 y
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|