|
|
#include "global.h" 6 G8 ?* U; U6 X# m w! X) ?3 q
#include "md5.h" ( \. x$ _1 r! K u$ O
3 ?" D4 |: k* N/* Constants for MD5Transform routine. */ % D2 c% n' N. k+ R8 a( T+ y
3 P G$ y- I. E( L2 O1 o1 g
! `' u2 K+ a3 h& w7 G V
#define S11 7
; W. r# J K0 B1 _' u) z* p6 h#define S12 12
' M( t$ }& h9 C#define S13 17
2 e9 O0 E) E( v4 {* |- g# D#define S14 22 8 t8 ?, A+ q. [. D* `
#define S21 5 : l/ r2 U' `8 A, F5 K
#define S22 9 . K$ O i( o+ U1 b7 ?2 M
#define S23 14 P2 {2 W S) _( l! r' S
#define S24 20 - |3 J' `2 j* E$ _
#define S31 4 4 m0 x% W, D& W+ u0 e; B+ Y P
#define S32 11
1 D- g1 s) a- F2 H) a/ x, A7 |#define S33 16
$ e; b# L. n) Y0 V' a$ D#define S34 23
% C: b7 I3 ]. j) ]#define S41 6 7 d# o1 n$ T4 L
#define S42 10 & m, |! p) V8 n2 K% y' z; @4 w" Z
#define S43 15 % ^, x9 H; T$ W# {. w& d9 l
#define S44 21 4 \; M+ v$ h$ p8 U8 K4 F! {: ?. q/ e
; Z- p& J; K- Y8 |6 T8 _# k$ t5 J6 r
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
' W+ O- g7 }+ w5 N: K' c ^' Nstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
# ^! X0 M2 A: v. h b( kstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); ) W( u) ]7 s& g0 c z
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); ' x9 L/ l) Y+ [% _
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 7 X" _# k8 V/ ]3 f/ a4 c4 S
# [0 @. D8 e( Y" Hstatic 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 1 X+ R, t$ T4 U; ^9 ~
};
1 ]( T8 v' J0 A f $ L6 h1 _; O7 r% |% }6 [8 l: w& J
/* F, G, H and I are basic MD5 functions. */
; S" G. p; y. t: y& T" C#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ) n7 ?; M( {8 G- m+ Y
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) & Y$ p* U) y( f+ i- ]" m
#define H(x, y, z) ((x) ^ (y) ^ (z)) / ]0 E/ G) ~& T# r7 X
#define I(x, y, z) ((y) ^ ((x) | (~z)))
: N+ k2 n% m+ L9 s7 R7 e& C
) v2 z; N: n/ q& b K/* ROTATE_LEFT rotates x left n bits. */
- n, r9 i/ E6 v2 M' A6 V#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 3 @. r7 b, ^, H+ E
$ g/ R0 t9 z. S, O8 k+ H4 G
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 5 Q5 _ g% }; \- Q2 y3 H
Rotation is separate from addition to prevent recomputation. */
0 l7 m8 j' v' H4 U" X#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 3 i9 z, O7 |" 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); \ }
6 |( K8 ^' m9 V#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } - ^) G7 h! a* m( f. i# }9 C6 f8 ?
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 7 ]! {3 d$ r; z. U! m2 s! Q
+ @% [ t/ v7 \( Y/* MD5 initialization. Begins an MD5 operation, writing a new context. */
1 K0 l# x; ~" e$ x/ `: o# yvoid MD5Init (context)
3 A% Q' f( u/ v6 WMD5_CTX *context; /* context */ , a" m& n: _% n' n8 O* S9 E6 |
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 3 r- i3 E$ C' L. C1 Z
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
% @0 p" @( G4 {# C( H$ ?8 s} 8 `3 S- D$ ?) [$ m. B. {
4 ]/ C2 w( P! m9 h& J
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ : z$ t% p7 ?* p( U& v7 h3 m
void MD5Update (context, input, inputLen)
4 D ], a/ |1 l9 N' S& J T" ?9 wMD5_CTX *context; /* context */
8 k0 i) D' ?4 funsigned char *input; /* input block */ 1 ]+ o" u5 n0 \6 ^& @7 X2 l
unsigned int inputLen; /* length of input block */ " ^* |9 [5 C) R& ^6 p
{ unsigned int i, index, partLen; * M0 D) v/ o3 n" C: }# G
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
- [ Z2 D1 |* ^9 g6 `2 }& } /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|