login: add support for gnutls

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini
2024-04-09 15:43:02 +02:00
parent e07472a337
commit 35fec3ea0e
3 changed files with 43 additions and 4 deletions

View File

@@ -78,11 +78,29 @@ AM_CONDITIONAL([BUILD_EXAMPLES],
AC_CONFIG_HEADERS([config.h])
AC_ARG_WITH([gnutls],
[AS_HELP_STRING([--with-gnutls],
[Use gnutls to compute MD5])],
[WITH_GNUTLS=$withval],
[WITH_GNUTLS=auto])
AC_ARG_WITH([libgcrypt],
[AS_HELP_STRING([--with-libgcrypt],
[Use libgcrypt to compute MD5])],
[WITH_LIBGCRYPT=$withval],
[WITH_LIBGCRYPT=auto])
if test "$WITH_GNUTLS" != no; then
AC_CHECK_LIB([gnutls], [gnutls_hash_init])
if test "$WITH_GNUTLS" = yes && test "$ac_cv_lib_gnutls_gnutls_hash_init" != yes; then
AC_MSG_ERROR([gnutls not found])
fi
WITH_GNUTLS=$ac_cv_lib_gnutls_gnutls_hash_init
fi
if test "$WITH_GNUTLS" = yes; then
WITH_LIBGCRYPT=no
fi
if test "$WITH_LIBGCRYPT" != no; then
AC_CHECK_LIB([gcrypt], [gcry_control])
if test "$WITH_LIBGCRYPT" = yes && test "$ac_cv_lib_gcrypt_gcry_control" != yes; then
@@ -91,8 +109,12 @@ if test "$WITH_LIBGCRYPT" != no; then
WITH_LIBGCRYPT=$ac_cv_lib_gcrypt_gcry_control
fi
AM_CONDITIONAL([HAVE_LIBGCRYPT],
[expr "$WITH_LIBGCRYPT" : yes > /dev/null 2>&1])
NEED_MD5=no
if test "$WITH_GNUTLS" = no && test "$WITH_LIBGCRYPT" = no; then
NEED_MD5=yes
fi
AM_CONDITIONAL([NEED_MD5],
[expr "$NEED_MD5" : yes > /dev/null 2>&1])
# For MinGW.
AC_CHECK_LIB([ws2_32], [gethostbyname])

View File

@@ -12,7 +12,7 @@ if TARGET_OS_IS_WIN32
libiscsipriv_la_SOURCES += ../win32/win32_compat.c
endif
if !HAVE_LIBGCRYPT
if NEED_MD5
libiscsipriv_la_SOURCES += md5.c
endif

View File

@@ -44,6 +44,10 @@
#include "iscsi-private.h"
#include "scsi-lowlevel.h"
#include "md5.h"
#ifdef HAVE_LIBGNUTLS
#include <gnutls/crypto.h>
#endif
#ifdef HAVE_LIBGCRYPT
#include <gcrypt.h>
#endif
@@ -681,7 +685,20 @@ i2h(int i)
return i + '0';
}
#ifdef HAVE_LIBGCRYPT
#if defined HAVE_LIBGNUTLS
#define md5_context_t gnutls_hash_hd_t
#define md5_open(hd) gnutls_hash_init(hd, GNUTLS_DIG_MD5)
#define md5_write gnutls_hash
#define md5_read gnutls_hash_output
static void md5_close(md5_context_t h)
{
unsigned char digest[16];
gnutls_hash_deinit(h, digest);
}
#elif defined HAVE_LIBGCRYPT
typedef gcry_md_hd_t md5_context_t;
#define md5_open(hd) gcry_md_open(hd, GCRY_MD_MD5, 0)
#define md5_write gcry_md_write