|
|
#include "global.h"
5 Y5 L9 R7 \. y6 Y#include "md5.h" + [; ~. I7 T% g1 ~' L
/ j. a E' D3 N+ a d
/* Constants for MD5Transform routine. */
. g3 v! C2 D) y: @, G ~2 _1 ?' y) Z" }; U' A
' W/ |- M1 U( {/ f- v- {) o#define S11 7
/ I6 _- w" C4 @1 Y6 d) z L- h#define S12 12
- d$ C8 H; E+ q) I$ U#define S13 17
6 p4 M, [+ Z5 b+ n#define S14 22
" H8 o" _( |. N+ n; _#define S21 5 2 @) Q2 @; d2 p5 \
#define S22 9 p, c) q! F/ Y6 I' x
#define S23 14
9 W s, r' F+ E3 G) n+ y#define S24 20 u" Z2 d# z0 Y0 L1 P* M: [
#define S31 4
' M' }$ z, f' E" t# I& ?1 v% U* ?. l#define S32 11 " d1 ]' b% ~ c9 b- G
#define S33 16 ( D4 m c2 e4 A$ j2 C c. J' G
#define S34 23
6 h! U9 P0 q0 K4 m$ G! b. V+ p#define S41 6 ) y" J+ o+ U: {2 Y2 ]7 n. W; k- b8 \
#define S42 10
& p N) |2 B6 C' q#define S43 15 h8 z* O" l2 J+ w4 u! T
#define S44 21
4 j3 S# ?" A) ]2 R k+ @( r5 I
3 l1 g, D5 G1 d+ L: lstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
$ I; `4 l2 `! s: O- jstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ! w/ p+ v9 h% _' \
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 9 ?& Q) ]' i0 Q0 b
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); # k4 \# w8 A) m
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
1 Y8 m/ w" E! X6 t2 }! j& c
7 y$ T1 I; `- C' y$ r$ N% u) vstatic 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 3 v- J" w2 y) ]+ d% w+ E) E3 J
}; $ e' T5 X2 k K9 v+ O/ T
0 E* o& e5 r a) n* X/* F, G, H and I are basic MD5 functions. */ 0 `, v: _+ U& j# l
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 1 D6 y4 q7 A3 a( S
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 2 @1 ^, x+ k; m2 s/ y! w
#define H(x, y, z) ((x) ^ (y) ^ (z)) * I. [* v2 X; {! s$ ~2 m3 {
#define I(x, y, z) ((y) ^ ((x) | (~z))) & ]: }" s- h, m$ C. c
) O+ ~8 R1 U8 `8 p/* ROTATE_LEFT rotates x left n bits. */ 8 C* s0 K' ], z$ X, ]
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
, n; s: J5 {: ? O
3 r7 ]# n6 t9 ~- W/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
; A$ q7 E/ Z b) o' t7 h2 n& }Rotation is separate from addition to prevent recomputation. */ : g- a \- V! [. g! d
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" Q! Q0 s5 C" Z3 _#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& O1 L4 i8 s+ k& e7 v#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 L* F+ u8 e/ K% e#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } & @$ {' Z9 y2 l" `9 K
! `+ Y' i. \7 d( Q0 x/* MD5 initialization. Begins an MD5 operation, writing a new context. */
/ v- }: F7 l0 D+ `8 s8 uvoid MD5Init (context)
* c) W) e% r/ f- L8 ?/ ^* QMD5_CTX *context; /* context */
% O, d' h8 k6 \8 Q- i5 {2 c{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. & X8 l2 `5 n; v1 W" o" H
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; ( s1 ?$ G6 }9 u8 \# Q
}
4 n- i$ Y5 ]) j) G % k4 f( X! D! o
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ # |& N1 o& D. b' u: S. m$ g
void MD5Update (context, input, inputLen)
, U6 \, u5 s# u) `; [4 F- IMD5_CTX *context; /* context */
2 a7 W& |/ k% r) @0 b: c2 iunsigned char *input; /* input block */
+ ^. k: ~( Q" ?3 } L; J! Sunsigned int inputLen; /* length of input block */
7 d" @$ W% l$ |3 W/ J7 y/ L{ unsigned int i, index, partLen; ( \1 j7 d- t% p: h: @# `1 @
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); / u& t3 m: f6 p7 b
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|