|
|
#include "global.h"
7 t; Z4 {4 [% R#include "md5.h"
, K) Q) f7 p( O5 n3 B
# I* X2 _" w% v+ l7 D/* Constants for MD5Transform routine. */ 2 [9 r- d. W1 [! r* [" {- i
* h% I/ F, u% q' h5 P& F. T 1 ^2 ^' ~( l8 ~
#define S11 7
. ]% g; ]5 u9 F* N( X/ U#define S12 12 - Z( {; f$ W) ~7 S: A* L
#define S13 17 # D8 F" H0 H$ ]- v! j( _
#define S14 22
* P2 j' `3 G# z' \! q) b$ j5 M/ Z; G4 ?0 _#define S21 5 " \+ Y+ u9 }/ \* N
#define S22 9 : w+ l; d5 C& |- x) M0 f
#define S23 14 % K$ y8 S2 P, {
#define S24 20
0 B" `; q# J% B7 z% V2 M#define S31 4 6 J* v) c8 \# r% S) t/ T# x9 U
#define S32 11 2 u( _# R" v4 z- X
#define S33 16
2 z" W+ p. q- j#define S34 23 G. \! U% c1 a
#define S41 6 & x4 ^; w9 I" V$ a
#define S42 10 8 _/ [! F! o5 @% }2 b
#define S43 15 - J9 c1 t9 N5 v U0 U7 S |2 o
#define S44 21 6 n* I0 f9 b* T+ ?% r6 a
5 [: m4 X' W1 X: `6 c5 Tstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); " S" O: O+ G* o8 A
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
0 l' P+ m6 S7 a' ^7 W6 \+ k' S% Qstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 8 U8 ?- L% n; g3 S7 w
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
' {: y- b: [- E9 W. C4 p3 Tstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
~5 Y5 `' Q& i; d3 Y! a+ l o& z* v
6 d. F: @0 |6 Y5 O+ kstatic 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
- ^6 g+ ]3 H! f& ?}; 6 Y; _' `* k' T6 ? \: l
& I! n% J* v4 e2 e6 L6 C1 x
/* F, G, H and I are basic MD5 functions. */
: S4 n% d% R. u1 h# ~8 W#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) + Z* D: G, d( A; ]# p% b N. X
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
; X- I8 P# q5 n; x X#define H(x, y, z) ((x) ^ (y) ^ (z)) # j$ R9 w4 @3 ^8 l. d& ^
#define I(x, y, z) ((y) ^ ((x) | (~z))) 0 M, g. `6 ^) r4 Q3 `* y: m
/ U, ^9 F' H* E: X
/* ROTATE_LEFT rotates x left n bits. */
0 z$ Z7 M8 p; p" b" F9 A#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
9 l W, ~4 o8 {) G 1 b! L, d! J7 ?' ?/ r# u/ j' p
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 7 H% J# N6 ^, f( K1 |9 g8 i+ H" M/ J
Rotation is separate from addition to prevent recomputation. */
9 ^; p& S1 c- I+ x7 R1 C#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 9 t2 M5 i; W F0 O
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" d' R+ z- L2 h5 @9 e$ P. n; g, P#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 D- [# ^9 ?- Q+ p1 U
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
7 d5 V7 k4 W' {* F, G6 l
; G, M5 w. M4 ^9 Z' a8 q. f/* MD5 initialization. Begins an MD5 operation, writing a new context. */ n- e+ X, e; J: f* g
void MD5Init (context) , f3 T: [& i! d8 S q
MD5_CTX *context; /* context */
' t$ b! D2 b( O. T/ g$ _* ?{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
' k1 s7 [# }" V' u2 y5 K& I5 P* Q*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; , W+ ^- b: T4 n8 j4 D
} " h8 n4 |% s/ Z, R! T5 n, f
3 y5 ^. d! u5 S, q
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 0 B2 m0 A3 u, \+ q' D+ C
void MD5Update (context, input, inputLen) # K p9 n: q0 W& [0 Y8 u
MD5_CTX *context; /* context */
" e7 j6 }; I" K/ _; kunsigned char *input; /* input block */ 7 U* x, P0 p. P! @4 X% H
unsigned int inputLen; /* length of input block */ - _7 j7 u" B# C7 ~. V' @
{ unsigned int i, index, partLen;
9 [; p# Q6 b! m/ y /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
' i8 m8 P# A5 ?/ V( } /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|