|
|
#include "global.h" - S0 `" g) R0 `0 n( m5 t
#include "md5.h"
; m* D. K6 S+ _8 [
1 F- N0 ?9 t' o5 j- h& `) W% J8 h9 m/* Constants for MD5Transform routine. */
6 _% P" w9 G3 Z( q; `4 _
; P, ?2 s: [ M
# Y0 D9 S5 G9 ` {3 L7 x2 n#define S11 7
7 q, f' q* @# ^$ N#define S12 12
; @ W* L- D5 k2 [* T1 H#define S13 17
; Y$ `2 {9 {/ s) q0 e#define S14 22 9 N) H. @, @8 F! e3 E+ ?4 l
#define S21 5
B% k$ q7 h( }3 a#define S22 9
2 S) Z' \- q# \' y. m#define S23 14 - k' o4 B8 C6 Y! F4 L
#define S24 20
! j' a* Y, E& [, j! r#define S31 4 $ L3 n% O% }! k4 _( r2 a
#define S32 11 & g1 H( {0 ]4 e- T1 q- t
#define S33 16 3 V7 a! U/ i; _% U7 n. C' v
#define S34 23
& Z3 D F6 T" ~6 t' n#define S41 6
* [+ r: W: _. s; Y- P& C#define S42 10 1 b3 u7 N$ r" i- P5 {* h
#define S43 15 - t% v) y% s/ G/ V J" Q" p3 |/ u
#define S44 21 ! C" _. J% j5 R" ?9 Q S6 U
1 W; z" q% _' j# m' i3 @
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); ' R0 m# P. I4 M1 ~
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
0 Z7 |% g/ ~' B% [6 D a( bstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
7 E0 j9 U8 Q! ^: h* U1 |# D0 pstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); ' B' W: ^: j+ A }$ U
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); A+ K5 [* G8 v/ |
+ j4 s7 K" C l0 x- x
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
2 M- K4 `1 N. h; x# K9 t}; - N8 T( Q0 w/ F' q2 Q
( z" _6 X. d) X* B/* F, G, H and I are basic MD5 functions. */ 2 A" b( [' F2 Y- Q
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
- G! e+ v- Z: ~( Q* l#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
2 V1 ^! S* g& [5 G3 f#define H(x, y, z) ((x) ^ (y) ^ (z)) 0 u" t/ f% i; f2 Y6 x: t) A
#define I(x, y, z) ((y) ^ ((x) | (~z))) ) Q( q, g% x8 R8 S
$ ~" O; P* d, R Q/ N
/* ROTATE_LEFT rotates x left n bits. */ 6 s+ I y4 M I. h6 c! l
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+ f+ @! b. I Q' }
/ J" {4 a9 W% e2 G0 r# R/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 0 [+ {; p ~# K! s P
Rotation is separate from addition to prevent recomputation. */ 4 j2 \8 ]; F z" Q
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 4 o7 {0 F2 i! j) R( X4 A
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ( E+ `$ d; e" P8 V4 h4 R
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 3 \0 K; q6 \+ n8 t {5 T
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
5 o y- r: ]7 h2 ?9 S
. J8 W0 |& V% N: s; i/* MD5 initialization. Begins an MD5 operation, writing a new context. */ + o5 m! p. E; Z' p! w6 g; f
void MD5Init (context) ( g. ^, C* i! G) f- P& s
MD5_CTX *context; /* context */
; f+ ?! p- D2 a b; w{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
, Q( u9 Q7 f2 g/ S0 ?& y*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
! t6 |" I; W+ z2 H8 k( E; L& N} 6 M% Z0 b E% @1 y& G y; h
. e' }7 z- S+ }, _+ Q
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
3 O+ F3 m( _; L6 i+ a& K% k/ ^void MD5Update (context, input, inputLen)
7 O$ a0 o. j/ T; NMD5_CTX *context; /* context */ 8 H9 N% ~7 l7 R
unsigned char *input; /* input block */ 6 H. l& Q' m% a c
unsigned int inputLen; /* length of input block */
! f( O4 [2 N* l @% K6 p{ unsigned int i, index, partLen;
0 i& B9 m2 l% B& f3 F3 W+ N& |; \ /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
! l( C7 {4 q2 [ /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|