|
|
#include "global.h" ) g* e$ u. B0 B
#include "md5.h"
7 U9 g$ A. w9 C' q5 X* \. P - x! R) m. U. O% e7 e i
/* Constants for MD5Transform routine. */ {( m) w. U' N" E& |: u3 A2 Q. \
. I& k- S `( c: q" r& }
6 g* ?3 v! l3 q! G- X/ D i3 O5 I! Z5 v
#define S11 7 1 n7 _0 S8 k) W/ A1 ]
#define S12 12 4 i7 Y+ W$ u* Q( b
#define S13 17
T9 w6 m$ c* Q& Z#define S14 22
% y9 r# F A. k4 w a. K4 n* t#define S21 5 $ D8 L$ a2 k- t8 r
#define S22 9
: G& ?5 v" m& X! |$ ?+ A#define S23 14 7 x7 ~/ q0 z: E0 t. i" l, w- Y1 t8 a
#define S24 20 ' Z1 g# ]1 P n
#define S31 4
! W% s# @* Z) d% i1 n: J9 ~3 m% G; |#define S32 11
7 e1 d6 j/ V" r0 o0 L#define S33 16 - Z4 M2 G: ~6 h2 K+ c* v# A. Q7 a
#define S34 23
5 r. w5 }5 ^$ J# X. u#define S41 6 4 H7 `" _' M4 v) r7 a# q6 }# v" @
#define S42 10 ) N1 o( |0 n' u- u8 U7 t& ^
#define S43 15 ' g: |+ K8 S v: s4 g" ]
#define S44 21 6 h8 E* n) J1 C3 \- Q0 s$ u ~( U
+ I4 g' p( J$ S& i z7 {8 e5 e
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
! y7 D7 d, y' ^6 Y" P1 N' U/ rstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
6 y6 F* m, C# T$ F0 P" A9 {static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
3 }, @; F8 @8 s! H) i# bstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
1 ^, Z# h) _# X4 a8 b& ystatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 8 L7 B2 q) n7 Q j, _
5 `. l* y* G1 X, f
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 # l3 L2 r4 L& k; q) W! s$ k
}; 1 ]: \, W( R: [. i r6 S5 U; x
% s- N6 Z9 N$ G3 u4 |# x, `/* F, G, H and I are basic MD5 functions. */ $ a+ G. s" v H* b' z/ u, e
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 1 ]8 a1 m/ M- n
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) * a5 A4 \4 Y0 @
#define H(x, y, z) ((x) ^ (y) ^ (z)) , u5 u6 h+ `5 S% @8 ?! Z" X
#define I(x, y, z) ((y) ^ ((x) | (~z))) - Z1 s" L6 |: j3 u9 P6 C+ r
* T* N5 `: O4 i" A& j2 |/* ROTATE_LEFT rotates x left n bits. */ 9 z: o& m8 }. i5 n7 d& d/ |
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
' d! U- e1 e$ h3 |% B4 [2 a& h8 ~
+ t! v- G# i$ I3 R4 C( S/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
7 d# N0 A7 D& d) g; N2 m9 qRotation is separate from addition to prevent recomputation. */ / Z9 _& g8 u; Q$ D
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
6 H9 X8 b& F' u* g" o4 E#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
9 A3 t) _( O. f#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
, V' H) t- H8 ]' ^' A0 F* x#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
( r7 U* r2 V2 ~' T+ z+ Q4 | x$ ^. m9 P3 D6 Z
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ j8 u& f' M. _/ b& Z+ O- I
void MD5Init (context) # M, C) F, \+ Q! ^1 l% S- {
MD5_CTX *context; /* context */ % J- z& S b, s/ ]8 @. u7 U9 Y; |
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
0 ^" Z0 ~ i! ?$ p+ Q*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 8 B6 Y w6 W ]
}
9 F5 X! O: s- X' J) q a1 ~ + x$ N$ n* U( B- H$ ^
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 9 w0 Q' }% l+ E: S
void MD5Update (context, input, inputLen) , e% G; X5 @! j% V6 ]% I5 y
MD5_CTX *context; /* context */
* y7 r; E) x% Kunsigned char *input; /* input block */
- D) u1 t4 W' m3 O9 Wunsigned int inputLen; /* length of input block */ - @: _ ~: y$ e$ f- O: ?* ~8 K2 W' I
{ unsigned int i, index, partLen;
9 e2 I4 E; F1 U0 D' c+ E /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ) n7 S" p$ P6 q/ H' r. W
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|