|
|
#include "global.h"
9 ]7 G# k0 } M0 |0 t4 E; p' y#include "md5.h"
& t9 k/ T. }$ q+ u3 r5 R% s 7 C" C/ p$ b8 R& X4 v0 V7 R
/* Constants for MD5Transform routine. */ ! U3 f" Y4 _1 v" _: ~4 I, y
5 _8 F5 B! l8 F
! T. V! ]5 E* V0 v% V( ^#define S11 7 . y6 g4 @% I3 L; w- i0 |% d5 A" U, Y( \
#define S12 12 # U5 Y# u/ Z( U# ~ g4 r
#define S13 17 * _: d% D* d; c" _* L1 Y. E& D4 @
#define S14 22 4 X' d, k% I9 B! N; S, \
#define S21 5
4 W/ I9 A% v0 t0 c! X#define S22 9
Q! b! k/ R4 P#define S23 14 " ~1 e1 h2 N0 I9 N
#define S24 20
. y& j _6 j! [( t3 k0 B1 {* B#define S31 4 8 k) h/ {9 @, S+ ^2 B
#define S32 11 % Z# C) m( ^$ ^8 X, K0 @6 M; t! c
#define S33 16 * D& D8 U2 y3 T5 S# X5 D
#define S34 23
9 S* p4 O. A+ x$ v$ c7 v) C#define S41 6
8 @$ `3 {: x( B+ Z3 t: m5 A9 }#define S42 10 2 a# F/ B4 R2 Z u6 Z4 v: n
#define S43 15
' Y) A) g8 Y/ J0 l6 `6 O+ c8 ?#define S44 21 2 \9 ?6 u. M% N6 K6 J
' j- E* n6 C/ t" B5 B5 L
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
* o8 _+ x/ W, I8 U$ ~ c. X- H2 y- estatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 6 t; l3 Y6 m N% w, P+ e
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); - \/ {. q& u$ v- V3 \" \3 Z! ?
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
3 `/ C, ^8 T4 v3 Fstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 2 s/ ]) B) x6 ^" O& O
# N ^, W" R) \. E7 f
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
4 M! v: y+ h4 P};
3 C( r0 }# J H4 C7 U( l 9 S3 P9 ]0 _0 f
/* F, G, H and I are basic MD5 functions. */ 1 b' D5 `3 B/ ~3 e$ y
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ) K" h1 S3 x! ~/ k8 y8 x' {+ O
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
3 e4 o' c& r1 M# f, {#define H(x, y, z) ((x) ^ (y) ^ (z)) ) L) Q( ]+ N+ h9 m8 s1 w, E
#define I(x, y, z) ((y) ^ ((x) | (~z)))
! {9 y( Q, o2 n3 ? $ Z% k5 l! J; q' L" ~1 e' G6 I
/* ROTATE_LEFT rotates x left n bits. */
5 k- |8 p h* s#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 8 Z, y. P. m8 s# p
0 u2 i6 n b; t3 G( D1 h! K" z
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
! g u' \* q- k, ?/ F6 bRotation is separate from addition to prevent recomputation. */ 6 ]: m8 ~2 [6 W. i
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 N4 Y) |" z7 G3 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); \ } 9 @% B8 l ~. p/ u
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 \. Z5 E" @# R2 x5 j9 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); \ }
, e) h# C( {& G$ f7 c
+ N' J X/ o' ]7 {/ M# H: X/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 9 u- G, s3 z+ x, {( Z) q
void MD5Init (context) 7 J e4 t3 y; L; F6 @
MD5_CTX *context; /* context */
3 M5 @/ z7 R+ t, H. m( c7 }{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 0 c" [) i; b! U. X
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 5 Y, o$ I) s0 X" T4 D
}
* V; c0 i6 h: S4 ?$ l% r3 w$ Y& F
3 L, n @$ N7 n/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
- k" s6 b+ n2 ~0 @void MD5Update (context, input, inputLen) # n4 @9 n# \1 y
MD5_CTX *context; /* context */
" M4 ~# t- r& c7 q1 h# a1 t. M) P2 h ~unsigned char *input; /* input block */ 2 q1 F# ~2 u: G7 N; Y
unsigned int inputLen; /* length of input block */ 4 w3 S. `# F+ \ ]! J2 {
{ unsigned int i, index, partLen;
4 o% \6 h7 K) b+ ^9 i3 C( O /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
* Z! T" x/ J* `1 [4 C /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|