|
|
#include "global.h" * o8 ~3 c- e U6 @0 Q$ _, n! m7 S6 K
#include "md5.h"
. j# U9 } J9 B' k
* u3 Q c" X7 g9 o3 W/* Constants for MD5Transform routine. */
9 W! r& b; | A4 j; W& [ a* Q
X- ]( s1 I2 D# e+ g. @5 N% t) f) Z
9 y1 [' d" h! J#define S11 7 0 j1 g1 r' |8 q) ~, @) A
#define S12 12 8 b- }( f& p% j
#define S13 17 9 O3 s9 N: k( g2 }6 @& B
#define S14 22 , S$ ^$ c7 {# v5 \
#define S21 5 5 R+ b7 L- M& {- |2 L3 i7 s- [
#define S22 9
# n) r& m/ P6 N3 O#define S23 14 ( S T9 p6 [- J7 A! T! C- L
#define S24 20 ' N# E4 S' K( w; ~( |! W% ~
#define S31 4 + T) y) q. z3 Y+ _5 G: D+ ]7 R
#define S32 11
4 e- ? c' f& K6 ?" K#define S33 16 / a1 p' X5 |$ M( e6 d( r
#define S34 23
W3 B- @+ S- @. i7 j#define S41 6
. s( o# z R2 F#define S42 10 - O2 P2 v+ ]5 G4 ^; S! R- k' J' _$ \
#define S43 15
. `1 `" m( z+ c _#define S44 21
% Y7 I& \9 X+ I+ n1 q( Y
. E7 J0 {% Q3 f8 _' k7 q; Istatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
$ t2 P7 Y; m4 \7 t: d8 V5 N+ Kstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
7 G" J0 B7 X1 r: pstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
. e `+ }) g3 q5 R. kstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
& ^5 ?; U& B: T z( mstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 6 V/ S0 K* c+ P. h X" K
0 m' ` Q5 q9 s9 Gstatic 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
* X) k# y* n4 S9 q( K};
, O2 y* a4 y$ P3 H; d- d 3 W4 @) U0 ]2 i2 R$ F
/* F, G, H and I are basic MD5 functions. */
; H2 }( W- h& }! r% G#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) - w( U w! R% D8 [
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
( m+ d+ s) e' v#define H(x, y, z) ((x) ^ (y) ^ (z))
, z3 q; M) z" e: k3 {* l1 @#define I(x, y, z) ((y) ^ ((x) | (~z))) % R1 a4 ]( a5 x7 C- `
% T+ j5 ]6 e! W0 b/* ROTATE_LEFT rotates x left n bits. */ 9 p- X. x- d {* i0 B9 \ u' _
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) * K! P f; C/ i* O3 c3 @0 m
" u: T0 L! ^0 K3 F
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
1 O; m/ }5 y3 `6 P" vRotation is separate from addition to prevent recomputation. */
5 `. g* w L0 A' D) w9 d I P; u+ h Z#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 3 Z* a' s5 R0 L2 ^ m/ n
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } , l4 W* e7 T3 o1 x$ Z
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 2 w7 _7 x- E% C6 ?5 }; F) 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); \ } # S% _: ?. k( X2 u. u' V1 h
4 B8 c4 d" U7 q8 d# [* J9 K
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
3 c/ I" c' j( Q: y, Uvoid MD5Init (context) 8 c5 V( {1 @1 ^! |& g" F" Y
MD5_CTX *context; /* context */ . x: i8 z+ {: \7 T0 P
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
6 f3 f& Z- G0 e" b$ d2 q*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
P9 z, q, ~# g7 R4 |- |} ' a$ z1 B- y0 [; ~0 W
5 j6 T0 k1 [& N/ t, F: {
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ . j1 I) u& v- Y& i: a8 r
void MD5Update (context, input, inputLen) 5 Y, d3 o% [, [: ]' K' _% Q
MD5_CTX *context; /* context */ * s' {9 B/ }5 [" [2 p6 J+ |
unsigned char *input; /* input block */ $ ?0 A$ m1 S" Y1 w1 H
unsigned int inputLen; /* length of input block */ : l6 b2 ?& G9 \3 ]6 k: |/ Y
{ unsigned int i, index, partLen;
& ~0 J7 [! L: ?+ a0 n* I /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
$ N( }+ b6 B+ Y7 {, C! Q /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|