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
--- /dev/null
+/*
+ * 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;
+}
+
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."),
#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 */
* (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.
* 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.
+ * 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
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;
-
- _gnutls_gcry_register_mutexes();
-
- 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.
# define GNUTLS_GLOBAL_H
#include <libtasn1.h>
+#include <gnutls/gnutls.h>
int gnutls_is_secure_memory (const void *mem);
extern gnutls_log_func _gnutls_log_func;
extern int _gnutls_log_level;
+extern int gnutls_crypto_init(void);
#endif
#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
gnutls_mutex_unlock = unlock;
}
-#ifndef HAVE_LIBNETTLE
-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)
-{
- 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);
- }
-}
-
-#endif
extern mutex_lock_func gnutls_mutex_lock;
extern mutex_unlock_func gnutls_mutex_unlock;
-# ifndef HAVE_LIBNETTLE
-void _gnutls_gcry_register_mutexes(void);
-# endif
-
#endif
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
--- /dev/null
+/*
+ * 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 <gnutls_num.h>
+#include <gnutls_mpi.h>
+#include <gcrypt.h>
+
+/* Functions that refer to the initialization of the libgcrypt library.
+ */
+
+int gnutls_crypto_init(void)
+{
+ return 0;
+}
+
#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
-
-#include <pthread.h>
+#include <locks.h>
#define SOURCES 2