|
|
#include "global.h" / W# J, j! [; S+ W
#include "md5.h"
! p9 B* c, P3 i9 b* Z* h7 }5 Y/ g
3 e" u! X5 y0 S, {, H* s/* Constants for MD5Transform routine. */ # A/ Y. n2 e* E0 E* K
/ \& L" `4 L6 i9 [- w
* a( D1 [( X1 `; @- h. s#define S11 7 7 X" d7 L m! q1 A9 V
#define S12 12 5 b; a* j) \9 _8 }
#define S13 17
. i8 F0 W' U: A2 x! o#define S14 22 & q) L- w! q$ I5 q/ \/ i! O
#define S21 5 & ^9 T }! i" ^) B
#define S22 9 1 Y6 E, Z! F5 E( O H' n! J: n
#define S23 14
, ]- ^6 q' ]" D9 n, X# P#define S24 20
3 ]0 \! }3 K, P( L/ E, ^# Z. m#define S31 4 . p3 h/ I) }, i( z2 X/ } b) \; U
#define S32 11 & y2 V$ n! ]: s2 o+ s' q
#define S33 16 . l6 M5 a, U q! e$ O( h$ h
#define S34 23
W4 ?7 R' p4 Q: a& O#define S41 6 4 M# Z$ U8 X* K) g* ^3 o
#define S42 10
7 _" c2 e* X$ n# U+ ?& _. r# h#define S43 15
: a) v) k, n7 Z" B* }9 z#define S44 21
% L4 U- y* E$ A1 R ; g* Y+ s4 k0 A) n
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
9 T6 `9 `5 H* m, y3 |% Qstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); # E9 D! X# D& Z
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ' `3 @0 ?" v. [# x4 g) H
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 2 ?" z5 ?( r( j0 t
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ! w+ @9 t: ?5 a
" q) F. ^7 U7 z& ^2 W9 B8 W8 ]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 * f) g: A8 {5 V
}; . E+ w1 W- g/ R, \9 v- N8 m
. @) q+ I. R f/* F, G, H and I are basic MD5 functions. */ - B. a! R; ]+ f6 N& _- U" }
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
7 _6 { s! U4 e! W1 N; o#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
* [! H4 H' W% p#define H(x, y, z) ((x) ^ (y) ^ (z))
1 p! k1 R' [# U5 ]#define I(x, y, z) ((y) ^ ((x) | (~z)))
; D! P0 @( \+ N6 a U w: T G" F$ z" G
/* ROTATE_LEFT rotates x left n bits. */ . ^5 N9 g6 Y/ F! I5 ~) T; |! S
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ) }! K8 [- O! j# b4 g
; U7 V- x; d- E/ t/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 9 f9 W$ ^& H- e/ [4 s9 L' [
Rotation is separate from addition to prevent recomputation. */
! `$ ^1 f, ]3 s, v2 Y" B#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
; K/ w) }: P1 C4 @+ O* b4 Y( i% z5 \#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
; } t. T, Z6 J/ J#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 7 i5 U- F0 M: }
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
- e; Q+ d2 k5 W3 K! @ G
8 v, J, S- r, Z+ {/ L) B/* MD5 initialization. Begins an MD5 operation, writing a new context. */ , V& n4 o; q9 w
void MD5Init (context)
* I7 n' n1 X2 b3 ~) PMD5_CTX *context; /* context */ # }: I7 [; e' e
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 2 t$ I7 A1 @7 T8 [& a
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; + x+ i+ P Y' m2 d) o; N
}
+ R9 H6 U# w/ _ # _ `9 M) v# O7 t
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ ( v5 {7 r+ m6 v
void MD5Update (context, input, inputLen)
, G0 Q7 t$ g9 PMD5_CTX *context; /* context */ " V% q9 W# L3 F, L. D. K: S. t
unsigned char *input; /* input block */
+ @5 w# K" Z5 [. t$ a% Iunsigned int inputLen; /* length of input block */ : B7 g4 o( V' o) P
{ unsigned int i, index, partLen;
$ d/ T) j8 }) Z7 j/ j /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); % c# A5 P! ?0 |1 s
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|