|
|
#include "global.h"
( U" i: l5 l! ?3 U#include "md5.h" : b' S* }4 \- C( m% K0 c9 _
/ ?$ z9 Y0 r) }, w% F, d5 ^. c: N/ g/* Constants for MD5Transform routine. */
' N% N5 p2 s) J8 E4 W - T& \' H9 d' V, E* G
3 N m3 O2 k( z7 F#define S11 7
0 {: L. j. y- {- ?# ~* }#define S12 12 ( Q* L: [& K3 C! q3 e& L6 C9 j
#define S13 17 . V; L% [; p" G5 u
#define S14 22 / j6 ]% O3 v2 k. q6 f& G
#define S21 5 1 w, c7 E3 z4 E& p
#define S22 9 8 V" H+ j* C! r* ?
#define S23 14 2 G; U) p/ P( T$ s& j
#define S24 20 ! R7 z' H+ G3 Y+ o. B
#define S31 4 ) K7 P/ o& ^& B
#define S32 11 1 c x7 T6 L: H% P( q/ |
#define S33 16
6 M- J6 j& j( F9 B' |; ]% f0 X#define S34 23
7 c# f$ e( w5 k0 U/ q+ T5 g8 F! d#define S41 6
4 m2 `& b: a6 K( m7 z#define S42 10 3 A3 I |* \5 Q8 R6 J
#define S43 15
% O$ z& i( j! U) H% U. }: M }#define S44 21 - V5 a3 o$ [1 D* ~* Q
, n+ _, U$ M" \% V) U
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 2 D x' F% W! L, k7 Q* ?
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 1 _) A6 ]/ _: [2 o) j+ ?
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 0 V: \: { G0 W, [/ n; G
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); + U. [% u3 z7 g. T
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
4 S" w7 j% M h8 \ W9 ^, t! q 4 ~7 O/ |6 k4 _8 ~ }
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
" N* k: i/ g M/ |8 C}; & _: Z5 l# q( P: |" ~
6 e1 @8 M; X; _6 S5 p/* F, G, H and I are basic MD5 functions. */
" D- q& Z9 k) v: k) @- H#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) & g) Y5 A' v& F# \! x: e
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
% J) l8 \" n0 L/ c8 Y% B4 Q#define H(x, y, z) ((x) ^ (y) ^ (z)) + ]( Q* ~( \' n3 P& f H
#define I(x, y, z) ((y) ^ ((x) | (~z)))
6 w1 C, P8 h* F! P, D- Y& a1 ]2 Y 8 `3 ^) Z9 S( U3 J
/* ROTATE_LEFT rotates x left n bits. */
" O8 ^7 P3 D+ Y4 f#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) " E4 _- ~+ p) ^ h% h
3 E3 b1 I+ R ]3 D2 t; w2 I+ O
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
8 p, q7 n' M N3 IRotation is separate from addition to prevent recomputation. */ - O1 ~7 z# Q2 |0 G# {5 }) r! w
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } " Y8 G9 Q/ @! d6 W: Z
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } - P- h0 L1 T" U# z/ z
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& ]$ Q) w3 q0 R+ b#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
1 U6 q4 S* P# S% a9 q " `6 c# V/ [. l9 S& n
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 2 l3 p J' N7 O/ c( U6 j; S
void MD5Init (context) 5 L! y8 b" T. P Z7 S
MD5_CTX *context; /* context */ 5 A0 \8 a1 l. ^4 B R! u
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
: h% _8 a3 Z) a0 U; e& ^# {: U* F*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
4 n( y- O* K" l. u} ( r4 z9 |$ `, ^
8 D; a& [; R, g/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ . t( W& S) E4 Y
void MD5Update (context, input, inputLen)
" e7 d7 w& n0 c) Q- ^MD5_CTX *context; /* context */ . T- m2 f# i" ~. w9 H3 J& t7 g4 F
unsigned char *input; /* input block */
8 F7 ]# k! ?; v$ L5 y$ I7 }" N' [unsigned int inputLen; /* length of input block */ 4 f) N" }1 p- }/ u( q" M5 w0 ]! H
{ unsigned int i, index, partLen;
! ]5 Z. S6 y) U /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ; h) D1 \. g! P0 o
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|