|
|
#include "global.h" 7 i4 K9 R5 a# i
#include "md5.h" $ u, H) o* N6 K6 B
; a. b- s2 T6 I% @/* Constants for MD5Transform routine. */ 1 k& k. Y9 W0 ? v$ M
" x+ x5 ~8 C( W c
/ ?' _6 q: d# Z2 H7 g9 a( [: N#define S11 7
7 L" K; d( A6 z9 a; x% `#define S12 12 * [5 f- p5 p4 E Y* `
#define S13 17
+ l3 n. b: G L, W% N: P#define S14 22
9 G/ H6 y9 j* n/ T! O#define S21 5
4 ?" P4 ^& w8 C, D" W) Q: [/ X#define S22 9
8 m! Z7 W) |. ^6 L#define S23 14
+ i# W) ^7 ?3 v' T; Q9 g- u#define S24 20
5 ~5 z7 r, v) Y( P% K7 i3 P#define S31 4
! Z0 T; m+ H0 \4 b8 a9 \#define S32 11
: ]" S; A- g6 t5 N/ ^+ G#define S33 16 9 L7 R( V% e- y/ b! \8 I1 ]! y7 F
#define S34 23
( @8 h$ L# Z$ v! v( e: Q: Z; w#define S41 6
u, m+ m; U/ @; @8 W. J0 X#define S42 10 1 X; m, f, k- }+ g) M {
#define S43 15
. U U, f2 U: D" Q- Y#define S44 21
( @3 B& c- E$ B 6 [8 p" z8 J# z; K8 u
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
" U; M Q) P; D. s K0 ^static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
7 {3 u' f" |9 U/ T# e9 K" Rstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ( ^* @6 Z: w; [0 p. \
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); $ Y2 [; U7 M7 m7 V( s6 q1 [
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 5 ~& V' n( j0 b
4 L8 C$ P6 W3 G, w7 e
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
3 ^9 p0 V( V: A% _0 j};
: d1 j3 ]6 z/ w 7 j0 _* M% E( b) _
/* F, G, H and I are basic MD5 functions. */
3 ~. ]4 p; m( `8 Q, W2 O#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) + i3 ?1 Y5 Q% k2 v7 S
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
; {; E( l% ~3 _) k1 u% Z5 ^#define H(x, y, z) ((x) ^ (y) ^ (z)) , M3 P' r1 T' o2 H, N
#define I(x, y, z) ((y) ^ ((x) | (~z))) - D+ f7 o3 U2 ~3 ]" O' i
/ g) q3 x0 f6 M9 \6 b+ R% E
/* ROTATE_LEFT rotates x left n bits. */
" e/ Q' R0 k; } e% `, A ~#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
- Y8 I# e. c, ?, A2 `5 p
8 [5 P- j7 |. _7 u) m) U8 @/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
' W! e! V' p8 @9 `' g3 \. P' oRotation is separate from addition to prevent recomputation. */
, `8 p5 Q5 {( t/ _#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } " v0 x3 n: r; H4 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); \ }
/ r8 N# N* u6 a! _* r# ] U#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } / `3 T5 K' j Z/ u5 x) i" R
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
) q+ @) e; {8 L' J, H : k, X) q$ g. y7 Z! ]
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 9 {& B' A+ Q; F# a, o( z3 H
void MD5Init (context) 6 k: e6 Y) A% Q
MD5_CTX *context; /* context */
, n! _. d$ k3 h, x2 o4 }( U7 S{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 7 j& \# S9 C5 t
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
" U) K3 t; |- r% p$ I$ e}
2 [* ^8 M. x. A/ i5 h * `; ]. Y! n& {# n6 o2 R
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ ! u1 D Q4 x9 |! N) t; H
void MD5Update (context, input, inputLen) ( ]: d+ T' e0 y7 f* n' V
MD5_CTX *context; /* context */ * X4 W# B! [ b5 O# c+ W
unsigned char *input; /* input block */
1 n3 d: U7 ?' |7 q3 b- ^unsigned int inputLen; /* length of input block */ $ k' C y2 ^5 n$ r3 i/ Y
{ unsigned int i, index, partLen; ' @: J9 C- T+ x( b9 a, U
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); # ]+ N3 \5 Q5 I+ M W- y! Q
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|