|
#include "global.h" 4 Q# Z6 M W% @+ K
#include "md5.h" D4 A* x. D6 v7 I+ x- J7 G6 j
5 w# R1 i! H5 q$ Y
/* Constants for MD5Transform routine. */
( b; \/ g) Q" \6 k# @ 0 C+ n# D7 S$ @$ V
0 h8 a' o5 T3 M+ N. k% }: Q#define S11 7 & \2 E; x8 A% S( z) D. B7 q
#define S12 12
/ }$ n6 B& s# A1 g. D#define S13 17 9 Y9 b1 ~% x* `* B! i8 E: ]. N
#define S14 22 4 G& ~5 t) i& r" f/ G& j' B h6 ?0 p C
#define S21 5
( M* }- O1 K9 L) a( S* F#define S22 9
2 J. \* H7 o' k7 c5 |7 Q& f8 `#define S23 14
$ v) w2 n3 H M: T#define S24 20
, V+ z+ v' Y3 i$ g! F. M0 ^#define S31 4
4 s: T5 C2 H2 u! g Q; {#define S32 11
8 ]9 S6 l, w: Z& C! x% C) [#define S33 16
6 g; X1 F" D! y3 J; p4 q#define S34 23
0 L; r' @7 n% b% A# ~#define S41 6 7 Z& B+ a# o' x9 E o) I; ~
#define S42 10
7 W% D- F& N. Q6 z#define S43 15 X! T: X' f- L7 [
#define S44 21
* b3 j: w. n% }" i3 O& p* M0 h
: g0 Y0 s" p# k7 p1 Wstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
; _; `9 f6 y, t: vstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
% a/ a0 C* t+ m7 Fstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
" V( D' S9 n4 ostatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
+ s8 p/ i+ q% X* O$ e0 dstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
' ?* A3 `! ?3 e
( G5 K7 T6 v8 Z+ b: U/ Ostatic 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
, @% U2 g! ^# i! U& F; K}; ; @8 y! V0 y9 L, i% C( [
- U- ]: T2 U/ M8 X0 X% O/* F, G, H and I are basic MD5 functions. */ / u+ R; _: w p: {2 m/ P/ v
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) : |1 K0 i1 L( O Z3 R2 ` M( f5 v* j
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
. k, _6 ]1 z: m. y#define H(x, y, z) ((x) ^ (y) ^ (z))
5 b# |, z+ r1 U/ D#define I(x, y, z) ((y) ^ ((x) | (~z)))
- M4 y% K5 _' u- {6 P; c 5 A0 O* _- g$ }! w2 r6 e0 l9 ]
/* ROTATE_LEFT rotates x left n bits. */
! Y0 M* l5 k/ u' c9 G! W#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) $ i( ]# a# g3 E( D$ Z, t& e- D
8 Z& D5 J' u; t# e/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
- O; C# R$ k' G9 Y3 {) l6 dRotation is separate from addition to prevent recomputation. */
6 | m9 p L# 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); \ }
9 ~) c) }# P- O% p#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
7 k: e4 a4 o1 r/ \; J0 n( 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); \ }
0 e: W2 q% k3 t% {% E9 Z) j# v#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } - [, f* m+ l0 R" P
3 I# [. }. Y0 E# }# a- g/* MD5 initialization. Begins an MD5 operation, writing a new context. */
. J, k( l" I. _: A- Bvoid MD5Init (context) $ j. l8 L, w8 Q' C0 b) ?$ L
MD5_CTX *context; /* context */
6 s, s- ]6 A- F9 l" W! ^' t" ^6 z{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ; L0 I9 e& v0 f8 F) P" C2 F
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; & ~ K8 F' s) ^" @
} ; d' m. b- t! z- V# V" u
9 E7 ~ U1 Y! y, }- [
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ M2 X% S# n3 |/ ~9 B! x! _3 t
void MD5Update (context, input, inputLen)
4 _4 P! `& f7 _MD5_CTX *context; /* context */
9 K# g) b" K6 j2 l1 Q, kunsigned char *input; /* input block */
w9 [& J/ e+ g5 h* h/ kunsigned int inputLen; /* length of input block */ % i' ?4 D% q$ V' R# I) B8 w: P
{ unsigned int i, index, partLen; 8 z: T' j8 t! v3 K+ |8 c( S& x6 B
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 4 s5 W8 k( k3 Z( T6 T% J5 q& h
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|