|
|
#include "global.h"
* B+ s! B2 J0 a- a9 X' r#include "md5.h"
* L- u1 f2 B* Q% j3 b" a5 ]; E . p# W) w0 u" @
/* Constants for MD5Transform routine. */
3 c$ ~3 i0 Y. V 7 K/ x2 ^6 x f! |$ z" u7 S
9 q+ U2 I+ b7 t' {8 ~& |5 j) ]
#define S11 7
# {1 ?8 |- z+ Y {! x#define S12 12 # J h2 O7 E3 {( D9 \# C2 j& _. _
#define S13 17
5 e# A# g3 B) o$ Q, s4 R3 f#define S14 22 0 ^5 e! M: S0 F+ n9 Y1 z) [
#define S21 5 - ~* [- [2 ~5 p7 L
#define S22 9
3 q+ W9 t ~7 F! d. t: |#define S23 14
" B6 z7 @+ b) c Y: b#define S24 20 % ^: G% P# K4 t/ v
#define S31 4
/ R" T, c) u7 w8 i1 Q#define S32 11 . ?% A+ j, C0 z- x4 d1 `( n
#define S33 16 + x4 E; t) `" T! W9 _
#define S34 23
7 z7 U$ g: k, z" p# A5 k4 @#define S41 6
; E: j! A) Y4 A7 h1 p#define S42 10
- p2 }6 o& b& z3 a#define S43 15 ' X' [% H5 P+ _/ `8 o
#define S44 21 4 t) a" o- _8 l* U& W9 f4 e
3 {: u2 q) M' L2 _static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); , T- f- x9 N' g3 y+ y0 k) E
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 5 q7 \; r+ L$ p; t
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 1 M8 i+ Z( Q' d8 f9 I' N7 J
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
0 c& J+ H5 X/ Ustatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); . ]- L0 l8 R2 m' @5 z$ }+ ?
6 x4 g, r8 F1 p3 g1 P+ ]7 qstatic 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 9 s* ^, f* X% r3 c. |
}; 4 }, j* z; H" p/ |/ Z
2 O1 I* M1 W0 T' J/* F, G, H and I are basic MD5 functions. */
8 i/ P& _- R; M: t( R7 k#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) % w/ f' z1 {# [9 O" c- ~
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
( m; b6 P9 k3 P t( _#define H(x, y, z) ((x) ^ (y) ^ (z)) ) }# i1 x& n F9 q# \+ V2 D* C
#define I(x, y, z) ((y) ^ ((x) | (~z)))
0 U+ b/ O/ E: z5 N2 k& x0 @8 S7 o
4 D0 N* d3 N% e. p/* ROTATE_LEFT rotates x left n bits. */ 7 e, z% b1 U+ u$ J
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ) e4 g# G; D# u. c0 V
+ o3 |2 |% _- S# ?) u
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
" G! Q4 h& z/ k* _: m9 g1 q; iRotation is separate from addition to prevent recomputation. */ 9 f' _+ b3 I: Q2 I B
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" x" G' `( g# x% ~9 Z#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 8 H ]. f( S8 h
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ) u' L+ _" W/ T1 o
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& i* P, A7 e: ~" f
3 e9 @1 }2 ]9 B/* MD5 initialization. Begins an MD5 operation, writing a new context. */
( m3 I) P) F! lvoid MD5Init (context)
* Y1 o7 F7 z, t3 H7 rMD5_CTX *context; /* context */
: f8 b9 `, _) h" d8 [{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
9 \( {( g+ R7 G& L c2 c*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; & o( l" m5 {; v0 T
} 2 ?& J8 @' S" I. _5 U* x
' U. X* d U( J
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ ' }0 Q& ]$ _6 ]' m; P5 }6 Z
void MD5Update (context, input, inputLen) & c6 y5 P& |& S- o$ I$ F
MD5_CTX *context; /* context */
' n$ ~" [! J8 p8 i- nunsigned char *input; /* input block */ 1 I, u8 ]0 ^* H3 e4 w
unsigned int inputLen; /* length of input block */
; u7 ], T" Q2 v- K{ unsigned int i, index, partLen;
9 T1 n" S+ T8 s /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
- {# R; d6 e0 n' A/ Q! W /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|