|
|
#include "global.h" T, Y! s, B6 v: @8 m
#include "md5.h"
! o: n& k" v; Y( Z 7 C/ ^: z S4 ^, i6 m3 t. V
/* Constants for MD5Transform routine. */ & C8 I1 b6 x! r+ ]* D' ~, T" y
9 W# N2 s* C( m: G
/ z# w" \6 D% T/ U
#define S11 7 : a7 G0 D% d6 w: @! J4 l8 K
#define S12 12 3 F' R0 z; p/ F6 n6 |& Z. @9 L
#define S13 17
8 X0 r! |9 M0 Z+ X% o#define S14 22 ; l0 }) k! d) R: @, A1 W
#define S21 5 - I' E/ M- S7 m8 H9 i8 ?
#define S22 9
5 I0 L% p- f6 D4 Q#define S23 14
" W0 L3 c8 p) g5 ?/ H# K5 L5 J#define S24 20 0 ^, L7 }" i/ {1 J% n" p* O3 c
#define S31 4 $ ^, O, U5 o4 E6 b
#define S32 11 : r2 W' ?9 n" y I+ [
#define S33 16
$ L/ r$ U5 F- Y#define S34 23 3 I1 R4 ^" D" |7 G5 y
#define S41 6 8 _& B, m7 g: k! F/ J
#define S42 10
7 S" ^" R; D8 ?: L: U6 P5 v5 ^#define S43 15
% |7 O, s1 [3 W9 p0 H#define S44 21 / E, j& P+ a3 s/ H4 m% I
! T `; ? l& l* s) R
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
S" H l7 C+ i1 z) f- rstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ; L: n) D2 \- C1 S7 a9 j/ F
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
. \( K* f" h/ c1 T [8 D8 A1 Bstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
7 |- N7 ^) E' ystatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
+ W6 I! r5 n! ?: w / O& o/ |3 ~( @9 w# u$ E
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 ) y5 q9 W6 W% R- g! q5 i) b
};
( j( v1 }, j- F% {8 L
9 a, \9 F7 ]# G/* F, G, H and I are basic MD5 functions. */ 6 _6 T% L& D, I1 e# `
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
/ z$ {2 K& A+ ~/ M& C3 t#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 7 D2 K& a; n0 u8 a" }( t% d
#define H(x, y, z) ((x) ^ (y) ^ (z))
I2 `4 X. ]4 B* p3 S$ n#define I(x, y, z) ((y) ^ ((x) | (~z))) U }6 B0 x5 _+ I9 \( O6 `' e4 \/ s
- i) s, {. c% S% G+ v1 U U1 y
/* ROTATE_LEFT rotates x left n bits. */
% X/ _1 G1 H6 J; P0 \#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) & K4 I, `! [/ j1 l
* m1 M2 A$ X) z* {! t6 Z/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
. |& X5 Z3 D+ ^2 ?6 t8 V; J# yRotation is separate from addition to prevent recomputation. */
! v0 H S& G& C! I" ^1 M! O#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
* u. a% J8 Q- N6 [9 E#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
$ P+ L! }& m: S+ [#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
3 I' U/ Z" z; Q k5 d7 j" E6 N#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 8 q9 A: C6 J# h# z; o
- y# ]5 Y6 q. g
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
) z3 m& b- b9 E7 Fvoid MD5Init (context)
, M2 U9 `) f& g# T' B* tMD5_CTX *context; /* context */
: i% U# f6 e& C8 w{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ) u( X; X/ m! r/ M3 }# W% z
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
2 I& Q+ W3 [7 E; X# Q4 p6 f R}
' N' F) t% u4 T+ n0 u& D $ Y9 w( Q, i" U( K
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 5 W }. z- X: i9 e
void MD5Update (context, input, inputLen)
- _) `2 Z$ m' |) t C& zMD5_CTX *context; /* context */ / o( e) J5 r9 H' h$ X
unsigned char *input; /* input block */
& d$ \# f& N: V, H# Uunsigned int inputLen; /* length of input block */ 5 d+ d. ]- ~3 m# _
{ unsigned int i, index, partLen;
$ ^: y! q- F, h" x) S K- G /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
% r! V8 }8 T8 }# |8 g$ `1 w! } /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|