|
|
#include "global.h" ' M0 m* m4 E3 y: ~+ m9 e6 |
#include "md5.h"
/ Q. h8 x8 G, k3 X2 ?0 A. G4 b9 N! g
! J2 k0 ?1 D4 N; k! m" M, v/* Constants for MD5Transform routine. */ 8 v/ B% [& y9 ?8 D9 S
$ B( v; W7 P _0 j( K) Z
2 n7 \4 |( q( W; R: g
#define S11 7
/ `3 C$ ?: E- w7 Q; L#define S12 12 ~ [/ g( |# e @
#define S13 17 0 L' \3 K8 B. B% d2 H
#define S14 22 9 J/ Q! u7 R! J5 ~/ h( \
#define S21 5
- G3 l# y* b! {2 `#define S22 9
/ O5 ]2 {0 r" Q* }" ?6 H#define S23 14
' O+ t8 a v2 w2 p$ _+ }6 ]! L#define S24 20 + F- |4 }* A, S5 l/ F9 f% N! Y
#define S31 4 , K3 q8 W D2 e) j
#define S32 11 2 t+ C7 Q& [$ C
#define S33 16
. r/ R: R- S3 ^( D% I, D#define S34 23 & C) B& G' q$ ^1 N/ I7 }
#define S41 6
& X0 b9 `- i$ T( }( x; }) @2 l) R#define S42 10
# U) l* I2 r6 p2 ]0 ~" N! o#define S43 15
# [/ _/ m, L5 G: t# X#define S44 21 % Z9 k3 O. |0 J& l, _4 `
9 [/ U0 K* t- g2 }
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
; T, g, J& r" f; V6 Lstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
7 l: [( U2 D9 d# X/ C, z! j3 a, P; zstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 9 j! W6 }5 f3 }8 Z$ V5 S2 v) \
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
: a& ~ w2 r7 Y4 y) Xstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); - ^& ?0 ~- m% |- U( l9 M
6 Z! S- h2 e. T+ o* Fstatic 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 ! {* I8 z5 v2 q" U
}; ! \: u3 W3 i/ a- P" Z
( b4 o3 ^& l! K% v0 _/* F, G, H and I are basic MD5 functions. */ & t, Z- K7 q3 j p
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
, d r' w G `2 V$ T- X2 h, ]#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 5 |% `0 ~3 k3 R% G* E2 b
#define H(x, y, z) ((x) ^ (y) ^ (z)) 1 k% Q+ A7 g. ? w1 Z+ R7 n
#define I(x, y, z) ((y) ^ ((x) | (~z))) 0 u, x/ o2 \- n4 G
6 y7 l' U& [* r" Y/* ROTATE_LEFT rotates x left n bits. */ 2 ]) K0 Z, E% d% V9 D4 y
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ' ^* Q$ d! X! ^" `
/ Q& L" a9 i" Q2 T9 w
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 3 ]* g" P) G+ g8 v( `* x! T. D
Rotation is separate from addition to prevent recomputation. */
! P2 D0 ]8 b5 v. g3 s2 A5 z#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 `2 J, `8 V7 r0 U/ 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); \ } : E* Y2 E8 w' h W: e8 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); \ }
a& c6 g: K; J& q#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ W1 p: S% L2 x9 U1 u
" z( r4 B# c( w. k/* MD5 initialization. Begins an MD5 operation, writing a new context. */ . `8 e! G2 B2 A4 b% P4 G% L
void MD5Init (context)
. Y$ B1 E" a/ _2 KMD5_CTX *context; /* context */
( e) }, T. W P( s; T% J# E{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. / t. o$ P0 n9 X) m( b4 B( y& I
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
|! @+ f$ s& U3 G}
# Q3 H) Z4 @: N* A" @ x
) {0 B1 m8 j. h/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 3 ?' A J n" E6 S w3 |* W
void MD5Update (context, input, inputLen) ( D5 \; p3 X4 z1 W# @4 j) e$ }
MD5_CTX *context; /* context */
- B0 ^3 Z$ s& t% N* x( {unsigned char *input; /* input block */ 7 X0 D/ q# e; t1 z2 }
unsigned int inputLen; /* length of input block */ 2 y5 N' c- J* n4 @; O
{ unsigned int i, index, partLen;
3 T* |0 D. q2 W% h; W9 z3 j /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); & l' N/ {3 j9 w- Z6 i- U
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|