|
|
#include "global.h" 0 K1 z% l: E+ A
#include "md5.h"
4 u- l O/ ^/ b
$ f8 h- @9 w/ x ^" a/* Constants for MD5Transform routine. */ ! J/ i- Z3 G0 l3 x+ c- q4 b$ J
1 k0 i8 J, M9 p$ v0 ?
( A* z! n9 v" J3 k# s$ p
#define S11 7
* \; f' |- I2 A: T5 |/ K; Z#define S12 12 7 T! d" D$ @" p3 d9 j0 r
#define S13 17
7 g, I5 M! N: x1 s#define S14 22 # \+ Q; c2 }" R& a/ p
#define S21 5 1 ~/ K' y* t7 { p/ b& D
#define S22 9
4 U0 R# u. D. }7 i$ ~, T1 M8 @+ F/ \#define S23 14 7 W/ Y; B/ g& Y" p
#define S24 20
" N% g1 F: ]% V. S W#define S31 4 $ t( W' [- T. w
#define S32 11 5 B( T0 `4 U/ s1 \
#define S33 16
" v# N8 r) `; m#define S34 23
0 x P5 G* e) h7 F- U0 @3 B#define S41 6 0 P6 \* E# o3 [, [) y+ ~
#define S42 10
% N5 L, Z, a. [! M6 w9 V#define S43 15 % Y z, T4 P$ W9 Q0 n
#define S44 21
# u) w2 D& M' k- J& H7 h& q * l# L7 p# }! I
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
/ D1 l! {3 W' F( @3 ~static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 4 _& r |* B( p4 V
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
8 D6 i2 n9 H) w z- Z7 Y/ fstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
" O b# L6 {& j4 B pstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 2 h" V2 o7 F( o; O2 w. Y& ~2 P
' G2 v: }% B8 P; ?- d) q( lstatic 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 1 i g( ^0 [# g
};
) c! ]4 K- k3 g: ~% v
( H( L/ i& ] \, T) R. n/* F, G, H and I are basic MD5 functions. */ ) x! i+ @* K" m" y
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ( K* p' x# ?2 x; F6 `: B, u1 j
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
: D4 T& x& \; f% N! h#define H(x, y, z) ((x) ^ (y) ^ (z))
9 b0 E9 ?- h, E& t* R) ^8 O: L: S#define I(x, y, z) ((y) ^ ((x) | (~z))) $ |. _ A- F( d7 n+ w
) w3 F/ i! W/ u: m( i3 T. O
/* ROTATE_LEFT rotates x left n bits. */
# Q1 U! g8 ?$ R5 j: _9 p) A#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ) D& _ o( {* d/ o! c ? n
9 d2 ~$ b6 t) j! U3 j; y3 ]/ ~, u/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 3 c2 \, g4 h2 W
Rotation is separate from addition to prevent recomputation. */ ) E3 c9 z+ W6 _- i
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } - Y) D$ R% U# [; R; Z5 q# h) ]
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& L5 B# w# a0 x3 ^5 p0 w#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } % J' E5 o& m5 e5 d1 {6 Z
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
( J: O0 L; [7 C+ c4 O7 c / @" s6 a2 O. k, \0 `" c' K' e1 B' I3 r
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
- y# e% f) O% s* D) H: Pvoid MD5Init (context) 7 g# X! R8 I2 n
MD5_CTX *context; /* context */ 7 h4 z( c- F" i3 `
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
1 y1 ^* j6 [) q* G) p7 i' |*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; , I m* s+ T' E! v0 r0 l' Z
}
4 r5 I) \5 {, U$ U L* l$ A! w l* G , Z! K2 ^( F. U& C" s! \0 v
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
' D- e0 [* S& I' J& F! Y2 Rvoid MD5Update (context, input, inputLen) : N# X6 C$ }( l, @
MD5_CTX *context; /* context */ , N/ @/ ?) A' J6 y0 r+ m% u1 @
unsigned char *input; /* input block */
" x. w W$ r9 {, t5 ^unsigned int inputLen; /* length of input block */
$ R0 Y- T$ ?1 @" Q) f2 I6 a, X& I{ unsigned int i, index, partLen;
# o& Q9 R( A" P3 @3 A /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
/ _' G+ j8 K5 f. f /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|