|
|
#include "global.h"
0 n1 p A$ x) z#include "md5.h" . \2 y- x, X7 f9 A: B7 J
Q/ ^, S7 r' ~3 F
/* Constants for MD5Transform routine. */ 1 N9 i: H* V% V. L; B
( q! R4 O# o; H1 ]! E
Y+ u: o! Q6 G& F0 ?- R#define S11 7
( Z8 N" f& ~ E1 Y( E% f: w#define S12 12 ; D( M. l( \+ h7 {- T
#define S13 17
6 A. w) P/ _8 S& e" }: j! \6 N' y/ u9 }0 V#define S14 22 2 S# m# O E) a" C1 E% i% { L
#define S21 5
5 u# p9 a. F0 M1 g#define S22 9
+ ^2 g9 b' j0 E$ O4 i#define S23 14
* z' [0 T& }7 d. a1 y. A! ~1 w#define S24 20 4 A, Y* }. B* W: v! b' q& o& {
#define S31 4 % ^; u( d* f7 N# d: g; N8 Z
#define S32 11
1 n, s$ X) L& H1 B0 \6 k" T#define S33 16
; K' V" T4 F4 [7 B$ v#define S34 23
4 z( L1 ] f. m( J0 |2 o; Q#define S41 6
3 G7 j o0 b, l#define S42 10
4 {/ A: L# u! C8 V#define S43 15 8 j4 U2 ^+ u+ k1 Y
#define S44 21 ; z/ j, @0 C! k+ w$ z
3 I6 U8 {; B. ]/ H" C( \7 `static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
: o. V: \% i' R$ Qstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
- c: p- m; M8 l( I# z! A0 L4 rstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
$ m' U0 W1 C; t8 }. X% ]static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 0 ?/ \3 y+ Q, T3 ^- R
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
/ \2 {9 n% P' l+ r0 S! I
. h+ |2 V) `5 a8 t8 vstatic 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
" ~4 e% {2 I( [3 g/ I k. k( Y};
& N! U# e5 ?4 Y2 S% Z 8 e1 C) x4 v4 e- n, `$ \
/* F, G, H and I are basic MD5 functions. */
. ~9 O8 h% I7 g#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
( |& v+ Z) i$ M, v- y#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
2 K9 u6 |% `% @. l# E5 t#define H(x, y, z) ((x) ^ (y) ^ (z)) ?# ^6 j9 c3 D- L
#define I(x, y, z) ((y) ^ ((x) | (~z))) # E8 v1 {! t* F% m
0 H: T( `, B, S8 u
/* ROTATE_LEFT rotates x left n bits. */ 5 }0 f7 A- `+ v, D- P$ T
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) . j- u0 G, N& y* u, N* y; |
6 r: C1 ~) }* P5 n J( W/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. + ]# h) n! ^6 T8 h$ J( m
Rotation is separate from addition to prevent recomputation. */
T, x" {/ q8 r( `6 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); \ } ( c% `9 ~7 ?( W7 b. @2 |# q' @
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } * m5 W4 p' N0 A, V% \$ m. 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); \ } 9 E. U' b1 h- _6 u& ?1 L
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% X* h/ b3 i( b* A4 K( l L! X' B5 s$ {# T3 O0 d; i
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
. R, x8 L$ F# mvoid MD5Init (context)
: a5 a. D9 i+ W: x, LMD5_CTX *context; /* context */
! T- H9 O) t3 W0 t0 F% |. L4 D{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
, R5 R" u/ |6 M2 j* w*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; $ n4 W" ]( Y& p: B5 u3 M
} # X, B" Y+ I6 d. i6 e
3 A! z3 c# {+ f
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
' e( f* @/ P ^! pvoid MD5Update (context, input, inputLen) 7 J2 m+ `. S1 j9 s3 b$ r# z
MD5_CTX *context; /* context */ / B% g9 O9 Z/ ?+ j1 [
unsigned char *input; /* input block */ N* {1 ]' r8 Q O4 M0 X8 L ^
unsigned int inputLen; /* length of input block */ ' ]4 L( V- f/ x* F3 I
{ unsigned int i, index, partLen; $ T4 y+ }; w$ D
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
1 u5 r7 Y6 p! O K8 `3 t( h1 ] /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|