|
|
#include "global.h" . }! u6 h+ R3 _; s0 E2 S
#include "md5.h"
: D, H- ] i% n9 V % i# `& {' `% C- a7 d
/* Constants for MD5Transform routine. */
" k) [# R6 R1 L; R& K + r6 t' F) Y! \5 `' J
% t) [' B1 q% p6 T#define S11 7 9 N# j# P, O2 D( c. ]# w
#define S12 12
# p' I7 H0 u: |; p5 }#define S13 17
! `) t0 I! e: `" ^; q#define S14 22
& a5 m* n: q7 F( u1 W, P4 T#define S21 5
" q( S0 ]/ Q# {9 P3 @#define S22 9 ) D% `! w9 R+ R/ M( z3 ]
#define S23 14
0 l+ y% a1 f9 N8 E4 S& ]#define S24 20
7 Q# K$ ~* j" o7 F$ b#define S31 4 . r) A# ^( X& J0 B; E
#define S32 11 + y2 b: _0 b. A7 T
#define S33 16 : _* }0 f5 K$ x, f5 ~0 P7 D
#define S34 23 % }5 y8 ~! M5 Y) ^2 [/ o3 P
#define S41 6 6 }" T! q% w6 U7 P5 N
#define S42 10 6 w- b( f$ [7 O5 ^- k% p
#define S43 15 , w% j2 N5 P& M
#define S44 21 : m1 y6 ]1 L4 v9 b1 J- L {
. F" t( R7 z# ?5 J2 j: Vstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); , z `' t! O* h7 P Y
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); # p6 n2 M% P& o- j
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 4 W7 }, {2 h% T! a0 z. @, k
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); " f6 ^' [+ O+ ^+ c/ N& b2 w) b
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); - c+ l9 l+ P" U5 r7 j6 _
. s2 @. U$ I# u* B+ P5 [$ I1 Z/ @5 P
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
- B0 i0 A5 j6 D4 g3 b5 x) J$ o}; ; {$ r- x8 c7 }
' h7 b/ v* ]/ n, c" s0 |/* F, G, H and I are basic MD5 functions. */ + ]3 g9 g& u: G2 j7 c+ ?, `7 q
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ; m. R/ b# Q, r0 H% G
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) - j! y& H' _# ~! `1 w- d
#define H(x, y, z) ((x) ^ (y) ^ (z)) 3 K5 U6 y6 M' ~! J5 W0 Z9 u! }% g
#define I(x, y, z) ((y) ^ ((x) | (~z)))
( t5 j1 Y j; G
4 x( }" J+ O p/* ROTATE_LEFT rotates x left n bits. */
& h% U5 Z" P3 R& U# N9 i#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) % `" G/ j' b |$ j
( q4 I- H: _( W& _+ X: N+ Q, h/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
4 @% N5 ^" g3 ^2 S' s$ p4 T3 i4 S7 MRotation is separate from addition to prevent recomputation. */
/ O4 \2 m0 S, z8 E#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 0 ~, q, N4 M; Y5 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); \ } ' K* i" d0 k; j, i/ f
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
9 z& U2 L2 i- F1 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); \ } 7 ]6 r1 R% T3 S# R, y' P
! @( K& ?7 \4 j/ L# l: u/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 7 P) R4 X5 U3 J+ E
void MD5Init (context) " v: d% L% Y8 d! {0 e. ^
MD5_CTX *context; /* context */ ; ?, ?! X' `% g, o6 D- W3 C# V8 j
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
/ U- T' L) J; b$ U( t# T*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
6 U' r" ]: I6 w. b" W} * v2 \* J) U* i1 X0 a
: [* M7 k% { O3 `6 c; o8 A
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
" M3 u" f. w' I8 q0 H, {( ovoid MD5Update (context, input, inputLen) 2 ^+ H5 H/ X7 |
MD5_CTX *context; /* context */ 1 {- V; t; R6 b
unsigned char *input; /* input block */ 1 G9 }; c( j. t6 P0 z
unsigned int inputLen; /* length of input block */ 7 X# f# z k$ @1 m8 v- G$ c
{ unsigned int i, index, partLen;
& i3 l3 y6 u& P+ } /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); . s) q2 m& K$ I/ X
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|