|
|
#include "global.h"
( D+ A N$ B3 Y6 Z/ q- }9 d& p#include "md5.h"
' F" y' z5 Z, k1 S( A5 F- o
+ b3 C: N8 o( n5 ], D2 v/* Constants for MD5Transform routine. */ , Z4 c: a3 u0 R" [, |4 v
& ?! ~2 k% c1 }
! c' [- c2 f' L( J#define S11 7
* Q; |# G$ h* M* t6 z0 |#define S12 12 6 v7 {) Y, j6 f9 y% X0 a
#define S13 17
' p, P( l7 e5 W; O0 ~1 J& d#define S14 22
! C6 [* h9 S* [+ W$ t#define S21 5
( {" C Y; d: n0 \+ p& n0 O" p& O#define S22 9
+ L1 ]# ?- U( u6 V' ~3 W& |. `#define S23 14 4 W8 s$ [# G! j; x( d- z, h/ z1 k
#define S24 20 0 n+ i9 \# F( u! R
#define S31 4
$ S% Z# o! z0 j1 J E* x#define S32 11
0 G3 Q6 s+ \" R#define S33 16
1 s* W N! i* d+ I- ~0 V#define S34 23
0 ]7 c3 K/ d# h/ ~$ [#define S41 6 ; m8 \8 C' d5 |0 {$ Y
#define S42 10 5 d+ F) F& t; i
#define S43 15
' y6 a2 d6 @. M#define S44 21 3 R6 U& h6 c0 I+ I% O% B/ x
6 K1 w! }7 T0 i9 {3 |9 L2 {- O& Pstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 5 H' ~& ^5 V3 }" Y
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
0 ^% \$ A) |2 ?9 ]$ @! P: Dstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
* B) W! N2 s9 `# \, I+ Bstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
8 e; J" c- J/ V8 }5 |static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
+ _0 t$ h8 [' G; z . S2 X1 x6 O* G0 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
+ e" K, ^. ^7 P8 u* Q% F0 l' B}; 3 H- _9 [7 ?7 H
8 [; N$ s |6 q u( B
/* F, G, H and I are basic MD5 functions. */
A$ K& l9 j, P. l8 e- @3 g#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
4 m2 { [$ _; I6 r' v#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
; j0 l/ i. A6 t7 x# H1 C: `2 J#define H(x, y, z) ((x) ^ (y) ^ (z)) + l. L. T6 b1 M( e2 J
#define I(x, y, z) ((y) ^ ((x) | (~z))) ; M; y( R& J; v6 h1 Z; P
. |6 V6 `; c; R5 L4 Y" N5 f) L/* ROTATE_LEFT rotates x left n bits. */ & T+ e; ?! q7 |) B# {3 q- |- t, L
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
" D7 N% C: z- {% e, q& B+ b5 t; ]
7 c0 {# _9 J4 g/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ( [7 J; _$ K; V3 a c6 U" G! j3 L: f Q
Rotation is separate from addition to prevent recomputation. */ " t8 U" }8 o: 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); \ }
% b$ R5 T0 R& z9 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); \ }
8 O( H& V( i- C) ^6 T1 j( a6 i* 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); \ } & e/ k7 a4 \' v5 x/ m w' W
#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 |0 p/ g' L4 W8 T' V
& P5 Z& L7 m c2 O1 s/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 0 k' f Z. h9 n& `' [% s
void MD5Init (context)
0 f, ?" ^; L: A/ A rMD5_CTX *context; /* context */ - ?7 M3 Y8 q5 k. c
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 8 x2 l) ^+ E. z" D
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
6 ^% |1 l5 Y: U. o, h/ j3 |4 j} / G4 }) j% s, c
5 I% v. S7 `) A
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
' l6 y% \% c3 h4 o2 X# R$ n: Mvoid MD5Update (context, input, inputLen)
( H% I9 u/ ?' p" @) c; _MD5_CTX *context; /* context */
: N' z3 N: F, n4 l# Y3 nunsigned char *input; /* input block */
, U5 m6 V' ^) G5 R3 X2 T! Lunsigned int inputLen; /* length of input block */
, s0 T$ m2 N1 J, |' D{ unsigned int i, index, partLen; ' W- E# `! R; @$ r* y; F
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
9 I, [+ q0 J1 ~! A. X- W/ Y /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|