|
|
#include "global.h"
& V# A9 |. c( C" K2 d) E+ [#include "md5.h"
1 L; Z0 _- [2 ]9 [3 c9 m" O
$ m+ S- N# c" l/* Constants for MD5Transform routine. */
5 L3 v9 l8 {7 m$ A0 z0 P 2 Y& w6 l0 O( T3 @
9 m L8 o$ d2 k6 ?#define S11 7 9 j1 |( _# b. n$ q& G/ o1 c7 i
#define S12 12
0 D% {0 E/ Z5 x3 P- k( S#define S13 17
" k* E/ ~7 }1 @: M, @- Y; l' \#define S14 22
" X2 T9 Y/ a, _5 }1 Q5 x1 P#define S21 5
- K( _2 }0 w+ t' _) w! h! X- U#define S22 9 3 H* t* n2 z' j, }. y8 l' Q
#define S23 14
1 S; l p& \2 f9 j7 |( Y* v#define S24 20
9 i& L) ]+ [' Y4 O" U/ B' I0 g- F, V#define S31 4 # B( t- I' ?5 d8 D' m
#define S32 11 & q/ D; z2 p/ }) R8 j
#define S33 16
! I/ ?! E+ h- H* t#define S34 23
$ y3 s0 P) o3 a& H! ]5 r#define S41 6 & [& o# A9 b# d2 m
#define S42 10
; B7 B# y( R q#define S43 15
# c8 A* G. P! {#define S44 21 3 G7 P5 Y4 o9 e/ `
( d& |' q4 h7 e7 o
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
2 t( ]1 f& @2 j9 vstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
2 o8 Y' C" |) w) o4 V1 X; o( P4 |5 ]static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
. w/ O& Y# W+ Y% D% ^- t2 B6 vstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
) N% d2 X0 s7 j9 c% P0 Fstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 8 E+ A: {$ |9 [4 n: F L
4 v1 j. S6 ]/ r* 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 : L0 c6 j( [8 C0 {! `
};
$ I9 x4 p; Z4 Y' z- e2 d. I
4 }; \, e9 E6 d& P/* F, G, H and I are basic MD5 functions. */ 0 u5 [" V# n. Y6 O% {' Y, |
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) & j/ b3 }" P: U6 w" m
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 1 r0 M; s2 A5 g) X, T; {
#define H(x, y, z) ((x) ^ (y) ^ (z)) 0 V* {8 [. B3 \1 [* f
#define I(x, y, z) ((y) ^ ((x) | (~z))) " A/ M; [( U, g8 U% g8 W
4 t( N3 C. Z5 B6 I4 H/* ROTATE_LEFT rotates x left n bits. */ ' b3 j, u$ s. W; x N5 Q
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ( m' @% _- s6 J) S3 f0 S
; `5 M# ^3 Z2 R1 k( ]2 d# g. D y/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. + x! h1 O: i# W6 d3 O
Rotation is separate from addition to prevent recomputation. */ / k1 H, Y% O1 J! ]5 I* C8 o$ }7 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); \ } / B% R, M. V' r% l% A# m% i) [' `
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ; w4 h( H# V% R9 p& {5 ] e2 l
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
, H/ }$ [* J6 A8 l#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ; h! P7 A9 b( k' n
# Q6 \- d9 x: m. {6 V* f2 f/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 9 j3 k6 U, z% j( h
void MD5Init (context)
! J: L% q1 g! A( b% J; A: TMD5_CTX *context; /* context */
- q% W% t: j! c" B V{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
9 C* b# K; X$ p5 a6 `$ E7 _*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 6 c, q D( N" U9 W' |# C
} 0 N- m1 `4 w& f; X) O* q4 Y0 r
0 H6 g( ~& f" \/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
# m8 w6 E7 T; ^3 ]& X$ xvoid MD5Update (context, input, inputLen)
3 m! v' x0 f O% U; [6 `MD5_CTX *context; /* context */ : U9 U( D6 N2 s6 N
unsigned char *input; /* input block */
4 r& L C6 u4 {& b zunsigned int inputLen; /* length of input block */ # Z# D' R& @% W
{ unsigned int i, index, partLen;
" c& M1 Z5 ?; q4 J /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 9 ?( g9 g0 T5 ^% q! ^; B$ }
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|