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 <loggers/program_wide_logger.h>
20 #include <structures/static_memory_gremlin.h>
22 #include <openssl/crypto.h>
23 #include <openssl/err.h>
24 #include <openssl/rand.h>
26 using namespace basis;
27 using namespace loggers;
28 using namespace mathematics;
29 using namespace structures;
34 // uncomment to cause more debugging information to be generated, plus
35 // more checking to be performed in the SSL support.
39 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
45 const int SEED_SIZE = 100;
46 // the size of the random seed that we'll use.
48 // our global initialization object.
49 SAFE_STATIC_CONST(ssl_init, static_ssl_initializer, )
56 LOG("prior to crypto debug init");
57 CRYPTO_malloc_debug_init();
58 LOG("prior to dbg set options");
59 CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
60 LOG("prior to mem ctrl");
61 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
63 LOG("prior to rand seed");
64 RAND_seed(random_bytes(SEED_SIZE).observe(), SEED_SIZE);
65 LOG("after rand seed");
70 FUNCDEF("destructor");
71 LOG("prior to crypto cleanup");
72 CRYPTO_cleanup_all_ex_data();
75 // LOG("prior to err remove state");
76 // ERR_remove_thread_state(NULL);
79 //THIS HAD TO be removed in most recent openssl; does it exist?
80 // LOG("prior to mem leaks fp");
81 // CRYPTO_mem_leaks_fp(stderr);
82 // LOG("after mem leaks fp");
85 const chaos &ssl_init::randomizer() const { return c_rando; }
87 byte_array ssl_init::random_bytes(int length) const
90 for (int i = 0; i < length; i++)
91 seed += abyte(c_rando.inclusive(0, 255));