|
|
#include "global.h"
8 n, S5 R4 P V5 d" M. j#include "md5.h"
% {& N7 h& P5 h9 ~
* `* s9 R$ G9 T/* Constants for MD5Transform routine. */
! P$ o' `; ?& _8 E
% O& j, A1 J4 o
! {7 Y, N7 m8 s) q6 i#define S11 7
y& s) ?$ d6 ?" {. W( w#define S12 12 ! H8 ?4 ]* @2 Y s" b, `1 N
#define S13 17 ' ~+ T' [1 Z7 k6 u) P$ z
#define S14 22 ; o& S3 `6 }( X
#define S21 5 2 g, p7 n; B6 A w7 f8 Z# B5 f
#define S22 9 0 o8 {/ J1 m" J4 Q# U8 m
#define S23 14
/ u `' M/ B3 e# W* D6 n+ T#define S24 20
' I6 g+ o! t0 N2 d#define S31 4
9 e! l8 U. x5 S+ R$ [+ E& H#define S32 11 ! }' j. Z f( ]5 n0 a+ }& _
#define S33 16 ' C' v Q( e5 P; T% g
#define S34 23
8 j5 F" u5 U1 d7 b#define S41 6
, X. D8 N: j+ h( a0 r#define S42 10 $ Y6 E) O6 \" j) p( z {
#define S43 15 ' a+ y. E9 U' F. |8 N
#define S44 21 8 M. ^% n0 ~) v2 k
. E$ l, T1 T s! F& F
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 7 x4 R; A) z- V& V9 u
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
# r- ]0 e& g1 i2 E# R- p1 q8 X% p( Fstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 8 C2 W" _$ T* Z, H3 D
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); , Y R$ _ k5 g+ ?' x# c4 \; d- B) y
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 5 |2 ]5 |% {% m' i/ g
/ O* W# `; \6 F" X# C# ~7 @
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
' t1 y6 K u9 ^: Q. L8 E}; ) Y- |, B" C' p+ d& a
0 a" ~" Q# H1 _/ O4 O- r
/* F, G, H and I are basic MD5 functions. */
3 g0 l6 i. D, z# b% s#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ) [/ K. u1 b$ W. S( `7 m) n
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
9 O/ x x' \2 e! X' u#define H(x, y, z) ((x) ^ (y) ^ (z)) + J- q4 y7 Z) A" ]
#define I(x, y, z) ((y) ^ ((x) | (~z)))
+ o4 P' E J9 Z/ \+ g
5 `7 J7 d! t. p/* ROTATE_LEFT rotates x left n bits. */
6 B. H1 f* |- W) L* [#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) * x$ t9 Q; ^5 b7 Q
6 L6 x$ Y* O6 @. a9 r
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
9 o8 o; f% t. g' z( d! o$ V7 ^! ^Rotation is separate from addition to prevent recomputation. */
8 H# O4 `4 e% z, ~1 Y#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 7 ^( R" @# Q; Q; m
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% ]- J. o! O$ f: ^% n& 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); \ } 3 \% D2 A9 z3 f0 u
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } * [# A! Z. y# }
' \, ^% C$ T: b. M' H
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
$ u- Z* a, {' w( z8 M$ G' Yvoid MD5Init (context) * v7 ?) |9 j0 |' N/ w. }7 T6 R
MD5_CTX *context; /* context */ ! {4 T. N9 x8 ^; }' x# E# c4 S7 D
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 3 B1 }9 p6 _# p: v! V5 T
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 7 @2 f! o. R) b/ d
} + z! d6 U# P7 ^% ~: k: w1 p6 v& z
4 @* m9 D0 ]$ @: K# Q# S
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
3 e H. C; e5 @+ [. ]6 Wvoid MD5Update (context, input, inputLen)
{# V( Q2 Q8 w% A5 vMD5_CTX *context; /* context */ # _" Q# |* j8 L+ ? A
unsigned char *input; /* input block */
l+ _/ }* }) r# h" e* a) x, O' J) uunsigned int inputLen; /* length of input block */
5 v- K3 w$ d1 u& b9 P{ unsigned int i, index, partLen;
# [* Q0 w3 S0 T" C; q /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); % u, s0 L1 l M/ [+ z
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|