|
|
#include "global.h" # d7 r; X. p# T$ M) D( \# h& |
#include "md5.h" 5 h7 S _3 I$ i; p( X
! f; g/ G# D8 z7 e
/* Constants for MD5Transform routine. */
! W* j2 V% m; A3 ~+ j- n* U" K6 T 3 M! m' D8 [# i7 `) R. c
# J: J; P* C. M* F
#define S11 7
; o" M ?4 i, j& _- u8 H0 e/ f+ |* ]#define S12 12 " ?1 v, s9 ~' w
#define S13 17 0 B, y! z) j) v2 [ u! S4 x
#define S14 22 : _" t, @* o: R, V4 D; ^% D
#define S21 5
2 A. c* M# m" z) s) |#define S22 9 " n. q, S- `0 A; g5 n# ~4 {
#define S23 14 : [9 O- X: m6 R6 z+ b$ C
#define S24 20 6 h8 `& c$ R" w, N6 v3 {
#define S31 4 , `; y( M8 [) U& x# `
#define S32 11 - Q& d6 O0 Z% c
#define S33 16 . l B0 J7 K4 U8 a+ ^9 h9 y
#define S34 23
7 ^1 Y0 E* }. F) e% X& ]#define S41 6 8 Y3 p& c! J6 @9 [ Q
#define S42 10
3 a. l6 {8 u( I: D; c#define S43 15 9 e: C9 f i5 \: _; h; s
#define S44 21 7 c+ ~& N' M' |! u* M
1 m g0 Z. B, l& w9 qstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); o3 Z- `+ l1 Q) @, g& p8 e7 r* g
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); # a0 d3 j8 |. E* V
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 1 x$ N. }& [$ \' ^
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
1 A, g$ Q, q# K& _' x. a+ t2 lstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); , F. m/ j" l2 X" d6 J
: o" @" U5 u+ v2 a# d! y
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
0 }: N9 k; F. _}; ; e V% e0 m( X B
# ^! J7 g0 l: k ^
/* F, G, H and I are basic MD5 functions. */
: C' O& |% Q: x* }3 z# G#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
7 d1 z, C6 M6 X#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
1 k% r1 g; P3 z; v/ |/ H" L4 X#define H(x, y, z) ((x) ^ (y) ^ (z)) s( }# `6 D& D7 n* j0 z/ f9 o
#define I(x, y, z) ((y) ^ ((x) | (~z))) 9 K* R. b8 }& W+ s
. z6 ^" w# V/ a0 S' g' k+ D/* ROTATE_LEFT rotates x left n bits. */
! b5 z4 g/ n+ T+ b2 z: s: g v0 t R#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
?$ m. O0 d) @ k* n 6 }' F. u( `/ e7 R7 b
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 4 d" `# ~6 d: Q8 U, ^3 l' b
Rotation is separate from addition to prevent recomputation. */ 2 g: b/ H5 p2 Y3 C
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" G# c1 k8 j( t+ c#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 I: y$ u- P4 U) U" H#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ; [. j. `7 z. k# y( E% k' X$ n" p
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ M* C4 l: b( Z; o2 S7 f6 L. J Z2 s6 k& ~- E' g3 r1 U( E
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ . L6 D( O8 }7 x; u$ C- Z. P
void MD5Init (context)
5 V; R% J8 e. i# AMD5_CTX *context; /* context */
* t9 J. J9 L7 d% e7 B{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. " K7 k. I! _2 _0 y& z/ W) O1 l8 C# b
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; / H# c: k# l) o, t3 g- W& U
}
! o7 }2 R0 x m3 I
G' B& U# F, w& r& I$ x/ Q/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
3 S( ]' N+ @# i! F" s/ @1 s! Bvoid MD5Update (context, input, inputLen)
' w/ @$ o- ?+ G/ }MD5_CTX *context; /* context */ & y8 p, d. I) S3 q9 m; n
unsigned char *input; /* input block */ : e/ j" h4 N0 A8 `9 _6 ^
unsigned int inputLen; /* length of input block */
9 A. m4 l" W8 m' r# o& ?& G \ w{ unsigned int i, index, partLen; 6 G1 x/ p0 z. w/ x
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 8 j( g2 F0 j$ S" K
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|