|
|
#include "global.h" 9 c4 { ^% y# s. P
#include "md5.h" # d% T' d" Y9 e) k! F0 ]
1 r; U7 Y5 s7 M8 e5 B# m
/* Constants for MD5Transform routine. */ . u5 N& ?* T) E3 t8 P! G
( G1 `. J# t) \8 Y
: q3 u9 ^& g5 `0 @/ f% x
#define S11 7 1 J, t: Q# v! {, v* H _
#define S12 12 0 ]2 F) u' R- F6 N$ @2 O) m0 m) }8 E
#define S13 17
3 a, ]! u- d, l1 c6 [#define S14 22
& D* T Q0 w* I$ h6 u# e, ~# p#define S21 5
( h& P3 X6 Q3 U#define S22 9 9 l9 b0 J" _& ?. }) ^- L( w2 e* k
#define S23 14 , U$ I# r3 w3 Y/ X2 b( x
#define S24 20
0 w3 i0 k) N9 \, P7 D#define S31 4
, B0 r& k! j2 B7 d9 y#define S32 11
+ b* o% |: v5 q; H8 D9 q#define S33 16 0 E7 H( D" L& D7 V# B/ b( m9 }
#define S34 23 5 q1 x( A, v6 E& o& X% J
#define S41 6
5 u) S0 w, b5 h9 o" s) t% R! D# |#define S42 10
* ]1 r. `( X9 S5 s#define S43 15 5 b8 ^" k8 o) g8 m) ^0 W
#define S44 21
Z- N$ [+ ]+ [+ d1 D) N: o" ]' T% B + h3 P4 A; U: n+ |- f
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); # Y% _7 N' E! c& E: B
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 8 M' ` [0 r( w/ O& g$ R
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
+ g2 s+ b2 @ @$ ystatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
$ D& m1 o2 i" V; {) A6 v2 H+ i' ]* Mstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); & b3 ^3 K5 a# ]0 ~& ~$ e( n
% ]6 G8 U. e, b5 E( g: g! o! M5 Estatic 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( W) Z H; M, C; A" f3 @};
0 N5 w5 h1 Y7 U/ h) F. j: M
% n/ G* `" Z+ z7 f. j/* F, G, H and I are basic MD5 functions. */ / w% Y9 S8 D: G! M% C3 y& n. A
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 8 v5 H# q* G h
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 3 g* n1 m. j' }: R: `
#define H(x, y, z) ((x) ^ (y) ^ (z)) 3 F1 O( e5 n6 n- h
#define I(x, y, z) ((y) ^ ((x) | (~z))) 1 t9 c! p6 c# K2 z; H) R( b5 U, E; ^
7 S- I N* `: @1 C& H! m4 @/* ROTATE_LEFT rotates x left n bits. */
( Y# A- o, \* _4 }3 b. V" b2 U#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 3 \2 @: A: U9 z* l
8 R, D8 y; w8 j# [
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
4 b$ y( b8 [+ ?; \+ I+ WRotation is separate from addition to prevent recomputation. */ " A: i/ j) \( e! w$ J4 c: Z# G
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } % K+ |4 d) E; ?$ x
#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 Y! _: ^4 ^3 }7 o
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 6 N" n O( e3 N+ y; A2 g" j
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } . w0 G3 B2 X$ d
6 X& g X7 y6 n# ?# T1 P
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
, e4 G+ @- k' i( o# }' t" }9 ?void MD5Init (context) 0 W* a( D$ ]7 a2 o
MD5_CTX *context; /* context */ $ ~' ]9 k4 g6 g9 Q9 v. ]3 Y9 S& S
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
+ f% @: s! K8 o5 [5 X1 h: ~*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; ! W- H8 V [ S* {- n! J
}
5 P( T2 V1 a1 y; E & a& p, M7 {. V6 P6 i, h8 |
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
# G6 z* ]8 k/ ~void MD5Update (context, input, inputLen)
' r. z" o9 N% Y6 e! XMD5_CTX *context; /* context */ % P4 u$ R) M6 ]9 a9 n7 i2 C
unsigned char *input; /* input block */
9 L6 a" O* W3 N; b+ j5 {unsigned int inputLen; /* length of input block */
7 x& G$ a! S0 o7 v* m, ^{ unsigned int i, index, partLen; 5 i& D9 z+ h9 V3 A
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
8 {# N0 s/ h B7 T* v+ }9 k6 x: R2 l /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|