|
|
#include "global.h" : y8 P" y5 v5 F O* \
#include "md5.h" , w* u4 f" E' E
0 x1 r5 } s$ b
/* Constants for MD5Transform routine. */
1 Z+ o4 d9 \+ c' c* C% A: I& |/ r
4 @% a o) O* i% t+ n 8 u! j2 D. i9 c, d7 |# j% k
#define S11 7
~" O: B W( Q#define S12 12
; x' B0 \4 \9 s/ l! }#define S13 17
3 s# W9 s$ D# z9 D#define S14 22 , F" E9 o' ^1 Y7 D
#define S21 5
' T& o) u8 r5 q. _, d#define S22 9
2 a) M6 m" M" T- }#define S23 14
- w3 r3 i+ I+ v8 l" @2 o# l8 Q; K- Q+ M, [#define S24 20
( `* [, g3 o$ h1 V' r4 o$ ~#define S31 4
' k6 p$ t+ r( f F7 @#define S32 11 , }% }) E: }+ ^' Z- e: t& X8 U
#define S33 16 $ S) ?. h, Z) f- O
#define S34 23
- p/ e) g" v# Y/ O' J#define S41 6
7 S% I2 Z. m2 w& s#define S42 10
" @3 C, i8 k( K9 u% e6 i$ z0 x#define S43 15 ( w$ m/ D2 \- c8 i' G: G3 Y# }
#define S44 21 ! O/ R" i9 t9 Q* g
0 k: v6 {: n9 x2 a1 a" N+ Jstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
: S" S* O7 [- Y8 o: [static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
3 p: n$ i ?5 |static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); * b* E# S/ o( a' p, L
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
( t0 Y( J, Z) ?) D4 G Z( w! Istatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ; S2 x- @$ e4 K, Z$ y
4 z" ?; N8 \. V/ 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
, [+ h+ u) {+ A, h; z};
5 {0 N6 x& p& {+ u- c 1 F% ~! D, R i' q4 r+ _9 H; r2 u
/* F, G, H and I are basic MD5 functions. */
0 ?9 U( Q( I m |3 v4 z! p5 c3 x& L$ v#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) / A4 x% {4 D! l+ u( t
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
2 N0 D+ e8 K: x Q( p4 j#define H(x, y, z) ((x) ^ (y) ^ (z))
/ e2 n: M2 G7 P2 x1 K" R. }#define I(x, y, z) ((y) ^ ((x) | (~z)))
9 v3 c- n# j7 p# H- y! J
; n3 n. Q6 ]. W# U% E( i/* ROTATE_LEFT rotates x left n bits. */
) z( [1 g$ Y. c1 {0 i! K8 k#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) % I T5 I e" Z6 X% | `/ w
: \6 d+ U) v% i8 O" O/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ) h* k4 N& d6 F& y8 m' K) |
Rotation is separate from addition to prevent recomputation. */ / _+ ?) l9 f! 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); \ } ! i( G+ X, B- o1 M$ }: f# J K
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 s7 J- T* u2 ]/ h5 I% w#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
2 k* F6 V; w2 v1 U9 b#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } - [' |( U/ ^- m1 B7 d* M
5 S( }; @' `$ [* F) w& Z
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 7 v# b7 r4 X7 @7 j8 E2 ~
void MD5Init (context) ; `6 N4 d# E0 U( }! B
MD5_CTX *context; /* context */
2 j; v1 u8 T: y- @{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 7 B% @& c% k! Q' ^( v# P
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 4 _2 E: a9 m0 j; z3 n
} 5 M* o' C7 J- N# A
( e# L0 P9 \9 x
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
# Y. F; T. L* H8 ~1 a# I+ ?9 |void MD5Update (context, input, inputLen)
4 r; Z0 w: T* c! E+ K# B! L8 ?0 t: ^! eMD5_CTX *context; /* context */
# Z5 `0 S5 ]/ S7 g8 U& Dunsigned char *input; /* input block */
" a f h% p+ s5 j( Bunsigned int inputLen; /* length of input block */ 0 K5 O) N! H" R8 e
{ unsigned int i, index, partLen;
6 }( }7 D+ i+ V" U /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); # X! I0 Z; `! |2 U6 V' M
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|