|
|
#include "global.h" , x! O/ A0 v! W3 W7 U5 z' u @
#include "md5.h"
) m2 h; z K6 e4 y: _ 8 h3 g( K S5 M1 p
/* Constants for MD5Transform routine. */
4 \7 e. d! N5 t
# _+ |' b9 Z- f% Z 0 J: A3 L. V- `/ W4 X
#define S11 7 ( v, c7 \5 Q- Z3 ?+ E5 c
#define S12 12 ; x3 M/ v$ e, q+ j
#define S13 17
5 ]! ]+ z5 y% M2 t#define S14 22 0 X3 m2 y" a8 _! f! V4 n3 `* z0 o
#define S21 5
) F' b3 T2 }& @& }% p* R5 i( a( r#define S22 9
+ M9 @! X7 `1 x' [3 Z#define S23 14 ' S; Q/ N- {+ w" h, F0 ~
#define S24 20 x* d9 R9 T6 U# W# c
#define S31 4
: u. x) F* m/ n7 |1 j0 G#define S32 11
" {' f% r) o5 ?/ a( d$ }2 K#define S33 16 ' O7 g% W6 ]* t
#define S34 23
6 x; b$ S' z) j#define S41 6 : A- X2 [+ W9 ^/ e- {$ H0 K; e! z
#define S42 10
t6 S' d- L- U7 X1 j#define S43 15 ) a' I$ Q4 W) ^/ @( m
#define S44 21
/ K& W/ ?: o/ S( p6 |
" n. |/ ~9 {9 Y: W/ {% T0 Xstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); ) \6 S' j( O, }3 J5 M/ B. l4 L+ O* s
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); : O3 _2 a: m- w) `; Q4 a
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 1 Z4 N6 b' e0 [6 x
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
% v! F1 r1 [& s3 a2 Istatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); " I/ H# e% z; g0 F/ h
$ u, K2 L: e: n8 e
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 ( H& X: A: ]* P
}; 9 d" @& X' x* }9 r% |
& U# {+ l/ Y K- E; h2 x
/* F, G, H and I are basic MD5 functions. */
2 E( T9 l9 J# T0 p9 s; Z#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ( L Z$ N5 h W
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
9 u% I7 `' M4 D0 k0 l& J# e, H#define H(x, y, z) ((x) ^ (y) ^ (z))
& W4 c5 A8 `3 ^2 h. P#define I(x, y, z) ((y) ^ ((x) | (~z))) " n. q; m$ G# V$ ^# O
1 e) g) I6 j' f3 O' y% u( Y/* ROTATE_LEFT rotates x left n bits. */
; S0 x# v% b2 {! l7 D, j8 I#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 9 J; F% C1 J) p9 u- U" m
; _3 i$ y% t; D# u) X, r* e I/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
" R @9 Y$ z" _Rotation is separate from addition to prevent recomputation. */ 3 y) _/ r# F( l) x9 a- g) 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); \ } 1 j( a6 P7 P D4 z
#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 ] |6 t6 V1 r; U: Y3 A
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 4 T7 G0 I) ?% K. q1 C
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
, f7 l" G1 q% V% V 8 l, f ^7 y# o$ v: @
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ , }4 ~. f. j! _: [" p V+ C; e z
void MD5Init (context)
5 }/ g6 a9 z" GMD5_CTX *context; /* context */
1 _$ S% c7 L/ r* j{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
$ H* Q2 l7 b9 w5 V* ~5 q0 N*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
7 J- K; l B+ I6 @}
5 v2 t$ j8 z) x7 z# g% n
8 i: d. T: p. N/ b/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
% k; G: t0 J; D0 Ovoid MD5Update (context, input, inputLen)
4 k. W6 U* _$ _& X' wMD5_CTX *context; /* context */ # {1 [1 G& o4 a z+ @; p( C* }
unsigned char *input; /* input block */ ' j: ~/ J6 X! s9 K2 L$ K
unsigned int inputLen; /* length of input block */
x5 c% H {7 i% o/ p{ unsigned int i, index, partLen;
[: C B, h9 |* D, O2 [ /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
: b7 k# o3 o+ K# j' t /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|