1 /*****************************************************************************\
3 * Name : SSL initialization helper *
4 * Author : Chris Koeritz *
6 *******************************************************************************
7 * Copyright (c) 2005-$now By Author. This program is free software; you can *
8 * redistribute it and/or modify it under the terms of the GNU General Public *
9 * License as published by the Free Software Foundation; either version 2 of *
10 * the License or (at your option) any later version. This is online at: *
11 * http://www.fsf.org/copyleft/gpl.html *
12 * Please send any updates to: fred@gruntose.com *
13 \*****************************************************************************/
17 #include <basis/functions.h>
18 #include <basis/mutex.h>
19 #include <structures/static_memory_gremlin.h>
21 #include <openssl/crypto.h>
22 #include <openssl/err.h>
23 #include <openssl/rand.h>
25 using namespace basis;
26 using namespace mathematics;
27 using namespace structures;
31 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
33 const int SEED_SIZE = 100;
34 // the size of the random seed that we'll use.
36 // our global initialization object.
37 SAFE_STATIC_CONST(ssl_init, static_ssl_initializer, )
40 // uncomment to cause more debugging information to be generated, plus
41 // more checking to be performed in the SSL support.
47 CRYPTO_malloc_debug_init();
48 CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
49 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
51 RAND_seed(random_bytes(SEED_SIZE).observe(), SEED_SIZE);
56 CRYPTO_cleanup_all_ex_data();
58 CRYPTO_mem_leaks_fp(stderr);
61 const chaos &ssl_init::randomizer() const { return c_rando; }
63 byte_array ssl_init::random_bytes(int length) const
66 for (int i = 0; i < length; i++)
67 seed += abyte(c_rando.inclusive(0, 255));