|
|
#include "global.h"
0 B7 Q4 r" e0 w5 N) a3 H% L#include "md5.h"
g9 S0 S5 Z8 I6 ~ . [. B. m$ @, I% _5 P, o" \' \$ w
/* Constants for MD5Transform routine. */
4 q1 ?0 C: w! i0 Q
% y; U+ M- U) G5 ~- z C+ h' e6 p' r- V3 w
#define S11 7 4 e+ d# G4 J8 B
#define S12 12
4 v1 k" d( v, K% ?. _' R4 I/ f#define S13 17 0 X }* S6 d; M! U$ r
#define S14 22
+ s3 u' f, K! T& |2 B3 P" I#define S21 5 ! y0 ~: ~2 c( b% I f- D% @
#define S22 9 - } [+ }. s0 A* _. T4 h
#define S23 14
$ p# K8 ^0 o; I; v0 k# | E5 t#define S24 20
- H! `; d/ M) r% a#define S31 4
8 i2 v" s( Q* `8 o#define S32 11
; G/ g8 ~5 p3 d) [; c! ]#define S33 16 3 e: E1 Z! G% k
#define S34 23 5 P3 b9 A5 s4 E: P9 N
#define S41 6 p/ W6 I# v- S: B- f4 L
#define S42 10 3 a6 u% V4 f4 p1 K- @, g1 r
#define S43 15
1 s' g6 B2 m# v0 ^1 a#define S44 21
# |1 z& p2 V! A% G
4 ~* r# d+ T+ e5 q- `+ e+ gstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 5 i) C2 z) d1 J0 l' `
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
/ i! }+ d4 T9 w! \" h" Z$ Istatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); % G, G$ d7 D+ d- g
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
) Z% E8 m" P: U Pstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
8 e$ b/ D. |' z# }
( C0 H7 L* h- Z3 O* d1 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
+ @5 s" n. F- R3 g. h}; * e3 a& q' H3 E( c
, @7 e I; P' t
/* F, G, H and I are basic MD5 functions. */ / S: T5 N, x* M0 x W
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
. n! t" t/ `8 j+ O+ M8 J$ ~) j6 B& C: f#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 6 q6 E1 r: z" ]( @/ a$ ^
#define H(x, y, z) ((x) ^ (y) ^ (z)) ! i: Q% B P; ?$ N4 E$ U, t
#define I(x, y, z) ((y) ^ ((x) | (~z)))
- ~8 `8 b/ m0 ^4 ^5 s5 ~& F
; k! j1 L% ~" p$ R' C/* ROTATE_LEFT rotates x left n bits. */ , g& e& U- | H2 x# ^% u0 |
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 7 j3 \5 r. ]4 _) i; y& @. ]+ g
- U& h! u) y; [8 i8 a. P
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
- C% x( n; n+ ^ H% }0 n5 hRotation is separate from addition to prevent recomputation. */ K6 e! w+ P, s2 _: Q2 V: x
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ; q* u8 T4 Q* a. ^6 y3 K
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
) O, W) P6 G+ H; M6 L. x#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
; D8 @3 L% F/ \4 Z. b3 S8 \/ T Z#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
' N! K9 L, w; \9 a" K ) h6 Y% B/ C% a1 _ Q" x
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
2 W. f, @( F7 y* C/ |, s9 _9 Uvoid MD5Init (context) % z4 ?8 O( l3 s( h0 x% q
MD5_CTX *context; /* context */
3 k- B3 E& X: q! ?" Q5 k4 C{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
6 g4 l4 d3 {, h& d8 g! m" d9 W*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
0 {) @% [9 m: j0 e& d* W}
8 b" L; P! Z: B0 V 5 J8 {6 R! j' p' z7 S, I+ N
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
$ y% Q- o. G! D8 ~7 ?void MD5Update (context, input, inputLen)
3 P" c3 D3 }% ]( ~6 X9 I& O/ d$ CMD5_CTX *context; /* context */
5 t ^9 ?" V- s1 E$ N/ h. m, sunsigned char *input; /* input block */
+ n' E4 o6 j# H ]unsigned int inputLen; /* length of input block */
% ~1 p! p; z" k+ }8 J{ unsigned int i, index, partLen;
" L8 y+ g2 F: I* C& I /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 6 H1 `% t9 B8 D
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|