|
#include "global.h" 4 M$ G( `# B: u# \1 I/ @" h
#include "md5.h"
' \( E! M+ [ K3 {" l( i/ T ; K& @/ Z4 h9 P- ]8 B7 L0 i; r
/* Constants for MD5Transform routine. */
9 L! a$ | M" [. Y+ X
1 a' B- @% L) U
; V" m/ B! X" L. _) }% q#define S11 7
* {# ] [& H' t( J. S, }7 r: i#define S12 12 % Y6 m3 _ f. T8 \
#define S13 17
; ^, D( q" F/ b V$ s/ j#define S14 22 # x# w' B9 ^4 _5 z) K" Q2 y
#define S21 5
/ D7 A* I W$ ^1 Q: l# s+ A3 M#define S22 9
& r0 I! r/ ^) v+ t#define S23 14 # h8 m' m/ P& W0 w
#define S24 20 ! z) \. I1 y/ B
#define S31 4 : e# Q( c8 w& W& O
#define S32 11 3 x( Z: h8 s! J! Z" S
#define S33 16 / Z" A6 H' S# g+ y, l9 q$ }. \
#define S34 23
/ p' \+ j) K9 \1 _0 b0 ]& ?#define S41 6
* } @- Y9 ?5 n+ }#define S42 10
& k* ~; b5 s9 I1 B9 D#define S43 15
4 s; B) L2 Y: G- N#define S44 21
7 g& ]+ |$ n5 w5 X5 A
6 m+ a7 ~0 y+ b) astatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
6 d* a7 x; X2 p% ^' M6 O; ostatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); & m7 [* h/ F3 ?7 I
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
+ V" N9 j* e9 s& `- [1 Qstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); . ^5 Q, K( f; g. v/ z
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
" |- _! L$ t8 t- H: K! X$ ?
' @6 L* C" }, P p- V: lstatic 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 {4 C8 j) C2 J8 o( t}; & Z9 ?8 g- j* Z. B* K( P8 v
$ K2 r8 {+ L6 ]% U0 l
/* F, G, H and I are basic MD5 functions. */
9 r, M/ r6 ~* h' q: G! a#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) $ m/ Q9 E6 R$ V# ^8 Y
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) . ?5 H3 s5 M& f) @7 y/ {
#define H(x, y, z) ((x) ^ (y) ^ (z)) % H" U, n% e: [! V+ N9 A: ?# t
#define I(x, y, z) ((y) ^ ((x) | (~z))) , J7 O) a4 v$ O1 q
" z! m; X$ P' A
/* ROTATE_LEFT rotates x left n bits. */
! J& F0 l: n6 W% t+ w#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) " y6 Y% w6 }/ ?: I
3 N7 x! T3 [- k! \* h* m8 h( w/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
p+ P5 W) o/ N4 u$ uRotation is separate from addition to prevent recomputation. */
; }2 q2 |' T* } a#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 2 f; U9 f0 {: D/ d! d, u5 C
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
! }7 L3 g6 c% F+ \- T#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& U$ I6 ~! c5 {0 Q" h9 l#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
' ~: ~% [ L B! I / ?2 w) T6 H+ V3 L. a3 {* D H, ]
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ " L0 o- E X- w
void MD5Init (context)
, q0 G, I e+ J8 ?- P* ]9 FMD5_CTX *context; /* context */
) A) D+ n0 A# A% m" S7 L1 y4 y{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ; Y' V7 _: \/ c$ G7 q' H
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
2 r6 L+ P. U& l& L} + f7 m& E- k& H2 K& O* ~/ w
- D* s) ^8 D2 F; i0 Q
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
$ a. J: Z5 v- ]void MD5Update (context, input, inputLen) # s. l' U7 N2 h) P3 _' h5 a
MD5_CTX *context; /* context */
# |0 _) I6 u) z. r( R0 C( I, Punsigned char *input; /* input block */
$ w1 i1 y" V2 K: k8 ~, n0 I9 ?) U& iunsigned int inputLen; /* length of input block */
+ v# b9 q9 `* C* `$ { Y{ unsigned int i, index, partLen; & }5 U* v+ ~+ T+ t; c6 o
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
. L! R' ]7 z5 X2 ` /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|