void
egg_libgcrypt_initialize (void)
{
	static volatile gsize gcrypt_initialized = 0;
	unsigned seed;

	if (g_once_init_enter (&gcrypt_initialized)) {
		
		/* Only initialize libgcrypt if it hasn't already been initialized */
		if (!gcry_control (GCRYCTL_INITIALIZATION_FINISHED_P)) {
#if GCRYPT_VERSION_NUMBER < 0x010600
			gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
#endif
			gcry_check_version (LIBGCRYPT_VERSION);
			gcry_set_log_handler (log_handler, NULL);
			gcry_set_outofcore_handler (no_mem_handler, NULL);
			gcry_set_fatalerror_handler (fatal_handler, NULL);
			gcry_set_allocation_handler ((gcry_handler_alloc_t)g_malloc, 
			                             (gcry_handler_alloc_t)egg_secure_alloc, 
			                             egg_secure_check, 
			                             (gcry_handler_realloc_t)egg_secure_realloc, 
			                             egg_secure_free);
			gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
		}
		
		gcry_create_nonce (&seed, sizeof (seed));
		srand (seed);

		g_once_init_leave (&gcrypt_initialized, 1);
	}
}
Exemple #2
0
/** Tagcrypt initialization.
 *
 * This function can be called many times without harm.
 */
void tagcrypt_init() {
    gcry_set_outofcore_handler(tagcrypt_gcry_outofcore_handler, NULL);

    gcry_check_version (NULL);
    gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
    gcry_control (GCRYCTL_INIT_SECMEM, 4096);
    gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM); 
}