|
|
#include "global.h"
}6 A2 W0 b. _( o#include "md5.h"
% B" t: |3 C! N) c0 @0 g. r
6 d" Z* K `2 v) p/* Constants for MD5Transform routine. */ ' b9 V" H$ L( L9 T. B3 U
) t# X I" b$ O" w % F0 R: O2 Y. H" L( S; [* b
#define S11 7
' z0 k- e, v7 Q1 ^ }/ o; X#define S12 12 + \0 G; V' O l
#define S13 17 - L& |$ q) k( ?$ k- z. f
#define S14 22 $ d) H! ?. l9 C2 h1 g
#define S21 5
1 D+ m4 _/ L% F* C% z6 R8 f( Q* l9 \#define S22 9
/ _# A/ X+ }) l) |#define S23 14 / F) l9 K# M# Y7 [- k) G
#define S24 20
R# A6 B% u4 o: u9 K" z9 u#define S31 4
- K% {) }! k2 [7 z! `#define S32 11
; [+ k- F' p$ a2 U# N#define S33 16 0 t5 K/ I# k2 Y# ]; g
#define S34 23 + X, o; v; O. H1 m& p6 n1 W* |
#define S41 6
k. y& J1 M$ O4 l, c4 z! Q#define S42 10
5 O Z1 }+ y8 i6 y#define S43 15
5 X+ a4 P2 }0 [: Y( O4 M#define S44 21 5 w9 z0 z# I+ F3 M% C
@4 M7 H3 G& u* |2 J, r0 Ustatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 3 ^8 b1 C5 u+ \8 @
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
: X1 y0 |, n0 n4 d# Y; jstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); & c. R1 ^2 ?: a4 c
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); : _ ~' L+ ?" X' v* F/ w
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 9 a$ S/ ^9 ?% Q2 i8 _, \
5 G& o0 r1 J' O& h Hstatic 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: P8 K3 J: ~9 N- _1 `};
3 ^. J( N. \2 z7 t8 P
) t0 A0 k9 l a0 e/* F, G, H and I are basic MD5 functions. */
+ n4 `6 s9 u- E9 n5 h# u9 m#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ) Q) ^# r. I3 n% x/ V
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
2 W, g5 O% @; M" X1 C/ Z" h* A#define H(x, y, z) ((x) ^ (y) ^ (z)) $ c- V2 i4 N/ n- W' K
#define I(x, y, z) ((y) ^ ((x) | (~z))) + V. \9 Q( G0 l9 k
' C: ^8 \) I; _4 O7 [9 }' C/* ROTATE_LEFT rotates x left n bits. */
. V5 _" S( t% P/ z; g#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 5 T/ b8 f) W$ p3 n0 l8 M
5 Z. |& o. T! }+ a
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
& e9 ^$ H3 c0 U1 g& K: SRotation is separate from addition to prevent recomputation. */
+ Z5 o b9 S" a% D9 \8 | U0 ]#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 6 l. [0 ^: d# b" O* I
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
0 L( l$ f, `: ]+ r4 V. X1 r6 b! u#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 q" t7 Z2 B5 `* a! f( k#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
, r. w7 }1 s7 ~8 p2 X- ?: T
" m. O9 E! n6 z/* MD5 initialization. Begins an MD5 operation, writing a new context. */ * w& ~- c1 G+ n9 U7 N, |2 i7 J& k( S$ C
void MD5Init (context)
7 V$ C/ v; H8 g. UMD5_CTX *context; /* context */ # W1 u! `- H3 P# Y
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
# Z: D/ f2 r* w# u$ |! S*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; : a' Z. V/ b L i" s) i7 Y- o
}
' _8 p* K; `) y/ s1 ?2 N
: [; M6 D. D d/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
" D6 a7 x5 e' k% Y: K& Y* Bvoid MD5Update (context, input, inputLen)
. x3 h: E, X$ V0 d. K% A. P# N; |6 AMD5_CTX *context; /* context */ : |# c9 ]8 U8 p( M4 d
unsigned char *input; /* input block */ 5 l# X9 E: W w. A. ]' D$ s( V; Z! \! D
unsigned int inputLen; /* length of input block */ $ P! c' O8 g4 T$ y! N
{ unsigned int i, index, partLen;
# V+ Z& S5 l' B- [* Q$ i) A /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
% U4 W0 p! ^1 K! j /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|