|
|
#include "global.h"
4 A" l2 t+ y/ {7 n+ q; s: l* M4 r#include "md5.h" % ]4 k0 J& X" z
0 n! S& d2 H2 x& ~" w/* Constants for MD5Transform routine. */ B& n0 @# ^' F4 C! _' ]$ k
& M/ A& R3 x4 u L7 r8 E3 P& V
v* i6 X+ L9 i6 C: R& F. o#define S11 7 . b* j# H$ ]3 e! A8 Q: S; `1 y
#define S12 12 * a9 F% e* c2 k. ~# Z
#define S13 17 ' E& ?9 R3 `+ o) j, N. B
#define S14 22 4 v1 S$ ^! I0 T w8 x1 @& c
#define S21 5 " I# F. L$ S5 J0 }- }$ o1 l( j) y
#define S22 9
5 C3 |# W- I) j9 O- s#define S23 14
$ q6 h# n* N, {, U#define S24 20 l9 w1 S8 }0 I8 \2 e
#define S31 4
& E6 @% [: k- z+ `3 h g#define S32 11
4 n- X9 X t! \& U7 V6 H: [ J) V#define S33 16
$ `5 S2 P$ `& q! M#define S34 23
/ x* U5 [1 R4 {/ z( G% [#define S41 6
9 O, P% R' h$ W#define S42 10 ! P. g9 U5 j& C% i! g/ d
#define S43 15
4 K4 q5 b6 Q! n3 k' y. u#define S44 21
. R# d# _- o! R: o( D
) Q7 M' `1 Z/ i7 dstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 1 y5 H1 p5 e+ e U$ G7 ^$ m% R* G" A
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ) {: r! J' r+ ?* \) i
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
7 S+ j3 z8 Z0 H8 `7 tstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
( b% L6 K, P9 a7 ~static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
, c0 z- d; Z* S8 `3 b1 J0 X
0 C, \/ O/ W$ n& N N) R- `9 B1 ]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
& D# z3 i2 s9 |' F0 @* y}; + E/ C6 }: P6 z' G
1 @1 |& t: Q" @5 c) f# e9 x
/* F, G, H and I are basic MD5 functions. */ 4 S- I+ G/ I& j) p: T
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+ x7 W; {3 `6 h# F4 y#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) ( x2 _8 Q) U9 a- Q& a% T* ]6 y
#define H(x, y, z) ((x) ^ (y) ^ (z)) # N4 L( A: \5 M; e, \
#define I(x, y, z) ((y) ^ ((x) | (~z))) * ?7 U4 J/ E) y& t; a+ F
6 j S% \% W: _0 i0 S/* ROTATE_LEFT rotates x left n bits. */
2 x# Y. V0 |9 v8 _; \: W#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) . k9 @: @$ g4 J
7 d2 l$ S2 H( g6 \/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ! Z8 d7 g9 `. @9 n5 L
Rotation is separate from addition to prevent recomputation. */
8 I: m+ J w* C* g9 h$ V% ]#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } , L; M3 q* J9 w$ Z2 R) x! B! V
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
/ X7 h! v- [- j! U#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 6 ~2 z- L, |. F0 \3 I6 ?
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
0 `, i/ x$ W0 G
) q, t8 O0 h! G' V3 C* W! W/* MD5 initialization. Begins an MD5 operation, writing a new context. */ % `2 g0 a( d- _; B# X& } V
void MD5Init (context) , d: ?. \( y* `4 ]9 b1 I3 w9 z
MD5_CTX *context; /* context */
" a4 F+ p5 K3 M5 d$ u{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ; g. r, X& E* M S
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 2 e- E8 v3 n2 v3 G, M! x- @8 e
} , u- ]( Z- Z" S3 d3 N
/ ]0 }# d* @) q+ ]( {. M
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ : h5 r+ M9 H$ Q4 a& Z- @+ s) I
void MD5Update (context, input, inputLen)
, ]: P( z9 Z+ E" J1 d5 MMD5_CTX *context; /* context */ " q' ^7 U, Y& Z \
unsigned char *input; /* input block */ 7 n5 d# z( n9 p7 i. C, |& c
unsigned int inputLen; /* length of input block */
5 X: n7 S7 O' z( u! ^6 B7 T& z1 P{ unsigned int i, index, partLen;
+ j9 I2 E" e& s# V' d! P7 I3 t" W9 r( W /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
; R$ A G5 X; B7 h5 n /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|