|
|
#include "global.h" & H& z1 x0 _ `: K* |, O* j$ d) x
#include "md5.h"
/ ]! f. J& S& u3 z; F
( A! K! P2 x& {5 o/* Constants for MD5Transform routine. */
1 c( ]% d& Y4 k0 `) h& w! L3 K Y8 e: {" v; e; V8 A
! ]% b, W* S2 D7 Z; Z6 t
#define S11 7
1 i8 r! @7 i" W' a! J& a+ w#define S12 12
6 M+ e8 }: }. |- x- G- {#define S13 17 - V8 j" e) B& ?. g3 n
#define S14 22
8 a# [/ @# r" V% ?! d2 c; _#define S21 5 ; G1 U& ~& I% J1 f5 u v
#define S22 9 . R5 h0 b! z( L8 g/ i
#define S23 14 " n" ?; [1 W4 H& A+ @
#define S24 20 4 A1 ^0 m/ I1 e$ Y
#define S31 4
% g# `0 J7 i& N+ W: z#define S32 11
6 Q! \9 ?9 l# b! T4 a7 w7 h#define S33 16
. ~2 o Y6 d& P$ H#define S34 23
# J' ~9 ]; l# i( z. X/ Y: A#define S41 6 + r& \, \# ]8 k. W. x
#define S42 10
1 \7 _; g8 P6 ?9 u1 C |2 s#define S43 15
+ X* \( C, I6 z5 y; p9 m4 I#define S44 21 0 W$ P$ T. U: w) z+ \2 d3 u H
; @4 Y4 W% \$ n% z+ \8 Ostatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
7 W- V! a; d- H! N! {3 R- S/ D+ o0 _static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
" h9 G" b! X6 J: {7 dstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); # _4 [& N- U8 L9 c9 Q0 c
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
( @ g/ ^5 V& M! P9 d2 C! f2 ]static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 5 C8 v" X- Y7 r. t5 P/ |
3 N* t' G% w9 m* i sstatic 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 * t1 Q' @ B3 z: g
};
" y3 }' k( K5 ^# k b 9 b! o1 d* Z* v0 |
/* F, G, H and I are basic MD5 functions. */ $ q2 B0 _- W5 i; H
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) " I0 `( j; U' M* G8 Z4 x" i
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 2 W+ B- Y- b$ c, e" j/ A
#define H(x, y, z) ((x) ^ (y) ^ (z))
9 F9 g( d4 `/ C* h1 `0 L5 h* I; _#define I(x, y, z) ((y) ^ ((x) | (~z))) - C9 |. L7 g) z) {! Q4 T: Q. E
: t7 u1 U$ X+ Y
/* ROTATE_LEFT rotates x left n bits. */ r2 J- f& _; X! |0 k
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
4 l7 F3 t3 {5 x* v, O# e
& a5 c. H" i. Y7 W3 i+ r& y" T/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
7 b) i6 k1 M" n6 v3 R9 `6 GRotation is separate from addition to prevent recomputation. */ # r9 K' Z3 \3 T7 Q+ n! m( s
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 P& V9 _9 b" c8 g0 {
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } " @) `( G! e! 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); \ } & Y; s; l! y! K A* D- Y! L
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
' n- {7 R2 R1 v/ R 0 D0 a3 I5 F6 o, Y
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 3 \$ I) V+ h2 G2 p# V- l
void MD5Init (context)
1 q3 b' U* b) h, s. dMD5_CTX *context; /* context */
! a0 i) p+ _1 t* c{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ]; d; M1 Y" C1 V' N" r
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
4 N) R' d' }+ O, v# m} ) ]& y4 R6 y! Q) P3 q9 @
7 J K$ k" r0 ?9 }3 K4 ^
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ / U0 C5 R* i4 b
void MD5Update (context, input, inputLen) * V P3 d# J. _3 P; t
MD5_CTX *context; /* context */
5 B% r# z# C' C$ ?/ H7 o! Zunsigned char *input; /* input block */
9 p( U8 h- A- T" @( yunsigned int inputLen; /* length of input block */
/ i/ i' y: L4 }& ~{ unsigned int i, index, partLen; ; C% B( x% h5 u5 i# ]3 N
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); " Z/ w. ?: V2 N6 y8 i. F
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|