|
|
#include "global.h" $ i1 K* l3 Y5 M* S
#include "md5.h"
6 T D2 {" p8 U 0 V* r% H4 f U+ J$ x
/* Constants for MD5Transform routine. */
1 k* ~: e5 _& p5 w . ] y( R8 y* \- v' y
/ z1 @9 u0 _0 H7 v% Q3 `& @# q
#define S11 7 : K: d1 }. e4 y1 Q* |/ T) ?
#define S12 12
7 d0 s3 E3 X2 w8 F- {+ { `7 `#define S13 17 ( j: n) F- u& _ ~0 E9 V/ R
#define S14 22
1 M4 I) y* ^( \1 i/ F#define S21 5
s% D" f* Q2 D( ^# Y F#define S22 9
3 a3 Y& `2 U3 k, M6 `1 P#define S23 14
% m' D$ D+ g5 }- k. C6 t#define S24 20
0 k' [6 v$ v) D#define S31 4 9 d5 i$ r% o, V
#define S32 11 7 Z1 i4 X$ M! G1 F( ~* {; h% r
#define S33 16 & o8 ^$ U$ I$ t. \
#define S34 23 ! t) e7 V- |1 w! E3 M- G
#define S41 6
7 S8 p. d; {2 Y( R/ G! y; q#define S42 10 ) f4 t) H" U6 M7 s5 l; |
#define S43 15 9 e/ x9 O, a# A
#define S44 21
0 j- X7 b2 @% E7 m
* H$ t5 F& L8 F0 |9 u- ^5 jstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 2 A5 j# F/ @4 b# W% \) y
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); % X! s- ~3 c5 {6 C( E7 f6 Q* G" M
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
9 Z! G- K, u+ e6 R* zstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); W/ f$ ?0 ]" C& }; [$ F
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
! j. G; l5 c7 Z3 `6 ? + k6 u/ K# m V* p
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 # K7 n! |# S; ?2 A5 U% y
};
5 n4 Z" d( A0 @' s3 b1 u# N 1 S7 g5 ~8 b; K- O& |
/* F, G, H and I are basic MD5 functions. */
/ |) f3 U$ M7 X! F#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
* f1 {2 A* O1 H2 b1 I0 N#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) ; e, y" U8 [6 \& Q2 n. ^- u
#define H(x, y, z) ((x) ^ (y) ^ (z)) , ^* y# P% ?9 U; Q6 Z3 y. M
#define I(x, y, z) ((y) ^ ((x) | (~z))) " _, k% k* X% |: j$ E
5 W6 o; \. S( a# e
/* ROTATE_LEFT rotates x left n bits. */
# {" [5 K1 |# a- L$ y#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
' v7 H) x% _6 J% {
( C. w- q4 e5 @* w! F/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 8 ~1 R3 o9 Y* s" G0 ?
Rotation is separate from addition to prevent recomputation. */
& b% s t: d& m/ 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); \ } ( m/ V/ n* X- L1 ?
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } , [2 x3 j2 k. R" M) ^/ {* \) s
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
2 b4 q4 y0 ]2 L% j, f6 J8 i9 c#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' K) Y6 X; r2 v3 w1 R + u8 u' p8 X; \3 z2 `* o7 I
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
* K" i1 d4 J% uvoid MD5Init (context) 2 i) W: U( A+ b0 c
MD5_CTX *context; /* context */
1 D c% U* W2 o% Q{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ; y: y1 P6 R, k+ \
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 4 k) v; x8 T, f4 N9 Y# @9 l; Z2 W
}
8 Z8 T/ X1 C( ~6 R! N 1 E% X' _/ R. W$ Y
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
' M& r5 o6 T; ?! ~ Q' I. N6 Nvoid MD5Update (context, input, inputLen)
5 D$ Y3 U; ^0 JMD5_CTX *context; /* context */
6 c7 a4 B' ^ o* Ounsigned char *input; /* input block */ 7 k3 g% R! Q% J' B K& w) A% z0 p% m
unsigned int inputLen; /* length of input block */
2 g1 \+ v7 c* z/ T: V/ c$ w" a{ unsigned int i, index, partLen; # ~6 p$ c1 _' m2 i" M) k' P
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 2 l6 J# p% h8 W* x7 U7 a: g
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|