|
|
#include "global.h"
% b# `' u! U1 j L$ E/ M3 p. n#include "md5.h" ! D! m7 Z3 ?/ X
0 c2 x/ P+ u" F6 V( T
/* Constants for MD5Transform routine. */ : _7 _/ k( R; H+ B3 [2 h" Q
- G7 w+ _7 k5 `& K+ S" G |1 u1 X4 ?/ [+ Y. m
#define S11 7 3 ? [& R. ?# g# b: Y7 o
#define S12 12
& j; }9 X9 B n6 w0 `#define S13 17
! s4 Y! U8 v3 ~6 h: z$ M/ F#define S14 22 2 g+ R E, M3 ~+ z
#define S21 5
: n& E+ K6 \9 Z4 @$ ]#define S22 9 " v/ U% e4 \. M" C0 ]5 K
#define S23 14
% L o. z5 i# d- ~( z#define S24 20 9 z4 @% h# ] ], B8 @$ {$ W
#define S31 4 0 O8 M5 J( }! o4 b& J; o6 F
#define S32 11
, p$ T7 A R8 ~# `6 u8 O) _ Q#define S33 16 / n7 g( l2 y/ t. J! A
#define S34 23
$ ]+ I2 h8 ]1 K/ |' M ^#define S41 6
- b" l" O3 C/ _2 C( q$ {/ z#define S42 10
& u+ B; F6 f& M) X4 N, |#define S43 15
4 _" J6 Y# H+ e: S$ G#define S44 21 / `2 n' D: D& }- P' E. e
}* |" U0 S9 K' p
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); # y6 C% W) p$ X" _" }* J: h
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 0 T" L% _ }) h* g0 J' x
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 5 w# c0 `2 [. o5 ~( U. c% n7 S
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
& n) E1 x" @# ]+ z) I# Ustatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
% D# |9 `4 M7 ?( k9 e- U
4 U" k" A2 e" @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 ) Y( P: \9 z' c! A: v
};
0 S m$ p- N, ?4 m6 @7 K+ C. d 1 Q0 Q/ n2 t/ ~6 w
/* F, G, H and I are basic MD5 functions. */ . D' N2 {( \7 Z1 y
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 7 @- b0 T2 [) d% M/ Z9 |
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
1 n- p- t w7 s9 n+ L#define H(x, y, z) ((x) ^ (y) ^ (z)) - p" Y) k$ I% K- U0 s2 J
#define I(x, y, z) ((y) ^ ((x) | (~z))) . ]: K5 g1 K' @
# \2 }3 @) U/ z3 h/ T5 h' u9 O: k
/* ROTATE_LEFT rotates x left n bits. */ 1 @ e! n7 E8 ~+ C9 k! ^* a! ^
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) & R) Q& j1 x7 l3 T8 U. t
/ a' F8 g/ `0 l! O `2 A9 u4 u% r/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. , W9 ]1 d3 v6 M$ M' q f
Rotation is separate from addition to prevent recomputation. */
9 a8 o8 A6 k3 G3 U4 v#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/ q% u' S( B1 E0 _' ?7 G
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
5 k! j* j0 c; U# C% 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& c# W0 f! w8 t# G/ Z( }
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
: s3 G1 U" F* `7 _( [
5 Y! e# D, D3 V/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 6 V7 z( f1 ` @- @% D. ~" K, k6 X$ } I
void MD5Init (context)
9 ]& u1 R2 Q. K% jMD5_CTX *context; /* context */
8 E8 c4 O# O9 p2 W9 _: g{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
& Y% g8 O! N8 y*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 7 }4 `* @# @ k
}
: I% V5 ~% ^% B9 g W- s / [% q, A/ S# s2 ~
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
! }+ ^7 n3 j" vvoid MD5Update (context, input, inputLen)
( n! H1 p( ^5 ~0 F4 m* IMD5_CTX *context; /* context */ 8 _+ J& _$ M3 Y7 N3 L! j. J1 L+ u
unsigned char *input; /* input block */ ( w$ H4 m* F- \9 S5 y
unsigned int inputLen; /* length of input block */ 8 {& W: Q% h: u& B$ e- a
{ unsigned int i, index, partLen;
8 ^: u1 K" C! g' m /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
* z. ~. w; L" ^& V& J /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|