|
|
#include "global.h"
9 G6 Y5 K) R# O6 W#include "md5.h"
& C8 N* K7 |- Q- k3 ? * ~2 K% [9 a( Y
/* Constants for MD5Transform routine. */ 0 J. j/ u; p/ [
; ? a- Z3 u) G% E* p
- {9 g0 _1 \6 `#define S11 7 5 d' F( n* B% A0 t# }
#define S12 12
* z' l1 m, k N8 T# a/ G* L#define S13 17
/ W" Z, H- I$ J3 X#define S14 22 7 y8 I- T( i; h4 T) T8 x% `% O0 |
#define S21 5 ; H! Z3 |, f: r; M2 Y5 b
#define S22 9
3 k# K' R f" h$ P#define S23 14 Z, w. u5 k$ U+ T, r3 R: u
#define S24 20
6 k. u5 j8 Z) z#define S31 4
. W: P- k+ Z4 K#define S32 11 7 t' Q4 u* J" u
#define S33 16 " r" M' O8 B8 T4 G7 v5 w
#define S34 23
5 |! e- d, y: T- l' F/ v2 i- M#define S41 6
5 d" Z* R4 E ?7 u* ? [#define S42 10
& {- {2 y6 I" l" v3 }) o#define S43 15
: ~# q7 _: d* ]- E# @#define S44 21
- t* l7 d" U, y" i 0 S+ z0 ^. c3 q& w
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
. T- L0 P1 d8 `2 F# F# F- Bstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
9 y8 x2 k/ y9 r7 n; J4 jstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
2 i, z) [0 Y+ e) G% ^" @static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
+ P7 u. a- o. C9 G" I2 I' Wstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
[# N1 n2 M# t' E! \* E( B3 h3 G7 B
4 u$ m7 @$ v3 o/ |1 d4 Z' nstatic 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 2 X& `( Y7 g% W! i& p
};
* l; ~ G4 @5 D5 |+ z2 _8 \0 p 3 x s2 Y+ `) I/ S& u3 \& _
/* F, G, H and I are basic MD5 functions. */
& C; o& ^ C4 b' D' x* N: a#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
! Y" I$ W# n- K% Q5 O#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) & b( R* J- a* f' \+ z4 r% ]3 T
#define H(x, y, z) ((x) ^ (y) ^ (z)) , y, Z6 I8 v5 }
#define I(x, y, z) ((y) ^ ((x) | (~z)))
6 s# ] S% t. L; j( H- ^
7 f6 e" Q! A8 R( F. M/* ROTATE_LEFT rotates x left n bits. */
9 g2 t, A; ?$ Q#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) & b S5 y6 e/ q' ?; k7 \- p
9 }: o1 l2 M0 A
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 3 A5 u* Y& X2 s' ?
Rotation is separate from addition to prevent recomputation. */
7 F$ s+ |$ n/ ^" _8 b0 w6 I/ X#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
% [: \* d: A1 e& x) z y1 i* I#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 7 l7 U8 c) z3 f v
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
0 i. q- O$ Q$ d#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& M/ v3 _: {$ Q5 j + l) f7 X* i+ }- G6 ]: {, R
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ + n: ~$ O6 b0 i- ^5 S
void MD5Init (context)
2 b9 y$ O; C4 J/ HMD5_CTX *context; /* context */ 7 G3 F6 E" C( F( m# U9 i8 Y4 ~
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. * ~& c4 G; n6 o0 d5 e4 t
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; * S2 t0 n ]" f3 R9 p2 |. D
} - Q+ m2 j# L4 }1 k6 C8 k( Z p
1 w1 }5 s W& q- g9 I
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ , g' A( t! v' B8 |4 C
void MD5Update (context, input, inputLen) , Z& V0 M) K) }$ U+ Q8 q: m
MD5_CTX *context; /* context */
7 O9 K. p. q# E: @( {unsigned char *input; /* input block */ ( X3 F, j6 e" m, ?) ~7 a1 y3 O4 a
unsigned int inputLen; /* length of input block */ 9 h8 {. `3 D: ?* d, v' W
{ unsigned int i, index, partLen; 7 H( ~: z" q: y3 r$ P
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
. G9 D: U* l* w, t& ]+ G$ o* \ /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|