|
|
#include "global.h"
! t$ j% C; X( p- p* F% s#include "md5.h" 1 o; B( `6 X+ T
6 i3 k% e1 s; b3 M" ^7 z' E
/* Constants for MD5Transform routine. */ ' j" }. M+ {% a5 o- i& k0 D8 v
2 n' t& d2 @ N% p5 G4 y
! v6 j9 l Q2 b1 I4 b2 Q- G! f
#define S11 7 ' j1 n4 y- l# p/ T: G1 t' D
#define S12 12
7 o6 J3 Z3 e; {#define S13 17 1 H7 x; l; D, j
#define S14 22
0 k' a( }" j3 { V6 d3 z#define S21 5 $ g8 W" t% ~+ q, C, o' K/ Z4 D
#define S22 9 R! C5 q8 @/ T! N1 `0 D1 F0 ]% ^2 A
#define S23 14
! I: q5 T* J! \#define S24 20 . S2 N. U* i' |. l
#define S31 4
' V, Z- i% s1 [#define S32 11 0 ]8 d* e- Q9 [. m7 m
#define S33 16 1 S2 V7 \' x7 h4 k3 S* k
#define S34 23
+ R8 J; a& C( w4 e#define S41 6 ; m( l8 S9 ]0 F) f
#define S42 10 $ S' I4 z4 ^: T/ T! l }6 U9 C4 `$ O8 A
#define S43 15 4 Z- N- `( Q0 f1 N7 w
#define S44 21
1 |2 _1 k$ [+ q( l: x) w* @
% [4 \2 W9 \/ j% Ustatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
! Z; `/ y% `7 g' Xstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
( x( j L$ l( i! W' l+ |8 o3 f! dstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
) w) Q# s G# L# U3 ?static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); & p3 w3 \* Q, R; W9 O- ?1 \$ s
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); , X3 K7 y. n) K! _4 _$ t
$ e3 k) p2 M& H7 c8 G% w1 M( vstatic 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
6 Q, `! z7 ~/ w( {. N& \* x}; 7 U3 \/ A" r0 A v8 D
' F% o% ]* _2 Q
/* F, G, H and I are basic MD5 functions. */ " p3 e' ]- v' S! O4 L+ x# `
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 5 e" a: z& l0 K
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
& O( T4 ]; x" _2 k#define H(x, y, z) ((x) ^ (y) ^ (z)) 8 c& Z# O5 V. q2 P- T+ P* ^" Z
#define I(x, y, z) ((y) ^ ((x) | (~z))) : _% f4 z( f8 ]) B
; e3 s0 j r$ { x( o8 G
/* ROTATE_LEFT rotates x left n bits. */
6 \8 q. b! q' \#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 8 _& {+ }* J* }
$ d4 [+ ^9 o" m4 T0 M
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. : l3 Y5 k- o- {* g4 M
Rotation is separate from addition to prevent recomputation. */ 0 q* K r$ n8 ]! a/ n
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
7 v9 H) U" J C; I# `#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% m5 ~$ o, j5 [" y4 @#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
) \* m5 M' y$ O, k3 n) [+ k4 C#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } , l- X+ v! O4 w
* S8 L) x/ t' C( Y7 s
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
1 B) H. Q! z0 x; z4 Tvoid MD5Init (context) 2 s! U! F+ L0 W. u( z8 ^) n
MD5_CTX *context; /* context */
$ \# s7 t" N# j+ S `{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
4 h3 Z; k+ \3 Q z5 t( _*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
1 {7 S/ R$ ?# x0 L) w |! y& W( `}
' E8 e. S" W7 O0 }8 p! F" y ( H# h& |7 B1 X( [
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 8 v3 P7 M/ c1 y/ m2 Y
void MD5Update (context, input, inputLen)
* l+ o; }1 y( H* W& Q! f! \MD5_CTX *context; /* context */
3 s1 @) P9 f; g; D% W, eunsigned char *input; /* input block */ * t4 g' A x, m) R) c2 c1 O
unsigned int inputLen; /* length of input block */ 4 z. C& A$ K- T0 n. Z% ?$ r
{ unsigned int i, index, partLen; 6 ], C/ l1 T5 N2 v
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
9 h) [3 R9 G) J /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|