Convert pwd2key.c to use gnutls' HMAC function.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 942d751..2befa7b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,6 +14,7 @@
 INCLUDE(CheckStructHasMember)
 INCLUDE(TestBigEndian)
 INCLUDE(GNUInstallDirs)
+INCLUDE(FindGnuTLS)
 
 OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON)
 
@@ -152,6 +153,11 @@
   SET (OPTIONAL_LIBRARY ${BZIP2_LIBRARY})
 ENDIF(BZIP2_FOUND)
 
+IF (GNUTLS_FOUND)
+  INCLUDE_DIRECTORIES(${GNUTLS_INCLUDE_DIR})
+  SET (OPTIONAL_LIBRARY ${OPTIONAL_LIBRARY} ${GNUTLS_LIBRARY})
+ENDIF(GNUTLS_FOUND)
+
 IF(MSVC)
 ADD_DEFINITIONS("-D_CRT_SECURE_NO_WARNINGS")
 ADD_DEFINITIONS("-D_CRT_NONSTDC_NO_DEPRECATE")
diff --git a/lib/gladman-fcrypt/pwd2key.c b/lib/gladman-fcrypt/pwd2key.c
index 3bda272..c0cf9c7 100644
--- a/lib/gladman-fcrypt/pwd2key.c
+++ b/lib/gladman-fcrypt/pwd2key.c
@@ -35,13 +35,18 @@
 */
 
 #include <memory.h>
-#include "hmac.h"
+
+#include <gnutls/gnutls.h>
+#include <gnutls/crypto.h>
 
 #if defined(__cplusplus)
 extern "C"
 {
 #endif
 
+/* SHA-1 size */
+/* #define OUT_BLOCK_LENGTH 20 */
+
 INTERNAL void derive_key(const unsigned char pwd[],  /* the PASSWORD     */
                unsigned int pwd_len,        /* and its length   */
                const unsigned char salt[],  /* the SALT and its */
@@ -52,15 +57,7 @@
 {
     unsigned int    i, j, k, n_blk;
     unsigned char uu[OUT_BLOCK_LENGTH], ux[OUT_BLOCK_LENGTH];
-    hmac_ctx c1[1], c2[1], c3[1];
-
-    /* set HMAC context (c1) for password               */
-    hmac_sha1_begin(c1);
-    hmac_sha1_key(pwd, pwd_len, c1);
-
-    /* set HMAC context (c2) for password and salt      */
-    memcpy(c2, c1, sizeof(hmac_ctx));
-    hmac_sha1_data(salt, salt_len, c2);
+    gnutls_hmac_hd_t c3;
 
     /* find the number of SHA blocks in the key         */
     n_blk = 1 + (key_len - 1) / OUT_BLOCK_LENGTH;
@@ -71,7 +68,8 @@
         memset(ux, 0, OUT_BLOCK_LENGTH);
 
         /* set HMAC context (c3) for password and salt  */
-        memcpy(c3, c2, sizeof(hmac_ctx));
+	gnutls_hmac_init(&c3, GNUTLS_MAC_SHA1, pwd, pwd_len);
+	gnutls_hmac(c3, salt, salt_len);
 
         /* enter additional data for 1st block into uu  */
         uu[0] = (unsigned char)((i + 1) >> 24);
@@ -83,23 +81,25 @@
         for(j = 0, k = 4; j < iter; ++j)
         {
             /* add previous round data to HMAC      */
-            hmac_sha1_data(uu, k, c3);
+	    gnutls_hmac(c3, uu, k);
 
             /* obtain HMAC for uu[]                 */
-            hmac_sha1_end(uu, OUT_BLOCK_LENGTH, c3);
+	    gnutls_hmac_deinit(c3, uu);
 
             /* xor into the running xor block       */
             for(k = 0; k < OUT_BLOCK_LENGTH; ++k)
                 ux[k] ^= uu[k];
 
             /* set HMAC context (c3) for password   */
-            memcpy(c3, c1, sizeof(hmac_ctx));
+	    gnutls_hmac_init(&c3, GNUTLS_MAC_SHA1, pwd, pwd_len);
         }
 
         /* compile key blocks into the key output   */
         j = 0; k = i * OUT_BLOCK_LENGTH;
         while(j < OUT_BLOCK_LENGTH && k < key_len)
             key[k++] = ux[j++];
+
+	gnutls_hmac_deinit(c3, NULL);
     }
 }