|
|
#include "global.h"
$ L" Z7 a( ]( p#include "md5.h" % x5 X6 q6 D8 C8 P
4 Y. s; i; _8 h( V7 D- e9 i/* Constants for MD5Transform routine. */
+ s; z! e5 |8 ` 3 n% K* Z, ?$ O7 K6 z" P( Z1 B
6 ^6 m2 R0 L( l6 M2 q3 S
#define S11 7
' L$ o' v9 O& l9 H3 l#define S12 12 # b q# @& O$ V# L& d
#define S13 17
0 Y' N; y x# a4 ?: y#define S14 22 - v+ V) Y" w& d& i( Z! E/ V. T1 b
#define S21 5 1 V' z9 p3 A' B* {5 ]" e/ x$ R
#define S22 9 / L# W3 F4 Q6 ?9 T' L- J* ^$ {3 o
#define S23 14 ; h( ?# i# M: D4 Q: P9 p O
#define S24 20
0 K+ k! N* L h#define S31 4
8 s/ s% B8 \1 ? L+ L2 Z4 p# Z#define S32 11 * L% q& u6 {2 P$ G7 w4 p
#define S33 16 ! G g9 B7 |& V, ^ R/ }6 e* {
#define S34 23
% z/ ?+ n; m; Z6 V% y#define S41 6 * r3 {% s7 y' A2 r# S
#define S42 10 y& C% e/ @; V+ [
#define S43 15 6 \ I6 z& G, @
#define S44 21
, }( [4 Y. O0 x! Y
% `' R( |# C3 mstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 4 h! W5 C0 l5 l1 ]1 ?: ?1 o
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); * Q8 t, I7 u- J6 ~: r# P3 e( p
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
/ ?0 z5 j& F9 q) n0 m# C; `; }static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); I5 `9 e; o& I! C( {: D
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 4 J) Z1 R- p- J8 q( z2 k0 C! R& l! S/ |
2 F" X8 E3 U, y" C" |$ astatic 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 4 _! u! l& \6 X2 S5 a. I) L
}; & w) K, z. a6 ~
$ s$ s/ ^! ^* N1 ~) \ K/* F, G, H and I are basic MD5 functions. */
9 g* z8 U, T G5 A* y. e' K, M#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) & \' T8 T0 P& D. \1 m3 A3 E1 `( z
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
2 ^; ], _- S4 Q4 E#define H(x, y, z) ((x) ^ (y) ^ (z)) : k% o' u Y& i' A
#define I(x, y, z) ((y) ^ ((x) | (~z)))
' m; \3 x! q) @: x
a# A* J4 @; l4 N/ b/* ROTATE_LEFT rotates x left n bits. */ 1 z% C1 P3 X0 P0 f
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
% T! _% G* c1 j4 Y6 G# o% J
0 D2 G. z+ @; G1 P7 f. |; y: p/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. % W: q x4 n8 G6 t0 T
Rotation is separate from addition to prevent recomputation. */ & p6 e# _6 g, g: l. }+ k9 T
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 6 x' |) t8 L4 o4 |+ ~5 v$ X8 h. b
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
$ O {1 @0 C7 A9 t7 A#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% K% y# Q! ?, q$ j# r' \/ `#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 X1 y- d+ U" |: ^" p: h) y
( L a& Q# g1 x$ m5 ^0 M
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ - E |( G6 o8 X! e, j
void MD5Init (context) 4 A, `4 B7 H7 o5 L
MD5_CTX *context; /* context */
" d6 p/ h( r* Y5 `) X+ Q{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ( H; c* i: |+ q# Z* z/ H4 f/ Y
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; - U5 D! I% r7 h: n/ J& x) _
} r% o! J8 P& `$ W; g) s
1 ^0 f5 z. E# a# m/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ & v; i1 g: G; j( E: D+ y5 ?
void MD5Update (context, input, inputLen)
0 T+ A: E* Q# a& K3 H0 DMD5_CTX *context; /* context */
3 N! b3 t) V- dunsigned char *input; /* input block */
: u" j' q# W( Dunsigned int inputLen; /* length of input block */
: u, i$ I7 a+ c% F5 @{ unsigned int i, index, partLen;
4 |6 N, @8 @2 z8 k /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 9 t5 ^- C% n5 t$ }
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|