|
|
#include "global.h"
; l7 }4 {& S0 i9 o. s#include "md5.h" ' V# `0 a9 |6 ?" m5 n
' O9 S4 y) H' X; l0 {/* Constants for MD5Transform routine. */ ; W3 n$ Z: D; t/ X3 ?: V$ {; J' w
8 w; r9 S" w w* V/ M, l
! C1 k. U3 D8 ?#define S11 7 + \" E: f1 \1 m5 F4 t) |/ w
#define S12 12
" `% S# n; g9 \% }& N5 P' h#define S13 17
# c# }% s1 H0 t/ ] q1 B#define S14 22
& `: R. \9 z* N) U) P#define S21 5 ) n n8 _* D) {# V9 L v
#define S22 9
1 V3 J$ {# M9 B3 g! z3 v#define S23 14
8 y; G" L$ J; f9 U* `: p, n#define S24 20
! `( x1 B" c u( d- a o- F! k#define S31 4
9 J$ Y) Z7 j9 J#define S32 11 # u1 A' Q+ |: l3 ~) V; }3 _
#define S33 16 # t& B5 V5 [6 T% W4 f
#define S34 23 ! Y$ ^5 y8 x% g- N% l' U, J/ A: w
#define S41 6 / w, ^+ W/ k# _- Z
#define S42 10 % u1 l) C" f8 H V% ]3 S3 G# W. V
#define S43 15 7 O/ t9 }% m' c+ s* `$ G
#define S44 21 " T- I5 d8 Y& j5 k2 a n. v
; s2 }" H% z, h8 g
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
% @5 Y2 A; a, h9 h b3 Fstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
4 M% |4 {0 R6 K3 \' E" j0 [static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
2 A: M- f; e- U0 nstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); * {- a( x2 e+ y& l6 g7 F$ W
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ( J5 C1 m" I E5 w" D6 T: a
1 B0 O z7 v4 v% p& J
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 3 ]0 Q9 _ D$ z
};
" f! P1 h3 {( l & x b! |6 |- Q4 G7 X
/* F, G, H and I are basic MD5 functions. */ 8 V) q, Y9 A+ ?% G% N+ l7 ?: D
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) , i5 x. }/ z6 w4 o# d
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
" U0 E% Q/ ~2 E7 a) v }#define H(x, y, z) ((x) ^ (y) ^ (z))
* l9 P% m2 `5 h. A6 Y#define I(x, y, z) ((y) ^ ((x) | (~z))) ( y4 y1 x" {. V* Z, g% F( n0 q
4 s( i1 J3 ~2 r; f" @( J
/* ROTATE_LEFT rotates x left n bits. */
: O8 W. e) Y) G4 @+ N7 \% f& E. c# Q#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 8 k, b! L% m1 Q6 k
7 e6 w1 ?& y" Z' L2 c. S% R! _/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ) {$ e% H* c9 K0 V
Rotation is separate from addition to prevent recomputation. */ ! q3 y+ V. i$ F- J9 |& J- ]9 g, 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); \ }
( J) B2 l5 F9 r4 V5 \. `#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
, o3 m) X2 w9 ^& z* g+ @#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 w% R. m. R* `4 J6 K& O2 ~6 b#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 S8 J& J# p' i- o) v( b
0 p8 ^! Y) F5 H2 `4 A8 U/ N7 R' U; I/* MD5 initialization. Begins an MD5 operation, writing a new context. */ * t2 X; q2 l J) M: c W/ r
void MD5Init (context)
8 L& {+ `: v/ \4 x8 P! EMD5_CTX *context; /* context */
( K( |$ ] W: @# ^: y8 }{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 5 \( ]8 A! b, V" ~+ ?1 f
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 8 ?% d! x# z: O! G
}
, n" j; v( r5 L* e7 K: ^$ B / B0 C% A7 u3 G- Y
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
1 L" N/ C3 z. @2 W3 y+ E% A$ D/ qvoid MD5Update (context, input, inputLen)
8 w, J8 `6 \5 t: h+ lMD5_CTX *context; /* context */ 4 M4 E" }# Z% v: J
unsigned char *input; /* input block */
; ~3 s4 k3 q/ Munsigned int inputLen; /* length of input block */
( D2 m3 V3 f0 V9 y0 P' x" j{ unsigned int i, index, partLen;
9 ?4 c( y& ^' R* L /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 0 \# R& J0 m- `* O4 \$ u6 }
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|