crypto: add a gcrypt cipher implementation

If we are linking to gnutls already and gnutls is built against
gcrypt, then we should use gcrypt as a cipher backend in
preference to our built-in backend.

This will be used when linking against GNUTLS 1.x and many
GNUTLS 2.x versions.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1435770638-25715-6-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
diff --git a/configure b/configure
index 61a749e..f3c7ca6 100755
--- a/configure
+++ b/configure
@@ -2126,6 +2126,7 @@
 ##########################################
 # GNUTLS probe
 
+gnutls_gcrypt=no
 if test "$gnutls" != "no"; then
     if $pkg_config --exists "gnutls"; then
         gnutls_cflags=`$pkg_config --cflags gnutls`
@@ -2141,6 +2142,18 @@
 	else
 	    gnutls_hash="no"
 	fi
+
+	if $pkg_config --exists 'gnutls >= 3.0'; then
+	    gnutls_gcrypt=no
+	elif $pkg_config --exists 'gnutls >= 2.12'; then
+	    case `$pkg_config --libs --static gnutls` in
+		*gcrypt*) gnutls_gcrypt=yes     ;;
+		*nettle*) gnutls_gcrypt=no      ;;
+		*)        gnutls_gcrypt=yes     ;;
+	    esac
+	else
+	    gnutls_gcrypt=yes
+	fi
     elif test "$gnutls" = "yes"; then
 	feature_not_found "gnutls" "Install gnutls devel"
     else
@@ -2151,6 +2164,18 @@
     gnutls_hash="no"
 fi
 
+if test "$gnutls_gcrypt" != "no"; then
+    if has "libgcrypt-config"; then
+        gcrypt_cflags=`libgcrypt-config --cflags`
+        gcrypt_libs=`libgcrypt-config --libs`
+        libs_softmmu="$gcrypt_libs $libs_softmmu"
+        libs_tools="$gcrypt_libs $libs_tools"
+        QEMU_CFLAGS="$QEMU_CFLAGS $gcrypt_cflags"
+    else
+        feature_not_found "gcrypt" "Install gcrypt devel"
+    fi
+fi
+
 
 ##########################################
 # VTE probe
@@ -4463,6 +4488,7 @@
 echo "GTK support       $gtk"
 echo "GNUTLS support    $gnutls"
 echo "GNUTLS hash       $gnutls_hash"
+echo "GNUTLS gcrypt     $gnutls_gcrypt"
 echo "VTE support       $vte"
 echo "curses support    $curses"
 echo "curl support      $curl"
@@ -4827,6 +4853,9 @@
 if test "$gnutls_hash" = "yes" ; then
   echo "CONFIG_GNUTLS_HASH=y" >> $config_host_mak
 fi
+if test "$gnutls_gcrypt" = "yes" ; then
+  echo "CONFIG_GNUTLS_GCRYPT=y" >> $config_host_mak
+fi
 if test "$vte" = "yes" ; then
   echo "CONFIG_VTE=y" >> $config_host_mak
   echo "VTE_CFLAGS=$vte_cflags" >> $config_host_mak