|
|
#include "global.h" % J4 V6 X: q% o4 E# R
#include "md5.h"
1 Y; k* D/ E9 U: V; |7 ]3 u, [1 n 8 b s: o' K7 S9 l( ]6 u5 e
/* Constants for MD5Transform routine. */
/ P2 _; |3 p1 ~
7 N) P F# n5 j& ^2 M' F 4 s5 } C# ~4 n0 f
#define S11 7
9 M+ p4 n% c1 K/ B9 s$ ~#define S12 12
- W1 @5 u% e: L ~4 m#define S13 17 : j9 o! i- a) g( z# u0 P
#define S14 22
# U0 ?, O- y6 g2 x#define S21 5
% ]5 Q! ^0 p, [ W$ L#define S22 9
8 [7 n! ~6 M7 x0 o- z#define S23 14
7 V. }9 B& g. F8 ]#define S24 20
7 C! A- e; E% H" {7 b+ f1 j2 w#define S31 4 , j) A, w, b; J8 Y# ]5 |1 U9 x
#define S32 11
* y$ O& W( x3 x; Z#define S33 16
" q, `; H# |$ o y- M& ^#define S34 23
6 Z" C6 O9 O' r7 s- C! s; T& V4 g#define S41 6
! R) K2 s) X0 E3 i7 h% o# }#define S42 10 ! [) ?6 j* Q" t1 A) `4 j# g
#define S43 15 ' z% z3 @/ U" i/ l$ |/ k* a
#define S44 21
& x3 X O8 o2 i6 e' m& J' D8 p. W
# t5 |9 P i' ]( J% H1 v1 Istatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); : \* a3 c. H7 K. b2 q0 z N
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
# M4 V5 W% a2 j8 S9 `static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
1 {6 _" K8 o" Q* S' O. ~& _8 lstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); , A/ c, O# B i7 v S
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 3 T4 Z% a7 X- s' N( o* Z( p
2 {: r7 n1 I v, }) ustatic 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 . o* s4 a! B( f1 \
};
; S8 I, b2 |: p+ [3 G7 @
4 T+ \0 d7 a, |" V& H/* F, G, H and I are basic MD5 functions. */
* J) k( X& Y- _3 m. { W#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) * i3 H7 A+ E7 a) [" B( `" p
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
3 w2 Y" k9 u( c+ U# X0 a T# w6 I#define H(x, y, z) ((x) ^ (y) ^ (z)) - {3 r7 K5 l4 c' s6 e+ a
#define I(x, y, z) ((y) ^ ((x) | (~z)))
* f* G: b# j7 r5 X& B* d
s# v. E, g+ T8 S5 u/* ROTATE_LEFT rotates x left n bits. */
; W& q& X) s. r1 ~) I; r#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
8 ]% E6 C( ^/ W4 \" ^ 6 j9 K* u0 n7 B- o
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ; A b& {1 j$ t: C+ m
Rotation is separate from addition to prevent recomputation. */
2 k" W3 `4 H& L5 M. M2 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); \ }
- w$ b4 n' [ P8 D#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } S) `' I( E9 |/ ~* ]2 ]+ 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 R7 j; m9 a1 J3 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); \ }
. z# ?4 i% T1 { . @- t5 D6 ]; e+ U
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 9 v- ?( u$ Y$ G- X( }2 N
void MD5Init (context) & R4 u& @; r2 [% ~
MD5_CTX *context; /* context */
9 H5 o' W2 d7 K- G2 R& _{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. " S% N8 I4 {% K" T" j9 u4 X
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 1 Y* N" k9 j# f, X6 G
} ' w! K% ]; R1 Q% L8 f U" T6 S
! H/ Z9 P- Y1 l( @; P8 ~
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
" V4 f9 p; H3 o6 D6 }% Xvoid MD5Update (context, input, inputLen) 6 g; c6 p' v: S
MD5_CTX *context; /* context */
/ B w9 K& ]' _. ]; Xunsigned char *input; /* input block */ 6 i3 A6 |4 n. H
unsigned int inputLen; /* length of input block */
. f) p% ^" b+ p' a8 `' m{ unsigned int i, index, partLen;
1 r! U6 s9 M6 h9 ?- \# w# Y& D /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
% }+ l# d; B) |6 ^. r. {7 ] /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|