|
#include "global.h"
9 ~8 w* o* ~# L#include "md5.h"
: Z: }! j0 c5 @3 L } + ^/ n2 Z% h( d) w# l# s
/* Constants for MD5Transform routine. */
+ D" [5 L2 \. q! d) S8 L, G " w( z/ @# n) t# d
) g( m2 M9 e' g! Y% w" }
#define S11 7 " K7 s4 z7 d9 ?- ^" H7 O' Z1 l( X
#define S12 12 6 U! m- s' ]5 A w
#define S13 17 / _) d5 H) c, {7 l6 V" _# @0 v
#define S14 22 2 v' w4 c: a3 I2 v; B7 Q4 p$ Z
#define S21 5
/ {+ S f S0 a3 Y#define S22 9
$ {. F, b1 O1 }#define S23 14 ' g) A7 P/ m+ P9 p; P# |, p0 y& J
#define S24 20 " f) C; R' U6 g, a7 U- o' J4 K+ C
#define S31 4 & u* @1 W# D7 Y/ ^( a9 J! n; }
#define S32 11
/ Z' @$ A M* `& y* u#define S33 16 & o- ~" v0 N' Q) u, s" X
#define S34 23 0 L/ m/ \3 u4 {& p# W) T4 l
#define S41 6
0 t& k: H# P& i#define S42 10
- Z) ?, V P% O$ C8 {#define S43 15 + a$ S; p( w3 d/ {6 o0 q1 B
#define S44 21
7 p: u) F- o8 e) X8 T 3 | k3 m" Z6 p! q
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 8 H% i' ~2 x b: u/ j: C
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); * r0 ?( T8 R4 Z F6 u: t
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); 4 J/ ^: W3 i6 H& J
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
0 ?. s2 A* Z" D( gstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); $ \/ ^% }2 x5 }! p' U" V* r
5 ?! U7 M" o6 [' lstatic 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
9 H! L0 V h& d. ?' c}; 4 C9 \( O4 ^+ c3 r
3 _, {9 Q2 Q4 ]# q" D3 f7 Y/* F, G, H and I are basic MD5 functions. */ $ {' J9 E) X, J, y6 X1 c
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ) }; G1 R5 |4 W0 }6 B9 S: z: B3 [
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) ( K: R1 Z% J+ r+ z" z& Z: Z
#define H(x, y, z) ((x) ^ (y) ^ (z))
o0 @5 R- n. ^7 q#define I(x, y, z) ((y) ^ ((x) | (~z))) " f' w6 u+ {# {# _' e
, q& _% j" ]6 R! l( I/* ROTATE_LEFT rotates x left n bits. */
" m/ m0 W5 x3 q4 \#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
4 m" e8 H3 G8 C) G2 \) q0 f
9 l% P% r% ]3 ~' _ t' R9 I$ z/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
7 S [. O/ M! n9 n0 _, ERotation is separate from addition to prevent recomputation. */ 3 k% @2 x" p! y
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } , ?" w [- O" f; V6 t& `
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
* C' q6 E9 [1 J$ E% N- r: ~* b#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" P- z: X+ v3 l$ d; G/ s) X, `#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
9 I6 m) N; r8 j5 o
* S9 K) z: Y: e) o+ b: _' T+ c/* MD5 initialization. Begins an MD5 operation, writing a new context. */ + r O* `% e. s) @* _' H7 ^" v+ S3 i* W& V
void MD5Init (context)
1 F" v) R# o- J/ L: t- l. k7 eMD5_CTX *context; /* context */
9 v- s5 h; U" Y8 k{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 2 ? l, X1 }" P/ }& N
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; ) u& a+ y; y4 E# q! Z! Y
}
' g2 v; J! I! Y9 v7 c
# A% u5 {1 A' V" U+ {+ K/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
" T& J- j8 U( n" R5 P. W( R3 xvoid MD5Update (context, input, inputLen) ; F3 H- d R7 `0 W. r" l9 R" F
MD5_CTX *context; /* context */
7 c" @$ ]7 |6 \; K6 hunsigned char *input; /* input block */
J6 ~6 w# G& sunsigned int inputLen; /* length of input block */
; u: N1 O5 r/ T! L+ I# x! P' p{ unsigned int i, index, partLen;
0 Z/ m6 {& g, X! @& z /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 4 e. @. d" l; @+ D
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|