|
|
#include "global.h"
& A( R( H% h- D: H( t* b#include "md5.h" ( z4 y$ w1 N$ D
6 {: P% p9 w% y N6 u: J" F- `5 I/* Constants for MD5Transform routine. */
; C! M( d( m" o/ q/ B+ Q' F
9 ~4 z, }9 m7 ~$ k, H: a9 b # {% a8 k* e& {- ] P& o
#define S11 7
0 d2 a/ {0 b& C+ J) O0 I8 X- A7 E, r#define S12 12 ( ?1 B! F m" _/ A) u! n
#define S13 17 1 ~7 R* i1 {( d9 n6 V
#define S14 22 ; W& `6 u* v* `4 e$ Z% {
#define S21 5
* P, r; j4 |" @2 W#define S22 9 9 O! P4 ?- x& N/ r. v) g
#define S23 14
( z+ G$ N0 V% Q6 b$ @2 V0 j2 V#define S24 20 - K/ F4 X1 v$ N
#define S31 4
; A1 p; k0 S& U5 R" A" j0 \7 U#define S32 11 ' I+ M; C* w. ] L" \3 r
#define S33 16 % |3 F0 p* g8 p8 |* S5 b
#define S34 23
. d( W# x; R3 _4 i; M0 V, Q#define S41 6
% @) R6 ]) P3 a0 _' F0 g: ]#define S42 10 3 L: Z8 C: c2 M3 t6 [
#define S43 15
+ ^' ^6 w' A0 n3 V#define S44 21 1 H, J8 X2 I, _! J: ]# S
$ F1 Q7 n/ [( Q5 B2 C0 _1 Wstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
# s( Z& _3 x8 `( t0 F% I) j' e( cstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
, L& X7 u# M5 q* A. p& X4 P! W7 estatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 5 r, | p4 T" b: |0 A
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
; @! ?+ r* d W9 w; kstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ' q6 ~* S5 [, A
/ `3 b4 R* s" A& q
static 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
1 E& J2 J! E' F& G& k6 |$ q. b, h}; ' x; [2 S* B. O8 c4 d
2 D, N! m, ~' I: z
/* F, G, H and I are basic MD5 functions. */ 2 `: P6 s$ t7 `" G$ P* w9 I w$ `
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) $ |7 V4 g! o1 O1 j5 @5 T& |
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) & H0 }, }' j; P; i, V. k
#define H(x, y, z) ((x) ^ (y) ^ (z)) 7 ]; K8 I5 u7 B U7 w8 m
#define I(x, y, z) ((y) ^ ((x) | (~z)))
% X/ ~+ W% @4 S( {' L% i8 [
6 U/ ^, ], a7 ^; _% Y/* ROTATE_LEFT rotates x left n bits. */
/ X# ~+ Q; w! B. v* G; ^1 C#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
. H# d' o; E. m; A ) J) r; b' n0 Q9 ~- w2 O6 E
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
' ^+ W* d: n; Z1 I3 fRotation is separate from addition to prevent recomputation. */
0 H5 J- T- m3 i#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
6 O3 V1 a; x X" d+ }$ J- F& 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); \ }
& a5 y; w8 E7 d4 P; i, t$ b, B7 ]+ b#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
5 g$ Y/ M: z. ?& E6 ` g#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' l! C& ^" U( Y! C ' o; Y1 d, e- c6 t K
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ $ B5 C3 c( j6 ^. n; x2 [6 ^
void MD5Init (context) " Q6 e. c1 p' l# d3 h# X/ Q
MD5_CTX *context; /* context */
8 p! C2 F ?" O9 J. z{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. . X1 o5 e, U5 q) s
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
0 \4 E+ J. g, |( _) z9 @} $ `. j( Z' y9 O9 e% \" f) p! s
# ]2 k! J2 o: u3 c/ `2 b. j4 h/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 5 m) A- }) N1 |. j9 b- c2 S. Y
void MD5Update (context, input, inputLen) . v9 ^0 q3 H6 u
MD5_CTX *context; /* context */
: _( z0 ~- x, {+ O! Z# @; Yunsigned char *input; /* input block */ 1 S9 \* C- o0 n7 d0 y1 Y
unsigned int inputLen; /* length of input block */
5 A6 s5 q& _/ |( d6 q7 `% v- n{ unsigned int i, index, partLen;
7 ?# u8 e3 A' a6 g6 q/ T /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); + `" f6 `- [9 h6 {
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|