|
|
#include "global.h"
! c8 M( Z- o& A#include "md5.h" , t2 J4 e# _; r
! B! o. M. ~" E) e6 r: w/ _) G/* Constants for MD5Transform routine. */ ) b0 U# \0 A/ t# \- M0 W
/ }4 K+ s$ q6 D; S+ O; E8 } 1 c; l) z; E( S. U9 I: l, o/ C
#define S11 7
# \8 o8 T+ K4 X. H" t#define S12 12 / v/ Y @. u( m0 [1 M
#define S13 17
( s9 F$ E+ L3 J" Y' m$ Y/ H#define S14 22
9 j9 R2 x) \4 ?3 X* t+ M- x#define S21 5
+ _4 K7 \7 t4 \4 I' T#define S22 9 & S- d0 h# C- h4 ]: W9 V9 h
#define S23 14
& X6 A: V8 K3 z; s$ P: O#define S24 20
3 y& [3 j Z2 D8 N3 k#define S31 4 / q% p, h, K" r6 p3 c( c4 M) y
#define S32 11 / n1 y! F q3 ~4 z: o+ y8 x0 R
#define S33 16
! e% g) J i" p; t! c4 \' L5 W0 f#define S34 23
8 i( v p0 B) w7 k. b7 P5 ?( y% Q) W" A#define S41 6 ( `$ f" S& U( r: {8 I8 }; u
#define S42 10
4 z( ?3 p$ P0 w#define S43 15 , k$ b: c4 p; f' L, C
#define S44 21 : n" z3 _. X% D6 W6 x! x
$ J1 U7 y G1 C7 z( `( E
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 1 F, A3 D% X7 G( d4 X, z
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 9 s3 `/ H+ r! ^
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ! S- c+ ~. C7 U) D9 i4 v# `
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
/ _! O( Q5 N1 U; _static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
3 ^5 \) O2 B' f7 C/ a) a* @
& Y9 C0 }; t4 s( M# a" sstatic 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
$ Q& [# S1 N$ r& _3 D};
6 F' f, E- D) G6 j! k $ v0 o( G; Z- G* `& H
/* F, G, H and I are basic MD5 functions. */ 0 a! ]4 R9 G; |5 j' u" R# V6 v' f
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) , }2 ] g: ^- d1 x6 |4 b S
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
5 r- ]; _, P6 W' j#define H(x, y, z) ((x) ^ (y) ^ (z))
. T: t0 i* s$ H; G/ W2 M#define I(x, y, z) ((y) ^ ((x) | (~z)))
; C' p# y4 V5 X7 V( q7 r
+ L9 |1 H3 e4 q/ a. q: b/* ROTATE_LEFT rotates x left n bits. */ 7 R: b5 w$ L+ Z
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) & w/ [* s! r5 D2 a
' j# \- e/ P) ^0 M0 D* o
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
9 w. B* S9 N4 m L6 t% u, T0 l( QRotation is separate from addition to prevent recomputation. */ 4 p1 M9 @" T+ ~. c6 p
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 9 U5 T- R! m. W0 D1 ?$ 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); \ }
* Q, m: z( J- o% j' v#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
4 I6 W) \0 O7 t" N0 B#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ) m: |% m& v9 s) e
5 Q2 v! {# ~! M: m
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 4 w; C8 x( b/ ?: f6 \- u
void MD5Init (context)
" Y7 }, v9 i& B1 eMD5_CTX *context; /* context */ : [" l- W1 e) o$ r7 Q& R. d+ R3 F
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
2 E- }. V. N5 K) @9 i0 H*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
$ e) h) X3 C$ D( v+ T% n8 Q8 j} 5 }& x, e% j9 t4 \
- v2 L* q9 {: e& }/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
1 A3 B6 `% ]/ Ovoid MD5Update (context, input, inputLen)
* E- B* Q8 k1 u2 q* T$ V' mMD5_CTX *context; /* context */
4 r$ g, V: F7 D, {unsigned char *input; /* input block */
9 O* q2 ?3 e8 \+ W# X. m9 C; s; Hunsigned int inputLen; /* length of input block */ 8 Q& R6 x! n! A0 w7 j/ ?
{ unsigned int i, index, partLen;
4 s2 j8 `* W% N& a$ W' V /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 2 ?0 q2 T0 P) B3 J5 y# g% C* L* c
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|