|
|
#include "global.h"
n4 o0 I2 _7 n/ V, |#include "md5.h" 8 r1 w; c! e5 s' S1 r
( q$ V9 z, V+ Z3 C$ r
/* Constants for MD5Transform routine. */ 4 X$ g& R# W( J2 [# L/ |
+ D" \0 S5 K1 p/ J+ {$ h$ v 0 X, c: ?6 m; L! e7 c
#define S11 7
9 ?0 k) D$ E6 W& I5 x; B2 O#define S12 12 ' D0 |1 ~( w$ b a5 J
#define S13 17 # B) z# Y# T0 D! M G+ w2 j
#define S14 22
( v: O* G: [' {% ~#define S21 5
; ~6 O: Y$ r: W& ~#define S22 9 , U" V& }1 f2 o8 Y) x. n, J& v
#define S23 14
$ E2 B7 P) ~: ?) B1 B5 n#define S24 20 / `0 F0 S& U* }2 b
#define S31 4
" M Y, ~7 l d$ h0 S k#define S32 11 5 z. J5 Q7 Z2 R# k% h) a6 e* f
#define S33 16 1 a) l& n; z j+ l- F- ]
#define S34 23
* X J& F5 \9 u5 }: v) K/ D2 x4 C#define S41 6 ) |1 e; [! h3 b0 P5 ^7 }# d
#define S42 10
# D. l$ ~9 v: S8 m/ Q: d+ h#define S43 15
- z: o+ h% D5 q#define S44 21 : S. q3 }4 D; @
, I' U. _3 E4 d: U/ x* w/ c: m
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); ' v. ?. g2 |8 ]8 L1 N. N0 E0 A3 X
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
7 {4 H; H2 _% d: \. H2 d3 B& E1 ostatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
" F- b$ t& O/ w+ Y7 r t% ostatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); / }* b- Y2 ~7 T7 v8 Q
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); . R% {" j+ y" z
4 R) i3 K9 Q9 d+ X2 i* z( Rstatic 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) a- g+ M9 r! O}; + H, u7 @: M3 \3 y) \) g4 g4 c
* O/ {1 |, p) ~* m" T; ]5 L4 s
/* F, G, H and I are basic MD5 functions. */ " h0 G+ A% V3 L6 a( l
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) ! `/ d7 \4 Z, N
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) ; A2 j: v4 H) O) o U6 O6 s
#define H(x, y, z) ((x) ^ (y) ^ (z)) ! P" _1 X- l) `1 I q* l1 F) K \
#define I(x, y, z) ((y) ^ ((x) | (~z))) + r2 s1 q5 D. ^
! G& v$ z" N, u7 ?: M; \
/* ROTATE_LEFT rotates x left n bits. */ ; R9 L- o% h! ]- M! x- {
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
$ m+ F! E$ j; I. J" p
6 j6 \ j4 r0 N" S" i; l3 K/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 8 i8 w* T. z/ T( ?) t
Rotation is separate from addition to prevent recomputation. */ d' Z7 ^! ]# N8 V3 f
#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ) r$ r l( ]+ N. I+ q2 [6 Q
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
f' v2 ? Q/ R9 E0 R) h, [#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } , n' ?5 W+ L f" U+ e# v" ~
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
! x5 S! [2 {$ _; L V4 F# B0 P0 L: Z0 M ; T2 }' L ^. z3 ~3 I
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 2 j+ W2 K" e [: Y J
void MD5Init (context)
- J! P* Q& d0 ?MD5_CTX *context; /* context */
# H# K: H$ `8 M l; G1 A! V{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
, s8 ~# Y J7 a6 `. ]3 k*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; ' p, L( x/ { q( T `: T4 n
}
( | |5 C& l e7 d8 E" F 6 z o5 x6 T0 u7 C2 q/ _8 ^1 E
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
8 k' A8 }0 T6 W, _2 y' t% {; L. ^6 ivoid MD5Update (context, input, inputLen) , F* N$ V; O# [1 O
MD5_CTX *context; /* context */ - I' H2 s# t$ W! N/ K, ]; H- f
unsigned char *input; /* input block */
7 O( T, |/ i% I; p2 _2 xunsigned int inputLen; /* length of input block */ 0 z& ^# t$ v" e. q) k
{ unsigned int i, index, partLen;
" c4 Q% f+ ]2 T( n( J1 h /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
! e7 m9 s( V @. N& P% c( D/ p/ ` /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|