|
|
#include "global.h"
2 x4 O7 k' v1 O) m' Z8 _#include "md5.h"
3 ]& {4 _5 `# v; W8 Q
( h0 h7 G Q, k% |/* Constants for MD5Transform routine. */ 7 t7 v- f, q5 u5 Q3 F
) n' d0 x& a; r
& [" E7 Y. ~" @ m#define S11 7
) \0 r$ }' k4 [1 j#define S12 12 . M2 h+ f$ t V w' [
#define S13 17
' r9 n$ {7 a" e' w#define S14 22
5 E2 [# r1 k1 O: H, Z#define S21 5
' v/ r1 O0 l5 P4 U/ c#define S22 9 * D9 Y: p4 Q& U) s
#define S23 14
* K# ^" D" e+ j. z2 B#define S24 20
# r" d9 `! K @, f. I! l1 C4 j, `#define S31 4 " q I$ ?) u i5 Y* X5 D; M) @
#define S32 11 7 H7 w! Z" m, W v7 Y* t r7 U
#define S33 16
( y! e( B- M# t9 `2 {/ @" @#define S34 23 7 m- U/ S- c+ w
#define S41 6 - C' p+ ? o+ ]" u5 w: D0 f
#define S42 10
% A8 u& q! I; J U#define S43 15 & ^0 z! Z; }0 G8 s
#define S44 21
) h6 m% q& f* r( I# j ' l1 r3 n; x, I- x0 _
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
5 V& @- P ^+ I9 e3 Y2 cstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); - ^$ w6 O0 w! Y( `+ y' p4 d& y
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
0 e3 ]. _- c6 F5 R. j% qstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
, z& Z! x1 j, Nstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
4 \- P5 w6 ~/ G8 e; `8 [' R' {
6 M9 U- A) P9 k' _# }: o% ~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
9 i8 p4 q( o. d! V# Q" f! x}; - c2 y$ Y2 [8 ^! `0 t% w* S
3 v! w! t- t& @- g$ a/* F, G, H and I are basic MD5 functions. */
9 _1 K/ m) C, W+ A: f#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 5 s6 U5 u! X0 C2 j, j, ^) |
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) # Y6 v8 @' j* m* h/ i. J, {0 R
#define H(x, y, z) ((x) ^ (y) ^ (z))
% E2 v- G; A/ S0 O% [; Q0 f& Z# H. h#define I(x, y, z) ((y) ^ ((x) | (~z)))
$ B* w5 B) Z3 e1 G3 a/ b* c C# C! E7 F3 q( Y- j9 y
/* ROTATE_LEFT rotates x left n bits. */ 9 Z6 k2 S' @" [) K! X6 B
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) + h/ Q/ X& [5 p1 ]" N3 j5 L; N1 m) Y
7 G: S( [; V8 M& S8 z/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ( p" E: i# a2 _6 _% B
Rotation is separate from addition to prevent recomputation. */
5 A& D& f8 S) i# B+ }6 }4 Y#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 6 q; ]. S* O* W- K
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
( z9 y, k0 j, D#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% }+ m3 _* \* z' ^0 F#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
' }) k1 N( B1 a; V" h 8 W( L" L9 g8 ]/ _4 f8 Z" A
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ; J) I0 }0 Q: j8 ? S- p
void MD5Init (context)
) c: B, h( A' X; P. d) q% bMD5_CTX *context; /* context */ 2 R' y4 X/ e( r9 |$ B) G2 \
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
c$ d6 Z4 F- m) v*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
' H6 s$ g# K3 D6 c) @" H3 m} : V* j1 \2 i+ v' T
! |* E) E, j" u, D/ P9 C
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 1 \7 D( B0 R7 j, O
void MD5Update (context, input, inputLen) : ~' y: x* q' I+ o% c* d9 B
MD5_CTX *context; /* context */ 9 U: I$ N- h; r7 p3 x5 F' T
unsigned char *input; /* input block */
2 h$ g1 X# N8 M, t; `5 e; Bunsigned int inputLen; /* length of input block */ {- b4 f; S% D- H0 e& I
{ unsigned int i, index, partLen;
5 G5 E( j% `; k% P /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); # N- e1 T6 N: B5 v2 ]0 M& w. B2 @; @
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|