--------------------- PatchSet 11855 Date: 2008/01/02 15:49:25 Author: hno Branch: SQUID_2_7 Tag: (none) Log: MFC: System MD5 support update - Prefix all MD5 symbols with SQUID_ to avoid conflicts with system headers - --without-system-md5 configure option to revert to built-in MD5 - rename include/md5.h to include/squid_md5.h to avoid conflict with system md5.h - autodetect if libmd is needed Members: CREDITS:1.11->1.11.6.1 configure.in:1.430.2.1->1.430.2.2 doc/Programming-Guide/prog-guide.sgml:1.55->1.55.6.1 helpers/basic_auth/NCSA/crypt_md5.c:1.3->1.3.6.1 helpers/basic_auth/squid_radius_auth/squid_rad_auth.c:1.2->1.2.6.1 helpers/basic_auth/squid_radius_auth/util.c:1.2->1.2.6.1 include/md5.h:1.19->1.19.2.1(DEAD) include/squid_md5.h:1.1->1.1.2.1 lib/md5-test.c:1.2->1.2.18.1 lib/md5.c:1.21->1.21.2.1 lib/rfc2617.c:1.8->1.8.6.1 src/CacheDigest.c:1.36->1.36.6.1 src/cache_diff.c:1.18->1.18.6.1 src/htcp.c:1.55->1.55.2.1 src/icp_v2.c:1.72->1.72.6.1 src/mem.c:1.77->1.77.2.1 src/squid.h:1.244->1.244.6.1 src/store.c:1.584->1.584.2.1 src/store_client.c:1.127->1.127.2.1 src/store_key_md5.c:1.32->1.32.2.1 src/store_swapmeta.c:1.23->1.23.2.1 src/structs.h:1.538->1.538.2.1 src/test_cache_digest.c:1.27->1.27.8.1 src/wccp2.c:1.31->1.31.2.1 src/fs/aufs/store_dir_aufs.c:1.70->1.70.2.1 src/fs/coss/store_dir_coss.c:1.71->1.71.2.1 src/fs/diskd/store_dir_diskd.c:1.90->1.90.2.1 src/fs/ufs/store_dir_ufs.c:1.65->1.65.2.1 Index: squid/CREDITS =================================================================== RCS file: /cvsroot/squid/squid/CREDITS,v retrieving revision 1.11 retrieving revision 1.11.6.1 diff -u -r1.11 -r1.11.6.1 --- squid/CREDITS 28 May 2006 22:42:52 -0000 1.11 +++ squid/CREDITS 2 Jan 2008 15:49:25 -0000 1.11.6.1 @@ -1,4 +1,4 @@ -$Id: CREDITS,v 1.11 2006/05/28 22:42:52 hno Exp $ +$Id: CREDITS,v 1.11.6.1 2008/01/02 15:49:25 hno Exp $ ============================================================================== @@ -178,8 +178,8 @@ * with every copy. * * To compute the message digest of a chunk of bytes, declare an - * MD5Context structure, pass it to MD5Init, call MD5Update as - * needed on buffers full of bytes, and then call MD5Final, which + * MD5Context structure, pass it to SQUID_MD5Init, call SQUID_MD5Update as + * needed on buffers full of bytes, and then call SQUID_MD5Final, which * will fill a supplied 16-byte array with the digest. * * Changed so as no longer to depend on Colin Plumb's `usual.h' header @@ -187,9 +187,13 @@ * - Ian Jackson . * Still in the public domain. * - * Changed MD5Update to take a void * for easier use and some other + * Changed SQUID_MD5Update to take a void * for easier use and some other * minor cleanup. - Henrik Nordstrom . * Still in the public domain. + * + * Prefixed all symbols with "Squid" so they don't collide with + * other libraries. Henrik Nordstrom . + * Still in the public domain. */ ============================================================================== Index: squid/configure.in =================================================================== RCS file: /cvsroot/squid/squid/configure.in,v retrieving revision 1.430.2.1 retrieving revision 1.430.2.2 diff -u -r1.430.2.1 -r1.430.2.2 --- squid/configure.in 21 Dec 2007 11:36:59 -0000 1.430.2.1 +++ squid/configure.in 2 Jan 2008 15:49:25 -0000 1.430.2.2 @@ -1,7 +1,7 @@ dnl dnl Configuration input file for Squid dnl -dnl $Id: configure.in,v 1.430.2.1 2007/12/21 11:36:59 hno Exp $ +dnl $Id: configure.in,v 1.430.2.2 2008/01/02 15:49:25 hno Exp $ dnl dnl dnl @@ -10,7 +10,7 @@ AM_CONFIG_HEADER(include/autoconf.h) AC_CONFIG_AUX_DIR(cfgaux) AM_INIT_AUTOMAKE -AC_REVISION($Revision: 1.430.2.1 $)dnl +AC_REVISION($Revision: 1.430.2.2 $)dnl AC_PREFIX_DEFAULT(/usr/local/squid) AM_MAINTAINER_MODE @@ -711,6 +711,19 @@ fi ]) +USE_SQUID_MD5=0 +AC_ARG_WITH(system-md5, +[ --without-system-md5 Disable the use of any system provided MD5 + Implementation forcing fallback on the internal + implementation shipped with Squid], +[ + case "$enableval" in + no) + AC_DEFINE(USE_SQUID_MD5, 1, [Define this to force use of the internal MD5 implementation]) + ;; + esac +]) + dnl User may specify OpenSSL is needed from a non-standard location AC_ARG_WITH(openssl, [ --with-openssl[=prefix] @@ -1636,6 +1649,7 @@ sys/file.h \ sys/ioctl.h \ sys/mount.h \ + md5.h \ sys/md5.h \ sys/msg.h \ sys/prctl.h \ @@ -2106,11 +2120,13 @@ dnl Some of our helpers use crypt(3) which may be in libc, or in dnl libcrypt (eg FreeBSD) AC_CHECK_LIB(crypt, crypt, [CRYPTLIB=" -lcrypt "]) +AC_SUBST(CRYPTLIB) dnl Solaris10 provides MD5 natively through libmd5 -AC_CHECK_LIB(md5, MD5Init, [CRYPTLIB+=" -lmd5 "]) +AC_CHECK_LIB(md5, MD5Init) -AC_SUBST(CRYPTLIB) +dnl FreeBSD provides MD5 natively through libmd +AC_CHECK_LIB(md, MD5Init) dnl Check for libdl, used by auth_modules/PAM if test "$with_dl" = "yes"; then @@ -2338,6 +2354,7 @@ lrand48 \ mallinfo \ mallocblksize \ + MD5Init \ mallopt \ memcpy \ memmove \ Index: squid/doc/Programming-Guide/prog-guide.sgml =================================================================== RCS file: /cvsroot/squid/squid/doc/Programming-Guide/prog-guide.sgml,v retrieving revision 1.55 retrieving revision 1.55.6.1 diff -u -r1.55 -r1.55.6.1 --- squid/doc/Programming-Guide/prog-guide.sgml 20 May 2006 13:05:58 -0000 1.55 +++ squid/doc/Programming-Guide/prog-guide.sgml 2 Jan 2008 15:49:25 -0000 1.55.6.1 @@ -2,7 +2,7 @@
Squid Programmers Guide Squid Developers -$Id: prog-guide.sgml,v 1.55 2006/05/20 13:05:58 hno Exp $ +$Id: prog-guide.sgml,v 1.55.6.1 2008/01/02 15:49:25 hno Exp $ Squid is a WWW Cache application developed by the National Laboratory @@ -2853,7 +2853,7 @@ size_t swap_file_sz; u_short refcount; u_short flags; - unsigned char key[MD5_DIGEST_CHARS]; + unsigned char key[SQUID_MD5_DIGEST_LENGTH]; }; Index: squid/helpers/basic_auth/NCSA/crypt_md5.c =================================================================== RCS file: /cvsroot/squid/squid/helpers/basic_auth/NCSA/crypt_md5.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- squid/helpers/basic_auth/NCSA/crypt_md5.c 30 Aug 2006 18:16:08 -0000 1.3 +++ squid/helpers/basic_auth/NCSA/crypt_md5.c 2 Jan 2008 15:49:27 -0000 1.3.6.1 @@ -1,8 +1,8 @@ /* * Shamelessly stolen from linux-pam, and adopted to work with - * OpenSSL md5 implementation and any magic string + * OpenSSL squid_md5 implementation and any magic string * - * Origin2: md5_crypt.c,v 1.1.1.1 2000/01/03 17:34:46 gafton Exp + * Origin2: squid_md5_crypt.c,v 1.1.1.1 2000/01/03 17:34:46 gafton Exp * * ---------------------------------------------------------------------------- * "THE BEER-WARE LICENSE" (Revision 42): @@ -18,14 +18,14 @@ #include #include #include "config.h" -#include "md5.h" +#include "squid_md5.h" -#include "crypt_md5.h" +#include "crypt_squid_md5.h" static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */ "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; -static void md5to64(char *s, unsigned long v, int n) +static void squid_md5to64(char *s, unsigned long v, int n) { while (--n >= 0) { *s++ = itoa64[v & 0x3f]; @@ -43,7 +43,7 @@ * If not the normal UNIX magic $1$ is used. */ -char *crypt_md5(const char *pw, const char *salt) +char *crypt_squid_md5(const char *pw, const char *salt) { const char *magic = "$1$"; int magiclen = 3; @@ -51,7 +51,7 @@ static const char *sp, *ep; unsigned char final[16]; int sl, pl, i, j; - MD5_CTX ctx, ctx1; + SQUID_MD5_CTX ctx, ctx1; unsigned long l; if (*salt == '$') { @@ -77,25 +77,25 @@ /* get the length of the true salt */ sl = ep - sp; - MD5Init(&ctx); + SQUID_MD5Init(&ctx); /* The password first, since that is what is most unknown */ - MD5Update(&ctx, (unsigned const char *) pw, strlen(pw)); + SQUID_MD5Update(&ctx, (unsigned const char *) pw, strlen(pw)); /* Then our magic string */ - MD5Update(&ctx, (unsigned const char *) magic, magiclen); + SQUID_MD5Update(&ctx, (unsigned const char *) magic, magiclen); /* Then the raw salt */ - MD5Update(&ctx, (unsigned const char *) sp, sl); + SQUID_MD5Update(&ctx, (unsigned const char *) sp, sl); /* Then just as many characters of the MD5(pw,salt,pw) */ - MD5Init(&ctx1); - MD5Update(&ctx1, (unsigned const char *) pw, strlen(pw)); - MD5Update(&ctx1, (unsigned const char *) sp, sl); - MD5Update(&ctx1, (unsigned const char *) pw, strlen(pw)); - MD5Final(final, &ctx1); + SQUID_MD5Init(&ctx1); + SQUID_MD5Update(&ctx1, (unsigned const char *) pw, strlen(pw)); + SQUID_MD5Update(&ctx1, (unsigned const char *) sp, sl); + SQUID_MD5Update(&ctx1, (unsigned const char *) pw, strlen(pw)); + SQUID_MD5Final(final, &ctx1); for (pl = strlen(pw); pl > 0; pl -= 16) - MD5Update(&ctx, (unsigned const char *) final, pl > 16 ? 16 : pl); + SQUID_MD5Update(&ctx, (unsigned const char *) final, pl > 16 ? 16 : pl); /* Don't leave anything around in vm they could use. */ memset(final, 0, sizeof final); @@ -103,9 +103,9 @@ /* Then something really weird... */ for (j = 0, i = strlen(pw); i; i >>= 1) if (i & 1) - MD5Update(&ctx, (unsigned const char *) final + j, 1); + SQUID_MD5Update(&ctx, (unsigned const char *) final + j, 1); else - MD5Update(&ctx, (unsigned const char *) pw + j, 1); + SQUID_MD5Update(&ctx, (unsigned const char *) pw + j, 1); /* Now make the output string */ memset(passwd, 0, sizeof(passwd)); @@ -113,7 +113,7 @@ strncat(passwd, sp, sl); strcat(passwd, "$"); - MD5Final(final, &ctx); + SQUID_MD5Final(final, &ctx); /* * and now, just to make sure things don't run too fast @@ -121,44 +121,44 @@ * need 30 seconds to build a 1000 entry dictionary... */ for (i = 0; i < 1000; i++) { - MD5Init(&ctx1); + SQUID_MD5Init(&ctx1); if (i & 1) - MD5Update(&ctx1, (unsigned const char *) pw, strlen(pw)); + SQUID_MD5Update(&ctx1, (unsigned const char *) pw, strlen(pw)); else - MD5Update(&ctx1, (unsigned const char *) final, 16); + SQUID_MD5Update(&ctx1, (unsigned const char *) final, 16); if (i % 3) - MD5Update(&ctx1, (unsigned const char *) sp, sl); + SQUID_MD5Update(&ctx1, (unsigned const char *) sp, sl); if (i % 7) - MD5Update(&ctx1, (unsigned const char *) pw, strlen(pw)); + SQUID_MD5Update(&ctx1, (unsigned const char *) pw, strlen(pw)); if (i & 1) - MD5Update(&ctx1, (unsigned const char *) final, 16); + SQUID_MD5Update(&ctx1, (unsigned const char *) final, 16); else - MD5Update(&ctx1, (unsigned const char *) pw, strlen(pw)); - MD5Final(final, &ctx1); + SQUID_MD5Update(&ctx1, (unsigned const char *) pw, strlen(pw)); + SQUID_MD5Final(final, &ctx1); } p = passwd + strlen(passwd); l = (final[0] << 16) | (final[6] << 8) | final[12]; - md5to64(p, l, 4); + squid_md5to64(p, l, 4); p += 4; l = (final[1] << 16) | (final[7] << 8) | final[13]; - md5to64(p, l, 4); + squid_md5to64(p, l, 4); p += 4; l = (final[2] << 16) | (final[8] << 8) | final[14]; - md5to64(p, l, 4); + squid_md5to64(p, l, 4); p += 4; l = (final[3] << 16) | (final[9] << 8) | final[15]; - md5to64(p, l, 4); + squid_md5to64(p, l, 4); p += 4; l = (final[4] << 16) | (final[10] << 8) | final[5]; - md5to64(p, l, 4); + squid_md5to64(p, l, 4); p += 4; l = final[11]; - md5to64(p, l, 2); + squid_md5to64(p, l, 2); p += 2; *p = '\0'; @@ -171,17 +171,17 @@ /* Created by Ramon de Carvalho Refined by Rodrigo Rubira Branco */ -char *md5sum(const char *s){ +char *squid_md5sum(const char *s){ static unsigned char digest[16]; - MD5_CTX ctx; + SQUID_MD5_CTX ctx; int idx; static char sum[33]; memset(digest,0,16); - MD5Init(&ctx); - MD5Update(&ctx,(const unsigned char *)s,strlen(s)); - MD5Final(digest,&ctx); + SQUID_MD5Init(&ctx); + SQUID_MD5Update(&ctx,(const unsigned char *)s,strlen(s)); + SQUID_MD5Final(digest,&ctx); for(idx=0;idx<16;idx++) sprintf(&sum[idx*2],"%02x",digest[idx]); Index: squid/helpers/basic_auth/squid_radius_auth/squid_rad_auth.c =================================================================== RCS file: /cvsroot/squid/squid/helpers/basic_auth/squid_radius_auth/squid_rad_auth.c,v retrieving revision 1.2 retrieving revision 1.2.6.1 diff -u -r1.2 -r1.2.6.1 --- squid/helpers/basic_auth/squid_radius_auth/squid_rad_auth.c 20 Nov 2007 14:11:21 -0000 1.2 +++ squid/helpers/basic_auth/squid_radius_auth/squid_rad_auth.c 2 Jan 2008 15:49:28 -0000 1.2.6.1 @@ -91,7 +91,7 @@ #include #endif -#include "md5.h" +#include "squid_md5.h" #include "radius.h" #include "util.h" @@ -144,12 +144,12 @@ * MD5 digest */ static void -md5_calc(uint8_t out[16], void *in, size_t len) +squid_md5_calc(uint8_t out[16], void *in, size_t len) { - MD5_CTX ctx; - MD5Init(&ctx); - MD5Update(&ctx, in, len); - MD5Final(out, &ctx); + SQUID_MD5_CTX ctx; + SQUID_MD5Init(&ctx); + SQUID_MD5Update(&ctx, in, len); + SQUID_MD5Final(out, &ctx); } /* @@ -185,7 +185,7 @@ memcpy(auth->vector, vector, AUTH_VECTOR_LEN); secretlen = strlen(secretkey); memcpy(buffer + length, secretkey, secretlen); - md5_calc(calc_digest, (unsigned char *) auth, length + secretlen); + squid_md5_calc(calc_digest, (unsigned char *) auth, length + secretlen); if (memcmp(reply_digest, calc_digest, AUTH_VECTOR_LEN) != 0) { fprintf(stderr, "Warning: Received invalid reply digest from server\n"); @@ -279,7 +279,7 @@ u_char *ptr; int length; char passbuf[MAXPASS]; - u_char md5buf[256]; + u_char squid_md5buf[256]; int secretlen; u_char cbc[AUTH_VECTOR_LEN]; int i, j; @@ -338,9 +338,9 @@ memcpy(cbc, auth->vector, AUTH_VECTOR_LEN); for (j = 0; j < length; j += AUTH_VECTOR_LEN) { /* Calculate the MD5 Digest */ - strcpy((char *)md5buf, secretkey); - memcpy(md5buf + secretlen, cbc, AUTH_VECTOR_LEN); - md5_calc(cbc, md5buf, secretlen + AUTH_VECTOR_LEN); + strcpy((char *)squid_md5buf, secretkey); + memcpy(squid_md5buf + secretlen, cbc, AUTH_VECTOR_LEN); + squid_md5_calc(cbc, squid_md5buf, secretlen + AUTH_VECTOR_LEN); /* Xor the password into the MD5 digest */ for (i = 0; i < AUTH_VECTOR_LEN; i++) { Index: squid/helpers/basic_auth/squid_radius_auth/util.c =================================================================== RCS file: /cvsroot/squid/squid/helpers/basic_auth/squid_radius_auth/util.c,v retrieving revision 1.2 retrieving revision 1.2.6.1 diff -u -r1.2 -r1.2.6.1 --- squid/helpers/basic_auth/squid_radius_auth/util.c 20 Nov 2007 14:11:21 -0000 1.2 +++ squid/helpers/basic_auth/squid_radius_auth/util.c 2 Jan 2008 15:49:28 -0000 1.2.6.1 @@ -72,7 +72,7 @@ #include #endif -#include "md5.h" +#include "squid_md5.h" #include "util.h" /* @@ -166,12 +166,12 @@ } -void md5_calc(unsigned char *output, unsigned char *input, unsigned int inlen) +void squid_md5_calc(unsigned char *output, unsigned char *input, unsigned int inlen) { - MD5_CTX context; + SQUID_MD5_CTX context; - MD5Init(&context); - MD5Update(&context, input, inlen); - MD5Final(output, &context); + SQUID_MD5Init(&context); + SQUID_MD5Update(&context, input, inlen); + SQUID_MD5Final(output, &context); } --- squid/include/md5.h Wed Jan 2 15:55:42 2008 +++ /dev/null Wed Jan 2 15:55:42 2008 @@ -1,90 +0,0 @@ -#ifndef SQUID_MD5_H -#define SQUID_MD5_H - -#if HAVE_SYS_TYPES_H -#include -#endif - -/* - * If Squid is compiled with OpenSSL then we use the MD5 routines - * from there via some wrapper macros, and the rest of this file is ignored.. - */ -#define USE_SQUID_MD5 0 - -#if USE_OPENSSL && HAVE_OPENSSL_MD5_H -#include - -/* Hack to adopt Squid to the OpenSSL syntax */ -#define MD5_DIGEST_CHARS MD5_DIGEST_LENGTH - -#define MD5Init MD5_Init -#define MD5Update MD5_Update -#define MD5Final MD5_Final - -#elif USE_OPENSSL && !HAVE_OPENSSL_MD5_H -#error Cannot find OpenSSL MD5 headers - -#elif HAVE_SYS_MD5_H -/* - * Solaris 10 provides MD5 as part of the system. - */ -#include - -/* - * They also define MD5_CTX with different field names - * fortunately we do not access it directly in the squid code. - */ - -/* Hack to adopt Squid to the OpenSSL syntax */ -#define MD5_DIGEST_CHARS MD5_DIGEST_LENGTH - -#else /* NEED_OWN_MD5 */ - - /* Turn on internal MD5 code */ -#undef USE_SQUID_MD5 -#define USE_SQUID_MD5 1 - -/* - * This is the header file for the MD5 message-digest algorithm. - * The algorithm is due to Ron Rivest. This code was - * written by Colin Plumb in 1993, no copyright is claimed. - * This code is in the public domain; do with it what you wish. - * - * Equivalent code is available from RSA Data Security, Inc. - * This code has been tested against that, and is equivalent, - * except that you don't need to include two pages of legalese - * with every copy. - * - * To compute the message digest of a chunk of bytes, declare an - * MD5Context structure, pass it to MD5Init, call MD5Update as - * needed on buffers full of bytes, and then call MD5Final, which - * will fill a supplied 16-byte array with the digest. - * - * Changed so as no longer to depend on Colin Plumb's `usual.h' - * header definitions; now uses stuff from dpkg's config.h - * - Ian Jackson . - * Still in the public domain. - * - * Changed MD5Update to take a void * for easier use and some other - * minor cleanup. - Henrik Nordstrom . - * Still in the public domain. - * - */ - -#include "squid_types.h" - -typedef struct MD5Context { - uint32_t buf[4]; - uint32_t bytes[2]; - uint32_t in[16]; -} MD5_CTX; - -void MD5Init(struct MD5Context *context); -void MD5Update(struct MD5Context *context, const void *buf, unsigned len); -void MD5Final(uint8_t digest[16], struct MD5Context *context); -void MD5Transform(uint32_t buf[4], uint32_t const in[16]); - -#define MD5_DIGEST_CHARS 16 - -#endif /* USE_OPENSSL */ -#endif /* SQUID_MD5_H */ Index: squid/lib/md5-test.c =================================================================== RCS file: /cvsroot/squid/squid/lib/md5-test.c,v retrieving revision 1.2 retrieving revision 1.2.18.1 diff -u -r1.2 -r1.2.18.1 --- squid/lib/md5-test.c 23 Sep 1998 17:16:11 -0000 1.2 +++ squid/lib/md5-test.c 2 Jan 2008 15:49:30 -0000 1.2.18.1 @@ -1,5 +1,5 @@ /* - * $Id: md5-test.c,v 1.2 1998/09/23 17:16:11 wessels Exp $ + * $Id: md5-test.c,v 1.2.18.1 2008/01/02 15:49:30 hno Exp $ */ /* @@ -8,7 +8,7 @@ */ #include "config.h" -#include "md5.h" +#include "squid_md5.h" #include "stdio.h" static void MDPrint(unsigned char digest[16]); @@ -17,12 +17,12 @@ static void MDString(char *string) { - MD5_CTX context; + SQUID_MD5_CTX context; unsigned char digest[16]; unsigned int len = strlen(string); - MD5Init(&context); - MD5Update(&context, string, len); - MD5Final(digest, &context); + SQUID_MD5Init(&context); + SQUID_MD5Update(&context, string, len); + SQUID_MD5Final(digest, &context); printf("MD5 (\"%s\") = ", string); MDPrint(digest); printf("\n"); --- /dev/null Wed Jan 2 15:55:42 2008 +++ squid/include/squid_md5.h Wed Jan 2 15:55:42 2008 @@ -0,0 +1,108 @@ +#ifndef SQUID_MD5_H +#define SQUID_MD5_H + +#if HAVE_SYS_TYPES_H +#include +#endif + +#if !USE_SQUID_MD5 +/* + * If Squid is compiled with OpenSSL then we use the MD5 routines + * from there via some wrapper macros, and the rest of this file is ignored.. + */ + +#if USE_OPENSSL && HAVE_OPENSSL_MD5_H +#define USE_SQUID_MD5 0 +#include + +/* Hack to adopt Squid to the OpenSSL syntax */ +#define SQUID_MD5_DIGEST_LENGTH MD5_DIGEST_LENGTH + +#define SQUID_MD5Init MD5_Init +#define SQUID_MD5Update MD5_Update +#define SQUID_MD5Final MD5_Final +#define SQUID_MD5_CTX MD5_CTX + +#elif USE_OPENSSL && !HAVE_OPENSSL_MD5_H +#error Cannot find OpenSSL MD5 headers + +#elif (HAVE_SYS_MD5_H || HAVE_MD5_H) && HAVE_MD5INIT +/* + * Solaris 10 provides MD5 as part of the system. + */ +#if HAVE_MD5_H +#include +#else +#include +#endif + +/* + * They also define SQUID_MD5_CTX with different field names + * fortunately we do not access it directly in the squid code. + */ + +#define SQUID_MD5Init MD5Init +#define SQUID_MD5Update MD5Update +#define SQUID_MD5Final MD5Final +#define SQUID_MD5_CTX MD5_CTX + +#ifdef MD5_DIGEST_LENGTH +#define SQUID_MD5_DIGEST_LENGTH MD5_DIGEST_LENGTH +#else +#define SQUID_MD5_DIGEST_LENGTH 16 +#endif + +#else /* No system MD5 code found */ + +/* Turn on internal MD5 code */ +#undef USE_SQUID_MD5 +#define USE_SQUID_MD5 1 +#endif +#endif + +#if USE_SQUID_MD5 + +/* + * This is the header file for the MD5 message-digest algorithm. + * The algorithm is due to Ron Rivest. This code was + * written by Colin Plumb in 1993, no copyright is claimed. + * This code is in the public domain; do with it what you wish. + * + * Equivalent code is available from RSA Data Security, Inc. + * This code has been tested against that, and is equivalent, + * except that you don't need to include two pages of legalese + * with every copy. + * + * To compute the message digest of a chunk of bytes, declare an + * MD5Context structure, pass it to SQUID_MD5Init, call SQUID_MD5Update as + * needed on buffers full of bytes, and then call SQUID_MD5Final, which + * will fill a supplied 16-byte array with the digest. + * + * Changed so as no longer to depend on Colin Plumb's `usual.h' + * header definitions; now uses stuff from dpkg's config.h + * - Ian Jackson . + * Still in the public domain. + * + * Changed SQUID_MD5Update to take a void * for easier use and some other + * minor cleanup. - Henrik Nordstrom . + * Still in the public domain. + * + */ + +#include "squid_types.h" + +typedef struct MD5Context { + uint32_t buf[4]; + uint32_t bytes[2]; + uint32_t in[16]; +} SQUID_MD5_CTX; + +void SQUID_MD5Init(struct MD5Context *context); +void SQUID_MD5Update(struct MD5Context *context, const void *buf, unsigned len); +void SQUID_MD5Final(uint8_t digest[16], struct MD5Context *context); +void SQUID_MD5Transform(uint32_t buf[4], uint32_t const in[16]); + +#define SQUID_MD5_DIGEST_LENGTH 16 + +#endif /* USE_SQUID_MD5 */ +#endif /* SQUID_MD5_H */ Index: squid/lib/md5.c =================================================================== RCS file: /cvsroot/squid/squid/lib/md5.c,v retrieving revision 1.21 retrieving revision 1.21.2.1 diff -u -r1.21 -r1.21.2.1 --- squid/lib/md5.c 20 Nov 2007 14:15:15 -0000 1.21 +++ squid/lib/md5.c 2 Jan 2008 15:49:30 -0000 1.21.2.1 @@ -10,8 +10,8 @@ * with every copy. * * To compute the message digest of a chunk of bytes, declare an - * MD5Context structure, pass it to MD5Init, call MD5Update as - * needed on buffers full of bytes, and then call MD5Final, which + * MD5Context structure, pass it to SQUID_MD5Init, call SQUID_MD5Update as + * needed on buffers full of bytes, and then call SQUID_MD5Final, which * will fill a supplied 16-byte array with the digest. * * Changed so as no longer to depend on Colin Plumb's `usual.h' header @@ -19,14 +19,17 @@ * - Ian Jackson . * Still in the public domain. * - * Changed MD5Update to take a void * for easier use and some other + * Changed SQUID_MD5Update to take a void * for easier use and some other * minor cleanup. - Henrik Nordstrom . * Still in the public domain. * + * Prefixed all symbols with "Squid" so they don't collide with + * other libraries. Henrik Nordstrom . + * Still in the public domain. */ #include "config.h" -#include "md5.h" +#include "squid_md5.h" /* * Now that we have several alternatives the MD5 files are @@ -67,7 +70,7 @@ * initialization constants. */ void -MD5Init(struct MD5Context *ctx) +SQUID_MD5Init(struct MD5Context *ctx) { ctx->buf[0] = 0x67452301; ctx->buf[1] = 0xefcdab89; @@ -83,7 +86,7 @@ * of bytes. */ void -MD5Update(struct MD5Context *ctx, const void *_buf, unsigned len) +SQUID_MD5Update(struct MD5Context *ctx, const void *_buf, unsigned len) { uint8_t const *buf = _buf; uint32_t t; @@ -102,7 +105,7 @@ /* First chunk is an odd size */ memcpy((uint8_t *) ctx->in + 64 - t, buf, t); byteSwap(ctx->in, 16); - MD5Transform(ctx->buf, ctx->in); + SQUID_MD5Transform(ctx->buf, ctx->in); buf += t; len -= t; @@ -110,7 +113,7 @@ while (len >= 64) { memcpy(ctx->in, buf, 64); byteSwap(ctx->in, 16); - MD5Transform(ctx->buf, ctx->in); + SQUID_MD5Transform(ctx->buf, ctx->in); buf += 64; len -= 64; } @@ -124,7 +127,7 @@ * 1 0* (64-bit count of bits processed, MSB-first) */ void -MD5Final(unsigned char digest[16], struct MD5Context *ctx) +SQUID_MD5Final(unsigned char digest[16], struct MD5Context *ctx) { int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */ uint8_t *p = (uint8_t *) ctx->in + count; @@ -138,7 +141,7 @@ if (count < 0) { /* Padding forces an extra block */ memset(p, 0, count + 8); byteSwap(ctx->in, 16); - MD5Transform(ctx->buf, ctx->in); + SQUID_MD5Transform(ctx->buf, ctx->in); p = (uint8_t *) ctx->in; count = 56; } @@ -148,7 +151,7 @@ /* Append length in bits and transform */ ctx->in[14] = ctx->bytes[0] << 3; ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29; - MD5Transform(ctx->buf, ctx->in); + SQUID_MD5Transform(ctx->buf, ctx->in); byteSwap(ctx->buf, 4); memcpy(digest, ctx->buf, 16); @@ -171,11 +174,11 @@ /* * The core of the MD5 algorithm, this alters an existing MD5 hash to - * reflect the addition of 16 longwords of new data. MD5Update blocks + * reflect the addition of 16 longwords of new data. SQUID_MD5Update blocks * the data and converts bytes into longwords for this routine. */ void -MD5Transform(uint32_t buf[4], uint32_t const in[16]) +SQUID_MD5Transform(uint32_t buf[4], uint32_t const in[16]) { register uint32_t a, b, c, d; Index: squid/lib/rfc2617.c =================================================================== RCS file: /cvsroot/squid/squid/lib/rfc2617.c,v retrieving revision 1.8 retrieving revision 1.8.6.1 diff -u -r1.8 -r1.8.6.1 --- squid/lib/rfc2617.c 13 Jan 2007 16:06:42 -0000 1.8 +++ squid/lib/rfc2617.c 2 Jan 2008 15:49:30 -0000 1.8.6.1 @@ -13,7 +13,7 @@ /* - * $Id: rfc2617.c,v 1.8 2007/01/13 16:06:42 hno Exp $ + * $Id: rfc2617.c,v 1.8.6.1 2008/01/02 15:49:30 hno Exp $ * * DEBUG: * AUTHOR: RFC 2617 & Robert Collins @@ -49,7 +49,7 @@ #include "config.h" #include #include "rfc2617.h" -#include "md5.h" +#include "squid_md5.h" void CvtHex(const HASH Bin, HASHHEX Hex) @@ -113,25 +113,25 @@ HASHHEX SessionKey ) { - MD5_CTX Md5Ctx; + SQUID_MD5_CTX Md5Ctx; if (pszUserName) { - MD5Init(&Md5Ctx); - MD5Update(&Md5Ctx, pszUserName, strlen(pszUserName)); - MD5Update(&Md5Ctx, ":", 1); - MD5Update(&Md5Ctx, pszRealm, strlen(pszRealm)); - MD5Update(&Md5Ctx, ":", 1); - MD5Update(&Md5Ctx, pszPassword, strlen(pszPassword)); - MD5Final((unsigned char *)HA1, &Md5Ctx); - } - if (strcasecmp(pszAlg, "md5-sess") == 0) { - MD5Init(&Md5Ctx); - MD5Update(&Md5Ctx, HA1, HASHLEN); - MD5Update(&Md5Ctx, ":", 1); - MD5Update(&Md5Ctx, pszNonce, strlen(pszNonce)); - MD5Update(&Md5Ctx, ":", 1); - MD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce)); - MD5Final((unsigned char *)HA1, &Md5Ctx); + SQUID_MD5Init(&Md5Ctx); + SQUID_MD5Update(&Md5Ctx, pszUserName, strlen(pszUserName)); + SQUID_MD5Update(&Md5Ctx, ":", 1); + SQUID_MD5Update(&Md5Ctx, pszRealm, strlen(pszRealm)); + SQUID_MD5Update(&Md5Ctx, ":", 1); + SQUID_MD5Update(&Md5Ctx, pszPassword, strlen(pszPassword)); + SQUID_MD5Final((unsigned char *)HA1, &Md5Ctx); + } + if (strcasecmp(pszAlg, "squid_md5-sess") == 0) { + SQUID_MD5Init(&Md5Ctx); + SQUID_MD5Update(&Md5Ctx, HA1, HASHLEN); + SQUID_MD5Update(&Md5Ctx, ":", 1); + SQUID_MD5Update(&Md5Ctx, pszNonce, strlen(pszNonce)); + SQUID_MD5Update(&Md5Ctx, ":", 1); + SQUID_MD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce)); + SQUID_MD5Final((unsigned char *)HA1, &Md5Ctx); } CvtHex(HA1, SessionKey); } @@ -150,40 +150,40 @@ HASHHEX Response /* request-digest or response-digest */ ) { - MD5_CTX Md5Ctx; + SQUID_MD5_CTX Md5Ctx; HASH HA2; HASH RespHash; HASHHEX HA2Hex; /* calculate H(A2) */ - MD5Init(&Md5Ctx); - MD5Update(&Md5Ctx, pszMethod, strlen(pszMethod)); - MD5Update(&Md5Ctx, ":", 1); - MD5Update(&Md5Ctx, pszDigestUri, strlen(pszDigestUri)); + SQUID_MD5Init(&Md5Ctx); + SQUID_MD5Update(&Md5Ctx, pszMethod, strlen(pszMethod)); + SQUID_MD5Update(&Md5Ctx, ":", 1); + SQUID_MD5Update(&Md5Ctx, pszDigestUri, strlen(pszDigestUri)); if (strcasecmp(pszQop, "auth-int") == 0) { - MD5Update(&Md5Ctx, ":", 1); - MD5Update(&Md5Ctx, HEntity, HASHHEXLEN); + SQUID_MD5Update(&Md5Ctx, ":", 1); + SQUID_MD5Update(&Md5Ctx, HEntity, HASHHEXLEN); } - MD5Final((unsigned char *)HA2, &Md5Ctx); + SQUID_MD5Final((unsigned char *)HA2, &Md5Ctx); CvtHex(HA2, HA2Hex); /* calculate response */ - MD5Init(&Md5Ctx); - MD5Update(&Md5Ctx, HA1, HASHHEXLEN); - MD5Update(&Md5Ctx, ":", 1); - MD5Update(&Md5Ctx, pszNonce, strlen(pszNonce)); - MD5Update(&Md5Ctx, ":", 1); + SQUID_MD5Init(&Md5Ctx); + SQUID_MD5Update(&Md5Ctx, HA1, HASHHEXLEN); + SQUID_MD5Update(&Md5Ctx, ":", 1); + SQUID_MD5Update(&Md5Ctx, pszNonce, strlen(pszNonce)); + SQUID_MD5Update(&Md5Ctx, ":", 1); if (*pszQop) { - MD5Update(&Md5Ctx, pszNonceCount, strlen(pszNonceCount)); - MD5Update(&Md5Ctx, ":", 1); - MD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce)); - MD5Update(&Md5Ctx, ":", 1); - MD5Update(&Md5Ctx, pszQop, strlen(pszQop)); - MD5Update(&Md5Ctx, ":", 1); + SQUID_MD5Update(&Md5Ctx, pszNonceCount, strlen(pszNonceCount)); + SQUID_MD5Update(&Md5Ctx, ":", 1); + SQUID_MD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce)); + SQUID_MD5Update(&Md5Ctx, ":", 1); + SQUID_MD5Update(&Md5Ctx, pszQop, strlen(pszQop)); + SQUID_MD5Update(&Md5Ctx, ":", 1); } - MD5Update(&Md5Ctx, HA2Hex, HASHHEXLEN); - MD5Final((unsigned char *)RespHash, &Md5Ctx); + SQUID_MD5Update(&Md5Ctx, HA2Hex, HASHHEXLEN); + SQUID_MD5Final((unsigned char *)RespHash, &Md5Ctx); CvtHex(RespHash, Response); } Index: squid/src/CacheDigest.c =================================================================== RCS file: /cvsroot/squid/squid/src/CacheDigest.c,v retrieving revision 1.36 retrieving revision 1.36.6.1 diff -u -r1.36 -r1.36.6.1 --- squid/src/CacheDigest.c 4 Jul 2006 21:45:24 -0000 1.36 +++ squid/src/CacheDigest.c 2 Jan 2008 15:49:30 -0000 1.36.6.1 @@ -1,6 +1,6 @@ /* - * $Id: CacheDigest.c,v 1.36 2006/07/04 21:45:24 hno Exp $ + * $Id: CacheDigest.c,v 1.36.6.1 2008/01/02 15:49:30 hno Exp $ * * DEBUG: section 70 Cache Digest * AUTHOR: Alex Rousskov @@ -70,7 +70,7 @@ cacheDigestCreate(int capacity, int bpe) { CacheDigest *cd = memAllocate(MEM_CACHE_DIGEST); - assert(MD5_DIGEST_CHARS == 16); /* our hash functions rely on 16 byte keys */ + assert(SQUID_MD5_DIGEST_LENGTH == 16); /* our hash functions rely on 16 byte keys */ cacheDigestInit(cd, capacity, bpe); return cd; } Index: squid/src/cache_diff.c =================================================================== RCS file: /cvsroot/squid/squid/src/cache_diff.c,v retrieving revision 1.18 retrieving revision 1.18.6.1 diff -u -r1.18 -r1.18.6.1 --- squid/src/cache_diff.c 22 May 2006 18:55:23 -0000 1.18 +++ squid/src/cache_diff.c 2 Jan 2008 15:49:31 -0000 1.18.6.1 @@ -1,6 +1,6 @@ /* - * $Id: cache_diff.c,v 1.18 2006/05/22 18:55:23 serassio Exp $ + * $Id: cache_diff.c,v 1.18.6.1 2008/01/02 15:49:31 hno Exp $ * * AUTHOR: Alex Rousskov * @@ -54,7 +54,7 @@ const cache_key *key; struct _CacheEntry *next; /* storeSwapLogData s; */ - unsigned char key_arr[MD5_DIGEST_CHARS]; + unsigned char key_arr[SQUID_MD5_DIGEST_LENGTH]; } CacheEntry; @@ -81,7 +81,7 @@ CacheEntry *e = xcalloc(1, sizeof(CacheEntry)); assert(s); /* e->s = *s; */ - xmemcpy(e->key_arr, s->key, MD5_DIGEST_CHARS); + xmemcpy(e->key_arr, s->key, SQUID_MD5_DIGEST_LENGTH); e->key = &e->key_arr[0]; return e; } Index: squid/src/htcp.c =================================================================== RCS file: /cvsroot/squid/squid/src/htcp.c,v retrieving revision 1.55 retrieving revision 1.55.2.1 diff -u -r1.55 -r1.55.2.1 --- squid/src/htcp.c 21 Jan 2007 12:54:00 -0000 1.55 +++ squid/src/htcp.c 2 Jan 2008 15:49:31 -0000 1.55.2.1 @@ -1,6 +1,6 @@ /* - * $Id: htcp.c,v 1.55 2007/01/21 12:54:00 adrian Exp $ + * $Id: htcp.c,v 1.55.2.1 2008/01/02 15:49:31 hno Exp $ * * DEBUG: section 31 Hypertext Caching Protocol * AUTHOR: Duane Wesssels @@ -178,7 +178,7 @@ static int htcpOutSocket = -1; #define N_QUERIED_KEYS 8192 static u_num32 queried_id[N_QUERIED_KEYS]; -static cache_key queried_keys[N_QUERIED_KEYS][MD5_DIGEST_CHARS]; +static cache_key queried_keys[N_QUERIED_KEYS][SQUID_MD5_DIGEST_LENGTH]; static struct sockaddr_in queried_addr[N_QUERIED_KEYS]; static MemPool *htcpSpecifierPool = NULL; static MemPool *htcpDetailPool = NULL; Index: squid/src/icp_v2.c =================================================================== RCS file: /cvsroot/squid/squid/src/icp_v2.c,v retrieving revision 1.72 retrieving revision 1.72.6.1 diff -u -r1.72 -r1.72.6.1 --- squid/src/icp_v2.c 25 Jun 2006 15:53:14 -0000 1.72 +++ squid/src/icp_v2.c 2 Jan 2008 15:49:31 -0000 1.72.6.1 @@ -1,6 +1,6 @@ /* - * $Id: icp_v2.c,v 1.72 2006/06/25 15:53:14 serassio Exp $ + * $Id: icp_v2.c,v 1.72.6.1 2008/01/02 15:49:31 hno Exp $ * * DEBUG: section 12 Internet Cache Protocol * AUTHOR: Duane Wessels @@ -543,7 +543,7 @@ #define N_QUERIED_KEYS 8192 #define N_QUERIED_KEYS_MASK 8191 -static cache_key queried_keys[N_QUERIED_KEYS][MD5_DIGEST_CHARS]; +static cache_key queried_keys[N_QUERIED_KEYS][SQUID_MD5_DIGEST_LENGTH]; int icpSetCacheKey(const cache_key * key) Index: squid/src/mem.c =================================================================== RCS file: /cvsroot/squid/squid/src/mem.c,v retrieving revision 1.77 retrieving revision 1.77.2.1 diff -u -r1.77 -r1.77.2.1 --- squid/src/mem.c 24 Sep 2007 13:31:19 -0000 1.77 +++ squid/src/mem.c 2 Jan 2008 15:49:31 -0000 1.77.2.1 @@ -1,6 +1,6 @@ /* - * $Id: mem.c,v 1.77 2007/09/24 13:31:19 hno Exp $ + * $Id: mem.c,v 1.77.2.1 2008/01/02 15:49:31 hno Exp $ * * DEBUG: section 13 High Level Memory Pool Management * AUTHOR: Harvest Derived @@ -359,7 +359,7 @@ memDataInit(MEM_STOREENTRY, "StoreEntry", sizeof(StoreEntry), 0); memDataInit(MEM_WORDLIST, "wordlist", sizeof(wordlist), 0); memDataInit(MEM_CLIENT_INFO, "ClientInfo", sizeof(ClientInfo), 0); - memDataInit(MEM_MD5_DIGEST, "MD5 digest", MD5_DIGEST_CHARS, 0); + memDataInit(MEM_MD5_DIGEST, "MD5 digest", SQUID_MD5_DIGEST_LENGTH, 0); memDataInit(MEM_HELPER_REQUEST, "helper_request", sizeof(helper_request), 0); memDataInit(MEM_HELPER_STATEFUL_REQUEST, "helper_stateful_request", Index: squid/src/squid.h =================================================================== RCS file: /cvsroot/squid/squid/src/squid.h,v retrieving revision 1.244 retrieving revision 1.244.6.1 diff -u -r1.244 -r1.244.6.1 --- squid/src/squid.h 8 Sep 2006 19:41:24 -0000 1.244 +++ squid/src/squid.h 2 Jan 2008 15:49:31 -0000 1.244.6.1 @@ -1,6 +1,6 @@ /* - * $Id: squid.h,v 1.244 2006/09/08 19:41:24 serassio Exp $ + * $Id: squid.h,v 1.244.6.1 2008/01/02 15:49:31 hno Exp $ * * AUTHOR: Duane Wessels * @@ -390,7 +390,7 @@ #include #endif -#include "md5.h" +#include "squid_md5.h" #if USE_SSL #include "ssl_support.h" Index: squid/src/store.c =================================================================== RCS file: /cvsroot/squid/squid/src/store.c,v retrieving revision 1.584 retrieving revision 1.584.2.1 diff -u -r1.584 -r1.584.2.1 --- squid/src/store.c 14 Dec 2007 20:05:24 -0000 1.584 +++ squid/src/store.c 2 Jan 2008 15:49:31 -0000 1.584.2.1 @@ -1,6 +1,6 @@ /* - * $Id: store.c,v 1.584 2007/12/14 20:05:24 hno Exp $ + * $Id: store.c,v 1.584.2.1 2008/01/02 15:49:31 hno Exp $ * * DEBUG: section 20 Storage Manager * AUTHOR: Harvest Derived @@ -101,11 +101,11 @@ url_checksum(const char *url) { unsigned int ck; - MD5_CTX M; + SQUID_MD5_CTX M; static unsigned char digest[16]; - MD5Init(&M); - MD5Update(&M, (unsigned char *) url, strlen(url)); - MD5Final(digest, &M); + SQUID_MD5Init(&M); + SQUID_MD5Update(&M, (unsigned char *) url, strlen(url)); + SQUID_MD5Final(digest, &M); xmemcpy(&ck, digest, sizeof(ck)); return ck; } Index: squid/src/store_client.c =================================================================== RCS file: /cvsroot/squid/squid/src/store_client.c,v retrieving revision 1.127 retrieving revision 1.127.2.1 diff -u -r1.127 -r1.127.2.1 --- squid/src/store_client.c 14 Dec 2007 20:05:24 -0000 1.127 +++ squid/src/store_client.c 2 Jan 2008 15:49:31 -0000 1.127.2.1 @@ -1,6 +1,6 @@ /* - * $Id: store_client.c,v 1.127 2007/12/14 20:05:24 hno Exp $ + * $Id: store_client.c,v 1.127.2.1 2008/01/02 15:49:31 hno Exp $ * * DEBUG: section 20 Storage Manager Client-Side Interface * AUTHOR: Duane Wessels @@ -410,9 +410,9 @@ for (t = tlv_list; t && swap_object_ok; t = t->next) { switch (t->type) { case STORE_META_KEY: - assert(t->length == MD5_DIGEST_CHARS); + assert(t->length == SQUID_MD5_DIGEST_LENGTH); if (!EBIT_TEST(e->flags, KEY_PRIVATE) && - memcmp(t->value, e->hash.key, MD5_DIGEST_CHARS)) { + memcmp(t->value, e->hash.key, SQUID_MD5_DIGEST_LENGTH)) { debug(20, 2) ("storeClientReadHeader: swapin MD5 mismatch\n"); debug(20, 2) ("\t%s\n", storeKeyText(t->value)); debug(20, 2) ("\t%s\n", storeKeyText(e->hash.key)); Index: squid/src/store_key_md5.c =================================================================== RCS file: /cvsroot/squid/squid/src/store_key_md5.c,v retrieving revision 1.32 retrieving revision 1.32.2.1 diff -u -r1.32 -r1.32.2.1 --- squid/src/store_key_md5.c 16 Dec 2007 17:34:12 -0000 1.32 +++ squid/src/store_key_md5.c 2 Jan 2008 15:49:31 -0000 1.32.2.1 @@ -1,6 +1,6 @@ /* - * $Id: store_key_md5.c,v 1.32 2007/12/16 17:34:12 serassio Exp $ + * $Id: store_key_md5.c,v 1.32.2.1 2008/01/02 15:49:31 hno Exp $ * * DEBUG: section 20 Storage Manager MD5 Cache Keys * AUTHOR: Duane Wessels @@ -35,7 +35,7 @@ #include "squid.h" -static cache_key null_key[MD5_DIGEST_CHARS]; +static cache_key null_key[SQUID_MD5_DIGEST_LENGTH]; const char * storeKeyText(const unsigned char *key) @@ -43,7 +43,7 @@ static MemBuf mb = MemBufNULL; int i; memBufReset(&mb); - for (i = 0; i < MD5_DIGEST_CHARS; i++) + for (i = 0; i < SQUID_MD5_DIGEST_LENGTH; i++) memBufPrintf(&mb, "%02X", *(key + i)); return mb.buf; } @@ -51,11 +51,11 @@ const cache_key * storeKeyScan(const char *buf) { - static unsigned char digest[MD5_DIGEST_CHARS]; + static unsigned char digest[SQUID_MD5_DIGEST_LENGTH]; int i; int j = 0; char t[3]; - for (i = 0; i < MD5_DIGEST_CHARS; i++) { + for (i = 0; i < SQUID_MD5_DIGEST_LENGTH; i++) { t[0] = *(buf + (j++)); t[1] = *(buf + (j++)); t[2] = '\0'; @@ -70,7 +70,7 @@ const unsigned char *A = a; const unsigned char *B = b; int i; - for (i = 0; i < MD5_DIGEST_CHARS; i++) { + for (i = 0; i < SQUID_MD5_DIGEST_LENGTH; i++) { if (A[i] < B[i]) return -1; if (A[i] > B[i]) @@ -94,29 +94,29 @@ const cache_key * storeKeyPrivate(const char *url, method_t method, int id) { - static cache_key digest[MD5_DIGEST_CHARS]; - MD5_CTX M; + static cache_key digest[SQUID_MD5_DIGEST_LENGTH]; + SQUID_MD5_CTX M; assert(id > 0); debug(20, 3) ("storeKeyPrivate: %s %s\n", RequestMethods[method].str, url); - MD5Init(&M); - MD5Update(&M, (unsigned char *) &id, sizeof(id)); - MD5Update(&M, (unsigned char *) &method, sizeof(method)); - MD5Update(&M, (unsigned char *) url, strlen(url)); - MD5Final(digest, &M); + SQUID_MD5Init(&M); + SQUID_MD5Update(&M, (unsigned char *) &id, sizeof(id)); + SQUID_MD5Update(&M, (unsigned char *) &method, sizeof(method)); + SQUID_MD5Update(&M, (unsigned char *) url, strlen(url)); + SQUID_MD5Final(digest, &M); return digest; } const cache_key * storeKeyPublic(const char *url, const method_t method) { - static cache_key digest[MD5_DIGEST_CHARS]; + static cache_key digest[SQUID_MD5_DIGEST_LENGTH]; unsigned char m = (unsigned char) method; - MD5_CTX M; - MD5Init(&M); - MD5Update(&M, &m, sizeof(m)); - MD5Update(&M, (unsigned char *) url, strlen(url)); - MD5Final(digest, &M); + SQUID_MD5_CTX M; + SQUID_MD5Init(&M); + SQUID_MD5Update(&M, &m, sizeof(m)); + SQUID_MD5Update(&M, (unsigned char *) url, strlen(url)); + SQUID_MD5Final(digest, &M); return digest; } @@ -129,10 +129,10 @@ const cache_key * storeKeyPublicByRequestMethod(request_t * request, const method_t method) { - static cache_key digest[MD5_DIGEST_CHARS]; + static cache_key digest[SQUID_MD5_DIGEST_LENGTH]; unsigned char m = (unsigned char) method; const char *url; - MD5_CTX M; + SQUID_MD5_CTX M; if (request->store_url) { url = request->store_url; @@ -140,22 +140,22 @@ url = urlCanonical(request); } - MD5Init(&M); - MD5Update(&M, &m, sizeof(m)); - MD5Update(&M, (unsigned char *) url, strlen(url)); + SQUID_MD5Init(&M); + SQUID_MD5Update(&M, &m, sizeof(m)); + SQUID_MD5Update(&M, (unsigned char *) url, strlen(url)); if (request->vary_headers) { - MD5Update(&M, (unsigned char *) "\0V", 2); - MD5Update(&M, (unsigned char *) request->vary_headers, strlen(request->vary_headers)); + SQUID_MD5Update(&M, (unsigned char *) "\0V", 2); + SQUID_MD5Update(&M, (unsigned char *) request->vary_headers, strlen(request->vary_headers)); if (strBuf(request->vary_encoding)) { - MD5Update(&M, (unsigned char *) "\0E", 2); - MD5Update(&M, (unsigned char *) strBuf(request->vary_encoding), strLen(request->vary_encoding)); + SQUID_MD5Update(&M, (unsigned char *) "\0E", 2); + SQUID_MD5Update(&M, (unsigned char *) strBuf(request->vary_encoding), strLen(request->vary_encoding)); } } if (request->urlgroup) { - MD5Update(&M, (unsigned char *) "\0G", 2); - MD5Update(&M, (unsigned char *) request->urlgroup, strlen(request->urlgroup)); + SQUID_MD5Update(&M, (unsigned char *) "\0G", 2); + SQUID_MD5Update(&M, (unsigned char *) request->urlgroup, strlen(request->urlgroup)); } - MD5Final(digest, &M); + SQUID_MD5Final(digest, &M); return digest; } @@ -163,14 +163,14 @@ storeKeyDup(const cache_key * key) { cache_key *dup = memAllocate(MEM_MD5_DIGEST); - xmemcpy(dup, key, MD5_DIGEST_CHARS); + xmemcpy(dup, key, SQUID_MD5_DIGEST_LENGTH); return dup; } cache_key * storeKeyCopy(cache_key * dst, const cache_key * src) { - xmemcpy(dst, src, MD5_DIGEST_CHARS); + xmemcpy(dst, src, SQUID_MD5_DIGEST_LENGTH); return dst; } @@ -192,7 +192,7 @@ int storeKeyNull(const cache_key * key) { - if (memcmp(key, null_key, MD5_DIGEST_CHARS) == 0) + if (memcmp(key, null_key, SQUID_MD5_DIGEST_LENGTH) == 0) return 1; else return 0; @@ -201,5 +201,5 @@ void storeKeyInit(void) { - memset(null_key, '\0', MD5_DIGEST_CHARS); + memset(null_key, '\0', SQUID_MD5_DIGEST_LENGTH); } Index: squid/src/store_swapmeta.c =================================================================== RCS file: /cvsroot/squid/squid/src/store_swapmeta.c,v retrieving revision 1.23 retrieving revision 1.23.2.1 diff -u -r1.23 -r1.23.2.1 --- squid/src/store_swapmeta.c 14 Dec 2007 20:05:24 -0000 1.23 +++ squid/src/store_swapmeta.c 2 Jan 2008 15:49:31 -0000 1.23.2.1 @@ -1,6 +1,6 @@ /* - * $Id: store_swapmeta.c,v 1.23 2007/12/14 20:05:24 hno Exp $ + * $Id: store_swapmeta.c,v 1.23.2.1 2008/01/02 15:49:31 hno Exp $ * * DEBUG: section 20 Storage Manager Swapfile Metadata * AUTHOR: Kostas Anagnostakis @@ -73,7 +73,7 @@ assert(e->swap_status == SWAPOUT_WRITING); url = storeUrl(e); debug(20, 3) ("storeSwapMetaBuild: %s\n", url); - T = storeSwapTLVAdd(STORE_META_KEY, e->hash.key, MD5_DIGEST_CHARS, T); + T = storeSwapTLVAdd(STORE_META_KEY, e->hash.key, SQUID_MD5_DIGEST_LENGTH, T); #if SIZEOF_SQUID_FILE_SZ == SIZEOF_SIZE_T T = storeSwapTLVAdd(STORE_META_STD, &e->timestamp, STORE_HDR_METASIZE, T); #else Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid/squid/src/structs.h,v retrieving revision 1.538 retrieving revision 1.538.2.1 diff -u -r1.538 -r1.538.2.1 --- squid/src/structs.h 14 Dec 2007 20:05:24 -0000 1.538 +++ squid/src/structs.h 2 Jan 2008 15:49:31 -0000 1.538.2.1 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.538 2007/12/14 20:05:24 hno Exp $ + * $Id: structs.h,v 1.538.2.1 2008/01/02 15:49:31 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -2192,7 +2192,7 @@ squid_file_sz swap_file_sz; u_short refcount; u_short flags; - unsigned char key[MD5_DIGEST_CHARS]; + unsigned char key[SQUID_MD5_DIGEST_LENGTH]; }; struct _storeSwapLogHeader { @@ -2212,7 +2212,7 @@ size_t swap_file_sz; u_short refcount; u_short flags; - unsigned char key[MD5_DIGEST_CHARS]; + unsigned char key[SQUID_MD5_DIGEST_LENGTH]; }; #endif Index: squid/src/test_cache_digest.c =================================================================== RCS file: /cvsroot/squid/squid/src/test_cache_digest.c,v retrieving revision 1.27 retrieving revision 1.27.8.1 diff -u -r1.27 -r1.27.8.1 --- squid/src/test_cache_digest.c 12 Jan 2001 00:37:22 -0000 1.27 +++ squid/src/test_cache_digest.c 2 Jan 2008 15:49:31 -0000 1.27.8.1 @@ -1,6 +1,6 @@ /* - * $Id: test_cache_digest.c,v 1.27 2001/01/12 00:37:22 wessels Exp $ + * $Id: test_cache_digest.c,v 1.27.8.1 2008/01/02 15:49:31 hno Exp $ * * AUTHOR: Alex Rousskov * @@ -63,13 +63,13 @@ typedef struct _CacheEntry { const cache_key *key; struct _CacheEntry *next; - unsigned char key_arr[MD5_DIGEST_CHARS]; + unsigned char key_arr[SQUID_MD5_DIGEST_LENGTH]; /* storeSwapLogData s; */ } CacheEntry; /* parsed access log entry */ typedef struct { - cache_key key[MD5_DIGEST_CHARS]; + cache_key key[SQUID_MD5_DIGEST_LENGTH]; time_t timestamp; short int use_icp; /* true/false */ } RawAccessLogEntry; @@ -211,7 +211,7 @@ CacheEntry *e = xcalloc(1, sizeof(CacheEntry)); assert(s); /* e->s = *s; */ - xmemcpy(e->key_arr, s->key, MD5_DIGEST_CHARS); + xmemcpy(e->key_arr, s->key, SQUID_MD5_DIGEST_LENGTH); e->key = &e->key_arr[0]; return e; } Index: squid/src/wccp2.c =================================================================== RCS file: /cvsroot/squid/squid/src/wccp2.c,v retrieving revision 1.31 retrieving revision 1.31.2.1 diff -u -r1.31 -r1.31.2.1 --- squid/src/wccp2.c 7 Apr 2007 10:02:23 -0000 1.31 +++ squid/src/wccp2.c 2 Jan 2008 15:49:31 -0000 1.31.2.1 @@ -1,6 +1,6 @@ /* - * $Id: wccp2.c,v 1.31 2007/04/07 10:02:23 serassio Exp $ + * $Id: wccp2.c,v 1.31.2.1 2008/01/02 15:49:31 hno Exp $ * * DEBUG: section 80 WCCP Support * AUTHOR: Steven WIlton @@ -446,7 +446,7 @@ { u_int8_t md5_digest[16]; char pwd[WCCP2_PASSWORD_LEN]; - MD5_CTX M; + SQUID_MD5_CTX M; struct wccp2_security_md5_t *ws; debug(80, 5) ("wccp2_update_md5_security: called\n"); @@ -469,10 +469,10 @@ */ /* XXX eventually we should be able to kill md5_digest and blit it directly in */ memset(ws->security_implementation, 0, sizeof(ws->security_implementation)); - MD5Init(&M); - MD5Update(&M, pwd, 8); - MD5Update(&M, packet, len); - MD5Final(md5_digest, &M); + SQUID_MD5Init(&M); + SQUID_MD5Update(&M, pwd, 8); + SQUID_MD5Update(&M, packet, len); + SQUID_MD5Final(md5_digest, &M); memcpy(ws->security_implementation, md5_digest, sizeof(md5_digest)); /* Finished! */ return 1; @@ -488,7 +488,7 @@ struct wccp2_security_md5_t *ws = (struct wccp2_security_md5_t *) security; u_int8_t md5_digest[16], md5_challenge[16]; char pwd[WCCP2_PASSWORD_LEN]; - MD5_CTX M; + SQUID_MD5_CTX M; /* Make sure the security type matches what we expect */ if (ntohl(ws->security_option) != srv->wccp2_security_type) { @@ -511,10 +511,10 @@ /* Take a copy of the challenge: we need to NUL it before comparing */ memcpy(md5_challenge, ws->security_implementation, 16); memset(ws->security_implementation, 0, sizeof(ws->security_implementation)); - MD5Init(&M); - MD5Update(&M, pwd, 8); - MD5Update(&M, packet, len); - MD5Final(md5_digest, &M); + SQUID_MD5Init(&M); + SQUID_MD5Update(&M, pwd, 8); + SQUID_MD5Update(&M, packet, len); + SQUID_MD5Final(md5_digest, &M); return (memcmp(md5_digest, md5_challenge, 16) == 0); } Index: squid/src/fs/aufs/store_dir_aufs.c =================================================================== RCS file: /cvsroot/squid/squid/src/fs/aufs/store_dir_aufs.c,v retrieving revision 1.70 retrieving revision 1.70.2.1 diff -u -r1.70 -r1.70.2.1 --- squid/src/fs/aufs/store_dir_aufs.c 12 Oct 2007 23:58:43 -0000 1.70 +++ squid/src/fs/aufs/store_dir_aufs.c 2 Jan 2008 15:49:32 -0000 1.70.2.1 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_aufs.c,v 1.70 2007/10/12 23:58:43 hno Exp $ + * $Id: store_dir_aufs.c,v 1.70.2.1 2008/01/02 15:49:32 hno Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -404,7 +404,7 @@ LOCAL_ARRAY(char, hdr_buf, SM_PAGE_SIZE); StoreEntry *e = NULL; StoreEntry tmpe; - cache_key key[MD5_DIGEST_CHARS]; + cache_key key[SQUID_MD5_DIGEST_LENGTH]; sfileno filn = 0; int count; int size; @@ -463,13 +463,13 @@ continue; } debug(47, 3) ("storeAufsDirRebuildFromDirectory: successful swap meta unpacking\n"); - memset(key, '\0', MD5_DIGEST_CHARS); + memset(key, '\0', SQUID_MD5_DIGEST_LENGTH); memset(&tmpe, '\0', sizeof(StoreEntry)); for (t = tlv_list; t; t = t->next) { switch (t->type) { case STORE_META_KEY: - assert(t->length == MD5_DIGEST_CHARS); - xmemcpy(key, t->value, MD5_DIGEST_CHARS); + assert(t->length == SQUID_MD5_DIGEST_LENGTH); + xmemcpy(key, t->value, SQUID_MD5_DIGEST_LENGTH); break; #if SIZEOF_SQUID_FILE_SZ == SIZEOF_SIZE_T case STORE_META_STD: @@ -1246,7 +1246,7 @@ s.swap_file_sz = e->swap_file_sz; s.refcount = e->refcount; s.flags = e->flags; - xmemcpy(&s.key, e->hash.key, MD5_DIGEST_CHARS); + xmemcpy(&s.key, e->hash.key, SQUID_MD5_DIGEST_LENGTH); xmemcpy(state->outbuf + state->outbuf_offset, &s, ss); state->outbuf_offset += ss; /* buffered write */ @@ -1335,7 +1335,7 @@ s->swap_file_sz = e->swap_file_sz; s->refcount = e->refcount; s->flags = e->flags; - xmemcpy(s->key, e->hash.key, MD5_DIGEST_CHARS); + xmemcpy(s->key, e->hash.key, SQUID_MD5_DIGEST_LENGTH); file_write(aioinfo->swaplog_fd, -1, s, Index: squid/src/fs/coss/store_dir_coss.c =================================================================== RCS file: /cvsroot/squid/squid/src/fs/coss/store_dir_coss.c,v retrieving revision 1.71 retrieving revision 1.71.2.1 diff -u -r1.71 -r1.71.2.1 --- squid/src/fs/coss/store_dir_coss.c 28 Apr 2007 15:48:01 -0000 1.71 +++ squid/src/fs/coss/store_dir_coss.c 2 Jan 2008 15:49:34 -0000 1.71.2.1 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_coss.c,v 1.71 2007/04/28 15:48:01 serassio Exp $ + * $Id: store_dir_coss.c,v 1.71.2.1 2008/01/02 15:49:34 hno Exp $ * * DEBUG: section 47 Store COSS Directory Routines * AUTHOR: Eric Stern @@ -469,7 +469,7 @@ s.swap_file_sz = e->swap_file_sz; s.refcount = e->refcount; s.flags = e->flags; - xmemcpy(&s.key, e->hash.key, MD5_DIGEST_CHARS); + xmemcpy(&s.key, e->hash.key, SQUID_MD5_DIGEST_LENGTH); xmemcpy(state->outbuf + state->outbuf_offset, &s, ss); state->outbuf_offset += ss; /* buffered write */ @@ -560,7 +560,7 @@ s->swap_file_sz = e->swap_file_sz; s->refcount = e->refcount; s->flags = e->flags; - xmemcpy(s->key, e->hash.key, MD5_DIGEST_CHARS); + xmemcpy(s->key, e->hash.key, SQUID_MD5_DIGEST_LENGTH); file_write(cs->swaplog_fd, -1, s, @@ -1263,7 +1263,7 @@ squid_off_t *l, len = 0; int blocksize = cs->blksz_mask + 1; StoreEntry tmpe; - cache_key key[MD5_DIGEST_CHARS]; + cache_key key[SQUID_MD5_DIGEST_LENGTH]; sfileno filen; assert(cs->rebuild.rebuilding == 1); @@ -1299,11 +1299,11 @@ debug(47, 3) ("Size: %" PRINTF_OFF_T " (len %d)\n", *l, t->length); break; case STORE_META_KEY: - if (t->length != MD5_DIGEST_CHARS) { + if (t->length != SQUID_MD5_DIGEST_LENGTH) { debug(47, 1) ("COSS: %s: stripe %d: offset %d has invalid STORE_META_KEY length. Ignoring object.\n", stripePath(SD), cs->rebuild.curstripe, j); goto nextobject; } - xmemcpy(key, t->value, MD5_DIGEST_CHARS); + xmemcpy(key, t->value, SQUID_MD5_DIGEST_LENGTH); break; #if SIZEOF_SQUID_FILE_SZ == SIZEOF_SIZE_T case STORE_META_STD: Index: squid/src/fs/diskd/store_dir_diskd.c =================================================================== RCS file: /cvsroot/squid/squid/src/fs/diskd/store_dir_diskd.c,v retrieving revision 1.90 retrieving revision 1.90.2.1 diff -u -r1.90 -r1.90.2.1 --- squid/src/fs/diskd/store_dir_diskd.c 1 Mar 2007 07:21:46 -0000 1.90 +++ squid/src/fs/diskd/store_dir_diskd.c 2 Jan 2008 15:49:35 -0000 1.90.2.1 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_diskd.c,v 1.90 2007/03/01 07:21:46 wessels Exp $ + * $Id: store_dir_diskd.c,v 1.90.2.1 2008/01/02 15:49:35 hno Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -581,7 +581,7 @@ LOCAL_ARRAY(char, hdr_buf, SM_PAGE_SIZE); StoreEntry *e = NULL; StoreEntry tmpe; - cache_key key[MD5_DIGEST_CHARS]; + cache_key key[SQUID_MD5_DIGEST_LENGTH]; sfileno filn = 0; int count; int size; @@ -640,13 +640,13 @@ continue; } debug(20, 3) ("storeDiskdDirRebuildFromDirectory: successful swap meta unpacking\n"); - memset(key, '\0', MD5_DIGEST_CHARS); + memset(key, '\0', SQUID_MD5_DIGEST_LENGTH); memset(&tmpe, '\0', sizeof(StoreEntry)); for (t = tlv_list; t; t = t->next) { switch (t->type) { case STORE_META_KEY: - assert(t->length == MD5_DIGEST_CHARS); - xmemcpy(key, t->value, MD5_DIGEST_CHARS); + assert(t->length == SQUID_MD5_DIGEST_LENGTH); + xmemcpy(key, t->value, SQUID_MD5_DIGEST_LENGTH); break; #if SIZEOF_SQUID_FILE_SZ == SIZEOF_SIZE_T case STORE_META_STD: @@ -1471,7 +1471,7 @@ s.swap_file_sz = e->swap_file_sz; s.refcount = e->refcount; s.flags = e->flags; - xmemcpy(&s.key, e->hash.key, MD5_DIGEST_CHARS); + xmemcpy(&s.key, e->hash.key, SQUID_MD5_DIGEST_LENGTH); xmemcpy(state->outbuf + state->outbuf_offset, &s, ss); state->outbuf_offset += ss; /* buffered write */ @@ -1557,7 +1557,7 @@ s->swap_file_sz = e->swap_file_sz; s->refcount = e->refcount; s->flags = e->flags; - xmemcpy(s->key, e->hash.key, MD5_DIGEST_CHARS); + xmemcpy(s->key, e->hash.key, SQUID_MD5_DIGEST_LENGTH); file_write(diskdinfo->swaplog_fd, -1, s, Index: squid/src/fs/ufs/store_dir_ufs.c =================================================================== RCS file: /cvsroot/squid/squid/src/fs/ufs/store_dir_ufs.c,v retrieving revision 1.65 retrieving revision 1.65.2.1 diff -u -r1.65 -r1.65.2.1 --- squid/src/fs/ufs/store_dir_ufs.c 1 Mar 2007 07:21:47 -0000 1.65 +++ squid/src/fs/ufs/store_dir_ufs.c 2 Jan 2008 15:49:37 -0000 1.65.2.1 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_ufs.c,v 1.65 2007/03/01 07:21:47 wessels Exp $ + * $Id: store_dir_ufs.c,v 1.65.2.1 2008/01/02 15:49:37 hno Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -409,7 +409,7 @@ LOCAL_ARRAY(char, hdr_buf, SM_PAGE_SIZE); StoreEntry *e = NULL; StoreEntry tmpe; - cache_key key[MD5_DIGEST_CHARS]; + cache_key key[SQUID_MD5_DIGEST_LENGTH]; sfileno filn = 0; int count; int size; @@ -468,13 +468,13 @@ continue; } debug(47, 3) ("storeUfsDirRebuildFromDirectory: successful swap meta unpacking\n"); - memset(key, '\0', MD5_DIGEST_CHARS); + memset(key, '\0', SQUID_MD5_DIGEST_LENGTH); memset(&tmpe, '\0', sizeof(StoreEntry)); for (t = tlv_list; t; t = t->next) { switch (t->type) { case STORE_META_KEY: - assert(t->length == MD5_DIGEST_CHARS); - xmemcpy(key, t->value, MD5_DIGEST_CHARS); + assert(t->length == SQUID_MD5_DIGEST_LENGTH); + xmemcpy(key, t->value, SQUID_MD5_DIGEST_LENGTH); break; #if SIZEOF_SQUID_FILE_SZ == SIZEOF_SIZE_T case STORE_META_STD: @@ -1250,7 +1250,7 @@ s.swap_file_sz = e->swap_file_sz; s.refcount = e->refcount; s.flags = e->flags; - xmemcpy(&s.key, e->hash.key, MD5_DIGEST_CHARS); + xmemcpy(&s.key, e->hash.key, SQUID_MD5_DIGEST_LENGTH); xmemcpy(state->outbuf + state->outbuf_offset, &s, ss); state->outbuf_offset += ss; /* buffered write */ @@ -1339,7 +1339,7 @@ s->swap_file_sz = e->swap_file_sz; s->refcount = e->refcount; s->flags = e->flags; - xmemcpy(s->key, e->hash.key, MD5_DIGEST_CHARS); + xmemcpy(s->key, e->hash.key, SQUID_MD5_DIGEST_LENGTH); file_write(ufsinfo->swaplog_fd, -1, s,