|
|
#include "global.h" 9 U: M9 S, o' `! |- _1 Z
#include "md5.h"
( g/ j5 c/ F# M1 B
2 F, y: E4 F! Z! s0 n4 D( ^/* Constants for MD5Transform routine. */ 1 ~- F# }+ K. W3 l1 O& K
# F% g5 O# A7 o8 c4 B0 n
; H* Z0 v, C$ U$ `) m$ {8 j
#define S11 7
J1 o( C7 z, `$ i0 [#define S12 12
' @7 f+ g9 e0 e: x4 K N9 z0 H#define S13 17 Z4 s m+ G s% `
#define S14 22 ( G4 T, {# U: T8 p1 j
#define S21 5 9 `7 M5 x6 g6 I& N$ M- b5 y& X' {! q, v
#define S22 9
/ f$ i. A' p2 X#define S23 14 ' G. Q5 G# q( r% n- h- k
#define S24 20 ( z4 d, ~* N3 E% x& e+ ]% ~" i4 j# G U
#define S31 4
h% J) j- G- H) N4 q#define S32 11
- h6 K A+ I4 b/ F+ z: K$ S#define S33 16
" ]) t' K& f0 Y#define S34 23 # @' B5 \7 Z0 c8 x# [9 f/ W8 g
#define S41 6 3 t9 r$ |$ h2 Y/ f
#define S42 10 $ O0 S1 Y+ t3 X7 i
#define S43 15 . T9 Q" G" C# x7 v3 s" X1 F8 S) U
#define S44 21
4 x" \5 w& U& i# y' W
$ i, k G7 R/ ~6 s2 |# G2 n Dstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
5 @. y. n' f" l( }static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
) Y2 T0 b! G7 ]. L' }0 Istatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
# j1 v+ Y7 \: ?4 @7 {% Zstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 7 k1 u* H' j- P9 ~8 Q6 z# E/ r
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
5 H# y/ J0 A9 b# I
; F% g7 Q( Q; A: q d; Jstatic 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 * ^) w3 p' G; M# W
}; j9 P9 p4 \& Z! [% \
' k# l( S/ T8 H, I# H5 d0 ^/* F, G, H and I are basic MD5 functions. */ ( e" G4 Q" y" ^
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) , {; C f R& V) Z6 j
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
' O7 F$ o) }7 I& E0 ?# z9 D/ ^6 ^#define H(x, y, z) ((x) ^ (y) ^ (z)) : }% @, n2 X; q" S( }+ y! I% H
#define I(x, y, z) ((y) ^ ((x) | (~z)))
V/ W0 ^, r: U, T4 ]* R5 k; B+ v . {" h7 [0 [8 x6 d
/* ROTATE_LEFT rotates x left n bits. */ # S, K3 e/ F, `
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
7 T& X6 U. n' Y% ]. x0 P& m& h
- N1 h; s! s. [/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ?- M/ J; G1 G3 G4 H0 d
Rotation is separate from addition to prevent recomputation. */
! S+ X( u1 K7 i4 Q% I# `' r1 U. B#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } $ A$ w! J. s3 n: n2 S2 h
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 2 U5 N6 i: M8 V, ]2 g, T; A
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
( T9 q' A! u+ W3 L2 o& |# n#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
9 u% u: n9 z3 g4 k; o3 W/ C ' h y0 S& @$ u1 q% k4 w
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
' q% A% K/ c9 ^& A# F3 wvoid MD5Init (context) 9 a' f. k4 s; ]
MD5_CTX *context; /* context */
/ X( B/ C2 Y1 X- F{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
5 c; }) b' I3 Q( t8 ~$ J*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
- }5 E6 { y2 S$ s I7 R}
/ k* t! w; W5 [( G) P" V
( ], h8 u# L) }# |% w/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ : S9 _) E) _% f5 e/ S% o5 f
void MD5Update (context, input, inputLen) 2 ^4 D6 F- Z/ ?# ~ r
MD5_CTX *context; /* context */ 9 [$ k+ v y1 l) Y7 r. |4 G
unsigned char *input; /* input block */ # w9 V! \ S ^+ D% y
unsigned int inputLen; /* length of input block */ 7 n' p& }" [6 R P- [( R
{ unsigned int i, index, partLen;
( V6 q% d* v5 \- W' w5 D /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
- C2 e1 ` l7 ^ /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|