|
|
#include "global.h"
" e1 l- }- f/ U5 {4 A; ]' z& J#include "md5.h" % w( s% p& B8 p c' r3 d
' {/ j/ M1 R% ^; a/* Constants for MD5Transform routine. */
R2 {% z; V9 c4 |; }$ {! y
: |! S: G4 X4 i, K
1 p( M4 y( _1 h. V#define S11 7 + U3 G8 b! j1 M/ T4 M1 e# U8 K
#define S12 12 4 v3 e; U6 ^ o m
#define S13 17
! X4 r4 v4 A$ B7 m2 k- l#define S14 22 7 h! x: i. G$ u0 y; R2 b' n) { E
#define S21 5
# ~ u# m+ y0 N5 H#define S22 9
% x; ?# c% c. z/ f- H#define S23 14 T% z# v1 ]( M& A
#define S24 20 $ r3 g$ A1 \0 h0 q- |. t' O
#define S31 4 " ?3 g5 o3 \' P J0 L
#define S32 11
) o! ]' I+ w8 _, K9 ~4 N! @$ s#define S33 16
$ R* y* A7 m+ {& k- n" o$ u#define S34 23 - B/ D& W, u0 i- G
#define S41 6
8 n" e5 y9 A7 C' B1 x#define S42 10 8 g" U' r& G0 e' L* b9 B
#define S43 15 / E9 Y) H1 t) b# Z
#define S44 21
) f- k9 L) B7 O/ O: D" b, e / u7 h0 }' h/ }# c8 d
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
9 e I$ C+ d( g! cstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 8 u1 i: L1 U- ~
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
$ J: M3 G4 H( K; |5 C# Z9 {static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 5 u3 r2 R7 Z* e0 T& _
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); " J# \/ O) m9 I: w/ F: M: H9 e
/ P* _2 f' `, E, H5 \/ Y9 y: n+ J, 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 8 r8 d% T0 n$ t/ d% H
}; + K1 S) h+ \1 \6 E# t
/ g& A$ l) K0 |% }6 k
/* F, G, H and I are basic MD5 functions. */ / m0 A; y4 A2 F3 i2 R- Z
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
6 i( c1 }: H/ k( e& v& s0 r#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
4 U' G9 G+ s0 r8 ?' M% X2 u#define H(x, y, z) ((x) ^ (y) ^ (z))
9 @* V4 M8 A3 U* ? i6 O#define I(x, y, z) ((y) ^ ((x) | (~z))) 2 Q- r s# V6 l5 z# S9 ]
0 t' y8 t" ~, T; Z% }' S8 J/* ROTATE_LEFT rotates x left n bits. */ : |* n5 I2 H4 ^% N0 w. G
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 9 V+ x7 y$ y9 c, E% J
5 o' J9 v2 N7 ~% S& c/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. # N& N$ j( _0 s- z
Rotation is separate from addition to prevent recomputation. */ * b8 a2 ~3 r5 A- [ _
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } , }, t/ K. m9 |
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } : t$ O! e, q0 J& |7 h$ s# 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); \ }
: g0 t7 S/ F4 K$ R6 f3 T#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } & H$ u0 m2 g9 |
2 }0 t# [7 g$ C0 @
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 6 X/ ?+ p& j3 B% R7 p
void MD5Init (context) 7 J( W' q$ g+ I0 i: y4 l; t
MD5_CTX *context; /* context */ 1 ^# f: l8 m6 {0 |% {& I
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
$ H8 _9 w0 B; B* w, u*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; ) M2 }' X; h) X2 Y' X4 Z) {( ]6 Z
}
1 r. p& C8 V& _6 `$ R& v
1 r# a+ I2 y" \( O( A/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ . V c5 X& _3 q/ n
void MD5Update (context, input, inputLen)
& U; B$ j. _, B( k& ~. ZMD5_CTX *context; /* context */ 3 _) ]# n r% E* U b, o8 O
unsigned char *input; /* input block */
5 N( L0 _0 [4 t6 T Wunsigned int inputLen; /* length of input block */ ; c" i/ q# U4 X; N
{ unsigned int i, index, partLen; & N, n- V6 j7 ]( O$ K) Z( A2 ]
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 8 D, h# @- j2 P" w$ p2 q0 U
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|