|
#include "global.h" 2 c+ N$ K' c( X- W t1 x
#include "md5.h"
: ~) H% O( F4 W0 j! M: X
( o$ A8 k0 Y( m _4 ~! Y/* Constants for MD5Transform routine. */
' }& t1 h8 a9 W: g$ H" W ' {) q2 L# U' Y. s+ ~
1 n0 _4 _9 }% V- F5 B, A#define S11 7
: l8 R/ a" Z+ Z/ Y% W; C$ t#define S12 12 & Z: M, ~' B! F0 {
#define S13 17 9 d4 E, W; S! S& O5 j/ h! a
#define S14 22 % e. `! }. E x
#define S21 5 $ N. w1 V; T) x& q
#define S22 9
; W6 [% a9 ~' x2 y; U0 m#define S23 14
0 Z$ A7 r, x" }* A8 }#define S24 20 . U z' l5 c% G. @' y
#define S31 4 ' N9 g, Z! t; g: \
#define S32 11 " w8 v8 S( Z8 v' V' s
#define S33 16 6 O" a& i- x# j1 V9 [
#define S34 23
' o* ?$ T5 l# A" {+ K+ I ~ e#define S41 6
0 R9 w( z* j6 h j#define S42 10
( o! T4 J5 H( ?$ z#define S43 15
( }2 [; [) O0 A5 p% K#define S44 21
; G) D s8 N5 N- L6 N$ a ; d+ p$ |8 {7 x2 ?3 r, c7 s' t
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
: c3 R1 D7 N3 m B; j& j3 qstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); & ?2 a1 U5 h% m
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ; E3 V. Z3 f9 G1 L: Q* O9 y* f
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
6 ]5 j6 a& ]7 h6 }5 jstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
5 k o5 v0 Y# F9 P - B: W; e# Q+ f4 h
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
; \, F/ j7 q S' G};
( o. @! A6 [: m$ | 3 ?3 d$ C! ?& T8 M3 s2 O
/* F, G, H and I are basic MD5 functions. */
9 h9 X. ]* X; x) P x3 b$ w#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 3 w8 U* u" B; A
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 9 @# i0 e, w: T
#define H(x, y, z) ((x) ^ (y) ^ (z)) 3 A, E# N1 a" Y# Q( w( k
#define I(x, y, z) ((y) ^ ((x) | (~z))) . L6 w3 S% w% y9 [" e
2 C: B( r) F/ K6 H# R. C5 q8 U
/* ROTATE_LEFT rotates x left n bits. */
j7 q) R8 B/ \0 W+ O#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ) I4 W, Y4 _! ^6 { D
1 P5 H6 g0 {- X& [
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. / v. b3 f' [# ?
Rotation is separate from addition to prevent recomputation. */ ' Q; ]) q, k: Y6 R
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } . b+ d1 u$ S& l
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
1 A4 P3 M" b$ [/ `( x: Z+ j( 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); \ }
0 I. }- z7 ~/ ]! k' j#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } , G6 V3 H, k# m) \; x- z5 ? U
0 k( o" P( }5 N; z5 F k
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ : `9 L) i1 M9 v5 {; A9 Z. v4 N
void MD5Init (context)
5 Q( R4 ]/ Q" d( o5 F/ AMD5_CTX *context; /* context */
! _; D1 Q* R5 W5 G- |4 |$ a( L{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 6 J* m' u" V/ _6 ?+ z
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 8 ]. s; P2 }/ r: g2 o5 E, r. d. f
}
6 J4 L1 b$ W% z4 x8 N$ K1 R
# s9 t! L4 n8 K1 b% g/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 6 H! }" g+ A+ f# ~
void MD5Update (context, input, inputLen)
$ e, T4 H' K3 P' o bMD5_CTX *context; /* context */ 7 r' x5 `' G4 x# E& c* V) w, D
unsigned char *input; /* input block */
4 P4 y( U: S2 R7 funsigned int inputLen; /* length of input block */ & L% @" T) |4 z
{ unsigned int i, index, partLen; ( |" P; G1 ?) Y
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
, t: r' V' V9 k /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|