|
|
#include "global.h" ) _/ r3 w& R+ a$ k* e- g
#include "md5.h" # Y6 ?1 W9 } s: C( A( ?# ? O0 s
$ o5 x! Q6 r* l
/* Constants for MD5Transform routine. */
6 H7 ^- K, W2 M9 C0 P3 @
: G% L3 p" l: v9 W * Y& X! L+ n9 j* {
#define S11 7
, L, [0 D2 m+ u9 w& p#define S12 12
* B- D) F2 X' B7 S% M#define S13 17
+ V/ ~3 C% V- D/ {6 y#define S14 22
: n3 |4 F, H9 l U d v4 }#define S21 5 # |( z) n' v! i4 p3 Y+ }% |
#define S22 9
M) W7 k% s& _) C3 o# l% x# ~% @#define S23 14 ( m q7 u3 o# _
#define S24 20 5 ?# R; p' B$ A9 j( D) M+ K
#define S31 4
2 e+ X& C: ^6 ^- U#define S32 11
. W9 C8 z5 ?1 q5 L) F7 r#define S33 16
" v( @) ~+ w3 r. k7 A#define S34 23
/ Q3 b3 l* k* @% t) K#define S41 6 ) d( H1 a) h+ D2 w+ Y! r/ t7 p. e; m7 W
#define S42 10 - \( j. m; h) j9 Z+ R
#define S43 15 + m; o) @* y, D1 s9 B. g( U' V
#define S44 21
A. O Z% n- ^
) f' q" T, z7 j: r5 X; istatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
3 p2 X L4 t6 p- Y/ v" ? mstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 7 n J! C# K* W4 W
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); : z# ^+ U; T' I$ K, }, g
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); " I* e& b9 _; q# Y2 m& A# J
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
; d5 x0 C/ b- b 0 R# E, l* N. e9 L* H: o4 R/ F) V
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
* E" T5 m% i8 w! y/ U}; , v: s! b; @( y( u1 T: @) d( s
! V3 y. b$ v8 m/ V/* F, G, H and I are basic MD5 functions. */ ) _( o$ c7 ]3 T' S
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
) J6 L }" h4 u& R% o# X/ J#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) / D8 Q, Z3 I' g. L0 k
#define H(x, y, z) ((x) ^ (y) ^ (z)) $ i+ Z3 _3 w3 \, p$ X2 I. q/ x
#define I(x, y, z) ((y) ^ ((x) | (~z))) 7 [3 C5 L/ l3 l) b* i7 R" K+ Q" G
6 ]; P( g/ g$ f' N2 w7 f1 k' k- r
/* ROTATE_LEFT rotates x left n bits. */ 8 C* M' ^2 N p0 P% u- {) G& D
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
, R6 ^/ K/ | a1 Z3 D ^5 |0 @ " {/ s; U3 \: B$ o
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 5 `7 I3 t" { d- @% L
Rotation is separate from addition to prevent recomputation. */
4 k5 H r, u! r6 l#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 C/ s; a6 E. d8 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); \ } ; o' P/ I$ `& X( U0 d
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 6 @6 _ m ` i4 Q8 s; I
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
4 ?/ @) G t+ u
( v2 d* p* S( `5 a/* MD5 initialization. Begins an MD5 operation, writing a new context. */
) O. j2 ]/ F( f! a Kvoid MD5Init (context) ! N3 e3 g7 L# i$ `* W% @# S8 G! \
MD5_CTX *context; /* context */ ' V, ^( ?* v4 f8 S' S( U" S2 l5 H
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. - B/ ~1 D; P( U
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
- b9 n' Y- M5 z( k! ^2 B4 ^- ^} / u* d \, W. @' |# R" l) w- }7 F3 Q
" b$ N8 M& F1 |: M( k8 \# a7 Z/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
3 q4 [7 w+ W8 P: V6 Svoid MD5Update (context, input, inputLen) 6 f3 q- D% b* v0 Z% v* S; O0 B
MD5_CTX *context; /* context */ 6 i0 M; n1 y7 Y
unsigned char *input; /* input block */ J$ J7 L0 m3 ]9 V* m0 H- B+ b
unsigned int inputLen; /* length of input block */ 0 \' d3 @2 P0 I }5 I4 Y
{ unsigned int i, index, partLen;
- |, T( E: ]+ I e, a /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
! P$ ]$ \* N3 t* b: R; M7 c _, p /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|