X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2FMD5.c;h=c12b7615ec5d3f2a0ed744e833d8ca609ed40a51;hp=7107b40cbafdc59e09e5345110899a780c0c26c4;hb=bf04757cd94e94c1f67fa3d2a4e3e59fa5bce0c0;hpb=c9d4eeb03932fcb193df379346314d6e8e3d7418 diff --git a/lib/MD5.c b/lib/MD5.c index 7107b40..c12b761 100644 --- a/lib/MD5.c +++ b/lib/MD5.c @@ -30,11 +30,29 @@ * SUCH DAMAGE. */ +#include "../config.h" + +#include + #ifndef _NETINET6_MD5_H_ #define _NETINET6_MD5_H_ #define MD5_BUFLEN 64 +#ifndef LITTLE_ENDIAN +#define LITTLE_ENDIAN 1 +#endif +#ifndef BIG_ENDIAN +#define BIG_ENDIAN 2 +#endif +#ifndef BYTE_ORDER +#ifdef WORDS_BIGENDIAN +#define BYTE_ORDER BIG_ENDIAN +#else +#define BYTE_ORDER LITTLE_ENDIAN +#endif +#endif + typedef long unsigned int u_int32_t; typedef long long unsigned int u_int64_t; typedef unsigned char u_int8_t; @@ -65,10 +83,10 @@ typedef struct { u_int8_t md5_buf[MD5_BUFLEN]; } md5_ctxt; -extern void md5_init(md5_ctxt *); -extern void md5_loop(md5_ctxt *, const u_int8_t *, u_int); -extern void md5_pad(md5_ctxt *); -extern void md5_result(u_int8_t *, md5_ctxt *); +static void md5_init(md5_ctxt *); +static void md5_loop(md5_ctxt *, const u_int8_t *, u_int); +static void md5_pad(md5_ctxt *); +static void md5_result(u_int8_t *, md5_ctxt *); /* compatibility */ #define MD5_CTX md5_ctxt @@ -118,13 +136,27 @@ do { \ * UNIX password */ +#ifndef HAVE_BCOPY +void bcopy(const void*src, void*dest, int len) +{ + memcpy(dest, src, len); +} +#endif + +#ifndef HAVE_BZERO +void bzero(void*mem, int len) +{ + memset(mem, 0, len); +} +#endif + #define MD4_SIZE 16 #define MD5_SIZE 16 static char itoa64[] = /* 0 ... 63 => ascii - 64 */ "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; -void +static void _crypt_to64(char *s, u_long v, int n) { while (--n >= 0) { @@ -133,6 +165,16 @@ _crypt_to64(char *s, u_long v, int n) } } +void hash_md5(const unsigned char*buf, int len, unsigned char*dest) +{ + u_char final[MD5_SIZE]; + + MD5_CTX ctx; + MD5Init(&ctx); + MD5Update(&ctx, buf, len); + MD5Final(dest, &ctx); +} + char * crypt_md5(const char *pw, const char *salt) { MD5_CTX ctx,ctx1; @@ -366,8 +408,7 @@ static const u_int8_t md5_paddat[MD5_BUFLEN] = { static void md5_calc(u_int8_t *, md5_ctxt *); -void md5_init(ctxt) - md5_ctxt *ctxt; +static void md5_init(md5_ctxt *ctxt) { ctxt->md5_n = 0; ctxt->md5_i = 0; @@ -378,10 +419,7 @@ void md5_init(ctxt) bzero(ctxt->md5_buf, sizeof(ctxt->md5_buf)); } -void md5_loop(ctxt, input, len) - md5_ctxt *ctxt; - const u_int8_t *input; - u_int len; /* number of bytes */ +static void md5_loop(md5_ctxt *ctxt, const u_int8_t *input, u_int len) { u_int gap, i; @@ -406,8 +444,7 @@ void md5_loop(ctxt, input, len) } } -void md5_pad(ctxt) - md5_ctxt *ctxt; +static void md5_pad(md5_ctxt *ctxt) { u_int gap; @@ -445,9 +482,7 @@ void md5_pad(ctxt) md5_calc(ctxt->md5_buf, ctxt); } -void md5_result(digest, ctxt) - u_int8_t *digest; - md5_ctxt *ctxt; +static void md5_result(u_int8_t *digest, md5_ctxt *ctxt) { /* 4 byte words */ #if BYTE_ORDER == LITTLE_ENDIAN @@ -465,13 +500,7 @@ void md5_result(digest, ctxt) #endif } -#if BYTE_ORDER == BIG_ENDIAN -u_int32_t X[16]; -#endif - -static void md5_calc(b64, ctxt) - u_int8_t *b64; - md5_ctxt *ctxt; +static void md5_calc(u_int8_t *b64, md5_ctxt *ctxt) { u_int32_t A = ctxt->md5_sta; u_int32_t B = ctxt->md5_stb; @@ -481,6 +510,7 @@ static void md5_calc(b64, ctxt) u_int32_t *X = (u_int32_t *)b64; #endif #if BYTE_ORDER == BIG_ENDIAN + u_int32_t X[16]; /* 4 byte words */ /* what a brute force but fast! */ u_int8_t *y = (u_int8_t *)X;