|
|
#include "global.h"
% Z5 t; {0 b# D* R, {#include "md5.h" 2 J7 c: ]: Q% E
6 \/ |/ I0 f& Y5 R4 R
/* Constants for MD5Transform routine. */
7 c2 Z+ O: n: E) `" {
% j7 ]4 _: x, m4 S6 Q/ S1 s ) O& J. r% }# l& g- H) d2 H
#define S11 7
$ L/ g4 ^' O. }# S#define S12 12
) j, B- `5 ~( R3 \9 U- t#define S13 17
7 t: ~9 T* {6 Z8 F/ T#define S14 22 6 G7 G9 n, x; X+ _5 A
#define S21 5 % X/ }% k& Z# i# Y+ U" y# R
#define S22 9
+ ^0 k, K/ K) t. ]* M% e7 z#define S23 14
5 \( [% }. N! Q: s' \- w#define S24 20 # l* R, c& j4 D7 I% n! y
#define S31 4
& Y% I2 ]/ f! j#define S32 11
2 Z9 g: B9 g" A9 Y/ d- F9 G1 J#define S33 16 9 R3 Z8 ]+ ~3 `& a% ?
#define S34 23 ' H1 E7 `5 I/ H# Q" R
#define S41 6 ' {' L$ {' ^! y& A: g! @
#define S42 10 1 s; m) N3 B8 D A
#define S43 15 : r# G/ J- O$ W+ m( z2 n8 Q* |- O; y
#define S44 21 1 T* v) {. a( W$ n% w
0 a5 Y4 D0 I0 m3 Bstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 2 b/ j. ], J2 T2 J3 x$ K5 b
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
# o& N5 I% p" a) J% S0 R* G* ustatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
, Z* I1 I! o" T3 g$ o \9 \static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); / ?0 V3 `7 O: W9 a; H S
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ' {: N; n5 w; _! a( E3 N
7 }6 I) H, l6 A) E1 _
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 9 e+ F) j- x1 h
};
& `6 Q- B; J C$ B* m! Y) m
. S3 W# C1 }3 ^# R/ ~* _( R+ Y/* F, G, H and I are basic MD5 functions. */ , _2 L. _2 ?2 z" M* d
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
/ j7 z. j/ V2 d' y# B#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) : ^. O! c8 A/ r' d9 n
#define H(x, y, z) ((x) ^ (y) ^ (z))
& y, [: t# L- E0 _#define I(x, y, z) ((y) ^ ((x) | (~z))) % |. O/ I1 y$ t( o2 p
5 _- B& I0 L( X+ B% j3 R' x/* ROTATE_LEFT rotates x left n bits. */ . I" G2 [4 I4 G* w1 m! ^: b* g
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ) N$ _) ~2 d$ i% h1 h! O( @" h! A
. q* V0 P- E% l% ^! U/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 1 U0 B# E6 F; j. K% N
Rotation is separate from addition to prevent recomputation. */ # g7 k1 ^( U# m- D+ ]( y
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
; j0 l, r% 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); \ } & O2 W# t9 W: _( j! R+ M$ [7 K
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
: t8 P; V5 W+ W6 N#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" U) {+ ]/ _' ~; O U% Z4 U6 G1 H 8 @% ^/ H- J5 K. A) T/ ~% X( C
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
# F" } p3 e A% x, f! rvoid MD5Init (context)
5 c ~6 ~" S5 w# @MD5_CTX *context; /* context */ : F1 e: a2 m2 {* O2 V: O0 n
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
4 C/ E- R! m: {/ B z. _*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
/ S; W7 y- K/ U k}
2 m# Z* [7 T1 i3 P % ~' B/ J' E, U; g
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
8 Q% o8 J: j4 @% A# Svoid MD5Update (context, input, inputLen)
# e( j a) _6 @& m2 HMD5_CTX *context; /* context */
) _+ Z) \: J; H5 Q2 iunsigned char *input; /* input block */ ; A: Y7 {* o z) N, Y
unsigned int inputLen; /* length of input block */
# t5 p4 s9 [2 v3 v" h1 G{ unsigned int i, index, partLen;
9 M2 Y" T5 x, e. t3 K /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); # k' j% k; q+ O1 B1 E. E3 t) x
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|