|
|
#include "global.h"
; M K, k$ E/ p: s: i* E/ C! f5 e* H#include "md5.h"
! k0 u+ A8 ~6 l; S3 |& ^ 0 N& @3 f! g, ~0 s1 @
/* Constants for MD5Transform routine. */ % A, E6 c) J) I- }" }
|, \$ ^3 n# l7 m' X3 n" x
: n+ z* u/ n. {- H#define S11 7 $ Q$ E: Y: G! e! a9 p; q- T- ?
#define S12 12
( \, S, Y( R% c9 n9 W#define S13 17
* s" X" @: ?" [5 T0 \#define S14 22 9 d- e$ }/ q& |
#define S21 5 , c; n& K, ~. e n4 \2 p: I8 ^
#define S22 9 t" C& b# C8 r
#define S23 14 * r J5 ]) u( j5 j2 N
#define S24 20
3 d2 o9 S8 _5 Z" u#define S31 4
$ t* O& \: c1 D; t#define S32 11 , G9 s r" M" O% k6 B
#define S33 16 . H3 |- N3 }3 g* o+ T& r
#define S34 23 : h) ^5 F: M) p+ g
#define S41 6
1 R2 ~# j8 z3 ~% Q8 q#define S42 10 8 w' f6 G7 ?3 }) E9 V
#define S43 15
# G2 K3 `, e5 ]' H5 }) n# O& V$ T#define S44 21 3 y$ q+ o; D4 t$ O5 w" w' Q `
" Q' V# f. d& j- ]. I! W. r2 m
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
2 M0 D$ [* c- T, d" Gstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); - c$ |" c2 B; {$ }5 p/ A
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 3 z0 A- j3 a/ O( T
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); * D0 i: I s- z5 T. h# J
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); , i8 _% N1 N5 ?$ e
) c- X6 w" j! d. o/ e& j) ]% q
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
2 y0 r9 @& [; ^4 `8 x, q}; ; X- s( y* m0 d' I7 D) o. p
4 D! o$ ^* B5 H L1 B0 w8 x2 R/* F, G, H and I are basic MD5 functions. */ , T& H# h% g7 [4 Z& Q7 O$ F+ _
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ) l. C/ ]9 B$ v) C3 p. z
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) , D% X4 |5 @4 z2 Z1 y! {% @
#define H(x, y, z) ((x) ^ (y) ^ (z)) ; m! [. }' V' u$ l* ^/ ?
#define I(x, y, z) ((y) ^ ((x) | (~z)))
# ^; N6 y8 K/ _- W) y. \+ |, H8 b, X 1 p0 o$ Y2 g! F# U) n
/* ROTATE_LEFT rotates x left n bits. */
0 C( m- Q7 q. r3 c* W8 y#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
% @0 [; A* I. x, @. | . [* `) }0 {: X+ W8 V( e; r# ?# z/ g
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ; g( ?5 g/ H" L* V9 D( ^
Rotation is separate from addition to prevent recomputation. */ 9 r L! S3 T8 Q+ z7 c
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } i c8 ^. D3 j7 N' z; r
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" \. k# T" N8 \! B+ W4 p#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ! h! X$ `$ N/ y0 f& F
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } " X# _: H* k& w* H2 J1 L
2 V% O0 X0 G9 r; c( _5 \0 Q/* MD5 initialization. Begins an MD5 operation, writing a new context. */
: s* s7 V& m( bvoid MD5Init (context) " n7 ~+ g6 K1 h2 C
MD5_CTX *context; /* context */
7 p! c7 U" j' r{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
' o% k. `* d/ z! F. M# R& t' N*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 3 L% I! s/ D" ^3 X
} 8 v+ L! ^- H% Z% J# m: y* q+ ?
n2 f6 R( Y: O. R( b: L0 x
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 1 Z7 b" J$ B; o& D3 b% T& |& N' ]8 V
void MD5Update (context, input, inputLen) . u4 o* Y. W" k9 ~
MD5_CTX *context; /* context */
5 `6 [% Y3 d. e$ p2 uunsigned char *input; /* input block */ * n$ i/ \: M+ x8 ~: x: E
unsigned int inputLen; /* length of input block */ ( ]4 g& Z; U# t
{ unsigned int i, index, partLen; * L( M/ M) |3 N2 T# U
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 0 a/ T5 [1 D8 u" }. t, y
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|