|
#include "global.h"
: X" G4 I# K% ]#include "md5.h" " _( Y/ s2 d1 U) b
' ~, C( Z$ p! q7 N" E/* Constants for MD5Transform routine. */ : @7 ^ P2 k4 K5 @' A; D) A
% r. w% j w# H2 q2 u
- L0 C: L7 Q. M( D2 O5 q4 u6 y#define S11 7 " h5 z4 J2 Q. A( K7 |( Q( ~0 s
#define S12 12
# Q4 \) n8 ~# }#define S13 17
1 ]1 O- N/ x W7 J#define S14 22
- b# R5 r4 J8 y7 b# X5 ^! ?1 p#define S21 5 # F. f2 @/ S) {- U4 I1 c y! t# x
#define S22 9 % D$ p2 z) A6 r9 y3 U K
#define S23 14
- [: T& w; |, r$ ` d% |. o#define S24 20 ( J6 @' v3 Z8 N) b2 @
#define S31 4
3 z( @* c8 }2 t |9 f5 m% g0 ?#define S32 11
" z6 _1 p1 {! e5 _0 u; L#define S33 16
* ?! r6 H' {) w#define S34 23
1 U4 g0 ~& W: p' ~#define S41 6 ' U1 O- r/ d d1 X, P4 S$ v
#define S42 10
5 f. c- s1 V9 F- e$ @8 C#define S43 15 ( T9 C; f0 I/ K
#define S44 21 + H9 V( h: W) [! b( S6 ?3 D9 f
x6 U% {+ U" N+ T0 Dstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); : ]: {( P0 s' w+ A' K
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
# ~' b3 {0 ?- c: Sstatic void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
/ a/ ~1 E8 J1 k2 s3 o9 [6 dstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); ) `1 c5 H; }- f3 L
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 2 x0 X2 I+ B+ Q& \+ U0 C1 d
7 D* L& v' m, ?" t4 B8 V7 dstatic 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 5 h( x& G; Q! W7 \& r; o
}; 7 r) I+ g9 n6 B8 {/ A
' d& p) Z* J H: m7 A7 ^
/* F, G, H and I are basic MD5 functions. */ " c2 U. j: b4 m0 D4 i7 f; v
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 8 w& L9 {# D% C" W, q: X
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
: j3 I( e0 S/ m#define H(x, y, z) ((x) ^ (y) ^ (z)) ' E$ Q8 j1 D$ w; A6 ?' G/ S* J ^
#define I(x, y, z) ((y) ^ ((x) | (~z))) . x; Y3 N9 z5 i1 ?& Y
' [ t; {4 @# r4 ?6 _/* ROTATE_LEFT rotates x left n bits. */ 1 u- w' ^0 c+ h- h4 p
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
$ ]# a+ r4 ?! F2 W
1 N* }. v$ u4 F. A/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
8 N* `8 |! Z3 ]0 s1 \Rotation is separate from addition to prevent recomputation. */ " s0 R* ~3 p4 d* u
#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+ D% W. O# 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); \ } $ a j. A1 a, ?" W% [; y0 }
#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& ]' t$ @2 w1 m
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 1 F' K* V$ W; {' `) p+ e ~
# ]- Q0 \8 s# ?: a1 i/ M e+ R/* MD5 initialization. Begins an MD5 operation, writing a new context. */
+ a. B8 H2 v7 t% M) \; dvoid MD5Init (context)
9 A6 d! Q2 G5 E% kMD5_CTX *context; /* context */
8 v) o" X8 D4 ]0 H{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
' D* j7 N X& t- c" l4 L8 \: i7 R*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
- g1 n$ X: S0 E} % U' r2 \# k, ~6 v% T4 z
( v) x9 G: X1 z/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
+ f. \ M, x6 \6 h$ {( F) zvoid MD5Update (context, input, inputLen) 5 v# {3 P1 h" A! P
MD5_CTX *context; /* context */
& S L4 c4 s0 z: U) Qunsigned char *input; /* input block */ 4 @2 S) O8 l: \3 N
unsigned int inputLen; /* length of input block */
$ x% r7 k. E2 L' E{ unsigned int i, index, partLen;
9 L0 k' q5 x4 d3 d' y( R& P /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
' w0 r! r+ x. i /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|