|
|
#include "global.h"
6 M3 P8 `$ K! E$ L/ W" ]+ R5 x l" ?0 t#include "md5.h"
( v# l7 x) u1 e% q5 B7 p
; S- N- Y; W' W, H" N9 b/* Constants for MD5Transform routine. */
$ Q! f9 _6 Q6 P; q* c4 h9 N 1 `4 K0 d% k4 |- F
6 p4 [1 e; I, p$ {6 U# L3 Q#define S11 7
. S" ?8 @$ [. l7 r( z' W#define S12 12
+ L, U a$ ]4 j8 T0 a* u#define S13 17
E7 U- N6 {% Y* V2 t#define S14 22
; @: Y/ T; ?) r( n& [#define S21 5 0 H) U! q+ m/ x; d$ c8 p& q5 y
#define S22 9 6 M. N+ M3 w" f
#define S23 14
6 B% W# z( h! w0 @5 I8 n#define S24 20
1 s4 d9 o$ z9 \* c& B" W1 u% w#define S31 4 2 V5 k/ E6 O# v- l
#define S32 11
- C6 }- n Y1 b! f#define S33 16 + O4 w* Q8 G5 `. m; M8 S
#define S34 23 . c2 B6 f; j i" Z
#define S41 6
( g/ S! G- _+ d#define S42 10
: P2 {8 T w) ~4 b#define S43 15 * q6 n F, z( o- w: ]) G
#define S44 21
' h# u/ o& |: N" B% ?) n7 a 8 P! H8 z# ~- R# N* z
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
, D: Y$ { }5 W2 [: S$ L9 s) N# x! wstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
8 \1 f; V& e5 i' g6 Ostatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); % l3 Y% V" r, l4 O' _
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); ( ]9 ?) V/ H: p& @0 r' U
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
{- e* N+ T! K/ |4 l3 D$ x
7 R* C: m0 ? ?3 Y' ystatic 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 ? Y* n Z6 t( i, U
};
& k# W0 C/ _, Y) L
: ?& Z! s: V8 O3 d% q9 Y/* F, G, H and I are basic MD5 functions. */
7 q- x; W6 E( Q% D6 Q#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
( S* R# r6 Z4 e1 @% Y2 ~: d" e#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) : j9 ~6 |* i; N0 N/ E
#define H(x, y, z) ((x) ^ (y) ^ (z))
! ~0 Q' }1 ]- x! c. }" d#define I(x, y, z) ((y) ^ ((x) | (~z))) 3 ]' V4 Z8 G+ {: Z
: p+ W4 ?( V, b9 j" O' ~/* ROTATE_LEFT rotates x left n bits. */
( }1 P" \# c* ^. D; s6 g2 u#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
: L) D- i' a: @
7 u3 f/ H& B; Q m8 q' b/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 1 s- s2 @; x6 b2 v& W# m
Rotation is separate from addition to prevent recomputation. */ 7 p2 T; O' B4 Z3 n1 q, E
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
) M2 ?9 O0 N9 [, P#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
4 T) m; ^- ]/ u" T#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 K9 j& T1 n- ]8 ]#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
6 s2 j& Q! B2 A ; d$ ~3 ~$ w! U. v4 Y
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 9 o/ \+ t, D, _- Q1 ^! }
void MD5Init (context)
/ m% Q0 V' [: s/ Y( }MD5_CTX *context; /* context */
) j! A) V: j* o5 K/ z4 H{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 1 g4 y$ X+ q$ l
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; , B) p2 O+ K Q/ N
} ; r6 M9 o; i& v6 x& ^- G4 W- c+ ]
& s1 e/ M P% k; r, L) a2 l/ m$ i
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 3 W9 a5 r) V# ^0 Y) @
void MD5Update (context, input, inputLen) 5 }' J9 }$ s0 F% {2 l; Y
MD5_CTX *context; /* context */
6 N7 ]3 }/ J; b! T3 T3 f0 Eunsigned char *input; /* input block */ H) Y2 d9 d- O/ l; ]6 A
unsigned int inputLen; /* length of input block */
/ _+ B& w9 [. a# m, M1 x5 P{ unsigned int i, index, partLen; ! E3 [! E9 _+ D( g$ k
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ! ~# ^1 T, t* Z" I. g
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|