|
|
#include "global.h" 3 y% Q3 M4 Z- M% v
#include "md5.h" ! i* c+ i; H2 t8 \# q
7 G# e& \( d$ q# J% w9 U& S
/* Constants for MD5Transform routine. */
: D i" T: e5 ]8 y. y
# n$ ?5 J" z+ q0 _2 Y ) Y3 k5 G) \: x* S
#define S11 7 # \! m% u& W4 p- a) b
#define S12 12
! e) m" }/ O8 K! x! b#define S13 17
9 h! T2 H6 z1 X, Z7 h s#define S14 22
6 z$ }6 i& z$ E t& f( d- r* `( c#define S21 5
5 y1 H* u- b# f. K% P* @! R#define S22 9 2 v$ k: @* x) f5 j p$ t
#define S23 14 0 u, L) z% h8 w+ X
#define S24 20
. p5 a2 V. i2 H$ ^7 |) ^# i! G#define S31 4 # E2 ?; V6 G0 b$ a! ]9 N# Y
#define S32 11 # g6 p6 O. |4 ?3 H4 J
#define S33 16 $ Y7 t# \: ?! |3 J5 |0 b
#define S34 23
, K1 n0 y5 r( T#define S41 6 ! M9 k0 b) K2 `, z8 e- |
#define S42 10 ) `( i$ P$ V4 T0 p6 t0 _
#define S43 15 / v! l( c/ ?- X0 B
#define S44 21
6 Z. V! `. S. T+ {* y% j
% `# ?2 g( c; P4 R# j Hstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); ) A4 P% x' h; q. w5 u$ t# N+ C
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
( R/ T& ~" N' G1 a% y0 `; A! D" Gstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ' `- K, C1 ]1 Z. ~) h/ `7 h* O
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); & C- w& O1 y) U8 X) M7 W5 c
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); - b; N4 b4 j3 J A" ]( \1 H
9 N3 |3 l( y% ~; p3 ~# O6 q4 n
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 1 Q9 m% L) N3 _8 _4 s9 N
}; 6 q7 ]5 m4 _: T* r/ K8 ^# Y
I4 X( B; s7 W9 v
/* F, G, H and I are basic MD5 functions. */
% g: f! l0 e- t Y- e1 }#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 9 A, W1 u2 U6 Y3 Z
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
# D- y2 t3 U, `- i8 m6 D" b#define H(x, y, z) ((x) ^ (y) ^ (z))
" b/ G+ x" j% c+ L( D. X#define I(x, y, z) ((y) ^ ((x) | (~z)))
3 e' t! P4 B) Q$ u7 G
7 L A# {: L {3 {+ G/* ROTATE_LEFT rotates x left n bits. */ ; U. o2 O( h3 U: h0 R- T
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) , l! k, ^ K: |. c6 }
& b- H: \, p: T& ?
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 4 N/ z0 }* A) l5 T6 w( D
Rotation is separate from addition to prevent recomputation. */
9 k1 r2 k( _, b+ v/ O$ a#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } / T8 y5 a& z% a5 ~% v9 y& L5 U, U
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
1 B1 ~7 y: }& j! P8 B3 _- x% @#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& r. d4 B# n# i) 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); \ } 5 z$ y: Z* s* M0 b9 s$ {, e( X& {
1 Y/ H, s: {: F/ K
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ' R! h2 _0 w D2 W; O
void MD5Init (context) 0 Z3 D5 ?- P5 w, @
MD5_CTX *context; /* context */ ! {; H* M5 J& n; b- h& Y
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. & I7 U8 X+ T, q. Y- ]3 U0 |: Q
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
+ o% M. ]9 Q+ z, C( {8 _3 f} , \" V p+ \7 x1 P9 T/ [
$ N* J% B+ m0 V3 X/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
3 R5 }8 B1 ]. R/ Lvoid MD5Update (context, input, inputLen) 2 X( K/ V7 B3 S' y8 v% H
MD5_CTX *context; /* context */ * }2 ^# l9 C [. W. X( ~& z
unsigned char *input; /* input block */
6 x8 U5 X ^ f7 _- Q0 {6 eunsigned int inputLen; /* length of input block */
" V7 f. p' ^! d% y) k2 k/ U$ H{ unsigned int i, index, partLen;
- E9 Y/ l+ ^% t /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 7 K9 B9 d* J Y. i0 }5 {* O
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|