|
|
#include "global.h"
! | O) m' V+ D6 a#include "md5.h" , z7 Q2 _/ U0 X9 R) G
; l6 _! Z" q( t' L6 D- k
/* Constants for MD5Transform routine. */
9 ?- z; E' z8 D Q" B0 B! j# M5 H ' l }7 T4 w% x1 A1 Q' b8 M
; A4 m2 k% _& ^0 |, z8 w#define S11 7
* n+ b. w* d7 F0 N0 q#define S12 12
4 X* i2 e$ F& X9 u#define S13 17
5 O4 m. T! Q% J% \+ K#define S14 22
) t4 \( y# s" b+ X0 W#define S21 5
, J$ e' F1 i) T8 F$ v$ ?#define S22 9 5 q8 Q9 P& k, Z4 P
#define S23 14
$ y, C( O+ @- x#define S24 20
( |9 H5 j! T( U; s2 w' J#define S31 4
5 a. G4 T. J4 f#define S32 11 3 P# `; Z2 G. {1 @6 [4 P7 h
#define S33 16 # V) X2 B6 `$ K5 J+ g& n1 z! |
#define S34 23
& U. r+ C, F2 _7 o' n$ r3 W$ ], X#define S41 6
5 l! D. Q1 f$ q& `#define S42 10 + U; D# M& X. ^% Z% `4 r6 h4 T1 L& ]
#define S43 15 0 d1 Q3 n. @/ ]% a, O2 a- E
#define S44 21
# B% j9 b' v" \/ K7 V% W& G 9 r& r+ ^+ E+ |+ M. f. J
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); ' t9 e" }0 H$ \- \7 C6 k4 [
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
3 m+ a) b+ Q, T! Z6 f/ Ystatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
4 J8 x- T2 u# N; ~static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
8 e5 S- E' B) N" C" n- g" mstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 9 r+ o+ |! @) \0 z
B( o" P L! d U& w6 ]# I+ L jstatic 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
- \! _4 j: j5 g};
% {3 q2 ^; z( U" w5 v0 H$ c0 e . @7 R Q6 i0 ?+ a
/* F, G, H and I are basic MD5 functions. */ ( C7 J' X2 Y+ x% `
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
& X7 M- m# W' |5 D; B: y% y! Z#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
2 L% V1 v0 K4 F% o" N- O#define H(x, y, z) ((x) ^ (y) ^ (z))
; d+ J$ X J& Z#define I(x, y, z) ((y) ^ ((x) | (~z))) 4 b/ l A/ T/ n4 |' L
4 l# |" l H0 j1 j/* ROTATE_LEFT rotates x left n bits. */ % p& s0 ?9 W4 r& D; k( H, z! R
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) - l& Y( s! U# e# g6 l6 `! D( {/ Z
% e% P$ f) O) `, T/ O# U/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. $ R* G3 S3 C6 E9 \
Rotation is separate from addition to prevent recomputation. */ # R5 N3 h F$ b
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } - o3 ~7 [0 C7 }2 r7 P
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ! e" v. a, c& c% [$ p; A
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
5 x$ S+ {! B1 L( _; l/ I#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ' u l% t4 O4 t1 M0 J
9 }2 E4 \- s& R( E1 w" k
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
n% S7 ]# ^9 Bvoid MD5Init (context)
- r. @! `( K4 Z: TMD5_CTX *context; /* context */ + w8 x% y% f% D5 m
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
0 n( b9 T" h2 h( O& [1 T. t. x*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
0 p4 F, u/ O, d b}
7 h4 r, w v4 H Z* X7 r
% ^$ c% S$ I2 h5 F5 Z; {" {9 @" u/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ $ V; M- G* ^$ J$ A* c5 S
void MD5Update (context, input, inputLen)
5 Y/ R0 \. H J5 o9 M% }. GMD5_CTX *context; /* context */
+ I3 N3 X, A' j. ^9 Aunsigned char *input; /* input block */
2 G0 Q2 e6 i. N2 ~unsigned int inputLen; /* length of input block */
( ]. W% T8 A& m$ K/ o+ @3 |% ~{ unsigned int i, index, partLen;
" R4 M9 L+ }# p /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 7 ? ?; v. v1 j% ^, b+ e2 W( P+ j
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|