|
|
#include "global.h" + y2 \& j3 d5 T8 L
#include "md5.h"
/ B! o. v! x6 c, |/ M$ n* Q % c0 r9 Z9 Z! n4 d l7 [+ G
/* Constants for MD5Transform routine. */ 5 _2 c b3 @( T) u) S
' n$ m9 y# z: m5 r; _) s: X4 J
0 E5 U; O+ I4 |/ G# Q6 ]#define S11 7 " q" J; Z3 K7 L* i& b
#define S12 12 & u- Q$ x; j* F2 }
#define S13 17
* [% c7 r8 A! l1 M! b2 @#define S14 22 ! k0 E$ F* t1 H; v+ L O3 ]
#define S21 5
2 C0 z0 P; b. s3 K8 @) c. j" l#define S22 9
, z6 d; y) s! X7 ^1 l+ r7 H! k' n#define S23 14 & I2 }# U, w) B) Q, D
#define S24 20 $ ~) L$ G0 c7 F/ J) |
#define S31 4 6 u. V* w0 a4 O6 E5 x
#define S32 11
* F- V" n9 F% N& m3 _#define S33 16
6 W0 B- h% Q& j3 S; X1 D; s#define S34 23
8 o+ O7 x n9 }* Q9 ~. x* W#define S41 6
+ ]/ ?7 h% M5 e# l& o. i# y#define S42 10 % O: S! X! _ O% n# d7 T
#define S43 15
3 k9 \" o1 a \, Z#define S44 21
# d1 ]) l2 k' v1 s0 C. }( C9 u1 Z 1 _9 J9 Q/ ] ~! ~- ]6 J# ?/ {. m
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 3 C9 ~9 e9 h: M& H0 |3 w
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
7 A0 y. W0 |) Ustatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ) x, ` I% f+ D1 j! d" g
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); $ w9 S+ V7 e) n; j
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
" I' b+ f$ A& X0 Z, a : @- G/ m; o' e+ A0 k' y( G# w8 i
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 9 e5 A9 @* [ y* q8 t# Z! Y; K; V
}; 3 ~ S2 b/ e1 ~4 C. c
6 S1 J; A; R! Y/ C# @% M; `
/* F, G, H and I are basic MD5 functions. */
0 c/ L0 x, E2 I; C1 ~( U#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) - {2 P2 K8 `3 d
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) . |% h2 Y8 H) R$ L/ o) v9 s! {
#define H(x, y, z) ((x) ^ (y) ^ (z)) y4 d$ R, G) n4 @
#define I(x, y, z) ((y) ^ ((x) | (~z)))
! Q4 t% a2 R! x& @0 g
8 [0 {5 s/ }4 \/ A, U/* ROTATE_LEFT rotates x left n bits. */ 8 r. d, d' A0 E# D" J$ r- t
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) $ a! ], `) N& N1 q z
5 q* I Z8 }( n4 B* z/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 4 {) B2 r1 _+ f+ W- J: b
Rotation is separate from addition to prevent recomputation. */
6 `9 x2 y1 d- z* L9 J#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ) c. r! C' m* G2 \
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
# s3 s& P! D1 G3 D#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 7 I# o0 n3 J$ N _- D7 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); \ } ' M8 ?9 l. w) v( G5 D
" S1 Z5 E% O8 o) v1 s/* MD5 initialization. Begins an MD5 operation, writing a new context. */ : O$ v+ ]& V* v/ j7 ]7 v$ P% o8 N/ \" s
void MD5Init (context)
8 m& i4 D& C/ G! BMD5_CTX *context; /* context */ n6 H$ |, Z) F9 p; M
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
' e& ?1 X- o0 L7 T4 T* T# B/ {& v*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; $ Q7 A0 Q9 W( ]/ G% e
} % f7 _8 Z1 ]9 K6 {/ K) g2 ^3 {- q
, ]2 H" I- F v9 Z! E8 r/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 4 J- n/ J$ k) ~1 f" h" n$ f! R* A
void MD5Update (context, input, inputLen)
) g1 L( _: T( K- B" ^! wMD5_CTX *context; /* context */ , ]9 U; o, V4 V2 X& g& t
unsigned char *input; /* input block */ # F, f3 e: Y! P0 }. n5 W# k7 |
unsigned int inputLen; /* length of input block */
; g: [* p6 ^) ^' }- d2 y{ unsigned int i, index, partLen; ; _7 k/ h# B7 N
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); $ }: `' e9 T' S' A' J; b+ y! k
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|