|
|
#include "global.h"
3 L8 Y. E4 |" O- x! V/ Y! j3 a#include "md5.h"
5 B% b) a" F( N" g $ K4 B* v: V8 ?; g" P I
/* Constants for MD5Transform routine. */ 0 d7 l3 O% W( X! r" `; k
, b6 |3 g2 k, u* i# U6 h: `* Y( {
$ K5 n: {3 E {0 g#define S11 7
9 I4 L( g4 m1 I( M#define S12 12
) c: M/ }; l9 [0 p; C#define S13 17
, G, K6 V5 ~: ^* V& i& h#define S14 22
+ C5 N, p' h$ y/ Z0 L#define S21 5 : @/ Q/ W' J4 \0 m6 Y( u) d
#define S22 9 0 Y! J, L8 l0 I Y! \# _! ?
#define S23 14
1 z6 i+ _* s7 W% U k. Q2 L" R#define S24 20
4 q7 b% t1 o% [% t a1 s) Q- ]! }% p#define S31 4
8 }, M$ R7 q- y8 [! y9 r#define S32 11
2 D2 h6 z5 M6 {( E2 O2 q' G! u#define S33 16 * K) E% y1 z7 N. ^- A5 f2 u! Z
#define S34 23 ( z# M# f0 R. g
#define S41 6 % M$ \4 ]) X& v- F* e4 c" X
#define S42 10
7 i8 d+ ^1 P. M6 _, c) P5 ^#define S43 15
6 `) m1 z( K+ B, ?#define S44 21
. {" y0 v, z$ F ( ?( Q. D, n$ T2 z* b; ?
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); , J' U0 ~; O2 W% S( |: b1 I- |2 M
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 7 [ c) C* J6 T% u
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); $ |/ ~* e" o$ f* K- o& ~; B
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
0 e- M6 J: c% tstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 5 J0 z( q5 H8 ~( |, _6 m
+ d" K0 @; X8 J
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
+ c2 g+ X4 }- P2 g3 b};
7 U0 |: E5 u1 x5 n. k* k U! L" w: D5 k: C
/* F, G, H and I are basic MD5 functions. */ 9 q: R) s/ J K" ^
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
: ^+ Z' ]) ~+ e$ m5 Y e+ `9 P#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+ @ V2 X. c+ o* P#define H(x, y, z) ((x) ^ (y) ^ (z))
; X8 U+ u- q& R2 Z, Z; B7 Z#define I(x, y, z) ((y) ^ ((x) | (~z))) - W. O* T# ^" y( t" a
% g3 b/ B5 g4 _- f
/* ROTATE_LEFT rotates x left n bits. */
- E) Y) c& t6 u" o#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 4 z( z* _* u H
' Q) M, I4 q$ S% p/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
* |5 j/ ~4 @( {& A1 P; R. ?0 S2 TRotation is separate from addition to prevent recomputation. */
" L! w+ L2 `8 V' j* q& O3 \#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
9 P) j( e/ ^: O: `# |4 s#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 w* P5 }( a% I8 K
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
' o2 `1 ?% {" Q) w6 [4 H8 |( m#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
/ B2 N: @7 B" F' E9 o1 l6 v
; O0 S" y5 Z( b; j% L) r/* MD5 initialization. Begins an MD5 operation, writing a new context. */
7 K. E# `+ L4 v* s: Avoid MD5Init (context) - Q% G3 J/ @; Z! k2 Q) m0 U) w8 s
MD5_CTX *context; /* context */
5 x+ u: Q' i8 V- h* N& \1 M{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
! @' Q9 C8 j) Y- x( x g+ O3 m*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
, }$ i* b3 u: n* A7 R% ~}
3 }/ `, c$ R. g6 p" B v3 t
. B/ |6 `% A/ F& T6 _) y/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
; }6 o6 h3 c' O7 c) v" {! H$ hvoid MD5Update (context, input, inputLen) ; \7 \: p' a( p6 b
MD5_CTX *context; /* context */ 9 M3 M8 e: F, u$ N" i- c3 b; J
unsigned char *input; /* input block */ ) h: d, W3 m3 q* Y$ s" [4 N
unsigned int inputLen; /* length of input block */
. Z! f; H; s! U: U6 s d{ unsigned int i, index, partLen;
/ x% ~# ?4 i& n7 P9 e /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
$ A L: o* I' X7 Z& K- |. [, u /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|