|
|
#include "global.h"
1 ~' r& L0 f% q5 N#include "md5.h" 6 b% {1 i- O Y2 z
9 A6 K6 R& b9 t- E6 V
/* Constants for MD5Transform routine. */ 1 ? ?, f) ]( E' _% G
" @) L5 O0 t7 i9 X1 G+ G0 M( `
2 a% R1 _2 I: }
#define S11 7
3 C- ]* ]1 T' U! Y4 M9 y% B#define S12 12
6 Q v5 c& j4 M+ S) ^2 b2 B7 b" @8 T#define S13 17
( n" ]$ J1 y$ b2 F: r#define S14 22 7 y- [+ g5 U4 J0 {* L- o' T
#define S21 5 4 F2 ]7 y$ }( {! E# ?- Q
#define S22 9
5 Z- F% q. c a#define S23 14 , o, O. }4 t- c
#define S24 20
8 G w( i9 [* P5 L$ {, z3 D#define S31 4 & p5 R: H) Z! u: g# h3 o) C1 Y
#define S32 11
& `8 H* t0 _' _2 _5 q- C#define S33 16 ! y1 |# M+ O' m0 m; K
#define S34 23 ( ~4 j. s! X! \& k6 U
#define S41 6 , W1 u' w! c( u/ C( f6 u5 s& g3 |. F8 X
#define S42 10
! l5 }. W. A) S* z7 }% N#define S43 15 4 a; M6 x. r, ~. ?) C
#define S44 21
3 {) J- t" I" M6 p* V 6 _. H) i/ z9 O
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
$ M7 c4 o! [1 V: H0 }" W1 A4 qstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
4 N: i4 {5 v8 W e' [static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
% `8 y) [1 f# u% Y% x; Z9 e, Cstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
4 Q) X+ Q" Q: ystatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
$ l0 M% A8 ~. |7 a; y7 B
, B: ]/ ^6 c" q4 X! Istatic 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 5 @0 J0 H+ k. k" u/ x2 f# q
}; 9 |, H( J8 |6 i& }
+ e1 x8 Y. A8 n, }
/* F, G, H and I are basic MD5 functions. */
3 S7 M- d$ ?, P9 T5 z/ |#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
6 [, l U! {6 O#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) / t; i8 P+ k! O7 o# w7 ?* L
#define H(x, y, z) ((x) ^ (y) ^ (z)) ( ?) h! v5 ?9 p6 V
#define I(x, y, z) ((y) ^ ((x) | (~z))) $ L5 F k' y7 Y4 H/ L+ E
: e$ ^# n/ h# |5 q/* ROTATE_LEFT rotates x left n bits. */
# m& U- m* K* j" ?# P' B#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) , w' |: A; ], ~0 m5 q
& d+ n: W7 O V/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. ' L) e+ k* I: |9 F
Rotation is separate from addition to prevent recomputation. */
3 d* {6 v' r3 e#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+ h# k& m; ~/ G' {
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } + `5 m) s$ E. H
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& ^$ h. ~% v, l7 O" ?0 N) A# [( j: F#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
4 p4 Z5 Y6 k7 M, F+ v0 S# u% ~9 S
- h1 J, k2 {1 r: K6 P; D/* MD5 initialization. Begins an MD5 operation, writing a new context. */ , Z/ ?7 Z! A! W8 a- o3 C4 T
void MD5Init (context) 1 c' Y7 R% Y. @1 l
MD5_CTX *context; /* context */ 5 _1 j7 D. J* l+ r0 Z+ S9 s
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
5 ^( E" H' t3 ?. O/ G8 R5 k6 Y*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 1 A0 T) {6 x' G
}
* z4 s8 G8 f" m& B5 r # D/ c* ~2 {, N p! G0 f
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
! @ X8 Z' d3 {8 A4 I6 uvoid MD5Update (context, input, inputLen) % e. \0 Z" M5 ~6 V# U6 ]
MD5_CTX *context; /* context */ ! x- E! C+ S, m: k3 i) X
unsigned char *input; /* input block */ / t6 T4 D0 u2 H
unsigned int inputLen; /* length of input block */
, }0 r3 Y, B5 j$ H# r9 f{ unsigned int i, index, partLen;
# S% D/ w( @3 e* ]1 ~! M /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
- U. w2 _( i1 p /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|