|
|
#include "global.h"
9 f* u& W) C4 H: m4 r; M, N#include "md5.h" + S7 k1 J! u3 O* n$ B6 C
- \1 _3 g Q0 V6 {/ C
/* Constants for MD5Transform routine. */ 0 |) i" k% @3 W. W0 t! @9 \
$ ?5 ~3 \% ]5 y+ N G) n. I F8 G- g# g
#define S11 7
+ @( Q0 @5 M4 ]6 J- }, P7 r% |#define S12 12 * h6 d: \. Q. Z7 [
#define S13 17
& I; U/ s" k* k i7 ^: l" l#define S14 22 - W3 v- W+ s. v9 t) r
#define S21 5 : p0 B- m x; ]' K* \0 {6 B
#define S22 9
. q/ U/ ^, a: p#define S23 14
! ^' U' H: {; n$ e9 [#define S24 20
0 Q5 ], g: T0 ]2 f! O, b. {& Y" m- A#define S31 4
$ A5 d. d5 ~0 ~9 |0 S1 _& G" U#define S32 11 % d" s3 U7 W9 \/ Z/ w6 G
#define S33 16
9 [( I2 l/ ]/ c/ B+ \% U! z% G#define S34 23 & G; f0 _# z3 J$ V% k5 B' J; J
#define S41 6 8 I6 S* r4 V0 X- z/ p
#define S42 10
/ P2 ^: W D: c3 x# G# H#define S43 15
) |" y% P' V3 X1 S4 o#define S44 21
2 L$ h( B1 ~$ k2 C% |1 v $ l$ Y, _& j& v! e2 h
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); ) q( ~1 P) r% m+ w- r1 x! ^4 k5 R
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
& w4 s, L& l$ q- W' ?static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
5 v, E$ b% f6 r7 }7 o4 Nstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); F" ?0 B. {. y$ A: |0 x
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); $ `$ r' v! O! C
" G+ T! D f- @4 d7 \; ]% V6 W; O" Astatic 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 1 F6 P4 R: | E! f B
}; % v7 G3 s7 H3 x8 B. Y9 \
0 P. @. }' P b& f) {, U8 [/* F, G, H and I are basic MD5 functions. */
- o1 | b1 e3 F* g- D#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
. Q; y4 i2 S `8 `& y4 g* P#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 9 G, |) u+ g: k% h G
#define H(x, y, z) ((x) ^ (y) ^ (z)) * K$ J, r' p* K3 n- [3 r
#define I(x, y, z) ((y) ^ ((x) | (~z)))
2 \' _! ^ U+ f
# G8 P0 y) u; L% G; V- n/* ROTATE_LEFT rotates x left n bits. */ . S" j5 W9 t! V5 Z6 L6 U1 }3 p
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) & Z# ^% i: h6 W/ B6 L* @- H8 p
5 G# B1 y6 M+ D/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. # ?1 M* q2 ? D
Rotation is separate from addition to prevent recomputation. */ 8 }5 [. G/ v2 X+ P6 ? _
#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, c: i3 a8 q; r: e5 a D: C( 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); \ } # E4 C0 R m3 w: U% u
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" J: N" c. w' @) O& T#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 d. N5 K; P9 C9 q' u
+ o8 D- p; Z& `5 @1 |; n/* MD5 initialization. Begins an MD5 operation, writing a new context. */
: i& p Y" e0 x+ Yvoid MD5Init (context) / ]9 M# }1 ~1 T' n0 Z) ]5 o# l
MD5_CTX *context; /* context */ - R. b' I3 B8 L7 W" a
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. # ?7 Z5 Y, C# n" I1 L
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
; A" H3 ?3 e- X% V8 ~3 j) t} 0 [: [" X% L: o4 A: Y
3 P8 z, I. ^/ u. A/ C" Q9 f6 C0 V/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
6 d* k; w4 d% J8 S# Dvoid MD5Update (context, input, inputLen)
& H+ q6 I* k# X/ @; P9 `( M9 `MD5_CTX *context; /* context */
' m5 c2 q6 J3 Aunsigned char *input; /* input block */ # K8 H* j/ M7 p
unsigned int inputLen; /* length of input block */
; r. Z- l% ]0 y3 S{ unsigned int i, index, partLen;
: v& _+ H9 m) Q* F! a K' } /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
5 }. d& I5 ~; W" |6 W /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|