|
|
#include "global.h" ) G# K' H" V' o' _
#include "md5.h" ' {- H9 t7 O2 A7 v" v# @* ]
% O% c. w2 g2 ^2 l/* Constants for MD5Transform routine. */ ( C# o1 k5 B2 k
* U L. Z: e, L * R$ C* k9 s; L/ ^; g$ o
#define S11 7
; [5 k8 d; _4 q- a6 R8 Z#define S12 12 + t- N8 Q+ w1 ^( {4 v) N- a! K" P
#define S13 17
7 ~6 c1 O9 K) K* F+ D#define S14 22 ) R! c4 _6 M C# k
#define S21 5
2 |6 t$ O3 W7 V6 Y#define S22 9 7 k3 Z0 F8 W1 C
#define S23 14 + v. s1 C: r) }$ y5 L" G# I
#define S24 20
. _& h/ p' V) Y; L' N( n% [" o# s#define S31 4
: F1 N8 J$ e; X1 J. r1 ]& S r#define S32 11 1 |7 A; `9 Z% Z% N. x
#define S33 16
7 h. F) f* F& M#define S34 23
7 e7 q# Q1 q- F: z3 v* C#define S41 6
. |/ T, w4 K0 q Q# J' C#define S42 10 $ T+ N4 A$ \9 g9 o
#define S43 15
+ ]: M& q4 v0 n. u) H V% X6 Z#define S44 21
4 R8 k5 j* ]& e* i/ m$ N : [! }# p! w: z, w
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
, A0 k6 ~! \7 t9 D' ^static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 4 s0 l, C( G' j! n
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 2 }; ~; y; t- n" }9 I
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); % y9 h5 s$ C$ P& U4 ^
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
$ D4 C% Q' b( h C % h2 l9 L4 L# y! x/ D9 u% G9 i
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 8 s& T V8 N7 h r$ [* p/ [
};
P* y" ?+ z% |( I , `6 {9 L& f5 s$ ^8 e. R: u
/* F, G, H and I are basic MD5 functions. */ ; x* k7 f; y' r5 F- ?) Q
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 1 w" _3 Q& C" S2 I
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) % ~" V7 Q0 }; {* T; y
#define H(x, y, z) ((x) ^ (y) ^ (z)) , W+ ~7 |: U" ]- b
#define I(x, y, z) ((y) ^ ((x) | (~z))) , g) z4 V* F; _; S% `4 ]. ~
, r8 m! j4 T7 n
/* ROTATE_LEFT rotates x left n bits. */
8 ~2 q( O/ z" M#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 9 }* p `' `, V/ C* t
7 m2 d7 m0 S: q9 L) |
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
. \8 l: U0 w: RRotation is separate from addition to prevent recomputation. */
6 g9 n# n) O, Q4 L#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } % S& a" j6 E0 Y8 t7 j* U$ H3 D, C
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ( b5 Z$ t/ q" M! i/ S2 ?
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 6 W& ?2 J: w) P+ D+ X
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
' i5 ]2 L- { u& \' m. h, K " ]8 e3 J( S* N, V1 Z% ]
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ' a x% U) d/ S3 o1 ?
void MD5Init (context) * H# E1 J+ H0 I! `: Q- u) H) s
MD5_CTX *context; /* context */
( s. ^: w" K' V8 J" b- Q+ z{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
' ?+ R7 k# q. s$ \9 |5 Q*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 9 `8 M7 {% p+ G
} + t0 n4 N7 Z8 ~: E |
5 [" y* I1 m6 @. d. E- x5 |' `6 l/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
/ a; t. @# n3 A! M8 l* a6 \; Lvoid MD5Update (context, input, inputLen)
* c& O- `- N+ m0 TMD5_CTX *context; /* context */
( X* [1 J# h0 bunsigned char *input; /* input block */
0 D' q8 l! ~0 N; ~unsigned int inputLen; /* length of input block */
5 D' @. Y. C% M6 L4 r% g{ unsigned int i, index, partLen;
7 F& p' w& R1 D2 y /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
7 x% u3 ]6 }! w- N O- A /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|