|
|
#include "global.h" % d) h, M, M+ E$ H: U1 b
#include "md5.h"
+ p0 p/ Q l# Q0 d8 t% n & v6 b' P# l2 E) n7 E: M' _& m
/* Constants for MD5Transform routine. */ 0 W& _. F4 ]7 k6 {8 i6 R* n
, R) S* k, k& g
( d6 g; n# \. H" W
#define S11 7
$ Y: A0 Y j+ ^* E+ F' f#define S12 12 5 M( u* B# |/ j, \" E: l; G0 H; o
#define S13 17 9 ~1 F, D& i6 ?% ^$ a
#define S14 22 - o# ~2 g9 E, ]
#define S21 5 1 q: ?1 b4 q& U6 s) R% v
#define S22 9
1 e& X, E# N$ x2 d#define S23 14 - j1 L9 Z) g: v+ q* U5 I
#define S24 20 ) A+ @5 _9 m* Q2 L/ d7 W3 {
#define S31 4 ) r* ~. ^( \* M, x% l+ t* @
#define S32 11 , V" m/ j3 x0 ~7 l7 N4 w& L, k
#define S33 16
0 t3 W% J5 } ^- O' l#define S34 23 ) \! d7 H- o3 L8 y0 W
#define S41 6 6 G" d8 j; E8 O, ^8 u. \
#define S42 10
9 E" E" @7 e& f1 I; J. p#define S43 15
( G' n6 f/ \: ^" [$ o- e#define S44 21 3 |5 p7 S8 b6 J
; E. f! @$ ?% X4 f; V
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
! f r) o; r Nstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); & }: Y4 X3 Q4 s2 i6 |
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 6 c7 L8 w. y' A3 U0 d# D1 W
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
b4 E" S3 O+ h$ A- n! k# Cstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
/ \0 o# t1 o4 W9 H
9 E- x# }5 t/ Q2 l' C! G8 q3 G7 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 8 \9 m! p+ H4 E+ s! b3 f9 T* o5 P
}; ) E+ Y* Z2 L6 F
: ?* N5 {; m/ j4 ?
/* F, G, H and I are basic MD5 functions. */
$ T9 o [7 v9 |& {! O. R#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) % b8 {- |! i0 `$ Y3 B- q5 \% d
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 9 a: F+ x, F# Q
#define H(x, y, z) ((x) ^ (y) ^ (z)) . E" c6 C5 \; p7 w' g0 q7 _
#define I(x, y, z) ((y) ^ ((x) | (~z)))
& H# W* ]4 p0 ?2 D. {& N1 I
1 |& J7 B! n/ u) S/* ROTATE_LEFT rotates x left n bits. */ ( e' z5 H( L$ H' k: E1 f4 n) A
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
# Q9 G4 W U& U5 L
2 G/ s' ]8 ^; H E$ A$ q l/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
9 t5 g; p! f9 O; F& ^Rotation is separate from addition to prevent recomputation. */
& P" k* X" k ~5 v# t6 `8 l* W7 C#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 ~# L( _9 E# h b# @, 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); \ } $ F1 s% T! [1 Q& [/ N
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 M2 Y7 U6 k9 _: e' Y# |6 Q
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
; p& t* P8 X, w 0 _& Q/ K6 P' R) `) q( G
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ $ |5 S( \3 G+ q
void MD5Init (context)
% E( t, f0 W" u9 _MD5_CTX *context; /* context */ # c+ s1 z9 `* y8 }$ x
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
9 V4 M4 g3 K+ N# @% [9 a*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
- O$ Q f+ \# u' Z2 q}
0 p) i! e5 u5 L
; P2 f$ y2 ]# t/ a. E" w9 H/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ : u+ X( V3 `2 \% ^; q0 W) `
void MD5Update (context, input, inputLen) % a+ q5 ] K# |/ j; |( M" v
MD5_CTX *context; /* context */ % {* K- H6 k2 N+ X* \
unsigned char *input; /* input block */
% t. {- d. V2 A4 ~unsigned int inputLen; /* length of input block */
. R# i! e2 E8 E& Y4 p1 d& ]; d{ unsigned int i, index, partLen;
9 V' V: d0 f& u9 |/ V5 K /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
; M+ V# `5 R( z: A4 R" X8 A /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|