|
|
#include "global.h"
9 n6 ]# _' D% G% S& v% t# H#include "md5.h"
% @2 F# i& g9 t& u) z6 E
( h0 Q5 ]4 r" @! s2 U/ J/* Constants for MD5Transform routine. */ 6 f. p) ?$ m, Q
8 S! }# E: \8 a9 x9 E6 n4 N# Q; c 6 F+ v! Y( a$ l: {0 s7 l) q% N3 A
#define S11 7
+ O! N. O/ f: c6 O; ?#define S12 12 + P( [2 C" ]* M4 C2 V0 O/ }
#define S13 17 % T; s" M- @5 }8 i0 u% ]& H
#define S14 22 ' V; J1 J# q7 V. L
#define S21 5 , e! ^% }8 U! I" N* A' g0 [' s
#define S22 9
1 F& j) I3 q4 U1 K#define S23 14 7 O% [! B' z! O J# d! c9 }
#define S24 20
B- A3 B( _2 C$ b#define S31 4
. u: }" [8 |& {#define S32 11 0 B, D/ Q& r8 n# e( S
#define S33 16
4 {7 t5 s- f2 Y7 T#define S34 23
0 ~' j! y: G; @. k$ a#define S41 6 3 X: V' K9 g# m7 T# }
#define S42 10
2 g0 O, m* ]4 U, Z#define S43 15 9 v J" e% H- r) p
#define S44 21 ' S9 {; W9 n, X3 \! k+ T
8 e% b: s/ p/ m# Bstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); , Q, I( Z; U- D
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 5 P- Z7 }8 T1 [, o s0 }& J
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 8 g$ c# w4 Y! J. s: y
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
2 O, s7 n7 j6 nstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
9 V- Y/ d7 A7 B/ y9 l# M % ^ S; ], }" G) y
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 $ L8 _7 ~; s/ L5 t6 i& w
};
- a* y+ T# _$ _; J
' V; K4 o Q3 n( V9 Q; F' D/* F, G, H and I are basic MD5 functions. */
6 S3 ]$ O" x+ h0 _; T#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
) A, U0 [" u6 k T9 H$ T#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
5 P. Q+ C( @( G T#define H(x, y, z) ((x) ^ (y) ^ (z))
) u) F( k" x2 F) R4 H3 m#define I(x, y, z) ((y) ^ ((x) | (~z))) , N4 E! b; ?) c6 q. E z3 w3 V5 P5 G
9 _/ v. `3 b, n5 G/* ROTATE_LEFT rotates x left n bits. */
6 o% J# E$ u4 _, o+ r#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
N; _! N# J8 F3 r; o z
5 z* I7 T5 m2 r2 J- u/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 9 w. e6 l& y% i# W
Rotation is separate from addition to prevent recomputation. */ " w: ?5 H" l7 Y' f' {% K- d3 `
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 H- ~! P- E0 b, W- M% ^
#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 q- a1 P+ b. C; `! 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); \ } 0 ?6 u8 [1 E' c8 R# a9 Y( 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); \ } % Y8 }" i1 [* {( n9 ~6 m" {
0 n# |$ _4 A, @& ]8 U( v6 t" ]: t. n P" e
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
- ]' q% T. w. t2 W" Q0 ^$ L Zvoid MD5Init (context) & _5 x7 |( u# b4 g3 t8 s) A) U Q
MD5_CTX *context; /* context */ . h9 I, {/ X4 J2 f% R
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 6 r2 g6 j! r i0 V
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
" \7 V8 ^: k( |* l! _6 r} t' W1 z2 p% A( C2 }) @
5 e3 Y9 N/ M' [) N& s$ L! E" B
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
! f r, K3 O9 y* m; wvoid MD5Update (context, input, inputLen)
$ P% `% K6 t" R( m, Q" MMD5_CTX *context; /* context */ & X, L/ {- D3 V5 d4 r( }
unsigned char *input; /* input block */
7 I `9 m% e C1 \' I, dunsigned int inputLen; /* length of input block */ 7 K. r0 f& J9 ~1 \+ q% R
{ unsigned int i, index, partLen; $ `6 n1 [1 t i$ R1 _& l
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ) A7 m0 P, M& }+ x
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|