|
|
#include "global.h"
! c& O! W# p; O3 S; J1 ^: T#include "md5.h"
4 P7 S! q' H9 x' T- u
% b" z: D7 `' v: ~/* Constants for MD5Transform routine. */
$ g( m, U. ^: d ]7 z
" O# Y$ [# O8 W; G ! ?5 h4 V7 y5 ~
#define S11 7
) r- O9 J+ }. I0 V+ d#define S12 12 6 s; Z; `- {6 k' Y" K, t8 |
#define S13 17
3 T) _* Z6 U: S; E#define S14 22
0 C/ r# f( T1 \9 c, L8 e! f#define S21 5
* t. N, L) q2 r) [, H& ^& `6 N6 K#define S22 9 7 k$ _* g; q1 }5 v. N& I
#define S23 14
2 R# K ]' U" s! E1 \#define S24 20 * G5 U% |, L+ L4 S3 |' b, v
#define S31 4 ) E( f2 [3 V6 s" h: \$ Z
#define S32 11 ; f1 }. @+ A% c# f# _9 S% r- D ~3 U5 Q
#define S33 16
! O5 N; V* E" F/ J2 x8 g% k" f) Y#define S34 23
7 ]2 }; T2 A: e, h: Z B6 B#define S41 6
/ j" ^) D, H; i6 [1 d0 l x#define S42 10 9 g6 V+ ]0 C" d9 ?# z$ {
#define S43 15
* [8 W3 p+ v# e% T( v6 \. S* x#define S44 21
. [* I8 \' X N" W( B! |; g) I + |. S2 Q$ g4 T
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
# x6 F1 A. {* |* @+ {static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
. D& J6 m/ H8 S1 h6 t: @static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
3 v1 w; e* n* X+ Lstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
! b6 h m, t; a, Z! q3 M: S& ]static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); / q% U+ ^; z7 i- a
, j: c3 B2 k; ~7 K7 B3 }, Astatic 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
$ \( j9 @1 X" Y5 A$ s1 B};
: _+ ~* d, z% h
3 l0 u4 N1 g1 X# ~# y, B/* F, G, H and I are basic MD5 functions. */
& ?5 ]/ w, g. n; b- r5 ?* X#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) + A4 t4 H4 C6 i7 [, ~
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) + L0 p# d" ]/ b( [5 ~2 r+ g
#define H(x, y, z) ((x) ^ (y) ^ (z))
) M/ d" S1 @2 v8 D0 A#define I(x, y, z) ((y) ^ ((x) | (~z))) 9 `( L( j; m) R, F, I; Y n$ p
* l/ T' _+ a6 N! H, G8 _# B/* ROTATE_LEFT rotates x left n bits. */
. V5 f! T8 {9 d+ z* K#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
& s+ f. }" g7 X# a
3 f" h2 V2 y- R8 K, {2 p$ H/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
) w4 Z& ]% H& R' ]" l. }8 ORotation is separate from addition to prevent recomputation. */
7 D, o' ~8 I0 b5 ~4 M, ~0 h#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
/ L$ P& o; X, D( U9 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); \ }
+ f2 ]9 J+ e2 x8 K. r7 O$ T#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } $ D0 l- q9 P# \; I* p: E+ x
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
0 }" p) z% Y* g9 i6 C9 W5 N7 J , B, v6 r7 c7 J( X1 h
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
$ J5 }* `" ?, _7 z: t D' t6 a* ]void MD5Init (context)
+ E" ^; C% a( I; H4 uMD5_CTX *context; /* context */
+ ?5 v4 l0 t3 d) z{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
) k- v5 a/ f+ S+ j, N$ \*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 1 _$ k* ~, q, h- x- H9 |8 F/ Z' {
}
) D' l( P, m z+ N' E 3 D! e3 |! u$ n$ j
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
6 `2 A0 \3 @7 x& zvoid MD5Update (context, input, inputLen)
g. X' {0 y) c! p ^MD5_CTX *context; /* context */
- v7 A6 I' K3 c8 f+ `unsigned char *input; /* input block */
3 d8 b! b& w ]- ^& q% k9 s, G6 xunsigned int inputLen; /* length of input block */
# ^. |% }# ^ u9 k- Y0 Q0 v8 U{ unsigned int i, index, partLen; 6 F; a; i0 n& L( I! t( R: H
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 9 q# ?5 I' r' h9 \
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|