|
|
#include "global.h"
8 v W% f" J% O9 r! w' J#include "md5.h" 5 Y3 J: |7 C* I& z
8 i: v% }+ A( e5 L0 i8 D s4 h/* Constants for MD5Transform routine. */
6 A1 H2 ^8 `7 {( _& f1 I( u $ x j, h$ a& D8 i
/ G( ~3 I# O* T2 \$ C# q7 E
#define S11 7 1 J6 \; h% z- V3 d
#define S12 12 % s7 C* T! [: P* j5 |2 A- ^
#define S13 17 ! O6 v" v2 X& A! Z' B
#define S14 22
" V1 \6 K4 K2 c% Q% V#define S21 5
- n1 O$ ]3 Y: w' h0 f#define S22 9 ' v8 u. y, R$ C
#define S23 14
, h7 c, M$ _- ~+ s3 h* ]#define S24 20 # C, g: A- Q4 H3 |+ r* w* O2 w+ q
#define S31 4 ' ^8 f, `* |7 O8 V
#define S32 11
& y2 E Z* o+ A1 y% }5 j @#define S33 16 5 v9 t7 f; B3 T4 D8 N0 K# c
#define S34 23
" @, ]( R4 |0 x3 i l0 n#define S41 6 $ P& @% p) K* ~
#define S42 10
( p! Q: U4 Q/ s& }#define S43 15
' b% M; O" l( ^3 J& B#define S44 21 - [ _2 i1 M; U. M' Z0 Q- B) t
; J& f- m1 O* N1 xstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); " _; v. o* `* J9 l
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
! c' m8 K7 A' E" U, Cstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ( E6 L: R5 {# ^! I6 R
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
) c& C/ u7 b. v0 l% astatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
2 W" m) |% u: C
! g6 y" S! O- V9 G' Q% [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 - J5 k# [# Q0 Q$ `
};
3 ]: s y& ~. u6 q
, e0 D) O9 R R& X4 E/* F, G, H and I are basic MD5 functions. */ 1 E0 s4 N' B6 @. q J1 ^
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
7 |% ?% R; F5 y K#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) " f/ R- a& Q! `; o8 `
#define H(x, y, z) ((x) ^ (y) ^ (z))
" v8 l6 r3 U/ O$ P/ q. m#define I(x, y, z) ((y) ^ ((x) | (~z)))
1 j$ @* a# u7 S' K
/ z% M3 x) ?2 P: ^4 z, N/* ROTATE_LEFT rotates x left n bits. */
, H- i8 n( x. ]7 s#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
9 A) b1 ~2 f" x# u " M" o% U; j1 U/ }6 z6 ?
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. , B" r. P+ A% B) B6 q x+ m7 |
Rotation is separate from addition to prevent recomputation. */ 5 U( T# Q( a' q2 X: P0 G1 K- l
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ) B7 d& u( l2 C _& o
#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 b- A# x' e# m
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 X( U+ x5 E/ N# m: u
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 0 W O8 T# S5 O
2 q& T6 G5 m) j& M+ A7 v5 h/ Y
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
& k# F5 V8 L; O$ T5 }void MD5Init (context)
1 f+ [/ J3 B' {MD5_CTX *context; /* context */
2 S- u. j7 X* c3 F( I% D{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
3 h2 Y7 Z$ t8 H. @6 A B*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
) Z+ l" O! r: R5 B9 w$ {}
5 z. d/ Q3 T" d. r: H& L/ m
3 D0 x- J0 G! j3 X; D3 [2 M% J: d/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ , z; m4 s# s. I3 N4 T6 |9 d9 _
void MD5Update (context, input, inputLen)
/ N5 ]' O/ T7 D8 hMD5_CTX *context; /* context */
! z, L. |/ c9 @unsigned char *input; /* input block */ 5 V0 ^5 Z+ N: o2 Q$ ]& j8 Q
unsigned int inputLen; /* length of input block */ , j6 N. e, g' N7 C2 ~/ `! \ k
{ unsigned int i, index, partLen;
! i5 j6 Q& H/ j0 s1 q9 j3 n /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
" I) f' E3 A: d9 b8 y7 k /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|