|
|
#include "global.h" 8 ?) V, K3 ], c6 @2 L
#include "md5.h" & R: P, ~; t1 o
; K/ ]5 e% i" L/ q
/* Constants for MD5Transform routine. */
* ]9 j) C8 R0 l. ~/ k& ~% I; y
4 l! L9 q6 J% H, M+ {, J" C 9 F# u+ F$ h+ @) h; d4 b
#define S11 7 2 N+ @7 [ X. z# Q- I( g* K
#define S12 12
5 v- n; e1 B6 h# x/ c7 h `#define S13 17
p" d! Z$ C5 z: `#define S14 22 ' w' p. H' c5 X$ X+ T. Y
#define S21 5 D% U0 C4 G/ q- l/ ~3 \' k0 \
#define S22 9
3 i1 D; q' B$ ]6 G! u3 y#define S23 14 4 q6 z' ]' x9 v" J( v9 m
#define S24 20
6 |/ a6 P. o- l' s, J6 u `#define S31 4 " m, U. a. D$ b
#define S32 11
) z0 E$ |1 I8 t O#define S33 16
+ |% g+ D6 ~. e. R7 L5 M#define S34 23
5 C3 z5 y+ H- J#define S41 6
* K0 Y c' N# K8 E* Q#define S42 10 : [+ y$ y* ]# t
#define S43 15 $ L% c2 d3 B+ U' R6 c& j, U
#define S44 21 1 I1 R; s+ l( F4 q) { A
# H9 k% ~! D5 M4 `static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); + B$ e+ L& i, ]0 M# h
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); $ I& b0 R: G& ^; T, k, N( I3 m
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
$ [) W0 ?- k0 V2 h L3 Dstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
5 z' B4 }9 ]- Xstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
7 I3 B: L/ q! g
1 T' h. x- y! B+ t' s3 |- k& Estatic 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 ) x; H6 C4 b8 G
}; 7 v. L8 I3 y/ ~7 u) l, h# P
N+ |% q. G* T7 d
/* F, G, H and I are basic MD5 functions. */
% e5 D# I7 m4 ~# e1 A8 Y+ ?: K#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
* V6 L8 _6 {2 X. P8 Y#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) . y" w+ g7 X# ~8 |
#define H(x, y, z) ((x) ^ (y) ^ (z)) % @* f( D% v0 |$ X' b" R
#define I(x, y, z) ((y) ^ ((x) | (~z))) 1 N7 ~$ U0 ]$ D( H$ z2 x6 Q i
( ?+ |) }! v- F, P$ R- d
/* ROTATE_LEFT rotates x left n bits. */
) P3 G1 I- N4 A* C9 i#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 2 E- I& b4 K' p
- G- L; s7 U R& l( C- D
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 0 s; D: k$ _% {
Rotation is separate from addition to prevent recomputation. */
3 @/ F3 X& E- O6 G, E p& 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); \ } * V) q \) w* b; z7 @& p0 b
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } , \: P( ?9 B0 C! d) N5 z+ g G, Z* M
#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& X y {# M; P#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. u* {4 ?9 I 3 A9 ^) O A/ R) e
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
" s# G2 k% k* w9 x* v0 M. R/ u+ avoid MD5Init (context) + V$ W8 K2 }0 _' M: t2 D3 o
MD5_CTX *context; /* context */ / y- V) b% I! N
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
; |9 ^. X4 c/ @: F7 f4 d( b*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
; B# y" A% Z- `1 o* s% t9 P}
* _' f, N3 n! n# Z8 H$ p0 U ( J! ^1 m3 C, [* O3 u! H
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ B: R C g' z( Q# s7 a3 m! O9 D) {
void MD5Update (context, input, inputLen)
( U* m$ U2 P( g& C3 N aMD5_CTX *context; /* context */ ; e4 Y4 z+ U: N3 y% X& L/ a
unsigned char *input; /* input block */ + p- c# c( _! e4 n! {3 L6 `7 A
unsigned int inputLen; /* length of input block */
# T3 x1 m% |$ U" t T, E{ unsigned int i, index, partLen;
& J) \( B* ?4 Y1 _, }* v /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
4 a3 e9 l3 V! g- u4 V+ E9 B /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|