|
|
#include "global.h" @: f/ |5 n9 ]0 l0 F; X9 u8 E
#include "md5.h"
1 A. B- z4 ^0 q: |5 Z8 d 0 E6 [8 @8 t- b
/* Constants for MD5Transform routine. */ 3 x1 t2 X. \! j$ u
/ ~( d, A3 |) M: d* F, Q: i 3 L7 I+ V9 ?4 q3 n( ^- }
#define S11 7
4 K& g- X0 `. U# p#define S12 12
4 Q+ k3 n7 t2 D& {#define S13 17 1 ~* @9 M. M/ |/ L
#define S14 22
/ O; I3 l' Q6 z#define S21 5
, L2 H( |# w" _#define S22 9
9 A c. N z: a, ]; L: z#define S23 14
( t8 \6 |2 r5 ?, Y#define S24 20
% |$ S7 `, f6 s: B' d. L: O# B) T#define S31 4 & T% Z8 G9 d$ g; M7 B$ _
#define S32 11
& }' D8 r$ m. G9 d- Z4 z5 j#define S33 16
; F* ^6 F# p8 J4 G, p6 d#define S34 23
2 m, ?8 J) `* p, z#define S41 6 2 B# g7 p9 d( o2 G6 x: v, y
#define S42 10 5 s, w# u( \; U9 ]9 i% p3 [
#define S43 15 # D f; `. F3 m# T. J8 z) n
#define S44 21
4 ~/ U4 W: G. \% e3 D9 ?+ x
" {' z2 e" c0 d- z( `7 lstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 3 b. ~' P7 C2 @3 s. l. c
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
9 ]1 ^6 g# \2 `6 qstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ( G) V% H! l; r( O/ ]6 F- m" C! R
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); % q1 r" x, r/ H( k" A, J$ x3 x) \
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
6 S9 t- I, i/ e% b: v. c 8 _2 ]/ n1 _$ f2 x j
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
% E8 H4 R. f p T7 `9 L}; / {# v! z# f% p5 ?
. P# `# N; P7 Z9 ^7 o
/* F, G, H and I are basic MD5 functions. */
3 v% D+ S5 D# `0 A$ `" ^# i! W#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 6 C6 J+ u' N0 q- J3 y1 }
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
' c- V- s% y% o C2 T h" y' I. W#define H(x, y, z) ((x) ^ (y) ^ (z))
0 q. ^- Q7 N9 M; C& u#define I(x, y, z) ((y) ^ ((x) | (~z))) 1 f" J$ B' t0 Z. j7 h
9 g P' Q8 Q. ]6 e/ }* u, o- c) n' G/* ROTATE_LEFT rotates x left n bits. */ " v, i( g3 t; N6 Z B' q+ N) M7 B* B" t
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 2 X# M( p4 d: Z9 S, i8 A: l- S
+ T# C: B. d$ _, X7 Q- }6 ]0 e/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
8 |" _% A9 P7 ]5 w! F8 ]" B# WRotation is separate from addition to prevent recomputation. */
' R. a% c- _ C9 ~( b: K% O#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } - P. o+ _1 v( C& A$ G' O0 M
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& I. g4 O/ t" ]; n#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } " y+ l& H. {' y" O/ u8 ?3 D% p" p
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } / K5 `: K; g# d& F3 P0 Q$ W; I+ F- ^$ E
. E" f" a; r# i o5 u) A/* MD5 initialization. Begins an MD5 operation, writing a new context. */ . X4 O+ c% e- U, q+ J/ c7 F( B: _
void MD5Init (context)
! q& T6 J3 k5 i( UMD5_CTX *context; /* context */
8 Z& l1 q5 [7 O0 e! o! ?{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
& i! q1 |) G- I8 K' _4 L. C2 [*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 2 S% N" q' @. W8 P0 b: N: {; i& `0 F
}
% }; }" Y- A! S: i
# Z: L5 ~! D% `% L# G( x' \/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 3 j( b7 t( D: n" B/ T: ^1 ?2 M6 P
void MD5Update (context, input, inputLen) , |8 ~/ N. G! c# ?
MD5_CTX *context; /* context */
1 Y; \8 G$ W5 P0 u `unsigned char *input; /* input block */
: `# I7 G, P/ x' hunsigned int inputLen; /* length of input block */ % I- `" `8 t2 ]
{ unsigned int i, index, partLen;
' L3 y# J4 V0 a6 c /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); # B* h. y$ N. T- C) H1 h( l! g# O
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|