|
|
#include "global.h" $ d) i$ L: z; R% X6 r" y9 z
#include "md5.h"
# K6 b6 }1 r. V7 l- U7 ] , c6 Z" m' E5 @2 D
/* Constants for MD5Transform routine. */
6 a8 y+ g C; u" q, o / o/ f# q) T( O9 a6 l
. v7 W# F4 i, j8 U6 n' [2 [: B#define S11 7
3 }. g D' b3 G! B#define S12 12 : L; N8 c( P5 i4 |
#define S13 17
9 a2 B7 L8 E# E- K5 T) B#define S14 22 ! m& I: U/ U; ~/ s; _1 S% ]
#define S21 5
' T2 c. D8 T$ T% ^. y4 k0 f4 d#define S22 9
9 i* v$ _$ m( x( ?; r#define S23 14
; i+ s; [9 y7 E3 f1 S#define S24 20 * U0 t: E* i! U$ w* F5 @
#define S31 4
% K5 n* V/ Z% e) G, y% Y7 w- L# c4 H#define S32 11
6 d' N' c' X# f9 W" }9 P% p#define S33 16
0 L0 |0 `- G! u8 Z#define S34 23 % @9 e! v! E+ x- H
#define S41 6 " l/ P3 ]4 m4 x8 V) y
#define S42 10 9 u( o3 ] l) ^! a
#define S43 15 ; M S* z7 s# ?5 U2 z3 L7 t9 e
#define S44 21
; h7 ?6 g5 X2 ^+ _4 p0 ]1 K' ]: \ + H: V* }! w, r5 q) w
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
6 I+ @, H$ \+ ?static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 1 U" k: e1 h! D# \: k. |+ I, X6 G
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
+ w2 B: Y, _7 E) w3 O2 \static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 3 { L2 H2 Y1 ~0 N( H* t9 a7 S
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
7 d% z4 C* _" @* t" \- v$ N % A* P' h4 R J5 i6 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
; r0 S" s% R! z# T) A};
+ m- l4 F2 x, j+ e: H $ t9 |( \$ r% N& p
/* F, G, H and I are basic MD5 functions. */
) i \8 Y/ g$ O' W( _1 j#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
* H) Y& g6 D- C `, v+ K+ r#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 3 P* x' {1 K: c
#define H(x, y, z) ((x) ^ (y) ^ (z)) 4 d% x# K* e; Z# F
#define I(x, y, z) ((y) ^ ((x) | (~z)))
6 ^+ }+ h+ ]* D
# x0 I. @' Y0 o8 k2 t, |/* ROTATE_LEFT rotates x left n bits. */ , m4 c( M: ]0 n- N
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
! h6 h4 m) W4 B" h
+ e' F4 J, r* m1 ~/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
8 r6 A2 s) q% w2 |Rotation is separate from addition to prevent recomputation. */
) P! ?8 U. G( _+ W+ X. S$ G#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } & U9 \( p8 @ n9 V9 o1 J
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 9 C: o7 o/ Q: R% b4 B) l7 A- ^* j
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } " Z- F. s/ Q* P/ {$ H0 x$ e6 }
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
6 n# }3 T4 o. {& [- q
/ _/ C) y+ `7 y! c/* MD5 initialization. Begins an MD5 operation, writing a new context. */
6 G8 {5 { s- F; _" T$ a/ a- ]void MD5Init (context) 2 |9 D; x+ h: k9 \
MD5_CTX *context; /* context */
; A! C( t# k: b5 B1 R{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ) ?# u M9 Y) Q; q4 ^7 |3 D
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
6 P2 G% \ r3 q, e1 z}
2 m2 ? B4 z- k+ Q+ Q/ G/ r; Y C: B6 N" h8 e6 X
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
9 \ c% @: r, ]( U8 y7 \! Ovoid MD5Update (context, input, inputLen) & v) ~! |2 [# W5 V
MD5_CTX *context; /* context */ 5 G2 F# D3 ~* L8 p. A' z
unsigned char *input; /* input block */ & I7 s+ @6 h' p5 ?$ n) b$ a- W
unsigned int inputLen; /* length of input block */ X% w: C! n4 X% k' q* J# ?0 z
{ unsigned int i, index, partLen; ( A) o8 f W" C y8 s
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
2 @+ P1 t2 K4 [4 y2 I' B /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|