|
|
#include "global.h" ) E) i) A" R4 d: j
#include "md5.h"
4 g% l9 ?6 o0 l; k& e6 G- h8 v" Q4 ?
. M% z1 ]) a) J$ _/* Constants for MD5Transform routine. */
! M) d. U9 j' h
! X% j9 q0 m0 }7 ~ * h6 A& {+ D( h& c/ `; o% b' H o
#define S11 7
6 M( }! p' j' a. ?$ x#define S12 12
& W6 q: e4 m" v: `# ?#define S13 17 - }! E8 K$ E d: I% o
#define S14 22 " F( @3 `5 [7 O3 I
#define S21 5 9 ?2 j+ b# u/ R. z1 {! Q6 @5 u* X) X
#define S22 9
2 O" F6 d6 W' }#define S23 14
$ _9 U% A+ _$ x#define S24 20
1 x) q2 y6 t' @: V#define S31 4 q* N8 D8 |7 s2 X2 z+ e2 V
#define S32 11
. l2 d0 c+ }) d( p% R#define S33 16 $ @* c$ d6 j( \
#define S34 23
6 @) r* {3 m/ ?" K#define S41 6
4 Q) v' M/ o$ g: z3 f5 C! c' _#define S42 10 0 t) u7 i% T+ K* C
#define S43 15
1 E6 D/ u7 s- ]( A* Q#define S44 21 / y1 h1 I2 d) M+ d
. @- S5 k" \+ z. O& F! k2 l) \static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 2 {! O( G1 V- `9 ^1 f+ t* ]4 f' V
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 1 A2 K+ M9 {$ ~) N4 A# S! g+ B
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
9 A' M- H/ z% e' w6 vstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); ! j' ~, Q% C- _. y
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
2 Q* h" E$ L- Y' `6 e" \0 t M% K
* M! W! i1 r7 Ustatic 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
4 j7 `1 D! b7 Z6 a; t7 N}; + l" n) s$ s8 [% K5 _
9 S S5 c" R* y8 n
/* F, G, H and I are basic MD5 functions. */
2 S: v6 I M+ t6 b/ p- X#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) " W) E. w+ {, b, q% `+ [5 j3 u$ @3 l
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
5 E( X) S# t7 ^3 @4 g6 _* ?6 h4 U8 V#define H(x, y, z) ((x) ^ (y) ^ (z)) 6 H/ f) {; _, x0 o% b: |1 x
#define I(x, y, z) ((y) ^ ((x) | (~z)))
2 l8 G$ l3 o! X2 G* i( c$ J2 t
: D# `; ^% G$ `+ m, y! K; G2 z0 e* e/* ROTATE_LEFT rotates x left n bits. */
0 p& a3 p3 W, A9 q#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
& T. g1 L# S$ L# e
9 q+ L8 ~! c" V2 G3 x9 q/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 0 {, f- z3 e) s3 j, o8 P
Rotation is separate from addition to prevent recomputation. */
# S, t% _# }* W1 P#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 }" c& D& Z0 r D
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
j& K' ^$ g. j1 p# u1 _#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } * O8 |8 x4 H( g4 i0 j0 T8 ~
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 8 A: U& e4 l1 F& h9 T" b
/ j( e Q9 f: A+ G/ E1 }' X/* MD5 initialization. Begins an MD5 operation, writing a new context. */
8 R ~% u9 N$ k" n; \2 Avoid MD5Init (context)
* X- X! m- y+ SMD5_CTX *context; /* context */ ) M' W/ ?7 W# P
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ( S J$ @. D- F: c5 Z I
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 7 r' u6 u$ p; Q* b2 _1 j
}
Z9 G; s8 Z% C, D- S # e Z9 j. k/ t7 B8 \
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
5 g# g m( `" r+ i! O/ Rvoid MD5Update (context, input, inputLen) - }% ?) F6 j' s8 s/ ~: ~, V* `! ]
MD5_CTX *context; /* context */ 2 ?: E3 R L/ \3 ?. I& w- H9 V, X
unsigned char *input; /* input block */ ' \* b& w' u4 ^0 r4 A4 v" B% ^/ K
unsigned int inputLen; /* length of input block */
C3 o1 P0 V- {, q{ unsigned int i, index, partLen; ( H8 }1 i) T, u) @
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ! C1 j/ L! t: Y8 k6 X2 k- ]6 \
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|