|
|
#include "global.h" / G. Q$ x6 W+ i+ W" A) l; D3 }
#include "md5.h" & J& ]0 ?5 j: m0 m2 o( R' P4 q2 C
& d6 k6 k) z2 a" w3 j9 b
/* Constants for MD5Transform routine. */ , |7 E, t, U# |; B$ @; D
2 k4 r$ W7 }% A" ]/ w2 ~- P" L
) G+ h- E8 t5 T#define S11 7
) f" I& d% r+ S% b4 I#define S12 12 # t% U. d+ z) K# e
#define S13 17
" [& w+ g% r/ Z* `#define S14 22
6 V1 i1 j9 c0 ]3 L3 e# v, L* l#define S21 5
) Q2 L2 P$ a6 c3 E. s* k#define S22 9 n/ s$ j3 L2 z, C. F4 }: T; T
#define S23 14 ) B% ^" u, m/ O M
#define S24 20 ! }7 |7 R& K* K. g3 l9 D
#define S31 4 / t7 y' z, j% b" Z! U3 y8 w
#define S32 11 + A$ P' S5 Z9 W& x% \1 Z6 ]5 `9 ]
#define S33 16 & Y. p' o, @ V. N9 L/ [
#define S34 23 ) F6 M1 i- n6 L8 ?
#define S41 6
+ c5 |. g' H1 x% l( |#define S42 10 / c' U4 U; r8 O! v9 T% P
#define S43 15 1 x a Q# }' w( q, O
#define S44 21 % k& q, p0 l. a, x* q) U5 T1 C
6 _" c1 ~) Q3 S/ L$ _static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
/ T% i% k, l" A: j1 x0 \static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); % D H3 s) ~4 e5 n t5 E' W
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
, r( _$ c4 ^5 `7 P# P8 I( Ystatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
7 A, f+ w" h( [) Y7 ~7 L- P- bstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); * G3 ^9 ?( k, I. @& W
8 [' I% [. A, T) \+ [ X- J9 jstatic 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 7 B2 v, R) [! r Q) W' u+ r1 z- n. I* \
};
9 U- r- ~; H0 c' |# n; Y1 u4 R
3 u- q/ k' h4 f% J+ {2 v/* F, G, H and I are basic MD5 functions. */
3 M8 u) U% G4 {; f$ R7 s% S#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
. G, Q; \: O! `; E#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) * d( u3 L& u; n$ d/ `
#define H(x, y, z) ((x) ^ (y) ^ (z))
, w" d) I/ V# Y+ L- p#define I(x, y, z) ((y) ^ ((x) | (~z)))
0 b& v6 O4 m. M3 I1 n
: F1 H9 {, N/ n: [& Z/* ROTATE_LEFT rotates x left n bits. */ ( u/ k0 X0 ?; H" @3 J
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
- _% E8 N8 l, y' G+ e ^( v4 y . X: O6 l& l9 |, F) O7 |6 q
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
* [0 W9 w# g p2 hRotation is separate from addition to prevent recomputation. */ * o. u& l, t, q! R/ p; F
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ' Q7 p- j0 \& [" `, g/ Q7 F
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 9 I9 g# T3 ?% d% n% n- Z# {: j
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 9 F# j) p6 T& ~+ k$ 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); \ }
# P' T7 C4 d# @& \
$ o+ {+ f3 a @/ O! A! u# t: L/* MD5 initialization. Begins an MD5 operation, writing a new context. */
! M; m+ t& t$ Pvoid MD5Init (context)
t/ F" M, m# S1 `8 {9 a0 L7 ~MD5_CTX *context; /* context */
! r. F7 T1 c: Q; A8 Z" _2 |{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 0 o2 X1 S5 s9 x
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; / @5 r# @9 c0 C! i. \
} . k$ m$ f' k$ D$ P J) l* f
# f9 `9 [! J. m. L6 s. I% H/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ ( x% E, _3 K. G
void MD5Update (context, input, inputLen) 3 I& D" r: D* @" M1 ~7 J( C) r! R, m
MD5_CTX *context; /* context */
. _% @! M: M+ I3 H6 Kunsigned char *input; /* input block */
. j9 M1 |1 O5 f- @ hunsigned int inputLen; /* length of input block */ 8 |+ I# `9 }5 E B3 t) o6 C4 q& M
{ unsigned int i, index, partLen; 1 v0 e% m7 c$ P9 p7 z
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
, Q/ g0 k3 l/ P% M" L /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|