|
|
#include "global.h" 4 p" k7 f0 o K1 N1 I: M- C: U
#include "md5.h"
/ U9 e; l4 i1 _$ g+ x/ t
: H$ {7 `* ]9 S$ G" T/* Constants for MD5Transform routine. */ 4 C3 ~7 A$ ?1 |; ^+ K# ]2 ^
# l+ {8 V2 O: F! b1 n: }& W
& S) ^, w3 n. n8 B& ^8 d#define S11 7
( r9 O9 T) [0 i9 R#define S12 12 $ X' \# Q1 ~& ]# z( K
#define S13 17 0 l: N& Y. M9 m
#define S14 22
! {# j- H9 R' Q+ g% ]#define S21 5
1 M# P" N. O+ G! V#define S22 9 , R; ?5 m9 N& v7 U* Y: V5 b8 l
#define S23 14 ; d9 p9 f# F8 K0 S3 f
#define S24 20
$ E0 _- D/ F' x: c4 H. T/ w! {#define S31 4
2 j, U* u+ n% F* v#define S32 11
+ k! `- t) _: t$ F#define S33 16
$ |9 D+ s9 c1 ` k2 }, N#define S34 23
5 x" F# w: R+ q+ W#define S41 6
9 P" J2 v/ v' G/ n4 [; X#define S42 10 6 U: {: C& v+ j1 m
#define S43 15 , M+ b) e' ?3 a2 m; R
#define S44 21
; i% q& l! z& X/ [! @ : ~% k; S+ p9 s, q
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
% v+ Z3 |0 ^8 z4 zstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
+ I2 ?5 T% d) S9 e }7 C. `) zstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
7 b0 |% z) I% d' _2 G6 b* }static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); ' y) [, u# }! b2 @$ k
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
7 O3 K4 {4 V% l w l0 S ) b9 y5 q3 Y/ ]9 u
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 ( S% X( [, T$ u! Y
};
U8 F4 Y# G* h2 {( I
9 g$ L) h, z( Y7 X& R @9 V/* F, G, H and I are basic MD5 functions. */
. ^$ j0 M$ D1 e3 m( d#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) & x; x5 v# p/ _4 W! q3 Y
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
: ]2 U+ p' D' q1 [( @+ H#define H(x, y, z) ((x) ^ (y) ^ (z))
, \& h" @2 k) i1 N$ e#define I(x, y, z) ((y) ^ ((x) | (~z))) 4 C5 ?6 x1 {2 s0 X1 W
7 h& ]9 l! d& t1 }; @3 ~: t
/* ROTATE_LEFT rotates x left n bits. */
* r2 W* y K$ G/ [: d0 v#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 5 `% D1 Z) j7 I5 h/ {8 _. `+ u9 z$ d/ Z
% o) R9 y5 @7 Y- j* w& m
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. % j% e9 m5 J- J
Rotation is separate from addition to prevent recomputation. */ 3 U n$ l# l% l/ u9 a
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ) W4 H' ]& E+ N+ R ]2 n+ d
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } . w9 U6 E% f& a: ~/ s& B/ a" m3 o9 n7 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); \ } 6 J8 ~$ Q5 |/ t5 P& D
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 K+ _" Q6 P# C% G, }4 H) y
; s$ Z: X. y) d9 W6 h
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ , e6 \& j" ^) H2 k9 Z9 \
void MD5Init (context) " B: d% _9 t6 l4 p6 h n1 `5 n
MD5_CTX *context; /* context */
1 G0 ]# D, `1 @$ s9 t3 u{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. % i' ? ~9 s. l( l. Q
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; * z. l/ u2 [, X( q" D8 w9 l
} 8 }' g2 K$ V+ Q* a; v- G% ~1 m
5 m, e6 R/ ~$ b8 W" T) R/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 1 }( }+ n" b" |3 z
void MD5Update (context, input, inputLen)
! t9 ?5 X% c2 E0 [% s5 i8 VMD5_CTX *context; /* context */ & V% \" d( q4 y3 Z* r7 K
unsigned char *input; /* input block */ 7 b x A7 ], `, U' J) ?6 w
unsigned int inputLen; /* length of input block */ ( [$ O0 n9 Q; u; i. t
{ unsigned int i, index, partLen;
# S8 Y5 G$ U& k /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 8 G; @ H Q9 c e+ ]$ q
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|