|
|
#include "global.h"
; B) S1 v( l7 P0 V; {* A' q; {#include "md5.h"
* N5 Z# x6 i" Y5 h$ ^: s " P7 D8 D1 _) d) ^. t
/* Constants for MD5Transform routine. */
* l. p) C1 R# v/ H) v( f ! B6 X+ ?. R+ I
/ j5 H) ~; |( I0 B6 e
#define S11 7 6 b& j6 _$ S! p9 H
#define S12 12
( o4 Y: k: w2 I# Q- |#define S13 17 1 {. I6 L" Q! L" s
#define S14 22 . @+ {, `! L% y- E: Z% m
#define S21 5 / P* l W1 s0 G+ K
#define S22 9 7 R; z m# T v2 _+ y( {- F! q
#define S23 14 4 _- z/ Y9 B- \$ Z9 B9 }
#define S24 20 # g+ F3 G1 `$ f6 u0 U
#define S31 4 v5 C) P2 k; A$ }1 N, M
#define S32 11 1 s( F3 {6 R% Q _& b
#define S33 16 - Y, h1 j4 K" ]0 w
#define S34 23
. ~- @; F+ D$ ?/ j1 |# k#define S41 6
7 y! v; x0 g6 j2 x#define S42 10 : B( A+ [0 ]* R; F* F; w
#define S43 15 - r7 Y0 J5 B- m
#define S44 21
8 @, o8 T6 q/ [- J( t& e
: m0 D# @5 U0 C+ Vstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
" S! ^2 ^: l; u* [% r8 f5 nstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
7 w- n6 D! A! e( o8 Sstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
; Y1 V7 \, S9 m* Fstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
4 o0 w6 f/ J- D( X% Z- t1 Vstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); , `* N8 p6 Y$ |3 F3 p$ F! p+ D
' g7 C, \ z( f( G3 Mstatic 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 5 ^' y! x6 K9 L0 d. _% Z6 l% p! |
}; " s- V- w, C3 H E6 _/ ^6 \
3 V1 T% f! U- q
/* F, G, H and I are basic MD5 functions. */ 6 G! K) u: V+ S; T: L
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ; S8 J: X; ^7 V0 c# e( K! A
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
# m4 J. @% R3 L% M#define H(x, y, z) ((x) ^ (y) ^ (z)) ) q4 D, V) p$ A% q% w
#define I(x, y, z) ((y) ^ ((x) | (~z)))
" p2 O4 d, c9 u- k, j- Z) w
1 [. v' B" V+ f3 d" F/* ROTATE_LEFT rotates x left n bits. */
' k1 S/ k% D4 ~5 b#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
6 ] `+ Q- n1 y4 Q$ ^
) I; t" o2 c4 J* k0 g7 C/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. % f' x+ y' c v! G9 U" q$ s+ o5 _
Rotation is separate from addition to prevent recomputation. */ . @) \: u0 G) 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); \ }
' r9 C# ]) p) t9 ], ~! V#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
( p4 I$ G2 F r" v#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ t& `1 m( W2 r$ x- \- |5 _( F- R# V#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
4 g2 ^5 K3 b- Q' ~7 _6 S$ z+ i 2 n2 G% K4 c( H5 W+ W- ^
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
2 Y5 |$ S+ U2 Yvoid MD5Init (context) 2 I. L. c7 N l4 d; m
MD5_CTX *context; /* context */ 2 o* k, N; {! g! K$ H9 V
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 1 v5 w! T- Q; q: }( e
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
" u. X, j2 I" q$ F1 D, ~: w} & ~0 ?3 M2 e8 S# i. u0 ^, h$ b
8 V$ M% b. H- B# x x; `% c
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ - c1 S" T4 x$ c0 U) V
void MD5Update (context, input, inputLen)
8 j( e* I8 }9 K6 A o( l, r9 UMD5_CTX *context; /* context */ # p. Z) g* y- t
unsigned char *input; /* input block */ 5 l9 m$ C8 a7 O. o" J! o |# W: W7 T
unsigned int inputLen; /* length of input block */
8 h8 g- k5 y4 u6 |3 X! L& ~{ unsigned int i, index, partLen; $ b) B, l3 O: @# _1 p3 Z" }1 X
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ; x9 j9 i. u! \5 U! C3 u( Q
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|