|
|
#include "global.h" $ P" K$ D% ?% m2 F# X+ ]- b; Y* ]5 l0 Q
#include "md5.h" ) q4 V$ n, `5 d# {2 ~* \# R+ d
- Q7 o$ o6 e, N; G% n6 G
/* Constants for MD5Transform routine. */ / ^- O7 p" G( H0 G
, f( L( A+ D3 C' g
8 `1 h# `! s) B$ Q7 `6 i7 }#define S11 7
% p* n% v4 W2 P1 \2 B9 S#define S12 12 $ m2 [: l* K# ?" r
#define S13 17
: R- Q8 h/ d, }0 n) P#define S14 22
- ^$ K m$ I: d4 N. x6 S( f5 a6 K#define S21 5 ' N2 c% @4 G. G* q
#define S22 9
4 F1 K0 U: X0 {- i7 X#define S23 14
- d1 ~1 Q; h9 {) \- G! ~#define S24 20
& ^5 V" S3 F7 j" e+ o) }2 t% A#define S31 4 1 U- |1 X+ @) t3 q0 @
#define S32 11 / D+ k& |2 R5 ~6 l$ M- T
#define S33 16 % N5 X! E/ M: i& b2 `: P- ~
#define S34 23
7 S/ ]3 ?8 I* e#define S41 6
+ B: P* ^8 x9 L B! T#define S42 10
1 I5 A* X- X0 {1 e( D* x1 |# m#define S43 15
8 |; i; a+ @4 ^" S, S" j# r#define S44 21
6 S) f+ y, [% I% a s
# d1 K+ i8 n; D6 t5 Estatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
5 X& J- g6 k8 U' E2 S( `6 Qstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
8 S% z8 f" ?! y: Vstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 0 v& ^6 W% {* C
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); % w( i; Q9 ?. X) [/ ]+ A; L& s+ @
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
: \8 Q& f0 D+ I$ z
1 B. f2 Q" ^& Z3 U2 z0 xstatic 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 1 ?! E4 k7 {+ A; {0 A% q
};
6 q n6 E: Z( g3 d2 ` 8 z+ S, j! R& O/ ^, O" H+ ~
/* F, G, H and I are basic MD5 functions. */ : K; W# o7 i( j, d2 H K. z4 S
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
. _9 g% {$ n3 q, W S4 b! l#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
$ N1 {7 n+ |* S, k1 [% t* V7 u#define H(x, y, z) ((x) ^ (y) ^ (z))
: x5 d# u' V8 w' b#define I(x, y, z) ((y) ^ ((x) | (~z)))
/ h7 v2 m9 |5 W% Y+ j* V$ ~ 4 M7 Z0 `. r7 E( j7 Z- J
/* ROTATE_LEFT rotates x left n bits. */
1 d8 S2 @% ^7 Y% h#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
2 Q: T) v& B: ] 0 m, a* _; y4 v' w
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
. |+ ~* g: N2 O$ WRotation is separate from addition to prevent recomputation. */
- A' O' S* P# [0 d$ k; Y9 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 m7 X' \% d# s' f4 ~& 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); \ }
2 `6 t! l a S4 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); \ } 2 s- j5 t3 z" J3 i2 z- [
#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 ~- t5 o( G& u' S$ J( H " O; I y" ?/ B& H
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
: B& d, f7 P/ }) Rvoid MD5Init (context)
# v$ g/ D. q; J8 i2 y6 R. X' [MD5_CTX *context; /* context */ ; L2 u o2 _: l/ J
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
I2 z4 f* Y9 y! E, g7 v. `, e*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 4 Z# S( U$ Y. q; a4 G) d! O3 S8 j+ s
} 9 s3 ` |: \3 {# Y H' v
* f% o6 ^2 s1 y9 n
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
0 F3 a& b& r, G; Z3 g7 ?2 x0 Hvoid MD5Update (context, input, inputLen)
8 k, t- v3 ?0 l- MMD5_CTX *context; /* context */
& W' y5 B+ N) }; i6 r8 }& ]unsigned char *input; /* input block */
p' v4 P% `) ~: Junsigned int inputLen; /* length of input block */ . G# ]* f, Z; ~' R
{ unsigned int i, index, partLen;
6 W0 \. D* R4 ^7 D/ V% n /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); : y) o0 D% }+ R) A+ }- e
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|