|
#include "global.h"
4 d" W) J) L3 E9 C5 o( _; C) i% ^' p#include "md5.h" 4 Z7 M+ @1 z9 ~
: g) d4 \( | J+ u: e/* Constants for MD5Transform routine. */ 0 P- S2 @* Q9 r* a7 D* k
$ x$ n0 P: w1 E# Y
; `0 c% ~& `& I3 O#define S11 7 9 f6 y9 B8 a P7 M) H) q( Y$ P
#define S12 12
3 C& t0 n& }1 q: v8 R; f#define S13 17
+ u5 D$ b( V9 o9 [3 N' I$ t#define S14 22 8 q: ~& t7 K6 j/ ]" |& L
#define S21 5
8 {- s% H$ c# }) R#define S22 9 ( Z- z- A$ D! P! h/ B7 N
#define S23 14 4 _( D, h( Y! f
#define S24 20 # L* M1 z* G. l! }& L2 F5 N
#define S31 4 - _; B U. [$ }( e* S; A% G
#define S32 11 3 k$ B! h: y7 | G' i# l* C
#define S33 16
8 F& i. \. o. ?9 R#define S34 23
9 s( u' ~7 E0 l9 a l$ A#define S41 6 $ ~# q3 w4 j0 _- Q! ]% J
#define S42 10
: O1 B4 a* Z! ] L; G* S- [#define S43 15 8 G# r' {' \& f9 Z: ]
#define S44 21
# W; o/ |1 C P8 B' @8 \/ o6 p ' |) Z+ p- c0 q Q5 ]4 v6 `( b
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); % [# y) P* P' C6 [" u) r' @
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 9 M% o/ T0 w$ U n
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
* c z+ ]$ B. }2 @3 }static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 1 C( X" ~7 z; n' Z3 i4 t
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
+ x2 B6 p. G' `. J" q9 m
. C" L3 N& |( f, z- q# vstatic 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
+ p& O3 F- N# o};
" h( s6 [$ G1 t2 H4 b, D
$ e) _# D# v: Q7 _. T5 Y( x/* F, G, H and I are basic MD5 functions. */ * v7 x% k$ c, c! i! T
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ) A& M* r) j- `( A2 h
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 1 _6 u" h) t N1 n3 }+ ]
#define H(x, y, z) ((x) ^ (y) ^ (z))
% g+ }, J' P/ f# |7 N9 m#define I(x, y, z) ((y) ^ ((x) | (~z))) - [" K8 R/ y5 T, e/ F
: x2 o! n* u0 C6 Z- ^8 T' d/* ROTATE_LEFT rotates x left n bits. */
8 }3 N7 t) W0 ^6 X+ f& O#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ( r, |7 n* R- E% h. K" R- U
4 h% z0 n5 L% q0 |
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
. t" O8 e% f0 Z- F$ VRotation is separate from addition to prevent recomputation. */
. o N& ~1 n& V' q. ]3 d#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" C# |5 ?$ }9 T#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } # f9 [, S' S! N# b
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 9 R: N& c* [0 {) z' `
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
6 @# Y" y* \% S7 s* O2 w% Q( q
& v6 ^6 f1 V8 i7 V/* MD5 initialization. Begins an MD5 operation, writing a new context. */ , B0 G& K: [- m+ J5 D
void MD5Init (context) / r T/ V, E$ M1 @4 F3 U2 I' A$ |
MD5_CTX *context; /* context */
& f' f: ^# {- J1 i Z' u$ g{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 8 h" q0 |! w6 K- B4 `, ]# K' ]
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
1 m% D$ x, E/ E0 `}
7 q, |" W) a; p: E* d
1 `8 O# k4 ~9 c, A8 P9 Q/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ # a1 k0 }& \4 Z
void MD5Update (context, input, inputLen)
* h% d, Y4 p; C+ \$ ~2 ^MD5_CTX *context; /* context */ 7 _2 a7 f8 ~" e
unsigned char *input; /* input block */ * j) o/ G& B8 j7 G
unsigned int inputLen; /* length of input block */
9 n+ K! L( H3 p7 x{ unsigned int i, index, partLen;
4 A8 ^. x4 k' v L" j /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 2 ^; ]- W( Q& e# A$ g# q& Y
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|