|
|
#include "global.h" 3 K# F& ?; P; i% U$ k
#include "md5.h"
' u' }: y4 G$ `7 Q* N! D5 U
3 ~" Z: C% f. s4 [9 H/* Constants for MD5Transform routine. */ ( _' U* x% d" b/ G) H5 V- T
2 h, t+ A& x4 d5 y( G
6 ^* |4 u }0 y: r- k) P4 z- Q$ I- z#define S11 7
$ E2 ^9 h7 [! i1 h#define S12 12 % `/ a/ a' u# [2 q F
#define S13 17
4 ^! V- ]( R# l3 ]" b6 V#define S14 22
9 b+ Z; B8 p/ u3 U( |3 w: d% V, a#define S21 5 , ]& _& Z* z% f( h+ r! B0 V, T9 d
#define S22 9 ; h! H% u4 e/ k, ^
#define S23 14 : | f! g/ h2 C# @8 B' O
#define S24 20
% A& ~3 _# n3 d! P0 S9 Z#define S31 4
$ @% a6 M) r% }3 y' B# j#define S32 11 + h) O' ?6 Z. R
#define S33 16
! z2 a- z% S) O2 F8 c. y/ K#define S34 23 1 ]1 }6 ?# u! { j# \
#define S41 6 " k3 ]( ~6 t6 [) [
#define S42 10
; V( a6 A6 I1 L; P: I, g#define S43 15 2 n2 b3 _" R( t' r0 A; c
#define S44 21 ; E8 k! d% Y' q8 X' L0 F C
0 g: @$ A8 O% }
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); ; E" B. r8 S3 N7 v6 p, K! T
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
8 B: a. P# }, a) cstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ) O7 y" [$ `& q) j6 f
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
& B( H1 j& |1 j: X9 H/ Mstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); : D) M% F" w& o0 V! |) _
' Y9 o) Z5 F% Y8 Tstatic 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
$ X6 U. z5 K* X1 ^% n};
; y4 Q2 ]% I. H9 X" z4 J6 i / r1 a2 p* S- [2 r
/* F, G, H and I are basic MD5 functions. */
3 p. c: f. I/ b) \' R0 C#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
( o8 B0 l# V' S: K' I. X#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+ V0 y2 r- R5 n4 x1 K- Q4 H#define H(x, y, z) ((x) ^ (y) ^ (z)) 1 R9 ^4 ]/ J k4 r: }
#define I(x, y, z) ((y) ^ ((x) | (~z))) 5 ]/ m" b! ~! |6 P
+ s/ \( T% l8 U8 E
/* ROTATE_LEFT rotates x left n bits. */
5 }' @# O9 O. \ {#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) , ^* d- J/ c+ l/ M
' U. a7 ]- n' [/ }: z2 D6 I/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ( R. o2 ?0 O: ]! A: v* B3 K2 |
Rotation is separate from addition to prevent recomputation. */
5 @. a* B, ~# M( ?0 H#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } . ~0 a' T- \ }) \0 C; T. i
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } " h9 y& i' `; T8 U$ d/ |8 J
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
6 Z" Z4 h+ m, @9 Z8 K: h9 x* h#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
4 ~, O( X! I. l1 P1 o8 p- d# V( U
) @0 z+ b3 W4 d* s7 K! g/ v/* MD5 initialization. Begins an MD5 operation, writing a new context. */ / W9 Z+ K4 j0 W3 m7 K+ L
void MD5Init (context) ' j& `( _# v: d {
MD5_CTX *context; /* context */
* k2 K [6 u6 w$ M% ?! V V{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 5 a/ _9 v. W0 f6 k) E' @6 X: e
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; # \( T- u4 w& Z% @: J9 w) Y" n
}
; C% |* c9 U( t6 R4 E# p& j
% T0 M0 h* T$ j# z, A0 K! ~/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
/ `# I2 |' e8 ^# {, uvoid MD5Update (context, input, inputLen)
# y9 K% L8 A/ L' n( PMD5_CTX *context; /* context */
9 h) u' O9 U2 M& U( y0 c+ \: U( Junsigned char *input; /* input block */
* R% l# n g/ b8 Xunsigned int inputLen; /* length of input block */
: O% E9 p9 `- b( t7 j" Z8 D7 Y{ unsigned int i, index, partLen;
4 f+ |: M5 P) L /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); # y) e9 W7 a0 B+ F+ Q ?
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|