--- parser3/src/lib/md5/pa_md5c.c 2003/04/15 15:10:04 1.6.2.1.2.1 +++ parser3/src/lib/md5/pa_md5c.c 2013/07/16 21:48:36 1.15 @@ -3,7 +3,7 @@ Replaced ap_ to pa_ prefixes. linked into all targets but Apache-module target, where linked targets/apache/pa_md5c.c stub instead. - Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) */ /* @@ -97,7 +97,7 @@ */ /* - * The PA_MD5Encode() routine uses much code obtained from the FreeBSD 3.0 + * The pa_MD5Encode() routine uses much code obtained from the FreeBSD 3.0 * MD5 crypt() function, which is licenced as follows: * ---------------------------------------------------------------------------- * "THE BEER-WARE LICENSE" (Revision 42): @@ -107,18 +107,11 @@ * ---------------------------------------------------------------------------- */ -static const char* IDENT_MD5_C="$Date: 2003/04/15 15:10:04 $"; - #include #include "pa_md5.h" -//#include "ap.h" -//#ifdef CHARSET_EBCDIC -//#include "ebcdic.h" -//#endif /*CHARSET_EBCDIC*/ -//#if HAVE_CRYPT_H -//#include -//#endif + +volatile const char * IDENT_PA_MD5_C="$Id: pa_md5c.c,v 1.15 2013/07/16 21:48:36 moko Exp $" IDENT_PA_MD5_H; #define pa_pa_cpystrn(strDest, strSource, count) strncpy(strDest, strSource, count) @@ -192,7 +185,7 @@ static unsigned char PADDING[64] = /* MD5 initialization. Begins an MD5 operation, writing a new context. */ -PA_API_EXPORT(void) PA_MD5Init(PA_MD5_CTX *context) +void pa_MD5Init(PA_MD5_CTX *context) { context->count[0] = context->count[1] = 0; /* Load magic initialization constants. */ @@ -206,7 +199,7 @@ PA_API_EXPORT(void) PA_MD5Init(PA_MD5_CT operation, processing another message block, and updating the context. */ -PA_API_EXPORT(void) PA_MD5Update(PA_MD5_CTX *context, const unsigned char *input, +void pa_MD5Update(PA_MD5_CTX *context, const unsigned char *input, unsigned int inputLen) { unsigned int i, idx, partLen; @@ -266,7 +259,7 @@ PA_API_EXPORT(void) PA_MD5Update(PA_MD5_ /* MD5 finalization. Ends an MD5 message-digest operation, writing the the message digest and zeroizing the context. */ -PA_API_EXPORT(void) PA_MD5Final(unsigned char digest[16], PA_MD5_CTX *context) +void pa_MD5Final(unsigned char digest[16], PA_MD5_CTX *context) { unsigned char bits[8]; unsigned int idx, padLen; @@ -278,13 +271,13 @@ PA_API_EXPORT(void) PA_MD5Final(unsigned #ifdef CHARSET_EBCDIC /* XXX: @@@: In order to make this no more complex than necessary, * this kludge converts the bits[] array using the ascii-to-ebcdic - * table, because the following PA_MD5Update() re-translates + * table, because the following pa_MD5Update() re-translates * its input (ebcdic-to-ascii). - * Otherwise, we would have to pass a "conversion" flag to PA_MD5Update() + * Otherwise, we would have to pass a "conversion" flag to pa_MD5Update() */ ascii2ebcdic(bits,bits,8); - /* Since everything is converted to ascii within PA_MD5Update(), + /* Since everything is converted to ascii within pa_MD5Update(), * the initial 0x80 (PADDING[0]) must be stored as 0x20 */ PADDING[0] = os_toebcdic[0x80]; @@ -293,10 +286,10 @@ PA_API_EXPORT(void) PA_MD5Final(unsigned /* Pad out to 56 mod 64. */ idx = (unsigned int) ((context->count[0] >> 3) & 0x3f); padLen = (idx < 56) ? (56 - idx) : (120 - idx); - PA_MD5Update(context, (const unsigned char *)PADDING, padLen); + pa_MD5Update(context, (const unsigned char *)PADDING, padLen); /* Append length (before padding) */ - PA_MD5Update(context, (const unsigned char *)bits, 8); + pa_MD5Update(context, (const unsigned char *)bits, 8); /* Store state in digest */ Encode(digest, context->state, 16); @@ -427,7 +420,7 @@ static void Decode(UINT4 *output, const * the FreeBSD 3.0 /usr/src/lib/libcrypt/crypt.c file, which is * licenced as stated at the top of this file. */ -PA_API_EXPORT(void) pa_to64(char *s, unsigned long v, int n) +void pa_to64(char *s, unsigned long v, int n) { static unsigned char itoa64[] = /* 0 ... 63 => ASCII - 64 */ "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; @@ -438,7 +431,7 @@ PA_API_EXPORT(void) pa_to64(char *s, uns } } -PA_API_EXPORT(void) PA_MD5Encode(const unsigned char *pw, +void pa_MD5Encode(const unsigned char *pw, const unsigned char *salt, char *result, size_t nbytes) { @@ -487,34 +480,34 @@ PA_API_EXPORT(void) PA_MD5Encode(const u /* * 'Time to make the doughnuts..' */ - PA_MD5Init(&ctx); + pa_MD5Init(&ctx); pwlen = strlen((char *)pw); /* * The password first, since that is what is most unknown */ - PA_MD5Update(&ctx, pw, pwlen); + pa_MD5Update(&ctx, pw, pwlen); /* * Then our magic string */ - PA_MD5Update(&ctx, (const unsigned char *) PA_MD5PW_ID, PA_MD5PW_IDLEN); + pa_MD5Update(&ctx, (const unsigned char *) PA_MD5PW_ID, PA_MD5PW_IDLEN); /* * Then the raw salt */ - PA_MD5Update(&ctx, sp, sl); + pa_MD5Update(&ctx, sp, sl); /* * Then just as many characters of the MD5(pw, salt, pw) */ - PA_MD5Init(&ctx1); - PA_MD5Update(&ctx1, pw, pwlen); - PA_MD5Update(&ctx1, sp, sl); - PA_MD5Update(&ctx1, pw, pwlen); - PA_MD5Final(final, &ctx1); + pa_MD5Init(&ctx1); + pa_MD5Update(&ctx1, pw, pwlen); + pa_MD5Update(&ctx1, sp, sl); + pa_MD5Update(&ctx1, pw, pwlen); + pa_MD5Final(final, &ctx1); for(pl = pwlen; pl > 0; pl -= 16) { - PA_MD5Update(&ctx, final, (pl > 16) ? 16 : (unsigned int) pl); + pa_MD5Update(&ctx, final, (pl > 16) ? 16 : (unsigned int) pl); } /* @@ -527,10 +520,10 @@ PA_API_EXPORT(void) PA_MD5Encode(const u */ for (i = pwlen; i != 0; i >>= 1) { if (i & 1) { - PA_MD5Update(&ctx, final, 1); + pa_MD5Update(&ctx, final, 1); } else { - PA_MD5Update(&ctx, pw, 1); + pa_MD5Update(&ctx, pw, 1); } } @@ -543,7 +536,7 @@ PA_API_EXPORT(void) PA_MD5Encode(const u passwd[PA_MD5PW_IDLEN + sl] = '$'; passwd[PA_MD5PW_IDLEN + sl + 1] = '\0'; - PA_MD5Final(final, &ctx); + pa_MD5Final(final, &ctx); /* * And now, just to make sure things don't run too fast.. @@ -551,28 +544,28 @@ PA_API_EXPORT(void) PA_MD5Encode(const u * need 30 seconds to build a 1000 entry dictionary... */ for (i = 0; i < 1000; i++) { - PA_MD5Init(&ctx1); + pa_MD5Init(&ctx1); if (i & 1) { - PA_MD5Update(&ctx1, pw, pwlen); + pa_MD5Update(&ctx1, pw, pwlen); } else { - PA_MD5Update(&ctx1, final, 16); + pa_MD5Update(&ctx1, final, 16); } if (i % 3) { - PA_MD5Update(&ctx1, sp, sl); + pa_MD5Update(&ctx1, sp, sl); } if (i % 7) { - PA_MD5Update(&ctx1, pw, pwlen); + pa_MD5Update(&ctx1, pw, pwlen); } if (i & 1) { - PA_MD5Update(&ctx1, final, 16); + pa_MD5Update(&ctx1, final, 16); } else { - PA_MD5Update(&ctx1, pw, pwlen); + pa_MD5Update(&ctx1, pw, pwlen); } - PA_MD5Final(final,&ctx1); + pa_MD5Final(final,&ctx1); } p = passwd + strlen(passwd);