|
|
#include "global.h" $ e$ z: |) o# F# S" l& D
#include "md5.h" " V, r' M2 e z3 ~
4 `0 V6 ~; h% U
/* Constants for MD5Transform routine. */ % [" R8 F8 F! R8 w; A1 ]$ h8 J
1 e/ @8 F. N9 u' p m% _ c
# ]. N3 Q, \9 F' Z8 m3 e#define S11 7
- h4 B: Z! h, a ~#define S12 12
2 x: b3 c5 A* B7 u6 f#define S13 17
6 X$ T, |7 H- J+ Q/ t#define S14 22 * P: m% p1 S2 k; r! b0 m
#define S21 5
. T& w/ ^( }& ]2 l1 m) N4 @1 }0 n#define S22 9
7 F0 @3 V5 v0 [5 m% k#define S23 14 $ @) L9 _% u& B* T3 X- F
#define S24 20 % N! J, ^6 [, \5 q! @( k
#define S31 4 ; U5 k" {# _( x$ |5 p0 `
#define S32 11
; b; {) [" l+ a& S#define S33 16
4 W7 {( d& D. k7 M7 d0 R#define S34 23 7 u) C! C% o3 Q! ^) I$ Z
#define S41 6 * K/ h0 i9 V2 x; D
#define S42 10
% W; @8 N; X8 [+ Y; f, D#define S43 15 8 y8 `& J: J, s' n- d
#define S44 21 ( M; j! B" O, W4 [% F
0 K* [! B: c" s p1 O% ~. `' rstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); & x' l) \1 R# R" X% ^. @; @
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
: F9 n U6 x! @5 l/ ^' _( S# S, bstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 0 L, s( n4 x3 l2 ^1 r( i. q
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); ; H7 h7 s! d$ `" V1 y$ M
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
$ g" o5 l$ T3 c8 _. f
$ Y4 i( X3 W6 b7 Z& Lstatic 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
/ T: \* c7 k6 Q/ t; m( a% z}; 6 i% a4 y+ R$ N5 N6 L& b
+ b$ c3 \& |+ [* y* |4 O. K/* F, G, H and I are basic MD5 functions. */ 7 O7 z, y- X1 u7 P) E, u
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 4 i g$ O# L+ l8 Z! v
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) % `" E$ {0 |& O7 `2 M+ f+ P5 W/ V
#define H(x, y, z) ((x) ^ (y) ^ (z)) ! ~+ \" j* r" J6 ]
#define I(x, y, z) ((y) ^ ((x) | (~z))) Z3 j7 x" s( ~' `) ^) u& x
; m( U0 ]& ^. R/* ROTATE_LEFT rotates x left n bits. */ " E% r1 l& n t
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
0 e7 D9 M% \8 r# ^5 y4 h
$ A; ?4 a' X1 }* M8 h& D# W$ A/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
. ]& L1 i, u$ X# b0 ERotation is separate from addition to prevent recomputation. */ ( `( Y* \8 p+ a; b& u' f' P
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
) G# R# o; {1 B# M; k$ U) ~#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 f! Z4 r6 {" m! u& J- _" A# S#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
6 q+ b- B" L& m+ v# o#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ( X7 i) t' ]* ?% F3 b' c
! c/ O; q8 L0 u1 E
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 8 @( l, ~( [) _' \5 j: @: \
void MD5Init (context)
; M7 \- @5 p6 sMD5_CTX *context; /* context */
) v2 e% D+ K9 H; \& B f& ?5 \{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 5 C! e' ]; a* H( F! Q
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
* }/ v2 |( d5 d( D}
% M6 P. W4 ?- K: d! K- F$ e 3 z+ H' L& ?& @
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
Q5 G) b6 z! }+ K9 ivoid MD5Update (context, input, inputLen)
) D. [/ I/ j2 SMD5_CTX *context; /* context */ 8 C7 }1 c. K& ?7 ?) g& |
unsigned char *input; /* input block */ & @! `' H# L' K: G! {* g
unsigned int inputLen; /* length of input block */
, K; C8 E, Y+ a' |& k{ unsigned int i, index, partLen;
1 f( O @5 F% y: A- }: h /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 0 H+ D- o+ p M6 y$ Y5 @! O/ x1 M O
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|