|
|
#include "global.h" 9 Y* B- H2 y+ u
#include "md5.h" b0 ^: A; b1 _5 n5 ?9 {3 W
4 I8 q' X' v8 j b, i% G* a
/* Constants for MD5Transform routine. */ + Q/ j; {' M9 p' g" d
' `3 t4 e0 C1 G0 U
8 Y. {& \2 @+ Y" ~6 k: P#define S11 7
+ A" o4 Q9 f. a8 H0 u#define S12 12 # Q6 T- @+ r" U2 q* s ^4 W: b
#define S13 17
. Y4 u! `2 f. q#define S14 22 + \* E. Y. s- A0 r \3 n$ ~
#define S21 5 1 f, Q% l# U, f1 l
#define S22 9 0 w7 r! r; A( z& ~- U" O
#define S23 14
1 \, _" ]# i9 v5 S) ]- p6 e#define S24 20 , d U% G* ^) i. R f
#define S31 4 ) T" _& N: S1 A( A& Y
#define S32 11
* a* f( E8 ~$ \0 X6 k# E. m#define S33 16 0 y! W( H0 P. x6 u8 ^
#define S34 23 3 J5 i/ @9 Y2 `" `% d+ {
#define S41 6 ; r' e6 B2 |6 s6 T, n
#define S42 10
3 Z( r* m, G1 H" k#define S43 15 2 V2 H; e' z9 { G4 A
#define S44 21 5 I7 Q3 i0 U% I' O9 e7 g! p3 v9 _- r; q
: W3 z$ n! L$ A4 y/ h. o
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
* T8 O; w/ T' f# O$ v% Zstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
: q! o- Q5 Y( Xstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
- L, I2 o6 ]2 ~( fstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
! m: @3 U* k8 U* }static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 8 v4 F. T- N9 M! l
, e& A# g5 [& N9 m
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
. C4 j6 a( |$ V7 h}; / t6 E. ]3 g* B% h+ m/ X
7 C- z& X0 K4 K) K5 k! k/* F, G, H and I are basic MD5 functions. */ + Y( x6 a/ G7 ~+ z" t
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) . l, S& t9 P7 W+ h
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 8 E! F" n1 p: u3 P4 n0 k+ {
#define H(x, y, z) ((x) ^ (y) ^ (z))
, m2 x( o+ }' p& j; i#define I(x, y, z) ((y) ^ ((x) | (~z)))
7 }. {- q P7 c% d8 ?8 ?# M 2 v& N- m4 N6 z7 r
/* ROTATE_LEFT rotates x left n bits. */
6 P: r: K3 u3 d$ r2 q) L#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
& m; u9 @6 \- t; G
' H9 B5 V/ B S3 }/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
. W y; }9 M& l1 E9 P _5 L/ P& {Rotation is separate from addition to prevent recomputation. */
2 N) }. \3 w9 C7 y2 L#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
7 C( s+ S7 Z4 |, ?2 Y5 G#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
* G1 C9 W, n3 X#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
( Z: j9 j' Q: c f. N' }' \3 P( d#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" F# F% q. Y7 C& j I 3 j9 t8 J) p# l$ _0 N, J. i2 t
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ % j; q* r! z' P5 e
void MD5Init (context)
& {4 H: I a9 s2 C5 mMD5_CTX *context; /* context */ 5 i/ C! _1 F1 Z
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
. e8 L5 o: S: o6 Q: @. q*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 7 x2 _( E) O9 h0 W
}
: b4 i3 C% t! [8 E
; i9 s# y h9 H; a, [+ X/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
, k% E# A% X. z1 m+ s, i* g/ Dvoid MD5Update (context, input, inputLen) ) A5 B! i8 s7 `$ i( F
MD5_CTX *context; /* context */ 3 l' c# r' s* } y/ v& a0 I
unsigned char *input; /* input block */
; w1 y% l2 \0 s0 g, l/ C0 \- K5 Kunsigned int inputLen; /* length of input block */ 4 f9 p9 E1 M+ f3 G
{ unsigned int i, index, partLen;
) Q2 j# a4 l! J& X+ A$ D: ?: \ /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 6 n; p. e& K3 Y* J2 J Y6 q
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|