From 1c7b33fb91c8b3a7de85f82a0cdd18976fb4d97e Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 17 Dec 1999 20:04:01 +0000 Subject: Remove -lmd. Use dlopen() and dlsym() instead for calls to the MD5* and SHA* routines so that callers of libcrypt are not exposed to the internal implementation. --- lib/libcrypt/Makefile | 3 --- lib/libcrypt/crypt-md5.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- lib/libcrypt/crypt-shs.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 91 insertions(+), 5 deletions(-) (limited to 'lib/libcrypt') diff --git a/lib/libcrypt/Makefile b/lib/libcrypt/Makefile index 3742913..ef66357 100644 --- a/lib/libcrypt/Makefile +++ b/lib/libcrypt/Makefile @@ -24,9 +24,6 @@ CFLAGS+= -I${.CURDIR}/../libmd CFLAGS+= -DLIBC_SCCS -Wall PRECIOUSLIB= yes -LDADD+= -lmd -DPADD+= ${LIBMD} - # Include this early to pick up the definitions of SHLIB_MAJOR and # SHLIB_MINOR which are used in the existence tests. .include "${.CURDIR}/../Makefile.inc" diff --git a/lib/libcrypt/crypt-md5.c b/lib/libcrypt/crypt-md5.c index 95255e4..004ba60 100644 --- a/lib/libcrypt/crypt-md5.c +++ b/lib/libcrypt/crypt-md5.c @@ -11,15 +11,29 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$FreeBSD$"; +static const char rcsid[] = \ +"$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ #include #include #include #include +#include #include "crypt.h" +#ifdef __PIC__ +#include + +#define MD5Init(ctx) dl_MD5Init(ctx) +#define MD5Update(ctx, data, len) dl_MD5Update(ctx, data, len) +#define MD5Final(dgst, ctx) dl_MD5Final(dgst, ctx) + +static void (*dl_MD5Init)(MD5_CTX *); +static void (*dl_MD5Update)(MD5_CTX *, const unsigned char *, unsigned int); +static void (*dl_MD5Final)(unsigned char digest[16], MD5_CTX *); +#endif + /* * UNIX password */ @@ -41,6 +55,9 @@ crypt_md5(pw, salt) int sl,pl,i; MD5_CTX ctx,ctx1; unsigned long l; +#ifdef __PIC__ + void *libmd; +#endif /* Refine the Salt first */ sp = salt; @@ -56,6 +73,29 @@ crypt_md5(pw, salt) /* get the length of the true salt */ sl = ep - sp; +#ifdef __PIC__ + libmd = dlopen("libmd.so", RTLD_NOW); + if (libmd == NULL) + return NULL; + dl_MD5Init = dlsym(libmd, "MD5Init"); + if (dl_MD5Init == NULL) { + warnx("libcrypt-md5: looking for MD5Init: %s\n", dlerror()); + dlclose(libmd); + return NULL; + } + dl_MD5Update = dlsym(libmd, "MD5Update"); + if (dl_MD5Update == NULL) { + warnx("libcrypt-md5: looking for MD5Update: %s\n", dlerror()); + dlclose(libmd); + return NULL; + } + dl_MD5Final = dlsym(libmd, "MD5Final"); + if (dl_MD5Final == NULL) { + warnx("libcrypt-md5: looking for MD5Final: %s\n", dlerror()); + dlclose(libmd); + return NULL; + } +#endif MD5Init(&ctx); /* The password first, since that is what is most unknown */ @@ -118,6 +158,9 @@ crypt_md5(pw, salt) MD5Final(final,&ctx1); } +#ifdef __PIC__ + dlclose(libmd); +#endif p = passwd + strlen(passwd); l = (final[ 0]<<16) | (final[ 6]<<8) | final[12]; diff --git a/lib/libcrypt/crypt-shs.c b/lib/libcrypt/crypt-shs.c index 683a3f5..0617b19 100644 --- a/lib/libcrypt/crypt-shs.c +++ b/lib/libcrypt/crypt-shs.c @@ -11,15 +11,29 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$FreeBSD$"; +static const char rcsid[] = \ +"$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ #include #include #include #include +#include #include "crypt.h" +#ifdef __PIC__ +#include + +#define SHA_Init(ctx) dl_SHA_Init(ctx) +#define SHA_Update(ctx, data, len) dl_SHA_Update(ctx, data, len) +#define SHA_Final(dgst, ctx) dl_SHA_Final(dgst, ctx) + +static void (*dl_SHA_Init)(SHA_CTX *); +static void (*dl_SHA_Update)(SHA_CTX *, const unsigned char *, unsigned int); +static void (*dl_SHA_Final)(unsigned char digest[20], SHA_CTX *); +#endif + /* * UNIX password */ @@ -41,6 +55,9 @@ crypt_sha(pw, salt) int sl,pl,i; SHA_CTX ctx,ctx1; unsigned long l; +#ifdef __PIC__ + void *libmd; +#endif /* Refine the Salt first */ sp = salt; @@ -56,6 +73,32 @@ crypt_sha(pw, salt) /* get the length of the true salt */ sl = ep - sp; +#ifdef __PIC__ + libmd = dlopen("libmd.so", RTLD_NOW); + if (libmd == NULL) + return NULL; + dl_SHA_Init = dlsym(libmd, "SHA_Init"); + if (dl_SHA_Init == NULL) { + warnx("libcrypt-md5: looking for SHA_Init: %s\n", dlerror()); + dlclose(libmd); + return NULL; + } + dl_SHA_Update = dlsym(libmd, "SHA_Update"); + if (dl_SHA_Update == NULL) { + warnx("libcrypt-md5: looking for SHA_Update: %s\n", dlerror()); + dlclose(libmd); + return NULL; + } + dl_SHA_Final = dlsym(libmd, "SHA_Final"); + if (dl_SHA_Final == NULL) { + warnx("libcrypt-md5: looking for SHA_Final: %s\n", dlerror()); + dlclose(libmd); + return NULL; + } +#endif + SHA_Init(&ctx); + + /* The password first, since that is what is most unknown */ SHA_Init(&ctx); /* The password first, since that is what is most unknown */ @@ -118,6 +161,9 @@ crypt_sha(pw, salt) SHA_Final(final,&ctx1); } +#ifdef __PIC__ + dlclose(libmd); +#endif p = passwd + strlen(passwd); l = (final[ 0]<<16) | (final[ 6]<<8) | final[12]; -- cgit v1.1