|
|
#include "global.h" " j* y8 N% v& d
#include "md5.h" . z6 e6 O( s0 X8 Z% T% b
+ B9 j& ~3 r! l+ H% S" T" e/* Constants for MD5Transform routine. */
( P, \2 O/ F M% L2 k" Q 0 X+ x _: D: J0 d8 V3 z
5 V2 s2 O( l: j8 K#define S11 7
) t$ B* \# v* g( K) _#define S12 12 $ N/ ^" e4 p- V' R3 @4 M6 S
#define S13 17
8 z# A/ r9 l" c" ~( W#define S14 22
* Q1 H1 d: K- R" T$ a#define S21 5
- d& ^! b E# _0 J$ m#define S22 9
# Y9 {7 }5 t2 @ |+ M* o! \' M#define S23 14
$ F* _+ A( \- \% e) m" c1 I#define S24 20 0 B8 _6 ^; c$ _. n* ?6 ^
#define S31 4 4 Z& P y5 U8 u5 e. U
#define S32 11 ; S; h% k$ S% U/ q, `0 Y2 A
#define S33 16
3 Q6 C4 j- \8 x1 S+ O#define S34 23
# p* n& k& Z, v#define S41 6 3 q+ t% k m' v* h8 l1 _) ]
#define S42 10
( c" t8 O: _3 |$ z#define S43 15
5 e8 f" o: X t8 N. q: g#define S44 21 - Q7 R8 i G+ }, u5 P8 s
8 _% J- q5 T9 m8 O6 xstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); " v3 v* {: w- N! t1 v- @ N) I0 x
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ( W5 s. J/ s/ h8 V
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
- z8 q# }/ q/ f# Cstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); # r/ z3 W& L: _
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
+ Y( m9 }* K8 a# |2 _+ z # U! V% l. r8 y( i/ c0 N+ }
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
' l7 ^' s' p4 k; a* T1 @};
( y& Q/ D1 a, Z5 c6 E" X1 z& _3 W7 _. ? O
9 w2 G2 q" P$ I V/* F, G, H and I are basic MD5 functions. */ / D; T: w. K6 J3 S! E
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) - d8 t; A* }& z* Y% G
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
1 m+ j( P7 w$ b7 M% w* s+ c$ ~7 U#define H(x, y, z) ((x) ^ (y) ^ (z))
" k+ z( `* B, r k8 E& [#define I(x, y, z) ((y) ^ ((x) | (~z))) : j: V* ~* f0 e" A
( d$ G7 R; }9 n2 L8 E/* ROTATE_LEFT rotates x left n bits. */
: r& `! v& J' p5 }0 i+ V#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) : j: P5 G& K2 P9 c9 J. i$ f$ e0 u
$ S9 [. R0 u# y9 Z
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
. s% E/ S+ E' S" P1 Q5 }Rotation is separate from addition to prevent recomputation. */
6 T- W+ \7 t/ Y/ P' K8 m/ [5 q#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
. G/ z' _9 ?) A& r. E# \4 ~#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 x2 o) g- p& p8 X* u2 f2 |
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ?; h. |, d: N' O: O# l+ c( }0 p& K# V
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
6 W) B) {7 X: j9 U1 V 2 L7 @7 U& v1 w% _5 A4 k
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 2 O ?. F Y' \$ P
void MD5Init (context) - h7 w$ h: ]4 U5 c# ~
MD5_CTX *context; /* context */
7 ~1 \& }2 B" ]7 c7 e{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. + C3 E& X3 T8 \3 K; ~
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
9 c' M6 m, K6 U6 G4 ^( ?! y} 5 A9 ], T( V! ~- C0 I' ~
8 F, M" {# G I; I4 t8 i/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
b+ U" r* \& {9 \8 `5 e& wvoid MD5Update (context, input, inputLen) ' I j9 b2 w: j0 ]( K
MD5_CTX *context; /* context */
; g3 }6 T* C7 ~! Eunsigned char *input; /* input block */
L, M: I8 c( T( }& Tunsigned int inputLen; /* length of input block */
8 c- x1 s# N3 E7 ^{ unsigned int i, index, partLen;
- B9 C1 Y \+ \9 y+ G8 ^ /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
( g# `2 E- m( g4 z0 p /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|