|
#include "global.h" ! F6 {- ~+ Z B. u# r
#include "md5.h" 6 u5 K! X6 Q% s8 q- b
- k7 f; j5 O* q6 R/* Constants for MD5Transform routine. */ 0 W- b; L: {: n2 }) t9 j1 P3 t, T3 h
+ u/ R* [ q* M! _& ]. Q+ O# }
7 G5 Y+ I1 d5 V0 P3 m3 A
#define S11 7 3 q& I/ }& n @* v+ `& p, ?
#define S12 12
/ ?. A Y" Y: W: s' ^#define S13 17 ( [- Y. I3 k6 i3 M% S; A
#define S14 22
' N+ T7 m( [. W+ F9 \) l% A6 ]#define S21 5 6 S' X$ K0 Q. I& t. ]9 y2 ?: m% H) V
#define S22 9
- |, e5 J: o) f4 Z, d: t#define S23 14
; z+ A) {0 S+ H( q9 {: F$ I! u#define S24 20
5 P3 `! w2 h$ b/ M#define S31 4
& h m# r' Q0 a% x1 D#define S32 11 0 O* E* M; h* ~6 i5 I, o
#define S33 16
C( L5 \$ s4 f5 Z; x#define S34 23
' _: Z Y/ E7 o. F2 R#define S41 6 # g2 J- x, G: o2 z% f0 R/ s; N
#define S42 10 2 z6 R" [" N6 n) r
#define S43 15 ) X, |; t+ G% S& }. h9 |
#define S44 21 6 u* d; [7 c% x& T: u. \
) }/ }! \: c* \4 C+ T4 bstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
& _" B" n7 P3 K# s2 L& ?: Zstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 6 i! v2 A0 _! S1 r, ~* t6 _" c
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ( t( A7 ?# N/ M8 ]3 w/ |1 W8 Y
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
0 m: n, I& U5 e b, |static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
$ o# f% ?/ |* k, {& A: @
- [: {3 W O* U: `% f: Cstatic 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 $ N! ^1 z: T, @# A. c% z
}; . C; v8 C# O+ B. ]
3 Z6 }- }' g1 x/* F, G, H and I are basic MD5 functions. */ 9 Q0 W, ~& s; H p" {" W" l9 V
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
2 w; r2 O+ |6 c6 Y#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) ) |* k* c* s7 m/ k8 W, W* P$ ?+ B
#define H(x, y, z) ((x) ^ (y) ^ (z)) 1 u' x8 G8 g% u
#define I(x, y, z) ((y) ^ ((x) | (~z))) / g0 x3 M- ]4 I7 P5 ?0 u) g& ~
2 ^+ F: l& \, K3 C: P* e/* ROTATE_LEFT rotates x left n bits. */ 3 ]' k' R; ~; Z3 `
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ! X7 W; f4 M# z- G) u$ v/ k
8 V" |! o, G" `% [* b3 h% y/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
* }" H) y+ F" h5 T+ oRotation is separate from addition to prevent recomputation. */ : P/ E' g6 e+ D0 p5 x# h Z
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } . ], T5 h0 j. 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); \ }
4 C0 O) ?/ w; L- y" m9 Y: u#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ) T6 F& A% J% o! \# t
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
; s1 M, `7 G3 Y8 L8 v ; i; |" k7 w# f3 U0 j$ H
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ; h1 K$ f! f% C' q4 M+ P
void MD5Init (context) 1 L7 {# H. c" t5 m4 @, x
MD5_CTX *context; /* context */ , b6 U: M1 j- Y' }) a, y
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
# G' K- S! k7 v9 T: N1 V*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; " Z/ S j& U. i* [
} & V0 r- d# n0 x# f! R1 d% ?
( A4 {* Y/ G) f6 _5 F Q$ N0 g/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
2 s+ Y: t+ {/ G1 g1 Zvoid MD5Update (context, input, inputLen)
& W. Y! p' r, O3 E% k& X; |$ r) x7 \MD5_CTX *context; /* context */ 0 U' b |' a5 n! ^$ b
unsigned char *input; /* input block */
+ ~4 @1 f" ?; n5 S3 z3 ?unsigned int inputLen; /* length of input block */
- t& b; j3 r0 a{ unsigned int i, index, partLen;
- f/ g2 i+ n' L: I /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
/ X3 E. e- O$ @7 _, H /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|