|
|
#include "global.h"
# u, w0 }0 V! p3 a#include "md5.h"
. Q* p. k+ X" V4 B 6 o3 s7 Y0 q, a/ |* O3 h
/* Constants for MD5Transform routine. */ & n7 I, r6 a+ e P
- O; E# B3 B% J: ~0 ~8 o! h
I; M2 t7 G7 `7 V6 T* f3 S+ g#define S11 7
2 K. w( ~0 Q9 C' b2 G( o4 \* @#define S12 12
3 z: z, f+ s, h( f#define S13 17 7 _8 e, a- s# d/ L+ Z; Y: q
#define S14 22
. u$ Y2 i3 C1 f4 ?, K#define S21 5 6 M/ i t: j5 P$ c6 {2 L
#define S22 9
o1 I% b# Q" J#define S23 14
8 N& f6 ?6 |/ p2 j" n2 {#define S24 20 - N9 J% L/ P2 y& t: d- _
#define S31 4
4 n3 h& A8 {5 A8 z) @#define S32 11
9 Q3 Y% o+ l9 e+ a' p#define S33 16
/ _! C4 e! U4 A- j$ Q( J#define S34 23
- z3 h9 D3 {5 ~#define S41 6 " ~$ E6 c" w! F0 k$ H: ]( Q1 i
#define S42 10 7 S" x. e6 Y- g' U5 D
#define S43 15 - v4 T& d5 L% W/ I; t
#define S44 21
$ g4 x9 Y9 b" e5 V, y # i. l3 @8 M' {& R6 c! I, ]. e5 I% y
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
* i4 D/ T& w; ]1 x$ A: x8 `' Cstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
7 j& c# J3 R$ r# G6 {, i+ s& Ystatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
" ~1 B- H% o& w0 bstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 8 r8 l" k; H3 Z
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
M) G4 f9 J% P# x 5 d& z) v# i, U, y5 O" ~! w9 O
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 f& p: O6 P2 W' R6 E$ y+ I3 ]2 _
}; 8 p7 \" t. D2 B; r' J/ P
+ {- \8 @9 x% Y5 r9 n
/* F, G, H and I are basic MD5 functions. */ * S8 @2 t* D5 b/ _7 V9 K; s
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
) }( H, i3 q0 m6 H# L4 Q" O#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 0 }8 K+ P. k( b8 }' w7 Y. g! ]
#define H(x, y, z) ((x) ^ (y) ^ (z))
8 h8 v1 s5 Z+ o! M! f3 G#define I(x, y, z) ((y) ^ ((x) | (~z)))
$ b3 W- u8 N5 D+ ~- M # ?5 a: T8 L6 c) h( E
/* ROTATE_LEFT rotates x left n bits. */
% o9 m: Z- v% U: X#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
5 y2 T) d9 a' t' t7 E; z ) ]0 \$ f$ r: I1 g* s. ?! I: U1 P7 R
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 9 `* Z" ^7 p+ V+ B+ s
Rotation is separate from addition to prevent recomputation. */
3 {# _; C2 I4 F, h6 B: [: c& p' q#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } . ]4 v4 M) U4 k7 m! Y4 A6 z
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
( v1 }( m; w. d#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
4 N! b: A+ Q! n' i1 \" X! M#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } & Y8 ]& h6 B0 f; W& N! J/ Y
) F! w1 d& T4 S3 m- w/* MD5 initialization. Begins an MD5 operation, writing a new context. */
3 l4 R2 q" ~+ T& P- @2 |3 Kvoid MD5Init (context)
' R" L1 c! w2 ]+ G8 jMD5_CTX *context; /* context */
% n- W/ O' ~# x4 |! }: f{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
3 g; y% N1 t9 N: c*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
3 w2 J9 z5 l+ _$ M) ?} ' v1 q3 }" Y, N$ k# \+ G, ?3 m+ Y
* B+ X7 z% M5 s$ P1 U/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ & O. H" ?. ~1 G" p1 |, h: W
void MD5Update (context, input, inputLen)
* O* _$ u2 b; o) q: X. qMD5_CTX *context; /* context */
( a" c! ]% [, |6 k5 u# t* ?unsigned char *input; /* input block */ 0 u2 m; Y% R4 k
unsigned int inputLen; /* length of input block */ 7 e. t: B0 l* {- g4 ~/ {2 q
{ unsigned int i, index, partLen; * E& a, t3 z* Z" |' S- ~5 s2 U
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
0 U, W* y1 d( s# C6 O, N /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|