|
#include "global.h"
5 S% R9 Q% n% F1 l$ m! ?, I& o#include "md5.h" " A+ k" ^6 D% \ X! ^& F7 Z
, z- ^! S. Z0 R2 `: X- l/* Constants for MD5Transform routine. */ / R! E! W/ u$ ?! Q2 W# ]3 l
' P0 w" v8 Y, V) J. {
0 b# X$ v+ h$ Q" p6 u [
#define S11 7
5 ?8 G, u3 C6 v) B7 _; r! L* g#define S12 12 ) g p# G% U" o0 [6 g3 R
#define S13 17 , q/ r' q2 \) z1 G) F; A- X& \2 ?
#define S14 22
1 a/ ?( w8 w! a V#define S21 5
3 w7 y. y( | g* k3 T) a( l6 i#define S22 9 7 T# D* h5 ^# |. X x d2 z% f$ h3 N
#define S23 14 ) T/ v" X* s/ x7 x8 y4 n2 A, ^
#define S24 20 ) Z% [& |( r+ K: ^) P7 o
#define S31 4 & M6 K) R2 p8 J, S6 g( N3 I) g
#define S32 11
' E! p( @, m; z0 M& n( m* I) c#define S33 16 6 C' U9 i9 { O8 i2 |+ U o
#define S34 23
6 {5 P; y6 X1 l/ {3 r#define S41 6
4 ?# C5 |( f3 p7 b#define S42 10
" c- @3 @8 }* x8 m5 f: _( {#define S43 15 ) g! F) r5 [. x8 {
#define S44 21
3 l! ]! e8 ?. N, e. E: l# u 7 b; L, w# t+ P6 P# T. o
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
: f& j5 d! ^, P7 q4 V) f. ~! Fstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ( L3 u5 y; v9 A+ z& V" u8 L
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
6 s, Q4 n) ^$ S, S0 R6 lstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
. @- i, }6 X1 \" k. Q6 M" K& lstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
8 O) W, N9 m7 K) f; ~
+ E7 P4 Z" v/ t" M6 U5 cstatic 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
- F( S) G! Y% y. O1 }7 T Y% T; C* q3 H}; % Y" X v) Q. R9 ?
: u4 a9 z+ X; \
/* F, G, H and I are basic MD5 functions. */ ! _* b3 a9 y) K0 p& E/ v9 V- O
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
2 z4 q4 {* D% j#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) # J' _5 G0 t. t& A* n, E
#define H(x, y, z) ((x) ^ (y) ^ (z))
* M, e+ P% z M- h: x1 g7 a& i9 v#define I(x, y, z) ((y) ^ ((x) | (~z))) : [' y9 D8 h! {# b
9 K$ o. t% H( g9 ^
/* ROTATE_LEFT rotates x left n bits. */
0 ]8 ^( E" u- w# q; ?5 ^: [#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
. k9 R4 G6 ~# b6 R5 ~! M
3 m3 X0 R, E0 A) |1 b$ W& Z# c6 f/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
7 o# o' _# u' J+ v2 N CRotation is separate from addition to prevent recomputation. */ * Y' R7 Z! N2 j4 C3 _
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
# h9 {( l% B. d' e#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } - E* s; s% J5 D( c: ?
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 2 y. U2 v. q/ Z* U: y) I
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ' E# L6 l6 Q9 A- ]( Y: C
. ~9 }( j. N) h7 _/ ^* ^- K* b) l/* MD5 initialization. Begins an MD5 operation, writing a new context. */
& P6 l, [& l5 }& Ivoid MD5Init (context) 1 I: B, O9 `* f ^; q
MD5_CTX *context; /* context */ ! r! V0 ?" ^+ w! ^: e; ^2 V v
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
, e+ W1 C9 [5 w; f; ^7 ^; x5 F*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
1 u( G. T* Y! ]0 l) m8 w& X. B9 _} " Z" R3 R p9 J) O/ m
+ p/ B: l1 t' n: U$ x: A/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
" N( Q w3 T2 Pvoid MD5Update (context, input, inputLen) 7 I$ a) s- E; a$ _2 S! S
MD5_CTX *context; /* context */ - n6 T& |& d% G1 D
unsigned char *input; /* input block */ / G7 \4 O( {0 s8 r1 n$ e$ c) v( d+ u
unsigned int inputLen; /* length of input block */ ; Z U5 A) u' B5 w6 s
{ unsigned int i, index, partLen; / _1 H4 @$ f, y3 F) U
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
: n# w; q% S' Y; B% P2 r /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|