|
|
#include "global.h"
/ R# c3 | ^5 l4 a3 N1 h# X#include "md5.h"
, x( x, F! c' g& F; m9 s7 } ) t3 A' x) D9 b. P) r
/* Constants for MD5Transform routine. */ ) R: M/ C9 P4 y9 I! A5 W
1 X [- w2 u- q, [4 {7 N5 i% n* n 9 |$ K' V6 Y- [# O0 [
#define S11 7
* L; ?& |2 ~, |" o! i5 B9 L( Q; O( z) n#define S12 12
4 c+ ^2 l! }) {" R% I2 {#define S13 17 $ g5 Q c2 x& Q- o5 q0 f
#define S14 22 & |5 s4 Q0 k: B3 Y
#define S21 5
* S4 I9 k$ S0 l" K0 V4 b8 x8 N#define S22 9
! @5 {# q, m- q* A) k# r( G#define S23 14 8 n) S4 c, E, m5 V6 }" m
#define S24 20
3 {. c, I L( v1 Y% I$ s N9 j$ Q#define S31 4
1 L; I! y. A; h; \6 C#define S32 11 : ~& j8 s$ I! k5 m) a! B
#define S33 16
0 x) ? D: m; w#define S34 23
7 O6 R* K' g) d( k5 G; z3 q+ @#define S41 6
! e, K l+ p3 |+ `6 q6 O$ \#define S42 10 1 z, T2 d% Y9 G! L" ^
#define S43 15
8 p# c, e5 [! N Z* b- \#define S44 21
# l4 P; j: a, V 3 v0 A- b9 m" @" |0 m2 Q. i* M
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
% |- n1 @+ N7 ]; fstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); # C% t2 T5 m( T/ T. T7 e
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 5 @' Y& N/ U/ H9 u: P7 I- Y
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); 9 ~) A! v, ^# v% _5 i
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); & Q0 p- A4 b$ P0 q6 G
2 A/ G& \! e |5 e2 ?: |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
4 q3 {+ f1 {8 C( m7 M! w# Z};
3 A: L' X* }% Y, B, } . x$ j4 [2 t# m" a
/* F, G, H and I are basic MD5 functions. */
' p) e3 D& t _# Q" f2 Z! R#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 6 U) x- {- j; m$ O5 Y6 H* J+ A2 ~
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
; A' s' A; n; c#define H(x, y, z) ((x) ^ (y) ^ (z))
; P2 ]9 k7 d# H0 D#define I(x, y, z) ((y) ^ ((x) | (~z))) U$ [7 S* I, @* I1 k
8 ]8 G* v9 K$ u4 b: S' C' {2 R
/* ROTATE_LEFT rotates x left n bits. */
8 ~( K: O% z3 W' ]& H8 E, |#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 6 J7 J# a, z8 v- m
% ^# i* f# N' ?
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
- D/ I& s+ u' BRotation is separate from addition to prevent recomputation. */ : B" A8 P- z( q( E6 e; Q2 Y& ]# o/ s
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ! O1 }% o4 Z4 M6 V6 q
#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 r/ e+ O" |$ q
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } : b7 z. A: ^2 G- X" ~: Q, P2 M
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% Z* e0 D0 ], O: x3 u
$ T, n9 ?2 C0 U1 ?- ]- K/* MD5 initialization. Begins an MD5 operation, writing a new context. */
8 G# I u& |; O5 \7 U6 mvoid MD5Init (context) / H# P. q% f: Z) F! }% R0 x
MD5_CTX *context; /* context */ 4 B1 B% E( l/ c1 v4 F' c: N+ c4 V5 p3 F
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. , s) u5 E% u6 r9 Z7 R
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
$ f& s: E0 w5 u0 b, c0 p( E}
! o- g3 ?) n. r: r3 { ^2 b) ^3 s) Z4 M
1 c0 `8 G i/ v' `/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ ) w' n% ]9 ~' g( m# [4 C
void MD5Update (context, input, inputLen)
: Z5 M0 L6 |- V. `2 _MD5_CTX *context; /* context */
0 M, _; C$ e. t: @unsigned char *input; /* input block */ / ~, a/ U* T" T3 f3 Z
unsigned int inputLen; /* length of input block */
7 Q- D4 ?1 j7 B% z+ ?{ unsigned int i, index, partLen;
8 G4 ]* f& c) r4 ]7 ^: {; g /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
9 c$ e" B6 r" X /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|