|
|
#include "global.h"
0 ^8 h4 O5 l( q( P#include "md5.h" 5 c5 r0 p0 G* s# a! t% J/ S
, Q& }' A c) y- B; \
/* Constants for MD5Transform routine. */ * Z( o, ? u, _
+ R+ i N: u8 N' d+ q
4 \* n6 C4 C% p" @0 [6 t. R' C4 ^. @#define S11 7 " F9 z$ w% ^4 f- V. {
#define S12 12
0 C, ]7 N1 k0 Y$ ?" l: V* S9 @5 W7 v#define S13 17 1 F+ e/ x" {3 K& M8 Q
#define S14 22 ( x* r i5 a6 a1 w. }3 w
#define S21 5 1 T1 K7 X2 H5 B) n9 p( M4 ]
#define S22 9
$ g* l: Z! u+ W. ]# i( a3 z#define S23 14 ; ^! P# B* g0 E) p1 J8 @
#define S24 20 " \2 l4 A+ ?: }! y; q
#define S31 4 ( \5 Y3 ~- t3 e& c0 b
#define S32 11 1 q5 j G+ x K; L0 J% Y
#define S33 16 7 W, k' |3 c1 l1 e
#define S34 23 & J3 W B* l$ t8 b( f1 ]8 k& W7 I5 b
#define S41 6
2 `3 S! G% m6 P0 s#define S42 10 2 e7 J9 ]7 ?" d* i7 _4 a7 l% T/ ?
#define S43 15
0 [6 |1 g0 H" @#define S44 21
0 E' e& _. d% `% C) F
* F1 J r- {+ {- c$ H, xstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
% x9 ^, q. d1 }( \$ @1 z: Istatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 5 B) q( r$ o, i' z% h
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
, X& {+ j4 ~9 }% kstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
* D7 q& U1 W( R) ?; }9 pstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
* N3 }, M$ S% I! d+ b
?* x5 O, G" a4 Z3 L) estatic 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 ' T- i$ m7 a6 S. r' v
}; 0 H' r( s1 b9 l9 Y6 @& m8 {0 T; q7 u
7 H/ u& L& n! C+ q3 b* A q' d
/* F, G, H and I are basic MD5 functions. */
. |- H: C9 v# [" `, m#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) . ~. T" l1 y7 l3 \
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) @9 b/ ]- _& W' @9 s9 a: E1 J1 \
#define H(x, y, z) ((x) ^ (y) ^ (z))
/ c( E( L) r7 G# l$ i1 m D& V: c( Q#define I(x, y, z) ((y) ^ ((x) | (~z)))
8 l1 q" b' _ e7 [! M9 R' w 1 W( ]1 W! I* t! k* j: C5 j& z
/* ROTATE_LEFT rotates x left n bits. */ ; O3 I) Q V$ X
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 7 K Q2 b& o4 T6 i% P. Y
/ a( }2 ^' v- e( \9 g/ |, @+ w h
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
8 q) s+ k' \0 i+ `: U+ xRotation is separate from addition to prevent recomputation. */ ) Z1 B; C+ `2 X5 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); \ } . ^$ y4 e- z( ` B; u
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" V7 ]+ {9 }5 h* ]+ 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); \ }
7 E+ U; ~6 _0 d( w/ U) `1 m3 u#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% Y# G1 @. j9 {3 r4 I; G0 H4 r
" ? ~- w: S' }" Y6 L/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 3 m' Z! R0 ~ F& {
void MD5Init (context)
- i$ z" J; ` WMD5_CTX *context; /* context */
2 }5 w/ I- M/ M0 B{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
+ o6 p( ~( ~! e# W: j% K*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
" K$ @7 K$ d% D( S} " y% X# c4 q2 u! u A
" s Q5 u4 ]7 ?4 N' j: F
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
2 A! N& X4 L% D- W7 K( S& Xvoid MD5Update (context, input, inputLen)
" _% @4 c6 D- q4 }. y2 C) YMD5_CTX *context; /* context */ % O; w# b' i, I5 T" c5 L) d
unsigned char *input; /* input block */ - N% Z2 }) f1 L. s# F
unsigned int inputLen; /* length of input block */ . B2 d5 X$ `2 A5 \6 {! Z. e
{ unsigned int i, index, partLen; 6 P; O$ }: Z, k2 h& J5 Q, _
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 8 p2 Y5 u/ v3 _" Y: ^9 u4 w) V
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|