|
|
#include "global.h"
, }: L: B: z& x#include "md5.h"
# N" s2 }: Z: K6 R1 N% v
8 K0 y; s) Z$ z( x3 x, X/* Constants for MD5Transform routine. */
' y" k5 m; X& d: P: U 5 D' z! b8 n% O2 M. f
! j% b1 n& r5 _( {- T* v, y+ v#define S11 7
- B6 I0 G, t4 G5 G, ^; K( H1 B* R#define S12 12
, Z, }6 S% ?' U9 v#define S13 17
$ r% }2 R+ z" w3 k0 i#define S14 22
- G4 J" d, W! F4 L* s#define S21 5
. f! V4 m ]' {- x2 O8 j#define S22 9
( E9 h Y3 H5 d2 Z4 b( C6 r#define S23 14 ) D; t4 n# q* \) Q8 Y7 T- ]2 J
#define S24 20
0 F9 K8 }4 M. F; b#define S31 4
, q( L0 C) L- ^+ v9 D7 l% a5 y#define S32 11
1 ]& \/ b& R! v9 d7 i#define S33 16 5 E6 }) c8 m5 h2 b5 k
#define S34 23 w/ L3 w. J4 B* G( H( H9 X
#define S41 6 6 L' U/ c+ N$ ?+ ?( ]0 U4 F% N
#define S42 10
! w; V$ A3 t3 E* l& K#define S43 15 " N! d' D2 ?% I& Y9 E( H
#define S44 21
6 u* {, d- z, B0 b0 x! n: @1 s$ b 5 d; d( X) p# w# D* n2 o* f( [
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 3 j5 y- F2 W! n* B
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 8 w& w( e$ F$ ^
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
" r1 U7 g& D/ Gstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 1 V% J# q0 I4 L: R: X
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 9 W! g: N% O9 R6 M: T4 a8 u) Z/ J: T
- G L# { }1 `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 ( f. ^# M U' P8 h/ p% I
};
3 h8 q4 U+ d O/ X) d0 v8 }. W) |
2 ^- E) ?, o3 D' [3 O5 x* [5 D/* F, G, H and I are basic MD5 functions. */
! m+ B; q8 N9 ?9 D5 t#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
4 P- d/ E9 z' }" o! P7 k#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
" R' l& `* h, q2 w#define H(x, y, z) ((x) ^ (y) ^ (z))
. c1 Y( q% k; q' C#define I(x, y, z) ((y) ^ ((x) | (~z)))
; p2 e& @6 i( g" ] e2 s# X
: A9 K2 d9 q9 D- v/* ROTATE_LEFT rotates x left n bits. */ ; e+ d. J7 z. O1 G
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 9 Z- \! O1 \" { [. d7 d
# u( Q( \: z. L7 h/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 7 f; |0 S7 B1 ~. p9 G
Rotation is separate from addition to prevent recomputation. */ + C# z4 [% k$ j) J! b
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } # e: `' D8 n2 x
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
$ J1 |' c. l5 u' 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); \ } 8 G/ p& }, ]: 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); \ }
6 q2 W! ?5 m0 D2 T% h
: T& J2 F/ Q v0 o7 c( o2 V/* MD5 initialization. Begins an MD5 operation, writing a new context. */ % v; K B) h* R; c2 Q% X; i
void MD5Init (context) : U* c1 L8 W- u4 P2 H8 I
MD5_CTX *context; /* context */
" k, h; `& A- H2 O$ X$ l{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
E f4 [! B5 X! p" _*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
1 W1 s8 T0 H: V& t2 I' V! P} # m& @- I- o, ~9 \& y
1 R2 W9 R4 l4 \/ \/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ , \$ M) _% h; ~% Z/ a/ l' g
void MD5Update (context, input, inputLen) 6 ?) P8 N8 X" s" |" M
MD5_CTX *context; /* context */
& m0 p0 H' j& |+ ?, k, Y; funsigned char *input; /* input block */ ! k) \; f! q7 J5 A* ~
unsigned int inputLen; /* length of input block */
! V$ G3 I) K0 D/ j! T5 T{ unsigned int i, index, partLen;
4 F) q2 S2 ^1 a k4 T /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
P g% S! [$ _+ L3 g/ h /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|