|
|
#include "global.h"
& m9 Y2 o; H: Q4 b% i" |. R4 w3 N#include "md5.h"
: N! t/ b: w3 z; k: _% l! F. M3 H
+ E5 Z; z1 `. r' C; U3 ?% S8 p1 I% c/* Constants for MD5Transform routine. */ 2 G+ ?) {' A' o$ Q( M3 l- Q, N7 j, ]
7 D2 c+ h0 K' x! r, Y8 o: N1 A B
) J1 Y5 E+ @2 _+ w) ^1 F7 L+ x#define S11 7
# A! G5 i6 o7 N9 V3 Y/ a#define S12 12 . S- M2 Z3 J ]
#define S13 17
- x) ]9 ^: b& O" p0 N+ h$ z% a$ T#define S14 22 8 u7 v# x, w q5 f: b3 M: x
#define S21 5 1 Q. q9 \3 V, d* y
#define S22 9
# t9 A; q+ u* O#define S23 14 + |4 m# l1 m% _' M. D6 L
#define S24 20 5 t G! _) [7 Y, K% G( O0 Q6 z2 O
#define S31 4 X5 A7 ^! a8 x4 T6 R
#define S32 11
0 A$ c5 D( [% {: h, f9 M/ l. V#define S33 16
7 g y9 \1 [% N2 ~8 f; ^1 d#define S34 23
; f6 P+ H% m/ p$ a q9 b% A0 a' F% D x#define S41 6
. a; J5 v9 s8 P6 _% [) i/ A#define S42 10 B4 ~$ x5 Z5 z4 F: W; e2 H+ x; P( b
#define S43 15
7 ]* a/ Y ]- d$ ?$ |" w#define S44 21
2 w h' ? c& L2 L : Q. i" w7 \: _
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
2 ]+ q& z) C2 }" D4 w* ^static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
% D9 X: j6 G0 J: ^0 F( G+ g$ I& zstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); # i' p( G( Y7 m6 z
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
7 }0 R$ o( r" R/ J: L! ^static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
$ K+ o5 S! o! `1 ]% k$ q
" M+ {. C9 j2 q3 H2 F, vstatic 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 , \8 F3 a. j& T; \8 Z
};
- c, d! ~; t2 f2 C7 s- y0 S x % N( C$ Z: J, [0 a; y8 n2 Y9 }
/* F, G, H and I are basic MD5 functions. */
$ k2 t1 f, F3 W5 z& N0 [#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ' L! P3 K! g; o& k& s9 _
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) ( B5 c+ F& w N4 I
#define H(x, y, z) ((x) ^ (y) ^ (z)) - D# F% Y3 ]4 V- b# q
#define I(x, y, z) ((y) ^ ((x) | (~z))) 4 w' T+ H( S0 C5 v) x- f( `
+ L! F+ k* l4 C: {( ^4 A; q3 K1 Z* T
/* ROTATE_LEFT rotates x left n bits. */ 8 V1 I6 e, K' M; j3 s2 w
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
$ o2 X1 O+ G4 ]" e8 K & n% P7 G$ c8 W6 p* R; D: d# L
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 5 X4 p1 f& n( C/ D
Rotation is separate from addition to prevent recomputation. */
7 ~' W6 l6 \4 F. p( v5 v% j#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
9 m* N% `, P2 A. S# J#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
6 f7 J0 B7 s" F0 A' \: ^#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 C7 z. ]& ^ D5 V( ^% [& v; o
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 6 p5 i9 o ]$ T) S/ B
6 E+ M ]5 c o0 R9 S. ^
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
3 C9 B9 z6 O" w- T2 e5 ^0 uvoid MD5Init (context)
+ C i8 T9 u+ v3 ?, W EMD5_CTX *context; /* context */ 2 r7 ^0 u6 p4 p6 ? V! e
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 0 I! u; Q. n& h6 s4 T2 F
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
6 Z8 P& C2 ^6 J, y} + ]% v4 W9 U0 V+ @7 F" d
+ Q, r/ M: U! q0 c- G- Y/ C/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ " T5 A( T1 I# G; k/ Q# |) Z" c; t
void MD5Update (context, input, inputLen) 2 R( Y4 S* y1 u! z5 C- e/ X/ |
MD5_CTX *context; /* context */ ! V% F1 d3 j9 \, q
unsigned char *input; /* input block */
9 A% Y# r1 k! Y+ k7 p# ~' Z5 {unsigned int inputLen; /* length of input block */ ; }% h+ K q% Q) R3 |
{ unsigned int i, index, partLen; & ^: U# ^& r' x6 D! m$ V$ i" Q
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); , ^! W0 [5 A6 y; l% q0 p! Y
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|