|
|
#include "global.h"
) A$ k! z* ~0 h" j#include "md5.h"
; ^1 v* n& w2 ?$ k8 ?9 ~8 n8 K0 X0 b
0 e! H& H( O( d( R- n5 T- M* u8 Z/* Constants for MD5Transform routine. */ 6 `3 M; t+ K) r! a
- u- g, A d( a
$ B0 p! a9 ]# X) r. Q6 U- R9 s#define S11 7
. Y6 e8 W# @- w2 U7 J#define S12 12
4 F& ?, d. C' u7 L#define S13 17 * c, r0 k2 C: c8 v
#define S14 22 / U5 {" }8 J0 B8 \; L7 B
#define S21 5 + c) l! S2 E6 b' {1 N
#define S22 9
. e8 G1 O3 {; E( {4 B#define S23 14
0 e' w9 a l+ R7 S7 Q* r; f% Q#define S24 20
+ J/ q- p7 F/ \* G1 u/ b8 |5 [#define S31 4 ' O+ `8 J( o6 t, Q5 @' P
#define S32 11 4 L: Q: T' H/ D
#define S33 16
% F# k0 W0 ~7 Q0 g#define S34 23 # S& R! w" P: G) R c
#define S41 6 6 n, L" t2 b( [+ f7 Y9 a
#define S42 10
+ z: T! T9 l1 A; `% K, U. ^: A#define S43 15 5 U) a$ J) c$ V b) ]+ t) E
#define S44 21 ( e$ c1 y( Q% b, i* |1 l; Y$ S
0 a4 r) B$ ]) T& E0 b1 t7 e1 K% qstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); / ?( F" t0 ]9 j# Q. b X! v, A& U
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); " S5 G/ T: J0 ?- c; A5 I e8 s
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ; F+ v* n/ Z, \& F. c8 P
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); / B+ N8 ^2 K- H$ q2 _! k# A
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
' N- u0 Z. X3 E: Q* S 5 U! t1 n7 F2 A3 J, M
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
; Q5 a$ {- M$ P+ t) k}; ; D0 D+ Z9 I* y1 z! g9 F
) Y: k) ]; x* w
/* F, G, H and I are basic MD5 functions. */
: M/ d- @) F' w- q7 H#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
! ]# ` u' _2 | |: o#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) * ^) x4 @7 X4 k8 ~# |& o2 `0 A
#define H(x, y, z) ((x) ^ (y) ^ (z))
! l$ T2 Z7 Q; |#define I(x, y, z) ((y) ^ ((x) | (~z))) * X7 o* h! K- o/ ]8 i
& O4 o& O) i7 s" m B
/* ROTATE_LEFT rotates x left n bits. */ - `& G# S3 {# K1 i: _
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
! ~% h& v* ?4 a8 N. w5 M* r6 X ' p& F7 \' D2 \& q e; x* {
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. % Q' X8 o. V5 g8 F# {/ z( h) G
Rotation is separate from addition to prevent recomputation. */ 3 ^( f/ O d! E1 e
#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 q/ E3 p: K, y- i( X
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ! ?, ]& J' P D& 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); \ }
- q! e+ l( h4 u6 T h) ~$ [#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
; H! P$ f' A) b N" v& f , ]9 g$ p* a& U
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
* N- ~6 V/ g( q f+ {void MD5Init (context) # `* N* O" W/ B2 l4 F) [ t" ^8 Y
MD5_CTX *context; /* context */
4 y1 O% W; o7 d) P) `{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. $ _3 k3 c b7 b. q7 P0 T
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
: s7 O' F$ Q/ _! t" ~) }* R" y! \}
& |% m @# }/ ^" i
0 O9 c3 I6 G1 v5 u+ B/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
5 H" b; ?; J3 x) h& u" Ovoid MD5Update (context, input, inputLen) - J. d# S; ?! c6 S- n
MD5_CTX *context; /* context */ + K- F% P8 D( _1 d+ B" _4 ?
unsigned char *input; /* input block */
& h5 U$ b& [- D& p+ w# Zunsigned int inputLen; /* length of input block */ 8 A( C; A- S8 x
{ unsigned int i, index, partLen;
7 n' X* S. _) l& Y /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
4 h( w0 @" t2 d /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|