|
|
#include "global.h"
- v$ l' C2 p# R2 ]) B# C6 d* x5 r#include "md5.h"
2 G8 D: ?/ ?# l4 n9 Y0 h " c+ O! O d; A; D. q: B7 ?( c" d0 L% E
/* Constants for MD5Transform routine. */
# G, M$ P4 t* M& B! B , F. u8 r. W. M( U5 I
" l4 x: H4 s, l4 j4 Z% \#define S11 7
, U8 J; o; X2 T0 m( P' b- x# n#define S12 12 # k4 J6 Q: b p- c0 x- A6 V6 L+ h$ ?
#define S13 17 9 |( q* K8 @6 \. Z# x
#define S14 22
8 f6 F9 ?- p1 b7 T) k" K$ ^+ |#define S21 5 - m" @. G/ F1 Y9 s' ?/ ]
#define S22 9
b; W! S+ o) [ w5 ^/ Z; {: g#define S23 14
) E9 I. h5 c: A* O5 s5 N# Z#define S24 20 * B4 S9 n( P! p# ~: U* c m
#define S31 4 . Z, k. N* v( a: i
#define S32 11
- v% d% _; T9 @; W& B* I#define S33 16
* Q2 h) {* \; @#define S34 23 2 E ~! {2 v! J+ b$ j4 o
#define S41 6
/ A. ]1 C3 Q3 ~2 P) |+ {#define S42 10
9 c4 E/ ?* b% B; B#define S43 15 " ?3 L0 I0 S6 E# J
#define S44 21
' @* B: T" r* Y, r 2 H4 V7 @: }' ]; B9 }
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); ; W$ g" G! @! w: }
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
- c: D3 ]2 Z7 jstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 0 B( |2 a7 l F3 i7 n
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
" o% e. c1 r& P) n; M- dstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); " C$ z+ m% c/ w1 ~/ E( J
8 t% l: y/ X) P/ K9 _
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
: N5 u% }9 t3 G0 Q}; 8 N' \% Y6 b3 t2 y
9 S& l8 d4 e5 D
/* F, G, H and I are basic MD5 functions. */
% u; ?" o# o- u#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ! H) i) V' A4 @; A- T& _. {3 W
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
3 |6 y! G' f5 a% L8 x#define H(x, y, z) ((x) ^ (y) ^ (z)) ; p! }9 ^$ _4 z6 o4 D
#define I(x, y, z) ((y) ^ ((x) | (~z))) - k7 ?* v9 [& p9 R D8 @ I
* z3 m8 L3 Z, |& e6 Z
/* ROTATE_LEFT rotates x left n bits. */ : F ?5 b) d# h. p% i) d# b
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 2 c! t) [- D4 v- ~
. I; `' s# }# B. b9 U/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
X' m5 h& {" |( u; x3 M, pRotation is separate from addition to prevent recomputation. */
! d/ X( X$ e1 I" w! {7 U. Y2 Y#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 f/ J- a3 j5 C7 I" V/ _1 _% 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); \ }
! g* b* O( b/ w) ?" D! ^+ L( X! _#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 n. o2 k" L/ S#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
4 A1 _ `5 e2 b; v
) U( M7 g7 O: o1 e" v0 L) k5 A* y/* MD5 initialization. Begins an MD5 operation, writing a new context. */
9 O; {# ~8 T6 l9 jvoid MD5Init (context) / K3 ?' f0 r8 |# d* V* k" ?
MD5_CTX *context; /* context */
6 i# N6 I5 p8 `) Z5 s+ m" V% I6 W; d{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 8 K; n5 H3 w; B% M* r
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
6 x) P5 g1 }/ k, r} + {" g: I# g+ t) t
* w' Y6 f X4 ?: p/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
. v* [7 {3 Q- u( o/ K$ P: kvoid MD5Update (context, input, inputLen) % r3 v! q2 m' H) _
MD5_CTX *context; /* context */
! ~) q5 ~; A$ N8 `unsigned char *input; /* input block */ ( }5 Q9 x. d$ s* f8 ?7 q
unsigned int inputLen; /* length of input block */
2 A4 x7 y1 N* ~) u' a{ unsigned int i, index, partLen; ' J b/ B! j. s! |0 l" P! @
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ) Q" q8 k3 T7 ?
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|