|
|
#include "global.h"
+ d5 y8 w2 I1 B9 ~/ {& U#include "md5.h"
$ A R) t$ o# l/ Z2 {# ^& w4 ^ : O5 A% y+ S$ Y" o
/* Constants for MD5Transform routine. */ . o) e w* y: }- W# \
]- N4 H( b' M( x5 A
, w0 v6 ~# ]/ G- o, c# O# ~#define S11 7
& j4 w" Q- l. d1 W# G4 Y" K#define S12 12 4 s3 |! q7 S! Z
#define S13 17 + }& {* l5 ?7 f& h% X' H
#define S14 22
8 ~* G; {& D" C$ ~#define S21 5
7 u9 K0 e8 w. ]% m7 e. `' ^) z& j( q- w#define S22 9 * r' o. n2 b; X" a
#define S23 14 $ P+ l, y* l, r0 M$ o* ?$ y: A5 H
#define S24 20
' r x7 w' V' a; M* \; d#define S31 4
* b' {7 J, _" y#define S32 11
3 J6 t' n1 P+ E: i0 p. W' z#define S33 16 / V8 s$ H4 @& g8 q0 K( k: M
#define S34 23
3 @) N. L6 o' `$ x! m#define S41 6
$ T0 X; L5 H1 X: @#define S42 10
( r2 P3 K2 v) d, H1 i9 W) }#define S43 15 7 ]$ y2 @+ D* v' D, u: r
#define S44 21 ' F7 {+ @' z7 `' u, @
5 D2 y y2 y0 y: _" d$ e
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
, H g2 r) H. l7 s! n3 Wstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 9 I; ^4 U% O' [ Y9 n# q5 W) c
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); * N! R# x+ o6 r% x4 f9 w( F& L
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
c7 |" C4 f2 A: gstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
& }( R$ g8 D5 ?6 y
2 } Z' x! N' i. 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
! |4 O* \1 [9 V6 o" |% |# A$ p};
2 }9 V! Y; P1 R" p/ `7 h
% R% d4 O2 P7 P/* F, G, H and I are basic MD5 functions. */ * T" {* J% \0 Z
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
. C- |, Q& P9 s2 G! \& Q; z( N#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) , U* ~8 w6 H9 t2 o
#define H(x, y, z) ((x) ^ (y) ^ (z)) $ a9 B) ?# n G
#define I(x, y, z) ((y) ^ ((x) | (~z)))
- h* W( b: i+ P. _6 W0 T : a0 ?( g0 [* M; Z B2 }3 g
/* ROTATE_LEFT rotates x left n bits. */
7 c N4 @* ?3 Z, H t8 Q2 {#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
5 b. ~2 M0 C1 A _8 [8 N
2 k) R, x% }1 w" ^" Z# u: o/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
! R+ S/ A! G6 ERotation is separate from addition to prevent recomputation. */ 5 K# f. K$ N# R# M, O7 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); \ }
' t | S/ N) a& l! F! I X#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
. ?0 w; L6 I6 |4 z#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
$ y* \( Q! ]4 m3 A#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } % u/ C% _+ r; C5 C/ V' M
5 a4 N2 e8 I i+ m8 M9 Y/* MD5 initialization. Begins an MD5 operation, writing a new context. */
5 b0 g6 `6 k% b) [5 A9 jvoid MD5Init (context) 3 \% u) z" {1 V/ E) c" u6 C
MD5_CTX *context; /* context */ ) H8 d- B+ S5 A* ]
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. ' B8 ^/ J6 z+ }: b
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
' P* n: Q$ m6 t3 B4 @* Z}
4 S$ K- d) R H7 k3 p 0 X& A& |! U% L/ f, A
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 8 X: `+ ~0 K, D& F5 G1 j
void MD5Update (context, input, inputLen)
5 R3 q3 Z5 F; bMD5_CTX *context; /* context */ ! N8 C3 R+ D8 p; `! S g
unsigned char *input; /* input block */
* m* \* U. N% |. F, Iunsigned int inputLen; /* length of input block */ 0 s! n5 r( e r* V. B2 V
{ unsigned int i, index, partLen; ) C% U4 z) P/ H! L
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
7 t; p+ k5 f2 [# R4 B! v$ U1 L; @2 E7 e /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|