|
|
#include "global.h"
_' u8 y% q9 j% s0 J |#include "md5.h" : V6 q4 z* m* d: G
9 J. a0 x6 e/ S3 i$ E6 R& H/* Constants for MD5Transform routine. */ 9 E0 G' [' j7 G; A% O; m
- G$ Y) ^: L. y* ^. i( |+ K% l& {
: r: \! T+ D* G# G. L#define S11 7
5 r2 x( q% d5 p#define S12 12
* x) ?$ j8 c) H$ i#define S13 17 / }9 f; P% k2 b9 f/ D% [
#define S14 22
5 M, y, L; H1 c#define S21 5 6 n( R6 E0 J6 `; \$ z2 T( J
#define S22 9
& N4 L2 ?! Y/ b; q#define S23 14
- q! J i3 X) B( S) `#define S24 20 % b; `/ _$ G* Y0 \9 [6 g9 b
#define S31 4
. R. u8 D" B' K/ S( V! x#define S32 11
% Z2 J! [ u$ J: E#define S33 16
3 K2 r/ @5 P o3 d; g) {#define S34 23 ! f9 t1 N0 \' B
#define S41 6 ; G( T \$ o9 f! k3 A5 I# M U
#define S42 10
/ Y' T! U: e+ H# b) a, E& u9 w' K( @#define S43 15 2 `1 V( ]9 h6 _2 a
#define S44 21 ! ]" s! B, r! D7 C
3 G } I% h0 g0 q
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
) Z$ s% r7 @7 X5 {& S9 {2 O" t5 [! Ystatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
& W' q3 t6 T6 B: Ustatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 6 C' i6 e# Y Z! a& X6 x& A
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); : }8 C2 O, V9 E( ^- O7 G
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 6 b C7 X7 @- r8 D
0 L' Q* e$ O* @% @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
; n5 Q! X( \: B+ ?3 o, ~}; 9 o3 @* C: M P# M! t
- U/ ]2 \- B! p9 I. _& a/* F, G, H and I are basic MD5 functions. */
. h+ r* v. B: `) O' p) d( p; Y#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
, ~8 |9 T% G8 m; [, L#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) ) ?- T0 A# H; z
#define H(x, y, z) ((x) ^ (y) ^ (z)) : ~$ P. J, A4 J2 \
#define I(x, y, z) ((y) ^ ((x) | (~z))) 8 W. P3 _; b+ {$ S7 l( u# n
0 _ \8 H6 k* \& x, T
/* ROTATE_LEFT rotates x left n bits. */ $ S/ s* J; R* F4 O; A% F
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
% z1 s' C, @: B* P6 p
6 S& D6 N6 y- i: }. ~$ @3 `/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
- D* O# o2 m! ]$ |' P- n' x! ZRotation is separate from addition to prevent recomputation. */
5 w7 z. _% X6 b! n. n6 _#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ' K: ?+ I0 ^4 T8 r0 l
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 u6 r0 s* k. A1 |0 f3 ]#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 o$ i9 U1 f. ~4 c" O, J#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ Z6 ?# `) [# \; o) F" n / o: t) @( ]) G9 r+ `
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
( J& f" d7 K* q, \void MD5Init (context)
9 K7 E6 \: S$ y; X# Y1 MMD5_CTX *context; /* context */
- Y# P; z. ]9 A( y/ X{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
5 C% V4 J w, R2 s9 a*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; " L! ^9 h/ f: @* w9 A y, ?& u
}
' S' c- L3 p& t. k
7 j W7 k9 ?) l: b5 f$ W/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ ' K( k: E# \7 y* f9 `# z+ F
void MD5Update (context, input, inputLen)
8 @0 c( g8 g, G1 t+ nMD5_CTX *context; /* context */ ; d0 }! g( n! ?1 a7 m
unsigned char *input; /* input block */ 8 b' m( X% M, L. G! M8 C
unsigned int inputLen; /* length of input block */
( p1 @2 d$ S! A5 B{ unsigned int i, index, partLen; # ~2 @4 D2 @1 v" O' P/ Q5 H- P, O& A
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
9 V( W) u1 U* `4 }% x3 T /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|