|
|
#include "global.h"
8 N8 u5 ?6 B% v- @& h- Q2 j- H9 q- }#include "md5.h" * b' M* u' s1 a. \" K" X
! O* R* U. ]2 v/ k9 ]$ ?
/* Constants for MD5Transform routine. */ / u5 N% ]( F/ _+ c
r7 w# f# r3 F L$ v; O # B4 T% n, \: F7 e
#define S11 7
4 O# u4 g2 u- v" e#define S12 12 ( t& E6 C/ s$ F# e# U- B
#define S13 17
; f. Y0 q( U! a$ Z# y0 g' t#define S14 22
# q, M0 [# r7 k#define S21 5 ; m' N0 q( A- {' ]
#define S22 9
+ m0 [8 [ t/ x1 z) l#define S23 14
5 o# {+ n9 s+ }4 C+ y% m/ i#define S24 20 9 I. ?* r5 Q$ Y$ N7 e
#define S31 4 1 l3 Q: c9 [% ~2 Z& {
#define S32 11 . }7 _- s' L5 w
#define S33 16 ! j' Y* d A9 o2 |
#define S34 23
3 O( M! K& k& e#define S41 6
- J4 A+ B: a1 ~3 a5 y( K#define S42 10
$ P) q6 I6 K- L- L#define S43 15 6 H: o3 ]$ f) k; T
#define S44 21
; K7 j3 J8 w. e) ^$ p " h9 k2 G0 ?. C# a0 J2 h2 `+ m
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
: @" i7 b' I7 W0 w; astatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); $ O% n9 c1 V3 }8 v+ T x; r
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 0 r9 J* p" d1 q" v
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
9 R# |' z# o7 ?/ F: p2 E7 r5 {static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); . y, G% K. v! p5 t+ T
, O3 O, [# |- y, T4 o1 V: \/ t2 Pstatic 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
! X7 n5 v6 y6 Q9 P k9 }% r/ d}; $ h( V2 c; n* w0 F5 V
/ D9 R3 E5 C$ N# ^' a( d& P
/* F, G, H and I are basic MD5 functions. */ % B/ }# N9 `5 ?' t: I( ~" x1 S9 h7 |* c
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
2 n( b, @- j3 N) a( F& h$ f; ]#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
g; y, M1 N& `" E: G, I1 C& [#define H(x, y, z) ((x) ^ (y) ^ (z)) ' {" F" G. [( e; E% \, Z. [5 ]
#define I(x, y, z) ((y) ^ ((x) | (~z))) 6 F, p- S* o2 _8 }/ K5 R0 \/ h$ F: H
8 h2 Y: \4 n0 O; E; \
/* ROTATE_LEFT rotates x left n bits. */
" x- F; K% I0 Y. e8 H5 }#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
: Q H) x9 n3 o) b. @ 2 T1 Z/ X$ z4 a( b3 |( F
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
2 E+ l' U. Q' c* c2 q+ d5 ARotation is separate from addition to prevent recomputation. */ $ ~2 ]1 _* p6 m0 J
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 8 a; \0 d P" x% W4 k4 |$ e; q
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } , b3 Y, I2 h2 f, V; z0 S* Q
#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 D, E# \7 w, c( m0 k6 H
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
3 G" P% x1 q0 [ P6 K+ Q9 B1 L1 n0 t
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ( r8 U+ X2 j/ y: S; X" U
void MD5Init (context) 5 f) h* n5 ~! z! T7 a
MD5_CTX *context; /* context */ + e' T: I9 n5 A9 G0 E" N' E2 x
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
`. y# ]% ^& M- s, L' b*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
; `( @, u; v$ r: A} 2 _- ?* c' o' _! j$ _. N
9 y; Y. i3 d# \6 I( m/ E4 Q2 U) m
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
0 D' f& v7 ]" Qvoid MD5Update (context, input, inputLen) {& j0 D8 v1 i+ q- V! N! _
MD5_CTX *context; /* context */
* e8 Z" V' D* ^unsigned char *input; /* input block */
) D" q+ J" }2 {( w5 \unsigned int inputLen; /* length of input block */ 8 P0 E/ b$ B/ n
{ unsigned int i, index, partLen;
6 Y1 R, C; u# | y9 W2 B2 G; Q /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
& h- F% E [! M' p+ Y /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|