|
|
#include "global.h"
9 C. |" P# }5 z; z#include "md5.h" ' I; n' `# M+ R. U% I" K
& Y; n2 @! {% I. q/ k" e) Y7 S
/* Constants for MD5Transform routine. */
4 @4 T: v+ }" A3 `2 _ ' S8 P3 q2 r# T; E
) f/ ` {; g% A* T
#define S11 7 . j' ?. Y9 g0 F8 V; J; e0 c1 C5 t1 B S
#define S12 12 9 E9 C2 M; _4 X
#define S13 17
6 C# P" h2 y: U$ l4 ]4 U#define S14 22
3 ~# Z1 J( f/ h1 L8 m+ h3 b: @5 s#define S21 5
( [) Z+ |* H, g/ p" J5 E7 s+ T#define S22 9 ) G. I6 Z. H& Z$ D- ]3 t, q. t
#define S23 14 ; Q( A5 u0 _! B* ^
#define S24 20 0 q0 I# U+ u9 b n0 f5 O0 k5 P
#define S31 4 9 i; U/ |/ y' |; w
#define S32 11 2 x0 N7 r1 N/ X) T, c
#define S33 16
" y% L* {8 e. q( Z% s#define S34 23 0 H: J! u- }: Z, T- A% `% n2 ^
#define S41 6 . h6 q8 n6 m* Q4 F5 q* S2 H
#define S42 10 . U5 \, A( d9 J8 | a; ^
#define S43 15 . E$ `& ^# F5 r. A+ ?& l- Y' m' Z: r
#define S44 21 3 A6 X6 b4 v3 E. x0 {: f
9 u$ U# v6 k" j2 u5 o
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
, \5 V0 F) N- O9 M% Nstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
& y' ]# s+ _ g# hstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
% o: h | r+ r4 o; K3 b! kstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); , B" q: A% g1 E" ~5 c
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ! g8 U/ v& y" e- n- E8 ]
7 u8 a9 W. t1 _& P# F
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 # U% ?+ P7 }4 J$ O8 `
};
. b5 {1 F+ H: | 4 t! X0 m5 R: \4 V U6 ]8 W
/* F, G, H and I are basic MD5 functions. */
" g$ E: A9 c: U#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
% p6 Z+ U3 J9 [; S5 N5 p- ~#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) # k' t. X# L# H3 P% o5 E
#define H(x, y, z) ((x) ^ (y) ^ (z))
) `5 S; \3 H2 s5 E$ u' c1 t#define I(x, y, z) ((y) ^ ((x) | (~z)))
: c4 e! K) z' `# ]* C
9 Z- _" A. a O7 S+ I3 ~' S6 ~/* ROTATE_LEFT rotates x left n bits. */
& {4 l& F% a: C, h4 ?6 f0 F R6 v/ T#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
7 ]& n" c3 n- W5 U
" p4 Q+ ?. L; X: s* A' ~+ n/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
" ^/ V3 e. v' Z0 g7 N' uRotation is separate from addition to prevent recomputation. */ 0 ~6 g+ s3 E" H$ o {
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& h8 y8 v# j6 B#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } / ?* l6 z& r. ?( s4 d# J
#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 n' C& Z. C0 a+ o# ^# |+ f' q. R, R
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
5 b9 F) ] U) G0 v , K* f0 c0 u/ g6 m
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
. k: w$ C5 S9 b& @void MD5Init (context)
3 v9 E/ q5 x$ w6 jMD5_CTX *context; /* context */ ( }7 u9 k* [/ o( V- q8 s0 z
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. , V! i6 U" @6 I0 i1 T
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
+ D6 j! a1 E) @2 f a6 w4 q}
. a, M; p; Z( @
& W( V& H/ J# I. g% x/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ ]7 E; w4 p' o7 B w
void MD5Update (context, input, inputLen)
: |6 ^# N$ a9 t. tMD5_CTX *context; /* context */ % P/ f# b& o5 [' H9 f8 }2 J# G
unsigned char *input; /* input block */
8 [7 i# ?6 o* H( R3 _1 Hunsigned int inputLen; /* length of input block */
9 w; o5 X& U0 g{ unsigned int i, index, partLen; " h7 ~5 v$ S: e, y9 b8 C, f. B! j
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); : G: }4 Y6 H% q+ {
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|