|
|
#include "global.h" 8 T; I; |" E: R, j
#include "md5.h"
# W k/ i" ^$ {/ S$ D
: @9 O. q; Z8 v7 U( \/* Constants for MD5Transform routine. */
9 [1 P9 m; }3 i% {# r! Z
6 k8 m; R: \3 F! |; ^& f 4 ~8 ^: H* _0 `* s3 v; X
#define S11 7
3 \! J/ d6 ?+ ~9 `) ]$ @3 T#define S12 12
; z+ P& [$ ]' O# k7 p' i#define S13 17 5 e% y7 l1 u! C
#define S14 22 * t1 ~' U8 _+ X. a l4 U/ O8 f
#define S21 5 . w/ t: [/ l8 v8 Q
#define S22 9
3 C1 D, l5 g: W2 E" D9 ?#define S23 14 4 W5 V! ^6 X: A, h. c7 J! E
#define S24 20
/ K. d& t* c4 Y: u; \' u#define S31 4 # d* f, Q5 d) v" Q, }/ U7 |% A
#define S32 11 ' Z0 A* j& K2 g) o
#define S33 16 0 E( P4 b) U/ _* g; j
#define S34 23
: J: J; [8 e* M0 q" C#define S41 6
/ A3 S5 k% H) l, s#define S42 10 % o- I* K0 R. }' p, q2 G4 A
#define S43 15 6 d8 ?5 h) |; n4 q* G! H
#define S44 21 + p/ F" O: T$ @6 A6 e
& T: I" I) s2 ?% R4 \4 h
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
, i0 M5 W0 D: R8 R( Pstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); : n, _: N$ B1 Y! D' X! x. C* D8 y
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); % p; \( L1 p/ A Q- [
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
4 g, Z. C* ^" r( r& m5 ` N! H, g% G; Cstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
. [; Q+ E6 U$ P" _3 P- I
. X) z- r: W; u, ?- E# g5 |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
7 e1 l" {8 S# Q0 q0 w};
3 Q; f, O2 }+ R7 i! \( v9 X, o + s+ S, ?" k1 [+ B, ]
/* F, G, H and I are basic MD5 functions. */
8 Y {7 W& ~9 D% P: N2 y5 q#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
: A; v% ~- o+ t, | F0 q( ?+ ]#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
" k, p6 G) X0 s5 w: L0 D# m |/ D#define H(x, y, z) ((x) ^ (y) ^ (z)) C: c# ?8 l% j& s
#define I(x, y, z) ((y) ^ ((x) | (~z)))
% y. X& e7 S j: \. j1 Z% R
8 \: O6 N0 {2 F1 w8 G6 {3 G/* ROTATE_LEFT rotates x left n bits. */ # G. e% E) |% `5 e- A
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
" Q9 n. ~$ V3 a1 P6 I$ p" ` q; d ! N6 }$ @2 O, |! ?7 c; L7 {0 O3 F) I
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ' t) f$ ?+ f9 N) ~( C9 o* f
Rotation is separate from addition to prevent recomputation. */
1 w6 F* e/ l8 x7 }2 d5 Z#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
$ U% x: F( N5 E4 {) [+ H& j#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } & ^9 u( r* r: ^ \
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" p6 Z d+ h, K* L+ K#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 O5 o" }" N# e J; N, K + W# Z: o5 }8 h, _! p0 S
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ - j2 e) @! k. _3 `7 R5 H) `, u% N
void MD5Init (context) . f# _6 S3 ~0 P. K" p6 \7 R" w' Y
MD5_CTX *context; /* context */ 6 ?* T# F P6 p! I$ Z. K, j2 a" `
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
$ g1 I. ^# R- G! l$ w% z*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
8 E9 W/ U! Z; u E}
H5 g, K0 v" d& A9 q( r( X O$ S
+ E" B& Y# D( ]9 k+ ^0 p* {) F o/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 5 Q% }* P: T: I
void MD5Update (context, input, inputLen)
s6 ]* }. `( ~; w" W7 H0 }MD5_CTX *context; /* context */
1 [: e- ^0 x; D% n5 iunsigned char *input; /* input block */ 9 M. T A$ T2 A" `% h
unsigned int inputLen; /* length of input block */
* M8 z7 x/ t, Z/ |1 c7 P{ unsigned int i, index, partLen; , U. w1 d) F$ D
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
0 c8 |; h @( D3 Y4 h( x /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|