|
|
#include "global.h"
1 Q* ?" `) W5 K4 o9 Y( A, ~#include "md5.h"
7 i7 b0 ^7 q: U9 n" M8 x
5 J, \! \, F- Y7 f' [ z/* Constants for MD5Transform routine. */ $ f; P0 \" }4 b$ ^# t
' ], l& l( x: o: q6 L3 ?. B
: K" n% p* N: P1 q, V+ g" x' N h#define S11 7
; f/ N4 G1 Z# e h#define S12 12
+ F+ R9 Q) O, u7 Z4 x0 B6 s#define S13 17 3 P# f; o+ P+ E2 y7 M5 k1 n( S# n6 ?
#define S14 22
& M2 n$ N+ A O#define S21 5 5 U; H4 M3 ~6 a4 _3 K) I- C
#define S22 9 ; U# t4 L6 J9 D) Z8 o" Y
#define S23 14
9 s: E; Q) C( S5 i#define S24 20
& [9 O7 v5 ]/ G! D5 m1 x! ~& p#define S31 4 3 |- e- P, i" Q: y$ b Q, D
#define S32 11
2 \9 Z) C1 B- q5 g#define S33 16 8 T4 Q+ w: S h) c
#define S34 23
( l/ I" S6 D, U0 o8 N; c#define S41 6 4 J+ d+ H: S `! g: S3 N( j
#define S42 10 ! c7 q/ D: K* \! K" J5 }
#define S43 15
0 N' e. G, j0 k#define S44 21 " O9 p& w' G8 c' M* f' U1 s8 R3 ?2 u+ Y
! a5 X9 `. x7 t7 R
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
7 \* a+ B/ O+ y' Lstatic void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); * X* H/ ?, U; v
static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); " R+ N- ?* p' l# H& C3 J# |
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); ) s B9 I$ {6 c. ^( |! H
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); # g4 J: y- W l/ C& f7 {
& G0 e& p7 e! e& W" R/ S/ vstatic 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
2 O) A6 K! l5 F2 J5 S5 r6 `; P}; 2 t0 D3 z( \( W& _8 d
2 G5 c& m6 I; D' l" {2 |
/* F, G, H and I are basic MD5 functions. */ $ ?) M4 w5 W. T9 ^* m2 `
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
2 k2 \8 q4 w. Z# s#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 5 [1 [- i* {, r) {- Y5 E
#define H(x, y, z) ((x) ^ (y) ^ (z))
; s9 G: k# Q q; E0 N2 E! G X$ w#define I(x, y, z) ((y) ^ ((x) | (~z)))
8 u; J) ~; f, w; s6 \ & ]" t- R5 m) y! i
/* ROTATE_LEFT rotates x left n bits. */ 1 r# u; m) X# h1 p z
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) % N0 u# P3 i6 t: b
1 W: f: o" m- q; I* {$ N
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. $ H" C8 e+ Q+ X" @
Rotation is separate from addition to prevent recomputation. */
! {* \$ t e' I% y, i& ]) I, \* o6 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); \ } 9 d; ?3 Z" H B' A
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
3 K7 @+ v2 k3 Z- `+ 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); \ } / o. \+ M$ G+ `: [9 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); \ }
@7 z9 ]- `0 r% g
/ p5 [3 m ^# X, [; t$ |/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 2 I7 c* `! t1 F) S. }9 [
void MD5Init (context) ) f; w# U6 m7 j! ?0 k9 d3 |' [0 R
MD5_CTX *context; /* context */
5 f9 | i' ^, X4 W. E9 r$ v{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants.
$ |, \# ^3 i% j8 H1 E*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; 2 [- l( Z$ l8 J& C$ f7 M: O5 W' X7 B
}
. E* A2 o% v% D* y4 d3 M$ U, `
1 P, |+ U( _2 ^/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ 4 H \, k* l1 w8 Z
void MD5Update (context, input, inputLen)
* E b" x% u( Q, X3 {5 ?MD5_CTX *context; /* context */
7 `/ S6 N4 {. Y- yunsigned char *input; /* input block */
2 N; v1 w' G" H/ T( u4 nunsigned int inputLen; /* length of input block */ ) c5 v G& `' N! `
{ unsigned int i, index, partLen; 3 X1 [5 @( ?) X4 V/ y0 Y
/* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
% f! v& b& k0 P& w7 c /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|