|
|
#include "global.h"
# F% Q' P) b3 L! ~5 w0 P#include "md5.h"
, D( v) M- x/ B$ l) Y$ E) V v9 W* L* { * W" Q; I0 W( l0 _, L
/* Constants for MD5Transform routine. */
1 U* r& u! I' N7 [5 @ , g( i r; j+ q% L: O# ^& y. z
/ N$ m: G) H! e
#define S11 7 7 d3 _$ Z( C+ L
#define S12 12 7 t. \5 Y+ W! f- a
#define S13 17 + J5 r2 B' z6 ?: W* y" Q6 G
#define S14 22
; z( }9 v2 p+ f- A1 j |4 }#define S21 5 0 F" j: U/ \8 ^. C! l; L+ s/ I
#define S22 9
9 }7 r0 l8 o9 g0 H `( V#define S23 14
9 f F! z' I& H1 v#define S24 20
7 i2 C# x/ X& x1 ]# }, r#define S31 4 0 k/ U: z6 p* g2 s+ x
#define S32 11 1 w/ Q3 p7 ^% [
#define S33 16
% s( I# P& t% M#define S34 23 7 M1 P' k; A- {( ]
#define S41 6
; F! p8 j4 U" w+ v1 N3 z: I#define S42 10 # F% d* S u, J/ J( X# v
#define S43 15 9 s0 d0 c. w5 {- g3 J7 Z1 ^, t$ L
#define S44 21 1 L: D5 O4 f* m
1 b! }2 Q$ t3 z W% ]$ Y! C
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); y6 ~! N3 p7 _9 {6 [# W# T( M
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ; G; }* a* x# ?5 x) `
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
6 E8 F/ H6 m0 z9 _2 Q+ S% ostatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
' d& c) ]! H+ F7 j. Astatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
: H* B7 a9 s/ P: b$ m. l7 O 0 O& c/ ?9 O0 b: x
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
2 w" U/ B: M( x& K6 K: S- k* H5 {}; ! _0 l9 a: O3 R }3 @$ K
: h$ `, D( h2 X. j- b2 ?5 q0 t/* F, G, H and I are basic MD5 functions. */
& D( M2 B8 F, T. ?0 E* P#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
4 J: ?3 Q# q* _# U. V1 i#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
' U) A- B. Z( V6 V* l! M9 h#define H(x, y, z) ((x) ^ (y) ^ (z)) / w; q/ x. V6 h- d. o2 T& Z
#define I(x, y, z) ((y) ^ ((x) | (~z)))
( B( _7 @8 @; | n" R % v/ I! D* S" c" W
/* ROTATE_LEFT rotates x left n bits. */ : ^ r3 m% u% s3 T
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) / [/ V/ o- I) D: L9 {
% y& K* ~) A' A \1 Q" a/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. & w1 E0 Y$ O( o8 ?: a4 g
Rotation is separate from addition to prevent recomputation. */ 0 _8 P0 u2 F6 j' m3 O* j
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } : F2 n$ A. L3 e- r& a; w
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } % e2 f. u8 p) x+ @# A
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
( ~& ~/ g- G8 N0 y- E* M5 v#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# D# y7 f3 i + ]/ v& W+ r& t. _; x
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
& |4 }: p5 X3 xvoid MD5Init (context)
- Q3 r% c5 ]3 W& `0 C) WMD5_CTX *context; /* context */
! K7 k* [' V: Q! g8 s% `) U, U{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. : T+ B) p7 u# K7 V
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; - Q) Y. K1 x6 c( ~) L1 i7 C) d/ J
}
1 @: V: u! s R) J- H " ?( d! s1 Z3 [! R4 H/ T
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 3 Y0 I3 W+ q5 E3 s# G4 n; ~4 R. C
void MD5Update (context, input, inputLen) + V5 {" R6 Q+ @+ b
MD5_CTX *context; /* context */ # |: t* T4 V- Y( _
unsigned char *input; /* input block */
9 M) e9 g0 e6 Y. m* f9 x3 _unsigned int inputLen; /* length of input block */
. a, o4 j* z4 e% P+ D{ unsigned int i, index, partLen;
! w: q3 G1 f7 f& ]3 `, z. Y9 q /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
" X/ k$ W3 `2 S3 l0 ` /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|