|
|
#include "global.h"
3 n1 R0 v# K* `$ m! u#include "md5.h"
( t4 l* V* S' h1 H, c' N6 T ; {/ C, Q" U$ Z# I% I9 q
/* Constants for MD5Transform routine. */
2 Z) l9 F! l3 D2 ^ C( @' x 2 h4 o l2 ?- `# G
8 m* K; ~& W; ]) ^; L#define S11 7 & W( g" O" ]. T) u4 Q
#define S12 12 , ~. F U: J, H2 V( K* A
#define S13 17 0 A% O% v& U. A0 U' l
#define S14 22
- B5 f9 f% Q5 N& k#define S21 5
# W# U, t5 e! Q9 o" @#define S22 9
F M7 m- S2 {3 E. i2 X#define S23 14
, P( Q- }. @) G* f7 d#define S24 20
+ b- g1 S4 y; L! z* B: O#define S31 4 : |" ` n3 H j6 \1 Y( S: H. J: Y5 R
#define S32 11
2 ?5 \' f" @- _#define S33 16 * ]" |1 K3 w5 e- q; N
#define S34 23 2 C6 v5 A; m( D6 h( Q3 z }
#define S41 6
0 M% o4 J( \% t#define S42 10
7 [0 V( w; q( @: A) \" g+ \#define S43 15 ! p( h1 B& t+ Y, ] ^; y
#define S44 21
$ c! i. V$ V' p6 X. z 2 @0 {: W; i# ]; F2 b } f7 a) I
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
1 [. R) z7 g9 \ ^5 o, q8 Y5 D0 K1 pstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
1 d5 l p* r6 Y6 J% y8 gstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 7 [# X: |1 E. Q! ~" r0 g4 h r
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); + T- i- U! ~' G& m; p5 t7 o
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 3 N9 ]; Y9 n; N0 j, q4 {- H# L: S
7 q5 b6 m d( V" t) M* f
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 7 _0 a+ }" l2 i0 [3 c4 n
};
6 D5 m% e: u- s$ B8 J3 w2 r ' f$ {9 J1 \2 D7 {. t
/* F, G, H and I are basic MD5 functions. */ ) M, H) q" q, G! `& K' i
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) & B0 m3 A, i# R0 s; s) E j0 m
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
9 H& r4 Q1 m9 {: x0 X#define H(x, y, z) ((x) ^ (y) ^ (z))
; w& `. @0 y: p F( l2 i) k#define I(x, y, z) ((y) ^ ((x) | (~z))) 7 o& I/ D# d* M. e, ]* N$ W" Z( [
& W g- a x5 V) [/* ROTATE_LEFT rotates x left n bits. */ * J$ I, o' _7 c- p8 G; B
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 2 {9 H7 h) v+ a& ^
, \( N5 Y8 x+ I$ |- s
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
7 B2 s% R' G( R. [; K) IRotation is separate from addition to prevent recomputation. */
# b1 Z9 U* x) d& _2 J7 I; 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); \ }
( ^. |: ?0 s5 d7 X1 }5 }6 S#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& g/ G8 Z" H4 I7 A7 ~* F. }#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ _" M {2 l( ^( u( o6 J( `#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) b, }
& p b" `/ Y& P3 T. X/* MD5 initialization. Begins an MD5 operation, writing a new context. */
* a" T" h8 t* d. Y0 S# Bvoid MD5Init (context)
- e/ r$ a3 I- A2 l9 YMD5_CTX *context; /* context */ : R9 W+ ?8 ~. q# Z5 w$ j
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. # K. P; C. U% Y- U) z/ ]+ B, p0 [% o
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; % v" ]/ M: d+ n0 U C
} 5 h$ T5 p$ T0 ^$ V2 q8 {8 R3 E: Q
7 p! J) t* Q: F* [/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ * e/ |; X) F( x4 S4 h6 n4 m9 D
void MD5Update (context, input, inputLen)
8 B6 a( G. }" E. |6 ~# W2 kMD5_CTX *context; /* context */
4 _% J z3 @% f& i0 Iunsigned char *input; /* input block */
' s! Y. Q5 B M4 b; J8 _; D. Yunsigned int inputLen; /* length of input block */ + y$ c8 z6 ]4 x- n" `
{ unsigned int i, index, partLen; 6 w/ i; J+ z4 z- X' K5 m" f( f
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
9 E) O1 K! c; J /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|