|
|
#include "global.h" 0 f6 c6 p6 M1 h5 l3 Z
#include "md5.h"
' a7 C9 ~: G4 M/ b* ^' S& j 6 I" `6 P7 z1 b8 U3 l
/* Constants for MD5Transform routine. */
$ o+ T A$ [+ T. j
1 z3 q1 ~9 b5 A* m( U& E
+ C4 N. m8 j9 G# `# e9 t1 N#define S11 7
6 `6 V( K- I! { Q) }#define S12 12 8 q; q5 Q# {' N! p2 c+ W/ V
#define S13 17
* g/ ]* T6 [, Z2 K#define S14 22 ; J3 P- h% x/ v
#define S21 5
/ h! x, `2 Z- B" p1 _ S#define S22 9
( e" q6 I5 X* i# y/ X#define S23 14
! Q& q' s) S3 g" H% ~$ s#define S24 20
6 ]1 }3 [! f0 p7 ~& `0 L#define S31 4
' M# P* o2 }" ]" R0 j#define S32 11
$ o- @/ g$ s3 L' y, u& |1 |#define S33 16 * v- w( z) x7 \3 K0 D
#define S34 23
' ?& G' H0 D' e+ c+ R- `#define S41 6
0 B+ f1 o' ?+ e#define S42 10 3 H5 J ^, `3 ^/ r# Q( X
#define S43 15 N Q: H+ ~* X4 \6 o5 T, S E8 ?
#define S44 21
. _7 o5 ^, }) j1 ?7 L; F
" c- s. o( D5 P3 L" tstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
1 d: q7 U% [1 r% o8 Wstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
& h, P1 N& H' D* U! E+ @static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
8 ^+ }$ i8 @3 k; r+ M8 }/ M2 q, ]static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
1 o" {* F) A% j. J9 S$ q' N6 T. ^& jstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); + t3 m# l/ I0 l3 d9 D9 a! ?2 |
: b- B2 Z! U* B7 R: E8 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 0 b- K* T, G, q+ Q* k5 [5 r
}; ( b' `: @3 v/ g1 `( Q
& o3 C3 Q7 \% N/ {% y/* F, G, H and I are basic MD5 functions. */ y% R! E# u; C( G
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 2 r" t B: C9 @
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
4 p# K" C4 J! g# L4 t+ H#define H(x, y, z) ((x) ^ (y) ^ (z))
5 x8 g3 Q p1 Z#define I(x, y, z) ((y) ^ ((x) | (~z)))
% ^, b7 {# A+ D+ q7 ^/ L8 z1 b . K, N' N. e* l, P
/* ROTATE_LEFT rotates x left n bits. */
6 I5 X* g: Q8 C#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 9 R7 K, Q2 b( P% F5 _
+ d% j: _ S+ B8 {. ?. j, f/ r" x/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
9 z, @( ]5 R2 a! B+ ~Rotation is separate from addition to prevent recomputation. */ ) E# Z4 ~% |1 i3 g- J; |2 u/ S
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ! |3 n( ~0 v) A
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& ]/ l* t4 r, e! `& R! C- ]; A#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
5 R- t+ X E2 q" e# N: [: K#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
( I4 {/ v3 t4 J8 b7 y9 B# X. ^
( X# c# ?9 f; |$ Z" w3 L/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 9 B5 X' x4 p3 F7 ~' R
void MD5Init (context) + ?% K p [- X, a! W9 D% k
MD5_CTX *context; /* context */ # a/ O/ H) n! u3 ]7 z+ g. a/ X" V
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ) Q3 {7 l2 @2 w3 C) c- f$ D+ z
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
/ ]4 t& P. @/ c2 P1 v} + V; m. E/ ^& s5 @
) h8 Q: d) p1 w+ P/ y2 ] z/ p
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 7 ]8 q! |5 F2 W1 [0 D. R
void MD5Update (context, input, inputLen) * K# {7 v/ a3 ]! O0 i1 U r, Z
MD5_CTX *context; /* context */
2 D+ X6 Y! E; G* ~6 y% x1 funsigned char *input; /* input block */
6 i. `3 |0 E) O, ?- }- ounsigned int inputLen; /* length of input block */ $ I5 M! n+ Q) G
{ unsigned int i, index, partLen; " v! w+ M4 Q6 s2 a$ {
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ; y3 T7 U0 z3 H: Y
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|