|
#include "global.h" ' g& F$ ^! N" Y# L3 |; m% O& A
#include "md5.h" 7 S$ b6 E& `7 I$ a
% J+ `7 C h5 D, b c
/* Constants for MD5Transform routine. */
0 T2 X: Y0 E& l( Z 3 L0 G1 v/ p. a, K+ T
, Z3 \7 d5 {4 ~* @2 b
#define S11 7 0 d* b, M# W9 j5 [
#define S12 12
" l A# @% y* f2 P) J* X" M#define S13 17
. i4 h8 D+ s$ v5 E#define S14 22
$ v+ t# z. r$ `- q/ E+ ?5 e( \#define S21 5 ' i* \) j% y+ m2 d/ [: G4 i% |
#define S22 9
1 b% Z! m g% p" G! L#define S23 14 2 \% m7 R6 y% l8 V
#define S24 20 - G! @7 t/ U( |
#define S31 4 3 P" D7 M) A1 _" v
#define S32 11 ) E! y" G! m6 q8 B- Q
#define S33 16
. M) W6 J- [2 I8 I* ?7 _6 X#define S34 23 7 Z% P% c3 O5 N1 o4 H5 H: Y0 N' s7 r$ H
#define S41 6 % W4 J% S$ {' L, a
#define S42 10 6 }7 S; [7 h0 B" n h% z: ?
#define S43 15 8 O0 Z0 N |- S- b
#define S44 21 ! U6 p4 m. A# O* c' V' `
) u) [$ U* K2 N
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); & h! J. Q7 a9 {3 a- e/ s$ D$ ^
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); " }5 ?$ U L0 l- B
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); * w1 U/ c f1 }) A5 N
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 5 t# Q& q3 W$ l: ~4 V2 O0 |
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
3 f; N- P i5 C- x5 {5 W; r ; f2 i6 V2 m1 N9 G, [
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 $ d ?5 Q7 ]1 u, {, Z7 ^6 `
};
# p- O6 `# E7 E 0 w8 t5 U- z' b' \
/* F, G, H and I are basic MD5 functions. */ + _# s* `+ E: T4 r [: Y3 u
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) . W( P' s- `; A1 e( i' n* S0 i
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
1 l. m5 d w& M% L9 _& {# h: J) L7 T#define H(x, y, z) ((x) ^ (y) ^ (z)) ) b8 K) X" N1 ^8 v
#define I(x, y, z) ((y) ^ ((x) | (~z))) - Q2 [( R6 R' Y! M! H/ h B2 V
_! n. T6 R2 l" G; f/* ROTATE_LEFT rotates x left n bits. */
* @' X( M* N D; P! \#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
6 T% y/ ? z P3 ? - y" o9 |/ X2 l
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. % A- N& I4 r; c2 S9 U
Rotation is separate from addition to prevent recomputation. */ , ` J3 D+ b$ I9 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); \ } + L$ S* @: C$ x' k9 Z
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
( v# Y8 n# V" g- \7 p#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 D5 {, r! `- I2 e
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
: m) r; v+ x4 @- k7 d1 Q5 q
8 ? e. I; e6 e; z! |# v+ d. p! b/ I4 [/* MD5 initialization. Begins an MD5 operation, writing a new context. */
" q( v- @7 y2 V' V' E5 c' Vvoid MD5Init (context) & B# O: d' \9 B' M2 ]9 Z
MD5_CTX *context; /* context */
4 e! K/ z C8 m0 I+ r3 G7 E6 @{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
1 r. d i" `: a7 X/ o) w% r% o*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; : f0 N" c! d; ?! f/ ~" c/ R
} , Y- A4 `& W' B7 {9 S
6 F5 ?8 l( ?; y; d
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ J, j& m" P k! }. |; [1 u
void MD5Update (context, input, inputLen) ; g7 L e' b. o, L7 F8 Z
MD5_CTX *context; /* context */
- y- q6 F' f+ f8 H' W0 ?unsigned char *input; /* input block */
& M+ ^6 D b1 d3 R) x: Yunsigned int inputLen; /* length of input block */
u E2 O& o' j$ T2 m* v1 d{ unsigned int i, index, partLen; 4 m l6 k) M" q7 E7 e
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); * ?' h" @7 @7 E5 _1 z% W' A
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|