|
|
#include "global.h"
/ o& _: ?0 ?0 `/ d, w1 U#include "md5.h"
- P$ b. Y/ L ^5 X* e! D8 A 4 I1 P# q! q$ y
/* Constants for MD5Transform routine. */ " z6 d+ w" y1 h M$ t2 a6 Q
- S+ f' `1 ]* X' ~" j
1 Y5 }( |5 V/ k0 g1 g/ h; b) F
#define S11 7
4 M( L3 S# R& h1 ^- v#define S12 12
6 O, O: u! o( G* R( k#define S13 17
/ ^3 N7 B# }4 q1 C2 z#define S14 22
' w6 y% N$ R, S8 {#define S21 5
; ?: y! [5 Z) o. Z" k+ P#define S22 9 4 T( r4 w5 n1 c% `+ N
#define S23 14
3 J% _$ w. W; y n9 y#define S24 20 + D8 G; j# }( D7 K" V; N7 F" {
#define S31 4
$ V$ |. l! w5 o5 P ?1 x0 W#define S32 11 3 N- D3 ?( K" y( q/ R
#define S33 16 1 K' ^* k8 b" c6 ]- B0 D
#define S34 23 5 U5 r0 N+ a @; p/ ^: Z5 U
#define S41 6 ~( ~; J% W6 P6 M6 L: b
#define S42 10 ; E9 a. r6 d- d7 w9 w7 o
#define S43 15 9 ]( t, j& P8 E' N, w6 C: I4 o
#define S44 21 9 d; d0 Z0 q" g8 n- \ {: ~
' e, s1 N5 r& P
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); * A: c+ |3 q) ^. \
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); & s# l0 q) c% c; Q+ @
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
% N9 r% t0 ^( f: d8 [5 tstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); # b5 g- W! Z1 x x! b6 x. [
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
/ A# H3 W. U8 m8 D6 p$ P+ n3 ] m
* ]$ ]# n" ^7 K! G6 hstatic 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 J- ^+ ^' i4 u: E3 h8 t% `$ p
}; % q- [4 b, [# {+ p1 c! o, J
8 C$ I% C! F3 v+ S
/* F, G, H and I are basic MD5 functions. */ 5 K$ H6 M) ^" F
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 8 |1 ?) S+ I8 g) s" J
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
, q9 m4 r, B' Z% r$ E( m3 T7 e#define H(x, y, z) ((x) ^ (y) ^ (z)) 6 n) Z f" W1 `
#define I(x, y, z) ((y) ^ ((x) | (~z))) 7 P7 [5 r6 Y6 N$ m) [
" Y5 a8 h% \% u, ]# Q0 K/* ROTATE_LEFT rotates x left n bits. */ ! E0 f; B+ y, C/ A4 s! H
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 6 `+ x$ E o/ S6 I
; C) t% \9 B2 c0 v/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
( W' G/ U# N& l/ p! E* ~Rotation is separate from addition to prevent recomputation. */ * q" j, H) `0 T4 g7 ~, Z. ]6 _
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ! J/ e. b/ D, ]0 Q. B
#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 }9 X! o' T7 N5 L$ 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); \ }
/ G5 I' l2 e% j H$ ?' a#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 5 P( j+ Y) o4 q' ^/ i; H
0 V. {9 ~1 c! T1 p$ Z
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 6 T k5 D6 r+ e: ], n" q$ H
void MD5Init (context) ! E; e9 U0 c$ j0 w9 m8 a
MD5_CTX *context; /* context */
, n( `# W7 Q! f{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. , P5 Z$ d9 j/ p
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 6 O4 r' Z5 h8 Y! J# r6 L
}
: @$ D( q% w$ @) E4 D5 t
* t) ^, s2 m" M, E4 I: e" s8 B/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
" R; Z% M! X# P& x# vvoid MD5Update (context, input, inputLen)
$ F) H4 R) `' ?# x+ R4 b9 }MD5_CTX *context; /* context */ . V; h) R. s8 L# h* M4 c
unsigned char *input; /* input block */ ) G$ p% D M8 j
unsigned int inputLen; /* length of input block */
I1 C$ d0 t5 k) Q+ e{ unsigned int i, index, partLen;
2 j8 g9 P' @/ D/ v6 L, R% L /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
/ j6 R& d3 _, x+ R /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|