|
|
#include "global.h"
: {# R! ~# `1 Y1 ?+ r#include "md5.h" 1 A: c6 h& J) s
$ `6 F, P( A. y% f1 t
/* Constants for MD5Transform routine. */
: ^- f( ` ]# h1 u& U1 ~& n& A5 {/ Z4 F 1 W6 Q6 K' o2 E7 N* e1 O* a x
0 F/ I4 k$ p: T2 Z7 T/ W#define S11 7
9 R5 J5 p% N% e" U- k# P#define S12 12
" l+ y; _3 R+ _8 e: B#define S13 17
% v& G% [" Z! d/ o#define S14 22
1 ^* D5 {, w+ `#define S21 5 # c1 Z8 \ J. `7 `0 T" m9 [
#define S22 9 5 t3 ]) u7 {, S8 w/ U+ D, @
#define S23 14
# }7 T1 ~" {1 v0 p% q p6 b/ P#define S24 20
( d; e9 T; \, q9 M#define S31 4
* ^+ h) ^6 A7 X |0 D' u5 z#define S32 11 - B0 P- s6 S) r# M0 ~
#define S33 16 9 }2 X+ D& O, F* X: V7 G) K
#define S34 23
% \5 }, B) {4 \6 h, w7 W4 h5 W! ~#define S41 6 9 J: N+ I; I% J
#define S42 10
/ A G% ]7 S- r/ V6 |9 C#define S43 15 3 T' p9 H/ ]$ H- v5 x2 X
#define S44 21
$ @0 K, b0 R+ O+ J4 F7 H
( R4 N f R+ T! H3 e6 f) zstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); 5 u8 v1 e/ T+ R* n: C, g0 b
static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
# y- m- d: |* [8 M* P% \! }static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); - V$ K3 F% \/ i$ n" }' a
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
2 i) B: H0 [! U$ a; t# ^: jstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
- t0 o' y/ {7 d/ I4 m
# `8 _. }5 R2 u5 ~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 1 S/ b3 z o- Z& {9 z
};
. k0 A" p8 m7 Z, n 9 x& w, z) g+ q. l
/* F, G, H and I are basic MD5 functions. */
/ t$ }+ E8 I' V0 d: a J, M0 ?#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 6 p$ M6 V# I6 u) y% j1 B* h
#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) / l- B. W- W3 ]5 M2 t% R V
#define H(x, y, z) ((x) ^ (y) ^ (z))
9 x' l) U% a# j#define I(x, y, z) ((y) ^ ((x) | (~z)))
+ T' j! `6 e$ e! z. q3 R9 X" G3 c ( F" t, c; I! T9 h& E2 i0 B
/* ROTATE_LEFT rotates x left n bits. */ & k/ }# B* _, f5 l- o; z0 J
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) ! Z" w) m) T5 C, r5 J
6 q8 o4 i( \0 f
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
% u$ y1 Q& b/ {$ O5 f% z3 p5 ]Rotation is separate from addition to prevent recomputation. */
! K8 X5 Q& Y3 {#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } 3 f( C- |$ i) a; i( R8 h% k
#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } , i a- H4 B3 A0 F2 E) p9 I
#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* Q/ ~. a$ F6 X; w9 x& W0 B
#define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ }
; s. r( I5 I' ^! U / Z$ p% ?& Q2 `* {; {5 H8 @7 Y" C
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ + s b2 F, v& N9 e! `1 R8 ^
void MD5Init (context) 6 U/ Q& x7 Y3 j) s
MD5_CTX *context; /* context */
; ~" u* Y; ?# }" V{ context->count[0] = context->count[1] = 0; /* Load magic initialization constants. # C9 t) h, K! f5 `* M. i
*/ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; ) E, Z1 z2 q- B0 m; H
} x" ^" V5 x8 f9 w
! b$ t" O8 T: U
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */
7 r7 j7 }5 |% lvoid MD5Update (context, input, inputLen) % Y" s2 b, ~. i. e6 n8 y5 [& p/ `' l' E
MD5_CTX *context; /* context */
4 U. H$ [; D% e: x4 @unsigned char *input; /* input block */
& S6 M! u: c0 @- l& a: Cunsigned int inputLen; /* length of input block */
, m7 U/ R5 u) @/ E1 T; I5 V{ unsigned int i, index, partLen;
* S( y- o. d* o /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
, B. L4 P9 `8 [# v, u0 t /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) & |
|