|
|
#include "global.h" 4 L+ A4 v8 j4 S7 L% Y
#include "md5.h"
- d7 i% q+ z5 c" u, S$ y% |
% K* g3 C- v D9 |" m/* Constants for MD5Transform routine. */
7 C/ C/ E3 X0 J. r% ]- y . D2 d& `/ T$ b, t& D, E. ?
- k- N+ }2 G0 H1 b0 {#define S11 7 # x! \2 P, g4 m
#define S12 12
6 p6 q2 l* H& j2 X- [: I1 e#define S13 17 . f5 t/ H# f' p L8 ]/ n
#define S14 22
8 J: _1 v$ _8 O e#define S21 5 - Z5 v. I$ z+ Q- S& F
#define S22 9 - I& H; E. p8 x! b' ~8 g3 w
#define S23 14 ; {/ j, w5 u2 ?' `& [& P* D5 }
#define S24 20
- Y5 {9 _, H4 c* t8 @( n2 A#define S31 4 3 D# O/ ^8 I0 P: u7 z
#define S32 11
0 w' e; n$ a$ U2 v! O#define S33 16
9 }- m% ?3 r2 A' K& f9 H$ P#define S34 23
6 J9 M1 w, N! n5 \#define S41 6
& l( Y7 C0 ?2 @. Z6 N/ G1 t( g. ]- X- A8 u#define S42 10
" |# p6 I) C7 k#define S43 15
/ B" X2 W/ H9 c' E#define S44 21
: s% _; @; |( p) h6 {0 A7 l , K+ H$ m, e2 o. l. O' h3 `% V& P
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
3 i6 R- J Q9 n3 x T: Xstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 6 j! l5 o+ S0 o
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); + Y4 g. s4 b+ R3 V& w" f5 Z7 O
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
3 _' F" X( s8 Jstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); % z5 g4 M, ` E4 \3 y. o+ U
2 A* w* E3 g n1 ~3 B6 Dstatic 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 : W: {) n0 ?! F9 A. V! j5 G2 \: ~
}; + U9 `) V- |+ _% S9 b
( D- g0 N7 B3 @5 p6 p/* F, G, H and I are basic MD5 functions. */ * P3 z6 Y% Q% @4 O
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
# |$ o) A4 Y h9 @% y- `& A#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
. @7 o2 O7 }- [+ {#define H(x, y, z) ((x) ^ (y) ^ (z))
& b9 N) B. W6 { z7 I! @/ Q! w#define I(x, y, z) ((y) ^ ((x) | (~z)))
% A$ @0 f* U) S. `- v/ R; [ / T( ~ A4 \3 ] x
/* ROTATE_LEFT rotates x left n bits. */
/ s4 _* n3 [/ n/ c#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) . \% @4 E8 J ^$ t9 ^8 e# U+ F7 J
( u$ i/ I: Z! l5 _* t
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 8 M- Z5 u2 f; _. s
Rotation is separate from addition to prevent recomputation. */
" b# Z3 w6 P+ |# j: {7 ~& n' N3 X#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
u& I2 U3 |0 F#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
# d; |; w% J$ B#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
/ k2 M R e9 F#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 r8 o, \/ O' k! V t
4 y% _5 Z: q2 ]' R/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 5 s/ W4 d5 z! q
void MD5Init (context) 9 O. C( s( K/ D3 R5 X" r1 ^ }+ k4 P% M
MD5_CTX *context; /* context */ , _1 F! Z+ b% ^' s
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 0 w# \( p8 a9 m( n' ]- _' _
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 2 t5 G8 F8 @0 a9 v# r$ ~6 e6 v% R
}
, l9 X( }- j! A' L* Q* U6 I* d3 T1 }
3 ]2 J8 U4 h* @- k/ Z* s3 [- h/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
7 Y5 f- _$ S- H" P/ kvoid MD5Update (context, input, inputLen) , j7 |* m- u8 c/ A4 j. X# e) V# q
MD5_CTX *context; /* context */ 2 O8 m7 D& M0 ?
unsigned char *input; /* input block */
) G3 x& D5 _5 m/ G/ Cunsigned int inputLen; /* length of input block */
, i+ P* p. N1 a# Z* K+ [/ {$ Y{ unsigned int i, index, partLen;
* R2 g. H; ]7 i6 ? /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
$ J* d8 ^. C! b /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|