|
|
#include "global.h"
5 o2 p7 n; X" C7 d" [0 }#include "md5.h"
: q! Y m3 g0 m4 z& ^+ @ 5 p$ |# ?. K3 E: H
/* Constants for MD5Transform routine. */
4 u9 N4 b9 V9 p
5 j8 F- | {- q, H/ h1 L) s
t5 k( K% z1 t#define S11 7
! {" Q3 q; _( u/ H' o' A! ~#define S12 12 ( K$ T2 @, i5 e% O8 h& r+ y
#define S13 17
: R. i; k1 P9 L! N. t+ v#define S14 22 4 h4 I% V* ^+ c5 @& i, p/ d
#define S21 5
/ u& {6 T# ~) E0 Q3 Z#define S22 9
6 q: R6 i* W, F4 o' G#define S23 14
9 W* r J$ ~8 N5 l3 a& _+ i#define S24 20 0 [$ o5 t" W' S* W6 ?
#define S31 4
2 P8 z8 r- V* `# r#define S32 11
7 f; W- ?7 L* n6 _#define S33 16
% ~+ L. D+ w5 E- m; U#define S34 23
3 a" I: Q# l' l, n- e0 p% d#define S41 6
+ V8 A' v% J2 p/ K2 @- ?- z9 N#define S42 10
8 R$ y5 E* {0 q3 N" o0 M% L#define S43 15
" D' o+ \! F# m#define S44 21 4 K: u. x; V2 z
3 D7 l0 K9 b, N* x9 ^static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
, |: |$ Y; M! k# K* Q [0 Estatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ! l; D( G- {6 U3 q- M. W3 i' L" B5 C
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 6 K# D. d0 l, v0 o, I7 w* C3 j$ C
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); + r/ w J) @" n, |
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
( Y& H2 n! l4 G% K* S8 d0 ]# g, l
( G) W; b: r- ^. r+ T/ Sstatic 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
) |, v' S7 t& }6 Z/ M5 Z. i};
5 A- B% k% I0 Y+ o) N5 G ( }" w% }* e& j# g; U+ N+ ?
/* F, G, H and I are basic MD5 functions. */ 2 S$ p5 u* u. ]
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
1 _2 `" B4 u# p+ L* z#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
) a) f6 u4 g q1 [8 r+ q1 F4 A7 H' `#define H(x, y, z) ((x) ^ (y) ^ (z))
% @/ c7 h" C& ]9 b6 l$ }! v3 r, l#define I(x, y, z) ((y) ^ ((x) | (~z))) ; Y; ^2 {; p! x% T3 T6 P* Q+ Y
, _* a4 n8 T6 h% e
/* ROTATE_LEFT rotates x left n bits. */ " r: O1 `6 j) {1 t- [! c: C `
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) d! `% w7 }! k4 b- B! g
+ d* k1 [ K- J2 m Q1 N+ o/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 0 c, e; A* W! l3 V# m4 b+ v
Rotation is separate from addition to prevent recomputation. */ 0 u1 P; s& u4 M
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
5 l2 _9 i* I$ j% Y/ x#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, @7 X0 M; g1 _( B
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } % f: b: t \. c# I
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } # b- |6 r: H$ @* w) `" W
) S) g! _- A* W
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ , ^2 f2 f. M0 L( u/ a1 b
void MD5Init (context) A+ }, Q% W# i' u, O w
MD5_CTX *context; /* context */
$ D- w; n9 n5 Y5 v& n+ q{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 4 X. L- Q, d$ k
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
& ~7 d$ X9 k2 b! l. L' f' t$ B}
- R4 B" c6 F* M o: a: ] ! V7 M6 U& P+ z! ~
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 7 I) H1 X6 z: U T1 Z4 [
void MD5Update (context, input, inputLen) , S) y5 ^+ r4 P' s$ l" Y& G
MD5_CTX *context; /* context */ % q6 x6 ~# P, t! d( s5 B/ X$ _
unsigned char *input; /* input block */
, ^( X5 D% f M: p/ q! M. f( vunsigned int inputLen; /* length of input block */
! F# j" a- T2 d$ C- w5 \6 [8 R{ unsigned int i, index, partLen;
) D. X7 j# L& a( H /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 8 N: x) B- B0 F' v5 W; K) t
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|