|
|
#include "global.h" 9 C4 e c3 U- D3 c* z, ?: Y9 B* b! d
#include "md5.h"
+ K- I5 T. W9 h5 e; t: T7 y ' e( z* |# A1 |
/* Constants for MD5Transform routine. */ 2 B& {: f& ~! C+ z# N; b
* T2 ]6 v) p) X2 J 4 @" ?4 _* f' w' \
#define S11 7 4 G; f0 \0 o) J. V
#define S12 12 , c2 k: _: S* q+ q
#define S13 17
" Q" F& S5 D8 `#define S14 22 5 {: B# U* r5 Z. A% @
#define S21 5
4 ^% N! {. b3 K, T#define S22 9
+ w3 ], c/ @- p$ a, K7 F3 _#define S23 14 9 n' }: J8 K: N0 J# V% h* |
#define S24 20
- @9 P7 i) s: K; ?$ C% d! |#define S31 4
8 S6 I* H/ p7 b8 D( i+ x1 D#define S32 11 , t! T1 h' p! z$ j7 j
#define S33 16 1 v* Z- t+ Z0 `7 _ M& h9 [
#define S34 23
* j' ~! v# I) H: m9 _; d) |8 P#define S41 6 4 y4 o& a8 u3 w1 q0 W( B# S3 P
#define S42 10
1 M. Q" F n, R" l: d9 A#define S43 15 7 S$ ~: d$ }+ g. _1 D: ^
#define S44 21 : v) z6 }' [" B$ u
- w" k2 X1 A8 _8 S) ?
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 4 f& Y4 d Z5 e
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 4 F* b' J2 U, f1 e. S8 F0 w
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
8 T2 G4 r4 b2 y7 C9 l# p g" ~$ C. {static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
" X6 l7 O9 b5 U" Nstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ; T2 }. q- a. G7 ~1 _& D* s" [$ q7 A
! S3 G9 }% `- H% d+ P1 wstatic 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
Z2 A4 r. m4 \0 D};
* E& K3 u$ c* y8 L( } & U5 j) i4 P1 x+ u( w
/* F, G, H and I are basic MD5 functions. */ x3 |4 b& q- d4 B4 B
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
; k D9 W i7 {: x: K#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
* R% k* b; n5 F9 w2 u2 t1 ~( |; @#define H(x, y, z) ((x) ^ (y) ^ (z))
4 l& P) `( x, b( `6 T$ k8 Q6 F#define I(x, y, z) ((y) ^ ((x) | (~z)))
3 L; w! @/ ~- M# k* ~3 m
, n, Q) @, J3 u( u/ V9 F- m) W: l8 M/* ROTATE_LEFT rotates x left n bits. */
& k# @$ }+ s! J" Z/ h" l#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 3 i# t4 _# R$ `( i
& D+ b/ S: e. ?. v* C+ o
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 0 U( }, x2 Q! A3 M
Rotation is separate from addition to prevent recomputation. */
! H- P! [* l0 u' }#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 H- m1 S5 Z9 C$ N7 e! F/ I/ Q; F) K#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 f+ U+ o/ R" ?! ]
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
+ R& n' T/ l& D# S! S0 E. O. P#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ) j% M" |9 I3 }4 J# g+ F6 s8 Y: v
# g/ `( O5 F" v$ k6 Y, A/* MD5 initialization. Begins an MD5 operation, writing a new context. */ ( M8 s% I8 V+ Q- x
void MD5Init (context)
' Y( M4 G! l! D8 {' \* P# _MD5_CTX *context; /* context */
$ x9 n+ E; q8 [ a4 p3 b. E4 V6 S- g: f{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
/ b' x! A2 {# O; B* h3 _*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
: R% O" [- Y8 q9 z} * ^$ |$ _9 C4 J4 X3 b
: S2 c+ ?6 v: i: B4 \/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 4 T" q9 w: l+ ^1 h
void MD5Update (context, input, inputLen)
& d! R" K: t( r7 C1 {MD5_CTX *context; /* context */
" r* E# Z* n. D& Yunsigned char *input; /* input block */
* S) W: r5 Q; |# i/ d( Lunsigned int inputLen; /* length of input block */
' P0 {6 f2 R3 Q{ unsigned int i, index, partLen;
5 L4 U0 r! M! M) }5 t8 Y9 z /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
: v* r5 F$ F! g% u( ~+ \ /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|