|
|
#include "global.h"
( ]% {4 P% L) g#include "md5.h"
+ [- ?! ^4 J! x- ^1 G L I6 E) V/ K# T* e
/* Constants for MD5Transform routine. */
2 Z- s/ C ~2 G0 _6 u+ `8 T4 h # @* V9 Q7 c; P' r
% T6 z3 o+ q7 u' |( q
#define S11 7 $ C5 y' r* V4 ^9 M1 D8 Z
#define S12 12 & S. B$ ^6 j9 O
#define S13 17 n5 b# L4 H* b2 R# L
#define S14 22
' u6 A1 w) B) i; D% a9 N) `#define S21 5 $ x9 V. [5 `' V: Z' T2 P8 e, o
#define S22 9
' D! Z. I; N" m8 F/ z M/ {#define S23 14
- Y, e% f- u+ w#define S24 20 + y! @$ {% b6 b# Y: l% I
#define S31 4 3 G- D* ?5 Z/ r
#define S32 11 , c% v$ }1 N9 _
#define S33 16
: _/ `0 V' v: ^$ G#define S34 23
# O+ V. S( {" o#define S41 6
, Q0 T/ T/ A9 u( r) B8 g1 c6 L#define S42 10
( r+ I! r' z. j0 k0 B$ v1 w! }2 n. k#define S43 15
# ^* I F. H& I' P1 r1 V- E, m#define S44 21 " q& i7 h* ^, L8 p3 ~$ y
0 s! ?, \6 B. d$ L I! f$ [static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
6 u7 D5 Q: V9 P, b$ S8 |static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ; {+ x0 S9 g* W" s6 F% c: G- N5 h
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
! \& z& W! c W' n( l" }$ h8 Wstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); , n9 N6 K/ u8 j6 O8 U5 q: h* i
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 0 G* e" g& {) w7 ^- K% c! [$ K
% i. U, ?" p' A% @
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 2 P% y3 e& X6 O; _
};
9 G0 E/ ~, r# V; l3 f& V6 Y
' b& i8 O- y1 y; y/* F, G, H and I are basic MD5 functions. */
1 [' \7 ]# k) ]' H: A/ A#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
8 `5 q' P& s' e. o+ P#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
: e$ X& n0 G* T/ w#define H(x, y, z) ((x) ^ (y) ^ (z))
) Q4 R; Y/ b: n/ o2 d- s; `0 a#define I(x, y, z) ((y) ^ ((x) | (~z)))
0 j, o' X% K4 J2 g8 s9 P / \2 w+ D0 S& A
/* ROTATE_LEFT rotates x left n bits. */
2 c, W4 p- t7 X6 k7 |5 ]#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ) M. E4 b2 G$ S
8 H2 D# v" q4 J$ o; l+ ^1 u4 \/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 6 o; s6 K7 W7 l9 R5 s. K
Rotation is separate from addition to prevent recomputation. */
% R5 T1 T+ F* X4 O#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
! j! B u$ z& ^ s& m3 ]8 m#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 7 _. z8 z' F: m& ~
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } # e1 j% }$ a+ I2 k
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
! k: \% | d' G8 Q" M" C
3 L$ q# X3 C) S/* MD5 initialization. Begins an MD5 operation, writing a new context. */
5 S% M, b: n* W- R( ]void MD5Init (context)
/ W8 ]* D1 ~5 ~! \, M$ U- M5 `1 xMD5_CTX *context; /* context */ : {, E' Q8 ]# g( d, v. B
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
' L( Z6 m& A. n/ F8 `2 v: i* B, f*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 1 C! S% E8 v( H" L0 L- p! U
}
0 B Q, i# Z$ s/ b9 X+ l" ] ' `; j( {) J, l: C0 O- J9 o
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ $ P2 x+ S7 `3 h9 n! P
void MD5Update (context, input, inputLen)
( m; u2 }: L2 b' }MD5_CTX *context; /* context */ 9 O1 G1 W" @& R; f5 c# K/ m* h* }
unsigned char *input; /* input block */ * O- j% a0 [4 r% {
unsigned int inputLen; /* length of input block */ 1 Z6 T5 j/ T3 Y6 C" o) p+ \) e
{ unsigned int i, index, partLen; , j; d! T5 I' Q. E6 H
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); + d! `4 N% z( h. t
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|