|
|
#include "global.h" ; N N3 Y; y; A# F, ^, A
#include "md5.h" ) U& L8 B; H1 c7 o A, i
- |" F4 v; l a- {
/* Constants for MD5Transform routine. */ 7 _5 K" E) m4 @6 b: u3 p! o
: C1 t( T _9 m- ^4 l/ D8 W' r+ [
9 F. N" ]8 D, D' L% ^#define S11 7 9 o: C: u% M( V0 w7 l- s8 b6 ^
#define S12 12
; X% A3 t; ?' O; a#define S13 17 ; h8 `& H; T; X' {
#define S14 22
! e6 @/ W, _! y, P2 U4 e#define S21 5
4 \& A v" w$ y$ R& e) s#define S22 9 6 `" Y6 i' c1 l2 B& M( I* g
#define S23 14
9 }9 W+ F3 F# y, l0 P- V4 T#define S24 20
0 D# l; I1 g' j#define S31 4
6 t6 a( Q$ c+ ^#define S32 11
1 Y4 I j3 D5 j7 u#define S33 16 * u2 N. A9 h, ~, e% Q
#define S34 23
% J9 Q1 F. F) {: y; R6 K#define S41 6 & e) a' ^ {2 w; ^4 r/ y
#define S42 10 5 r6 U5 D: c5 z$ M% s% U
#define S43 15
! ]. a9 f* |8 T$ T' E#define S44 21 ( K! M! u |; G" l8 u7 I" v- l. x
3 i& Z( |8 p7 L& l+ {: Hstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); + A5 `8 K& R1 j6 S R" G+ o
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
* B: A# e h# ]$ _static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
# \: k3 V0 Q- \" y& Y- E& q$ fstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); ' e! u- R; y( w& g- d
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); $ g$ O3 k7 K- |
. y. v& m) G0 A6 }) k$ nstatic 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
5 ^0 ^# |4 }" L}; ) b6 k; C6 ?$ K7 [+ h) {
$ `7 b+ s" i N' L% Z( x/* F, G, H and I are basic MD5 functions. */
% c3 C4 {3 t. G$ H E#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
& r* s1 H" {% s3 c& k2 G#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 4 H4 H5 H( o0 @5 R4 n4 e
#define H(x, y, z) ((x) ^ (y) ^ (z)) V8 e( Z9 `2 N! Y" g) F) j/ J
#define I(x, y, z) ((y) ^ ((x) | (~z)))
% \9 H3 |3 P' X; N s; I( C# `5 [
5 Q, C- F; g9 K" u# Q$ q) m/* ROTATE_LEFT rotates x left n bits. */ & h: F2 V0 e5 C- P4 G2 f! {
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
! \% y0 H0 G' N8 P% F+ f
" ]1 B X. ]( l& b/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
1 U5 m9 E. D$ m [! h; o+ oRotation is separate from addition to prevent recomputation. */
) b R3 u0 a6 k# y7 h#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
: L; v+ n/ ^* a* o- s#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } & Y% U9 i$ }9 W: I
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } * P9 Z$ C& t: m) [! ]* J
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" m# u2 h2 j+ Q r 6 H W* p- d) _4 c
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ . M# E* k* y3 V& u% n- J
void MD5Init (context) p' \. C' [/ W6 g+ {
MD5_CTX *context; /* context */
2 v+ M0 L4 L: C: x$ H{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 5 E/ P5 `) t& Q \" P. d/ T
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 4 O1 I, j" \/ `9 d* g4 s- s& F
} ) J' G- e1 ]: H& e, R& b
9 @; q- H% K7 E/ M& G% U/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
2 G! Q$ z' {# u4 B% P' ivoid MD5Update (context, input, inputLen)
9 D: T) S* Q8 R* L# E+ e1 e/ o: DMD5_CTX *context; /* context */
+ z2 [% u9 e- c; t+ eunsigned char *input; /* input block */
% t; W+ x; _- vunsigned int inputLen; /* length of input block */
8 w/ Y1 A% H4 i/ M; _ _{ unsigned int i, index, partLen;
: x5 C0 \1 T! E5 \$ g7 w /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); * q- a% ?! j) B; m/ {
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|