|
|
#include "global.h"
6 S) p) f% ~$ b( N, U0 ]# A#include "md5.h" # V1 X# B- H) c! Q
9 b; Z# t K) p1 b4 u9 X; R
/* Constants for MD5Transform routine. */ 7 T2 O; k8 b( G* W! |& j
% n- X' l X) Q. g2 \# ?. ^' _ 5 g# z; C. }: g
#define S11 7 w- f; [3 S Q
#define S12 12
/ V# Y3 L4 e4 ?5 H3 G#define S13 17 w6 I( D2 A! M8 K
#define S14 22
) K+ u* m$ I/ Z/ F#define S21 5 0 a7 {0 ^( v; B/ U
#define S22 9
0 J4 l- o8 c9 {+ }" e! n& _5 |7 D, B#define S23 14
2 |* \' E$ n7 C& @#define S24 20
" N; I1 G3 S1 g, ]#define S31 4 ' M5 `- d& x- j$ Q3 r
#define S32 11
4 T% W7 c8 e' [9 ^. f& t#define S33 16 3 |& g2 h. b2 n7 U" w, ~2 m7 T
#define S34 23
) ^# _4 }- F7 S- d#define S41 6
- Z: G: B' O6 t0 e9 u2 B& C#define S42 10 # ?# H5 A$ W" j, N. s j" c4 q
#define S43 15
, j& j4 _7 U5 n#define S44 21 . a" G q! t/ P/ \# u S6 a3 f
4 h o- p6 R) G% \static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
, r, P8 j7 \) Z# C) S4 j' Dstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 1 A; d' G* K$ g5 p' F3 \
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
- s) Q ` T4 |: U6 y3 rstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
9 D5 e- f, ~! ~2 jstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 0 x2 e# h8 J7 p' u. {& V
7 v& ^' l6 f7 F0 C) c( L
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
; U9 D: m6 {8 Q9 T4 s+ a* S! E}; ! ]8 A: I% u5 |! ?7 G# i
6 m$ R' Y8 r/ x+ x$ a/* F, G, H and I are basic MD5 functions. */
. y' r" B# R4 ~& W6 u2 r: a#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
5 w# Q5 i, A6 v, p#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 8 l& I; N- R, H0 v0 ]8 }4 D, o
#define H(x, y, z) ((x) ^ (y) ^ (z)) , p4 j( S o/ T
#define I(x, y, z) ((y) ^ ((x) | (~z))) ' ]3 H$ Y1 A& [/ j5 a3 |
: ^8 N6 C4 t1 r0 _" X
/* ROTATE_LEFT rotates x left n bits. */
7 D* M5 Z$ v. B. _$ ~% n$ y0 g ~#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
' } `8 t5 x# v ; [5 S1 e( M7 o: L$ l$ y# C
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
' W- i: @+ @! `" L9 D7 O/ ?. CRotation is separate from addition to prevent recomputation. */ 2 h' e5 o3 X& M: V$ r2 L
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
; D- S9 Z9 ?2 Q! x, t) C8 g0 `/ 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); \ } # V* d7 ^2 U" y0 B9 y+ v$ c
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } , V8 w/ W' H( e( p) e; V
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } : `. N! J+ s) D
' Z' `1 B, O+ v, `5 ]
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ + D; L8 E: r. s+ |( m# H/ N
void MD5Init (context)
) [9 i' \4 n$ ~! m, u+ r" GMD5_CTX *context; /* context */ * R1 ]/ `) {" B* c0 u* j% A" K
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
8 |% D$ T0 t, H! H; y*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
& n# W* G' H' n, x6 S! b1 T" I' G} ' h& l- G/ M2 n3 B: Y9 I6 Y
. a' o3 T! G3 B: C' Z5 i/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
. e- V7 a; W+ |& i, qvoid MD5Update (context, input, inputLen)
1 ]2 ~0 t2 s* f2 F; GMD5_CTX *context; /* context */
& a, u( R% `' o/ E2 X0 ?5 Q$ C, ~unsigned char *input; /* input block */
8 F ^2 g. V+ T5 r8 I" @8 X6 s) yunsigned int inputLen; /* length of input block */ ; k" ]7 ]) q9 x7 c& I" F
{ unsigned int i, index, partLen;
$ ^) w9 _5 A' ~9 T- R8 D2 n7 t7 s, D% ] /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 1 u% P3 S( ~0 X
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|