|
|
#include "global.h" 8 h8 y% d) b5 h- v2 J
#include "md5.h"
: s, e/ F$ }3 ^! n" t1 x3 d' U S( {
: W1 q5 |8 E9 w+ K/* Constants for MD5Transform routine. */ * g. x3 r. r* x* }/ w1 X- h
- r$ d% }, v4 S) H0 {
) ?6 ~! B+ N; ^, F' H6 r: n2 V#define S11 7 - X4 a0 j* \5 V) {
#define S12 12
1 s8 z8 y- Y9 P9 S; m6 V: ]#define S13 17
# d, I# {& o- Q' \8 l1 [: j#define S14 22 8 Z* c; J1 }: A6 t& y3 D
#define S21 5 $ n( X1 N8 l8 u4 g. N) o
#define S22 9
# p; c* |7 a. ^ [5 p" E6 z#define S23 14 " Y4 s- [8 H' Q7 f! c
#define S24 20
' B! g/ a' \, X, x. s#define S31 4 . n0 d0 j l9 K
#define S32 11
% ?2 W6 G$ v! R5 R+ O3 Q#define S33 16
# U' B# @3 {8 e* n, b; K1 v#define S34 23
( |4 @! a. N$ R2 c. h#define S41 6 ) s3 F' G8 A: y
#define S42 10 + ?+ \ {1 _2 \
#define S43 15 L# h# |" y" U" \1 K; A; n2 c
#define S44 21
( t, \6 j# t6 J( X ! h/ F* F2 c* E8 o1 u: a4 _
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
% ^& b2 V7 q) j9 ]$ x0 v; dstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
7 p+ _2 O7 t* ]" ]static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); H/ N5 ]/ ~" {0 ?, E5 \! L9 Q
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); ( O* m @$ N& o
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
7 [+ t: r3 ~; A. U6 J6 b
2 j9 r& s% C; \/ j( `2 Sstatic 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 2 l( n. ? H& A1 o+ Z
}; 2 h; [% R9 [8 H
m; d1 Y1 a& P3 t5 Q7 r) ?/* F, G, H and I are basic MD5 functions. */
0 o$ l# w( `; o% h }#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 2 ^4 y' s; l8 ?( j3 u' E) n, o
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
4 p9 D. `4 l; H7 w9 J, Q4 n; a z#define H(x, y, z) ((x) ^ (y) ^ (z)) 2 {: |$ M; _+ |6 d" Y# M$ A. p
#define I(x, y, z) ((y) ^ ((x) | (~z)))
8 j4 o5 u, w" Q9 V$ F# G
; G, D7 G0 H( H! F& S- ?: D( n8 Y/* ROTATE_LEFT rotates x left n bits. */ L* D" m: p3 R
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
& p9 _- f$ _# S# ]7 L# S7 V2 | ' P6 B' M' E* s1 b9 c
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
* V/ w4 c! M4 D$ T p* yRotation is separate from addition to prevent recomputation. */ 1 Q1 G& f" F( u1 }+ f- r6 ?
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
. C& q3 X4 W! ?#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } : z3 l$ V% j5 I' u
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& L/ b3 L2 I p3 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); \ } ) X' Y# e* [& c
1 f: o, S8 S5 q& O! q
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
Y3 O6 W. D N/ E4 Evoid MD5Init (context) . I. W! E! b# X4 w, N
MD5_CTX *context; /* context */
( J2 o' c5 Z4 y$ E, ~3 ^{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. + H5 s6 J2 o8 i$ i7 V
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 4 H9 q% p% F4 G; _; T9 h# j
} " ]" V1 ? z" t8 Q6 r
' v! t; Q+ L5 a( `5 F8 T
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
/ G/ c+ u8 Y h1 Q( Q! N* M! k9 y) xvoid MD5Update (context, input, inputLen)
% O- _6 R$ @) j! B( f4 F+ ~ M7 oMD5_CTX *context; /* context */ % V5 x8 i* L$ q, s" b
unsigned char *input; /* input block */
& r4 @: F% y: C2 funsigned int inputLen; /* length of input block */
6 ?) {6 o# N' i) s{ unsigned int i, index, partLen;
+ d) W6 d% L6 `! b* r! i /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 2 o3 D0 d, ~+ ]* m
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|