|
|
#include "global.h" 5 {* P. r, j$ {5 a$ M: q% y
#include "md5.h"
! W" u1 a' w; M5 c 0 W4 \5 }5 k0 [. y" m7 M* L
/* Constants for MD5Transform routine. */ # C. j: t$ Q- i+ A( A) ^- d
% o" G4 U$ S1 J# S/ B. n1 j
% H9 m+ |0 f2 r2 o) m) l9 s# T9 P#define S11 7
3 D, o/ ?, }6 B, z4 x#define S12 12 / o; E% ]& ?* J# _$ v4 t6 F! ?3 e
#define S13 17 ! l4 Q2 L6 x& d8 D1 a' N" S
#define S14 22
9 c8 m6 Z+ n+ a# r#define S21 5
- \+ h5 O/ R4 a: b& J" b#define S22 9
9 N+ R1 o- P% {& D7 H7 z. R#define S23 14
* l+ |8 Z/ }7 z9 K- P5 Y: ^#define S24 20
% n9 j' p; x2 x#define S31 4
2 s6 O# H9 H; D7 b7 p$ C% [1 x& b#define S32 11
8 h2 }! P, q+ z, U8 H#define S33 16
& t+ E5 Q5 A) H* e& J#define S34 23 ; A; a: u( ~1 D
#define S41 6 7 Y" ^2 N+ N7 Y' i% w
#define S42 10
$ u! U* {. |$ m, n8 y#define S43 15 & M# ?4 O- N& `
#define S44 21
! V, v) L& z2 |3 {/ B* D7 D
7 \4 x) X" z$ W- X0 m$ X0 ostatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 5 _) C1 _/ m3 A. c
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
* |" K9 E/ ~' ?7 T3 rstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
( ]2 o5 v, X; B& Q. Tstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
( R. a/ U- l' y. C4 O6 Kstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
0 n$ I# s% K( s
4 f3 o* q/ [; p( K' I1 _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 : u6 c0 g/ `! F2 K+ C* s
}; ; P( f; ~; G$ Z6 a+ z
4 X( r& f5 Q$ U. Y
/* F, G, H and I are basic MD5 functions. */ 8 r7 }$ @: E; b& O r+ ^
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
9 t: y8 S! e6 B# @: B" B, @#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
" A; L1 z! \1 k( u) l#define H(x, y, z) ((x) ^ (y) ^ (z)) 4 }* R- {- C! @* `
#define I(x, y, z) ((y) ^ ((x) | (~z))) ; ~2 C1 O1 l! O# B: L- y
8 H7 }1 r6 z, |, t/* ROTATE_LEFT rotates x left n bits. */
8 p6 j+ L$ T1 J% Z" [- n! v: P#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 8 `3 Y, h0 ^/ c0 ~- m9 Q5 F
" Y% m8 R' x9 R: G9 a/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 0 g; U8 A$ _; R. V: m
Rotation is separate from addition to prevent recomputation. */ 4 C' p: V( M3 m; ?) N( K4 E
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 2 @5 F: b8 ?! I' c% |: `
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 5 p! s' C3 \4 q7 M6 I1 o
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
5 A+ W2 N6 c$ m1 u A' L#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 2 o+ F% R. [1 y
9 P1 T7 q7 A9 M' k5 r! F0 c- L/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ; A4 {% C8 z& u) d0 D* ]
void MD5Init (context)
$ ?* M3 j2 Q- z. rMD5_CTX *context; /* context */ " A9 c- ~9 {7 O. S7 D' d* `
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. - G7 w! D$ X$ [9 S
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
: n# z+ @$ v* B' b} ' Q7 [: L9 S! O9 X) O# \* |. r2 `
0 V; n/ f9 [" Q+ d5 H" D6 J/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
5 X( k, o7 w+ S! ~# e" bvoid MD5Update (context, input, inputLen) + y0 W1 b. _/ F; A4 c
MD5_CTX *context; /* context */ ' j' D; H" Y0 b6 E# Q5 B
unsigned char *input; /* input block */ C/ b1 t9 [+ d m
unsigned int inputLen; /* length of input block */ 0 x" S- r0 s; `/ P" x
{ unsigned int i, index, partLen; 2 ^0 j' F* M |+ q# O, ]" a
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
7 S# `: ~, t, _9 z b /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|