|
|
#include "global.h"
( z) J9 D: C' N, _0 b$ ]#include "md5.h" ! p( t' s& B" b
7 I) @5 I: t& ]. n4 i: W& F
/* Constants for MD5Transform routine. */ 6 S0 U) g7 s/ L4 J
, z: ~& X8 y# V. [2 E3 A
/ d2 H! k# @6 h; V#define S11 7 , s! t6 w" v9 A
#define S12 12 # J& J. ^0 y7 G- C' z
#define S13 17
0 y8 Z* v, X) {#define S14 22
! r! W5 p- u, S- t* q6 e#define S21 5 / f2 C! o6 h" A- _( B {
#define S22 9 $ G& h9 \7 a0 b" y& `
#define S23 14 ; \/ E! o% y1 q+ m% p' Q
#define S24 20
0 j. p0 M8 J( G8 D. P( P% O#define S31 4 ) p8 q+ d, t" y% I6 S6 ~' ^+ o
#define S32 11
5 k& D, m) L* T& l#define S33 16 5 L1 q5 w1 I- E. S' d8 P
#define S34 23
B" F) ~$ H+ T" C! y#define S41 6
& Y- U; q7 w3 ~ _/ u$ y# d#define S42 10 & J' o% h, u0 \! D
#define S43 15
- |& J% I1 S4 i. b6 k7 m6 ]5 m1 C#define S44 21 / ~6 H, H' }. t. \7 g# M
/ I6 }; l8 w+ |' i& N6 H
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
, {; C; q; T: o' D; p7 M/ n/ H9 dstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
) E- J3 m+ F+ h3 V2 B6 F1 n/ H; Estatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
* P3 s8 |0 g6 U9 ^) J) {# [: Y7 Pstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); |+ x. f3 ]& M" I2 M
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); . @- p/ ?6 L8 D) Z- d
& u; i! v8 C4 Y) b2 Y; }
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 ( N0 l: K4 U: f* ~) G' Z
}; + p/ x( R. c. c) d$ q
- i( H' I/ Y; C, @7 D/ E/* F, G, H and I are basic MD5 functions. */ & \% b) `. d, K+ r/ a
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 4 \' E( g, Z O' S6 ?( d* V$ H: }. \+ a
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) m6 T7 Y' S* G; v8 [' l
#define H(x, y, z) ((x) ^ (y) ^ (z)) " W7 y; i U% W6 r
#define I(x, y, z) ((y) ^ ((x) | (~z)))
5 l4 o5 J4 T' o( g$ b3 j3 r' e) J: E
# ]7 T; _" S$ e) Q( e& I6 ~/* ROTATE_LEFT rotates x left n bits. */
/ ]. h" a% y L9 a' F( [+ F1 q* l#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) . `9 {& @ I) Z
" U8 z# |3 g( O( v- V% \% n# |: C0 l
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. : D$ _! d6 V9 c6 g0 i, F" Y: Q
Rotation is separate from addition to prevent recomputation. */
8 l0 c- ^$ r! P9 v#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ |2 v# y/ ]$ r+ p& k) B#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 D u% U4 ^6 p! Z {* ?$ A
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } * y! m9 C( O0 l6 ]" ]
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } & L- R5 G) _& f) q% D) I
% ?: m) j9 C3 q2 Z* G/* MD5 initialization. Begins an MD5 operation, writing a new context. */
z0 e+ q. r; _7 E. Vvoid MD5Init (context)
* P5 G* h8 X5 R. S3 Z, n" \$ `% [MD5_CTX *context; /* context */
7 z1 Z, L% S$ z& l; ~5 m9 k2 z{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. * @) G( l0 S9 A
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
: M9 ~+ e7 @$ `' S T. y} ' X- b9 L$ Y7 ^4 N- b0 q
" L! R1 Y' h1 b3 c8 l5 X
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 6 K4 V( H5 h$ d k5 J3 ?. Y" _, O
void MD5Update (context, input, inputLen)
, Q; y' U3 N. D& ?MD5_CTX *context; /* context */ % ~/ g3 |0 I( f# h/ U: u
unsigned char *input; /* input block */ " ?- z! I6 o" \" o( J9 p' f- N
unsigned int inputLen; /* length of input block */ & A6 s' e8 E3 K+ q) t
{ unsigned int i, index, partLen;
/ O: ?: T- Z) q7 r/ [ /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 8 U4 Q" ^9 ~$ A
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|