|
|
#include "global.h" ; m( g/ g7 i! {/ d
#include "md5.h"
* I, @$ o x' @
5 e* t- R3 i& R" ], _ k4 g/* Constants for MD5Transform routine. */ # T: o! Y: Y6 ` }
% Q8 `: R, n2 Y0 z # m/ {( C! f# ]( _5 E8 {, U/ C ^
#define S11 7 " i0 Q. Y. r3 H: H: U
#define S12 12
4 U& ^, n. d# n- y2 g#define S13 17 ! }% ~* P8 j( O! P( w
#define S14 22
% ^. ^8 ]. i; v#define S21 5
& `! W7 a [; }* R/ V' C; O#define S22 9 4 {, w/ }* ?/ N/ C; z3 g9 a
#define S23 14 5 d" P; q, [8 l- D! H3 I& u) b7 |6 C) t
#define S24 20
& ?/ X! ~: K1 R. w( R' a6 }#define S31 4 9 S7 u- M- x/ ?+ ^. {2 E* r! n
#define S32 11
: J. w+ p5 M0 s5 f, a" q#define S33 16 0 Q; P3 T! t* D9 O2 I" y- \; c0 r
#define S34 23
3 ~" |* C7 O' {0 c- S/ l9 F6 j+ l$ x#define S41 6 8 ?$ M' ?6 r, {& L9 }" s* S
#define S42 10
$ m/ v+ g8 ?0 \% H#define S43 15
/ {' R# |4 D7 W2 W2 {/ [1 b#define S44 21 5 n: M" ]8 j. Q% _
8 @) y4 K# m. J. @+ C% a+ y: x) e
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
6 \1 ?; `9 K nstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
' Z" Q: q* J, b* s/ A% Z8 Vstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ( Q2 V1 g6 l- b( z# X9 [: \! R# l
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 0 U2 c( Z! f4 _9 N0 h% F
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); % |; G7 k% [& N8 L
4 h9 O! q2 E* h7 p3 Q! w v$ L' Ustatic 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 , w" [) Y! z1 r, D2 u
};
1 S- l$ P+ U# Y/ Y- ~/ `/ p
$ p; ?) P2 J$ `' s2 g+ E# W7 N/* F, G, H and I are basic MD5 functions. */
* D: M7 V* L3 v0 L1 ~0 I#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
$ i+ q3 S( x0 C) u( X#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
, _% N5 L( ^, S2 J$ Z0 ]#define H(x, y, z) ((x) ^ (y) ^ (z))
; P5 V: P E. N J' U. D% e#define I(x, y, z) ((y) ^ ((x) | (~z)))
! N3 A8 A% j0 |% U + t6 p3 q3 c5 o# U- G$ \
/* ROTATE_LEFT rotates x left n bits. */ 8 n$ U, `8 r. E3 F
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) - z$ v X3 I v* m. q% N
- l" S( z. B2 [4 y% V/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
9 K& ]3 }' K' e( JRotation is separate from addition to prevent recomputation. */ + r7 ?) w3 ^" w B: l2 Z
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
# R- r: n: t2 n' | n! x6 y#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, }! `7 M1 Z M- H8 P
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 0 S$ C6 C8 e' d, `$ v( N
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } * S! d& I$ @- J) a
9 L& a) S& C7 y( K: D/ P
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
; c n1 X- C6 G# bvoid MD5Init (context)
5 U' h( Z) z; V) QMD5_CTX *context; /* context */ ) a) S0 |7 _/ I' T7 y; q
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
. L8 [0 Q2 s2 s*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 7 O- d) K1 A& A$ A* ^# n( D; ?
} 2 x$ s$ R. B' @: z5 J2 l: z
! E& F: h- f1 a0 D) k( R2 y/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ & _6 v/ V: M6 l( ^$ h4 ^$ r6 W
void MD5Update (context, input, inputLen) E5 g0 m; J1 q8 _
MD5_CTX *context; /* context */
" d$ Y1 l* C" f, [' `" r( v6 P9 cunsigned char *input; /* input block */
2 C( R6 `! k4 H6 p- l5 sunsigned int inputLen; /* length of input block */
5 W6 @9 y ?7 ]9 r: B* w{ unsigned int i, index, partLen; 4 z8 H4 |% _# @2 c% X" h1 x2 V; ~
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); $ L) Q+ n4 Z3 _* V
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|