|
|
#include "global.h"
# G+ S2 ]5 x \8 M8 _4 a+ d#include "md5.h" $ e) g! D) L0 o8 `! D7 l
# p& N# `! ]' O7 \: c
/* Constants for MD5Transform routine. */ - ^& P6 r# a* l1 h7 X2 g" H# c
$ m$ ] D1 b% f
' q( N( \+ R$ g1 z#define S11 7 ! L! N" @; T K
#define S12 12
. X: R$ d2 Y; e- Z" r#define S13 17
r8 Z4 P- W3 w" l" I" ?/ ^: m#define S14 22
7 h0 N2 I: R. b: E# k8 J3 t#define S21 5 + l4 w& K' b8 D+ f! M
#define S22 9
% X) g9 V) k5 Y$ e* Y$ D5 F#define S23 14
: E" @8 l S+ Y4 R# ?) n; q1 l#define S24 20 / i7 {4 } F# T% j( r0 U1 u5 B
#define S31 4 4 D8 B0 K0 i* ?
#define S32 11 2 K0 x, G2 O: l8 W0 Z
#define S33 16
' O0 w) u3 I: u' }1 p5 I) ^#define S34 23
6 E5 e( o1 w. G! o5 v! {& W3 Q#define S41 6 0 [% O; I: G4 \- F
#define S42 10 / `! X- B* \3 H8 \+ U" }
#define S43 15 6 K8 i! y" i3 T! J5 a
#define S44 21
: Q$ T9 Z3 v1 g# q. Z. {, l) V
3 C5 S' u; o' @+ M( W( w, F2 a/ Fstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
% Q" E( m2 @1 Z: D% Q5 s- fstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
# w3 C: }* U6 p4 c7 c9 E P5 pstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
# A$ H- h% \; M# istatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 1 O8 ?( E+ ?0 p
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
; D5 j. `4 N% G+ _; x, Q$ e( E* Q
. ?0 D" }5 d3 X* i+ p0 h' |' n+ Bstatic 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 * e, _; M2 ~ B( g9 x. Q
};
! ~. _: _8 M7 b( q* d2 D3 l% T' {! |" o ! h) k! n9 X# z$ R, z, F
/* F, G, H and I are basic MD5 functions. */ 5 h+ g h; {' G/ z
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
3 P. H- V! g" {, a3 f; a+ `% Y8 T#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) , K: P' Q$ z" D: G6 ~+ ]
#define H(x, y, z) ((x) ^ (y) ^ (z))
# y' n5 y e' R8 ]#define I(x, y, z) ((y) ^ ((x) | (~z))) * [' u( h# W' j; v+ B4 O/ c
) @! {4 [ n) d, H3 J% X Q% W
/* ROTATE_LEFT rotates x left n bits. */ ) Q" K5 l+ d p6 s) t( R2 ^6 q9 f
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ! c9 q6 [: H6 l: K9 r2 }- U) h9 `
# o5 r2 n" K7 Q2 h( o5 ]/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
/ a( Y: v3 e3 W- ]Rotation is separate from addition to prevent recomputation. */
8 ?9 ~" ~, Y4 {6 W9 A#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
* @* |# c. e+ q- o' G#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 9 G3 v3 m8 G" @/ a$ N) m0 t% Z
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
7 Z+ J2 W: z. e/ b0 t7 ?#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
5 I" A# w# c5 M- ~( s8 N* d7 O
% }* u* m# r/ q. m$ j& r+ y/* MD5 initialization. Begins an MD5 operation, writing a new context. */ " |3 B5 n3 `) F/ E! L
void MD5Init (context) 7 F; H% h- \/ a# E( g! ~0 \7 ]7 `. L
MD5_CTX *context; /* context */ 6 C- ` p* z0 i; G9 a
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
7 n6 [: f2 R; ]6 k8 [*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
2 U8 T5 _' Z) m# s} : n9 H! ]( l% q
" t/ k; ]' a( Z. s/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ . `* a! L/ ]* b1 D
void MD5Update (context, input, inputLen)
1 G4 \6 V: S/ `1 Q6 r/ |MD5_CTX *context; /* context */
. }# v3 }, n R* K4 kunsigned char *input; /* input block */ ; U5 m7 G! N! G" e0 v( h1 ?
unsigned int inputLen; /* length of input block */
6 ?! [/ I& P; Q5 o* B( n; G f/ c{ unsigned int i, index, partLen; * ?+ U" p( k. U/ C% A1 A9 W
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 0 b( P* S' K: v+ b! R% L1 @
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|