|
|
#include "global.h"
- w9 a2 r0 a# O( Y#include "md5.h"
7 P! u. @4 R5 e. { : l0 ?7 A8 ~& f0 e# j7 r; p- e
/* Constants for MD5Transform routine. */ ) F: g8 w; m. u! u7 }1 ]/ R
& a2 F( O2 U$ a' L9 a
6 E; ?2 r, i9 D7 ~+ i
#define S11 7
0 O" k/ E7 e# q: H9 J4 \#define S12 12
, a! M. y* ^6 \1 }#define S13 17
; V/ s, J. m: J! Q+ _+ P& B1 x#define S14 22 6 p' ?2 B o0 v% u" K* H
#define S21 5 & T# }; x/ u4 l1 A* X
#define S22 9
3 ]% N- K8 Z8 a; |# Y& {+ P" ^) V#define S23 14
# A# p' _- n _7 i- f- z- Y- S! u#define S24 20
4 W2 Y* \ Z o0 L" W/ Z# f" \#define S31 4
2 o9 Q- X8 ^9 p& u5 W( `; L#define S32 11 * ] c, f) C/ ?# O3 }, k
#define S33 16 & w. S6 u$ y, E
#define S34 23
: T$ I/ W+ Z' @+ H7 [#define S41 6
x# M/ a5 \7 q#define S42 10 : G5 a* E2 E3 b
#define S43 15
( l5 Y5 D) y. J1 p$ R7 y7 c& j#define S44 21 & o% Q/ {/ ~! @) C9 b
! i2 J* h# w$ `$ w- ~
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
8 Z9 K* o1 R5 J# z4 a/ xstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
/ Q8 G- _/ T+ B: U' D* Istatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); . }7 p& d0 W4 G z
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
$ M* x6 X+ P j: J+ Vstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
# C6 L9 m. b A6 t' G5 | l- p& H5 P2 G) C9 a2 [
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 ' w; g0 M! W" T0 Y2 h' U
};
, O& {; x& O' v, {7 N' s* G& {
2 E; t: P. v! T( M* e; O! g4 B/* F, G, H and I are basic MD5 functions. */
$ a W0 f( M5 S( d#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
; c1 ?# R+ e1 I/ v#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) ! |# l( w0 ]' t+ Q5 H) T3 s
#define H(x, y, z) ((x) ^ (y) ^ (z))
' V0 y, a, N$ n/ `#define I(x, y, z) ((y) ^ ((x) | (~z)))
F" G) q/ e ~' [# [; v9 [
% F) {& b6 s ~# q/* ROTATE_LEFT rotates x left n bits. */
% }- `5 A; k* k5 {7 D+ ]6 M! D#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ' L( \0 } L! R5 A. V U% _
" Z4 Q9 r- M1 h8 y- f" H/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
. ?- ?7 p+ K/ `" M0 U. FRotation is separate from addition to prevent recomputation. */ 7 M% ^' C& _) Q. 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); \ }
0 a W, g( m' Z4 a2 s% j# A#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
( l: {5 T6 q2 J; O( K3 J9 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); \ }
. v s+ _: ?9 f+ h# {#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
9 K- {: S' g) [% x+ f- t' ]; s 1 J# d0 c% |2 ]* u# c
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ + B3 }3 V/ d+ G+ X2 a! e
void MD5Init (context)
$ g" t8 H( q) u% v4 a1 U, I% _MD5_CTX *context; /* context */ ) X. T. u) ?8 d( a7 z2 z5 _
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
' v6 P0 E" w8 k; h$ k*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 3 t, z# E' T% ~# z
}
" n) y' M) J7 V% o) p* i
4 f. M1 q& ~) t8 m/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 8 ~9 K: l% w4 K. A5 O& m
void MD5Update (context, input, inputLen) " V m6 A$ ^3 [5 N O& R7 J6 O
MD5_CTX *context; /* context */
+ P) z! m/ ?) r9 iunsigned char *input; /* input block */
7 w/ @ z3 j6 i+ aunsigned int inputLen; /* length of input block */ 6 g6 e! j6 c. Q! H
{ unsigned int i, index, partLen;
8 e, ^" q3 J; y, v- j /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
) ~& \$ x' M+ W5 F /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|