|
|
#include "global.h"
* V; [9 x0 B# g) s1 i#include "md5.h"
* m9 n6 Q. Q$ F( h( Z, P0 i 5 }2 }/ Q# d) i4 {
/* Constants for MD5Transform routine. */
o( y, G+ x& L# X* b6 @
! }7 O: B! a/ f4 T/ _9 k+ _1 ] 3 k# O# o, K, m- ~4 K
#define S11 7 6 T* Z- W8 q7 q- d6 s0 {5 ]
#define S12 12
0 z2 |3 ^1 T' j- K#define S13 17
( Y7 i, [, u1 ~* ]3 `#define S14 22 & L" W7 q3 y1 ?( @5 @9 [$ u
#define S21 5
+ w- d6 K$ m: m/ b, s' @+ Y1 ?#define S22 9 ) {5 r% `. e& N2 c8 U
#define S23 14 - ]0 V3 g' v; v3 Z8 n3 q
#define S24 20 ' M5 x( l8 k% F. {
#define S31 4
% f S/ T$ n' H6 C' H/ V+ s#define S32 11
2 h5 A: s+ h6 D2 X#define S33 16
; X/ _8 W$ p2 z0 d. h" T#define S34 23
' A9 b7 G4 S, F+ ?* n+ F#define S41 6 ! ?$ ?: `, \- h+ ~0 W2 b( p6 q
#define S42 10
2 Q# q% @0 `0 c$ t6 a/ I! [- G#define S43 15
" n1 W' W" t& {! ?1 C# m7 j! P, N#define S44 21 4 b( r. ^ F6 L7 r6 [
4 ?& C6 ~! I0 e0 Y* ^; ^8 W
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 1 w! y& x% ?# W6 P3 Q
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 9 [" [0 H1 N6 C$ ~1 q
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 3 v8 k/ y, e, ?# W
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); , w. L9 D% D5 l* W" t. S1 E
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
: [ s- g7 Z" M& J3 _4 Z
2 y# p% g: A- P, cstatic 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 & b( H6 J6 \0 |7 d& x+ r! G
}; 9 s2 G) e# X. r! H3 t
7 K1 ?( V% i% Z# e$ s
/* F, G, H and I are basic MD5 functions. */
8 B$ X3 S# q! x) f3 h3 J. B#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 3 p% Y2 x' h/ _
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
; `1 K9 v5 R, c! }* G3 Q. H#define H(x, y, z) ((x) ^ (y) ^ (z))
+ b; X- A- @+ Y0 W#define I(x, y, z) ((y) ^ ((x) | (~z))) * y9 e0 m: Z2 k( M: y
0 P/ h9 k8 O6 S" V; s# _9 `/* ROTATE_LEFT rotates x left n bits. */
; o' N# U( B H1 \' H- X$ [#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
; u) g% l% [9 J3 [1 V; W
* O0 h& S/ O4 P; V# {8 q6 k/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 1 R, _ k+ I- W, O: V) ^
Rotation is separate from addition to prevent recomputation. */ 1 [, a" a7 R6 T, g
#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 G3 N. [- x6 M1 H$ x
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } . R5 j7 S2 l& v' S0 A4 H' V* J0 F
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 3 l) q( j, i: V2 r# ?$ o" 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); \ } 3 e, f4 t/ k; V7 T9 ?
' P9 T2 o( Y) j+ W
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
9 K% r& k0 C. P. X3 f! f# dvoid MD5Init (context)
. z& ]! h: V/ g) v8 h* p2 p/ PMD5_CTX *context; /* context */
3 d7 G z4 E+ b' e8 s{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. : e) W T4 m' |
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
/ [8 ^; L4 u7 o' `7 E0 ^} # B$ F0 F0 J; R* J% p6 l
/ f8 q6 h; L+ m* h3 v
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
7 z, j* D k$ T9 R0 Dvoid MD5Update (context, input, inputLen)
0 `+ T- `$ a2 i9 w, z1 JMD5_CTX *context; /* context */ & D1 y% B9 T K+ p0 i8 I8 t1 t
unsigned char *input; /* input block */
; y- a' V: _4 Vunsigned int inputLen; /* length of input block */ / N0 k% J/ M( K, ?. p
{ unsigned int i, index, partLen;
& i# Y+ I3 C2 }9 L /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
0 b! S$ `/ j0 d f f1 \ /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|