summaryrefslogtreecommitdiff
path: root/ninfod
diff options
context:
space:
mode:
authorYOSHIFUJI Hideaki <hideaki.yoshifuji@miraclelinux.com>2014-06-11 14:31:34 +0900
committerDavid Heidelberger <david.heidelberger@ixit.cz>2014-10-25 21:56:46 +0200
commitd8f1602c60e4a30858d622f99290d553c8542ff6 (patch)
tree850dbd669245ea86db2b1b03c17a5781c034ed6f /ninfod
parent3d1419542fd02a01c1367b5e6567c2c40a8404f2 (diff)
downloadiputils-d8f1602c60e4a30858d622f99290d553c8542ff6.tar.gz
ninfod: libgcrypt support.
Signed-off-by: YOSHIFUJI Hideaki <hideaki.yoshifuji@miraclelinux.com>
Diffstat (limited to 'ninfod')
-rw-r--r--ninfod/config.h.in3
-rwxr-xr-xninfod/configure64
-rw-r--r--ninfod/configure.in16
-rw-r--r--ninfod/iputils_md5dig.h52
-rw-r--r--ninfod/ninfod_name.c5
5 files changed, 107 insertions, 33 deletions
diff --git a/ninfod/config.h.in b/ninfod/config.h.in
index b1709dd..87ee886 100644
--- a/ninfod/config.h.in
+++ b/ninfod/config.h.in
@@ -15,6 +15,9 @@
/* Define to 1 if you have the <arpa/inet.h> header file. */
#undef HAVE_ARPA_INET_H
+/* Define to 1 if you have the <gcrypt.h> header file. */
+#undef HAVE_GCRYPT_H
+
/* Define to 1 if you have the <gnutls/openssl.h> header file. */
#undef HAVE_GNUTLS_OPENSSL_H
diff --git a/ninfod/configure b/ninfod/configure
index b29f7ec..2b8f24f 100755
--- a/ninfod/configure
+++ b/ninfod/configure
@@ -3564,6 +3564,18 @@ fi
done
+for ac_header in gcrypt.h
+do :
+ ac_fn_c_check_header_mongrel "$LINENO" "gcrypt.h" "ac_cv_header_gcrypt_h" "$ac_includes_default"
+if test "x$ac_cv_header_gcrypt_h" = xyes; then :
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_GCRYPT_H 1
+_ACEOF
+
+fi
+
+done
+
for ac_header in gnutls/openssl.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "gnutls/openssl.h" "ac_cv_header_gnutls_openssl_h" "$ac_includes_default"
@@ -4153,13 +4165,13 @@ _ACEOF
fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for MD5_Init in -lgnutls-openssl" >&5
-$as_echo_n "checking for MD5_Init in -lgnutls-openssl... " >&6; }
-if ${ac_cv_lib_gnutls_openssl_MD5_Init+:} false; then :
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for MD5_Init in -lcrypto" >&5
+$as_echo_n "checking for MD5_Init in -lcrypto... " >&6; }
+if ${ac_cv_lib_crypto_MD5_Init+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
-LIBS="-lgnutls-openssl $LIBS"
+LIBS="-lcrypto $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
@@ -4179,28 +4191,30 @@ return MD5_Init ();
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
- ac_cv_lib_gnutls_openssl_MD5_Init=yes
+ ac_cv_lib_crypto_MD5_Init=yes
else
- ac_cv_lib_gnutls_openssl_MD5_Init=no
+ ac_cv_lib_crypto_MD5_Init=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gnutls_openssl_MD5_Init" >&5
-$as_echo "$ac_cv_lib_gnutls_openssl_MD5_Init" >&6; }
-if test "x$ac_cv_lib_gnutls_openssl_MD5_Init" = xyes; then :
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_crypto_MD5_Init" >&5
+$as_echo "$ac_cv_lib_crypto_MD5_Init" >&6; }
+if test "x$ac_cv_lib_crypto_MD5_Init" = xyes; then :
$as_echo "#define HAVE_MD5_INIT 1" >>confdefs.h
- LIBS="-lgnutls-openssl $LIBS"
-else
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for MD5_Init in -lcrypto" >&5
-$as_echo_n "checking for MD5_Init in -lcrypto... " >&6; }
-if ${ac_cv_lib_crypto_MD5_Init+:} false; then :
+ LIBS="-lcrypto $LIBS"
+
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gcry_md_open in -lgcrypt" >&5
+$as_echo_n "checking for gcry_md_open in -lgcrypt... " >&6; }
+if ${ac_cv_lib_gcrypt_gcry_md_open+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
-LIBS="-lcrypto $LIBS"
+LIBS="-lgcrypt $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
@@ -4210,37 +4224,37 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
#ifdef __cplusplus
extern "C"
#endif
-char MD5_Init ();
+char gcry_md_open ();
int
main ()
{
-return MD5_Init ();
+return gcry_md_open ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
- ac_cv_lib_crypto_MD5_Init=yes
+ ac_cv_lib_gcrypt_gcry_md_open=yes
else
- ac_cv_lib_crypto_MD5_Init=no
+ ac_cv_lib_gcrypt_gcry_md_open=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_crypto_MD5_Init" >&5
-$as_echo "$ac_cv_lib_crypto_MD5_Init" >&6; }
-if test "x$ac_cv_lib_crypto_MD5_Init" = xyes; then :
- $as_echo "#define HAVE_MD5_INIT 1" >>confdefs.h
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gcrypt_gcry_md_open" >&5
+$as_echo "$ac_cv_lib_gcrypt_gcry_md_open" >&6; }
+if test "x$ac_cv_lib_gcrypt_gcry_md_open" = xyes; then :
- LIBS="-lcrypto $LIBS"
-fi
+$as_echo "#define HAVE_GCRY_MD_OPEN /**/" >>confdefs.h
+ LIBS="-lgcrypt $LIBS"
fi
+
ac_config_files="$ac_config_files Makefile ninfod.sh"
cat >confcache <<\_ACEOF
diff --git a/ninfod/configure.in b/ninfod/configure.in
index 2e3275e..ee5ce9d 100644
--- a/ninfod/configure.in
+++ b/ninfod/configure.in
@@ -77,6 +77,7 @@ dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_TIME
AC_CHECK_HEADERS(limits.h)
+AC_CHECK_HEADERS(gcrypt.h)
AC_CHECK_HEADERS(gnutls/openssl.h)
AC_CHECK_HEADERS(openssl/md5.h)
AC_CHECK_HEADERS(sys/uio.h)
@@ -123,14 +124,15 @@ AC_CHECK_FUNCS(nanosleep)
AC_CHECK_LIB(pthread, pthread_create)
AC_CHECK_LIB(cap, cap_init)
-AC_CHECK_LIB(gnutls-openssl, MD5_Init,
- AC_DEFINE(HAVE_MD5_INIT)
- LIBS="-lgnutls-openssl $LIBS",
- AC_CHECK_LIB(crypto, MD5_Init,
- AC_DEFINE(HAVE_MD5_INIT)
- LIBS="-lcrypto $LIBS",
- )
+AC_CHECK_LIB(crypto, MD5_Init,
+ AC_DEFINE(HAVE_MD5_INIT)
+ LIBS="-lcrypto $LIBS"
)
+AC_CHECK_LIB(gcrypt, gcry_md_open,
+ AC_DEFINE(HAVE_GCRY_MD_OPEN,[],[if you have gcrypt])
+ LIBS="-lgcrypt $LIBS"
+)
+
dnl AC_CHECK_LIB(crypto, MD5Init,
dnl AC_DEFINE(HAVE_MD5INIT)
dnl LIBS="-lcrypto $LIBS",
diff --git a/ninfod/iputils_md5dig.h b/ninfod/iputils_md5dig.h
new file mode 100644
index 0000000..4cec866
--- /dev/null
+++ b/ninfod/iputils_md5dig.h
@@ -0,0 +1,52 @@
+#ifndef IPUTILS_MD5DIG_H
+#define IPUTILS_MD5DIG_H
+
+#ifdef USE_GCRYPT
+# include <stdlib.h>
+# include <gcrypt.h>
+# define IPUTILS_MD5DIG_LEN 16
+#else
+# include <openssl/md5.h>
+#endif
+
+#ifdef USE_GCRYPT
+typedef struct {
+ gcry_md_hd_t dig;
+} iputils_md5dig_ctx;
+
+static void iputils_md5dig_init(iputils_md5dig_ctx *ctx)
+{
+ if (gcry_md_open(&ctx->dig, GCRY_MD_MD5, 0) != GPG_ERR_NO_ERROR)
+ abort();
+}
+
+static void iputils_md5dig_update(iputils_md5dig_ctx *ctx,
+ const void *buf, int len)
+{
+ gcry_md_write(ctx->dig, buf, len);
+}
+
+static void iputils_md5dig_final(unsigned char *digest,
+ iputils_md5dig_ctx *ctx)
+{
+ const void *p;
+ size_t dlen;
+
+ p = gcry_md_read(ctx->dig, GCRY_MD_MD5);
+ dlen = gcry_md_get_algo_dlen(GCRY_MD_MD5);
+
+ if (dlen != IPUTILS_MD5DIG_LEN)
+ abort();
+
+ memcpy(digest, p, dlen);
+
+ gcry_md_close(ctx->dig);
+}
+
+# define MD5_DIGEST_LENGTH IPUTILS_MD5DIG_LEN
+# define MD5_CTX iputils_md5dig_ctx
+# define MD5_Init iputils_md5dig_init
+# define MD5_Update iputils_md5dig_update
+# define MD5_Final iputils_md5dig_final
+#endif
+#endif
diff --git a/ninfod/ninfod_name.c b/ninfod/ninfod_name.c
index 6d7e92b..78b0f27 100644
--- a/ninfod/ninfod_name.c
+++ b/ninfod/ninfod_name.c
@@ -99,7 +99,10 @@
#include <arpa/inet.h>
-#if defined(HAVE_GNUTLS_OPENSSL_H)
+#if defined(HAVE_GCRYPT_H)
+# define USE_GCRYPT
+# include "iputils_md5dig.h"
+#elif defined(HAVE_GNUTLS_OPENSSL_H)
# include <gnutls/openssl.h>
#elif defined(HAVE_OPENSSL_MD5_H)
# include <openssl/md5.h>