|
|
#include "global.h"
/ w1 Q3 D% {; r% r#include "md5.h"
. ~: Q; a$ W. j/ W7 f ; n4 B' m _4 e" E/ G8 _' N
/* Constants for MD5Transform routine. */ ) k9 s6 k0 M5 D9 K- A0 ^2 U
3 p4 A/ r @$ g
! p" E' I w8 W, T
#define S11 7
w! X9 B( F$ k: z#define S12 12 0 L& d+ b: m5 t' ?$ I
#define S13 17
, f& W/ R& X" }+ A8 J#define S14 22
/ ^8 s4 s5 t9 ? m* f. F#define S21 5
+ Z: ]. f6 l8 f; _2 Q$ A# B#define S22 9
2 L: [3 u) n' q, M( B4 }+ o) s#define S23 14 & L+ P' Q* `' d6 E& t; A) C
#define S24 20 ! W$ z* a1 y" q& F
#define S31 4 2 A' ] T' M+ Q' e: {- b0 S' u
#define S32 11
8 F0 A: J( o3 G) \1 p7 F#define S33 16
: a% h: `" u X! \#define S34 23
+ K% L+ K( k0 |4 F9 r" n2 d2 b4 q#define S41 6
+ b8 \# q2 w u! i) }#define S42 10 . W v, u$ H* d X V) U' F
#define S43 15
i* \2 a0 X0 c* W5 D& U8 s#define S44 21 & U* c! q }% r8 U1 }0 t* E
' e: a5 h- l; W5 bstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
6 t* p& K9 i# S* }& U% [static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
+ `" _ V2 n' w7 a1 hstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ! u7 m g/ r+ P" i: `
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
+ R6 M( r1 h: Mstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ( d4 O7 S+ m2 l0 p
" r: a, q' N6 j, t" m! q8 o+ l
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
' @, L! R. Z( E, G8 h}; : M$ j1 l; X! H% F4 C9 L! O- A
l3 u R2 H9 q/ T' n/* F, G, H and I are basic MD5 functions. */
4 H: B7 w# E i4 g! I3 X#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 9 R( j0 ^( n3 T4 |# {
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 1 s' m4 z. k. ]" @9 b& H9 Z& [
#define H(x, y, z) ((x) ^ (y) ^ (z)) & y7 E! c7 k" k1 }9 J/ G5 D. q
#define I(x, y, z) ((y) ^ ((x) | (~z)))
3 n, E+ f; v; }0 R5 B# e* y + \; C1 p" F7 ^, v1 o0 V
/* ROTATE_LEFT rotates x left n bits. */ 8 F& v2 _8 _( t6 Q& J& B
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
1 w) d1 u. F' z- G 2 p: D) k$ C- K) M% C8 d% D9 s
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. + t1 x3 k. v3 g' x* O
Rotation is separate from addition to prevent recomputation. */ + Y$ w- S0 H7 u- _, E8 t
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
/ O# j- W4 L" u( g; a( S#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
6 W# i- Z8 h" 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); \ }
6 R# l4 I, N5 B4 _" Z. U2 u, [8 g#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
9 ~2 f" N6 N' E6 d. c% l & e+ ?. O2 y& q, D7 X( P
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ; x8 |# k1 h! T
void MD5Init (context)
9 j' c" s7 f' K6 P% Q2 G! l* D. uMD5_CTX *context; /* context */ 5 I# Z! [# n# d: |; P. W
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 5 J* k' [$ g0 X& K0 }
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 3 z% j8 J2 s# r2 @7 t8 q. `
} b8 `4 s7 @! m& \3 x
4 a. ?& x; |5 J1 k/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
8 ]; |+ {& ~' ~ g1 [" [void MD5Update (context, input, inputLen) 1 Q* i# h5 V0 Y; @- B% d
MD5_CTX *context; /* context */
, k0 S3 x' L5 ]" H9 ounsigned char *input; /* input block */
* i/ c+ m$ h( q/ x: zunsigned int inputLen; /* length of input block */ 6 E$ p2 Y) y7 ]: [ F
{ unsigned int i, index, partLen;
* F ?3 ]$ X1 K- l /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
+ [4 W5 C7 Z3 Y: _5 I+ M: } /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|