gnutls-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU gnutls branch, master, updated. gnutls_2_9_10-271-g16aa46b


From: Nikos Mavrogiannopoulos
Subject: [SCM] GNU gnutls branch, master, updated. gnutls_2_9_10-271-g16aa46b
Date: Tue, 29 Jun 2010 16:16:41 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU gnutls".

http://git.savannah.gnu.org/cgit/gnutls.git/commit/?id=16aa46b90da439cd992f4067394b6f8cb4cbb1ad

The branch, master has been updated
       via  16aa46b90da439cd992f4067394b6f8cb4cbb1ad (commit)
       via  223a78e601447d4d82be07da7e1506809d7d0e9a (commit)
       via  10a6640bfed1d64e59ca29ed27937d21758d3bc5 (commit)
      from  1c4ce7d26b4c71d15af101021d7ce28cf4fda240 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 16aa46b90da439cd992f4067394b6f8cb4cbb1ad
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Tue Jun 29 18:12:44 2010 +0200

    simplified locking code. Locking functions always exist but are dummies if 
no
    locks have been set.

commit 223a78e601447d4d82be07da7e1506809d7d0e9a
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Tue Jun 29 18:05:18 2010 +0200

    Initialization of crypto libraries moved outside main gnutls code.

commit 10a6640bfed1d64e59ca29ed27937d21758d3bc5
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Tue Jun 29 17:42:47 2010 +0200

    Moved locking code to special file.

-----------------------------------------------------------------------

Summary of changes:
 lib/Makefile.am                        |    4 +-
 lib/gcrypt/Makefile.am                 |    2 +-
 lib/gcrypt/init.c                      |  105 ++++++++++++++++
 lib/gnutls_errors.c                    |    2 +
 lib/gnutls_global.c                    |  214 ++------------------------------
 lib/gnutls_global.h                    |    7 +-
 lib/includes/gnutls/gnutls.h.in        |    2 +
 lib/locks.c                            |  181 +++++++++++++++++++++++++++
 lib/locks.h                            |   22 ++++
 lib/nettle/Makefile.am                 |    2 +-
 lib/{gnutls_helper.c => nettle/init.c} |   23 ++--
 lib/nettle/rnd.c                       |    7 +-
 12 files changed, 340 insertions(+), 231 deletions(-)
 create mode 100644 lib/gcrypt/init.c
 create mode 100644 lib/locks.c
 create mode 100644 lib/locks.h
 copy lib/{gnutls_helper.c => nettle/init.c} (76%)

diff --git a/lib/Makefile.am b/lib/Makefile.am
index 8eb2d2d..7034b53 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -80,7 +80,7 @@ COBJECTS = gnutls_record.c gnutls_compress.c debug.c 
gnutls_cipher.c  \
        auth_dh_common.c gnutls_helper.c gnutls_supplemental.c          \
        crypto.c random.c  ext_signature.c cryptodev.c \
        crypto-api.c ext_safe_renegotiation.c gnutls_privkey.c \
-       pkcs11.c pkcs11_privkey.c gnutls_pubkey.c pkcs11_write.c
+       pkcs11.c pkcs11_privkey.c gnutls_pubkey.c pkcs11_write.c locks.c
 
 
 if ENABLE_NETTLE
@@ -104,7 +104,7 @@ HFILES = debug.h gnutls_compress.h gnutls_cipher.h 
gnutls_buffers.h \
        gnutls_helper.h auth_psk.h auth_psk_passwd.h                    \
        gnutls_supplemental.h crypto.h random.h         \
        ext_session_ticket.h ext_signature.h gnutls_cryptodev.h         \
-       ext_safe_renegotiation.h
+       ext_safe_renegotiation.h locks.h
 
 if ENABLE_LOCAL_PAKCHOIS
 COBJECTS+=pakchois/pakchois.c pakchois/errors.c
diff --git a/lib/gcrypt/Makefile.am b/lib/gcrypt/Makefile.am
index c7efbe5..0b3d574 100644
--- a/lib/gcrypt/Makefile.am
+++ b/lib/gcrypt/Makefile.am
@@ -31,4 +31,4 @@ AM_CPPFLAGS = \
 
 noinst_LTLIBRARIES = libcrypto.la
 
-libcrypto_la_SOURCES = pk.c mpi.c mac.c cipher.c rnd.c
+libcrypto_la_SOURCES = pk.c mpi.c mac.c cipher.c rnd.c init.c
diff --git a/lib/gcrypt/init.c b/lib/gcrypt/init.c
new file mode 100644
index 0000000..a511ac5
--- /dev/null
+++ b/lib/gcrypt/init.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * Author: Nikos Mavrogiannopoulos
+ *
+ * This file is part of GnuTLS.
+ *
+ * The GnuTLS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA
+ *
+ */
+
+#include <gnutls_int.h>
+#include <gnutls_errors.h>
+#include <gcrypt.h>
+#include <locks.h>
+
+#define GNUTLS_MIN_LIBGCRYPT_VERSION "1.2.4"
+
+/* Functions that refer to the initialization of the libgcrypt library.
+ */
+
+static struct gcry_thread_cbs gct = {
+  .option = (GCRY_THREAD_OPTION_PTHREAD | (GCRY_THREAD_OPTION_VERSION << 8)),
+  .init = NULL,
+  .select = NULL,
+  .waitpid = NULL,
+  .accept = NULL,
+  .connect = NULL,
+  .sendmsg = NULL,
+  .recvmsg = NULL,
+};
+
+static int wrap_gcry_mutex_lock(void** m)
+{
+  return gnutls_mutex_lock(*m);
+}
+
+static int wrap_gcry_mutex_unlock(void** m)
+{
+  return gnutls_mutex_unlock(*m);
+}
+
+static int wrap_gcry_mutex_deinit(void** m)
+{
+  gnutls_mutex_deinit(*m);
+  return 0;
+}
+
+void _gnutls_gcry_register_mutexes(void)
+{
+
+}
+
+int gnutls_crypto_init(void)
+{
+  /* Initialize libgcrypt if it hasn't already been initialized. */
+  if (gcry_control (GCRYCTL_ANY_INITIALIZATION_P) == 0)
+    {
+      const char *p;
+
+      if (gnutls_mutex_init != NULL) 
+        {
+         gct.mutex_init = gnutls_mutex_init;
+         gct.mutex_destroy = wrap_gcry_mutex_deinit;
+         gct.mutex_lock = wrap_gcry_mutex_lock;
+         gct.mutex_unlock = wrap_gcry_mutex_unlock;
+
+         gcry_control (GCRYCTL_SET_THREAD_CBS, &gct);
+        }
+
+      p = gcry_check_version (GNUTLS_MIN_LIBGCRYPT_VERSION);
+
+      if (p == NULL)
+       {
+         gnutls_assert ();
+         _gnutls_debug_log ("Checking for libgcrypt failed: %s < %s\n",
+                            gcry_check_version (NULL),
+                            GNUTLS_MIN_LIBGCRYPT_VERSION);
+         return GNUTLS_E_INCOMPATIBLE_GCRYPT_LIBRARY;
+       }
+
+      /* for gcrypt in order to be able to allocate memory */
+      gcry_control (GCRYCTL_DISABLE_SECMEM, NULL, 0);
+
+      gcry_control (GCRYCTL_INITIALIZATION_FINISHED, NULL, 0);
+      
+      gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
+    }
+
+   return 0;
+}
+
diff --git a/lib/gnutls_errors.c b/lib/gnutls_errors.c
index 9c71cd1..22ff77e 100644
--- a/lib/gnutls_errors.c
+++ b/lib/gnutls_errors.c
@@ -211,6 +211,8 @@ static const gnutls_error_entry error_algorithms[] = {
               GNUTLS_E_OPENPGP_UID_REVOKED, 1),
   ERROR_ENTRY (N_("Error loading the keyring."),
               GNUTLS_E_OPENPGP_KEYRING_ERROR, 1),
+  ERROR_ENTRY (N_("The initialization of crypto backend has failed."),
+              GNUTLS_E_CRYPTO_INIT_FAILED, 1),
   ERROR_ENTRY (N_("The initialization of LZO has failed."),
               GNUTLS_E_LZO_INIT_FAILED, 1),
   ERROR_ENTRY (N_("No supported compression algorithms have been found."),
diff --git a/lib/gnutls_global.c b/lib/gnutls_global.c
index bdbdc64..223abdc 100644
--- a/lib/gnutls_global.c
+++ b/lib/gnutls_global.c
@@ -28,15 +28,11 @@
 #include <libtasn1.h>
 #include <gnutls_dh.h>
 #include <random.h>
-#ifndef HAVE_LIBNETTLE
-#include <gcrypt.h>
-#define GNUTLS_MIN_LIBGCRYPT_VERSION "1.2.4"
-
-#endif
 #include <gnutls/pkcs11.h>
 
 #include <gnutls_extensions.h> /* for _gnutls_ext_init */
 #include <gnutls_cryptodev.h>
+#include <locks.h>
 
 #include "sockets.h"
 #include "gettext.h"
@@ -54,139 +50,6 @@ ASN1_TYPE _gnutls_gnutls_asn;
 gnutls_log_func _gnutls_log_func;
 int _gnutls_log_level = 0;     /* default log level */
 
-#ifdef _WIN32
-
-# include <windows.h>
-
-/* FIXME: win32 locks are untested */
-static int gnutls_system_mutex_init (void **priv)
-{
-  CRITICAL_SECTION *lock = malloc (sizeof (CRITICAL_SECTION));
-  int ret;
-
-  if (lock==NULL)
-    return GNUTLS_E_MEMORY_ERROR;
-
-  InitializeCriticalSection(lock);
-     
-  *priv = lock;
-  
-  return 0;
-}
-
-static void gnutls_system_mutex_deinit (void *priv)
-{
-  DeleteCriticalSection(priv);
-  free(priv);
-}
-
-static int gnutls_system_mutex_lock (void *priv)
-{
-  EnterCriticalSection(priv);
-  return 0;
-}
-
-static int gnutls_system_mutex_unlock (void *priv)
-{
-  LeaveCriticalSection(priv);
-  return 0;
-}
-
-#else
-
-# ifdef HAVE_LIBPTHREAD
-#  include <pthread.h>
-
-static int gnutls_system_mutex_init (void **priv)
-{
-  pthread_mutex_t *lock = malloc (sizeof (pthread_mutex_t));
-  int ret;
-
-  if (lock==NULL)
-    return GNUTLS_E_MEMORY_ERROR;
-
-   ret = pthread_mutex_init (lock, NULL);
-   if (ret)
-     {
-       free(lock);
-       gnutls_assert();
-       return GNUTLS_E_LOCKING_ERROR;
-     }
-     
-  *priv = lock;
-  
-  return 0;
-}
-
-static void gnutls_system_mutex_deinit (void *priv)
-{
-  pthread_mutex_destroy(priv);
-  free(priv);
-}
-
-static int gnutls_system_mutex_lock (void *priv)
-{
-  if (pthread_mutex_lock(priv))
-    {
-        gnutls_assert();
-        return GNUTLS_E_LOCKING_ERROR;
-    }
-
-  return 0;
-}
-
-static int gnutls_system_mutex_unlock (void *priv)
-{
-  if (pthread_mutex_unlock(priv))
-    {
-        gnutls_assert();
-        return GNUTLS_E_LOCKING_ERROR;
-    }
-
-  return 0;
-}
-
-# else
-
-#define gnutls_system_mutex_init NULL
-#define gnutls_system_mutex_deinit NULL
-#define gnutls_system_mutex_lock NULL
-#define gnutls_mutex_unlock NULL
-
-# endif /* PTHREAD */
-
-#endif
-
-mutex_init_func gnutls_mutex_init = gnutls_system_mutex_init;
-mutex_deinit_func gnutls_mutex_deinit = gnutls_system_mutex_deinit;
-mutex_lock_func gnutls_mutex_lock = gnutls_system_mutex_lock;
-mutex_unlock_func gnutls_mutex_unlock = gnutls_system_mutex_unlock;
-
-/**
- * gnutls_global_set_mutex:
- * @init: mutex initialization function
- * @deinit: mutex deinitialization function
- * @lock: mutex locking function
- * @unlock: mutex unlocking function
- *
- * With this function you are allowed to override the default mutex
- * locks used in some parts of gnutls and dependent libraries. This function
- * should be used if you have complete control of your program and libraries.
- * Do not call this function from a library. Instead only initialize gnutls and
- * the default OS mutex locks will be used.
- * 
- * This function must be called before gnutls_global_init().
- *
- **/
-void gnutls_global_set_mutex(mutex_init_func init, mutex_deinit_func deinit, 
-        mutex_lock_func lock, mutex_unlock_func unlock)
-{
-  gnutls_mutex_init = init;
-  gnutls_mutex_deinit = deinit;
-  gnutls_mutex_lock = lock;
-  gnutls_mutex_unlock = unlock;
-}
-
 /**
  * gnutls_global_set_log_function:
  * @log_func: it's a log function
@@ -235,7 +98,6 @@ gnutls_global_set_log_level (int level)
  * (malloc(), free()), are used by gnutls, to allocate both sensitive
  * and not sensitive data.  This function is provided to set the
  * memory allocation functions to something other than the defaults
- * (ie the gcrypt allocation functions).
  *
  * This function must be called before gnutls_global_init() is called.
  * This function is not thread safe.
@@ -274,35 +136,6 @@ gnutls_global_set_mem_functions (gnutls_alloc_function 
alloc_func,
 
 static int _gnutls_init = 0;
 
-#ifndef HAVE_LIBNETTLE
-static struct gcry_thread_cbs gct = {
-  .option = (GCRY_THREAD_OPTION_PTH | (GCRY_THREAD_OPTION_VERSION << 8)),
-  .init = NULL,
-  .select = NULL,
-  .waitpid = NULL,
-  .accept = NULL,
-  .connect = NULL,
-  .sendmsg = NULL,
-  .recvmsg = NULL,
-};
-
-static int wrap_gcry_mutex_lock(void** m)
-{
-  return gnutls_mutex_lock(*m);
-}
-
-static int wrap_gcry_mutex_unlock(void** m)
-{
-  return gnutls_mutex_unlock(*m);
-}
-
-static int wrap_gcry_mutex_deinit(void** m)
-{
-  gnutls_mutex_deinit(*m);
-  return 0;
-}
-
-#endif
 
 /**
  * gnutls_global_init:
@@ -312,11 +145,8 @@ static int wrap_gcry_mutex_deinit(void** m)
  * shared by gnutls session structures.  You should call
  * gnutls_global_deinit() when gnutls usage is no longer needed
  *
- * Note that this function will also initialize libgcrypt, if it has
- * not been initialized before.  Thus if you want to manually
- * initialize libgcrypt you must do it before calling this function.
- * This is useful in cases you want to disable libgcrypt's internal
- * lockings etc.
+ * Note that this function will also initialize the underlying crypto
+ * backend, if it has not been initialized before.  
  *
  * This function increment a global counter, so that
  * gnutls_global_deinit() only releases resources when it has been
@@ -350,41 +180,13 @@ gnutls_global_init (void)
 
   bindtextdomain (PACKAGE, LOCALEDIR);
 
-#ifndef HAVE_LIBNETTLE
-  /* Initialize libgcrypt if it hasn't already been initialized. */
-  if (gcry_control (GCRYCTL_ANY_INITIALIZATION_P) == 0)
+  res = gnutls_crypto_init();
+  if (res != 0) 
     {
-      const char *p;
-
-      if (gnutls_mutex_init != NULL)
-        {
-          gct.mutex_init = gnutls_mutex_init;
-          gct.mutex_destroy = wrap_gcry_mutex_deinit;
-          gct.mutex_lock = wrap_gcry_mutex_lock;
-          gct.mutex_unlock = wrap_gcry_mutex_unlock;
-
-          gcry_control (GCRYCTL_SET_THREAD_CBS, &gct);
-        }
-
-      p = gcry_check_version (GNUTLS_MIN_LIBGCRYPT_VERSION);
-
-      if (p == NULL)
-       {
-         gnutls_assert ();
-         _gnutls_debug_log ("Checking for libgcrypt failed: %s < %s\n",
-                            gcry_check_version (NULL),
-                            GNUTLS_MIN_LIBGCRYPT_VERSION);
-         return GNUTLS_E_INCOMPATIBLE_GCRYPT_LIBRARY;
-       }
-
-      /* for gcrypt in order to be able to allocate memory */
-      gcry_control (GCRYCTL_DISABLE_SECMEM, NULL, 0);
-
-      gcry_control (GCRYCTL_INITIALIZATION_FINISHED, NULL, 0);
-      
-      gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
+      gnutls_assert();
+      return GNUTLS_E_CRYPTO_INIT_FAILED;
     }
-#endif
+
   /* initialize ASN.1 parser
    * This should not deal with files in the final
    * version.
diff --git a/lib/gnutls_global.h b/lib/gnutls_global.h
index e6bf08e..5e6265d 100644
--- a/lib/gnutls_global.h
+++ b/lib/gnutls_global.h
@@ -27,6 +27,7 @@
 # define GNUTLS_GLOBAL_H
 
 #include <libtasn1.h>
+#include <gnutls/gnutls.h>
 
 int gnutls_is_secure_memory (const void *mem);
 
@@ -42,10 +43,6 @@ extern ASN1_TYPE _gnutls_gnutls_asn;
 
 extern gnutls_log_func _gnutls_log_func;
 extern int _gnutls_log_level;
-
-extern mutex_init_func gnutls_mutex_init;
-extern mutex_deinit_func gnutls_mutex_deinit;
-extern mutex_lock_func gnutls_mutex_lock;
-extern mutex_unlock_func gnutls_mutex_unlock;
+extern int gnutls_crypto_init(void);
 
 #endif
diff --git a/lib/includes/gnutls/gnutls.h.in b/lib/includes/gnutls/gnutls.h.in
index bfd876a..f115691 100644
--- a/lib/includes/gnutls/gnutls.h.in
+++ b/lib/includes/gnutls/gnutls.h.in
@@ -1760,6 +1760,8 @@ extern "C"
 #define GNUTLS_E_PKCS11_TOKEN_ERROR -316
 #define GNUTLS_E_PKCS11_USER_ERROR -317
 
+#define GNUTLS_E_CRYPTO_INIT_FAILED -318
+
 #define GNUTLS_E_UNIMPLEMENTED_FEATURE -1250
 
 
diff --git a/lib/locks.c b/lib/locks.c
new file mode 100644
index 0000000..c017fc1
--- /dev/null
+++ b/lib/locks.c
@@ -0,0 +1,181 @@
+/*
+ * Copyright (C) 2010
+ * Free Software Foundation, Inc.
+ *
+ * Author: Nikos Mavrogiannopoulos
+ *
+ * This file is part of GnuTLS.
+ *
+ * The GnuTLS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA
+ *
+ */
+
+#include <gnutls_int.h>
+#include <gnutls_errors.h>
+#include <libtasn1.h>
+#include <gnutls_dh.h>
+#include <random.h>
+
+#include <locks.h>
+
+#ifdef HAVE_WIN32_LOCKS
+
+# include <windows.h>
+
+/* FIXME: win32 locks are untested */
+static int gnutls_system_mutex_init (void **priv)
+{
+  CRITICAL_SECTION *lock = malloc (sizeof (CRITICAL_SECTION));
+  int ret;
+
+  if (lock==NULL)
+    return GNUTLS_E_MEMORY_ERROR;
+
+  InitializeCriticalSection(lock);
+     
+  *priv = lock;
+  
+  return 0;
+}
+
+static void gnutls_system_mutex_deinit (void *priv)
+{
+  DeleteCriticalSection(priv);
+  free(priv);
+}
+
+static int gnutls_system_mutex_lock (void *priv)
+{
+  EnterCriticalSection(priv);
+  return 0;
+}
+
+static int gnutls_system_mutex_unlock (void *priv)
+{
+  LeaveCriticalSection(priv);
+  return 0;
+}
+
+#endif /* WIN32_LOCKS */
+
+#ifdef HAVE_PTHREAD_LOCKS
+# include <pthread.h>
+
+static int gnutls_system_mutex_init (void **priv)
+{
+  pthread_mutex_t *lock = malloc (sizeof (pthread_mutex_t));
+  int ret;
+
+  if (lock==NULL)
+    return GNUTLS_E_MEMORY_ERROR;
+
+   ret = pthread_mutex_init (lock, NULL);
+   if (ret)
+     {
+       free(lock);
+       gnutls_assert();
+       return GNUTLS_E_LOCKING_ERROR;
+     }
+     
+  *priv = lock;
+  
+  return 0;
+}
+
+static void gnutls_system_mutex_deinit (void *priv)
+{
+  pthread_mutex_destroy(priv);
+  free(priv);
+}
+
+static int gnutls_system_mutex_lock (void *priv)
+{
+  if (pthread_mutex_lock(priv))
+    {
+        gnutls_assert();
+        return GNUTLS_E_LOCKING_ERROR;
+    }
+
+  return 0;
+}
+
+static int gnutls_system_mutex_unlock (void *priv)
+{
+  if (pthread_mutex_unlock(priv))
+    {
+        gnutls_assert();
+        return GNUTLS_E_LOCKING_ERROR;
+    }
+
+  return 0;
+}
+
+#endif /* PTHREAD_LOCKS */
+
+#ifdef HAVE_NO_LOCKS
+
+static int gnutls_system_mutex_init (void **priv)
+{
+  return 0;
+}
+
+static void gnutls_system_mutex_deinit (void *priv)
+{
+  return;
+}
+
+static int gnutls_system_mutex_lock (void *priv)
+{
+  return 0;
+}
+
+static int gnutls_system_mutex_unlock (void *priv)
+{
+  return 0;
+}
+
+#endif /* NO_LOCKS */
+
+mutex_init_func gnutls_mutex_init = gnutls_system_mutex_init;
+mutex_deinit_func gnutls_mutex_deinit = gnutls_system_mutex_deinit;
+mutex_lock_func gnutls_mutex_lock = gnutls_system_mutex_lock;
+mutex_unlock_func gnutls_mutex_unlock = gnutls_system_mutex_unlock;
+
+/**
+ * gnutls_global_set_mutex:
+ * @init: mutex initialization function
+ * @deinit: mutex deinitialization function
+ * @lock: mutex locking function
+ * @unlock: mutex unlocking function
+ *
+ * With this function you are allowed to override the default mutex
+ * locks used in some parts of gnutls and dependent libraries. This function
+ * should be used if you have complete control of your program and libraries.
+ * Do not call this function from a library. Instead only initialize gnutls and
+ * the default OS mutex locks will be used.
+ * 
+ * This function must be called before gnutls_global_init().
+ *
+ **/
+void gnutls_global_set_mutex(mutex_init_func init, mutex_deinit_func deinit, 
+        mutex_lock_func lock, mutex_unlock_func unlock)
+{
+  gnutls_mutex_init = init;
+  gnutls_mutex_deinit = deinit;
+  gnutls_mutex_lock = lock;
+  gnutls_mutex_unlock = unlock;
+}
+
diff --git a/lib/locks.h b/lib/locks.h
new file mode 100644
index 0000000..f76b962
--- /dev/null
+++ b/lib/locks.h
@@ -0,0 +1,22 @@
+#ifndef GNUTLS_LOCKS_H
+# define GNUTLS_LOCKS_H
+
+#include <gnutls/gnutls.h>
+#include <gnutls_int.h>
+
+#ifdef _WIN32
+# define HAVE_WIN32_LOCKS
+#else
+# ifdef HAVE_LIBPTHREAD
+#  define HAVE_PTHREAD_LOCKS
+# else
+#  define HAVE_NO_LOCKS
+# endif
+#endif
+
+extern mutex_init_func gnutls_mutex_init;
+extern mutex_deinit_func gnutls_mutex_deinit;
+extern mutex_lock_func gnutls_mutex_lock;
+extern mutex_unlock_func gnutls_mutex_unlock;
+
+#endif
diff --git a/lib/nettle/Makefile.am b/lib/nettle/Makefile.am
index c7efbe5..0b3d574 100644
--- a/lib/nettle/Makefile.am
+++ b/lib/nettle/Makefile.am
@@ -31,4 +31,4 @@ AM_CPPFLAGS = \
 
 noinst_LTLIBRARIES = libcrypto.la
 
-libcrypto_la_SOURCES = pk.c mpi.c mac.c cipher.c rnd.c
+libcrypto_la_SOURCES = pk.c mpi.c mac.c cipher.c rnd.c init.c
diff --git a/lib/gnutls_helper.c b/lib/nettle/init.c
similarity index 76%
copy from lib/gnutls_helper.c
copy to lib/nettle/init.c
index dee2123..799d276 100644
--- a/lib/gnutls_helper.c
+++ b/lib/nettle/init.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2008, 2010 Free Software Foundation, Inc.
+ * Copyright (C) 2010 Free Software Foundation, Inc.
  *
  * Author: Nikos Mavrogiannopoulos
  *
@@ -23,17 +23,16 @@
  */
 
 #include <gnutls_int.h>
-#include <gnutls_helper.h>
+#include <gnutls_errors.h>
+#include <gnutls_num.h>
+#include <gnutls_mpi.h>
+#include <gcrypt.h>
 
-int
-_gnutls_file_exists (const char *file)
-{
-  FILE *fd;
-
-  fd = fopen (file, "r");
-  if (fd == NULL)
-    return -1;
+/* Functions that refer to the initialization of the libgcrypt library.
+ */
 
-  fclose (fd);
-  return 0;
+int gnutls_crypto_init(void)
+{
+   return 0;
 }
+
diff --git a/lib/nettle/rnd.c b/lib/nettle/rnd.c
index 2ae544f..169049d 100644
--- a/lib/nettle/rnd.c
+++ b/lib/nettle/rnd.c
@@ -35,15 +35,14 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <fcntl.h>
-
-#include <pthread.h>
+#include <locks.h>
 
 #define SOURCES 2
 
 static void* rnd_mutex;
 
-#define RND_LOCK if (gnutls_mutex_lock && gnutls_mutex_lock(&rnd_mutex)!=0) 
abort()
-#define RND_UNLOCK if (gnutls_mutex_unlock && 
gnutls_mutex_unlock(&rnd_mutex)!=0) abort()
+#define RND_LOCK if (gnutls_mutex_lock(&rnd_mutex)!=0) abort()
+#define RND_UNLOCK if (gnutls_mutex_unlock(&rnd_mutex)!=0) abort()
 
 enum {
        RANDOM_SOURCE_TRIVIA=0,


hooks/post-receive
-- 
GNU gnutls



reply via email to

[Prev in Thread] Current Thread [Next in Thread]