|
|
#include "global.h"
% v1 j& \, S# x# F- k+ `#include "md5.h" 5 b: a& a& G. l6 ] v, I1 P$ f6 w/ \ C+ H
0 `9 c' v0 l5 ?8 ^# Q
/* Constants for MD5Transform routine. */
" Q% o; R2 e/ Z# K6 r ) u; W3 z/ q6 N7 h4 b
( i; K; w* ^' e. j2 b2 L#define S11 7 3 [5 n2 Y0 L- X; ~ f) N; @1 ^
#define S12 12 ) f/ i" P8 D* g9 W
#define S13 17
* h( O8 M% f+ V6 ~ u& y#define S14 22
2 y& L' P. {, B! B2 b9 [#define S21 5
0 I6 d i% I3 _* N& ~8 k* ?#define S22 9 8 g( l3 L8 k4 D% b8 e' l, |
#define S23 14 1 A2 |9 f8 e4 P+ ^" Q1 ~& d, O
#define S24 20 c2 g M3 l0 a$ {* m' a
#define S31 4
- S% S1 u) u: {& |1 ?#define S32 11 5 U5 S" C' c" w
#define S33 16 ( V1 \! w, [7 _6 t+ m; j5 V
#define S34 23 ) B/ G$ S9 B# T; H; e" |5 d
#define S41 6
2 H S( c+ h9 ~: a% S) p' u/ X#define S42 10
8 T1 S! ~5 x1 Z2 ?! W#define S43 15
! s+ J3 m4 }* k+ n0 [4 n! l& `3 e#define S44 21
5 P5 _9 r6 k0 O+ V+ J/ L) j
t. d$ I( L1 O5 u8 Wstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); ! O9 \( f" q s( x6 z) \
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
) [, j- O f9 `static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
: D7 ~+ ]1 x+ _& X+ W* ^static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
7 J6 e; R& Y" l; X. W# p! Wstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
7 t* i3 p! L. z- @
5 ?4 q! D$ @/ J# q8 Z6 F$ N. U" dstatic 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
) ^0 M' R* J+ u: u7 k}; . e. l; [; l$ k3 i9 E$ d; N/ l* D
& }5 B8 y4 ~5 r7 {4 A, A! H. j: E/* F, G, H and I are basic MD5 functions. */ , Y. d7 N2 G8 e/ A) z
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ( G: h+ H- v1 W8 j! ~3 T. r3 U* x1 W
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) : x+ u4 L L% K9 j$ x
#define H(x, y, z) ((x) ^ (y) ^ (z)) 2 [7 g5 ^. z# x1 \
#define I(x, y, z) ((y) ^ ((x) | (~z))) 3 E7 ^6 K/ J0 O
6 ]6 n& s/ y' t5 X. A5 [1 Q5 q4 @/* ROTATE_LEFT rotates x left n bits. */ : d" ?0 J# i$ r6 K) E6 v* H, A6 V
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 9 ^4 b. U, c% K2 z" p) |" M& n6 z
) h$ h7 e& p) W: J- @. R0 a/ }. L7 X
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 2 q* I2 P( z* {" W y
Rotation is separate from addition to prevent recomputation. */ 4 _1 d: r ~! H
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ! A6 R9 _. C4 P; H( }/ y
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 3 X( C/ k# D6 n+ Y9 ?4 d; y/ k2 o
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } % p" Z& F. q8 O8 R1 F9 S/ W
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
* h" [5 z+ _- a' Z
6 v; Q9 b# _7 _( ~/* MD5 initialization. Begins an MD5 operation, writing a new context. */ * S0 s b1 u8 `+ v0 w
void MD5Init (context) + A" I; w1 b4 N2 ?" Q
MD5_CTX *context; /* context */ $ A. \& L% d; ~) j% h
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
3 I" I) P/ b% M0 J( K4 R* K# ^1 O) P8 m*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; , T: d3 N% X) q2 @& o" c0 z# [
}
6 L3 s7 [+ e9 m9 e
/ g$ a/ y0 L: M8 n% M/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
( S8 u- ~; I0 L( V! G: Svoid MD5Update (context, input, inputLen) % {; v* F3 `2 H9 R( R
MD5_CTX *context; /* context */ 8 j. O0 H8 X; F" i
unsigned char *input; /* input block */
) p! \3 d* W4 _: Lunsigned int inputLen; /* length of input block */ * Q, e3 C* E0 \3 F
{ unsigned int i, index, partLen;
; Z1 [6 W% r& k) \/ @ E( t /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
8 _( i$ ~5 [ `0 K /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|