|
|
#include "global.h"
* e, c* [6 G. A5 t#include "md5.h" * H: H; X# N: q: m. T# {
* }/ b K) a6 {/* Constants for MD5Transform routine. */
0 E3 s$ g. ]! U1 H0 |+ M# f9 @
) g v y# F0 b4 X7 O
" Q& h1 v% l2 y#define S11 7 * P* [1 ]$ Y; E" t
#define S12 12 # Y# J2 |! m. q: l: W, t: e
#define S13 17
6 V' _+ Q6 ~: @#define S14 22 / r: m" |, H+ w6 n4 W% _- i; |
#define S21 5 # U! |( P0 V( X: n. r/ T9 @
#define S22 9
; M# n' K& ~% e1 F7 M#define S23 14 7 O, H$ s. D: w# e; o" D
#define S24 20
. e7 ?" ]- k' R#define S31 4 3 m% t' ~0 B! w1 h5 k
#define S32 11 ; d" x! a9 u8 f
#define S33 16 5 [4 ` a6 `% A( V3 F- q
#define S34 23 + J1 V- S( U) o
#define S41 6 / N( S: \. d* [' E7 J
#define S42 10
! h4 _3 t& M5 m#define S43 15
" O( n$ P8 O7 w3 r' l#define S44 21
! y- G, G) [0 S* e* P
/ v# F: p2 e0 p4 T, Y& p8 f4 Kstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 8 j0 E' j& w$ ~* B; \2 x/ l
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 2 L* t+ t3 E# f0 l
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ) O$ q3 @+ d9 p) D8 g* E: }
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 2 H2 ?& e7 P1 Z* H
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 1 S7 Y9 E$ ~3 n" y
# ~0 u$ f0 a% o1 cstatic 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 , M7 D, s$ e/ S, t
};
9 t& V# M1 F3 B1 t
^( y6 S4 F0 f$ `& z/* F, G, H and I are basic MD5 functions. */ ' o* a/ l) Z& T5 }
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+ a4 u2 d4 I+ M, @4 m1 @* H6 h @#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 7 y% ~" m: p/ i
#define H(x, y, z) ((x) ^ (y) ^ (z))
. Q0 j, [. D+ c3 r3 c#define I(x, y, z) ((y) ^ ((x) | (~z)))
' K+ x; H U% P
, L$ H! _( u5 n7 X1 V& l/* ROTATE_LEFT rotates x left n bits. */
/ ?( E% w* b% k#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
0 t) ^/ v5 }8 J& d 8 l& E4 |+ C0 o/ v1 S5 P: u+ X1 \
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ( z$ _7 T, z9 t7 W1 d: d7 F* F. a
Rotation is separate from addition to prevent recomputation. */ * X- ^( r3 ?7 ]3 M$ h" N- P8 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); \ }
( X' X- {- \* 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); \ }
3 m5 l. F: d7 g# f8 {#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 3 U! _& q G4 S# ~: D5 K- G
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
3 L; b4 b! {! J1 \0 ?! t# b& F 4 ?, A, u# V f( N5 b5 F7 k$ ^
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ # ?6 k8 ]1 H' [- E
void MD5Init (context) . X. I, v* H9 Y7 _; o8 r( R y: \* d
MD5_CTX *context; /* context */
0 C% t0 f5 Q8 K: h{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 3 w+ _& _0 j- {) Q( Y8 J
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; # C3 F: D! a$ M6 i
} 0 u8 u; f: i9 K) x; W6 L0 ~
5 e, I- J6 @: q6 x7 ^. ^% W/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 9 F0 J0 }( o. I2 t
void MD5Update (context, input, inputLen)
3 Y& m8 h# v) h& Y. O& FMD5_CTX *context; /* context */
' K$ t- S3 u; ^. funsigned char *input; /* input block */ + t( U$ \, ?# s% k
unsigned int inputLen; /* length of input block */
: P. J8 d' [' m% g{ unsigned int i, index, partLen; ) ?7 W: R8 }$ L- a
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); % I2 k7 C6 c: y- N, \
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|