|
|
#include "global.h" , U# \. Q( x! N1 i6 b
#include "md5.h" , |% P7 |% g% j& r. o% f
& v8 ]! I& R! X+ M0 o/ n( G& F/* Constants for MD5Transform routine. */ 5 m; m, p& `% b2 K5 @# Y7 F8 l7 V
; H3 `5 d X+ A1 F5 }3 ^
- r$ G9 ~6 P7 h5 A8 D1 E#define S11 7
9 j0 I6 k& ]. k8 G( N3 O3 V, d#define S12 12 ) ?/ B; m6 L/ R; [* G
#define S13 17 4 q* {) a( w% F
#define S14 22
6 _8 h9 g- Q( ]2 k#define S21 5 / v6 W9 X3 {6 z+ W1 S n0 ]2 H
#define S22 9
# l0 z. _/ ?4 I8 `# o5 {# x( v+ t#define S23 14
( W7 `* i% g! j3 `& \; I/ s#define S24 20
( {' ^) y1 r- m1 W#define S31 4
9 d5 @ L( R3 d# B$ |4 s, ?/ Z) F* G#define S32 11 9 s$ h( @) W( d S% V! \7 E' ]
#define S33 16
5 {; y" {* F, t2 A. A+ @#define S34 23
n2 J/ U, [$ a. u& l#define S41 6
, m+ ^$ _% B0 z& Q$ Z# F# Q#define S42 10 9 K" I% b1 ]7 X, T- z9 G
#define S43 15 9 U2 |1 |# q3 |$ q2 d1 C- h
#define S44 21
! M2 J, s O, t4 v
( F; w5 z8 Z! j# d4 F3 Kstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
; n: B' T+ l7 }( d6 Mstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ) ~. R, w( G& z: n8 U# W8 U7 ]4 ?
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ; x, C+ |5 V9 r& F- k( o1 f
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 7 I+ |+ k+ J* Q7 }6 q) U6 A+ G
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ; e0 G7 _' y! h* x6 A( _
% p/ S% H; T {0 }& p% @2 xstatic 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 * \+ t/ n+ O6 y* e$ O
};
' Y) g2 ~1 S3 c/ ]
! V/ h# B3 {5 s- d O! u/* F, G, H and I are basic MD5 functions. */ " Q; C [2 I1 b% N/ K9 L
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ' r. N, C7 H( g. y( O- y' A2 y- a
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
, B+ K- z) O5 Z* P9 f#define H(x, y, z) ((x) ^ (y) ^ (z))
3 Z( W( j8 d: U) s: p8 Y#define I(x, y, z) ((y) ^ ((x) | (~z))) : m" q* U4 j" W( q2 S& |; a
5 H" a" a8 \7 M4 T0 m: M0 H9 N, h/* ROTATE_LEFT rotates x left n bits. */
2 c; T X) @" i& ~#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ) j5 v' D) H( H+ j& \! j8 I
9 M. v5 c% v. w) `$ E/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. $ \0 ]( ^9 h A( j& Y3 J; F: ^
Rotation is separate from addition to prevent recomputation. */
8 a) F+ g( @6 u& K/ Y#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 8 ~. |' G4 R% x# W/ t2 H% g
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 M1 V$ e( h) s& B#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
- R: v$ Q! _5 q2 { Y& e- N#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- s, S# z* A* Z/ S' p* A1 `
9 b' w4 i& |% e! p: i/* MD5 initialization. Begins an MD5 operation, writing a new context. */
& k' D- t+ E# D7 `" c. }void MD5Init (context) 0 r0 g0 C0 @) Q) x' t2 o1 o4 J
MD5_CTX *context; /* context */ 1 B0 A0 M% Y- W& a, ^
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. $ x7 ]! @9 A+ _* l" v4 `
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; / R- u- G3 j5 `9 }
}
$ k" l6 ?. u$ J. o5 w & ]( X0 A9 ]; s1 X2 w, k
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 0 ?3 A# l( w1 J2 D% V
void MD5Update (context, input, inputLen) , c6 t% f% S3 y% b2 C' @ Q! E
MD5_CTX *context; /* context */
5 E5 ]4 I- z: O \unsigned char *input; /* input block */
% {! Y* ~% e3 w, R% }. _unsigned int inputLen; /* length of input block */
) L" ] T; I r0 v{ unsigned int i, index, partLen;
4 t" V3 A* M! a$ i1 c1 b0 i w /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 7 D: F: ^: L. a+ F1 E+ M- {5 q0 S
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|