|
#include "global.h"
% r; `) s- r, `$ H9 @2 A9 u#include "md5.h"
7 h; Z1 n; v$ x ; v$ X, P/ o+ r. k) u
/* Constants for MD5Transform routine. */ & v! n1 Z# Q, v
& h9 Q! Q3 L; l7 ^
& I! |0 S4 d! v1 O8 m, c* ?
#define S11 7
v* c" m8 P; F6 Z1 V#define S12 12 5 h. X2 O3 }: h
#define S13 17
) p$ R/ _! B' F9 F! V) a5 s0 T#define S14 22 , o& h9 ], `6 c8 {
#define S21 5 1 f- \' A1 }& u( N+ {8 n) I; H
#define S22 9
- w9 [7 k5 b: d3 R( W* k1 X% N- }#define S23 14 6 U7 {6 K+ n" u8 |" V, V$ I! T; ~
#define S24 20 : G+ h+ v% ^. N6 T
#define S31 4
7 O, @- @* s5 @# i2 i! y#define S32 11 , Y0 O5 a4 T1 L3 S9 q* g
#define S33 16 * M K4 \/ E/ s# x
#define S34 23 & G1 m! ~2 c1 ?5 X9 V+ n
#define S41 6 % p+ `$ r) h2 n: [' x E; q
#define S42 10 2 {/ y7 N7 A1 r. }; L6 ~
#define S43 15 1 l: W2 |8 X1 ~! m$ G8 s
#define S44 21 $ k8 b5 z& P" D+ d H& d
7 P; H% u0 p0 e7 h8 E% V
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); * g! v! D! F7 O- j9 N4 g
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
' e4 j. g, x8 C5 Bstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); " j F6 A8 b+ V& r7 Y7 O$ W5 |
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); ( v8 m* L! B. z; f# j% b3 L. w
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
" ^& E% C; e* p% ^ [$ Q( M3 ]
/ K% b0 O. M9 {# O5 ^9 v2 B# ostatic 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 ) H, `$ w$ L# u
};
, p7 J! w1 r4 D3 v # r( x. t1 a) f8 ]* S1 S; G- b% O' B
/* F, G, H and I are basic MD5 functions. */
! l5 l, k. }' l, f#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 2 b: D! Q6 j4 Y+ G: E0 E
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
7 E+ f' \2 h. o! M#define H(x, y, z) ((x) ^ (y) ^ (z))
3 Y. i6 N0 N8 l8 R) I#define I(x, y, z) ((y) ^ ((x) | (~z))) % r; I2 `$ L6 b B7 l
0 E, m( U; ~, l; C8 j/* ROTATE_LEFT rotates x left n bits. */ 3 b& B% s) i9 e0 B
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
& j( J( m+ \ H# ^2 P$ i+ `
( B# f7 ~) U/ o/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
; Q9 z1 T7 h& B" D, d# I. _0 {Rotation is separate from addition to prevent recomputation. */
- D, b2 r$ N8 V. ]#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
) Z3 G3 I* I/ N! w; q! n$ 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); \ }
* B e/ p( M7 L7 s; [1 E" v/ 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); \ }
2 t/ I: N5 u7 v6 l9 ]2 D#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } % S3 r7 o$ f8 l3 V6 M7 }
" D1 I- v4 ]1 Q: ~
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
% U9 Q+ O5 e9 s L! s& rvoid MD5Init (context)
/ O U, W; A( d3 i5 c9 D7 x8 KMD5_CTX *context; /* context */
# x+ H! G) q, X3 s5 `+ R% z{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ) K5 b9 r0 E# j! ~. `
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; / C" j) t, D6 B4 U) j
} 9 @- @* b O. S% J7 g+ H+ d- G
A( |. u. {7 x, |4 [+ q6 }/ Y
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 5 x ?% i- s! A0 J! N' s
void MD5Update (context, input, inputLen)
6 h6 M3 n, S& D7 ^. P( \MD5_CTX *context; /* context */
% x& @) a' X( I% ^: b( zunsigned char *input; /* input block */
' s5 ~+ d0 Y7 F9 J; ~7 R* @unsigned int inputLen; /* length of input block */ 6 r7 h) K5 A# j% M! J
{ unsigned int i, index, partLen;
0 X6 o# @9 T/ M9 V7 | /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
; e$ ^5 ^0 H0 h# d9 x/ @4 i4 q /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|