|
|
#include "global.h" ; x$ ~1 u" {4 {
#include "md5.h" - q5 h% W: h- Q& m$ O- u3 L
$ i w' w; v4 R8 @* o/* Constants for MD5Transform routine. */ 8 [5 O. P l" _# X1 W2 \% u
2 V( H- e$ ?5 z O) m
4 t6 G8 e' U/ W6 ]- s' ~9 h
#define S11 7
3 E% @9 r% j8 t+ \; z5 m#define S12 12
! N9 r Y4 X# a* O% P% O% W#define S13 17
: Y1 \, ^, o9 O#define S14 22
! Q( ?/ m/ i& \, d R1 \#define S21 5
$ P* A/ P1 y' F) n: ~9 u#define S22 9 7 B! K7 R# h. M( U& p: z! e; @$ U
#define S23 14 * Y9 N: J4 s0 l
#define S24 20 9 R8 J; p1 \3 O& W
#define S31 4
4 h. c- ?+ n, r#define S32 11 ! r* J- M2 g4 I1 ^! K% h' S! b" W
#define S33 16 ( Q# f, ~2 L& W( n
#define S34 23 : d# j5 l0 ]5 i9 R
#define S41 6 . e) {* S# {6 ?
#define S42 10 1 A; a- k6 J* G0 \1 r8 Q" Z+ \
#define S43 15 2 Z5 Q2 d9 C" y( [) n- x
#define S44 21
; B" y! p9 t$ g1 E: u" B
* K* F* i0 `- }static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); + @+ ?7 l7 O; b" c: d& V5 O
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); : A/ e" p' z( m1 U0 J# K: i
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
4 z; ^- s! N9 {static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 9 }: T) C2 G: N9 V. ?. P
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 8 P! Z5 p% ~" }. ?! w
- T, @ t, [3 @8 x) Y+ Ystatic 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
; P% |- a. R6 i6 g4 T# E}; : T4 D% S; F4 Z& u+ \. V
5 @% A( d! _7 \4 N r/* F, G, H and I are basic MD5 functions. */ 3 V8 e9 ?4 e3 i3 Z
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) $ H# c- L- a9 m l; H
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) % B6 e$ `0 H% x
#define H(x, y, z) ((x) ^ (y) ^ (z))
3 B% }/ _. T9 ^6 X4 ?#define I(x, y, z) ((y) ^ ((x) | (~z))) - t. i; ~7 S- w/ B C
" @' X2 f1 ~4 ]) Z
/* ROTATE_LEFT rotates x left n bits. */
! s- M4 Q, l5 |) N7 Z#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
) D& B4 c( v P 1 R( `% o" q- t2 R. e
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
$ c+ |0 O' Y. M+ y t4 f1 ~! Q1 _7 Z2 pRotation is separate from addition to prevent recomputation. */ % D5 Q+ C; D0 K
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
5 X2 y X4 S3 V, H#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
4 X7 ^+ Q* j; g#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ; e' D3 n y$ `9 H
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
l; R9 {! P5 a u( ] 7 V4 _ R& d3 h
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
$ v6 c6 g8 y1 m0 K4 P0 p: Z+ mvoid MD5Init (context)
# d% V8 U9 _ y, v* A3 JMD5_CTX *context; /* context */ , D1 D% a B' p$ l+ e b( f
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. $ k g, t( Z& Y
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
7 T1 W& x& i1 P; Z/ N" Q" @}
( s U2 T7 `) I 1 ~0 {+ Z( i3 X I, K( p
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ $ Q& }. p4 F. B. r0 {
void MD5Update (context, input, inputLen) , H7 ~2 W1 a3 }$ M z- {
MD5_CTX *context; /* context */ ) y! W( u" q" H6 T( z0 j) Q
unsigned char *input; /* input block */ " S: \1 S- S4 ?- b9 J$ D
unsigned int inputLen; /* length of input block */
* b+ ^3 B+ w$ N7 c{ unsigned int i, index, partLen; 1 i P# A& Z( u2 h. K
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
/ e) e9 A: @" w! g1 ` /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|