|
|
#include "global.h"
8 T5 G. u5 a* R9 ]9 M( p5 D$ [#include "md5.h"
- a% v& [7 {6 t& a
0 _8 q8 G) T( c% O% m2 |/* Constants for MD5Transform routine. */
2 G* ~% i" t" P- ]* a! i
3 }/ o9 u3 @* h6 X4 `+ q9 y M ( l4 f/ s- B |1 N0 L$ u
#define S11 7 ' [& \4 I. |: U) ~
#define S12 12
4 _# z8 _" a/ D; J7 |#define S13 17 " ]1 z0 t: ^, j1 C1 I$ G" ^3 \. e
#define S14 22 ( v) |2 K) W9 i/ W! _6 s: L
#define S21 5
9 e! d7 P/ Y. w2 V$ G$ n+ W#define S22 9 $ t! l. J, m& u& N! ]$ M* T
#define S23 14 ! V- E( O& j0 `2 {' i& F
#define S24 20
. `1 Q; T5 M9 ^: W3 U4 E0 p* |#define S31 4 ( Q, c: R% x" W' e$ [$ L
#define S32 11
3 W# t1 v9 ~6 t( v#define S33 16
. F2 a; a' o4 C7 v#define S34 23
& ~$ x2 N% F( H, C; p#define S41 6
0 j# a; V, W' h0 E+ x#define S42 10 ' ?' W# J1 X5 }8 I6 \" k/ E
#define S43 15 . _6 G( m6 F& {! ^
#define S44 21 + q7 i1 d( n+ t4 n& S' G
" N. [2 G! A) I1 }% A; {6 J
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); * }- r3 f1 g: K4 _- W' Y. i. Y
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
2 J9 X. G! X1 G0 gstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); * L) K% z4 Q/ Q6 m4 e; t9 d
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
1 N1 f6 R! O# O2 v8 y; I1 H7 Gstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 1 f- h+ m, E/ ?8 m Y
2 x4 a. Y% h' F4 ^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 & l5 {" b" x) A: [8 Y6 S, k! }
}; 6 d9 U& [. @6 N' Z$ m1 U, A
, b$ T! {1 e3 @6 h
/* F, G, H and I are basic MD5 functions. */ $ s( q) E6 E K! ]% v
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
9 n% Z6 L# u% Q' V1 c#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 2 |6 }3 M: ~- E: d* O9 F
#define H(x, y, z) ((x) ^ (y) ^ (z))
8 B, f/ u- d3 \* T% P#define I(x, y, z) ((y) ^ ((x) | (~z))) 9 ?5 M* X5 _1 R, c w
, J/ Z+ K4 z: X8 N/* ROTATE_LEFT rotates x left n bits. */ , W! j* k# Q( F: \
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) : V$ A9 R; Q5 y; h" E4 s
* I8 n S8 e6 X9 g7 [5 I0 F/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 4 Z0 L7 Q( l' T# D' A
Rotation is separate from addition to prevent recomputation. */ 2 ^1 f) k" z) J: q
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
' ~9 h0 F! I& Y' v4 n3 ^/ R/ r#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ' L: y7 H8 O+ K7 T+ 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); \ } $ w# G, L# H1 @& O7 ^* F' ]. ~% V% E
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 6 G$ C7 B- G! V1 h- \
% _6 L( c& K3 F L+ i* v% q! V5 y/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 2 k/ L* F" |# c6 Z
void MD5Init (context) * E4 y6 H; B0 ^7 s* t0 _* d. S: h
MD5_CTX *context; /* context */ ; r. ~: M. u/ Q# s- |
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ( [" ^7 O& D4 Q7 Y7 {" D. D9 L
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
0 c2 h; s' \+ v} ) Y5 s+ _" f D/ ^
8 r) w# S2 I' Q8 W( N1 e- x3 J
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 5 d7 }) ?+ N# O9 ?
void MD5Update (context, input, inputLen)
3 \( l, Y& q# T& F( d5 b8 f- qMD5_CTX *context; /* context */
8 W& s* e) d; I. Z/ sunsigned char *input; /* input block */
+ J% q! q- [# v$ e" b6 vunsigned int inputLen; /* length of input block */ " y/ ~" U5 q& Y- l5 r+ [
{ unsigned int i, index, partLen; $ o2 D2 K; y8 _5 b
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 1 t* ~" M3 l. Q# e; b
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|