|
|
#include "global.h" . ?! Y/ L8 }& e. T' Y) p" G' H# k
#include "md5.h" ' P* C+ O: j2 a
0 ^# {; S5 V" X8 b& B/* Constants for MD5Transform routine. */
% d$ v2 H" }& }% u3 z) p4 L , [- S, z F! x$ P8 K6 a9 V
% q+ W' f( o+ y#define S11 7
1 i! R; L- E h3 F#define S12 12 / D1 b U7 g* Y/ m! T( j* Z
#define S13 17 . D% q' Y7 v/ F' a- f% F& A" P
#define S14 22 . Z9 I4 C1 l" f( E$ y
#define S21 5
4 H, f0 Q, O9 c) V#define S22 9 1 S0 m' ^$ h( A: W i+ n$ S
#define S23 14 , y o! P$ L: V+ M3 i7 K7 [$ i9 I
#define S24 20
& T5 {* ^! p8 L; Y& I/ V1 \% W#define S31 4
; U) _- j+ h; e" F' R' F#define S32 11
/ U# e2 y& ?+ h2 G#define S33 16
5 i2 r1 C0 U3 Q, g0 E#define S34 23 + U$ ?& j; q6 D. v5 @
#define S41 6
& ]; G# B3 A0 g- ?. n9 d4 C8 S#define S42 10
% {' J# {8 a+ a! T; K/ ^ s6 }#define S43 15
1 F6 h! N6 Z0 k) F# d#define S44 21
$ a" U/ W, h4 {1 e' P% h& H7 C
2 h. a% F7 T6 Fstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
$ s& u2 P6 H o6 h0 Fstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
, s! R+ X9 w4 c/ Q* istatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
) c! Y9 Z6 q! N, l3 u' vstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
' c T$ @+ E; Y& S* y/ tstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); , H. U$ _) {! |) |6 Q; i( b
2 a( a( N3 Q6 C. n* | Q, q1 O/ g
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
+ H4 L7 e% m1 v' a X; U};
/ B6 G5 B/ s; N, F+ _4 L9 r$ b9 _
7 D% a' C. m/ P i/* F, G, H and I are basic MD5 functions. */
+ j6 ^* b. V( ?$ a0 K7 X1 [#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
5 Q$ ^+ J0 Y1 `8 y `5 T9 b#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
5 Z% a! q9 O* t#define H(x, y, z) ((x) ^ (y) ^ (z))
2 d( V# ?' W- M$ Q3 O. n#define I(x, y, z) ((y) ^ ((x) | (~z)))
w. Y: b. M# x3 A) e
$ i% L7 N# {( u) t6 R/* ROTATE_LEFT rotates x left n bits. */ ( Y# D9 V7 [- ^% d. N
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ! y" E* o8 x. _0 [
$ A2 @- B/ E, b' V r# o6 d) m7 G1 A
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
) F$ c5 Q2 F* {6 W( V C, V0 E6 t# iRotation is separate from addition to prevent recomputation. */ $ T1 t4 u3 x3 m0 K6 n: n
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ! b: l. P, z# 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); \ } * `) _5 f! C$ U1 o- L1 x- F# 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); \ } 8 G! M' p: m4 h1 I6 A2 U2 M
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ B* _6 c# W- S9 s( E0 ?
( R0 i% K ]; y1 P/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 1 k/ v* g4 A6 G: ?% v5 P
void MD5Init (context) : j# m$ X: B. | e
MD5_CTX *context; /* context */ - A7 o7 `, j) u- m
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
+ Q$ X" r0 C( y3 K: O5 h* Q*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; , l' q9 h' I$ h4 w4 s+ ?
}
" I. f9 I5 A& N) \ N: W; f. @$ K
. \2 e: u" {8 S( Q/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
. s6 b: H2 x% v3 R; v Ivoid MD5Update (context, input, inputLen)
$ w2 A! S- \& x8 D) C3 _% SMD5_CTX *context; /* context */ 3 o# _6 w& Q: g% q
unsigned char *input; /* input block */ ) T( h$ j* h- w7 ?: h0 v; @! C
unsigned int inputLen; /* length of input block */ 0 u8 `* G* I9 e$ @- [* A8 h$ R
{ unsigned int i, index, partLen; ; E6 N* D0 p7 u% ]& B* P
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); , T/ I" P8 ~% B# D3 L
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|