4a88baf9b199530495338209afbbb8d413c1aaf5
[feisty_meow.git] / nucleus / library / crypto / ssl_init.h
1 #ifndef SSL_INIT_CLASS
2 #define SSL_INIT_CLASS
3
4 /*****************************************************************************\
5 *                                                                             *
6 *  Name   : SSL initialization helper                                         *
7 *  Author : Chris Koeritz                                                     *
8 *                                                                             *
9 *******************************************************************************
10 * Copyright (c) 2005-$now By Author.  This program is free software; you can  *
11 * redistribute it and/or modify it under the terms of the GNU General Public  *
12 * License as published by the Free Software Foundation; either version 2 of   *
13 * the License or (at your option) any later version.  This is online at:      *
14 *     http://www.fsf.org/copyleft/gpl.html                                    *
15 * Please send any updates to: fred@gruntose.com                               *
16 \*****************************************************************************/
17
18 #include <basis/byte_array.h>
19 #include <mathematics/chaos.h>
20
21 #include <openssl/opensslv.h>
22
23 namespace crypto {
24
25 //! provides some initialization for the RSA and blowfish crypto.
26 /*!
27   This class does the SSL initialization needed before any functions can
28   be used.  It also sets up the random seed for SSL.  NOTE: you should never
29   need to use this class directly; just use the accessor function at the
30   very bottom and it will be managed globally for the entire program.
31 */
32
33 // we define NEWER_OPENSSL for those places where we're using more recent versions.
34 #if OPENSSL_VERSION_NUMBER > 0x10100000L
35   #define NEWER_OPENSSL
36 //hmmm: to be cleaned up; should assume only new ssl from now on.
37 #else
38 //  #define OLDER_OPENSSL
39 #error not here
40 #endif
41
42 class ssl_init : public virtual basis::nameable
43 {
44 public:
45   ssl_init();
46   ~ssl_init();
47
48   DEFINE_CLASS_NAME("ssl_init");
49
50   basis::byte_array random_bytes(int length) const;
51     //!< can be used to generate a random array of "length" bytes.
52
53   const mathematics::chaos &randomizer() const;
54     //!< provides a random number generator for any encryption routines.
55
56 private:
57   mathematics::chaos c_rando;  //!< used for generating random numbers.
58 };
59
60 extern const ssl_init &static_ssl_initializer();
61   //!< the main method for accessing the SSL initialization support.
62
63 } //namespace.
64
65 #endif
66