|
|
#include "global.h" 5 T3 z0 u) o# j! j$ |
#include "md5.h"
& m& i$ s' ?) [$ _' T. J$ H 8 F4 Y. m/ N7 `# X# b- d
/* Constants for MD5Transform routine. */ % U2 I/ A0 X: V7 u
5 f7 }# Y. S5 I; |/ C) {, K3 R
( _+ S* ^; } K4 m, @5 `. m
#define S11 7
& I9 o) b& Z+ ?4 K$ z3 N#define S12 12
! t, ]$ E% o' N$ R#define S13 17 % u! V( ~% `; y) I
#define S14 22
4 i# D4 \, ~+ `0 b4 b#define S21 5 " E" f& }% F- i( a
#define S22 9 / U' P& Z! z# I( i8 ^
#define S23 14
% v6 p( v; V' j1 `6 r#define S24 20 " v, S" E) n, K y$ n& h
#define S31 4
# W5 c3 u+ F6 [# B6 M( {1 D0 o" B! h#define S32 11 ! m0 {; F8 j$ m# s2 P
#define S33 16
8 t3 h* `1 u+ r- t5 N* A7 v4 v#define S34 23
) M! P1 Y- ^; b. e+ f- f5 f* v#define S41 6 6 K8 m! g) c5 ~( w; c3 |
#define S42 10
$ H3 R+ K) G; I; V8 h8 T" D#define S43 15
) h- C3 ^1 g, t#define S44 21 ' D* L2 d: c; c! U5 z% x- F
8 L7 a6 G+ x; ~9 g8 ^3 ~* C$ p
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); $ u; _' U: G4 _ N5 R
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
0 ^4 F2 R/ E. Z- O2 J* nstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
' ^; c, R9 ^9 a9 w$ i& ~3 jstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); + m/ M0 }; T* M
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
4 y) J( c' C, h" v9 y
$ g5 t1 }5 ?) h- t/ ]9 dstatic 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
, O9 o b' T4 e# g% B}; ' l5 ?" T# z! P j1 z: {5 H
% O: x/ `1 ^, Q4 r0 [/* F, G, H and I are basic MD5 functions. */
! y1 _( f0 p0 g#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
/ N2 o6 S: v+ D+ @& Y/ d#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
. p0 h1 A" l# {( p% n* X! P) }% \#define H(x, y, z) ((x) ^ (y) ^ (z)) - R& ^6 j# F Z3 J$ @7 {
#define I(x, y, z) ((y) ^ ((x) | (~z)))
5 y% g9 G3 p* P5 u $ S$ c7 o q: L9 b
/* ROTATE_LEFT rotates x left n bits. */
! ]& T6 f2 ^7 P#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) * b; n# u$ [! |( }- b* v# h
4 V; n1 h; v4 H d, O
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ! Z* ]" F U8 j) [6 n# f
Rotation is separate from addition to prevent recomputation. */ 8 J: P: O4 l- b7 \+ k1 k
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } - X% D, I. t/ v3 d
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ( }7 H/ X7 |; o
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } " L" O4 K9 P2 g$ r( I* p1 E/ H
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ! b1 n7 H$ }+ v, ]) [0 A
$ g9 K* N$ U* j! {9 A/* MD5 initialization. Begins an MD5 operation, writing a new context. */
8 Z8 E1 U& B' {) z' a! dvoid MD5Init (context)
* Z# ?/ W' C7 S/ X& kMD5_CTX *context; /* context */ 3 F! Y2 V4 I, T: ?
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. * G, J4 G+ ~. |* I& u$ o* T
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 4 M, V% O" F$ J7 Y9 y
}
^- | j s+ [8 V( b |) P( n
& Z" ^" g& y# z% O6 b/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
8 c- }) c7 J8 F1 G j2 Yvoid MD5Update (context, input, inputLen)
& l! ~! O# e/ M2 z- q/ ~( l5 cMD5_CTX *context; /* context */ % v9 B, A4 G' t+ W$ X
unsigned char *input; /* input block */ - o0 ?% y: J0 T' x: X
unsigned int inputLen; /* length of input block */
# k$ d" F! p2 M. S* Q{ unsigned int i, index, partLen;
$ L1 d$ y( t7 O6 e /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); / J* j. Y7 ^. e8 n, ]- b; b
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|