|
|
#include "global.h"
# y' e, Q; n6 h! s#include "md5.h"
; r1 M7 ~2 v8 k3 `
( l4 j. @/ G4 ?1 v/* Constants for MD5Transform routine. */
1 l4 a/ Q3 ]1 |( V7 t, r5 d8 {3 q- N
, N3 \# K! T6 r4 f$ c; | ! D8 c* t; P! r- g2 D: j+ b
#define S11 7 8 |/ G. `5 F5 d3 d; t9 C( ^
#define S12 12 ' A5 m0 T* A& u1 g& J+ ?( y- E
#define S13 17
# c2 u8 c- N; g8 E2 m) }! z#define S14 22
( L# f/ h7 o& a: E) E- ~, K+ [#define S21 5 & F; E; k4 a& L- B& ]0 k" Q
#define S22 9 7 R v- G- ]) K# ]
#define S23 14
( u( t' Z, F' e( X" d3 \4 ~; q& G#define S24 20 8 S1 S$ H8 m. Y D
#define S31 4 8 h; v) I+ {. J) K( m
#define S32 11
s& ?& M& V- ~#define S33 16 3 k3 E# F2 s( O* @
#define S34 23
( P' r0 l6 D7 i9 t$ h: @#define S41 6 6 c7 }6 @) z( X, L$ g% B; H
#define S42 10
8 `1 _, j: C+ ~! z* v* i#define S43 15 # N+ T9 b3 ~! y8 E% O! w: j
#define S44 21
: W$ ^9 s9 ]1 Q9 @+ V% m- Q
+ R# B0 U+ O' L, c" lstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 6 M) q$ p! K3 R1 U
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); " k. g# k$ u3 w6 A& ]+ x4 r% W
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
& ^6 r9 w; s8 n) p# N0 D# n9 pstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); / {, p' f: C; I/ a$ B$ X
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
9 e# ^: `; P1 s; E
2 E' R7 G- Y- W6 x1 dstatic 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 ) m( I9 @5 ]+ M& O9 E
}; ! h$ c2 F3 I6 o3 ?" U7 K8 d
) E3 y7 C0 Q. M0 L8 w
/* F, G, H and I are basic MD5 functions. */ % p4 k. |4 V+ ]2 A. ?8 Q" Y
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 4 f+ F, H4 ]9 f3 L
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) . Q' s n7 G$ y6 w. _
#define H(x, y, z) ((x) ^ (y) ^ (z)) 2 x: n; D& y, m5 w
#define I(x, y, z) ((y) ^ ((x) | (~z))) ( e( [- c- |3 F, U9 x4 Q! _
4 f9 v% J0 ^! c0 Y, m
/* ROTATE_LEFT rotates x left n bits. */
- `# W1 |% \. Z" s#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
8 ?% s |8 ?* I- L1 Y4 t J/ n * O3 d$ T3 W1 F2 J3 T
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. + s) c4 y" F; F8 L( K. i
Rotation is separate from addition to prevent recomputation. */
: i0 C" a, z* a8 O, [' l#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 5 u% L. W! {5 D9 `! i# Q, 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); \ }
$ h9 a9 Q% X- ~6 I& K2 B" q& ]#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } $ A# u6 ^( ~. \+ @# a
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 4 } q" ~0 ~+ G* r' R
/ `; y6 Z+ m; F C! p/* MD5 initialization. Begins an MD5 operation, writing a new context. */ + I( V8 C; E3 e: ?0 C' W8 l
void MD5Init (context) , F+ o1 b2 g! q# Z. x5 D& a
MD5_CTX *context; /* context */
+ v N+ x2 z; _$ s p/ T- `{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 7 X9 y6 A# Z$ q
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
2 R' o& d2 P4 {; T" V; _}
: Y9 M" v% }& X& ?. K. y @2 Z: Y E- q. b) p/ C. ?4 d
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
% c) F$ P) m7 o' X$ |* E2 Yvoid MD5Update (context, input, inputLen)
& e! S! G2 }, I. L. n4 I9 AMD5_CTX *context; /* context */
' ^! l& z; M/ j3 }' \unsigned char *input; /* input block */
( j! l5 S; J& }% H9 k4 v2 o* ?unsigned int inputLen; /* length of input block */ , d( c! U/ p6 ^+ ]6 g4 K
{ unsigned int i, index, partLen; ! L$ w* P: G& h, r4 s. Q
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
, ?7 o% c0 k8 P: m /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|