|
|
#include "global.h"
/ \ w2 q9 X7 i) S8 {: I* x#include "md5.h"
0 _5 C0 G8 {' l, C 4 f8 ~) @& m. i# l1 n
/* Constants for MD5Transform routine. */ + r; l% r- M9 X9 Q7 M1 a
0 @4 t+ L- U) [/ i
8 r* W6 z* g H+ ?- ~
#define S11 7 " C3 N( R% ^. E/ t
#define S12 12
0 O; h. w$ n C& }% R#define S13 17
3 O* X2 ~- M1 R' Z0 j+ {- S0 d7 O8 L#define S14 22
& j6 z6 [( u+ u% c% }7 \#define S21 5
0 E+ O+ i, `, I& V#define S22 9 . i5 H! _- z' y0 d' f2 K/ [1 d
#define S23 14 . a |- c' Z+ j
#define S24 20 9 A( G' X3 Z3 L$ ]6 }+ h
#define S31 4
4 g" A0 v! `8 R3 W# H* t#define S32 11 # z" A& M# d( D
#define S33 16
6 W' P. x4 X4 s. y2 u- y#define S34 23
! c% C: i4 p3 S% `) F# H#define S41 6
s# Y v1 B' b9 L# o% H#define S42 10 5 `* W) ]* G; E3 C8 O. r m
#define S43 15 : _) R! d/ f# D8 A0 t
#define S44 21 9 b8 D% Z% O- _5 L+ c, U* L- I' W
6 \$ {( z0 k- b4 w( wstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); " j# G/ M; R9 u! U, Z: g% j
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); * I! g+ _8 n6 `8 I6 _$ s; p. E
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
' D+ u- v" G5 p: Pstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); # X3 Q; I2 T L, @3 Q! g2 ?. h
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 3 T& i& I- l* I F0 p6 U- p' P* v
; V% ~7 f! v9 G1 b" @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
( I+ N7 X5 v+ j' X+ ^}; 6 _1 {* w5 M6 @8 g6 {) A- S
! W% l' t; j+ M3 h% R
/* F, G, H and I are basic MD5 functions. */
- j* J" s# E) o# n' N#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
4 I h. c. J) j( O2 \) ]; a# J9 v#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
$ ^$ j: K' i8 p8 I: [9 X#define H(x, y, z) ((x) ^ (y) ^ (z)) , L; F6 ^$ K* @* J4 v
#define I(x, y, z) ((y) ^ ((x) | (~z))) ! g$ {' j Q6 u$ X& `6 K& {
) _7 h5 [3 _0 @& b5 p6 G7 V# E/* ROTATE_LEFT rotates x left n bits. */ + p$ Q# J" F1 w% j1 L& B1 J
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
. _( E0 L2 R+ B1 t ) ^; L6 t" q5 E/ C
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
4 n' ?+ h/ ^4 X3 f3 VRotation is separate from addition to prevent recomputation. */ % ^. y# e. F0 Z- x; Y4 p
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } a8 O8 ?- m' O0 G# a7 d
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
: J* U6 f" z0 B9 g9 H8 J#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ( K j; B6 D& H( z; z9 a4 ~& ~( A
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
; |6 l5 E' @4 M) y. C3 \4 t( D 9 Q4 Y# q) _4 e) R' L
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ " _$ c2 O7 y2 d
void MD5Init (context) 0 m) l) s$ d2 U3 _) U
MD5_CTX *context; /* context */ # @" B, |8 Q: q
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
( h6 [$ O2 B4 I4 A$ {- B*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
) H1 O" @. H( |. n. d} ' s& Y l y% w5 ^* J
. K% P4 j+ e m/ X& n6 Q! h! J
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
8 }& _1 Z0 o7 n8 G" Wvoid MD5Update (context, input, inputLen) ) i' ^3 ]1 [) S3 S
MD5_CTX *context; /* context */
; X4 G1 w! P% D6 @7 ~unsigned char *input; /* input block */ 9 O# T5 I6 m& f3 ?2 _
unsigned int inputLen; /* length of input block */ , G. J( u8 F W3 j5 `( A1 K
{ unsigned int i, index, partLen; \( E5 U0 D2 t
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
, T7 P+ D* d2 n( c- W- Y G /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|