|
|
#include "global.h"
% O0 G& w+ l O#include "md5.h"
* R4 p4 b0 w( P$ P! v9 x/ J" T' o+ h ( p. V9 `4 R K+ U% r! E; ]
/* Constants for MD5Transform routine. */
9 w. u( p. i6 {: I / ^4 N$ k' j5 }0 d! c a" O
, Y+ n$ K. o4 j; d& Y2 B#define S11 7 0 s* v6 @( H+ [) U `- n
#define S12 12
3 i1 q. E% r- }#define S13 17 7 e7 T+ H4 l2 L' x$ b! z. t
#define S14 22
7 k! x2 Q4 o d" m- Z- W$ W* \: w5 b4 Q#define S21 5 ! R# r0 i; M8 ~& X1 x3 L+ }4 K; H
#define S22 9 , D3 V. F. Y! k
#define S23 14
. c6 O+ N, j) }& v" y, V#define S24 20 ! r. E% D. C7 ?/ ?
#define S31 4 6 {; ^( n# i/ B$ j0 g0 C
#define S32 11 4 R! u J" o7 f
#define S33 16 ! G8 b* V& ^- x+ O
#define S34 23
' ?& ]& h/ C4 e" L+ P6 [#define S41 6 # ]) `* Q2 {8 ?- Y# u. I
#define S42 10 + d$ C b! h0 x: H0 ]; }
#define S43 15 ; t$ O B# h+ G$ S' M$ u
#define S44 21
2 P+ }7 S4 s4 r2 i$ P5 l
* v4 g, F& R4 X* ~static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 9 X3 r* Q6 A8 C, @/ p+ X
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
5 Q& P5 \+ v4 M$ ^7 ~- estatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
) E0 D1 ` s" g. C. y6 P1 Sstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 4 U6 X& }5 _) I9 u1 n9 ?. W B$ H
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); & ^ J2 m+ ^$ d6 Z# t0 p" P
: j/ s0 Z, v1 x2 B4 c0 C" Estatic 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 1 t5 r3 l' g( t( C3 Z, R
}; 8 w+ G- h7 }+ x! U, f+ |
! v* I2 @5 D5 ?7 j p0 h/* F, G, H and I are basic MD5 functions. */ 9 M3 z0 O+ L/ t4 x8 W
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
- ^/ t0 _# [" s" \/ s#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
* ~/ t: i! T: x! V% [9 R a0 P#define H(x, y, z) ((x) ^ (y) ^ (z))
) G: Z* [% A! e8 ~. D( M# y, t#define I(x, y, z) ((y) ^ ((x) | (~z))) + @5 Q8 z4 e) }$ G! h( T2 C
( M9 E9 W& I t* E, i7 V
/* ROTATE_LEFT rotates x left n bits. */
9 a z2 \( k* ^' c#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 8 d: t7 A$ ~9 a% q( Q8 \) G5 K* P5 N5 I
) `# a5 u' N( A3 b+ b+ V
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
$ w2 z! [5 ^/ F% W6 _) WRotation is separate from addition to prevent recomputation. */
, d+ n2 ~, w3 [& W6 v#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
v; R) p+ z. z2 J2 E0 Z#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
; d1 \! K: {0 w$ b7 v#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } # e+ p: V5 N0 Q& U3 \; F& C) r% {
#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' K/ f, @9 R, J( H0 p5 Q2 d+ w % p0 {" D7 h9 f6 V) C& P: R
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
7 p+ P# X* k. d2 ?) `void MD5Init (context)
8 X* M' `/ L) \4 K6 @& \MD5_CTX *context; /* context */
6 D5 P* @9 k; o n0 W- E{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
- U. B9 i; N; H8 a U |/ b: u, H*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
5 c b/ \( S8 S0 O9 \ q} ; Y- L, A- _3 B, ^1 d
* k U. e! J: e/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ $ ~" ^* S4 ~" m
void MD5Update (context, input, inputLen) : A* ?# m; I4 v! o. D5 U
MD5_CTX *context; /* context */ . y1 R7 N( n- u4 J# t1 M
unsigned char *input; /* input block */
: O' K0 Y- X7 ~2 @- Bunsigned int inputLen; /* length of input block */
% f- T6 M2 R) L9 Z$ `{ unsigned int i, index, partLen; . N t3 `5 G% N! v5 W
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 0 [3 E3 C! d) V/ k4 H y& ~0 r
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|