Skip to content

Commit

Permalink
login: add support for gnutls
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
bonzini committed Apr 9, 2024
1 parent 0fba169 commit 31ec184
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
24 changes: 22 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,27 @@ 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" = auto; then
AC_CHECK_LIB([gnutls], [gnutls_hash_init])
WITH_GNUTLS=$ac_cv_lib_gcrypt_gcry_control
fi
if test "$WITH_GNUTLS" = yes; then
AC_DEFINE([HAVE_LIBGNUTLS], 1)
WITH_LIBGCRYPT=no
fi

if test "$WITH_LIBGCRYPT" = auto; then
AC_CHECK_LIB([gcrypt], [gcry_control])
WITH_LIBGCRYPT=$ac_cv_lib_gcrypt_gcry_control
Expand All @@ -91,8 +107,12 @@ if test "$WITH_LIBGCRYPT" = yes; then
AC_DEFINE([HAVE_LIBGCRYPT], 1)
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])
Expand Down
2 changes: 1 addition & 1 deletion lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 18 additions & 1 deletion lib/login.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 31ec184

Please sign in to comment.