--- parser3/src/lib/md5/pa_md5c.c 2002/06/21 13:04:24 1.2 +++ parser3/src/lib/md5/pa_md5c.c 2003/04/24 07:16:34 1.6.2.1.2.2 @@ -1,3 +1,11 @@ +/** @file + Parser: copied from apache 1.3.20 sources. + 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) +*/ + /* * This is work is derived from material Copyright RSA Data Security, Inc. * @@ -89,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): @@ -99,16 +107,11 @@ * ---------------------------------------------------------------------------- */ -#include +static const char* IDENT_MD5_C="$Date: 2003/04/24 07:16:34 $"; + +#include #include "pa_md5.h" -//#include "ap.h" -//#ifdef CHARSET_EBCDIC -//#include "ebcdic.h" -//#endif /*CHARSET_EBCDIC*/ -//#if HAVE_CRYPT_H -//#include -//#endif #define pa_pa_cpystrn(strDest, strSource, count) strncpy(strDest, strSource, count) @@ -182,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) +PA_API_EXPORT(void) PA_MD5Init(PA_MD5_CTX *context) { context->count[0] = context->count[1] = 0; /* Load magic initialization constants. */ @@ -196,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, +PA_API_EXPORT(void) PA_MD5Update(PA_MD5_CTX *context, const unsigned char *input, unsigned int inputLen) { unsigned int i, idx, partLen; @@ -256,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) +PA_API_EXPORT(void) PA_MD5Final(unsigned char digest[16], PA_MD5_CTX *context) { unsigned char bits[8]; unsigned int idx, padLen; @@ -268,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]; @@ -283,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); @@ -428,7 +431,7 @@ PA_API_EXPORT(void) pa_to64(char *s, uns } } -PA_API_EXPORT(void) pa_MD5Encode(const unsigned char *pw, +PA_API_EXPORT(void) PA_MD5Encode(const unsigned char *pw, const unsigned char *salt, char *result, size_t nbytes) { @@ -477,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); } /* @@ -517,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); } } @@ -533,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.. @@ -541,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);