|
|
#include "global.h"
- s3 V6 R/ ^: N4 T: n6 L#include "md5.h"
' _4 m" A4 X8 j' B2 m4 t k
$ D. v5 h, A( o6 `- _$ Y, s/* Constants for MD5Transform routine. */
3 Z$ w0 R! z, c
$ m; Z4 e! [9 ~# ]
' s! K( h6 x* ` K/ L h8 s2 U#define S11 7 ; x/ M* ?" Q% _! [0 d( @ m
#define S12 12 , f- W0 b% |" T
#define S13 17 ! U% M8 g" k( f" y- s4 M
#define S14 22
6 J- ^( e: ^0 X6 Q7 R" P; Q% g2 Y. F#define S21 5 . B* N6 ?; f; m( ~5 N% l
#define S22 9
& H9 B/ w N. H) i' J#define S23 14 ; i7 R% h, Z" X" b! I& }; D
#define S24 20 8 Z( B* F7 w' A% u, h1 Y
#define S31 4
/ s: m% \# q, b+ O0 @4 m#define S32 11
2 S& S0 y. _: f8 A" q7 v8 `7 i4 I#define S33 16
2 L' }1 L" I' d$ ~- j& {#define S34 23
7 b- X5 \1 b. t d) c#define S41 6
% X4 o0 l, t c#define S42 10 7 N: u6 e5 s3 f
#define S43 15 3 x7 j. m9 Z! X$ |
#define S44 21
! W" y; a5 s6 W$ | }0 \4 X4 R2 S 2 i# f! C, G# D* B& q# X
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); $ R' ? E) i& v2 W0 ]
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 7 f5 Q, U3 R; u# z
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
0 j& t3 J; P+ j q5 D5 istatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); % z3 _- K5 G$ B6 ]7 D2 h
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
0 N) `- s0 c! v- i/ \6 u$ ^2 I
: n% q8 K) j" v6 _( fstatic 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. T5 j* V7 N8 M5 a
};
1 @9 n0 c* G5 \4 {
8 X% y; t y5 T' r! e, l/* F, G, H and I are basic MD5 functions. */ - A/ e8 H3 m3 s4 X6 F$ W
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
7 M/ c6 Z1 R" j3 K4 W6 @#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
; v$ h; s) W! p [% K1 L#define H(x, y, z) ((x) ^ (y) ^ (z))
8 o8 X; Q2 ~- S, l$ U6 c- H#define I(x, y, z) ((y) ^ ((x) | (~z)))
: n* l; q( @9 q8 P6 l& ]% h" N
2 G+ v }$ ]1 E, I, r1 E1 r/ L1 b/* ROTATE_LEFT rotates x left n bits. */ , H2 ]' d5 }1 K
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ' h7 Z8 k7 Q) y4 I( ^0 n7 P
, O0 _* a; A4 E2 O
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. $ o% H% u* \6 t ]0 }& ?5 _) V4 H9 X
Rotation is separate from addition to prevent recomputation. */ ! a- M- s) x0 B5 } T% P
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 ]) Z4 {7 y; B. Q& I) l8 J# P3 A#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 0 K) b2 v' _5 a$ c1 f
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } # [( }: l8 b8 S S' y; A0 j
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } L/ U3 h6 E2 N: x
" O: q. O! {& h$ {- p3 A0 x1 ]! L
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
, z; G5 e9 \6 S6 `+ ^# L% ]! t" rvoid MD5Init (context) ) \$ X$ i9 ^8 _! k2 k/ R
MD5_CTX *context; /* context */
8 T% r' p' X( x) N8 I{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. & N2 |9 p- F( q* ?% k4 q
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
- r, u/ L' X) ~. e}
4 i$ a6 \9 t% U, n( K9 r$ r
5 d9 J# I9 F; T( m) r/ J/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ * ?$ Z2 S" }- q# B
void MD5Update (context, input, inputLen) , f. x6 w- r3 ~2 {
MD5_CTX *context; /* context */ . H# P3 m; p" t8 i7 l' Y
unsigned char *input; /* input block */ 1 ?; ?# `0 y9 {% n2 B8 K
unsigned int inputLen; /* length of input block */ % x6 c$ p. ^" k# `
{ unsigned int i, index, partLen;
7 a; A4 U2 r) [9 ]% Z ?% f6 |' _ /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ; p7 {, y( q# s" H
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|