|
|
#include "global.h"
0 a0 v) x/ b" Q# W#include "md5.h"
* g# m1 V' Y) n; \7 Q * l% l0 w# S1 z" Z
/* Constants for MD5Transform routine. */ ) C: W/ p' R8 |. T4 Q
+ b8 `+ A$ O. M* z3 N& e4 Q8 L
& x5 l% W6 L0 F6 \( i* A5 q* U#define S11 7 + y" f5 |2 [8 x9 o a
#define S12 12 ' r8 L# Y2 t% K" \7 y9 R
#define S13 17 - K- E: Q A6 `5 @; v& i2 T/ h
#define S14 22 ! H4 ~( U$ ]: J) U. W
#define S21 5
$ ~# O1 s; x8 Q: V: \#define S22 9 # Q7 Z8 A# Y% d4 m- S: p* R
#define S23 14 1 i# q7 m* Z6 H8 j5 n( J: p1 C& |
#define S24 20
4 ^+ O9 W7 U0 O& j. ]0 k#define S31 4
( j$ o- t9 d# Q* ?, U#define S32 11 0 g9 A' \* N, m! O
#define S33 16
+ ~# V& ]8 z4 h, X, J7 k#define S34 23 F Q: q w5 \# W* }. x
#define S41 6
/ T1 z) B. t, r/ J2 H. Z1 N#define S42 10
" ~# ~2 `/ W* ]3 V$ Z0 G4 I9 c$ z" j#define S43 15 1 A. F/ q1 o& @
#define S44 21 7 F0 I: |# ~6 g# g
; U8 \( J) k) X5 \static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
) d/ V$ g) q6 ~7 Estatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ; h! B4 a \$ U/ y
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
5 J7 Q9 g O$ v. D# B7 R; Nstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
8 ~, a% s# a4 ]1 ] J2 V2 a; b( _static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 5 v0 C$ f8 M% L
( m* w- S7 K5 T9 M2 |# tstatic 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
- j5 _7 a1 e' A}; 0 |: N8 n3 P+ K
' X3 Y. `4 ~0 z; Q# ?+ D
/* F, G, H and I are basic MD5 functions. */
+ [* `5 M0 a- ^9 c0 j! ~#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) # p+ E# _+ s, ?# Y! b
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 6 n* G- _3 c. d+ X7 L$ w+ q
#define H(x, y, z) ((x) ^ (y) ^ (z))
$ m: V1 @5 [0 a$ i0 V( e#define I(x, y, z) ((y) ^ ((x) | (~z)))
! J7 b( q2 O. w; a% m 7 U" ^) z; E! }# Y3 k7 w
/* ROTATE_LEFT rotates x left n bits. */
% T) `1 p3 p* i' a1 u#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
* A/ k$ P- g: ?( M' z ?% ^* w: M! |/ Y2 V, o" U) b
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. . d1 J; j2 A) g6 O: ^+ j8 U
Rotation is separate from addition to prevent recomputation. */
5 P* d% f, L& H. y) g4 {( v: q#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% Y; a) d9 g, B, z3 K, }; K#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
( i: @8 \0 L9 j' 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); \ }
& s# a8 ]4 l9 y# ^7 u#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 6 G: U8 Q# [/ k# q
8 G6 v$ O1 R H z
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ( A4 z" I/ @. c4 K j
void MD5Init (context) # B1 I9 S$ ]9 ?! i. [0 t
MD5_CTX *context; /* context */
6 @; o, N1 Q) P( g) P- w{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ' a8 i5 [" w3 L$ E" h; [& D: _& h- x: V
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
1 D+ C" |; b. Y- ^5 u2 p$ |}
" w2 ~4 v1 d6 a8 f( I/ N % f# c' U" h' B u# P
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ : ?6 D& C, V: @* D5 N6 x. k
void MD5Update (context, input, inputLen) y2 f i4 d8 i- `9 P
MD5_CTX *context; /* context */
0 Z0 E+ w+ c6 o( F4 B1 ^! Kunsigned char *input; /* input block */ A9 r4 p- _$ M- S6 }
unsigned int inputLen; /* length of input block */
. `9 E) f' e; ]( z+ W; Y8 L{ unsigned int i, index, partLen; 1 Z5 U" L6 {: u% ^7 [
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
+ ~1 h! o5 E/ D7 p+ d5 O) ^7 l /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|