|
|
#include "global.h"
4 `4 G1 k* K# E; M! N0 F#include "md5.h"
; A6 A& [! t% f+ B2 H' @- V9 P
- b# E6 l# x$ O/* Constants for MD5Transform routine. */ X( C6 u% i! C2 H
1 d& h: H& ~' ~$ F( r6 ?- |2 C
( e n- z8 V: f! I- {; t/ ]#define S11 7
2 u N2 h v _. d#define S12 12
( \0 B9 X! i; {#define S13 17 5 f) a2 \+ \( C& j* Y
#define S14 22 1 L k- k7 I0 i% l& A5 {; |0 s
#define S21 5
2 ~( R, k$ h+ O8 M& ^ |1 L% o#define S22 9
! ?6 R/ u& N3 E2 N#define S23 14 - h0 I. ~0 v1 I" _. M
#define S24 20
( Z4 w/ o: r9 v9 H4 y8 ~; b1 C( v, G#define S31 4 2 ^8 V4 w* `! {6 f% K
#define S32 11
& ^7 F! C7 L @3 I6 S+ H2 Y#define S33 16
# t; l0 C' [6 s$ G2 }; q#define S34 23
5 G" q- A, u3 H" ?6 N3 S* q#define S41 6 ( G+ X3 \ R: V0 z( o
#define S42 10
1 D$ A! S9 p [8 m#define S43 15 $ V j" @: y* u" I
#define S44 21
% C# I; j+ q4 ]1 P! F5 q % ]6 W& e0 l9 s
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
% L/ p/ f4 B5 @9 g' ?" zstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); " b0 w; w6 v6 F2 {' O9 D" |
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 3 D* h: j' d4 Q+ O- w# M# W
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); + u5 S4 o; ?8 _' g1 }
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
7 g9 _: H# m. ` " U) p$ u/ c# P
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
7 k+ l* N% }' P% I, d" Y' v};
" d% I& F! U4 S5 N6 @ 5 O' D& [) K6 F3 b7 o! n3 L$ o
/* F, G, H and I are basic MD5 functions. */
2 g% ~2 d9 x I7 I#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) " h! u6 H I9 ^( L* f
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) # m3 W9 h% M3 W$ t2 w$ U) ?
#define H(x, y, z) ((x) ^ (y) ^ (z))
: V& b) K1 R, A; L' d' }) E% d9 C#define I(x, y, z) ((y) ^ ((x) | (~z)))
& [" _ {. o- ?6 w, I: b+ e 6 C* Y) b# B7 @1 e5 j- ]
/* ROTATE_LEFT rotates x left n bits. */ 6 k) x8 n: X( |7 \
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 8 D: s6 a% ^3 m6 A$ t: F9 ?/ V) k
& _" u# }: x. l7 B7 H/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 6 p& ?6 p- Q/ [6 Q
Rotation is separate from addition to prevent recomputation. */ 3 r4 g0 Q0 Z# r8 ~- Y0 z: ?
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 7 G, Q! c% y/ }8 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); \ } . M0 m2 L! h5 \
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" J# g8 i5 T2 Z2 }7 v R g#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } " P6 M: _! M9 r% a9 n' N1 J
% W: n5 z: L# |# F9 u9 |/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 1 f, h5 T* S m8 H9 L
void MD5Init (context) - ]: z, p* c; U/ _% q
MD5_CTX *context; /* context */ + T. b4 S5 |; _3 M; O5 d8 U
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 1 m- w+ w- s. p
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
" g" z5 A, \3 Q7 M/ X: C}
6 J" Q1 p4 M$ F/ U0 D
. ^# o! r% Y- p6 g/ ?/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 1 O. g! H4 D' X6 U9 h! `
void MD5Update (context, input, inputLen) 0 W6 A: a2 I! w
MD5_CTX *context; /* context */ . b& y6 G0 _4 E. M( j* G" r* P( G
unsigned char *input; /* input block */ 0 ^* B) i0 B1 J5 H6 L" F# q
unsigned int inputLen; /* length of input block */
( o: E. v% d5 B2 \1 I4 ^/ \{ unsigned int i, index, partLen;
% ^ I0 [) t" b4 o4 Z, o /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
4 Y: W& K2 R& n Y4 A8 l1 ?8 Q /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|