|
|
#include "global.h"
5 z; \. I+ c" V" ^- [#include "md5.h"
' X; O3 `% o+ `2 O1 Z! R 7 N* k' t, o: w/ i
/* Constants for MD5Transform routine. */ . h2 e! {. L! G, ~. ~
4 q' q" B8 ~ _; h/ f
' g, m; v/ u' j( F" h3 f6 f#define S11 7
]. q! F* i8 u, e#define S12 12 - C$ w2 C/ u* v4 ~
#define S13 17
7 z0 w F: s0 c! A/ ?#define S14 22 ) }7 ~2 k+ i0 [. z3 l- u
#define S21 5
! _" r, D' b& _. y. n( e# {. `#define S22 9 , G7 I6 R3 D- \1 ? j) r& S
#define S23 14 - ] [/ b$ B: i" i: |5 w) ^
#define S24 20 7 z2 Q8 h! e3 `4 k! m( u
#define S31 4
" g$ \6 a0 ?+ @: y: t# {#define S32 11
1 G7 L1 c" a" m! f8 j#define S33 16
& v# [+ L0 V, D3 S#define S34 23 ( u/ C# K- H0 r8 V& t
#define S41 6
: \# c. h4 `' R0 {2 _#define S42 10
/ }2 {. v- T9 i) P+ u9 j#define S43 15
# z/ M8 j! q3 L- d, U. I#define S44 21
8 L; Y9 u! s- q- T( U) C 9 z6 K+ Y# r; t: }' X
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
0 z$ E4 R/ ]7 A1 l" s5 F2 M/ Q) [& zstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
& t# z1 R2 j, |- Wstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
& ^5 v7 A9 O5 x# L9 P/ Rstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 3 ?8 O: b! {/ A- J. i. R
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
, ^& g0 Z k( v$ l) Z3 Y : }0 V! f4 [& K: n/ L" n; `$ ]/ I2 ^
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 # u8 [2 i# K V- s: b- H
}; 9 O' z* r/ B7 t( h
- O! L/ |5 b5 ]/ v& z& `# V6 o/* F, G, H and I are basic MD5 functions. */
" {% k: B- ^9 y! k' w( f7 |#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) / x3 q; E4 I) X) F$ x
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 2 T+ C8 x" p$ i& _, \$ n
#define H(x, y, z) ((x) ^ (y) ^ (z)) ; V" A/ H$ ~1 I+ G% ?. w
#define I(x, y, z) ((y) ^ ((x) | (~z))) - k# x5 u0 [, W/ U! F8 S
3 n& j2 N/ l/ C3 C# A/* ROTATE_LEFT rotates x left n bits. */
+ S% C1 h! M) g0 e! N* {0 _, F#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
p' }/ {; }; R' y 3 D* X5 E' h$ i/ d
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
) G; t" [6 s2 B# bRotation is separate from addition to prevent recomputation. */
* {" N# }) ]: ?; h# J4 c#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ p! m% `$ b9 B. C#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
6 F- |+ M y# j. K#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ Q! ^' \# Z7 m: p4 k! X7 u' 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); \ } : _, {# k p8 x5 P4 T$ O
5 J* Z; W2 D$ O/* MD5 initialization. Begins an MD5 operation, writing a new context. */
4 h% N2 y5 V7 V) E) F: I9 dvoid MD5Init (context) ' R/ T* B' |8 C* g3 e* ~
MD5_CTX *context; /* context */ 7 D- H8 g+ [4 m
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
, N6 O! _: {5 r2 ~! x& B: X7 ~*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 5 l% E) K9 f/ x
} # k! U. f1 H9 \# d& F# b
$ }& N8 s# J' Z/ T2 @) z/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
4 H& @& ]. o8 C! _$ Svoid MD5Update (context, input, inputLen) " I+ s; }8 [/ O6 V
MD5_CTX *context; /* context */
0 d2 I. H' h1 a1 K+ L0 F/ ?unsigned char *input; /* input block */ 8 a4 p% _" T) L' [
unsigned int inputLen; /* length of input block */ ' v4 \5 m& ~3 P+ B
{ unsigned int i, index, partLen;
n# b" c/ S- N, Z% b /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); . h1 \( k1 u; [) s5 p u1 x2 W
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|