Debian Codegraph @

src/lib/crypto/CryptoFactory.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 CryptoFactory.h
29
30 This class is a factory for all cryptographic algorithm implementations. It
31 is an abstract base class for a factory that produces cryptographic library
32 specific implementations of cryptographic algorithms.
33 *****************************************************************************/
34
35 #ifndef _SOFTHSM_V2_CRYPTOFACTORY_H
36 #define _SOFTHSM_V2_CRYPTOFACTORY_H
37
38 #include "config.h"
39 #include "SymmetricAlgorithm.h"
40 #include "AsymmetricAlgorithm.h"
41 #include "HashAlgorithm.h"
42 #include "MacAlgorithm.h"
43 #include "RNG.h"
44
45 class CryptoFactory
46 {
47 public:
48 // Return the one-and-only instance
49 static CryptoFactory* i();
50
51 // This will destroy the one-and-only instance.
52 static void reset();
53
54 #ifdef WITH_FIPS
55 // Return the FIPS 140-2 selftest status
56 virtual bool getFipsSelfTestStatus() const = 0;
57 #endif
58
59 // Create a concrete instance of a symmetric algorithm
60 virtual SymmetricAlgorithm* getSymmetricAlgorithm(SymAlgo::Type algorithm) = 0;
61
62 // Recycle a symmetric algorithm instance -- override this function in the derived
63 // class if you need to perform specific clean-up
64 virtual void recycleSymmetricAlgorithm(SymmetricAlgorithm* toRecycle);
65
66 // Create a concrete instance of an asymmetric algorithm
67 virtual AsymmetricAlgorithm* getAsymmetricAlgorithm(AsymAlgo::Type algorithm) = 0;
68
69 // Recycle an asymmetric algorithm instance -- override this function in the derived
70 // class if you need to perform specific clean-up
71 virtual void recycleAsymmetricAlgorithm(AsymmetricAlgorithm* toRecycle);
72
73 // Create a concrete instance of a hash algorithm
74 virtual HashAlgorithm* getHashAlgorithm(HashAlgo::Type algorithm) = 0;
75
76 // Recycle a hash algorithm instance -- override this function in the derived
77 // class if you need to perform specific clean-up
78 virtual void recycleHashAlgorithm(HashAlgorithm* toRecycle);
79
80 // Create a concrete instance of a MAC algorithm
81 virtual MacAlgorithm* getMacAlgorithm(MacAlgo::Type algorithm) = 0;
82
83 // Recycle a MAC algorithm instance -- override this function in the derived
84 // class if you need to perform specific clean-up
85 virtual void recycleMacAlgorithm(MacAlgorithm* toRecycle);
86
87 // Get the global RNG (may be an unique RNG per thread)
88 virtual RNG* getRNG(RNGImpl::Type name = RNGImpl::Default) = 0;
89
90 // Destructor
91 virtual ~CryptoFactory() { }
92
93 private:
94 };
95
96 #endif // !_SOFTHSM_V2_CRYPTOFACTORY_H
97