|
|
#include "global.h"
# o) X" e0 M7 ]/ r#include "md5.h" / l- L* u- m6 I1 P9 D Z
" \7 i9 x4 E3 }. w) i6 U
/* Constants for MD5Transform routine. */ 4 A X0 F n% Y
; o! f- ~( h/ K
+ a+ Y& {: d! Q- @. i4 ?2 d#define S11 7
2 t+ k7 X! Z/ B o( M#define S12 12
$ p, \( y& _/ u5 Y+ S6 h2 u" _# H#define S13 17
5 t$ s7 u& G& A: p8 L# U0 k#define S14 22
" l* n( B7 K) _, A- {% [9 Z9 b#define S21 5 3 [" K- c! S) A; G
#define S22 9
6 l* P* ]. M3 K$ o#define S23 14
9 d8 Q: Z: \" ?4 S0 y#define S24 20
" Y# d. w1 r! u#define S31 4 0 i% T% L5 u/ ?; s
#define S32 11
5 \8 N- s' B1 O) _- \#define S33 16
* w/ M. X) M& V5 [; I. z#define S34 23
& y; K+ l, W* k0 M3 o- Q; k#define S41 6
. Q' z3 V0 l" |, `" g#define S42 10 . Y$ H- [" ^) a, z9 \
#define S43 15 : ]$ C2 s$ `3 `6 ?( p, c
#define S44 21 ) |2 d: Y7 U* o9 D
: V! u, k* ^: D! E5 |static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); , _* |5 O1 K9 B# ^6 o3 K$ ~
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
0 \5 v* I) l$ Zstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); . x& O& z# k# c
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
( k2 U+ }' F$ S) { A- H' ostatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); : I$ M' I% U: E% O
. j' E) n' I' F$ A/ Q0 i4 Ostatic 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 & r2 q5 O3 Z$ K4 n; d% `
};
4 U2 y1 Y; z Z0 } " C, _; q* x Q6 F2 ^) P
/* F, G, H and I are basic MD5 functions. */ & K1 |" m9 t- G% [3 k/ g9 R+ P
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ' t! D$ p( N1 q' T
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 6 `1 V: t) t- B+ z; n. C
#define H(x, y, z) ((x) ^ (y) ^ (z)) : s4 B* H- F" l
#define I(x, y, z) ((y) ^ ((x) | (~z))) ) {" g' W/ F( C+ @, C
5 T) F. a: E$ q6 c% ]
/* ROTATE_LEFT rotates x left n bits. */
' A* }5 {- t, ?! s9 \& t#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) # g/ w- V1 `% t( M/ D+ V3 V. y& `
0 \3 y+ R- N t+ ?
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. + w. m) B7 v! \$ B( f( X7 w! z3 A
Rotation is separate from addition to prevent recomputation. */ ; O7 U# F, I; o7 t& D
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ' p' s ?( G5 n4 U) n* 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); \ } 9 j* d4 L* G9 \
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
) N) x' Y. P t. N, Q4 K/ 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); \ } 7 Y1 R9 z) P* B" M# D/ i; [1 @
9 i2 O! r1 M' ]' u% ~. ~" }8 D9 C/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 9 z( `! b" _( x2 O" L6 U
void MD5Init (context) % j# P4 e, \: A# M2 w
MD5_CTX *context; /* context */
7 z$ a8 a* P" F{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
6 [7 A) a1 K6 l% _*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
1 h' q! S' m r" @} - F1 l% V1 s4 \1 I" [
% L! h% m5 o' b1 Z/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
+ G$ k2 E: g7 H- ivoid MD5Update (context, input, inputLen) $ ~0 K7 j4 m' h4 K* F7 s
MD5_CTX *context; /* context */ # J1 Z. ^" i# Y N
unsigned char *input; /* input block */
" B% X7 V; e% ~# r1 B6 V0 S1 Ounsigned int inputLen; /* length of input block */
# O4 A" V1 D3 S5 T% h{ unsigned int i, index, partLen; - K E5 ]0 o6 f$ y* `3 I8 c
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
- m' g2 Z7 R9 y3 P0 w$ C1 g /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|