|
|
#include "global.h" ' G7 y" Q) x9 a* y ?2 N$ [7 [
#include "md5.h"
' b, o- q- Z% b: q3 m 9 j# k( a2 ?% |
/* Constants for MD5Transform routine. */ ' } ]- D1 Y5 p4 _
( | h! f. Z7 N2 y9 G
! Q3 N* [6 r) x' r' I' Z& N#define S11 7 4 M% f6 ~5 i$ |" t
#define S12 12 2 d% A5 \6 a. g3 }( V+ M, U
#define S13 17
# |' U) ~8 s- v#define S14 22
" D4 S: {8 e4 u) b* F, m0 @#define S21 5 0 ?' K- @' [# P# [2 ~4 \
#define S22 9
# T7 u* }* G9 F, I1 D& s& t3 D4 D$ }#define S23 14 * w5 V( Z9 M# X) x% ?
#define S24 20
4 ^, ^9 h t s2 s#define S31 4 8 N P# k& q: k: E. b5 U
#define S32 11
) q! d3 y. |7 l9 Z+ Q#define S33 16
) |5 K! F7 b2 q: c/ Q#define S34 23 . a2 U+ M" _0 c/ G
#define S41 6
, E$ g/ V, Z- s) R0 g#define S42 10 . z/ q8 C5 o1 ?( g+ M+ V
#define S43 15
' Q3 n9 E+ l+ F6 q7 r% i#define S44 21 6 j# N9 w N2 X0 N* V w( j0 A+ W
0 R) R0 b. d% H: l$ `3 S' y Nstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
& v" m% f4 |0 m7 W; [* x% Vstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
: d8 d; T' n9 }% {" A5 Qstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
, t) F7 m! y- H. X( G8 xstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
+ u' M% j7 W% l1 E+ gstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ' N# _3 O; N% O% Y, K9 g4 F
" J- _5 `! l0 p9 N, D5 |! \. B$ t
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
1 x; S$ J# l4 \' K; x+ B};
7 g+ U O% g5 J, L3 `" |3 i
' W& r, H0 f, J8 C/* F, G, H and I are basic MD5 functions. */ ; A! [$ h) J' Y& A: G _# l
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
! E' }& r2 U n ~ i7 q9 u#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 4 V9 j7 y: I, E" o" u& J7 [
#define H(x, y, z) ((x) ^ (y) ^ (z))
$ v7 R' e- V1 I8 t3 h5 `: I! C#define I(x, y, z) ((y) ^ ((x) | (~z)))
! r0 i/ ?0 }5 s" U) T& f : Y% N( g. l N) R5 T
/* ROTATE_LEFT rotates x left n bits. */ / C* L3 _: G P/ n
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
. F9 A4 i2 J8 H2 U 7 U+ Q. s' T* N- u- U$ n
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
0 N3 W4 D. }! {7 I5 Q8 F$ CRotation is separate from addition to prevent recomputation. */
) }! m2 D9 j* g1 j" Z#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } & K: m$ t! h# X/ N
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
6 p3 J+ ~* A) \+ c' p' T#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
: E4 o* x. n# P# S6 S$ e7 H#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
1 P! y$ |9 n+ _( b4 z- j- t + V8 _. q) k; @ @- v W
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
! L$ r7 k% r2 G1 h+ C. |. Qvoid MD5Init (context)
6 g: N* e) Z8 c1 [MD5_CTX *context; /* context */
2 |$ @" {2 f8 o% Q{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
5 R; y' `0 I4 w/ F5 ^4 Q+ o" o*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
+ |8 R3 z; u) @6 i}
( F. T9 g2 t6 Y* q
; d' U b' F* s/ m/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
+ x% J3 e& B. q3 `2 t0 I( L7 ^void MD5Update (context, input, inputLen)
( P$ O9 `3 l2 s* _$ wMD5_CTX *context; /* context */
B+ w3 b6 P7 ~unsigned char *input; /* input block */ : p4 i3 n6 S5 I$ P
unsigned int inputLen; /* length of input block */
8 n% _. v5 P! Q) r{ unsigned int i, index, partLen;
% ~- P) |0 B9 D3 @' } /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 6 {1 {: n/ H4 T& v5 a G
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|