aboutsummaryrefslogtreecommitdiffstats
path: root/src/algo_factory/algo_factory.h
blob: 2bbfde7d10dc7864878a0acf9977fdb2db508075 (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
/**
* Algorithm Factory
* (C) 2008 Jack Lloyd
*/

#ifndef BOTAN_ALGORITHM_FACTORY_H__
#define BOTAN_ALGORITHM_FACTORY_H__

#include <botan/algo_cache.h>
#include <botan/scan_name.h>
#include <botan/mutex.h>
#include <string>
#include <vector>
#include <map>

namespace Botan {

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

/**
* Algorithm Factory
*/
class BOTAN_DLL Algorithm_Factory
   {
   public:
      Algorithm_Factory(Mutex_Factory& mf);
      ~Algorithm_Factory();

      void add_engine(class Engine*);

      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;

      std::vector<std::string> providers_of(const SCAN_Name& request);

      // Block cipher operations
      const BlockCipher* prototype_block_cipher(const SCAN_Name& request);
      BlockCipher* make_block_cipher(const SCAN_Name& request);
      void add_block_cipher(BlockCipher* hash);

      // Stream cipher operations
      const StreamCipher* prototype_stream_cipher(const SCAN_Name& request);
      StreamCipher* make_stream_cipher(const SCAN_Name& request);
      void add_stream_cipher(StreamCipher* hash);

      // Hash function operations
      const HashFunction* prototype_hash_function(const SCAN_Name& request);
      HashFunction* make_hash_function(const SCAN_Name& request);
      void add_hash_function(HashFunction* hash);

      // MAC operations
      const MessageAuthenticationCode* prototype_mac(const SCAN_Name& request);
      MessageAuthenticationCode* make_mac(const SCAN_Name& request);
      void add_mac(MessageAuthenticationCode* mac);

   private:
      Mutex_Factory& mutex_factory;

      class Engine* get_engine_n(u32bit) const;

      std::vector<class Engine*> engines;
      Algorithm_Cache<HashFunction> hash_cache;
   };

}

#endif