|
|
#include "global.h"
x% R8 A+ }( `: U#include "md5.h"
c' ~6 W" m& i3 B : F# [1 E. D) G3 x+ y# u
/* Constants for MD5Transform routine. */
% a8 N4 s/ L% F* ~& F1 x; w4 }1 | , t: k, U2 ]: t4 f
* c- h3 @' ~, @5 K#define S11 7 2 M3 V% d) p8 }+ o' }0 e
#define S12 12 4 d7 j% W3 J8 f' Q
#define S13 17 6 Z7 x8 q$ A4 V" p _" _3 F* B
#define S14 22 3 q, ]3 J; Y% r: X' Q6 _8 D0 ?
#define S21 5
- t, G$ A# E: ~, M( R1 ?* Q#define S22 9 " c0 V% {! {9 A9 {( k
#define S23 14
3 R7 B9 E0 K5 D/ C0 P4 i#define S24 20 : l; k$ D: L8 m1 B7 @: T5 |9 U, [7 O
#define S31 4 3 k3 S$ t. `4 d
#define S32 11 ' Z E9 F3 e; y
#define S33 16 ( d8 q' N6 w! c1 m" [
#define S34 23 ) G5 n' _7 f& u$ V
#define S41 6
, s! k, L! R0 z) M* f6 T( j* \#define S42 10
/ H6 ^7 L' l# ~2 t: l0 {0 v- \#define S43 15
9 A$ S% X) x6 A: C: A#define S44 21
3 g/ f7 i# N0 H) O' D6 ~4 v
4 d4 }0 P; K. i& R2 z4 o5 q4 Ostatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 1 n- p3 {; o4 d5 O' L; K# l
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); + K& Q, G: g; j+ m' d
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); & M2 O) N( w D$ X4 s0 `/ M, w. ~
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
' @$ C0 Q ?" q( B9 Hstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ( I2 W, {) K: @2 s
# ]/ G; N' o8 u; A
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 % N2 V; ]& {/ _" }
}; - ? s5 p6 j8 e* M- E0 Q5 ]
* F- D1 h6 `0 K# N& \/* F, G, H and I are basic MD5 functions. */
4 { s7 F/ }1 _+ J e% n#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ' I& r& t6 M8 }3 m& t
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 4 S4 x* b- F( u0 B4 t: s
#define H(x, y, z) ((x) ^ (y) ^ (z))
4 Q# F* @8 p0 G' L0 T#define I(x, y, z) ((y) ^ ((x) | (~z))) ( b7 l6 j0 H0 i' N
Y$ v. @$ h* P& p. j. ^$ A0 A/* ROTATE_LEFT rotates x left n bits. */
6 G) I( I' P+ Y' i#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 8 [4 o- E Q2 d: o! L& T. N
$ g1 _) V) a: ^, E0 n7 U/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ! h- a0 f, S' m( X. j3 O
Rotation is separate from addition to prevent recomputation. */ & U. n3 e3 u# ?+ A; G: z6 E0 y8 k
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } / g1 j2 M' M& }' m1 E
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
; L r( Q4 U" z2 S. \#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ; B) x! s; g! ?6 i' b$ i& V8 ~
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
$ R6 q5 q$ }' V9 N/ @* T% X3 J
1 B* l' k' n* u9 _: c" O1 j/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 4 P2 K. _+ K( J) Z7 Q
void MD5Init (context)
5 |# V' n, X& B1 B, I7 D# lMD5_CTX *context; /* context */
1 I- G0 H) k n0 a7 e{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
. | M7 @( z2 f- a; f*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 1 ?/ r3 f1 S% u# f* Z! d
}
8 k$ s" r' X, y$ P' P' d/ G$ Z) R# F
8 ~) |0 f" t' ^/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
0 b; }8 O" n' i+ @9 o( Ovoid MD5Update (context, input, inputLen) 1 H( J4 N, j/ U. o4 A, l4 t
MD5_CTX *context; /* context */
$ M' u6 o+ M) I9 G* s3 W, ounsigned char *input; /* input block */
. E2 X9 A% `1 g$ p$ D; x, I5 C Zunsigned int inputLen; /* length of input block */ ' l/ i- `6 }+ W% g3 W9 }. C4 X! B
{ unsigned int i, index, partLen;
2 b$ X3 R2 J; ~4 s/ ~ /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ' Y4 M1 B6 O/ f) B$ A# B
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|