|
|
#include "global.h"
# q' N% d/ O+ U2 e7 q) D8 c#include "md5.h" . v# B8 Q3 ^3 U) ~: v
3 M b, U, i& {7 b% I/* Constants for MD5Transform routine. */
- A7 N+ Z0 l9 \1 D5 t0 P# w0 T+ N
& ?, ` m3 `9 ?7 O- ? ' Q% k8 v' \ v9 ?( q* }8 G. c j
#define S11 7
& r' f! g% Z7 m' r( \#define S12 12 ) J: V/ e( x5 H- _7 N# h
#define S13 17 8 m9 { H) g( c- k- v* m
#define S14 22 1 M: v- _. t; z* Y3 A0 p' D
#define S21 5 $ {+ j0 b. m3 G3 k& w- k5 u+ U
#define S22 9 6 y4 U% k- D( B. ^3 {, |1 C! w
#define S23 14 1 t* o# w2 i+ k% {1 ?
#define S24 20 % g7 H4 c- B, b1 m
#define S31 4 ; k& S) k1 T9 Y! |* p
#define S32 11 8 B8 q, g# g! ~1 G' q- B
#define S33 16 4 {7 j! V O& Z6 d+ @
#define S34 23 ( A. q u* \7 c& @8 X9 O1 w2 Y
#define S41 6
- _: e+ I5 ~( |#define S42 10 9 j6 `6 D- @) ]/ V: U4 v% u2 E% R5 ^# w
#define S43 15
' f. G/ {) c$ e# ]8 q#define S44 21
5 F+ y) u4 V# i" j0 e$ [' s0 I * E9 |; J0 q# c" X$ r/ ?/ C& i; X
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
1 P5 n+ x" I; g% l+ |static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
' u/ P, r4 O/ R6 @static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ! |- T" T! [: v/ }- |
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
* }2 ] @$ k, v7 k5 V3 B# Bstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); - h7 B1 Q) u3 V; [4 R
1 ^9 Y; j$ P/ ]' O2 M% s+ {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
* F G& j" m. W}; ; @4 p+ L0 {% a9 ~9 `! y, t
+ e; b/ g* K1 B0 W2 E6 S
/* F, G, H and I are basic MD5 functions. */
5 f. f% v! c3 W" n' D' S#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 9 i3 {5 t/ \0 l1 F1 a
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
1 E8 D3 c) d& Q, g, [) Q#define H(x, y, z) ((x) ^ (y) ^ (z))
6 n W; C; o! i% m' k, {" {, ~! \#define I(x, y, z) ((y) ^ ((x) | (~z))) : W) s# i6 _, x) O" T" E4 z
& h6 e1 q r* C; _ P( i8 y
/* ROTATE_LEFT rotates x left n bits. */ 5 e5 p6 y# V( o% G& D; K# F/ O
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
1 M9 e8 T3 B ]4 v, N. { k 1 u; J9 L: D7 c
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. * n2 r1 k) p- b. U* n' ?# v
Rotation is separate from addition to prevent recomputation. */
5 d) @; Y, S7 @% M#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" h% T0 O9 K4 Q9 z#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 7 j x+ x, I8 H' o
#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) Z( D( [ J. b# o" u& K#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
# P2 u0 j, n' o! j' ^" O9 h5 ]) D
9 D2 V7 G% R1 g/ ~/* MD5 initialization. Begins an MD5 operation, writing a new context. */
2 [$ d1 u6 m0 ?% n4 R- b. m* Uvoid MD5Init (context) " e i) e- m P6 e& h5 ^+ I* p
MD5_CTX *context; /* context */ 6 j b0 A$ _% R$ k1 i* u P
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ) |$ R5 U" A# |( q9 j9 Z; J
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
3 V- m% C# v$ s% X1 w}
, ]% L# B- ^$ c8 f* r/ a7 `$ [& d 1 Z( ]: z% {1 Q$ A5 r* L
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
( n, |; y- _/ c9 Pvoid MD5Update (context, input, inputLen)
: z( F4 D3 k2 _% YMD5_CTX *context; /* context */ . x! L. \5 w0 n- i! F" Y& z
unsigned char *input; /* input block */ 1 U7 X( R7 Z2 }( g
unsigned int inputLen; /* length of input block */ 9 I% ^1 Q1 N2 l
{ unsigned int i, index, partLen; _0 t! m- x7 c3 y- r/ g! B
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
; z8 V2 o8 w/ T. p* O: z2 a) _( C /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|