|
|
#include "global.h"
: B& O. d! x2 K6 h7 w, g! R% S#include "md5.h" 4 ] j7 z6 p8 _+ I: L
8 y( P7 O# c' o% Q6 B7 K: T
/* Constants for MD5Transform routine. */
+ @. F+ g- c) B4 }( R # O5 n! P; n. O$ [9 c% N
7 A% d/ v8 Q5 N" f4 G4 z m! p
#define S11 7
& e0 }3 z& u$ x# u; }# f#define S12 12
* U4 a3 z! E4 l$ ^ X#define S13 17 / K+ i4 i0 i# Z9 t+ c
#define S14 22
# |5 r! W1 r& p) x#define S21 5
' O/ O2 D' u% ^! u#define S22 9
2 d* S3 [9 X. F- v#define S23 14 & T" ^; S+ a$ r2 i
#define S24 20 & C6 |8 U2 j. l! C$ D( n. t1 c
#define S31 4 . P0 w& J5 r! G
#define S32 11
* @% a/ [& m* D/ X" t. ^#define S33 16 4 N( k1 I2 [/ h+ t7 g
#define S34 23
8 T' v6 `/ t6 M5 g1 A* C#define S41 6
# U8 Q9 R' B$ `; _#define S42 10
! e# M( B) @% x; ^9 b7 x) @#define S43 15 * q/ U3 Y' `$ v6 d4 A7 R- m, S
#define S44 21 # e4 r* u3 T( E U4 ]
% F/ H( X5 b# ^3 jstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
5 f& l; ?' j" P4 c) P' Hstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
% ~) S" W& C: w+ J: Zstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
% g% V H$ ^! X0 K. J/ ]$ Xstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
5 W* X- C, E5 _ s( estatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); $ g3 g/ M: d) A
% \& U) B: C) l0 Z
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
0 z1 Z$ Z" A+ ^) P5 i, C6 a}; ; V; v' f. l \
: G& _* u$ {1 W) G& R) }* O" `
/* F, G, H and I are basic MD5 functions. */ ( K; S4 U+ q3 e0 |
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
" L# N# D. \: C+ c1 m. K#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
% b5 O( c' V3 }! c% O#define H(x, y, z) ((x) ^ (y) ^ (z))
5 I! i. d, ?1 _0 x# o9 J#define I(x, y, z) ((y) ^ ((x) | (~z)))
/ i' U0 d: R9 I S
4 c" P& h5 \. o3 R2 h, w# a- ?/* ROTATE_LEFT rotates x left n bits. */ - z* ?$ y) m3 K" l' L, Z& a* f2 b5 [
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ( g+ u9 ]* m: L4 K u+ x! M
$ @6 Z3 Q0 x s( H z
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
, e" n1 c/ {" e v, uRotation is separate from addition to prevent recomputation. */ _" K$ z! b2 k2 R( P# v6 S
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ( ?, y( T: ^0 ~6 h3 }$ C1 w! O
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } # ]/ G' Q& Q) L7 u
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
- |$ ]& M# }2 m' p#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } & N7 D2 M- _! ^5 a
! T, t/ R$ \( N- O5 l# o/ Y
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ + p- s. F1 K. v0 X6 x5 g5 p7 p8 D
void MD5Init (context)
& k* i1 J% I9 P& o7 F% bMD5_CTX *context; /* context */
- k( E7 p2 T! @8 r{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
! Z& d3 F5 O* w& d3 n*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 8 X9 ?; [; W; m3 W
} , {& ]8 c$ \1 R) s8 S/ e
, J1 j* ^/ U; o! |" }, c
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ & o. \9 x) Y1 A! R0 L) e P
void MD5Update (context, input, inputLen)
8 s! P3 ~$ Q/ {* i+ @' a. ZMD5_CTX *context; /* context */ % H M; [ |8 d3 c3 [& K
unsigned char *input; /* input block */ * K& _) E6 g4 S4 k8 B; o. H# y
unsigned int inputLen; /* length of input block */
6 H' u- ? K1 o# v# P6 O4 C{ unsigned int i, index, partLen;
j$ U5 @8 W5 Y& M7 F9 Y7 @9 i /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); & [ o0 A! Q4 ~) P
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|