|
|
#include "global.h" + ?! S, M/ [; G3 X; h0 ~) ?0 J
#include "md5.h" + O0 N1 N5 B% D9 w" F5 p+ Z! q. F, L
2 H$ v) k! Z1 S2 u" m5 k/ t8 T# o
/* Constants for MD5Transform routine. */ / s9 g1 i5 v; V' c+ i
3 Z; S7 t( M) b* r $ D, G) ?4 G: k+ {- W5 f
#define S11 7 & c d8 |- K, [7 p) Q; c1 Q5 d
#define S12 12 & o& J4 T. k* o5 O J6 j; n
#define S13 17
3 o$ ~1 R1 e9 | c' t#define S14 22 - O, S) g3 b: ?# g( x, h! n6 T" G$ k
#define S21 5
9 D1 {, h/ }7 Q$ [#define S22 9 ) a. h' Z# p. r, ?; t
#define S23 14 4 L7 t+ F3 u2 \- ?! K
#define S24 20
3 |- g# x# M; L- m L#define S31 4
. |: A* w. M) F/ A" M' Z1 B+ {#define S32 11
O2 }, E2 }: j/ ~#define S33 16
6 T4 L! d1 J" A! g3 N) h+ }#define S34 23 : O8 W+ M5 [3 a6 V8 a
#define S41 6
6 J! E* {8 B, P$ e! \$ k1 B$ _- ]4 v#define S42 10
( R/ u( {9 O2 f7 @5 I8 q `& `8 z#define S43 15
6 J& J& ~1 C; |( P) Z#define S44 21
P0 y1 ^; u+ C! q0 a8 G h
. G" h: ]( j7 ?5 K) T' ?4 ~static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
7 d( c9 L9 b/ U* _+ ?" X# q; cstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); $ N" e- e# ?- O& V$ k
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
2 F% d' |0 g4 K, u' ^+ t( Hstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); " p7 z* s: i) X) @- F6 m
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); , q7 |. i1 A7 W: `- B( y
! K4 J" G7 o) Fstatic 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 4 Y* `) H. V5 u; r
};
$ U1 Q9 s7 \+ c' D5 k
; c/ D R6 e6 @, `! m# D, B& l/* F, G, H and I are basic MD5 functions. */ ; M6 z2 {9 Z5 `9 l" x, e
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) , E& z- ]. K+ Z3 g) I6 m
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) # n: h: ^3 X' ?( H: S% U
#define H(x, y, z) ((x) ^ (y) ^ (z)) 6 @6 I- b0 a0 m, u' r
#define I(x, y, z) ((y) ^ ((x) | (~z)))
6 d, W( o) h! Y6 x6 f * q V( E G$ }+ y+ |2 _
/* ROTATE_LEFT rotates x left n bits. */
; @* m. W% O( D+ k$ f0 A* a#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 5 u4 p" Y/ s- b6 O# b# e
3 T; ~1 R6 y* H( ~/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 7 M5 R9 D* }7 W8 i" g
Rotation is separate from addition to prevent recomputation. */ 1 p. a4 v: q1 }1 W
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 2 z: P. l4 t0 B' A" j
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
* m' P4 ~8 ]# Y" ? |& h#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
: {: P2 W2 A9 A* V) c4 r. O% s7 C#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ( C I. M$ s: B; Q
3 z' A' i: ~! K5 u! G" U# T2 ~3 s6 x/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 5 h! ~, H3 ^2 F
void MD5Init (context)
3 g+ ~7 ~" ?: `+ ]3 |' @* xMD5_CTX *context; /* context */ - V2 H! \7 y2 d6 H& u( f- K6 [
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
. \* ], x: q& @9 H% v1 F*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
9 D' M. p( W. Z4 R} # I/ o x" g y' X
3 P. k1 o+ X! \* }5 s! M% L
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ # ?. `8 [, [2 [" [2 \/ j
void MD5Update (context, input, inputLen)
4 B/ _1 A2 i( x. K# a6 lMD5_CTX *context; /* context */
# U" `; ~# V! W& x6 u$ Z1 ]unsigned char *input; /* input block */
/ f- C o: C8 f* [unsigned int inputLen; /* length of input block */
5 S e- g& d3 `# G A& e{ unsigned int i, index, partLen; . @7 k+ w! b" ^6 J, I: Q; g( k
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); & h0 z# K4 U9 J% s4 n
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|