|
|
#include "global.h"
5 D* S' p1 L i' c0 A. ~#include "md5.h" * ]* t6 Z7 d ~7 D
7 T$ ~! I2 n' j! g. C1 M7 ~6 D2 M/* Constants for MD5Transform routine. */ ! N5 S: ~' _: N
3 L1 `* m2 I+ f* t" i
/ Z" W2 N% P6 [# K/ Z: `0 S#define S11 7 ' p# S& h+ p9 l2 s* Z0 M$ P# K
#define S12 12
; q% @1 R9 X8 U, s#define S13 17
$ a# z, ]# m* w$ Q- D$ J2 n#define S14 22 % T0 a' @: ]; T. I& w
#define S21 5 # F- q: T- U- w# V: M/ e
#define S22 9 4 B1 f# p! e+ q( G
#define S23 14 ! n4 v- d( S' t5 ^( @& ^
#define S24 20
/ T3 d4 }# ^7 o" y: T; s2 t1 \) G#define S31 4 ; M) a, Y, [ h/ p3 b- Q
#define S32 11 6 e$ F* E( ^0 [6 t. c& j3 U* ]0 |
#define S33 16
2 e. m$ m4 M9 \- Y' k! H#define S34 23
3 I( G$ b6 W% W#define S41 6
& w9 Z f% Q( W% H$ _9 t4 F#define S42 10
" s& \( K% U: D9 h9 Z2 ^$ m7 F#define S43 15
6 Y8 o- H% O0 B' I#define S44 21 ' c/ t# [7 D0 ?: X$ X$ o
8 L9 T% j6 {: B% c+ {* }
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
5 H( m. \8 Z8 x) |& qstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
8 ]& e3 `. G7 A e! Tstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
6 \8 i& A0 f7 |! b/ U% d- z1 nstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); ' e7 P( ]2 R, {- Y
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
1 }+ Y! b" I! v0 N `) ?
! j2 g {5 m' O. z- Bstatic 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 , C) `2 B: h0 x" g5 q5 L
}; ' A! U* \7 Y) p3 d
7 p i% J- Z) D6 m5 V K- q4 D/* F, G, H and I are basic MD5 functions. */
8 l) c7 b' h. C& T#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
/ j. e$ n$ u) ~: [, J: r( J#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
1 w5 S6 F9 w" e- d) P$ a( n#define H(x, y, z) ((x) ^ (y) ^ (z)) ? \" f# b$ i- Y$ P
#define I(x, y, z) ((y) ^ ((x) | (~z))) & b9 O% z$ v6 K2 I
9 m/ z. u5 t' Z
/* ROTATE_LEFT rotates x left n bits. */
4 m2 c& C% ?: u. T, Q#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
' b) d5 ~, ~. T [; `9 M ; h7 ~9 m. }7 n: d5 u
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. / H8 k2 M: b; ^9 {: V. B
Rotation is separate from addition to prevent recomputation. */ . Q5 j1 {3 M* T" f' c7 A5 N
#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 m% o. A6 |; V1 h: V9 G#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
' r5 `# x" h* T. t3 m& @7 S#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
4 y! W# Z. c7 z/ c& I& W' 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); \ }
3 U* g: i0 n X + J4 y: f3 S) q! l/ I
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
& J. o$ }9 L4 b) ]( ]) U2 I4 Z1 `void MD5Init (context)
1 ?$ s4 z5 @: m3 C! L1 NMD5_CTX *context; /* context */ 3 K; h1 c) n$ L3 i9 k
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
+ q5 k4 F: W' n& K8 w*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
# v9 a* e8 ^* f U9 `# @} 7 `/ P. v/ u x: _& g8 ?' l2 x
6 C2 ?9 [" @4 c' N
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
$ J9 S$ ]' Q8 {8 h. ?) dvoid MD5Update (context, input, inputLen) G+ f+ V8 D" _ z5 y
MD5_CTX *context; /* context */
?! k d7 j% G, K, F5 x' f5 uunsigned char *input; /* input block */
s8 p) c( L8 ]2 X8 P; G2 A% B, kunsigned int inputLen; /* length of input block */
7 Y1 z3 ^: f, O2 a; |{ unsigned int i, index, partLen;
' C9 f( s1 H4 @3 X6 T /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
8 F+ K" b. s; W0 a9 V /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|