|
|
#include "global.h"
4 D3 q2 x8 V' Y% C#include "md5.h"
( O$ E- A7 u9 @& w8 L n+ j3 @6 I5 h% j1 f* l0 [
/* Constants for MD5Transform routine. */
2 W# V$ ]1 j5 H8 p+ Q9 b q$ ] + i+ |( B8 m7 d) e
- g) N- W% a# x' K \2 Y#define S11 7 $ q, }5 V* v6 b" y* a! K* [
#define S12 12
. m# G4 L" f: I7 O& w2 x2 H#define S13 17 $ J# v% M" g9 @% c0 h1 R& x
#define S14 22
! Q$ l% T$ G) z( Y2 F F5 X% ~* U#define S21 5 ; Y! S- q: c y" G( u3 H3 {6 S
#define S22 9
5 C: s1 ^1 w! e0 r( Q( {- `$ p/ e0 W#define S23 14 7 ~: L: \9 u4 W. B
#define S24 20 % l3 q, f+ d" Z; x" Q! t
#define S31 4 ( u) _3 k+ q! u6 w
#define S32 11
8 P' ~: y! s1 y1 M, E#define S33 16
; [5 b3 R5 x& A+ D8 ^3 y2 |% l#define S34 23
- p1 h1 O' I! [ m/ {4 w#define S41 6
/ p* j" V# C2 X0 @. ~5 P#define S42 10
5 w* q+ v) H0 f3 t* c5 [% w+ y F3 v#define S43 15
) n% q5 ^% W" O#define S44 21
! J6 e" i& K1 a! i# P' V ' x3 R. a; v8 t& q
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); % a: ]4 }2 F, V# K2 L
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); " {" u9 h) Q! ?( R1 b! E
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
) S: h! D$ W; m' T; G+ [static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
" M( Q6 v4 s0 U" U( G. j5 ?' |static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
' P0 |0 {( n; t+ U: k, c# ^ ! J+ E! h6 X4 S& p2 s0 C
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
0 s0 Z9 ~/ W) H, [% r: P( c. c) x5 v4 p}; 4 Y! F9 C2 ^$ F* N3 C
2 S1 `$ h x7 X8 h/* F, G, H and I are basic MD5 functions. */
- V5 K# e4 ?. S S" q#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 9 D' q0 i2 v- _6 O! F* G
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 6 K4 G, z9 p- d( |1 k1 F1 i* Y
#define H(x, y, z) ((x) ^ (y) ^ (z))
" A4 F# l$ Z" {' g+ s" _#define I(x, y, z) ((y) ^ ((x) | (~z)))
$ K8 {3 A& c# j # _$ U, A; l0 b8 A: [
/* ROTATE_LEFT rotates x left n bits. */
: |6 q- P# a7 g: ^& I" j#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) , G% g& j9 {1 Q8 X+ U3 u) k
- S: o& g: N& ]
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
1 x0 b# q. }1 U. SRotation is separate from addition to prevent recomputation. */ 7 |5 U3 n$ R2 r! M1 M* Y+ j
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 e2 r9 B7 ^6 R( f: o#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
# h1 V! m8 c8 ~#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ( B! y c E$ w U" h( \- N
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } # c& X; V( N! M$ n0 q6 X/ |! w
. K f* U) m* Q8 f A5 O/* MD5 initialization. Begins an MD5 operation, writing a new context. */
$ F0 H" ?) ^4 Yvoid MD5Init (context) 6 U( f. y8 [3 c. i' X+ h7 e
MD5_CTX *context; /* context */
' S4 z; @6 M) r# `{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. : i9 O! h/ k5 t- W0 Z4 S& z* {
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 7 _+ K7 x4 t* _0 h( U
}
- I; X& k$ S7 m# M$ Y
G( K$ p, d! B9 d. n+ v/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ & [3 g0 z7 Q: D- }
void MD5Update (context, input, inputLen) 6 a+ d1 x2 a6 p9 ?* U3 O
MD5_CTX *context; /* context */ 6 D9 w# _% J+ R l
unsigned char *input; /* input block */
9 H$ N4 f, h6 G9 ]unsigned int inputLen; /* length of input block */ , O; A. I2 v) M# w. x# G
{ unsigned int i, index, partLen;
8 P2 U! f" y" {, N0 b /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
$ B9 x. ^7 `+ K5 E" F( X3 [- { /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|