|
|
#include "global.h"
6 z; F+ G; r: |9 |#include "md5.h"
, N$ |/ `" [6 A7 L4 o U
2 `; v ^. }4 l' Z, b$ Q/* Constants for MD5Transform routine. */ & _" v* s9 n2 |8 J
* ^) K9 h9 P& S0 L. A! l' ?
: |7 V. l7 \$ q/ x. u; v#define S11 7
3 Z: ^% X! s, W; z% e#define S12 12
- @0 z* u$ ^7 v4 F+ q#define S13 17
/ P$ l; Q' u% A4 J( J; D#define S14 22 * y! B u5 d- S1 U6 s0 O$ s
#define S21 5
: m. |$ v2 T* L, A# F#define S22 9
0 a4 B* V, |4 P6 s+ z, s#define S23 14
: |- t f4 j1 r( V#define S24 20 6 S/ n, J' C4 x
#define S31 4
# i' u; E3 S' R+ D#define S32 11
' L* b% E' W. ]' K8 O#define S33 16 . K( P7 W) q% j3 [
#define S34 23
2 D$ G. Q8 [ K }4 [( e& z( F8 i#define S41 6
( q' v# ~4 e( W4 w% t8 e! S#define S42 10 0 D8 @: @' Z B D& b1 d% w
#define S43 15
6 P' q9 Z; t9 ]/ G; C( u& R#define S44 21 " i `: C6 U3 m0 F5 e3 u, D; R! K
7 ]: z) M; e) _4 O; r7 V0 ]static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); ) H- F; b& X t2 ~$ E# _
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); 4 d: p3 d$ q& N3 ~6 }5 R
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); - D: F8 X3 B" j* n2 F/ k: u$ d
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
n$ K# E# l9 u9 s* mstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); 8 z) Y) C& }) u5 V3 M S
* q6 Z* q5 S1 p" P3 Y, p
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 ' D1 W2 p) ]: c3 T# v
}; 5 n6 j, E! C0 H4 H1 j/ ?' d
( O6 K7 D, z3 o- d l/* F, G, H and I are basic MD5 functions. */ Q0 D- ~& |, }% S
#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) + E1 K! }, g) m
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
. a: \6 u+ J* l) N) i) @#define H(x, y, z) ((x) ^ (y) ^ (z))
/ y3 D6 V8 Y1 n#define I(x, y, z) ((y) ^ ((x) | (~z)))
5 i& b% j. Y+ b* B; P1 r" Z , j& [( ]( z! t0 f! L% B4 D
/* ROTATE_LEFT rotates x left n bits. */ 7 V* b% v( d5 v# @3 n& H
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
" H8 w& n! s: Q- ~) {! j
+ F8 w' m: s2 i Y0 c. b3 q8 l/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
4 M I* p2 i6 BRotation is separate from addition to prevent recomputation. */
5 a9 A. R3 z6 v4 i0 M/ |% p#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } ! i3 ?1 Q" s# o6 Z& K4 x- t2 x
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
1 _) z( e2 c, j+ {& n: |0 j#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
" g, [) a F# u* w#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 2 p. q' W1 i$ W' p o- A' p
0 j4 Q4 u" `& @& z. b2 a/ a/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 2 I4 L) @% ]" D1 l# U
void MD5Init (context)
4 n! _5 ^# `( U) D" M4 fMD5_CTX *context; /* context */ / l/ R; A+ D3 z7 t1 f7 K6 ~5 I6 t
{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
1 m0 T2 c( m- I; U( J! C4 R*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;
; i. N# P% X7 S) M' k, U} 8 G i7 `9 e- ^5 F8 R
* j, @" e4 D! U3 l/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ / m& F9 l6 p3 t, K) X
void MD5Update (context, input, inputLen)
8 q0 i x& G( G( e3 VMD5_CTX *context; /* context */
4 {" k @+ a4 {0 Nunsigned char *input; /* input block */
+ q8 M" b4 n4 ~. @6 t" _unsigned int inputLen; /* length of input block */
6 m9 H8 W9 ~8 `( V{ unsigned int i, index, partLen; * O, ^* G! v) W, D" G
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
t$ e0 n o( X5 C8 ?3 z" V; { /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|