|
|
#include "global.h"
% {( w! p, D$ q! k9 ^( \#include "md5.h" ! Z Q' ]+ k3 c% B- U/ t) x, @. L
5 r) W3 {+ ^9 ^# j5 N
/* Constants for MD5Transform routine. */ 2 p0 ]2 q" L7 U# }% @( ]7 b. w
$ D, e8 Z/ e7 [8 v! r3 }
- \! b* S2 Z, M: }$ E#define S11 7
) w4 k! q% ?6 A#define S12 12
( m, c- v. Y+ ~7 N* ~% `#define S13 17
/ r7 w( o* }, l7 _9 m0 o( R#define S14 22
8 p2 V' \" w5 k+ Q#define S21 5 + p5 Y9 f2 s: b1 j0 |! x
#define S22 9
5 b- f- r/ b" ^/ S" z" ~, g#define S23 14
; T9 P6 q& U( D( Y4 y$ [$ O#define S24 20
" H% K5 O K! }- I$ R#define S31 4 # r( r; K5 d" p5 q x% l
#define S32 11 + B. I0 o6 o2 |4 K3 K
#define S33 16
* i$ \* k1 j7 M#define S34 23 % N" y/ f! L5 {. T$ J: ], u
#define S41 6 ) e# A1 E" U; R- N( i
#define S42 10 0 ^$ o0 j+ s/ _! h
#define S43 15 # u' F+ `2 l4 Q; j4 _$ y
#define S44 21
/ Y9 D# V& d$ B' e9 J8 @. k
4 U5 f% ^, Z4 n: |5 w2 ~1 ostatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
7 s$ m0 w0 I2 dstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
& _+ R7 R s) g5 f6 vstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
, y, Z) Z2 n# W4 W5 Q( K9 w- n istatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); * `; _; [* _4 X
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ) |6 h$ ~2 z9 c7 j8 F$ E
8 d4 s+ H$ r& M2 b2 U4 b: x H
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 , D0 K/ z4 G6 P' h0 j5 p9 [
};
" j8 |) V. m: ?1 I1 k
3 z( T; F1 D/ ]6 K/* F, G, H and I are basic MD5 functions. */
+ m2 S5 q G, v7 r#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
/ y. g# i: q6 s) s$ W; I J#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
; b6 a' m; G: m8 L2 O#define H(x, y, z) ((x) ^ (y) ^ (z)) 9 Y, R# u. L7 A- I# e
#define I(x, y, z) ((y) ^ ((x) | (~z)))
) b9 q M; Z7 ?' ~9 u J
# {! Z% F5 t4 O; [, \+ @/* ROTATE_LEFT rotates x left n bits. */
& i( Q. X* {6 l9 g#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
" F, Z4 {6 @) a8 a: g6 ~/ S 5 p7 w' N4 b# {' g8 k9 m
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. $ Y3 b) J9 g" k% Y7 A3 E- D
Rotation is separate from addition to prevent recomputation. */
$ m* U6 J0 f) 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); \ } ) v* N7 X8 h; f# 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); \ }
# t- V7 G$ @/ @7 Q/ W2 K#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 0 {- A3 p6 G' J+ X( U2 j
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } * I( W, D; `; l
' `0 b0 P- I# s# a
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
+ m( J/ s4 \" d0 A4 W& evoid MD5Init (context)
7 C6 \4 z5 b" C2 M; g* lMD5_CTX *context; /* context */ ( F) E8 N0 b# j* o: ^
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. & N, L! f5 W' Z8 Y8 d8 T
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
( t2 d% D% _1 _9 v' @2 D- |}
" `5 ^; ^% i0 L# y q G5 W' A
) t0 v `! r5 O# k2 K8 G/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
. X3 Y* H+ X% \# Zvoid MD5Update (context, input, inputLen) / |9 H: V* K" |% b9 V0 Y
MD5_CTX *context; /* context */ ' M5 q& e. W% f( G7 A. k7 y
unsigned char *input; /* input block */ + w4 [& a) H5 [( Z8 c8 F# `; V
unsigned int inputLen; /* length of input block */
# H9 `/ |. O9 A{ unsigned int i, index, partLen;
& y) @- u8 p5 G. i" Q, E: P /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 9 L6 S- N1 i- u' S/ G: k
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|