|
|
#include "global.h" % e a4 F; S" |
#include "md5.h" 8 O3 k7 m% m, W4 F
4 d, T# |) U5 O0 Y* J
/* Constants for MD5Transform routine. */ & T( S* b: C: X6 {
- \# W+ C- S0 }, |+ i. @ % G# t1 [9 M4 L3 I Q
#define S11 7
, _. F) V' v# s4 F( W" k P% p#define S12 12
4 C8 U q0 b4 {- d5 z2 E#define S13 17
- W. O2 t: i9 @1 U8 c#define S14 22 + y9 t+ i* @ C1 p: z- f2 e
#define S21 5 " F& j5 h" I- Y$ z# i. u& O
#define S22 9
7 _+ Q6 h L8 [( G, S9 R ~#define S23 14 2 \- l P% \8 f: E9 M
#define S24 20 5 O" D8 Y: q* a) g
#define S31 4
; |5 C* x- `) j! p% j6 _#define S32 11 a; z4 k, w2 `* ~; Y9 X3 Z" i8 _
#define S33 16
& a+ { T; b% E9 Q6 p, w ^+ D' M' n#define S34 23
6 V; N, Y/ H7 h% u#define S41 6
Z6 ?' P+ J- ?+ [* D, U#define S42 10
' a0 _( F$ B. Q& @ m, N#define S43 15
' m% _, Q1 `) ~* @#define S44 21 ( P" T$ z9 B" ~& r$ z& T8 ^% c
$ O. o. B9 `3 t6 v& [! ~$ |
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 1 b. i* ~# R/ k, v- I- Q
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
1 J* c9 l; P; F3 Ustatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
9 K2 s; v! h2 X% H' O' ]/ @; v) | h- T5 u3 rstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
3 @' J$ H- H }3 vstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); ' O3 z; u( i* U- z
3 \) n3 Q1 ^1 c* k" xstatic 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
0 m+ [) h& G n: }};
- e% ?5 H( U# c: _% c
, v& ]% N$ j8 E: ^! X/* F, G, H and I are basic MD5 functions. */ - s2 o% |# o2 a1 R2 ]8 a6 w) u# u- J
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 6 s7 ?% \1 O& v# Y/ c+ @
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 9 }+ N: x2 @: [. ]. x
#define H(x, y, z) ((x) ^ (y) ^ (z)) , U2 v9 ]4 L. b, A' a
#define I(x, y, z) ((y) ^ ((x) | (~z)))
- Q7 o c$ v5 f# J- h- x/ d. ]9 X % q+ h/ F( [; Q. \" A E5 o; d
/* ROTATE_LEFT rotates x left n bits. */ 4 F1 l! y. B2 [! Q5 ? a
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) $ h: j+ L1 w k* c7 j& w2 G
: T: M* d. ?9 o* |( z/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
2 g, J2 E" A' g! L' w; z9 b0 s$ mRotation is separate from addition to prevent recomputation. */
0 o* v7 T* \* }& r: T0 V#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } / P) o4 o f* j& N# \/ ~
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
2 S$ J3 `* b* c, U5 \% Z5 \#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 9 t$ U6 @" L0 _3 {
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } - ~! g: z! u6 @1 \% `- t
+ R8 v+ v* O7 W5 v# i) v z0 C) `/* MD5 initialization. Begins an MD5 operation, writing a new context. */ + g# A" W6 z8 m: B
void MD5Init (context) {- S7 X( s% m& J- P5 [9 E. Q* C
MD5_CTX *context; /* context */ [9 G2 R# G0 ?; @" g; x; h
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
- I7 p5 A/ ^: |*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; # p% Y- n$ J, _' u
}
" T: @4 j0 R9 d% _3 h& I
6 |4 g% X! T5 k6 _# E9 i8 B X6 _6 H/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ / u' T$ ^8 a# o) S
void MD5Update (context, input, inputLen)
4 I4 [! D+ C; T$ f9 ZMD5_CTX *context; /* context */ 2 e- Y [3 a$ b* J9 A
unsigned char *input; /* input block */
$ K- i& o1 c4 s( z0 F: N+ X: H) yunsigned int inputLen; /* length of input block */ ! W9 Q) @, w1 _9 Z# e, V, ^9 V$ Q
{ unsigned int i, index, partLen;
5 G1 C( ^- ?# S- h* U/ O /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
S2 X: O. N3 q! b /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|