From d408dec0bd31acf56db87336a3e62929bf628288 Mon Sep 17 00:00:00 2001 From: hniksic Date: Sat, 17 Nov 2001 20:36:21 -0800 Subject: [PATCH] [svn] Use Solaris's libmd5 when available. Published in . --- ChangeLog | 4 ++++ configure.in | 22 ++++++++++++++++++-- src/ChangeLog | 15 ++++++++++++++ src/Makefile.in | 6 +++--- src/config.h.in | 9 +++++++++ src/ftp-opie.c | 15 +++++++------- src/{md5.c => gnu-md5.c} | 2 +- src/{md5.h => gnu-md5.h} | 0 src/http.c | 43 +++++++++++++++++++--------------------- src/sysdep.h | 21 ++++++++++++++++++++ 10 files changed, 100 insertions(+), 37 deletions(-) rename src/{md5.c => gnu-md5.c} (99%) rename src/{md5.h => gnu-md5.h} (100%) diff --git a/ChangeLog b/ChangeLog index 8fc1f81b..faf19c31 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2001-11-18 Hrvoje Niksic + + * configure.in: Check for Solaris libmd5. + 2001-11-18 Hrvoje Niksic * po/: Installed ja.po, et.po, he.po, fr.po, da.po, uk.po, es.po, diff --git a/configure.in b/configure.in index ee755dfa..8f1c3011 100644 --- a/configure.in +++ b/configure.in @@ -63,14 +63,15 @@ AC_ARG_ENABLE(debug, DEBUG=$enableval, DEBUG=yes) test x"${DEBUG}" = xyes && AC_DEFINE(DEBUG) +wget_need_md5=no + case "${USE_OPIE}${USE_DIGEST}" in *yes*) - MD5_OBJ='md5$o' + wget_need_md5=yes esac if test x"$USE_OPIE" = xyes; then OPIE_OBJ='ftp-opie$o' fi -AC_SUBST(MD5_OBJ) AC_SUBST(OPIE_OBJ) dnl @@ -180,6 +181,23 @@ dnl dnl Checks for libraries. dnl +dnl +dnl Use the md5 lib if available (Solaris). +dnl + +if test x$wget_need_md5 = xyes +then + AC_DEFINE(HAVE_MD5) + AC_CHECK_LIB(md5, MD5Update, [ + AC_DEFINE(HAVE_SOLARIS_MD5) + LIBS="-lmd5 $LIBS" + ], [ + MD5_OBJ='gnu-md5$o' + AC_DEFINE(HAVE_BUILTIN_MD5) + ]) +fi +AC_SUBST(MD5_OBJ) + dnl On Solaris, -lnsl is needed to use gethostbyname. On "NCR MP-RAS dnl 3.0", however, gethostbyname is in libc, but -lnsl is still needed dnl to use -lsocket, as well as for functions such as inet_ntoa. We diff --git a/src/ChangeLog b/src/ChangeLog index 7474aa46..0c727061 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,18 @@ +2001-11-18 Hrvoje Niksic + + * md5.h: Renamed to gnu-md5.h. + + * md5.c: Renamed to gnu-md5.c. + + * http.c: Ditto. + + * ftp-opie.c: Use the new macros. + + * sysdep.h: Define md5-related macros. + + * config.h.in: Define HAVE_SOLARIS_MD5 or HAVE_BUILTIN_MD5 + depending on which md5 implementation is used. + 2001-11-18 Hrvoje Niksic * res.c (res_register_specs): Initialize OLD and HP_OLD to appease diff --git a/src/Makefile.in b/src/Makefile.in index a38fea4a..b217d32a 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -146,7 +146,7 @@ cookies$o: wget.h cookies.h hash.h url.h utils.h fnmatch$o: wget.h fnmatch.h ftp-basic$o: wget.h utils.h rbuf.h connect.h host.h ftp-ls$o: wget.h utils.h ftp.h url.h -ftp-opie$o: wget.h md5.h +ftp-opie$o: wget.h ftp$o: wget.h utils.h url.h rbuf.h retr.h ftp.h connect.h host.h fnmatch.h netrc.h getopt$o: wget.h getopt.h hash$o: wget.h utils.h hash.h @@ -155,11 +155,11 @@ host$o: wget.h utils.h host.h url.h hash.h html-parse$o: wget.h html-parse.h html-url$o: wget.h html-parse.h url.h utils.h html$o: wget.h url.h utils.h ftp.h -http$o: wget.h utils.h url.h host.h rbuf.h retr.h headers.h cookies.h connect.h fnmatch.h netrc.h md5.h +http$o: wget.h utils.h url.h host.h rbuf.h retr.h headers.h cookies.h connect.h fnmatch.h netrc.h init$o: wget.h utils.h init.h host.h recur.h netrc.h log$o: wget.h utils.h main$o: wget.h utils.h getopt.h init.h retr.h recur.h host.h cookies.h -md5$o: wget.h md5.h +gnu-md5$o: wget.h gnu-md5.h mswindows$o: wget.h url.h netrc$o: wget.h utils.h netrc.h init.h rbuf$o: wget.h rbuf.h connect.h diff --git a/src/config.h.in b/src/config.h.in index 1d21a3fc..4cdab0ff 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -204,6 +204,15 @@ char *alloca (); /* Define if all libs needed for ssl support are existing */ #undef HAVE_SSL +/* Define if we're compiling in support for MD5. */ +#undef HAVE_MD5 + +/* Define if we're using Solaris libmd5. */ +#undef HAVE_SOLARIS_MD5 + +/* Define if we're using builtin (GNU) md5.c. */ +#undef HAVE_BUILTIN_MD5 + /* First a gambit to see whether we're on Solaris. We'll need it below. */ #ifdef __sun diff --git a/src/ftp-opie.c b/src/ftp-opie.c index c664ae02..c9c7d2b9 100644 --- a/src/ftp-opie.c +++ b/src/ftp-opie.c @@ -28,7 +28,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #endif #include "wget.h" -#include "md5.h" /* Dictionary for integer-word translations. */ static char Wp[2048][4] = { @@ -2152,16 +2151,16 @@ calculate_skey_response (int sequence, const char *seed, const char *pass) char key[8]; static char buf[33]; - struct md5_ctx ctx; + MD5_CONTEXT_TYPE ctx; unsigned long results[4]; /* #### this looks 32-bit-minded */ char *feed = (char *) alloca (strlen (seed) + strlen (pass) + 1); strcpy (feed, seed); strcat (feed, pass); - md5_init_ctx (&ctx); - md5_process_bytes (feed, strlen (feed), &ctx); - md5_finish_ctx (&ctx, results); + MD5_INIT (&ctx); + MD5_UPDATE (feed, strlen (feed), &ctx); + MD5_FINISH (&ctx, results); results[0] ^= results[2]; results[1] ^= results[3]; @@ -2169,9 +2168,9 @@ calculate_skey_response (int sequence, const char *seed, const char *pass) while (0 < sequence--) { - md5_init_ctx (&ctx); - md5_process_bytes (key, 8, &ctx); - md5_finish_ctx (&ctx, results); + MD5_INIT (&ctx); + MD5_UPDATE (key, 8, &ctx); + MD5_FINISH (&ctx, results); results[0] ^= results[2]; results[1] ^= results[3]; memcpy (key, (char *) results, 8); diff --git a/src/md5.c b/src/gnu-md5.c similarity index 99% rename from src/md5.c rename to src/gnu-md5.c index 8ab922d5..a157ff59 100644 --- a/src/md5.c +++ b/src/gnu-md5.c @@ -39,7 +39,7 @@ /*#endif*/ #include "wget.h" -#include "md5.h" +#include "gnu-md5.h" #ifdef _LIBC # include diff --git a/src/md5.h b/src/gnu-md5.h similarity index 100% rename from src/md5.h rename to src/gnu-md5.h diff --git a/src/http.c b/src/http.c index 023c753c..f95a53f5 100644 --- a/src/http.c +++ b/src/http.c @@ -60,9 +60,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "connect.h" #include "fnmatch.h" #include "netrc.h" -#if USE_DIGEST -# include "md5.h" -#endif #ifdef HAVE_SSL # include "gen_sslfunc.h" #endif /* HAVE_SSL */ @@ -2202,37 +2199,37 @@ digest_authentication_encode (const char *au, const char *user, /* Calculate the digest value. */ { - struct md5_ctx ctx; + MD5_CONTEXT_TYPE ctx; unsigned char hash[MD5_HASHLEN]; unsigned char a1buf[MD5_HASHLEN * 2 + 1], a2buf[MD5_HASHLEN * 2 + 1]; unsigned char response_digest[MD5_HASHLEN * 2 + 1]; /* A1BUF = H(user ":" realm ":" password) */ - md5_init_ctx (&ctx); - md5_process_bytes (user, strlen (user), &ctx); - md5_process_bytes (":", 1, &ctx); - md5_process_bytes (realm, strlen (realm), &ctx); - md5_process_bytes (":", 1, &ctx); - md5_process_bytes (passwd, strlen (passwd), &ctx); - md5_finish_ctx (&ctx, hash); + MD5_INIT (&ctx); + MD5_UPDATE (user, strlen (user), &ctx); + MD5_UPDATE (":", 1, &ctx); + MD5_UPDATE (realm, strlen (realm), &ctx); + MD5_UPDATE (":", 1, &ctx); + MD5_UPDATE (passwd, strlen (passwd), &ctx); + MD5_FINISH (&ctx, hash); dump_hash (a1buf, hash); /* A2BUF = H(method ":" path) */ - md5_init_ctx (&ctx); - md5_process_bytes (method, strlen (method), &ctx); - md5_process_bytes (":", 1, &ctx); - md5_process_bytes (path, strlen (path), &ctx); - md5_finish_ctx (&ctx, hash); + MD5_INIT (&ctx); + MD5_UPDATE (method, strlen (method), &ctx); + MD5_UPDATE (":", 1, &ctx); + MD5_UPDATE (path, strlen (path), &ctx); + MD5_FINISH (&ctx, hash); dump_hash (a2buf, hash); /* RESPONSE_DIGEST = H(A1BUF ":" nonce ":" A2BUF) */ - md5_init_ctx (&ctx); - md5_process_bytes (a1buf, MD5_HASHLEN * 2, &ctx); - md5_process_bytes (":", 1, &ctx); - md5_process_bytes (nonce, strlen (nonce), &ctx); - md5_process_bytes (":", 1, &ctx); - md5_process_bytes (a2buf, MD5_HASHLEN * 2, &ctx); - md5_finish_ctx (&ctx, hash); + MD5_INIT (&ctx); + MD5_UPDATE (a1buf, MD5_HASHLEN * 2, &ctx); + MD5_UPDATE (":", 1, &ctx); + MD5_UPDATE (nonce, strlen (nonce), &ctx); + MD5_UPDATE (":", 1, &ctx); + MD5_UPDATE (a2buf, MD5_HASHLEN * 2, &ctx); + MD5_FINISH (&ctx, hash); dump_hash (response_digest, hash); res = (char*) xmalloc (strlen (user) diff --git a/src/sysdep.h b/src/sysdep.h index 128d024c..74f8a7cf 100644 --- a/src/sysdep.h +++ b/src/sysdep.h @@ -195,4 +195,25 @@ void *memcpy (); # define MAP_FAILED ((void *) -1) #endif +/* Define wrapper macros for different MD5 routines. */ +#ifdef HAVE_MD5 + +#ifdef HAVE_BUILTIN_MD5 +# include +# define MD5_CONTEXT_TYPE struct md5_ctx +# define MD5_INIT(ctx) md5_init_ctx (ctx) +# define MD5_UPDATE(buffer, len, ctx) md5_process_bytes (buffer, len, ctx) +# define MD5_FINISH(ctx, result) md5_finish_ctx (ctx, result) +#endif + +#ifdef HAVE_SOLARIS_MD5 +# include +# define MD5_CONTEXT_TYPE MD5_CTX +# define MD5_INIT(ctx) MD5Init (ctx) +# define MD5_UPDATE(buffer, len, ctx) MD5Update (ctx, (unsigned char *)(buffer), len) +# define MD5_FINISH(ctx, result) MD5Final ((unsigned char *)(result), ctx) +#endif + +#endif /* HAVE_MD5 */ + #endif /* SYSDEP_H */ -- 2.39.2