|
|
#include "global.h"
3 B! F# Z& Q4 P2 q# {#include "md5.h" & ]5 e, ~8 x$ Q; ^7 }6 j- _
9 Z# @3 D8 q. B1 F) N6 T/* Constants for MD5Transform routine. */
% ]( f: h* z3 h( x" Y9 i & ~9 |# D8 A3 a; `7 X& v
* ?& H ~3 P8 N6 ^9 f7 }' s. U( M#define S11 7 ) \9 q1 i2 G* h/ Z/ s& h9 C
#define S12 12
1 B ~" F3 ?6 c* |* y#define S13 17
6 E- n0 d- h5 h8 a' A#define S14 22 7 s, n' l/ H" \$ c
#define S21 5
/ E1 Y) G9 M; w* K X- t#define S22 9
' H( a1 j/ h+ `#define S23 14
6 U& M9 |" P$ @5 N- f#define S24 20
( y# T5 @/ h& v#define S31 4
3 Z1 C2 |; `2 y) O, k5 ~4 r3 y#define S32 11 * x' Q! G, O, @" c8 i
#define S33 16
3 |* _2 e0 N+ O" B#define S34 23
9 H: V8 F# {$ N d#define S41 6
3 y# D2 Y' Z+ c% y9 O s#define S42 10 ( C! F5 k9 B7 I8 K/ |5 T- N' E8 V
#define S43 15 : y, v. a" E) v+ _9 X
#define S44 21
" K M% h; I/ U* R$ k: b; O& F ) T+ a6 g. h$ u; h4 J$ t- }: Z! q
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); . E; s7 W! M0 F' J" l- k
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
u6 V+ c- `" F6 E+ Hstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
% J4 q f6 s1 w3 Cstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
. L/ I6 f- T! i8 c8 Z, Ustatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
V6 s# Y, U8 p! e' ^- q ( l% r; g) g# l1 V1 T: }' W8 [
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 ' y- ]- b5 j l/ v5 d; r
}; 7 p4 G; y7 ~4 G; P2 l" q
+ G& b( D6 a* m [% {! o5 T$ e" e/* F, G, H and I are basic MD5 functions. */
2 S ^0 g; D9 g) C/ ~2 [6 c#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ) `8 R$ F# U+ o3 {0 e1 E4 U
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 4 ?% u6 c& K9 T( u! V6 j l
#define H(x, y, z) ((x) ^ (y) ^ (z)) 4 L7 L5 w5 h% N5 e0 A
#define I(x, y, z) ((y) ^ ((x) | (~z)))
; l, T7 t7 a/ u, ?% r. m% q0 n
( |+ c/ H1 o+ {/* ROTATE_LEFT rotates x left n bits. */ % T# d; i! H! l; [
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
. o0 i9 C( Q( ^$ l2 o5 t
& I( P6 C( m# Y* J/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ' |# ^' o; Z+ Y7 x! }) n3 t# M: v
Rotation is separate from addition to prevent recomputation. */ 9 D9 ~! m/ @; ~# W! a6 ]3 M
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
' I1 t% ?" A/ k. z/ U" I#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 7 n$ Q2 t3 J5 w4 R
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } / O, W" ]8 U& N. l6 r7 s
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
) ?* R0 q) L( g! B
0 h, u ]" S, f: i% a/* MD5 initialization. Begins an MD5 operation, writing a new context. */
, Z, U! X" P' ~. p# B) t3 k7 u. Cvoid MD5Init (context) ! z5 {+ h3 l7 u4 Y+ U# m
MD5_CTX *context; /* context */
9 N; o( `4 M3 _" M/ \' |{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. * P& K+ e: o) p& t4 b, F
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; " j& W# v0 g9 f7 \, j
}
8 _" Y* r% Q+ u! H0 e7 g4 J
- n& Y- |4 `% H. M5 U* c/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ - a7 z2 {6 z7 K+ z7 r" d9 L: D
void MD5Update (context, input, inputLen) 1 n9 ?5 }( i! j6 l: o/ L( W
MD5_CTX *context; /* context */
7 O* ^7 |7 t% \+ ^0 Vunsigned char *input; /* input block */ - \; u" I; P$ W- ~/ ^
unsigned int inputLen; /* length of input block */
$ I6 ?, [$ v* U. s{ unsigned int i, index, partLen; + ? w* X$ G) f1 @( o# Q
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
G, u/ x8 _8 C' m% M /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|