|
|
#include "global.h" 4 n+ Q$ R( t2 o; a: o+ o/ \3 N
#include "md5.h" 4 Z h% J% Y3 B: H
. P9 l3 g4 @- X! @! ?7 H/* Constants for MD5Transform routine. */
& z: G0 L/ U& {, a4 X4 @ k
" W$ J j7 r$ Z% w( X* q 8 ]0 t, o4 X- [ ^% O5 S
#define S11 7
4 A8 ~9 ^- f& `! Q u#define S12 12
: \1 n& V8 W# [: m8 L/ P, N) h#define S13 17 . b# C R$ J2 v: e, O
#define S14 22
% u# N6 s* f2 _" o, Y, g, r$ @; C#define S21 5
7 W6 @& m2 R- W3 ^9 e" e+ p! k" h#define S22 9 0 a2 Z, D; \1 Z3 |( T- W' K
#define S23 14
1 t7 o+ R/ H* {* i; u7 [6 X#define S24 20
# \+ g7 z' _; P$ ^1 w7 D9 H' F#define S31 4
+ ]6 a% q" x a$ Q) `- D! t ~#define S32 11 v/ p; v [& Q5 O! o& |1 K, G7 ?
#define S33 16 ( U! s9 F8 N/ J- L- \
#define S34 23
; L$ j7 p, m4 v9 ?9 y( ~5 r( W6 N! a4 E#define S41 6
" z/ u) j8 t2 I9 k0 M5 g; |#define S42 10 5 G! n' b9 e2 w9 B6 ?9 [* W$ C3 q
#define S43 15 q# C, U* `7 U7 T
#define S44 21
: v7 l& d7 W3 L* z0 g# J' D( @
6 B$ F8 f) c2 X2 w% `7 `4 a# estatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
! [ Q/ m! t5 F" B, m. O$ rstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 2 N. z' O8 |) p5 P, u) n2 O: T
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
3 d$ \! g& C Y! u8 ^static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
2 ]8 |2 n+ C7 ^3 z Lstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
) g* }) ?: J% Z1 M# W' ~
9 d" K N/ ]1 l( o( z* w( istatic 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
" K" C* O* s: Q ^* x) w}; U, Y2 z6 t& F# y4 ~
3 S' X! \1 z% f; M: F1 s0 d3 p
/* F, G, H and I are basic MD5 functions. */
! O- [! l9 O7 y+ M6 n0 L: i#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) , G! @( T2 G( ]. D) n" A
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) ( @4 n- ^! L$ F" z. a( r; k q
#define H(x, y, z) ((x) ^ (y) ^ (z))
$ {, j9 e' F2 p8 k8 w) l#define I(x, y, z) ((y) ^ ((x) | (~z)))
% A8 ]# a) C, Q9 Q * q7 M6 k. }' d7 x* a1 J
/* ROTATE_LEFT rotates x left n bits. */ , _4 M! N4 ]2 ?
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
( `' ?& t- r! h3 n / I6 ~9 T& N9 i) C
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
* D# x2 V J9 M& RRotation is separate from addition to prevent recomputation. */ 7 _$ P) u9 H. 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); \ }
3 q# X: L* a2 F: t2 z& e l* N' `! G#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
6 \. M' \' k/ k$ m2 Q7 F#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
' K! a7 O5 X. C4 w#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } , U0 Y# J/ S+ Z# V) p: s' p
* |) y* Z& ^! @ Y3 ^
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
u+ |' u" R1 n- ]+ ~4 _/ I3 Xvoid MD5Init (context)
+ ?# j. h1 t2 v* T% QMD5_CTX *context; /* context */
# n. w' Y6 S$ w% a{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ) H' w ^9 S( `: C- s% T
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 7 u8 j0 [% y& N2 {6 j3 K' x6 @
}
: m( T0 y# e% T" I1 B
: l( E$ ]' g* Y2 ^/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ : \* \, i* C, i; c
void MD5Update (context, input, inputLen)
, W% O4 V" r5 XMD5_CTX *context; /* context */
8 `) _# q; y( q/ J5 I3 A& \unsigned char *input; /* input block */ , ]) [+ o5 L1 I) `
unsigned int inputLen; /* length of input block */ 2 y; Y5 E1 r1 U# i* S8 I4 ~
{ unsigned int i, index, partLen;
- o! ~ k, {7 y9 V% L0 o& E0 p: o /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 6 y4 M: b3 R# c5 _" F t& a
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|