|
#include "global.h" ' t- Q) v5 p5 T3 V
#include "md5.h"
0 R+ W) F) q- {2 a- } . S" e2 D$ z2 Z4 C N/ V7 `
/* Constants for MD5Transform routine. */
0 l3 F/ R/ j3 |! U" J* S& ]( }
; s: j! C' I8 h/ K, g) K 3 [, B" Z& H1 q y% G
#define S11 7
+ h$ k V* ?/ U4 d e$ C#define S12 12 5 Y8 X ]# S3 s! o5 ~
#define S13 17
: C' B/ I6 v. ], v: n#define S14 22 . ]8 _2 V& l: \/ u/ q
#define S21 5
" Y6 L6 \: x9 s2 d# B6 C#define S22 9
0 q2 _0 w5 Q8 V& V. P#define S23 14 1 ?/ i' @- \" A: ~& E
#define S24 20
* Q: e% O# U" i: a#define S31 4
/ { {) ?7 d: @9 Y. z$ P/ m: |8 p#define S32 11
& t+ Y- \7 U. I# P#define S33 16 0 @" J9 D B( D7 j7 `( r/ x
#define S34 23 {9 \7 G4 f1 |% I
#define S41 6
& R2 f4 }+ A9 P: Z& _#define S42 10 ( D2 s% M6 Y. k8 x
#define S43 15 * m& x. r+ x5 E# x: M) l
#define S44 21
$ ~7 s, @ @& ]" L) ^# @0 f 4 R% J. u8 | z% ]: C% G
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
% D5 {+ R9 _4 ~6 A# A/ Pstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); # \4 a( C# v* N7 j! [$ U
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
' C! p% i$ b% j2 A3 U% ]% Q* Ystatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); . G. \( ^' C( k
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
; N/ | v7 Q' I
" W& r$ W" Q* I! N) K5 j& M; h4 Jstatic 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 ; `. k& l1 \3 O6 g" R
};
# [ ?( y9 y0 p) ~3 B; V; H ! U( J: q/ b- }
/* F, G, H and I are basic MD5 functions. */ |% @4 S+ u, F5 \% J/ w% Z1 b. u
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ' g8 p# s) P8 |
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
7 u) I* R, H5 u' H) N#define H(x, y, z) ((x) ^ (y) ^ (z)) e3 H4 |+ b/ T0 p
#define I(x, y, z) ((y) ^ ((x) | (~z))) . t- T( a y/ V5 X; }3 t: A2 A
# i/ }) l) c# ?2 c2 W; l
/* ROTATE_LEFT rotates x left n bits. */
7 f% S% z5 v4 e5 C- Q8 H# `#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 4 U& s- \ i" y! {
6 n% g2 @9 a' f5 J7 C1 S/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
f% B" y( i s1 l6 s& Z% bRotation is separate from addition to prevent recomputation. */
) G$ q, p# A2 E) U- s9 q#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 4 z; a2 K8 }% I" V0 X% R5 r# [% [
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
: l s" [5 u Z/ `#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
9 a4 F% |; b3 w- M4 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); \ }
7 o: S9 k) n- u7 U# b
) p! Y( y1 q$ n7 v/* MD5 initialization. Begins an MD5 operation, writing a new context. */
$ w$ A$ H- ~& D9 s3 c( E3 r( @$ w: F6 Jvoid MD5Init (context)
( o9 B6 j! \+ J3 S; d' ?3 AMD5_CTX *context; /* context */ ) ?4 I, A' z! f9 p( G* m
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
" V* a8 r; d9 p8 f- W1 E*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; , q1 ?3 D9 f8 v0 X
}
. f3 d$ C5 e* X3 n0 @
5 `$ C P# ^& C: X/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
# R, V& t( w: H7 R9 |* G9 z1 p Ovoid MD5Update (context, input, inputLen)
4 V" j& x0 ?" T* f+ v) bMD5_CTX *context; /* context */
/ f1 M8 ~' k- M* m! V3 Vunsigned char *input; /* input block */ 9 p) ^: S& F) v3 Q0 {" }
unsigned int inputLen; /* length of input block */
* d) q; d2 G: X! \. Z' d( N{ unsigned int i, index, partLen;
- O3 ]- ], _3 ~6 |% t' l" J! Q /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); / K' S7 Q3 Z% M) |* [3 h
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|