|
|
#include "global.h" ) I; h8 i; h+ ]% l9 o1 I- c6 c8 l
#include "md5.h"
, p7 ?7 j5 _& n
7 O: \" `9 g/ W/* Constants for MD5Transform routine. */
/ _5 A* e& l- l5 U, [+ u
+ @2 j9 I, _5 x! v, t( N- f- c4 f% j0 [ , s' _9 ?1 a2 R4 Q
#define S11 7 : J# B) L" F9 G: X
#define S12 12 3 B1 I( l; A0 o. Q
#define S13 17 ) \6 i1 V1 u- u A% ?! @, E
#define S14 22
# ~- ]2 u5 D2 P$ S#define S21 5 $ h0 ^4 v- a9 ?; F* m8 V
#define S22 9 $ H" P( u% ^1 p5 ^3 {- X
#define S23 14 0 @! S2 P" ^6 A; \
#define S24 20 - O) c% S2 v4 X$ p. q8 j
#define S31 4 2 v5 g0 ^- o) J |* ~' H* v8 M
#define S32 11
- u) ?0 ~ v: [2 N0 G" r#define S33 16 3 a' _% ^5 w4 i \! ]
#define S34 23 / s* I- j/ Q9 ^) V8 R
#define S41 6
8 J1 O4 H" ]. l; D8 n#define S42 10 # ^9 F1 `, R' {% E$ }
#define S43 15 5 d \" t4 E5 T! _
#define S44 21
, P/ W G' @. ` / w! l4 p4 Y5 Y- e6 D: V
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
4 ~6 E+ d# g* d' Hstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 1 K" ^0 E. w7 A4 ^! `3 h
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); C; q) F7 _0 M& O' P
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
7 r4 F7 k2 p5 S2 U9 D$ @1 z |# sstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
( W |4 w) n5 y! |
8 L+ k# s- k b6 A% }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 9 t' a0 k6 J8 Q9 q2 j6 O
};
, ~+ c' S7 y" [) N, | , l$ K9 J4 L% W: F4 S
/* F, G, H and I are basic MD5 functions. */ & W& L2 W; B+ }9 U( V9 U6 b
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) " V; {* z A0 g( c
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
! Z! ?8 M+ ?) h$ n+ A* X#define H(x, y, z) ((x) ^ (y) ^ (z)) 4 q: v+ y$ m% u. U. h! r4 {7 M
#define I(x, y, z) ((y) ^ ((x) | (~z))) 8 @- Y0 [- V1 [- q2 {, I
, Z( L" e1 b" t6 m4 U! o N
/* ROTATE_LEFT rotates x left n bits. */ ' r6 }5 i/ K! K. I! S" Y2 n5 [
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
% Y. \. g! n+ u" B% C
- ~& h$ c1 R7 c" U/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. $ w; Y3 `8 N0 M$ ]/ ^2 |3 |
Rotation is separate from addition to prevent recomputation. */ * i, L; Z2 w$ L) A0 L
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 2 I! q: s% E6 P& W u: h
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 9 T' P+ ~& ^4 f( J5 d1 G
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } * x% C3 u; |( D8 K6 q/ F( 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); \ }
0 _5 s6 \: R1 P- N3 c2 J/ p
; R* n- R+ I8 u" u4 T6 L' y/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 5 ~* y0 I9 s1 Z! `$ e6 A8 {
void MD5Init (context) ' y$ B- C1 T' Y$ C5 S9 ]; x
MD5_CTX *context; /* context */
& ~, c/ I2 f0 ^3 G{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. + ~& ^8 u6 N6 D, p" h1 U' w
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
# i! z, E& O5 Z" l. [}
0 ^* h( L3 K3 ~" \ n 5 }6 n" o5 t5 ^2 C. S% d- U* U
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
X X. e; f/ C* ]! x1 J8 }void MD5Update (context, input, inputLen) . K0 b' h' d( W: D
MD5_CTX *context; /* context */
+ M0 `/ r$ K2 S% I) E( ^unsigned char *input; /* input block */ 8 R9 t: M+ H7 q1 X0 I) x' z
unsigned int inputLen; /* length of input block */
% B5 E1 l; n" e% N: t{ unsigned int i, index, partLen; 9 J8 ?' P+ `& o' g. U
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ( H+ D: U) \$ I& [7 o* y
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|