|
|
#include "global.h"
9 z% {% a: b: k9 v$ I* U4 A( Z0 ^#include "md5.h"
+ N C( U% y' P1 Q
- }7 j: ^, h' g5 G* y! ]/* Constants for MD5Transform routine. */
4 y7 {) k' B: [+ P d( r0 u - M- e, v5 U+ r# M
' `9 l4 F, {* {+ }) H2 i#define S11 7
R8 z# N% r! E! l0 _+ I+ T0 H8 C#define S12 12
. L2 b9 {. {& a* z) R% R#define S13 17
9 y6 T7 r4 Q2 r' r1 x8 l) y#define S14 22 ) @0 ^' ~2 X' T3 L
#define S21 5 1 _. N9 ]3 T( S) S" J& I! K
#define S22 9
- T- [1 `3 o8 g, u! M. m. i7 ~& o#define S23 14 " |3 ]7 R& a# w( ?% C7 [8 N9 }
#define S24 20 : `8 X( } c% Q! j4 ~
#define S31 4
a! q5 O' I' n4 b" A#define S32 11
# A5 V5 x7 n; L4 C, |- k- W#define S33 16 ; G" R3 r/ H. u- z7 H
#define S34 23
2 O: y' P# R) Q9 G! j; q4 v#define S41 6 ! C. g% ~# {! ~5 O
#define S42 10
8 A1 I5 |( ]. T/ H; H( J( ?: Z#define S43 15
8 ^. s5 @+ L9 |6 |#define S44 21
+ |" d) k4 I& w+ N7 C, j6 h + Q6 k, H$ `% w c( S0 G6 }$ z
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); $ f6 q/ S6 N' {. Q- k4 w
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
2 m! G; A1 C) q* T; t" ostatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); # M4 c( F. @" e% M
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 7 ?6 J2 L; Y! [5 `1 w
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); : b2 l* l+ e) O7 U
) D( \& o N* J. {1 S6 ~8 v+ Z' M0 Z) ]
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 4 ]$ W' h5 t0 C A B- ?3 I; |
}; ' O4 A) e) C7 W$ @( h
9 c. L# U3 P, ~
/* F, G, H and I are basic MD5 functions. */ * p2 E& ^2 C V# M, |' k; K
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ) {8 l7 P: G/ j+ Y) I* z+ R. n
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
8 v& b5 p/ t* H- g. B$ i9 Z#define H(x, y, z) ((x) ^ (y) ^ (z))
; ^2 q3 `6 k: F: D! z# v$ N#define I(x, y, z) ((y) ^ ((x) | (~z))) t3 d6 i2 D1 x+ F4 D
! q; j( a% I" P- p+ O9 `& r/* ROTATE_LEFT rotates x left n bits. */ - @" |! H$ P7 Z
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
, @: B1 Y5 F; R0 T1 A0 k0 } 6 ?, m3 H/ x, s4 P7 Z
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
6 f$ A1 C5 [, CRotation is separate from addition to prevent recomputation. */ " O+ C% U$ F* G$ y* g
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 8 z! x: K: l/ w0 d
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 3 h$ t# N; x- Z. S+ \2 _1 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); \ } : p3 N: x' s) t' }6 n
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 q% l) n0 _& j- Y1 l1 C( y 1 k4 I# _! Q9 }% {
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 8 @9 S3 H |5 F, Y) w/ a& L2 p, M9 n
void MD5Init (context) - D8 Q. H: k7 }
MD5_CTX *context; /* context */
2 `8 Y& e- W2 r0 {; m{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. + S! a$ j7 }+ D% b
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
& B" S4 l4 a! L+ p% N! F( J, N}
! j* ^( H$ B/ E3 m' t8 W; @3 z
; [ Q; W9 L/ ?/ E# K; u7 ~/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
( |# ^% |! d/ S. v/ ovoid MD5Update (context, input, inputLen) . r; m5 M! d# E( \+ `$ Z
MD5_CTX *context; /* context */
5 T* N* s8 X2 m# _8 z( `unsigned char *input; /* input block */
+ W8 D+ R% \) _4 l3 Kunsigned int inputLen; /* length of input block */ 4 `! G6 V, @& f* s7 `
{ unsigned int i, index, partLen;
. b5 u0 s1 y3 e8 P /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ) W8 v. x+ K. {* }/ ^2 Z+ j% G% @
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|