|
|
#include "global.h" ( T* ]& w9 D# @
#include "md5.h" * s' W. e0 Q1 j* I; ^ i! [, r
5 S }8 Q( T9 i) |
/* Constants for MD5Transform routine. */
! [0 d/ l6 j. m: Y( X' p3 E
; w& ~- A1 X8 y7 d6 w9 N$ j$ N " K* z$ ^; i( D1 G; P
#define S11 7 1 J! t7 {3 i0 s3 [8 r L
#define S12 12 & f& y; K$ ?6 y8 W3 D1 j- Y
#define S13 17
% D+ _ _ Z L L) T: i; V#define S14 22
' }; Z5 H- ?3 [( r: e6 m#define S21 5 2 X- M- f0 g T/ U. a; n$ d
#define S22 9 7 C1 @( d L/ V1 ^; c: M
#define S23 14 / @$ Q# `* _) g; W' H" @7 a
#define S24 20 4 {& X! H5 L+ d) c9 p* [; t. Y6 r
#define S31 4 : w+ A* y" O; O$ N/ x! D
#define S32 11
; {3 H& Z+ C! p4 r9 b#define S33 16 * U! q+ p& b2 o+ q
#define S34 23 ; `( \5 b- O: f1 @
#define S41 6 # `$ `+ ?4 k% w: [
#define S42 10 / S6 S+ c# C" o" p5 q3 W- w
#define S43 15 / b! T* D4 I; {8 h! _: i
#define S44 21 ! N/ E1 C1 O3 C
4 Q( }* z! J; w$ Kstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 1 U/ K$ i9 r6 O
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
7 T8 B" s& H s& K$ ]: g Dstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
6 [, A9 k2 C" b& {static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
, C2 d# V8 P& o$ P8 [& ustatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ' K& J4 A. m! b
. K# B3 q# G: ]- _0 N9 |% bstatic 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 , x$ o+ ?( O( E" u; }: z2 Y
}; . C: u, Z8 `) P" j2 `$ g, ?0 X
, w8 Z5 F H. s" ^. W- f
/* F, G, H and I are basic MD5 functions. */ 4 Y; k3 m$ E9 T" C
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
! ^( h& w1 z9 A/ g: D#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
3 A2 M0 s# U# k/ D! X$ M#define H(x, y, z) ((x) ^ (y) ^ (z))
) x+ C! l' q3 t#define I(x, y, z) ((y) ^ ((x) | (~z))) " I+ D+ h, S' c: }$ V
' O$ n5 I ]# n# y! h/ F( m
/* ROTATE_LEFT rotates x left n bits. */
1 |9 h0 F8 ^/ \$ _#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
' I9 h5 e! G3 W" G* f5 t
" q$ s' E6 k- @3 a1 e/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
+ ]) ?8 @& Q+ A& W, WRotation is separate from addition to prevent recomputation. */ + K+ c. T2 J4 Z; |
#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 [0 m, X, H( j( ?1 \0 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); \ }
2 ^& A/ m# T; u#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 Q7 g- Q+ U, y6 Z" N% i#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } & i& {1 r1 t' ?5 E j! B0 O' ]7 w
$ ^ W+ K+ t0 N1 g% B: l/ F4 c7 e/* MD5 initialization. Begins an MD5 operation, writing a new context. */
" c8 v2 {' A% y: }3 p9 wvoid MD5Init (context) - |; W8 s2 j. c6 {
MD5_CTX *context; /* context */
; z% Q' y- ~4 [' x7 F4 p j* {! B1 G0 z' e{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 1 A; H' \& M+ }3 U8 B
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; , ?" u, l4 N6 C9 I3 J
}
+ D: Z! W/ V. s, F1 D9 \/ H& Y/ H0 I - D4 \' }1 `. C- w T) n# J
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 6 Y- ^7 u; j+ A# g) t
void MD5Update (context, input, inputLen)
, y& [9 C, `3 ]" o3 b7 p3 E. J% A% NMD5_CTX *context; /* context */ + v0 R+ f# s6 d1 N
unsigned char *input; /* input block */ 7 x% Y" I7 L2 x# e ~; `- l _. y4 D
unsigned int inputLen; /* length of input block */
) s/ k2 x% F. u1 Z: x" [/ W( \{ unsigned int i, index, partLen;
' L- ~, Z7 o: k/ \4 _# x4 p /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ; ?! l6 W( z! ^5 y1 l! T6 _
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|