|
|
#include "global.h" . \0 o. q0 d/ \- x. \
#include "md5.h"
0 ?% c$ ~, D2 _; ?+ p
; s, T" y$ e z6 X3 {/* Constants for MD5Transform routine. */ 5 R5 ] w$ b+ p3 c# D: y
) l* |' d$ j8 o1 V) \$ W
) F, \1 Z4 v9 D! j' ]#define S11 7
% J7 V1 t8 \; L2 Q#define S12 12 0 m7 a. O2 z# Z) g! e
#define S13 17 1 c$ S2 s) S. {& @. K% q
#define S14 22
. b: n5 S3 |2 ]; {; X" l- C$ m/ }#define S21 5
j5 q4 m1 N: ~/ d, W#define S22 9 ' h; U' A' J9 r5 G6 g/ ~& \
#define S23 14 # s9 `0 l5 }; R+ u9 O
#define S24 20 ; |! W- U u1 v3 o) y
#define S31 4 8 p8 j: P$ l2 J* |" `& L
#define S32 11 / x, [$ K/ I& P2 @$ i2 F* ~+ }
#define S33 16 2 i2 c! \9 @& K. p- z
#define S34 23
+ U( g. U6 s' N7 J#define S41 6
( r7 i5 K; a9 J0 Y- X5 W: ~$ g6 Z#define S42 10
$ V a; k4 @- H$ Q3 Q' z+ G# O#define S43 15
0 F; L! [( x1 d, z, e#define S44 21
y3 [4 E/ A2 W7 k; q! d0 H* r$ p T: O2 c( _" `9 m& z
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 8 o8 p' H9 j) v
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 8 v8 C; i! w7 l3 F. `
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
" Y4 ?; h4 @) f) r3 n* w, Dstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); / S) `; d J i- Y/ D
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
; e0 n( U% p: U) b . v) H* u4 R9 Q: r8 C" C# u3 L
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 " y. t" g) c5 `$ {
};
. V9 R% D7 W+ I! d 2 Q) f5 ^- @+ W4 y: l
/* F, G, H and I are basic MD5 functions. */ 7 b+ D7 v5 L2 Z. ?9 b2 E9 f
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
- D: s) u6 B/ T+ g6 q& F) U#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) . u! S; ~, s4 ^3 d5 Q: V# H( | B
#define H(x, y, z) ((x) ^ (y) ^ (z)) 6 c5 q: B/ k* r2 B0 z
#define I(x, y, z) ((y) ^ ((x) | (~z)))
" w$ G+ n- L" r- K) l V: s ( k1 c; H6 g9 c: [ [' ?# P7 N
/* ROTATE_LEFT rotates x left n bits. */ 5 K6 ?9 d! f6 d) m: P, N& }
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) $ q1 P2 o+ g# x$ X
% w7 Z4 [) h* N. Z2 e
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
& s/ L/ l3 {& ]( t [Rotation is separate from addition to prevent recomputation. */
9 @6 h) M3 d6 s$ B* h0 _#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$ V+ v0 x, A: X7 v#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
$ Q( n" }1 H1 a. Z+ f#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
- V$ _( |, u) @3 Z3 v7 M#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } # f- c1 O' _4 O- j8 E$ a3 I2 l/ r
" k8 M+ Z4 G3 ~9 m
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ) Z. }+ R8 i/ d# R% w
void MD5Init (context)
8 Q- T6 V4 C$ F( c( vMD5_CTX *context; /* context */
5 Q& D% {5 H, [; t+ C& `{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
9 H1 {6 B; p/ B5 F: V& z*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 0 f! V, {, [- K6 u" ~9 j" P; I& L
} 1 F. z" W8 K# ]
6 z3 U* y+ w5 F) `7 r2 ]; [
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
+ n \+ p* i7 @ ]( A/ P- W$ Yvoid MD5Update (context, input, inputLen)
1 F# B4 B8 d: DMD5_CTX *context; /* context */
9 b+ R' S3 `+ G" vunsigned char *input; /* input block */ / d, C8 x/ H( d6 |' R, h/ n# R
unsigned int inputLen; /* length of input block */
7 i, c1 W; _$ M+ X% @( K. ^{ unsigned int i, index, partLen;
3 ?( H+ S! e7 I6 z, ^ /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 6 \* f' u; J# }0 x/ j1 t
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|