a0d78bc2d5298863b02a42276c6d635ae6519092
[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 namespace crypto {
22
23 //! provides some initialization for the RSA and blowfish crypto.
24 /*!
25   This class does the SSL initialization needed before any functions can
26   be used.  It also sets up the random seed for SSL.  NOTE: you should never
27   need to use this class directly; just use the accessor function at the
28   very bottom and it will be managed globally for the entire program.
29 */
30
31 // we define NEWER_OPENSSL for those places where we're using more recent versions.
32 #if OPENSSL_VERSION_NUMBER > 0x10100000L
33   #define NEWER_OPENSSL
34 //hmmm: to be cleaned up; should assume only new ssl from now on.
35 #else
36 //  #define OLDER_OPENSSL
37 #endif
38
39 class ssl_init : public virtual basis::nameable
40 {
41 public:
42   ssl_init();
43   ~ssl_init();
44
45   DEFINE_CLASS_NAME("ssl_init");
46
47   basis::byte_array random_bytes(int length) const;
48     //!< can be used to generate a random array of "length" bytes.
49
50   const mathematics::chaos &randomizer() const;
51     //!< provides a random number generator for any encryption routines.
52
53 private:
54   mathematics::chaos c_rando;  //!< used for generating random numbers.
55 };
56
57 extern const ssl_init &static_ssl_initializer();
58   //!< the main method for accessing the SSL initialization support.
59
60 } //namespace.
61
62 #endif
63