monotone

monotone Mtn Source Tree

Root/botan/engine.h

1/*************************************************
2* Engine Header File *
3* (C) 1999-2007 The Botan Project *
4*************************************************/
5
6#ifndef BOTAN_ENGINE_H__
7#define BOTAN_ENGINE_H__
8
9#include <botan/base.h>
10#include <botan/mutex.h>
11#include <botan/pk_ops.h>
12#include <botan/pow_mod.h>
13#include <botan/basefilt.h>
14#include <botan/enums.h>
15#include <utility>
16#include <map>
17
18namespace Botan {
19
20/*************************************************
21* Engine Base Class *
22*************************************************/
23class Engine
24 {
25 public:
26 template<typename T>
27 class Algorithm_Cache
28 {
29 public:
30 virtual T* get(const std::string&) const = 0;
31 virtual void add(T* algo, const std::string& = "") const = 0;
32 virtual ~Algorithm_Cache() {}
33 };
34
35 virtual IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&,
36 const BigInt&, const BigInt&, const BigInt&,
37 const BigInt&, const BigInt&) const;
38 virtual DSA_Operation* dsa_op(const DL_Group&, const BigInt&,
39 const BigInt&) const;
40 virtual NR_Operation* nr_op(const DL_Group&, const BigInt&,
41 const BigInt&) const;
42 virtual ELG_Operation* elg_op(const DL_Group&, const BigInt&,
43 const BigInt&) const;
44 virtual DH_Operation* dh_op(const DL_Group&, const BigInt&) const;
45
46 virtual Modular_Exponentiator* mod_exp(const BigInt&,
47 Power_Mod::Usage_Hints) const;
48
49 virtual Keyed_Filter* get_cipher(const std::string&, Cipher_Dir);
50
51 const BlockCipher* block_cipher(const std::string&) const;
52 const StreamCipher* stream_cipher(const std::string&) const;
53 const HashFunction* hash(const std::string&) const;
54 const MessageAuthenticationCode* mac(const std::string&) const;
55 const class S2K* s2k(const std::string&) const;
56 const class BlockCipherModePaddingMethod*
57 bc_pad(const std::string&) const;
58
59 void add_algorithm(BlockCipher*) const;
60 void add_algorithm(StreamCipher*) const;
61 void add_algorithm(HashFunction*) const;
62 void add_algorithm(MessageAuthenticationCode*) const;
63 void add_algorithm(class S2K*) const;
64 void add_algorithm(class BlockCipherModePaddingMethod*) const;
65
66 Engine();
67 virtual ~Engine();
68 private:
69 virtual BlockCipher* find_block_cipher(const std::string&) const;
70 virtual StreamCipher* find_stream_cipher(const std::string&) const;
71 virtual HashFunction* find_hash(const std::string&) const;
72 virtual MessageAuthenticationCode* find_mac(const std::string&) const;
73 virtual class S2K* find_s2k(const std::string&) const;
74 virtual class BlockCipherModePaddingMethod*
75 find_bc_pad(const std::string&) const;
76
77 template<typename T>
78 const T* lookup_algo(const Algorithm_Cache<T>* cache,
79 const std::string& name,
80 const Engine* engine,
81 T* (Engine::*find)(const std::string&) const) const
82 {
83 T* algo = cache->get(name);
84 if(!algo)
85 {
86 algo = (engine->*find)(name);
87 if(algo)
88 cache->add(algo, name);
89 }
90 return algo;
91 }
92
93 Algorithm_Cache<BlockCipher>* cache_of_bc;
94 Algorithm_Cache<StreamCipher>* cache_of_sc;
95 Algorithm_Cache<HashFunction>* cache_of_hf;
96 Algorithm_Cache<MessageAuthenticationCode>* cache_of_mac;
97 Algorithm_Cache<BlockCipherModePaddingMethod>* cache_of_bc_pad;
98 Algorithm_Cache<S2K>* cache_of_s2k;
99 };
100
101namespace Engine_Core {
102
103/*************************************************
104* Get an operation from an Engine *
105*************************************************/
106Modular_Exponentiator* mod_exp(const BigInt&, Power_Mod::Usage_Hints);
107
108IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&,
109 const BigInt&, const BigInt&, const BigInt&,
110 const BigInt&, const BigInt&);
111
112DSA_Operation* dsa_op(const DL_Group&, const BigInt&, const BigInt&);
113NR_Operation* nr_op(const DL_Group&, const BigInt&, const BigInt&);
114
115ELG_Operation* elg_op(const DL_Group&, const BigInt&, const BigInt&);
116
117DH_Operation* dh_op(const DL_Group&, const BigInt&);
118
119}
120
121}
122
123#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status