|
|
#include "global.h"
6 _( e+ m3 Z- C& [6 e% C#include "md5.h"
* g/ ?% c- T7 A3 @1 L5 J: V ( b* R4 k d$ f7 U6 T1 m
/* Constants for MD5Transform routine. */ . Q* d; W2 [' M& i
$ z; h1 q3 R) Y9 [
# `& \4 d& t% [6 f9 X! `
#define S11 7
# q: v, ~6 ^! M2 S( e#define S12 12
0 P# R* a+ W( t$ U6 u#define S13 17
! l+ _. Z+ v( g#define S14 22
, ] e# G/ r6 X% r#define S21 5
4 `2 z9 t2 X& ~/ i l% I#define S22 9 0 u. }1 y5 [% t) w1 ~; d2 a& W; x
#define S23 14
3 o& ? G, ~6 T6 i+ f0 [" F: f#define S24 20
5 l" v) V6 g p#define S31 4 % V+ ^/ S4 }5 o5 m) O! p
#define S32 11 9 e% J ~9 q( z! M ~4 F* q1 R
#define S33 16 0 V+ y- z1 W/ v/ E5 v
#define S34 23
1 B. Z0 ?$ `- q9 O#define S41 6 : x7 ~ i5 M9 o5 J0 N
#define S42 10 . G" ?: @8 Q. Q
#define S43 15
2 ~; c4 t/ R' P/ w/ N#define S44 21 % K: |. K! w( v
: m% B- V# {1 ^! V8 `; ^
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); ( r; k$ }0 F* c$ p3 f8 l
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
q: \: e: p4 q. {/ Y- ^static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
* F- |" `0 a1 w. T: Nstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
3 |' ~: P5 W6 Rstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); $ L" g3 [4 J' i) E- I! {' B( p
- }! C/ U# y" }; g3 T3 G
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
6 }& D4 ~: p3 _8 i) K& [4 ]9 g1 W};
. B6 {4 \* A* G/ g
' E8 c) U S+ r Y# A [4 q/* F, G, H and I are basic MD5 functions. */ y3 d9 z# V) Y! x
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) " y+ t' w9 @) Q1 P. B. K D- {3 n4 B
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 7 L5 W0 q3 C3 G3 H
#define H(x, y, z) ((x) ^ (y) ^ (z)) 8 e4 G6 w" C& }& w6 f* d* D
#define I(x, y, z) ((y) ^ ((x) | (~z))) F9 A0 b5 |0 S+ _/ o5 g
( D ]# p# Z. }( D8 S$ g/* ROTATE_LEFT rotates x left n bits. */ # C# l/ q, p( g. \
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
- k5 l- y; @% J% S/ `# h1 l
1 g9 B$ T' O: X4 u/ h6 y/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ( q- |; }% O; z5 M* D8 w
Rotation is separate from addition to prevent recomputation. */ , O8 ^4 t/ `0 U
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% v& G/ C3 A% x) E#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } % K" ?6 g, Z+ F; J" 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); \ } 7 G; U6 Y" |3 u+ V4 I
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } # K2 r* H: R5 I6 W- c5 g
8 |8 z# I" {7 x5 [8 L
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
& ^( C; Y/ z/ B! Z" tvoid MD5Init (context)
T: v4 v" i) ^: FMD5_CTX *context; /* context */ - a. y* L% u' \7 e [
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
0 N/ l( J% t& f+ _*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; $ ^/ h6 G# z! f4 \) n: B1 {7 L
}
# c" h i" p6 s) v
0 k* _) V3 G, T- r/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
1 j$ @. N" F2 G& a: M$ Svoid MD5Update (context, input, inputLen)
& o3 m& B5 @/ N MMD5_CTX *context; /* context */
( ?9 E# [% w6 s ounsigned char *input; /* input block */ + a4 D( U# P- O& Y) f* p# |
unsigned int inputLen; /* length of input block */
2 @3 [3 z+ l4 C{ unsigned int i, index, partLen; " z- `7 E) x5 ]* S% D0 }; Z c1 Z4 Q
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ; K5 b: I( U. [+ b: v- V1 i& V
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|