|
#include "global.h"
) Q( s- b' u+ Q5 }/ Z+ S! ~#include "md5.h"
; }; q- y6 O4 {( P' n3 z. R3 O) _ + e9 |' k' C5 G) `1 b6 E6 l) q8 Y/ ]
/* Constants for MD5Transform routine. */ - M! C' L- ?( ^% e+ K
; y, `+ U9 ?; l& R. g8 s! O0 h
# y, b% }/ c$ @$ t1 a' }0 ?& d#define S11 7
7 n0 p7 o$ V1 B) O( w( W2 M#define S12 12
8 f- D% y/ T2 V- L) ~#define S13 17 4 P) l3 W$ `$ l/ V
#define S14 22 . a$ X' M" o! M: T/ l; o
#define S21 5 . Q- s O/ T4 _8 l* \. E
#define S22 9 % p2 a* ^) g9 v9 q; y
#define S23 14
5 _# o+ d$ i0 w$ Q' L) U: s; H#define S24 20 3 w2 `1 X' C+ M. k, R
#define S31 4
8 I" f* B$ l1 G0 {. s#define S32 11 ; K2 C8 I* J) s
#define S33 16
@" A* O& | T. @' o. M#define S34 23
- M# R7 u1 Y& }: j2 @* P#define S41 6 . T; h0 v: Y) I% S! r
#define S42 10
. C. ^2 T% Z8 ~#define S43 15
3 m: V; ^/ O& G7 k7 s2 @4 _- ]#define S44 21 * m$ \ O1 c0 z' K8 N* _7 f5 m1 s
# d: P+ q7 ]# t$ g+ Y" }/ D- jstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 7 Q i* z2 |2 c- T& e8 E
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); + \2 Y A( w0 O. e! L
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); . z* f( y; c" Q; T% I, V9 N
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); & e9 p4 H& ~- U; L; W* `
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); " I/ d2 G! U. k3 ?4 }# o4 ^# x% J
! w% u' |- U& j* m5 K! |
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 : \( u- k: \* L$ b% y6 @1 n
};
& {% o: B( @( a* y4 \ ( |7 w7 ~0 @, J! z1 ^6 E
/* F, G, H and I are basic MD5 functions. */ t0 {6 ^$ L$ [. u
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
5 _/ p4 Z. g% S' u" i7 B#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) & Q- y* m/ ~- I) e
#define H(x, y, z) ((x) ^ (y) ^ (z)) 5 q( T2 O% [/ O% Y
#define I(x, y, z) ((y) ^ ((x) | (~z)))
8 D/ T, A& }1 a& e& e
3 ~& B; W" _4 t X# Q/* ROTATE_LEFT rotates x left n bits. */ 1 {1 x& v6 c5 m: ]6 z* O' d* Z- s- R
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
1 x3 I% {8 [ Q , B6 s' E4 O: \6 q
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ' C! |2 p! w, @' P% K" G
Rotation is separate from addition to prevent recomputation. */
y4 O# R2 T/ g+ t3 ?0 p2 {#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
T& l/ I9 D' M0 a3 [. D#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
' C: M6 v; O1 W K% g1 }' 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); \ }
3 {* O" E2 _0 d/ 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); \ }
* U8 ~5 \0 J# m7 q6 D. K % }$ X! m+ S4 X2 M5 w
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
0 g: G; p% x4 H: b0 w4 ~( Pvoid MD5Init (context) W) X' ]/ ^6 O) Q4 K
MD5_CTX *context; /* context */ 6 @/ {+ l0 T) x0 K) C6 f0 S, e
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ; e" B/ K: F: [ g+ }" m% s
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
# ]7 ~& R2 R! _' l} ( M+ K5 s7 N% e/ y$ Y; e% V+ v8 ?
7 |" J3 K6 ^5 E0 k/ i/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
9 b* a5 i h5 P3 l; ^- ^/ |void MD5Update (context, input, inputLen) ; p; w7 l3 p) H) s4 Z$ J
MD5_CTX *context; /* context */ : @3 z) b) n% ^) E# i! l
unsigned char *input; /* input block */ # [: d, e% Z$ q6 M4 Y( ]# l
unsigned int inputLen; /* length of input block */
7 _, S+ d! Z: s5 i{ unsigned int i, index, partLen;
$ r" X$ J7 R8 w. T4 x1 J /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
5 j! q# H; C) C7 B; T; b: r /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|