|
|
#include "global.h" % @8 d' R, i) I d4 P d2 f
#include "md5.h"
4 _4 f3 T! u/ ^# o" n c
c# K: y C4 U; T) p' r' |% i/* Constants for MD5Transform routine. */ 7 {" x( M4 {& J1 n
( F% @: e% P/ K+ {3 K
5 `3 P+ j+ x" q; D2 I+ n#define S11 7 6 F) {" D o) N. _* K
#define S12 12
+ I, z& B- g& t2 K3 c: I6 H#define S13 17
6 `6 t5 l( y% h# S9 w9 V#define S14 22 % V( D/ P3 R* r
#define S21 5 3 k" v8 G* e, X! A
#define S22 9
; ~' Z I$ Q" X) z) ~" L& S#define S23 14
7 a- U J; p, j9 C#define S24 20 ; ~0 P- M. J; ?$ H5 F
#define S31 4 6 R$ h. v; M/ O) e+ p: z' X# i; T4 Z
#define S32 11
/ m- J: o* \1 B, n#define S33 16 $ ~5 E. e$ h! Q4 Z
#define S34 23 ! _& d* `) d" w' m q
#define S41 6 0 s2 M9 v+ P$ n
#define S42 10
7 E2 R, ~5 q1 ^5 a#define S43 15
$ A9 z$ S) v, ?) ?* c' w3 j J#define S44 21
: Z! _. r2 |; y" B+ r/ d , ?' ]* h6 A" n$ ?; p
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
$ l5 K4 B/ ~ v! ?- t9 {8 @static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 9 A# ^/ B; u" w) W0 `! H$ K# z
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
0 e* S1 A" M( z2 o) ]. C0 j8 ?static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); / S2 Q' y4 E9 Y' K+ X0 T# k
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ! r& a9 { o2 t# ~, }
& E' M+ }& E0 S/ Z/ c/ p
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
9 V9 p/ I+ r! R9 N8 t# _6 t}; 2 T+ B$ }7 m6 M
g: ~. @" v; p- i# d' K- l% b$ r- D
/* F, G, H and I are basic MD5 functions. */ ) i9 a8 D( @. x, `
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ; W# s8 c% h& p7 _ F- @& K: J
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) ( } e* @3 X$ Y# d2 n) c
#define H(x, y, z) ((x) ^ (y) ^ (z))
. i- o* l* l1 S8 r8 t- J#define I(x, y, z) ((y) ^ ((x) | (~z)))
% U* A% f: `5 H - X7 Y d- l* {! |; @% r: r9 g3 P
/* ROTATE_LEFT rotates x left n bits. */ 0 m9 W1 v5 X3 V7 R$ @/ q0 ?
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
* h5 S; A4 t: T
* e; R* [0 R, p$ Z; i/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ; G2 S7 i- }6 P+ _2 m& Q
Rotation is separate from addition to prevent recomputation. */
0 L' q5 V4 C3 U* ^! e5 s3 V3 L( I#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
! f q L3 i; {#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 3 v) q/ A0 q: T1 z# \ 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); \ } , @* U9 `. S, m" e, h% S
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
0 X6 x% L4 R3 [ y: r# V5 I 2 ~! H: c. N3 q0 h4 z/ } n
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ * p' P& J! N- v& y Y. D) q/ q
void MD5Init (context) V4 A' N7 |6 Q; h+ X o: J* l
MD5_CTX *context; /* context */
7 H, L' P* d) t{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ) U% o: Q1 W; y0 T
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
* X1 h1 i+ v" }}
& B9 _; c& F' U; l, T) n! _* m) [ 5 d( W, k `3 E0 S9 U
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
E& D% k& \4 J' m" U# U) ]void MD5Update (context, input, inputLen)
, Q: ^' r: d# E; ~- v; [% |MD5_CTX *context; /* context */
0 d' C9 Y; W" q/ I. o8 h/ T2 munsigned char *input; /* input block */
& Q M! V9 [4 h; hunsigned int inputLen; /* length of input block */ & J0 z- Q0 l; P( L; J4 r& X$ F
{ unsigned int i, index, partLen;
& L% }5 {2 m* `/ S" p: F" P8 N /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
9 O/ x& i. t& D2 d1 V- m; o9 H; h- u /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|