|
|
#include "global.h"
5 y% T4 P2 \# B' ~- s#include "md5.h"
& Y2 ]0 B; H& ~% X, ~! I1 ]( ] 9 F. U& Z' H; n2 n% X3 R5 j
/* Constants for MD5Transform routine. */
/ N2 V. H0 ^" W: @* u
! S/ s! a# a" k
1 e5 A0 j4 E+ Y/ f#define S11 7 x; {% ^& V8 `; E: ]' U: N
#define S12 12
) x, q) t: P1 A#define S13 17 . ~6 M0 s9 ]0 R+ }$ b$ Q
#define S14 22 " Y0 K/ i5 R: {- \; r1 H1 g( [5 D
#define S21 5 : e3 b, q3 K$ \* l
#define S22 9
1 T! L3 H& M8 w#define S23 14 2 X4 @( l5 x$ F9 n/ b; v+ u* Q, u
#define S24 20 6 v9 r9 ]# K" j. ^/ A
#define S31 4
9 b& ~; |6 t; Y* Z#define S32 11 ) ^1 X+ a- P9 g3 D, z
#define S33 16
% R" S4 i" R s; k0 |8 W#define S34 23 5 s4 m6 t T! r% ?0 v. |, W
#define S41 6
# |! q+ U! V7 S, M! m) m3 I; f, Q#define S42 10 & U3 c& _3 ]7 H( ]; u& Y- I
#define S43 15
9 p' r; h; L" L A#define S44 21 ! K% [3 }0 Y5 s; j$ V( v
D( V( m/ k6 f. t$ D8 P
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
4 M; y0 v, W; V! j8 z7 `2 m9 l- gstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); ' l& \# S9 F$ s8 z& a. z& W
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
7 F8 y! \4 |5 e8 f$ g" Mstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
/ D' Y% M" L4 G5 @5 ?4 {9 Hstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 6 q- n9 c/ x" U4 l$ F
; j* M& o( M. \ [- ]
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
' g; p m& K8 o: ?/ a};
' P' R' J; h: u, w2 } k# d" y: T) f
$ a+ N8 M! \3 K/ O, Z( I4 i0 H3 T/* F, G, H and I are basic MD5 functions. */
+ J3 h6 E U+ I- [#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 4 n9 y. ?0 ~( @$ I
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
) Z% h# s+ T' y! C0 t) M#define H(x, y, z) ((x) ^ (y) ^ (z))
2 U% @& |4 X3 D7 G+ v2 t#define I(x, y, z) ((y) ^ ((x) | (~z))) 2 G% |1 }' J+ {) p' O) C5 z& I
7 I6 N& U2 D$ m1 H, E3 B/* ROTATE_LEFT rotates x left n bits. */ % j0 M' n* @( l n. q5 j# e! W' n, o
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ' q; J/ ]- Q6 \5 Q3 Z
& {. Y& b! g+ d: o5 H
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
4 j/ b9 _/ K) |: U$ O+ v2 NRotation is separate from addition to prevent recomputation. */
+ C* `* [% O+ t- X/ E, g#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } " N' l8 h, u6 f' h5 ?) ?
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ s0 T; x0 W" d( C#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } b( e; d: x; [
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
$ ?' r# q' m) r" I1 B
6 o& c9 L# I/ B3 v7 _ z/* MD5 initialization. Begins an MD5 operation, writing a new context. */
3 P0 U# o7 x" ~5 Cvoid MD5Init (context) : D- n- ~2 b5 M" i7 ~* E5 o
MD5_CTX *context; /* context */ 1 j, @/ i' o3 p9 j; Y( u1 _$ ^
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
/ G$ a6 G( o; k$ m*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 9 ~' h/ {. f9 V" ], d
}
! B5 L$ u$ {6 B$ `
6 F u) N9 O7 l% T9 P2 K2 j# O% h# Y/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ / l1 |- E+ Q' j* t' i
void MD5Update (context, input, inputLen) / N) Y# t: x8 d3 C2 T# q
MD5_CTX *context; /* context */ . B( {* V, P( V# m
unsigned char *input; /* input block */ h/ T, M3 g+ `
unsigned int inputLen; /* length of input block */
( n* w* r3 Q/ N/ o7 G9 S0 S{ unsigned int i, index, partLen; 3 x) \9 b0 \% h
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); % L) r) u% k- i4 s
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|