aboutsummaryrefslogtreecommitdiffstats
path: root/src/algo_factory/algo_factory.h
blob: 73e592013e5e00bc1d7af51f9f235a765e956560 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* Algorithm Factory
* (C) 2008 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/

#ifndef BOTAN_ALGORITHM_FACTORY_H__
#define BOTAN_ALGORITHM_FACTORY_H__

#include <botan/mutex.h>
#include <string>
#include <vector>

namespace Botan {

/**
* Forward declarations (don't need full definitions here)
*/
class BlockCipher;
class StreamCipher;
class HashFunction;
class MessageAuthenticationCode;

template<typename T> class Algorithm_Cache;

class Engine;

/**
* Algorithm Factory
*/
class BOTAN_DLL Algorithm_Factory
   {
   public:
      /**
      * Constructor
      * @param engines_in the list of engines to use
      * @param mf a mutex factory
      */
      Algorithm_Factory(const std::vector<Engine*>& engines_in,
                        Mutex_Factory& mf);

      /**
      * Destructor
      */
      ~Algorithm_Factory();

      /*
      * Provider management
      */
      std::vector<std::string> providers_of(const std::string& algo_spec);

      void set_preferred_provider(const std::string& algo_spec,
                                  const std::string& provider);

      /*
      * Block cipher operations
      */
      const BlockCipher*
         prototype_block_cipher(const std::string& algo_spec,
                                const std::string& provider = "");

      BlockCipher* make_block_cipher(const std::string& algo_spec,
                                     const std::string& provider = "");

      void add_block_cipher(BlockCipher* hash, const std::string& provider);

      /*
      * Stream cipher operations
      */
      const StreamCipher*
         prototype_stream_cipher(const std::string& algo_spec,
                                 const std::string& provider = "");

      StreamCipher* make_stream_cipher(const std::string& algo_spec,
                                       const std::string& provider = "");

      void add_stream_cipher(StreamCipher* hash, const std::string& provider);

      /*
      * Hash function operations
      */
      const HashFunction*
         prototype_hash_function(const std::string& algo_spec,
                                 const std::string& provider = "");

      HashFunction* make_hash_function(const std::string& algo_spec,
                                       const std::string& provider = "");

      void add_hash_function(HashFunction* hash, const std::string& provider);

      /*
      * MAC operations
      */
      const MessageAuthenticationCode*
         prototype_mac(const std::string& algo_spec,
                       const std::string& provider = "");

      MessageAuthenticationCode* make_mac(const std::string& algo_spec,
                                          const std::string& provider = "");

      void add_mac(MessageAuthenticationCode* mac,
                   const std::string& provider);

      /*
      * Deprecated
      */
      class BOTAN_DLL Engine_Iterator
         {
         public:
            class Engine* next() { return af.get_engine_n(n++); }
            Engine_Iterator(const Algorithm_Factory& a) : af(a) { n = 0; }
         private:
            const Algorithm_Factory& af;
            u32bit n;
         };
      friend class Engine_Iterator;

   private:
      class Engine* get_engine_n(u32bit) const;

      std::vector<class Engine*> engines;

      Algorithm_Cache<BlockCipher>* block_cipher_cache;
      Algorithm_Cache<StreamCipher>* stream_cipher_cache;
      Algorithm_Cache<HashFunction>* hash_cache;
      Algorithm_Cache<MessageAuthenticationCode>* mac_cache;
   };

}

#endif