|
|
#include "global.h" 3 X% @, t7 |: A5 g) z
#include "md5.h"
" u7 V& v( _, k v2 q2 t2 o |3 R% q 5 ~9 c- W( m3 `/ K" [ c# H
/* Constants for MD5Transform routine. */
! F4 l1 r, |' w5 N
) T7 b* J7 `6 V5 ~) u. ] e
& o' X. f; [: h' @$ R! I#define S11 7 1 g6 ~+ O+ o8 n, a- E5 S
#define S12 12
+ |# e( P0 W# f: h3 f#define S13 17 , d+ T# d' ?0 b8 P- i7 G
#define S14 22
' C1 g1 ]7 F( y3 G#define S21 5 . m7 c, J! e* q$ @2 @9 m3 e
#define S22 9
: A+ J6 N9 K& N: u2 L, B! X" a, h5 b; }#define S23 14 - d5 Q1 k8 G( I; i( H8 G8 O) S0 P
#define S24 20
! J6 A8 V2 O* ]/ e#define S31 4 ; `9 v' E6 U a% ?
#define S32 11
) [: c4 U% W b: w, ^. U4 y#define S33 16
9 b! K) }6 ~) R& D2 U% t. u6 P#define S34 23 * K0 o* u+ T9 w' G$ {9 x
#define S41 6 + O A% G# F* v% B. S: h
#define S42 10 0 L+ l7 q, S2 X9 ?$ {4 \" i
#define S43 15
" D5 f$ I! [9 o c$ X; _#define S44 21 8 x0 ~$ x4 J. X) t U
" G4 G, n8 [) L& z, U- t
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
& o Z1 O4 N# j, j& K9 N: Ustatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
, r- e ?' p. ~- Y) c& c9 estatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ) f) {6 m9 w0 r( u) r
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
4 b! ^, S# J( j# A! |# cstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 4 s% e, f( R; O/ H' Z6 K) t
$ {& {* C' H9 i" K' w
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
/ d5 \& E0 M+ F+ T/ h+ h};
/ c- N) t! r' J+ @ u- n. x: T; _, \7 ^& H
% ?+ m2 } T% s5 {; M/* F, G, H and I are basic MD5 functions. */
+ R( r& l+ L; h2 g#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) * |( _8 a4 s/ p+ w
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
4 _) d- b9 D5 P; o- ]! b& P7 J#define H(x, y, z) ((x) ^ (y) ^ (z)) + j6 S$ P% V' e* J
#define I(x, y, z) ((y) ^ ((x) | (~z))) 7 q% T+ I7 M; s8 f2 D# m0 c
' F4 K' m+ {* U W$ c; v/* ROTATE_LEFT rotates x left n bits. */
, p/ u, i' h* x$ m% ^: ?#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 4 S! j. h) g! G
' v% ~/ W7 X1 ]5 h+ d5 C/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. + C4 w# Z- M2 J5 N( M
Rotation is separate from addition to prevent recomputation. */
. K8 I. L% l. [' i#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
1 E6 r, r" ]+ c( w9 C#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ( f+ Q$ r$ D1 \0 d$ {
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
. F0 \. m+ n: {1 Y) O#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } & x [3 n" k9 X
$ j, X$ q2 [. `+ V3 n9 K* r
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ; y$ S$ P$ ?# I! ~% n, _2 \4 O) V
void MD5Init (context) 4 Z: v* _4 R6 q: T
MD5_CTX *context; /* context */ / K( ^0 q8 V4 T0 o3 u
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
p N8 p1 h. g5 c*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
' R8 B7 Y% y1 H' M% B6 v$ }" Q} . K" T* \! R" ^5 |' \& J
1 Q9 m. o Q2 B. X6 Z) t
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
3 n8 X. ^, ]; V& Hvoid MD5Update (context, input, inputLen) 9 ~' r' ?1 \0 N: m* D; W) ?
MD5_CTX *context; /* context */ 2 F/ B; ` `# B: d; u1 [: Y% k
unsigned char *input; /* input block */
% e( [* J" B1 z X+ c: r5 T! munsigned int inputLen; /* length of input block */
9 }$ {5 T. e, ~. @, @ b{ unsigned int i, index, partLen; . F d6 l' ~' n9 n$ p0 A
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ! V6 H9 }$ K1 _; W9 C
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|