|
|
#include "global.h" 3 X9 S/ x- x! _0 F; v& P7 z# h
#include "md5.h" ) A- i+ C% x, Z; Z
) z& u# w2 ]( p3 }+ s K
/* Constants for MD5Transform routine. */ , \% E7 ^5 F/ O0 ^0 Q) \
5 g7 k+ E: }% U1 V$ T! x7 ]
! v9 d( O9 P- _1 g2 X#define S11 7 1 J3 Y4 X9 z; k/ n3 G6 Y% w
#define S12 12
3 ^6 T; G! P9 q6 r9 ^$ ~9 w#define S13 17 + w+ t% V1 j: B& ]
#define S14 22 1 U; B' l0 z5 f }
#define S21 5 % c$ {1 Q2 N+ M7 h
#define S22 9
M) {- l. ]3 q- D#define S23 14 5 }: T( ~9 H) I1 z* i7 _* p9 P
#define S24 20
) P6 N' y t: C, L+ q) }4 h#define S31 4
& Z# G$ |, i: G3 |#define S32 11 # H1 V5 K2 ]6 q4 U$ \
#define S33 16 ' O1 w0 G( p7 t: y
#define S34 23 4 `0 B8 }2 j/ u" Q/ p) u
#define S41 6
+ C ^4 V3 o2 o3 j#define S42 10
9 ^8 u& q/ k( r1 b#define S43 15 3 `; Z0 Q4 n: s6 `- v' T
#define S44 21 6 ~( w0 Z5 [& f. e5 w5 \8 G
( [ b+ F/ E* I
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
& b y& s5 N8 f- A) O7 d7 Estatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
$ r, o, e- u* H% h# Istatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); # g. W" c$ C& A; M$ m9 H! |% f- ]6 c" {
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
6 B, M5 W2 i b& g$ K, b4 p; Bstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
/ O# \9 G, j/ \0 k
; I! V4 V$ k4 C0 `3 E) {+ g- Mstatic 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
$ V3 c3 {, ~# ?( b};
' t1 Z! R0 Z# Z( P" p H" P$ {
1 A# t9 T+ T2 _: P& j/* F, G, H and I are basic MD5 functions. */ 4 O4 R2 P7 l% |
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
9 j& |! S9 y& W o#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) % a! h% Z' j9 g5 c
#define H(x, y, z) ((x) ^ (y) ^ (z)) 9 F+ E, E- o1 z/ M
#define I(x, y, z) ((y) ^ ((x) | (~z))) ) K+ x: E" A. r$ _/ h
& F R. [. {( X* u$ e
/* ROTATE_LEFT rotates x left n bits. */
- H6 s. d( r/ ~- H4 \5 ~#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) . |# V- ~( Q) ^) X
" t: t# a; U/ @4 A a& b# d* j
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
' D% y5 z- u) c1 ERotation is separate from addition to prevent recomputation. */
2 J' B' \& m/ n l#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } + S+ S9 a* ?% m2 Y- L2 u/ T K2 J
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ E4 m+ C% S0 z4 R. i: n#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
4 P2 b* x4 f: }; I3 q% D6 C- p8 C#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } # Z. L8 ^6 u$ |% z U3 g% Q
) O. j# h8 ]1 a5 V1 ?
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ! k0 @) s. y' t! z, g6 K" n, j
void MD5Init (context)
5 g$ O9 M' T1 S5 v& w( aMD5_CTX *context; /* context */
8 h i! b0 ], S' }8 C{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
( B' V3 e0 w- y0 ^! ^5 @*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
! ~4 y# K Y+ L+ u. L}
M* m: S. h$ W6 w % H9 C+ c6 o) q) g
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ $ C% J& O9 t" [
void MD5Update (context, input, inputLen) 6 N; g" P# ~9 W, \
MD5_CTX *context; /* context */
$ j b6 `2 D, l& cunsigned char *input; /* input block */ ' U- q0 U2 H% y, c* v
unsigned int inputLen; /* length of input block */ 0 k; t1 X4 Z; Y4 w+ n
{ unsigned int i, index, partLen; # i7 y; {$ C2 y6 F
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
; V% w( c' W7 }. S; y+ l) z /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|