|
|
#include "global.h"
0 E# a, L. D2 p2 s8 c3 u8 r#include "md5.h"
) m; c. o; a$ Q& s & b- x+ _9 z: V2 d6 F G
/* Constants for MD5Transform routine. */ ' n3 C, d8 C* Z M
8 o! C3 l, p) M1 A+ H) S: ]2 G
8 Z s+ f5 j2 S2 h; [. {' ^#define S11 7
( ^2 K1 {8 {# K1 G: s- v4 A4 c+ R#define S12 12
% ^ N, I8 y0 j: j; Y+ \9 c#define S13 17
% L0 v* o; w; o/ y9 s, Z#define S14 22
8 e4 V* D# _: R4 R0 p4 P5 c3 y#define S21 5 & g, V {7 E. }0 P y2 u2 A
#define S22 9
. x; x( t' o% y/ g. }" H& w: F#define S23 14
; {+ C+ n* E6 Y* N#define S24 20 8 n% p. Y/ q0 a4 x8 ~
#define S31 4 7 T6 M- d3 O Y1 Q6 B* g4 U
#define S32 11 " {9 f1 A w+ _. N# M: z |3 L
#define S33 16 7 O& B! ^$ w: g" m' c U6 \4 o
#define S34 23
0 U' `1 k! e3 x% A#define S41 6 7 o; \" r, J$ p! y( H' P
#define S42 10
4 i5 }) N! c* \#define S43 15 $ O1 a) v" H# k8 A, B6 T* {0 B' S
#define S44 21
R" u; v9 w! a$ V+ B% ~ A- U& |+ ] Y) t$ ?/ @3 {, y/ c
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
3 d# x* F: V0 L" b0 B: Istatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
# |; Q3 K: t* k. O: b6 ^static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
: H5 t! a# d9 L2 I+ Wstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
0 N5 j b8 Q- N" gstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
% \. |# A2 t* J ! [5 i1 m2 ^9 R: b; a+ r
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 1 c( g. e6 a1 N! I6 Z, p) y7 R% L
}; ( ?" o. C( {* K1 X
$ F, B: K! X6 a' l: {! K' k
/* F, G, H and I are basic MD5 functions. */
1 w x3 X4 Z- N$ w' ?2 P#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 8 {; g% d' }2 i
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
- d% ^8 h4 G0 {8 l1 o6 N#define H(x, y, z) ((x) ^ (y) ^ (z)) 8 T8 D/ [: ]. F# j' ~$ w
#define I(x, y, z) ((y) ^ ((x) | (~z))) ) @7 G8 V5 p4 Q+ G: P
$ X9 s& S; w: N, r/* ROTATE_LEFT rotates x left n bits. */ o8 j+ D3 h9 Z* t7 |; Y4 U
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ) o" P' {; O) V. Y' l, |" w1 q. k
. P6 e- f6 a' C) [3 ^3 c% W U/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
( M( ^0 H/ b3 L% J, [+ PRotation is separate from addition to prevent recomputation. */ 7 g6 ~* p9 v2 s$ e1 P8 B9 ]
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } : o! I- W2 }" ?. z1 s5 d$ `; w( ^
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } / I& Y& ` R" ?
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
0 X6 R- M& N2 `- |6 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); \ }
) O7 F* V3 n- w& t 6 i% `0 T: O2 j4 Z
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
$ ?& E3 Z- t( q8 w" Z. A2 Qvoid MD5Init (context)
, E9 }8 X. j: E& d7 {* iMD5_CTX *context; /* context */
, G6 @4 g9 O% l1 |5 S/ f% P) [* w{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
7 ~6 A" e+ I6 N+ y*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; D% \" z% `4 s: G
}
8 s8 z6 ^' N* p+ s8 ]" D 9 r1 a, b" {2 L* k- a
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
- X8 A; G% ]% z8 {4 p0 e) \void MD5Update (context, input, inputLen) . m0 w$ t' v# y
MD5_CTX *context; /* context */
" w( b2 X" q- j( T+ f. D9 z* nunsigned char *input; /* input block */
% K2 w* S) B! X. J" C2 A$ Iunsigned int inputLen; /* length of input block */
r5 Z4 j5 W3 B+ U. e6 m) B{ unsigned int i, index, partLen; ; h: [; e" V' P- ?9 E
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); W4 u! T5 e K, N# q! Q
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|