|
|
#include "global.h"
^) \7 a$ o1 T8 f#include "md5.h" . ]5 u& R- n# \ B D! T) z
1 T% g& v9 a2 Z$ U$ H8 [; v/* Constants for MD5Transform routine. */
t6 r( s% F2 v2 A4 c - `8 r. l# I8 k# y8 V2 M8 p! P
- _' [4 n: K( K$ @7 q" \) F
#define S11 7 " y3 T z6 p) I( H h* [
#define S12 12
+ D: I/ @$ ]" `8 W/ [1 k#define S13 17 + ^5 t* z# ~3 C) d3 U$ s
#define S14 22 X- J& q. O* R1 j! x
#define S21 5
/ S$ Y, r2 a4 L1 y) X#define S22 9
" w* `" c, R, c6 o1 o+ h; y#define S23 14 # N( t5 ]5 m* A& u) l ~1 P
#define S24 20 1 P3 S K9 @5 \4 I0 N/ a
#define S31 4
2 \4 p( {' Z/ Z#define S32 11
9 n! W' {) o# Y" \9 s- n( `#define S33 16
1 r o8 b3 m4 ~! _& M. }+ ` v#define S34 23 : w$ y3 u* j. A
#define S41 6
; F# x' ^- n5 d8 f. c3 ^! }% F#define S42 10 6 Q) D3 b. v% B0 A8 q
#define S43 15
3 I) b* ^4 G8 X! U#define S44 21 4 P% z' k* C- P4 k3 D
d6 j; A8 f+ S$ m' Z
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
" L) i: V5 k! E4 `static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 1 W- |# l5 H2 p1 V0 k
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
; P1 j$ j2 v; F9 L) J/ Q8 rstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); * E; K# h* m8 |" Z- j
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
. C! l+ P% ^+ o( E9 Q
3 _) O1 o' L/ N9 G# v; dstatic 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
# k O: O, O3 C0 P0 N: ]};
" u4 `- u" i1 ^; ~6 m5 T
. t% _5 c0 A3 W9 |4 }$ U# B Y/* F, G, H and I are basic MD5 functions. */ ' V8 L1 }8 e' A' f* o K V
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
2 ?' u6 s; W8 A; j& x" |#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
, b0 H; F- K. M% g- A6 \#define H(x, y, z) ((x) ^ (y) ^ (z)) / F$ J, h: ^ W; ~
#define I(x, y, z) ((y) ^ ((x) | (~z)))
1 S" S8 v+ \: \6 L$ C* I* H % t* B5 y: i Q$ N- N8 v5 o
/* ROTATE_LEFT rotates x left n bits. */ + E1 m3 N/ `3 v3 ^/ f7 {7 `
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
' }- A \; E( l4 O+ O4 e9 T * Y: P- k9 D& V
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
$ B9 E6 e) T( H, K/ _1 z4 sRotation is separate from addition to prevent recomputation. */
9 H9 e# I# U( H' y! @#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
: E2 f8 h# ?9 C; Y' o8 R* z: o. 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); \ } ) q& E( h3 ~) K9 @5 [
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ' c ^ c7 X1 I5 W+ p& C
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } - Z7 x1 M* _6 R- s% s: G
+ {% i! q1 j% [5 x
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
+ ^4 H$ Y! r7 v( V; [7 O9 fvoid MD5Init (context) x# g g6 I3 S4 V. d) |0 `
MD5_CTX *context; /* context */
! o* Y# h; U. L3 F! s2 B/ k3 b# ~{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. " p/ Y; n9 d6 z2 g9 k$ _
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
2 V/ k! w4 I: E} , o) A6 B ~. Z1 Y& ]7 ]
4 K: D6 |& g; c# d. f/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
0 z& }& P5 D- Dvoid MD5Update (context, input, inputLen)
7 W% n& ]4 B) R1 lMD5_CTX *context; /* context */ % S- d5 k( g# @7 v$ O; B
unsigned char *input; /* input block */ ; @ A) O9 H" K8 n, m8 j% m' M
unsigned int inputLen; /* length of input block */
+ I. Y# E# ]% g& J \$ ^7 H# T7 n0 A{ unsigned int i, index, partLen;
; R, [7 C3 A8 e, T$ C /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); " J" F1 E: w, k5 o% ~4 B* T
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|