|
|
#include "global.h"
! B+ {( j6 L/ w# p' b1 f#include "md5.h" $ m9 S- C9 u" K) E1 L, [1 V; Q
" o$ q% P) y" K& e: [$ G0 y/* Constants for MD5Transform routine. */
7 s* T+ |9 U: F$ {- s8 m ! \7 z, v% ~, B% ~# M2 V. |9 O
, |, n8 U& t6 |+ M t, [( o" B#define S11 7 : J, g5 `0 v& u; ]6 {# ^
#define S12 12
+ B- X* J0 M8 h- ^4 m#define S13 17 5 i& d. ]! X, w" ?( P2 |7 Q
#define S14 22
`& N$ i# [4 u7 s/ m" R4 r#define S21 5
h; t5 T& J! ^1 ?2 }#define S22 9 5 r/ l4 g3 X9 U: e6 q& }' M" D
#define S23 14
! ?- ?' u) }; N- R#define S24 20
; s; g4 t# ?; Q3 x#define S31 4 ' x: ^. ]3 m# ^4 D; z: u* G
#define S32 11 2 {1 U3 `9 [4 p9 I f7 @0 J, D8 Z
#define S33 16
0 w# p5 x0 ^. a: l- J' Z9 l#define S34 23
: y$ \9 l, c- s0 `#define S41 6 L1 d' D9 l7 z! m4 j- k& ^
#define S42 10
4 ^" A/ G4 e" I5 F0 K# K; y#define S43 15 & N9 x& ]: m# `; Y# Q4 S! J/ F" S
#define S44 21
2 C/ ^* p( G% H ! N3 ]" R! _. n; Z: u
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
1 h; T9 t: r8 g7 K2 w# jstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
. {& E6 d/ J8 V3 Wstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); * n5 E/ G7 R' i5 w7 ?; F
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); / ~# } A' s/ `8 |
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
' x* b$ [+ J# L; t/ E
) w+ v4 P" l7 K5 Kstatic 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 1 n" p8 L. z( F9 h r7 X
};
$ _* e W( F) E b" @7 m$ p \/ n% L 4 }) V) X" g3 G. n+ d3 [! N
/* F, G, H and I are basic MD5 functions. */
& }" K: M1 v" T k+ l#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
4 i P/ {1 V7 i& q6 z4 x#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
; A1 p7 F* k/ ]. `! N#define H(x, y, z) ((x) ^ (y) ^ (z)) , y% i5 f2 `+ U& |- y
#define I(x, y, z) ((y) ^ ((x) | (~z)))
( c7 G/ \! C3 ^3 l3 D
8 W, ?6 j8 a! n! r/* ROTATE_LEFT rotates x left n bits. */
' e j3 l+ M3 R) d& c#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 2 |) m3 L ~6 ?4 Z m3 b: R! {
- p) a8 t7 ]! S s8 X/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 3 N7 L+ X. r& y" [+ O; p# a, d
Rotation is separate from addition to prevent recomputation. */ & z! o3 ~" }( ]3 u: }- V0 E" A7 _
#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 s! S5 c+ e" J' B1 ^ J+ ?#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ) N- A3 F" E' i- K5 l
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } # z- |+ j! x; S( P8 z% Y
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 2 V5 s9 m2 H4 [% l; ?/ f
* ^2 y: F( s( @
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 9 \% g) N1 E1 z3 s( j
void MD5Init (context) / h+ y% b6 N, Q* w
MD5_CTX *context; /* context */
: v1 T2 _0 ?8 C2 j0 G{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
5 z! ^9 O/ o0 C9 s$ U$ u; H*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 2 T( s/ N% Z$ N
} % {1 U. A0 C5 ]7 E V. ]1 D
x9 E. X) l+ U; {5 r7 c1 e
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ F1 F4 x# R: X! Y- }0 F+ N6 C
void MD5Update (context, input, inputLen)
$ {0 d, a# C' s t& p2 ZMD5_CTX *context; /* context */
' B& G8 }! @+ n& g. Gunsigned char *input; /* input block */
+ C3 B) o4 ^5 E. Yunsigned int inputLen; /* length of input block */
& a$ V. R' {7 B. T{ unsigned int i, index, partLen;
* |, x+ Q8 U" v: p# t /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ) m* l% Y5 O! O' j2 j1 `# L
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|