|
|
#include "global.h"
8 ]# Q; @- X( o3 n+ B1 O#include "md5.h" # W( h% u* e9 B v2 E5 r/ e6 F
5 Y3 C U- G. v1 t, e8 Z
/* Constants for MD5Transform routine. */ 9 ^1 `% x5 }& B, X c1 `8 f3 [
2 F% q2 O+ y6 L- J$ K
9 e4 D0 N# _# _8 j' T* C#define S11 7 $ ^* G& K7 V0 F- { C$ X1 `
#define S12 12 3 N* k+ Z& F$ l+ l7 {$ t
#define S13 17 1 F% ~% w' e9 W& Z u3 Z, P+ F
#define S14 22
; e& h$ U) J- S1 i p#define S21 5
9 `( s( C! c1 T+ r#define S22 9 9 e' h0 p( ^! X1 D
#define S23 14
9 x2 }1 s4 P' t3 [5 ~/ P7 ^#define S24 20
6 }! k# K' q F7 f5 _- p" j8 S#define S31 4
; O* L# B6 ]; o5 p6 z* [" t#define S32 11
0 _/ r! a, L, m3 t# B2 w#define S33 16 $ t2 ]; L @- V7 c) c' b- [
#define S34 23 0 k: W8 `, R6 v) H% c" N. s
#define S41 6 ; k3 O0 ^) z' o( `
#define S42 10 4 s, h2 J. w' Q. N
#define S43 15
, h+ |& M+ p" @8 G% s7 _$ i#define S44 21
/ J6 v1 {/ z0 p4 e- r G7 W ?
+ q J! D( p2 b/ J: A; X& p. V; ^# Dstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); / o' {0 \# j% z
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
4 Q* J; H4 O, lstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
6 T! e' s& _( q0 ^* N- nstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
4 P ^2 O1 M7 ? o# Mstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
2 o; T$ s9 i* C8 u4 [. o/ B
0 \3 I% Z$ F9 F1 R! |" u! W! B5 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 " ?7 _9 T7 h, S
};
! p4 s" p1 P7 `: }! s
4 V8 c& N, G7 y/ n! E2 s* d* [# E/* F, G, H and I are basic MD5 functions. */
5 d; x1 o% j9 C- p6 Y#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
3 h% G' c/ P0 o#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 1 N. R) G% e! J/ `0 e
#define H(x, y, z) ((x) ^ (y) ^ (z)) ) p: y# m4 O1 w G, D2 H4 O
#define I(x, y, z) ((y) ^ ((x) | (~z))) 9 y3 x6 F3 M7 L( v+ G7 H1 g; u
7 n" n, S" Y: }; T& Y/* ROTATE_LEFT rotates x left n bits. */
, V7 G0 Z; X; R. S#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
: [& q- a" V: p8 v" N" M. h 6 ]$ A& M' g7 j+ j/ ?5 C5 s
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
* O# d9 C& e* |# WRotation is separate from addition to prevent recomputation. */ 4 G8 u$ N" I' l; a( o
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } / z( `) C4 M$ Z$ ?# P
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } % G: @, ] N# Q! C$ i
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ( q+ H) p' E8 B$ @) Y
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
* o+ u( F/ v9 N" |) f7 P0 ^ : A- N# h' l% e* S- g8 U
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
5 ?+ k+ U- C( s$ d6 @& m$ ~1 Pvoid MD5Init (context)
/ v9 `! ^% G3 k2 PMD5_CTX *context; /* context */
; J$ a( E# D- G" H6 T{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
0 }+ p6 p( i& z. g# L, V. F*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
& X: u/ l( Y ?! P& J+ U} y# r2 D Z: }
- Q3 g$ E' l9 m# Q2 w+ u- p5 `
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
* d7 _, G* f2 O1 T3 y" rvoid MD5Update (context, input, inputLen)
! U6 f5 i& }; K# x5 q0 TMD5_CTX *context; /* context */
* f' H0 i5 s" q7 O$ \/ |& n* dunsigned char *input; /* input block */ t, N2 {$ B$ Z3 M- V& B
unsigned int inputLen; /* length of input block */ 8 K# g9 a7 m0 V
{ unsigned int i, index, partLen; ( ~' g4 }! F H9 ?
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); ' S2 @5 ^. F+ U; w. ~
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|