|
|
#include "global.h"
$ F' [6 m$ e0 H/ q; E0 Z& ?6 X#include "md5.h"
, ^ k4 H g# p# I. n5 j' M% C ! p. o A) E* Y( D3 W" T
/* Constants for MD5Transform routine. */ , `" G1 w: r" f5 Z5 A
1 }7 M2 M$ ?+ v 0 L$ M* Y! w+ k2 B- @8 J2 e
#define S11 7 " h$ P% t3 _( V [0 {
#define S12 12
( Z8 C1 F- q6 g' ~5 w#define S13 17 8 V0 P& I5 }* R
#define S14 22 $ l6 [9 J6 s) ^, H& `( {
#define S21 5 5 j6 i; M' G; W! K, `+ U( Z
#define S22 9
# ?9 d" ~% T0 H" C1 ^#define S23 14
2 Z9 X! F4 ^* @2 [3 D#define S24 20
1 t' L/ A9 E, _/ f#define S31 4
w' O' V+ [6 r# C#define S32 11
3 H) ~* G( z* `3 m/ m#define S33 16 : o6 m' f. @7 s% ^7 Z
#define S34 23 & \7 H3 n+ B j! A, X( H8 X- Q
#define S41 6
z1 h: ~* X" w2 O5 m; e/ @) }% R+ P#define S42 10 9 z+ v: G* g. K6 {0 F
#define S43 15 " M F: h+ P( _4 }4 ~8 E& u8 @! h
#define S44 21 5 g% E: s# Z# R5 Y( q
3 ]+ d6 k; J7 C$ @
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
+ r; {6 N X$ _, Z5 ~static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
+ ?3 C$ A! Q, @static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); & s7 A! z) _. x* v- o4 m
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
0 V' `1 @$ q- `# q2 P' E( _, wstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
3 w% D& D ?+ W) r
' a* @, ?, Z* ustatic 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
- ]) E2 D) f L( o2 c3 e$ l};
2 {$ P( ~7 \1 M4 ? $ e- _+ E" B7 q N+ E/ _9 K3 ^/ w
/* F, G, H and I are basic MD5 functions. */ 6 H1 C3 ~6 F8 ~# c
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
7 p9 N. ]4 G9 o% F. D; [2 f: M; q#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
: I2 ~2 f! {) l: }. f {#define H(x, y, z) ((x) ^ (y) ^ (z)) ( d+ J- k; Y H* b! o3 ^
#define I(x, y, z) ((y) ^ ((x) | (~z))) 3 y2 j2 ?& G3 D) l, K
7 j% v e; T+ J3 e5 x/* ROTATE_LEFT rotates x left n bits. */ & i& e( L c' T( d$ E) j
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 9 E1 s Y; c- K( P" G
+ V% m, j3 d; ~' ?6 h+ u
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ?6 R2 p7 O# ^! r
Rotation is separate from addition to prevent recomputation. */
7 w' X# 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); \ } ' D* @! @$ {$ B% o6 ^
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ) w. d& f6 z% y8 t; d0 }1 E4 O
#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 w# ]9 r' _; H6 H4 [2 p#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 4 g- N0 N N0 v+ I4 c5 k U
5 }. [6 v4 r! f$ Z Y0 N: r8 u6 g1 Q) u
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
: o3 d6 J+ K* I* n5 I0 x4 I6 s) jvoid MD5Init (context) % @7 y* I# H e" i& D8 a: C
MD5_CTX *context; /* context */ 9 ?; l' z9 _1 e9 b" B
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
1 A1 T% q, h, Z: i, T( H*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; ( W" L$ i5 ]$ h/ ~9 d$ } x
}
4 w! L H& @$ S {& @
* o& C! j# d2 l/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
/ s1 r) d& s7 e/ d7 |void MD5Update (context, input, inputLen) 6 g3 h7 @* f0 R$ f" y! [
MD5_CTX *context; /* context */
8 s B; U* C5 `: zunsigned char *input; /* input block */
( X; n6 n/ Z1 y) A3 Gunsigned int inputLen; /* length of input block */
6 L; X { M7 L! i+ h& g, p{ unsigned int i, index, partLen;
( h( d1 y& G1 m0 B8 W9 w0 u9 _) T5 T% o% Y /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
4 A. w$ N" L4 A- Y8 R& p /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|