|
|
#include "global.h" 7 U% \& {* N7 C4 v/ }
#include "md5.h" ' ]! p' Q4 m1 V
2 g3 Z2 Y6 M" a; B) W/* Constants for MD5Transform routine. */ 9 |$ M- d- |+ `
; [) J: A; [' f1 [1 W1 b - `$ z# R7 N7 B. U6 }0 q+ D: r
#define S11 7
4 N) y9 w n l0 N0 a) ]#define S12 12
3 x; u% X! k) N7 q' T6 p/ m#define S13 17 8 M T, a9 I0 B2 B* n# }* c7 g4 j
#define S14 22 $ m5 v. A- Y4 B. y, C' d
#define S21 5 9 s3 {/ a2 y' N4 }; u+ a- w
#define S22 9
, {2 f: w3 c1 o' A" X8 V#define S23 14 $ _' v8 S/ E: s) b. b' R
#define S24 20 , g- l8 U# y& e/ `& ^
#define S31 4 1 a3 w) Z* u R% x, W" D6 ~/ T, M
#define S32 11
" y. j5 y1 a# a; G# k% i9 @#define S33 16 2 O4 ~2 Q @1 a' h
#define S34 23
* _. e7 {) G$ q, U. N9 N# f7 S#define S41 6
" _5 ?/ L. c8 V' L#define S42 10
- O; C0 I; d% p) ?#define S43 15
2 ~" y6 m5 M8 Q5 M! q, |7 R/ R#define S44 21
, {1 C1 ?5 T w n; v- L2 t: ? 5 R+ L2 \+ n- ]% ?! p; |$ _9 Z0 |
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
1 d& ~6 }8 K U. ^static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); : o' s. p* F; y1 P3 x2 B* t
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); % W* ^/ I! M# _3 W
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
/ ~' o8 n* Q n9 I6 p( C% X( Istatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
& \% r; G5 J% f
8 z2 F" |* `) B! K/ g$ s! Fstatic 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
; D- s, R5 B% Z+ }3 \5 i P9 s# i}; 2 A/ U; K7 ]& ?7 b/ V
' y4 p* G3 \; z/ A# n8 Q! N- w. S
/* F, G, H and I are basic MD5 functions. */
2 \$ }2 ?) {: J. O: v. P/ a#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) % l5 ]) a6 S* i/ u! Y
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
. p) S1 |1 X, L" s#define H(x, y, z) ((x) ^ (y) ^ (z))
2 n5 k) _# ]; x2 ^- n#define I(x, y, z) ((y) ^ ((x) | (~z))) * y5 @! ?4 @8 n8 M
. X& A: i: ?1 \) `4 H/* ROTATE_LEFT rotates x left n bits. */ 3 o r3 d- i, `! P% N, E: V4 @0 f$ `/ ~
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 5 J5 M }* J I
! z8 q/ k- f0 N" B
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. & _# s7 b0 x) V! Q. q
Rotation is separate from addition to prevent recomputation. */ ; ]( E7 L4 w. Z6 J& [2 Q. [
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 0 G% f* O% A" N j. @6 v- y. 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); \ } ( X! K% c, ^3 a, l; }0 U8 X& r
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 3 d y: y! r5 i* N
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
' s, @" ~6 @9 ? * K: k& N( T- J6 y, H8 |$ ~7 M
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
+ j6 k1 n4 J$ T3 s6 n" {6 }6 pvoid MD5Init (context)
: w0 F/ q' R* h; ~MD5_CTX *context; /* context */
/ S, j# o% B" [0 w{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
. A" `9 C; D M6 G& `1 ]3 S*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 3 a' z9 \- J% e3 P/ J7 I
}
* o7 o7 N1 k4 f5 v: p" W1 a
+ [3 m8 {6 T. J# P& p/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
3 ?/ B* J; q5 O& ^void MD5Update (context, input, inputLen)
[4 T- u/ n% G2 D( E# \+ gMD5_CTX *context; /* context */ 8 ]% ` D. D6 Q6 ^# H
unsigned char *input; /* input block */ * g8 n. D- c* K# S- j; R7 _
unsigned int inputLen; /* length of input block */
1 W" @8 L: n* V, q; l& f( Z3 ~4 ]{ unsigned int i, index, partLen; ; b( S, C- G6 d8 O/ S" ^6 _5 n& I
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
4 S* W3 I! d: I) d6 B+ B /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|