|
#include "global.h" # m. R, c/ l" q1 y' d
#include "md5.h" . z, p$ [ a0 F4 F. k& l
7 G% n: p6 ^2 z5 z
/* Constants for MD5Transform routine. */ ; s& W8 q& K$ W) G! |* Q0 C) @
$ {' B2 n7 z! H7 R& l# ]3 U, E ( c) A4 X, K$ o& P7 s* S' f) z6 S4 o
#define S11 7 . \! D; n% U$ ]. B$ Z
#define S12 12
; x1 I5 [' [3 R! U' ~, K3 ]#define S13 17
- `8 t% D. |. ^7 d#define S14 22
" t# `& o7 Y0 l3 u#define S21 5 1 g: W; t( K3 Z' v
#define S22 9
- j1 K0 D2 k1 e k& H#define S23 14
5 L3 v, |9 O2 _( M#define S24 20 # l; y/ h, I! J i, c
#define S31 4 ! H) M' U$ W7 X! V7 W' R
#define S32 11 1 n$ Z F& V. ^8 h) L6 S
#define S33 16
6 P' p7 z3 u# }% Q; V' o#define S34 23 # E/ ^% I2 d" Q h! w) @& ?
#define S41 6 / b2 |9 M1 K& [% H: `
#define S42 10 ! A. Z. ]4 H6 Y2 A" U3 w
#define S43 15
; {' S' y! B1 w! q5 y#define S44 21
' e! j @% d9 M! J. T) t8 B$ [ ! L5 ?* o$ J, \- f$ Q% v1 D
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
& Q( m. W" v& s) x' Istatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
& o6 @: k6 \7 B+ n7 `: Rstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
+ o- f! L: S$ Y! r" ?) estatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
9 S! J9 n4 [! v5 `3 \9 \) t( a8 Fstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
) u% f7 x, O8 i2 h( T+ G
% s7 u9 v" a8 N& Q* {static 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
, K1 y7 h7 F& d/ ^+ ]};
! {, W$ s' J. p( t* x
% n/ U8 F4 d8 G2 X/* F, G, H and I are basic MD5 functions. */ ) y8 M7 W3 w4 N# [! o5 w9 |
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
$ X3 E" x4 L2 Y/ s& S#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
3 p0 F, I, Y" Y5 |0 c' C8 O8 i#define H(x, y, z) ((x) ^ (y) ^ (z))
( J0 D( A- m7 |#define I(x, y, z) ((y) ^ ((x) | (~z))) , J$ e* [- W" N6 U6 N$ t
& E2 g5 V0 X7 d' d/* ROTATE_LEFT rotates x left n bits. */
+ R+ f6 ^3 H, F: k" ]#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) / }& j" h# v( P4 p( C" t
& s3 J* Z3 e$ B0 m' o& f% W* R3 {/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
; T/ R! G$ b- F K. g" e5 ]6 _4 y/ h" YRotation is separate from addition to prevent recomputation. */
. p4 l5 q2 K/ n#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
' v/ D8 g7 ]! q2 E* c#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 4 r) {! E; d. } {6 H7 l6 j. X) S
#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
& h) A& p, j# H% m+ F' p#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
8 P3 X+ V" l* n7 c3 u
4 ]1 K) Q& a4 J6 X/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 3 |# Z- b1 C7 o" Q( w
void MD5Init (context) 2 P C o" a( j: P
MD5_CTX *context; /* context */
* {1 ~+ o% G$ m! m. l$ }{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. 6 f. U& \- v: h$ c( e( H# a: s
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; ; C/ e* Z1 d6 S
} o8 F. }. m0 F. N( n |
# @8 k( c$ f; T) W$ e1 E/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ / r/ b4 j8 J5 o+ w4 A5 }3 q
void MD5Update (context, input, inputLen)
A6 E% n. {. Y8 \) f6 zMD5_CTX *context; /* context */ ' r0 F% U, ^0 x9 f' E
unsigned char *input; /* input block */ ' U5 ^8 T! G P, ~0 X
unsigned int inputLen; /* length of input block */
/ ~7 I9 T% M* G) ~; s{ unsigned int i, index, partLen;
, R9 l6 D# r! S6 u ~ /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); : W' t. X' k2 Z4 O( A
/* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|