|
|
#include "global.h" % }3 C' ~' h) `( m: U5 q, y4 T) D) h7 I
#include "md5.h" # s& O; R$ x2 G. f) H+ C
5 f0 r$ O r; W V) J/ e/* Constants for MD5Transform routine. */
% {2 D n. Z8 ?- i8 X; s 0 O0 e6 G e+ ~+ e3 B4 W5 h
8 h$ U i4 `4 m. I2 S8 S0 Q
#define S11 7 $ o3 m' _% Z! C4 c+ y: e: \
#define S12 12
: C$ v% O7 S* s#define S13 17
! N) D% U! R: W: h! Y* e$ W' ?#define S14 22 5 \0 q- l1 g [ ^; @8 V
#define S21 5 1 A1 @" }, _( |- ~; k0 h3 t9 S- Z4 `
#define S22 9
9 M0 M3 g6 L) I5 j5 H$ m7 b' x4 _#define S23 14 4 v$ H n8 r. Q
#define S24 20 8 z, R3 d" }6 i* \0 d
#define S31 4
, O( M5 ?. C6 }+ U2 R; Y8 O& V#define S32 11
+ {7 }7 k% t5 G. W' G#define S33 16 ( q* q: Z2 S3 [+ h1 P: e1 z' o8 t
#define S34 23
( x" d! I: y7 y: f4 i7 a$ F#define S41 6 " @0 [/ V4 d% k* q; m! `
#define S42 10
3 w! c: I2 O# `" y: w( X#define S43 15
- e! R& W) m( ?7 |- k; q#define S44 21 ( ?' ^# o3 b+ u+ U
# b& t; t& m i5 y9 d! U
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
6 I/ |. K( @; N. i2 y, ~" p% v* l0 Gstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
& G) L( d& S+ `/ S4 e# |5 ustatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
* t1 G% Z8 P! ^# `2 bstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); - s2 _: L5 b6 b# c: m
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ' n! q# e$ ]3 T3 k' p5 j
& ~0 o/ X- c3 t/ H7 d9 n( C9 vstatic 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 Z q' t/ L A, i+ g2 M
};
1 |! y H* h+ S% a+ t # \! u1 u# T7 z! P9 d- f" ]* r
/* F, G, H and I are basic MD5 functions. */
3 ~ N7 z7 a# v! W, U#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) : E4 X% e" M5 \" N) X. e, k
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 4 T* [7 s9 Y& @4 P- i, t# m4 L* s
#define H(x, y, z) ((x) ^ (y) ^ (z))
$ o4 X. \1 s. v' `, r, i#define I(x, y, z) ((y) ^ ((x) | (~z))) ' g3 |4 [. K( _! w, \
0 ]+ o* ]7 x: ~8 R' V8 [/* ROTATE_LEFT rotates x left n bits. */
6 H Z8 x% Q% F; F7 J+ v#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
" {# ]" F, _3 N* {; ~2 M( |9 x
/ H# }" T0 }3 l- l+ p/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 6 }: B& n) O- h
Rotation is separate from addition to prevent recomputation. */ 6 P; h" H S% d" ~2 C# _% W- e1 X
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
# \0 F: Z$ u- q: [: [# y#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
- n0 ^8 _& B* n3 N& g1 u- B1 Y#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. Q' M, Y z: R' g7 w8 i
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ i$ ]9 @. b' Q7 B h. ]( j & J, ?% f( k% Y" p
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
! U* {! k0 h+ R. N+ K1 gvoid MD5Init (context) ; z: f6 [8 a7 E$ g \
MD5_CTX *context; /* context */ : d. Y- C; M |' }
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
1 a6 \* O7 ~. U0 c& N3 ~*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
' G. L0 F9 A5 Y: S0 p' ]} - h R; z0 w% Y1 _) W! M" l
% ^, X: Y+ x: ~/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
9 h6 K* i j# _* cvoid MD5Update (context, input, inputLen)
' u6 I& A* S* @1 [, [/ g! H2 EMD5_CTX *context; /* context */
5 ] W7 I6 S% r" X0 Eunsigned char *input; /* input block */
( E$ @; X7 i8 X# Punsigned int inputLen; /* length of input block */ 7 d, l6 N6 N1 T r6 z4 j+ g
{ unsigned int i, index, partLen; 9 ~( D5 c0 g, J: R5 }! Z
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
, e3 m$ i& |/ w6 |" A /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|