|
|
#include "global.h"
7 V Z7 Y' k; o6 r7 }#include "md5.h" . h! K" S1 R9 L" |4 a2 y1 T! w
+ \# x+ c# K* A- V/* Constants for MD5Transform routine. */ 0 B- ]( @, u: D9 q
" O& E) c. w3 ?6 x; G
: Y, k$ {# G8 @# g0 H/ v' C#define S11 7 M" l3 @, O0 u. @5 h" e
#define S12 12
# r5 l9 G+ Z! n' Q#define S13 17
+ l9 F+ d3 l$ {5 e r#define S14 22 + r4 K- m( s0 t8 R1 l7 M2 c& q$ Q: J
#define S21 5 5 j( a! e3 @5 M+ U, ? h$ ~0 q8 h
#define S22 9 / {4 p, C( c. D. u
#define S23 14
! i& X2 Z$ `0 B" ~6 a0 {: ?: Y#define S24 20 6 a* f8 x2 a" R$ o K; _
#define S31 4 ' j6 j# f/ w0 M5 `
#define S32 11 8 X, E. G! \; z1 n o
#define S33 16 " u1 h( {, t+ @+ f4 D" b( g
#define S34 23 , e9 k6 Z% C5 ~* W, Z
#define S41 6 ( Z5 C4 o% a2 _: ]( p$ ?
#define S42 10 9 M5 ?$ y. p/ ?3 i% K, I3 _1 d
#define S43 15 ; C& z4 ] O' f$ Q7 ]
#define S44 21 ; @; O4 V4 c" X% @
2 r4 _" i# I) y7 J
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
7 @8 }1 e, J6 X: istatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); R2 ]' G! J& i; K+ c
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
3 T+ ^' d' u& g- X% w6 Y0 C, T6 N/ `static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
6 q0 p) Z$ r; R( h; zstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
# T. ~; M5 v/ x w : o. ~) C+ b) L4 W' W3 j D; {
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 * Y0 z3 e; F& r. J3 V: z% s8 ^
}; K' a* A# c ?( Q' y
E3 \1 m. f$ r, N, M- R' z
/* F, G, H and I are basic MD5 functions. */
# L- t- M6 z0 M#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
# _9 ~7 d( O/ h4 c2 g# a. Z#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
1 |' m: i2 V5 O& y#define H(x, y, z) ((x) ^ (y) ^ (z))
6 p# }1 {3 Q6 U. @ f/ e6 A#define I(x, y, z) ((y) ^ ((x) | (~z))) # N+ g' k& t0 m7 U7 Z7 ^3 ?
* y' z, Z$ E) J' k8 n/* ROTATE_LEFT rotates x left n bits. */
9 i$ q+ k8 S6 I9 x- p- ^5 g#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
5 e9 {+ C" Y2 P6 v, ` 1 P8 G$ a, j; E) Q+ v
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 1 x9 |+ q1 f) }: B- l
Rotation is separate from addition to prevent recomputation. */
8 Y1 r2 n# o1 p! S& l2 D7 m' ^* j#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 Y4 z& \1 O3 a9 m' V#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# J6 K5 Q* y) d/ i$ g2 e/ \
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% a6 D) W' \: S5 V#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
* I8 r9 `9 ]5 Q1 @& Y. o9 F; q# E - s8 W0 Z5 Z9 e @8 ?1 j
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ " U, y( o6 ^/ M
void MD5Init (context)
% ?: W, G2 E+ R3 h( lMD5_CTX *context; /* context */ 9 ~ R/ w; U7 l7 U
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
: A: g& E5 Y' K* s*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; S; n( q- Y! X }" |9 G Z, z+ J
}
8 T% @8 O" _% R! B # L0 k# g9 J% I7 i; o
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ , x/ o* M& w/ o3 D
void MD5Update (context, input, inputLen) ) I g, B# ^, m V
MD5_CTX *context; /* context */
% u+ o' h2 }- @/ x5 Ounsigned char *input; /* input block */ 6 D/ L. b) h: r
unsigned int inputLen; /* length of input block */ 9 L6 V4 c7 h; R
{ unsigned int i, index, partLen;
9 A7 h# l- ]5 C' X- E, @. v /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 3 D9 A' C7 n+ t7 D/ F1 X& ^8 G: |) z
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|