|
|
#include "global.h" 3 |, B3 x/ M8 L2 I0 z5 F
#include "md5.h"
; `; v5 Z: _+ F6 ]+ s( @1 Z % P; _( x" Y! N' T. @
/* Constants for MD5Transform routine. */ * `+ q3 Z% C7 x5 Y. \5 V
) A! {2 C/ M8 I% Z5 z8 D, ]1 F/ p 8 D- _) d5 P: L6 r9 h5 M
#define S11 7
/ G9 a9 l9 B7 z6 _, q#define S12 12 3 _- i9 n1 A; j4 T# T+ u/ t& Y
#define S13 17
% D% Q9 V, K! ?8 d7 b& B#define S14 22 , K8 `3 J( }, Q$ l# h: h
#define S21 5
( V+ _* ]5 g5 v" S5 b# l#define S22 9 3 G# S: j# j- |% Q
#define S23 14 - G$ Y& S5 q: [4 r8 J# U- J* {( m
#define S24 20
' S3 b9 z, F& e# J#define S31 4
, K6 {& O4 p# C6 A# |0 C6 F' @#define S32 11 1 r' V% x3 m, }; n
#define S33 16 0 x$ J' `4 X' B! e
#define S34 23 + ~8 R+ N, }$ R% ~* y4 I) b2 ]' M
#define S41 6 - R8 x0 Z$ y1 ^5 Q2 x' N& t, L
#define S42 10 , Y- ]4 b+ T: t2 [
#define S43 15 % d+ I5 Q' [ u( D- g9 r
#define S44 21
; D1 V' Q% [+ ~+ g
; L/ i# q' U- H: h3 b6 z9 Y) t; tstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); ) D- I# U3 e8 j: I
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
% N! y/ m: w- N2 y% c' vstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
+ ^) ?2 Q3 l4 Mstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
6 ~: U7 Z% I3 P( nstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ( |: T, g$ S; C6 w! |" f& Z5 F
% F) p* Q+ [5 @6 [
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
* V0 T& | l3 E6 Z+ u}; 2 B% h& f$ r& f! I" [2 l" L0 J
# D# {+ i% H5 m" S% ]
/* F, G, H and I are basic MD5 functions. */
( o% l- S1 s% g2 v# M#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) & M3 Y7 e( L3 }$ S+ G
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
, ^0 I7 f# ?' B5 Y, o7 ]5 B, Z#define H(x, y, z) ((x) ^ (y) ^ (z))
" e' `* B* B: z1 A0 p- k# r1 O6 n#define I(x, y, z) ((y) ^ ((x) | (~z))) / ?0 ?+ k3 u/ G, J
5 T- G; t) g9 H' o$ o" w$ {/ I) M
/* ROTATE_LEFT rotates x left n bits. */
: D8 D$ L4 ^4 e4 `3 G6 n5 G#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
5 h2 H+ }) Q, t3 u( e4 k' l
# U- I s$ | l p1 X/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
4 N; k2 F5 }3 x+ }0 _( e+ M9 L4 ]4 x, `Rotation is separate from addition to prevent recomputation. */
1 L" n8 M, }! q# m2 [) M; 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); \ } h1 o4 y0 W) u* 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); \ } * c8 i7 \3 W+ j& ?5 Q
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 x! }1 c5 N! Y# @: R S
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
( _" [; w$ p A8 W* e- j
. V- n) x7 s, p0 `% K5 z- R2 `" K/* MD5 initialization. Begins an MD5 operation, writing a new context. */ , R* C0 t3 r5 S) }; V
void MD5Init (context) 4 ? T! H; u% O
MD5_CTX *context; /* context */ 3 P! v! E. a2 G `/ E
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. : @- Z8 Q: t+ ^4 w8 `
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; ( p: G0 E% e$ Z; W f2 p+ H3 z4 y1 d( y
}
E3 N9 G; }, _( W/ W/ {1 h/ f. U
- B) j* M% N; |+ |/ _! E( r/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 8 q7 j b2 A2 x$ M
void MD5Update (context, input, inputLen)
# r: N1 O2 J9 V {3 v" J e |MD5_CTX *context; /* context */ / R7 I8 p. R5 [$ g
unsigned char *input; /* input block */
/ H, e4 a) X( a# x* J( Q* @# ]unsigned int inputLen; /* length of input block */
+ ^9 c/ U; M& r{ unsigned int i, index, partLen; & B4 U3 H* O- R. z0 ^; l
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 4 {5 V ^$ m+ c1 \
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|