Debian Codegraph @

src/lib/crypto/OSSLCryptoFactory.h

raw
1 /*
2 * Copyright (c) 2010 SURFnet bv
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 /*****************************************************************************
28 OSSLCryptoFactory.h
29
30 This is an OpenSSL based cryptographic algorithm factory
31 *****************************************************************************/
32
33 #ifndef _SOFTHSM_V2_OSSLCRYPTOFACTORY_H
34 #define _SOFTHSM_V2_OSSLCRYPTOFACTORY_H
35
36 #include "config.h"
37 #include "CryptoFactory.h"
38 #include "SymmetricAlgorithm.h"
39 #include "AsymmetricAlgorithm.h"
40 #include "HashAlgorithm.h"
41 #include "MacAlgorithm.h"
42 #include "RNG.h"
43 #include <memory>
44 #include <openssl/conf.h>
45 #include <openssl/engine.h>
46
47 class OSSLCryptoFactory : public CryptoFactory
48 {
49 public:
50 // Return the one-and-only instance
51 static OSSLCryptoFactory* i();
52
53 // This will destroy the one-and-only instance.
54 static void reset();
55
56 #ifdef WITH_FIPS
57 // Return the FIPS 140-2 selftest status
58 virtual bool getFipsSelfTestStatus() const;
59 #endif
60
61 // Create a concrete instance of a symmetric algorithm
62 virtual SymmetricAlgorithm* getSymmetricAlgorithm(SymAlgo::Type algorithm);
63
64 // Create a concrete instance of an asymmetric algorithm
65 virtual AsymmetricAlgorithm* getAsymmetricAlgorithm(AsymAlgo::Type algorithm);
66
67 // Create a concrete instance of a hash algorithm
68 virtual HashAlgorithm* getHashAlgorithm(HashAlgo::Type algorithm);
69
70 // Create a concrete instance of a MAC algorithm
71 virtual MacAlgorithm* getMacAlgorithm(MacAlgo::Type algorithm);
72
73 // Get the global RNG (may be an unique RNG per thread)
74 virtual RNG* getRNG(RNGImpl::Type name = RNGImpl::Default);
75
76 // Destructor
77 virtual ~OSSLCryptoFactory();
78
79 #ifdef WITH_GOST
80 // The EVP_MD for GOST R 34.11-94
81 const EVP_MD *EVP_GOST_34_11;
82 #endif
83
84 private:
85 // Constructor
86 OSSLCryptoFactory();
87
88 // The one-and-only instance
89 #ifdef HAVE_CXX11
90 static std::unique_ptr<OSSLCryptoFactory> instance;
91 #else
92 static std::auto_ptr<OSSLCryptoFactory> instance;
93 #endif
94
95 #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
96 bool setLockingCallback;
97 #endif
98
99 #ifdef WITH_FIPS
100 // The FIPS 140-2 selftest status
101 static bool FipsSelfTestStatus;
102 #endif
103
104 // The one-and-only RNG instance
105 RNG* rng;
106 // And RDRAND engine to use with it
107 ENGINE *rdrand_engine;
108
109 #ifdef WITH_GOST
110 // The GOST engine
111 ENGINE *eg;
112 #endif
113 };
114
115 #endif // !_SOFTHSM_V2_OSSLCRYPTOFACTORY_H
116