|
|
#include "global.h" ' I6 ?, e v. a) F" [- x
#include "md5.h" 6 Q8 g9 E$ d# [2 X4 S
& k( ~* R8 A) E8 T3 h
/* Constants for MD5Transform routine. */
1 b8 T& K3 j6 _- X9 Z 2 p1 z$ Y( W. I2 Y
P2 K) T3 k- a( j/ P#define S11 7 + W1 e6 T( p% N3 s
#define S12 12 4 K/ b; i* Y% a) T) A9 w
#define S13 17 7 v+ r9 ]5 l) r1 J
#define S14 22 " Q) o. p0 c9 {* o0 e0 Z
#define S21 5 ) s# v z% W3 o, i0 Z
#define S22 9
% {1 M! O, f2 N#define S23 14 + |# E; `. N3 L9 D* @$ ]: M* w
#define S24 20
@ A9 a# r5 x3 K! h- f#define S31 4
+ U- s$ S. V9 b: G2 R# h#define S32 11 ! o% `% ~! p( E
#define S33 16 4 @# x) N/ z& y" D* \0 [
#define S34 23 6 {! d$ C7 x8 \9 n5 U$ O
#define S41 6 # W: t$ p' J, I7 ~5 l' h9 A# ?2 }
#define S42 10
9 c% d$ E# _" k/ ]0 |! h) y5 z2 n#define S43 15
$ U6 j+ f1 j) J4 w8 S3 ~#define S44 21 . V3 b) D4 h0 d# R2 ?
0 J0 O3 E) H2 b) |static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
! K3 J7 I M- |static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
# W4 `$ J$ K7 K5 T2 s) [static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); + ^+ I# A0 x3 _/ j* V3 w: W' J
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
- _) C9 ]! y2 A! h1 Nstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); # B! j1 I: |2 ]& ~; v, }
8 F% y8 |- k, Fstatic 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 N- F) V1 d" z4 |0 D( y};
) x/ ?3 c( b, P ?) I
6 ^ a6 ]0 E Z+ @# k( {/* F, G, H and I are basic MD5 functions. */ 9 Y z3 u2 {: a
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
1 H9 H$ a, r1 Z4 |5 j8 t. L#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 5 B* f4 T: F f! ]; f7 Q: c/ Z5 N
#define H(x, y, z) ((x) ^ (y) ^ (z))
! L% ^4 i ?% f% Z1 L3 f% _. @#define I(x, y, z) ((y) ^ ((x) | (~z)))
- s; J' b7 y) K/ |; N : Q9 D, I7 [. P4 l9 G) [7 l
/* ROTATE_LEFT rotates x left n bits. */ - f$ \4 e4 z2 z
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) $ v B' g& e" S0 n. E! ]* g0 l
' @. ]2 E" Q) D" ?( c; B
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
7 q, R' E% n1 d* |Rotation is separate from addition to prevent recomputation. */ 0 R- R2 R* F4 u# I0 x. {
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 7 Q; i, w. r) I% \. R) J0 A
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% r/ \: n: ?1 ]% `! p#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
* y9 B6 Y0 @9 g) I [, 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); \ } 9 L, d$ z- f U% a) `
' T/ R P# O' r: P" U- L
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
: |6 J; [, O; f4 N( m9 ovoid MD5Init (context)
0 s" m: J' i, ~) g% U+ a: FMD5_CTX *context; /* context */ 9 S# m7 x0 v% b; m2 V1 V
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 5 \( D* I( t8 K7 z( D6 B0 r" @* B
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
* B, \$ A; T, X E( b" I: Z} : J1 y7 }$ d. ~+ g
/ W) B/ D. n: |! R+ x. A
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
8 d+ Z" n: u2 ]; g2 v0 cvoid MD5Update (context, input, inputLen) / c( E) n h* B" l6 z, L
MD5_CTX *context; /* context */ 8 _9 [. j' D" `: G
unsigned char *input; /* input block */ * J% N. d2 Q! \
unsigned int inputLen; /* length of input block */ ' }- I) r8 ]% R- W6 y6 f0 G! k
{ unsigned int i, index, partLen;
& E- P# ]* P2 `: ^4 {$ Y! m1 ` /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
3 ]2 J/ j4 t" e' c' u /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|