|
|
#include "global.h"
4 ?, V+ g, I5 T#include "md5.h"
; z6 d- V" B1 v6 ^; | / |1 D( Q9 ?; G3 s" g5 p( a8 `
/* Constants for MD5Transform routine. */
3 h+ M; @4 A9 m" a- f
- L) R! M: S+ D( V( ?! w) Q
5 p0 P1 M4 j/ e% X7 k#define S11 7
6 ?+ j3 D( ^; J" W6 d5 b# G#define S12 12
`* s# X. t7 U( w T+ |#define S13 17 # p [- ?( a. v+ T
#define S14 22 $ `+ P) e3 J" z8 Q1 G( _1 j
#define S21 5 7 @" \' I# V8 s9 T8 L, I
#define S22 9 ( o$ p' E0 @- E- U3 x f
#define S23 14 " V: m( `6 w g Z3 H
#define S24 20
% O5 E' k' D. b5 @1 {% n#define S31 4 . s) @/ _, n! g1 i4 R
#define S32 11
" s# c3 V% L" `' n+ K6 @#define S33 16
9 U7 ~1 j- w% g3 t" B0 E) [& m( n, [#define S34 23
3 k" A6 o+ X6 v% C4 B0 S& `#define S41 6
+ j6 a: P3 X, Z8 w#define S42 10
( ~8 t7 s$ S7 V/ A% c+ U* U- r5 E#define S43 15
. z7 |& G0 k" W$ V& r6 Y: i#define S44 21 5 R7 A' V0 Z! E* R# C; j# x3 d0 d- q
3 L5 @2 d1 i) I' y& W; M) Cstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); , f4 ]8 V$ _1 A' O% i
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ; v& R" u) R/ u+ b2 M1 [9 K7 Q% h2 r5 J
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); & D4 ?5 n7 [2 k$ a3 Q
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); " v5 E5 q/ o+ ~9 o' |* M
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ; A# q" l: B: ]1 _4 a: {
3 g9 v# m- d6 e
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
. V @2 w$ X6 {* c- \- f};
7 y. W4 T) [3 z& F) @% O 2 k5 r6 S+ _) |; h
/* F, G, H and I are basic MD5 functions. */
4 n: O% j1 x4 R. p7 G& B#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
, l$ k# C5 K6 d& j8 M8 Q+ g: d. K#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
3 D5 j$ T# r( H2 p/ Q9 K, G#define H(x, y, z) ((x) ^ (y) ^ (z)) # `% k; d3 [6 A. H* T
#define I(x, y, z) ((y) ^ ((x) | (~z)))
7 Y% \# Z+ L. h0 S2 u
: Q# }4 a0 i: v6 ]/* ROTATE_LEFT rotates x left n bits. */
2 }% F" I$ v4 B0 t j, N% z#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 3 S& n7 R* w9 N4 E
' `4 Q. N1 g) D9 |, l& u
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 6 y( P$ p( r+ D& G& u
Rotation is separate from addition to prevent recomputation. */
3 }8 C- C# j/ W#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% z6 a8 [$ ?* U& U#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& H( A: n8 ~3 n( ~/ ]8 M#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } & G* } ~6 v- Q3 C/ g! r/ n# 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); \ }
* }- _$ `5 J. k4 ?# c, d3 `8 [
8 p& V7 A: i; p3 j/* MD5 initialization. Begins an MD5 operation, writing a new context. */
" n% Z! o5 e; Z" w! Dvoid MD5Init (context)
1 @. y Y9 H% k ?8 f3 o( NMD5_CTX *context; /* context */ * D. W! ^' P) m7 x( \
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
9 z# H; Y$ l: w" E*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; $ o- q* J! ?+ W0 y
} 8 F& G8 g; R: u* j9 r3 r; }
9 {) `7 N8 T3 ]# N9 s
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ , L" M- d( l, e* F5 B* s* i* g$ H
void MD5Update (context, input, inputLen)
8 _0 _. u& W2 }4 ?* q1 n+ l5 CMD5_CTX *context; /* context */
- v. z6 N" y8 f- d8 O" T7 @unsigned char *input; /* input block */
% a) u2 S3 S0 x: n1 Cunsigned int inputLen; /* length of input block */
j- U" X! E& r' ~2 P{ unsigned int i, index, partLen;
3 ?: {0 K+ ~ P5 t; v /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
6 x$ [; L- f9 p. k& ~5 `" ?$ O /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|