|
|
#include "global.h"
- N7 E) S. S3 {4 V! g8 t* Y5 s0 X#include "md5.h"
) d1 | ]4 g1 I" y! l1 z
% i" A/ |( X4 z3 f+ P/* Constants for MD5Transform routine. */ * F$ r( t8 u; R; S3 ~8 \* G! M
. A! r8 n& s7 O 4 ^% r7 V; y5 a, b2 Z
#define S11 7 0 d8 V6 P0 v- G1 b/ D
#define S12 12
# N- a! G4 T2 u1 o7 L1 v* @#define S13 17 ) e5 z6 E+ T/ ~' q2 m4 @- ?
#define S14 22
0 U \$ D$ p: j$ |: W& }#define S21 5 y* h _& N. p
#define S22 9 - y2 B1 a3 ?, I4 _* s6 T* x7 N- k
#define S23 14 6 y1 y* K5 l9 u- W5 O+ ^
#define S24 20 , Y: t. d% R+ L* y, d9 j1 R' e2 m
#define S31 4
5 g& G3 B1 {7 N# A# T) x9 y7 F#define S32 11
6 P+ y8 z" T8 O u1 B+ r: `#define S33 16
3 o7 ?2 |) P# i) \: P#define S34 23 7 b2 y9 g6 |! M
#define S41 6 8 M+ f' X @6 h) e: A
#define S42 10
4 Y. V; h: w3 d#define S43 15 ( s# ^2 E. ~. v
#define S44 21
0 e* x5 q( `; J) a! @ , I* Z7 ^5 w) d4 c7 @
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
1 e$ O7 ]5 M X4 g" N, H3 X4 x; qstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
6 P& y3 Z# \8 ^ A* M/ M; Y+ Ustatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 4 B3 Y, B" s3 F- f5 `) L1 i& R* K
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); T% t2 Z& l( M& e+ b/ q+ O( H& m
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
* J$ G) [6 d3 W7 t. _ {# A# R2 s+ R: T" U
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
v3 ]- B0 u2 i, V8 x* M};
9 G. ?9 C% _$ r2 {: E. b: D
+ J' ?. e& |6 A0 v4 y/* F, G, H and I are basic MD5 functions. */
/ P, x3 L/ S2 j; s% s3 Z#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ) m9 P6 M/ x# P( A; M* M
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) $ k0 a8 S3 c1 a: ]% F
#define H(x, y, z) ((x) ^ (y) ^ (z)) 2 @3 `, J. I& B5 u" k, h
#define I(x, y, z) ((y) ^ ((x) | (~z))) 1 j N7 W, ^0 ?- D( N" m( \
7 U; c9 V# k3 ]& u3 |/* ROTATE_LEFT rotates x left n bits. */ 8 t3 D4 m6 V% a, F
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
( a1 N G0 m* J, t: G X9 j: k1 e
% i J6 U9 E7 G& ]" O, D/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
3 z. S. g# C5 k; a- i g9 rRotation is separate from addition to prevent recomputation. */ " B) W H5 U9 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); \ } 1 a+ I) }; D% Z. W$ L5 r- l8 C8 s; L
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
/ K" o& T7 b) Z/ N7 h4 h P X7 X#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ J; |% W5 f% 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); \ }
- S+ d$ x. G9 G* O. W. H2 _$ }) P
( n0 z. ^7 I6 E! E( }/* MD5 initialization. Begins an MD5 operation, writing a new context. */ # _6 g) E# A" t+ \5 v% j
void MD5Init (context)
4 u/ v, X6 S3 V& c* Q5 OMD5_CTX *context; /* context */
7 U1 D2 F% \) ~{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
1 m9 j8 a% M) s- J+ F8 m*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
6 W% a' m& O& m}
, y% \, |! y) I% i+ B " S+ t' I( r6 d
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 0 L! W4 V/ q6 c m6 _
void MD5Update (context, input, inputLen) : l; Z( j6 {" I/ [' x
MD5_CTX *context; /* context */
* I9 {. S r/ |* eunsigned char *input; /* input block */ & Z |* t' W0 q. y) W
unsigned int inputLen; /* length of input block */
9 w9 J0 k4 ?$ p! f; L+ T. z{ unsigned int i, index, partLen; 0 i1 R( L! ^4 }% u; H
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
9 Y& m9 z, d& f /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|