|
|
#include "global.h" h0 i7 s5 g7 }! C* e
#include "md5.h" $ W8 q7 [! a7 I6 Z, q0 r0 C! I
o0 D# \1 X) }+ Y
/* Constants for MD5Transform routine. */
9 k4 @, p7 X# n- q: |1 i/ C, }
+ r+ A# E {. G; q3 P2 I+ ~. A
; I+ f4 k; u9 \( o#define S11 7 / B) h& U8 x- c0 c% Z' q
#define S12 12 3 P" c2 ]( J1 @% s3 A
#define S13 17 ( e( g1 X/ c5 c+ z8 r
#define S14 22
+ P3 ? e8 o* C% `8 t#define S21 5
8 h- j8 k0 ^. w. g8 ^#define S22 9
1 B) h- z9 K4 R5 B, m9 o7 \ |9 U#define S23 14
4 {2 \6 B8 o8 K5 P#define S24 20
' s' t& k0 ^# I, z#define S31 4
2 s4 _' [. F% _# ~4 d5 W! f# _#define S32 11
& \# M9 [2 j1 E. S' X [* v#define S33 16 " Y" O( x$ [( ?$ m) J1 X; ?
#define S34 23
% K5 P# |- r; @#define S41 6 % _* C/ S/ k* l5 Q1 N$ U; w! ^0 i
#define S42 10 3 u6 ?- a/ I; I4 z
#define S43 15 % N1 H- b7 ]4 e. v4 |; Z$ O3 C Y1 y
#define S44 21
2 Q5 p! I* m& \ 0 Q! E+ Y6 m0 K: K$ w) h& p$ j
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
7 M3 h) I- U4 _$ }6 P* O! x8 O0 [static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 9 Y& z* J% [* ~* A+ q+ x
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
0 y: J) N$ V) v# Dstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); ' q+ [& a' W* _8 Y' T
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
: o. V. T( M1 E6 H0 e7 d & u) Q3 d# m+ C
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 - f% Q7 H1 B4 B. \2 j3 P
};
' x( K) T- V/ N- T" ~8 |/ ?- ^/ I ; M( L: ~( L. p: r7 P1 p$ |9 n
/* F, G, H and I are basic MD5 functions. */ 8 j# d% M9 b, I8 Y6 l8 ^1 T
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
% A7 M; v7 [8 j) D, l; ~4 A#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
% [) g& n* O/ X* e1 t1 q#define H(x, y, z) ((x) ^ (y) ^ (z)) , U& k X6 K, _4 e
#define I(x, y, z) ((y) ^ ((x) | (~z))) ( C* \; E0 T a8 B6 j7 C+ ^
+ y8 C0 n' ~9 `: K4 B7 K) ?/* ROTATE_LEFT rotates x left n bits. */ 5 Q2 [, M8 q4 r* f" a9 d/ P
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 6 B4 k) |* h3 k$ D, x( ]
/ L! q; P8 U3 J5 w3 c q/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 2 g I" x" v8 g
Rotation is separate from addition to prevent recomputation. */
0 t& Y* X; M- P/ N6 N* f#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$ G5 W% y
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } * y# L7 ]4 i9 D- k- `& B( Y. l' _
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
L7 b3 Z5 t* k4 k. S#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 7 u, S( u& H9 y: }+ H9 C r
) r' a+ @. W7 ~: X5 E) K/* MD5 initialization. Begins an MD5 operation, writing a new context. */
9 X4 j; H3 e' ]1 Lvoid MD5Init (context) 2 |8 {6 U$ b1 k
MD5_CTX *context; /* context */
# i* z9 h* @) h- S{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. : U$ T+ Z, H6 j; t7 u5 B0 I* t
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
6 b8 s1 h& P4 N0 }- x: n! y}
1 X" z2 H Z. e9 I* k5 N 0 D. n0 U& \* K7 q" N
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
/ I8 }+ `( R7 O; C2 B# `4 q8 e: mvoid MD5Update (context, input, inputLen) # [% ]* v* s. W
MD5_CTX *context; /* context */ ) A# I+ A; K4 z' p8 d& T
unsigned char *input; /* input block */
4 Y+ R/ a2 Z5 @4 s1 Yunsigned int inputLen; /* length of input block */ 7 M) |0 H& E3 E P4 a0 e
{ unsigned int i, index, partLen; % H, A! [" n) ?) r
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
- l3 g8 o) H6 L7 r, K- Q /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|