|
|
#include "global.h"
! M$ W! D$ l$ C# a$ f0 D. l#include "md5.h"
$ R5 ~1 o* ]2 T1 ?' S8 [ - B D1 s9 _! q
/* Constants for MD5Transform routine. */ 9 l* K" C2 s6 f
7 a: G% Q7 E+ Y y: z+ D
9 O( e9 |. L C# M; D#define S11 7 7 j# i3 k# j$ e5 g
#define S12 12 - B, _. n0 l6 S# K
#define S13 17
6 g' r0 y }4 }, @#define S14 22 6 P+ }3 ?) z0 r7 W% t, s1 W
#define S21 5 , s$ l9 w1 ~. |8 l! Y7 @
#define S22 9 , @& Q* N! Z) B1 p3 @: K/ a
#define S23 14
& S3 P1 f; Y) g l5 R#define S24 20 / C" \1 s; @3 V" x H
#define S31 4 9 [- s9 V N2 [/ J* f
#define S32 11 + c, G- x0 Q/ f! |
#define S33 16
& T! w* V0 M- A- z! T% e. R. _: r" E#define S34 23 8 d3 I" N: [0 v+ m* ?& w
#define S41 6
# [" e0 Q/ h r& F; [' |5 ~6 ^- i4 e#define S42 10 5 t; y& R) j1 u. Y: C
#define S43 15
1 j1 [. b" _4 x- }. s: C- I' N4 ?! W" z#define S44 21
2 {: V; X9 }6 i . l9 h0 S' S0 c/ U
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
; h3 F* S' J$ ^+ d9 a8 h, G8 jstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
: a8 c! F8 O% L6 |. Estatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
4 x( ?8 J5 |* D' G+ fstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); $ M* {8 A! ?% j8 A
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
$ W% `$ t: s: [ " o3 q- q' n6 R/ ]' C+ Q
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 - M4 S& P; f! X/ a0 N
};
; ]5 ^% o# P# j" y) n
: x" V @; r4 Q d6 \/* F, G, H and I are basic MD5 functions. */
) H$ h) F1 `5 _7 E/ b4 i' L#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) : |2 f! |6 ~) t* O& N# {$ k; |, @
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) + v4 v2 p% w% y/ Y* X. Z4 @
#define H(x, y, z) ((x) ^ (y) ^ (z))
& O7 q: d# {9 m2 ^! d" C#define I(x, y, z) ((y) ^ ((x) | (~z)))
8 m- v* W# n9 n( s" v7 I
. s2 b* A! v: J$ P4 z8 Q/* ROTATE_LEFT rotates x left n bits. */ / ]! ?' b/ K- k. z7 s: h. h9 y
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) q2 c# c1 p- ~. ] W
! y. r! F& l& J6 x/ [/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
. c: X$ v% p' ~" m! fRotation is separate from addition to prevent recomputation. */ + ~: t2 t7 ]8 `# q: x! H. 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); \ } # z2 H' E6 D& `
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ! Q; s1 i' T, J
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
9 _: k L: ]% P#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
$ z" \' M% m9 d$ G9 z( e
* e% C1 ?+ Z" f' b! w/* MD5 initialization. Begins an MD5 operation, writing a new context. */
2 ~% _- m- T+ C- mvoid MD5Init (context) : L4 P+ X6 Q# x; k7 j1 {" m
MD5_CTX *context; /* context */ ! K% u/ q# h7 m
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 1 `' v" H6 }" `, ~9 ~ D! f: J: e
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; - j- O! H" t8 q2 M* Y
}
, J4 D0 O2 J( g5 O
0 Z$ {6 L }$ ?" p* j3 b/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 2 Z0 h9 I! S1 N3 u9 h7 C1 u: {
void MD5Update (context, input, inputLen)
, ]/ q5 N: F& a1 e, {8 z, r) YMD5_CTX *context; /* context */ ( e9 K; C' Q# f3 J! r. F
unsigned char *input; /* input block */ X1 g$ q/ E/ |
unsigned int inputLen; /* length of input block */ 5 u* d6 v# V3 f# C( a; U
{ unsigned int i, index, partLen; ) I+ ? o" S* g. [/ V6 @
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); " e+ |) c' K& r' p
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|