|
|
#include "global.h"
6 z! `4 {' k! [8 n; u$ P#include "md5.h"
1 C% A0 F" O8 z' w4 K) O7 j5 _ 2 d2 n& g! L. ]8 s9 J
/* Constants for MD5Transform routine. */
6 C, M0 ` m/ F" A" x6 R+ q. q2 V! ` , H9 S0 E6 P4 F& Y# U$ R
9 }% @9 z3 v8 u9 j( T- }
#define S11 7 , H9 m9 q! ^0 ? {# P, a
#define S12 12 . M% ~' c+ M6 F
#define S13 17
% h& H) l; \# ^3 W" U' }* t#define S14 22
$ l& @$ h% C8 S#define S21 5 ! C7 [# ^( W: m) k8 I
#define S22 9
# u7 ?% o7 N8 X/ V! f8 m5 `#define S23 14 7 X! y* f6 {+ u, t" |! h- p
#define S24 20 9 B L( r X# \: `" m) R' C- }
#define S31 4 2 B8 J8 f: W$ @
#define S32 11
/ f5 q$ i9 O5 c7 s0 [+ q! S i#define S33 16 ) V- w9 k5 B' h% K1 z$ m
#define S34 23 7 J4 G% w7 O7 K/ _4 a
#define S41 6
' t/ A) S4 I( Y9 X$ \- W#define S42 10
$ d+ {4 m9 E8 g3 k7 W7 N2 k* c7 E9 u#define S43 15 $ Y( h9 x) z, `. i6 e
#define S44 21 % s/ m: L+ `4 T% k6 Z
) b7 d, o( J' i3 k
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
0 E4 d' I- n' F( F3 tstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); n. b" a4 P! @1 e9 f
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
" n7 U+ X7 X# v6 {0 |* c& U0 Z# ystatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
7 t- A! P1 K; h2 F# bstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 2 \/ n: P- \% I" W$ G8 k
' K/ L9 T0 ~( G, I; 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
c& y, o7 |* c" ]}; & u" o5 h, F/ ^5 m7 i& ]
, ]% J2 h8 w; s4 F7 N5 Y1 `7 Y
/* F, G, H and I are basic MD5 functions. */ 3 I: z5 k& y" Y5 M% @
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) * q) w* S3 a3 [( ]! Q5 T& p* X
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 4 \1 H; p5 ~8 @" \" M
#define H(x, y, z) ((x) ^ (y) ^ (z)) ' W" Q. Y/ a" q( p/ h- h5 k# U0 [+ B
#define I(x, y, z) ((y) ^ ((x) | (~z)))
" r& a2 A. H% z7 n
1 ~5 r, N1 l7 \6 d% D" _( ^/* ROTATE_LEFT rotates x left n bits. */ ' U7 {* p) @' z- [4 t" r# D
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 3 K4 m& o4 x/ t0 U# m% u" _8 I
& `+ J& J6 i$ m# J& P/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
0 e+ t! P# b3 X7 Q9 q( L# xRotation is separate from addition to prevent recomputation. */
, h2 N- I" f2 e2 \! ~' X0 A9 P8 p2 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); \ }
' q8 p% `0 T# i, a% r* u+ k1 }#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) B" y: O8 _ M6 S
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 0 L' V) q! D0 p6 U
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 8 T& w- K% @6 W+ F2 F
6 A4 ^ F9 I5 _% J8 t
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ( E8 N0 M8 Y3 ]6 O/ t
void MD5Init (context)
- A1 v. @1 f, I5 Z# {MD5_CTX *context; /* context */
; o$ V& N8 M0 S( M2 p{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
1 ^4 ]$ R: j" P) P+ }' h& k* l# x*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
" N/ V# W" T3 u; D% L}
; U! H( H& z! B: y- o. H) r. L: E 5 h5 h; O% H! O4 [) W3 F1 @
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ + p/ k" E5 E5 t' ]4 B# n0 H0 C( P
void MD5Update (context, input, inputLen) / D# B. r% k) I8 s) b5 s( g5 S
MD5_CTX *context; /* context */
' O! ]( q' X0 ^3 T% V# aunsigned char *input; /* input block */
' P) L: i, N: c: i7 v" f$ A, Y [unsigned int inputLen; /* length of input block */
' Z' |7 P; F$ Q/ s{ unsigned int i, index, partLen;
4 J0 v* j, Q) j2 J /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
! l9 I8 b1 P2 C /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|