|
|
#include "global.h"
. ~7 L9 Z j: \3 _3 P3 ]#include "md5.h" 8 p' R$ G8 r9 o) G% d7 d; F
& h2 X4 m: H) J$ g
/* Constants for MD5Transform routine. */ ; `2 W2 _& Q/ d. l0 F( W" Q. G5 ^
; K2 W v9 g4 \) n8 B C/ w$ y& a
* b0 T6 b" \$ S1 h) }#define S11 7
% e2 J) B0 o b9 n* K9 a8 T8 V#define S12 12 9 X+ }' ?9 ?; V9 ], b7 y
#define S13 17 % ~* V( Z8 x3 O$ g- u
#define S14 22
. Z5 Y3 a- b9 U4 N, N4 ^#define S21 5
1 P0 b' o z0 k#define S22 9
) t& m( o& X0 }) n4 x+ w7 D5 y#define S23 14
l) B# x/ Z; q#define S24 20 9 C0 `: R# ]2 B' r" K7 C
#define S31 4
, t5 O. o9 K. i& v0 H+ c# ~% f& V#define S32 11 - {* n7 E: j$ j q+ B* z
#define S33 16 ( P1 n) u, j6 g; v
#define S34 23
6 {! k/ w/ s) y" t9 e#define S41 6
" Y4 u- `& Q7 o+ l) C" ^#define S42 10
! F. V) N1 `7 p#define S43 15
1 b F% Z: [. `$ M& j#define S44 21
: m' k$ _. O' U; ?8 w
" L( |* M7 Y" ?& K3 estatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); ' s7 i: a) M& c- U
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); & K2 ?3 n+ k0 D1 \2 V2 V+ t1 I
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); / M* h B* q c
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 9 N3 R' U; V2 u6 o1 [& d) d
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ; i. C5 b, c% G1 A1 C% n$ O
( U( ~ F8 Q2 m8 `
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
+ j9 T' x5 M9 Q7 m* W* x8 Y};
" n, t2 B! h# S# |( y% z, | % J g/ ?6 b: W3 i0 ^$ d7 |% G T
/* F, G, H and I are basic MD5 functions. */
% ~" F. ? x: j5 K6 v s1 R#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ; y9 q" A; S* N2 x7 n- P- C
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
( N" Y8 z* R+ `#define H(x, y, z) ((x) ^ (y) ^ (z))
6 M" T0 E. B- R#define I(x, y, z) ((y) ^ ((x) | (~z))) * C# `* _* H$ [! G `7 b& S8 v! G" C
3 j7 I6 w3 ?6 T' I4 P& ^( z& N9 u# k o
/* ROTATE_LEFT rotates x left n bits. */ 5 Q# |, \- K/ b' Z! j# j' O' x
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) , L0 m/ p- _! [1 I- D
l" T, X1 H. G% b( M. L
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
+ s1 f* w0 N, \, qRotation is separate from addition to prevent recomputation. */
R; m; ~0 o+ b6 o#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 D) \- i9 X0 j/ {#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ' S" z; c, r' {: X! S |$ L6 w
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
. p: U- I1 O( @- c! D#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
* v, f5 N1 {! `+ i( p' B" M# `+ c & u- s+ j- W- ?
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
) T5 r4 ^; M6 ?/ r# C+ L# Fvoid MD5Init (context) / s! s& e* M, B
MD5_CTX *context; /* context */ : Y9 ?% e) b4 Z" [% u- @4 f9 a; L
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 0 V& {# V' C2 ]4 c$ K
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
$ P/ J0 \2 \$ C2 k. u}
) Y, M5 z5 {* H% G
# M/ T6 F8 r" m1 z/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
; T, i- n& ^# j/ s7 K" @6 yvoid MD5Update (context, input, inputLen) & M3 y1 \& H/ R+ x
MD5_CTX *context; /* context */
! e4 H, ]" n0 eunsigned char *input; /* input block */
% y: U/ \- o T+ Gunsigned int inputLen; /* length of input block */ 7 b% H' y% a F- h3 p
{ unsigned int i, index, partLen; , }4 C( \% L+ u
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 2 u. U7 V- p9 E8 A1 W
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|