|
|
#include "global.h" , h7 B7 X! K! q! A- Z9 r) f
#include "md5.h"
4 E, c* Y: k$ x* o- y 5 K0 v' [0 G# M4 D0 i
/* Constants for MD5Transform routine. */ & g- W! o" f# k$ q. _" M' l G( Z
" l9 c, M, ?# Y1 l " W$ ]4 h9 f6 i8 w
#define S11 7
9 j/ W$ b" Y" P#define S12 12 $ [0 p% `' Z+ d- }# }) A" |
#define S13 17
9 l6 j w( W8 H) D/ o) ]#define S14 22 & e: F5 G, y* J( i: L" O
#define S21 5 & p, u6 H4 u" A. u+ {
#define S22 9
. v* R3 T2 l* m9 k) R- J#define S23 14
" ~* O8 c# R, P% N#define S24 20 / \5 j# _. s: s J; J# ^* ]
#define S31 4
6 V. U/ t$ j C! e- n#define S32 11
- _: h$ o6 N1 ?" V: g1 C#define S33 16 % R' @3 N, }; Q/ Z
#define S34 23 . t4 k: ^/ ^8 f2 r& d; a9 F
#define S41 6
& k( T4 d+ E1 f6 ]1 e#define S42 10
G4 P" V* r, t+ s# u/ y% Z#define S43 15
& W, h8 b6 Q' X5 `; v#define S44 21 ; `2 T3 D9 @3 b4 @
6 f% `! k( X7 W( @$ J: ustatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
, e5 ^1 t% a; B7 \( qstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 2 f9 [; a* e, |5 c1 |9 K
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
* s3 z! l' R& |4 `static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 0 H! c& D" o/ H& J6 K8 m8 C, a
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
! \1 x, [5 k2 f( G, ]+ W ) y M, v; Y, F; I. e7 M) D- X
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
0 Y( {! w1 N! K1 K9 R};
- ?0 D/ d. q7 V |% ~0 u; r; Q' _ i + M' @2 V/ _3 ?
/* F, G, H and I are basic MD5 functions. */ 9 V1 \& B% X3 N8 J; X
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
0 V# r& b2 ^9 ?- y1 } I#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
% o- O' T; ^7 |# \+ t#define H(x, y, z) ((x) ^ (y) ^ (z))
' R# a; B0 H8 h+ d#define I(x, y, z) ((y) ^ ((x) | (~z)))
7 z- z( Z( v7 i, Q - ?: T x A/ _' `4 j) G3 m0 ?
/* ROTATE_LEFT rotates x left n bits. */ ! F% G! k% p6 Y
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
- H& O. O7 A7 s: S" A
3 N3 [7 ^6 F3 G% c/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
/ ]$ s" m# C5 h+ j8 s: [Rotation is separate from addition to prevent recomputation. */ o8 a( M$ i: ~
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
$ J- h" l q! b9 z#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
P2 y- d' }1 J! X( t* p8 D#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
; S* P& L; x& t 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); \ }
4 e) [' Z3 J( s* s + L6 o2 l. D! O( A0 W3 K
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ " _. F. k- b! V( k/ Q/ L
void MD5Init (context)
- I9 F m% H) }& u8 y( e9 hMD5_CTX *context; /* context */
' W6 q3 Y; j2 c( U/ t, }0 n{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 8 U5 c: s* e9 R7 ]
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
' A Q1 E$ w( I, z% g}
! ^( H) V0 a3 R% x }3 h t# D( G7 u& x
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
$ `* w) h# c, h" T, yvoid MD5Update (context, input, inputLen)
/ x m6 X* r2 PMD5_CTX *context; /* context */
; o2 Y& ?, f$ B( q/ yunsigned char *input; /* input block */ % @" l1 k5 r. N
unsigned int inputLen; /* length of input block */
j3 H$ J) O1 u7 i3 @{ unsigned int i, index, partLen; : p7 i" o3 }# \7 s% ]7 `7 n5 _
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
+ P. u- K8 t! I: a /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|