|
|
#include "global.h"
" G+ X4 r; Z3 }#include "md5.h"
& u% F0 i( H5 B' \ ?
% u6 z+ D$ Z) V9 Q/ P0 n$ K/* Constants for MD5Transform routine. */
# S8 u: H. C& U % @: \# r# M/ H) A
- v# e! D2 w, w% `#define S11 7 5 I% M% ~+ U. Q+ T* n: v' w
#define S12 12
5 a( M4 i, s, R. Y' U0 e$ F#define S13 17
( A1 u' T! d4 C- A! V. N b#define S14 22 ( F# J5 b7 F6 @; G
#define S21 5 6 M, i9 n Y' F; ]6 o6 o
#define S22 9
6 l5 F/ @: E: W#define S23 14 , t: Y. A' o7 K$ S# h5 P5 V5 Y5 `- C
#define S24 20 ' V f! |3 P, l2 C+ ?+ j+ U
#define S31 4 * y1 o1 |* o* E2 b# m. m3 b* G
#define S32 11 - ^4 N) A# x# g) x; J
#define S33 16
" A+ b% D1 Z4 d* Q#define S34 23 3 G; b6 {$ N, ]5 b! E
#define S41 6
+ y) B. s( _( |6 c, T4 j#define S42 10
& H0 a& S: R% D; V7 ^3 L q9 c#define S43 15 2 O: k" b/ j+ v! N; h* W7 @- i
#define S44 21 # k9 _; U( G9 L; c4 a
; M. \4 ]6 W2 F4 Lstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); ( Y# b- F' y2 e- |" c0 E
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ! i c2 a+ ?0 L. z, l# x
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); $ N4 j K3 L/ b
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 6 C3 \- a1 T1 l1 J% |
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
5 }+ r5 \, T( V0 I# w, h4 C 0 m1 f4 |. W8 U, \! q
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
( @! ?4 Y& [# H( D5 E6 |};
2 q, B/ p5 U9 X8 F0 Y, l) w7 v
7 F8 q% F, H* A% N& |5 O+ b/* F, G, H and I are basic MD5 functions. */
8 G( Q+ s5 D& c/ L#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
0 a! J$ I3 b! O$ O+ q- O#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 4 n7 W% c# Q# U6 M. @9 Q& Y" K
#define H(x, y, z) ((x) ^ (y) ^ (z))
" C3 \2 J4 R# o- c% q#define I(x, y, z) ((y) ^ ((x) | (~z))) + ]( u. z- X; K
6 n+ s6 s* f q# \- S1 n. Z
/* ROTATE_LEFT rotates x left n bits. */
) l8 Y- y; v' v0 H& \. G" H#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 5 g j( ^/ @& M0 l! k
I) k5 K0 Q1 n/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ! w% I$ @# ~ o: ~7 x# m
Rotation is separate from addition to prevent recomputation. */
! Q# v5 L% d T% ^6 ^& q0 n- O P#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
. e& g' E( {7 N3 y#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 h' P1 b& R% T/ M& `#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 r/ u! L; D& a$ r7 C8 T& V1 @#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } " H$ G) ?( t; K ?% |
6 n' p+ W6 P3 p
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ * w- [. E7 Z4 J% g9 w) f3 }
void MD5Init (context) ' a$ ?; Y% h; t5 E3 l5 a
MD5_CTX *context; /* context */
. j6 l% S9 t, d" _{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
! J4 V8 N( Z) q6 y9 C5 o$ I+ x*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
7 x Y/ ^2 O. Q. B% M0 \7 n}
0 }- Z4 J4 g/ ?1 U! e 8 |. Q: \; W1 }3 V- k7 R
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
1 Z$ N7 Y9 I/ A9 C, O% o p9 Ivoid MD5Update (context, input, inputLen) $ b7 i! q4 B+ u- [, h
MD5_CTX *context; /* context */
" e8 X a q8 k6 ?0 I! g& \unsigned char *input; /* input block */
; A/ K& d1 r6 {4 Dunsigned int inputLen; /* length of input block */
' Y- i+ E/ Y. H8 Z: j{ unsigned int i, index, partLen;
& R3 E m5 e7 C/ ?5 `1 Y# y /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
5 y) ]5 F, g# w4 e /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|