|
|
#include "global.h"
0 K" I0 p3 ]! N. ^5 }- g' c) ]#include "md5.h" : T1 ]! o# E& s$ c8 `' l* ?( q% J
& ?8 g* G* l. h/* Constants for MD5Transform routine. */ ; C# R2 R3 p$ n# S7 p% g9 R$ ~+ ]
' T( V# s [+ ^& V/ O' J' X$ {
. ?0 h( X) n# ^5 U3 d
#define S11 7
- R2 I& q+ G! ?* f' i* X#define S12 12 ' @- k" R. O) J
#define S13 17 ( c2 l/ L. t* G M
#define S14 22
* J9 Y! z: e0 I& ^#define S21 5
3 J1 D8 G4 E: L8 I2 s% |5 Z% N7 ^8 x#define S22 9
: A# }3 Y2 {2 M5 q. d#define S23 14 + o M' ~5 r0 q* S
#define S24 20 + Q0 B' |/ M, w
#define S31 4 3 f8 {+ z6 W- ]! q7 T
#define S32 11
1 i6 j: w, X6 i6 s#define S33 16 2 e# V# v% `2 k( D# m/ _0 u' r* S
#define S34 23 ( N8 u% H6 I' F. c% j M. x0 N
#define S41 6 8 o2 B0 R G8 h0 [3 [7 Y6 ] o
#define S42 10 * ~: @1 @( ?2 h. d6 v$ ~
#define S43 15
" u8 e. n4 w$ A#define S44 21
9 W7 ~' I* n7 a: Z, k& q4 ` ' [. R6 U$ _( Y1 Y( b" @: F
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
0 [/ [' ~% P M. r# B [# nstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
1 X" r' b! F+ u" lstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
/ _% W, v; @; E1 t; ostatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 9 X: z7 Y* e& i7 M7 s; s8 G
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); % O8 _) ^/ x& [% y6 m1 H4 _
: R( G0 \- R0 mstatic 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 ) K6 z0 }( Y$ {4 {, Q4 `
}; * `# k3 e# M: B# o* f0 y; @
% I3 v! z3 C' g1 s
/* F, G, H and I are basic MD5 functions. */
( i- o9 B/ H @' j* w#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
' d& e7 |# \ r#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) , N' p) o- W) c6 k$ b7 c% s
#define H(x, y, z) ((x) ^ (y) ^ (z)) % K! m) U, h, b" V; T* S5 v& Z
#define I(x, y, z) ((y) ^ ((x) | (~z)))
& h0 P; M: i0 ?1 \$ l3 ?+ n6 U+ u
7 A, P8 k& S0 }' M/* ROTATE_LEFT rotates x left n bits. */ ) I# T0 Y% l$ |" ` K( t7 p* E
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) + W- y( z0 e5 J" Y" [) O, E
Q# e0 Q/ }8 h+ u3 D. d$ x
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 7 Z) L) u* {( N( b3 x, h
Rotation is separate from addition to prevent recomputation. */
- j, A+ J# N+ r& q* }$ G#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 2 |0 i7 B" h6 O7 S) M
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } a" f' b7 U4 Q: I9 m: g8 I
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 3 t& _ B( }. ~; n: g6 T
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
D' G- }4 X/ U9 ~/ c R9 g % u: e: R- A; A# W
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
# ?' \- h; v0 [+ D2 u# Q% b$ E! Mvoid MD5Init (context) 2 l+ B/ g$ l: ^( d& u4 q& |4 q
MD5_CTX *context; /* context */ % }: e4 x: I. \
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. * @! X' c* k4 G. b! w! F. R
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
6 ~; h% W l2 l8 ~& A1 F} 1 H7 i1 A7 |7 n: c, F. \
3 [6 e6 C. c& u
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
# \/ `" F# C: ~void MD5Update (context, input, inputLen)
# R6 ]- K/ @6 ~: Z$ {MD5_CTX *context; /* context */ ' C: c+ n0 }8 y" t' a- C
unsigned char *input; /* input block */ ) `# O! p0 D( d4 h- \" b+ F. g
unsigned int inputLen; /* length of input block */
6 N# i+ b: q. K2 }. m{ unsigned int i, index, partLen; ; t4 z1 p' e- M7 }, s' }2 r
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 2 N4 }; m4 d8 ?$ g# _2 w5 f. I
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|