|
|
#include "global.h" . }9 K- O; I5 B1 a
#include "md5.h" . A/ G% q5 l: ?! R: j
y" w7 z9 c8 e/* Constants for MD5Transform routine. */ ! C( b' J7 F# l
) L" {& G% u; W, e! y
. U6 U+ I$ A& A9 h$ d#define S11 7
3 i) `6 U* X& Z; d; n+ f: \#define S12 12 % ^/ u1 q! x: z
#define S13 17 ( e* ^5 S( A! P. k' u7 ~( P) T
#define S14 22 , b/ `- J8 k& F7 Z+ f0 S
#define S21 5 : M* i) C- Z/ _- @
#define S22 9
' C2 z1 ?* z% l" ^#define S23 14
) V, s9 A( S; X! w! L#define S24 20 # q- r7 D- j/ V1 N( V# s9 ]
#define S31 4
$ v& a2 Q/ c7 Z& g#define S32 11 * u( y! c/ z: W7 a; A* U# E
#define S33 16
' \2 V+ c5 D% I- t#define S34 23
: v% e- D; ]$ V Z* L6 Z& U#define S41 6 0 I: r2 A* L$ A" z
#define S42 10 & [" D) `4 \& `$ Y1 |8 \
#define S43 15
: O( y+ t7 H R" [; F2 t# B. m#define S44 21
$ a' o( i# p8 N) m( t/ u
* a( @9 W2 E R# R0 K+ H- I% Tstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
0 v% u' A i1 H4 W# U" t s; ?6 zstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
2 }1 h9 f1 f( B6 Hstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 2 a$ M# Q- Y0 _
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
) |* J3 l0 O* d8 P H" E5 ~static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); # g o% o+ N7 `3 n, I# d
4 J9 e: F& u$ P3 B1 Y J% [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
, a3 {- Q7 k8 `! b}; 3 d+ V. e' o" d0 |! s
* {9 m: c' e2 P2 o8 g/* F, G, H and I are basic MD5 functions. */
$ |6 u5 d6 X' ?3 X# d4 m" S#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
9 p6 T+ @1 q) Z* V+ S#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
5 q8 ?5 k+ e) ~! `' b#define H(x, y, z) ((x) ^ (y) ^ (z)) ' X7 b/ X3 u8 {1 p- a7 K
#define I(x, y, z) ((y) ^ ((x) | (~z))) / }4 T; A' K2 R6 `' m' s9 Q7 s5 Q
8 l% B9 y2 N( E: H* b, M) ?" n/* ROTATE_LEFT rotates x left n bits. */
# G J: I0 C: u2 J2 _% r5 e#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
- d2 n7 E6 u# F( a9 ~) k- F
. F' n; J- C; d7 F: I7 m* `/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 4 y3 B. V# o- f7 G
Rotation is separate from addition to prevent recomputation. */
1 Q2 e: S+ J: S. B: ]#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" z- }7 ^2 H9 J#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
4 z4 o( a4 M3 J# V7 I+ H) p9 L; l l& I/ ]#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 N& V$ v' i" ^7 I. W#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } $ B4 |5 G8 V' m. c& A4 T
! A; m, u( L* F) d0 z/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ; M3 Z: C) C: n# O; G9 Y
void MD5Init (context)
3 |- A" v, X9 B, l( Z0 v4 fMD5_CTX *context; /* context */ ; Z0 a: Z- T8 w% X4 ]
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
6 v" F. r+ `6 f( B) a5 O; G' [*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; * {& }7 g# C$ _3 B
} 6 v' E" S2 _4 [' j7 G
+ `% \: s3 y% L9 S) e, R/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ # }$ J& C: x4 H1 [7 g! m: {1 _
void MD5Update (context, input, inputLen) + A) r: S& B# n# W" j z) w
MD5_CTX *context; /* context */ " z4 |/ ^, h9 n: ~% c
unsigned char *input; /* input block */
) z% Q8 J/ F. `4 E5 F- Dunsigned int inputLen; /* length of input block */
% b* k$ o. L" J3 \9 @% b/ y" q1 g{ unsigned int i, index, partLen; . |) [( `& S+ ^& d' j' a
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); " z6 x2 H! O! t. G
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|