|
|
#include "global.h"
; q; K# ]& R( X3 j#include "md5.h" 7 d8 v6 i0 c, B4 n
7 Y9 F2 w/ r$ }" O. \9 g6 G3 V2 S
/* Constants for MD5Transform routine. */
# r4 j1 c6 o+ i! W7 u8 y1 H. r
& \8 V% f' X4 k5 O& `
- h. J6 Z$ C* l( l2 P9 h#define S11 7 ' U+ z9 s& T' Z1 c* F
#define S12 12 ( V% y& D# p# E7 @5 Q6 s
#define S13 17 9 o- a; I% d/ X0 e
#define S14 22 0 c) H G/ S9 z+ W! o. S
#define S21 5
* s( F, z* w( n& ?7 O#define S22 9
) Q! D; _9 v( `#define S23 14
. V/ u, c q* d2 E0 T#define S24 20 ' A; \$ I, y4 j3 Z6 m( n: ]
#define S31 4
U, _4 v# Q+ y#define S32 11 ' A! [2 u' q$ N: Z' c
#define S33 16 * x0 L& H8 |; x- {) f3 ~/ T
#define S34 23
1 K9 {5 C8 _# q* K; e! c5 A" L0 H: B#define S41 6
% M( R% B `2 {#define S42 10 4 P: [. P' w! t! }/ w0 C
#define S43 15
# g0 B M, D) U/ |5 b#define S44 21 - v. O( ]$ J9 B3 Y! N3 \
/ R3 s% |1 ~/ Y2 e, E: h! }9 E) s
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); , g0 g/ W7 v0 c0 b f( Q/ G
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
' P7 W- I, N( t) ]4 B6 E' jstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
S/ h/ [# G; V. C" p V3 Ustatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 5 J$ m& S! Y$ l+ q% R l
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); * Y, h0 k- j' s6 L2 i
5 [2 i( o7 h( G" P" H
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 7 A" Z8 Q% B+ V' p" o% |& F# c! T
}; ' f* a& u5 U6 p7 g2 X
A5 `- J; r) O* O7 N5 E
/* F, G, H and I are basic MD5 functions. */
2 F [+ J9 X% B. u) ^#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ! w% [0 L5 v, d1 b) `
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 5 Q" I& |3 X" p$ X, u: S1 _& K
#define H(x, y, z) ((x) ^ (y) ^ (z))
" c. n+ ]: L4 O) z4 F( w- ^#define I(x, y, z) ((y) ^ ((x) | (~z))) ! o) l8 f; N, x2 W' J$ h0 ^1 c8 O. T
& j4 b* e7 p. T7 `. K, P, _! z
/* ROTATE_LEFT rotates x left n bits. */ , }4 @0 v- Z; |: L4 S3 ~
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
: D# h6 c# }7 O
" k( f# K% }8 X1 A1 Y# S3 I$ C/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
4 x; [* W# R$ ?Rotation is separate from addition to prevent recomputation. */
0 {- k7 Q+ F B3 ?#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* I7 a8 }( t5 }
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } % b; W, y/ e- @, w: v
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } # w6 [/ M$ G/ A5 E, m8 O
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 6 r9 N4 }1 d+ h; ^
N. l8 B- ~+ a+ o4 q( [/ C
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
: u4 g! g* W, v( \* Rvoid MD5Init (context)
7 w0 J3 A0 R7 M7 B0 WMD5_CTX *context; /* context */ * G% k) ]7 }, d% }; W8 c
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. + V6 G1 q. Y4 e8 i; t2 \
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
) F8 q" C: j( u3 X( j- h}
3 |9 q( O3 w. { ' ?( x' o: j) x; b
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ / H; E" m, s* ?# \# i/ i' X A
void MD5Update (context, input, inputLen) 3 M; M) O0 ]4 a8 T) X
MD5_CTX *context; /* context */ 3 d# Z1 \9 e+ ]4 g
unsigned char *input; /* input block */ 9 c, Q* Z& g6 \/ \7 k5 j
unsigned int inputLen; /* length of input block */
. @3 ~0 \& k/ H! h+ Q{ unsigned int i, index, partLen;
+ C6 Q. Y9 D$ [. x /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); - D) C2 F# _, h) C8 \
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|