|
|
#include "global.h"
7 \* C/ k8 D- ]) y* f' S! n4 l#include "md5.h"
6 t; H1 D( Q- w) P& h! S [# x* F
& L! h3 g+ X* B. C7 h% y$ I/* Constants for MD5Transform routine. */
( } V7 v/ i' ? Q: p: i3 u: G' ^ ' }; J1 B# ^) n) S9 b K
8 F4 z5 E0 [, l& F1 @5 x#define S11 7
% I6 Y3 P& r7 o0 B/ F+ z) b#define S12 12
K% @* k; G \( k#define S13 17
" V1 t; E% o' F6 o#define S14 22 " _* [' A& \ E" R1 I Y
#define S21 5 + f c: g+ }) v
#define S22 9
8 ?1 O0 G2 A; }- ?* L {4 h# p2 W#define S23 14
! C M: \0 `2 H9 I# q#define S24 20
% N( W/ j& e/ ^+ h; D3 V$ X; q( _#define S31 4 # r: H2 t( Z, l" o. b9 B
#define S32 11 # h) x" J, x; u2 d
#define S33 16
8 q3 C* N! v0 X$ P1 y2 `" z0 ^! t#define S34 23 " K6 g2 z+ n: K- J
#define S41 6 # ]6 b' s" d" Q6 O9 ~& S; F8 g, h
#define S42 10 9 O0 w7 r( d( Q4 }3 H3 g
#define S43 15
0 b! b/ H7 }% Q/ y( ^#define S44 21 7 S0 r0 s8 p. h
" N% g5 v/ k, V" e' [2 s9 Z0 B
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 5 H1 v2 t, p& \7 m; `
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ) }! V, I. b+ `0 M" T
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); . M; G+ m# P8 W
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
9 t6 H1 |1 C; z2 Q4 I3 S+ E( ]static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); . A v5 y$ b1 T/ i) Y. i2 E5 T
* N2 p: z H* G- c3 i
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 % K& w- a5 E/ [3 W+ `3 ?6 I0 \
}; % U6 v; r. j3 {" _; Y9 N
- U2 r' ]7 i' P) Y0 \/* F, G, H and I are basic MD5 functions. */
$ }: v, @6 _8 m9 F& a#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+ U2 W) [$ ^9 ?4 [ t4 O1 G#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
3 k& m$ Q- x1 @' v! _#define H(x, y, z) ((x) ^ (y) ^ (z)) ' F9 M9 }3 H1 r& i' n! r3 J8 A' t
#define I(x, y, z) ((y) ^ ((x) | (~z))) ) P2 u- I* }/ ~9 n7 S& P1 U3 w& L
1 _0 T% `: R' u; k6 M2 h2 [% z6 b9 F
/* ROTATE_LEFT rotates x left n bits. */ 2 ^8 `6 P) t% B3 K# W
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ! F1 E0 ~( k5 h
3 `0 _9 ?$ I! l% K' L
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. , v5 m# Y- F- V, l5 A( i! a! m
Rotation is separate from addition to prevent recomputation. */ & K) \1 \' L+ Q5 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); \ } : i) Z/ S( C. x: h G1 u" q' K
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
/ z. `* q5 B3 z#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
# S* C( P6 f7 U6 t/ M) Q#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ) x; A2 p) x8 T( y" l& g( u
9 \! M( a5 a- {# L/ U
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
! X- b' O3 _9 I$ d9 s. | `& Y9 [8 kvoid MD5Init (context)
/ j2 `- N& d* b1 V% g3 i+ LMD5_CTX *context; /* context */ & x$ I+ y( M; X
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. * S5 @2 V+ E( w1 S% n/ K
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
: B( v3 l/ [ p/ Z6 B6 z} 4 D2 e; \3 M L
T! z: ?3 Q/ w/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
# V; K, Q0 i- S& E6 _3 L& Hvoid MD5Update (context, input, inputLen)
# {, n1 w9 N+ h1 Y1 a1 ?- hMD5_CTX *context; /* context */
Z% a& L/ _" s! {9 p3 j- zunsigned char *input; /* input block */
7 I2 [/ e* i$ O+ H6 f. kunsigned int inputLen; /* length of input block */
4 X7 M, U8 \* w! m# ]3 e{ unsigned int i, index, partLen;
5 N4 [2 N1 T3 ]- ^, \ /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 9 X1 e* ]# N1 s W x+ |% h
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|