|
#include "global.h" & r8 G8 B/ z* ~ a) P$ z
#include "md5.h"
" I# \5 r1 e5 `8 W$ N 6 s \1 \+ B3 g! V5 n1 G
/* Constants for MD5Transform routine. */
! {1 m* e- U% R: k $ |2 A& L8 X: T9 `
! J) S1 g& b" Z
#define S11 7
7 J9 S3 G1 t: v( `% \#define S12 12 . R8 D' [7 R" g. S: g
#define S13 17
( f; G: E2 G! x#define S14 22
5 t) m1 a4 T& u2 X5 H7 Q#define S21 5
% r9 D1 w. Z( a3 k% M$ S#define S22 9
! T% y7 M$ k$ w0 |1 V8 g#define S23 14
9 O' b3 E/ h$ B5 @: q9 l5 T; }' ?#define S24 20
6 Q0 @! l4 G8 C2 P7 J#define S31 4 6 Z: L8 I1 B8 `) e8 }
#define S32 11 1 J8 m+ P4 I+ k0 S: A- ]" [
#define S33 16 0 I: ]; E$ o- u# {# A
#define S34 23 6 |4 `) ?+ D+ C+ e" L% @
#define S41 6
+ C/ q/ j, O$ P4 u/ l#define S42 10
( }0 v& A/ f& Z: m) w @$ t* q#define S43 15 ) F" I6 K8 B$ |+ L( O3 J
#define S44 21 5 R/ y# J, R" _" T' n, f$ K2 {/ f
) x9 W/ D, _0 g- [
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); - y& ]' `/ w3 s& b4 ?. Z9 ?5 B
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
e2 l6 k; C \* S4 Lstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ' O2 `, M- |* O( Z0 q, v/ b
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); $ _9 q/ Q$ k+ j I" a/ ^
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
" }% Y/ ?; Y9 r+ k+ B' r& y, } W
% q# W7 h4 T$ J/ r: @# q+ ]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 1 C9 l# v7 U! K$ ~% C8 I
};
; r+ B L4 ^- g6 W ( h/ ?2 ~6 ]: q8 s: p0 M
/* F, G, H and I are basic MD5 functions. */ / B9 ~3 B) v _2 |7 l; I7 n
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 4 e k5 P& L* n. n3 V7 I8 {+ e
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
1 L+ H% v! q2 j: w l#define H(x, y, z) ((x) ^ (y) ^ (z)) : M1 [' y2 l, H3 ?
#define I(x, y, z) ((y) ^ ((x) | (~z)))
. C# Y& T% X# V% L( ~% i9 z" v2 e6 \' ~ 7 y( y! s! o; V$ ^& }
/* ROTATE_LEFT rotates x left n bits. */
; Y$ T3 y$ ?0 j6 | ~; e' n E9 A#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ( O+ `1 r% |& M! g7 V2 D
: N* p0 ?& u/ [' u. d1 M% ?/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 7 a, O8 m: o5 r1 k% u
Rotation is separate from addition to prevent recomputation. */
: }# `8 S# B. [* I8 c#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } / H: [5 W5 Y8 `7 f' U! B* U
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
5 v# Y6 B" M! g7 E#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } " P* R/ z2 q, U8 v) f6 F$ f( ^& q
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ O$ h: S \2 n3 H7 ^ " N7 j% p: m. |$ V4 h6 y/ g
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
, a K4 o1 P% \void MD5Init (context)
5 I& p q6 }" v- U, E' z% r' u. ]) wMD5_CTX *context; /* context */ ! B" ^3 n q9 e* _' D
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
7 j0 K0 G" b6 Z% I% |. w; j) m*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
& K8 D( B* n- L9 h3 U}
9 T8 \6 ~0 Y4 P
( A$ a0 j$ g1 j; B# k+ T/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
9 c; i6 b& G( n% J: D; F; Bvoid MD5Update (context, input, inputLen) # I; k z% c- [) T* w
MD5_CTX *context; /* context */
3 u5 e( E- a$ x. N% }unsigned char *input; /* input block */ - A- a `2 c7 x7 v( F
unsigned int inputLen; /* length of input block */
, G9 P' J3 h" a3 ? u- W{ unsigned int i, index, partLen;
/ j0 y2 C* m# e# g+ j8 p8 X /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ' @ p" j/ G% y' }( A- M1 V& t4 D
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|