1 /* 2 * Engine 3 * (C) 1999-2007 Jack Lloyd 4 * 5 * Distributed under the terms of the Botan license 6 */ 7 8 #ifndef BOTAN_ENGINE_H__ 9 #define BOTAN_ENGINE_H__ 10 11 #include <botan/scan_name.h> 12 #include <botan/block_cipher.h> 13 #include <botan/stream_cipher.h> 14 #include <botan/hash.h> 15 #include <botan/mac.h> 16 #include <botan/pbkdf.h> 17 #include <botan/pow_mod.h> 18 #include <botan/pk_keys.h> 19 #include <botan/pk_ops.h> 20 21 namespace Botan { 22 23 class Algorithm_Factory; 24 class Keyed_Filter; 25 26 /** 27 * Base class for all engines. All non-pure virtual functions simply 28 * return NULL, indicating the algorithm in question is not 29 * supported. Subclasses can reimplement whichever function(s) 30 * they want to hook in a particular type. 31 */ 32 class BOTAN_DLL Engine 33 { 34 public: ~Engine()35 virtual ~Engine() {} 36 37 /** 38 * @return name of this engine 39 */ 40 virtual std::string provider_name() const = 0; 41 42 /** 43 * @param algo_spec the algorithm name/specification 44 * @param af an algorithm factory object 45 * @return newly allocated object, or NULL 46 */ 47 virtual BlockCipher* 48 find_block_cipher(const SCAN_Name& algo_spec, 49 Algorithm_Factory& af) const; 50 51 /** 52 * @param algo_spec the algorithm name/specification 53 * @param af an algorithm factory object 54 * @return newly allocated object, or NULL 55 */ 56 virtual StreamCipher* 57 find_stream_cipher(const SCAN_Name& algo_spec, 58 Algorithm_Factory& af) const; 59 60 /** 61 * @param algo_spec the algorithm name/specification 62 * @param af an algorithm factory object 63 * @return newly allocated object, or NULL 64 */ 65 virtual HashFunction* 66 find_hash(const SCAN_Name& algo_spec, 67 Algorithm_Factory& af) const; 68 69 /** 70 * @param algo_spec the algorithm name/specification 71 * @param af an algorithm factory object 72 * @return newly allocated object, or NULL 73 */ 74 virtual MessageAuthenticationCode* 75 find_mac(const SCAN_Name& algo_spec, 76 Algorithm_Factory& af) const; 77 78 /** 79 * @param algo_spec the algorithm name/specification 80 * @param af an algorithm factory object 81 * @return newly allocated object, or NULL 82 */ 83 virtual PBKDF* find_pbkdf(const SCAN_Name& algo_spec, 84 Algorithm_Factory& af) const; 85 86 /** 87 * @param n the modulus 88 * @param hints any use hints 89 * @return newly allocated object, or NULL 90 */ 91 virtual Modular_Exponentiator* 92 mod_exp(const BigInt& n, 93 Power_Mod::Usage_Hints hints) const; 94 95 /** 96 * Return a new cipher object 97 * @param algo_spec the algorithm name/specification 98 * @param dir specifies if encryption or decryption is desired 99 * @param af an algorithm factory object 100 * @return newly allocated object, or NULL 101 */ 102 virtual Keyed_Filter* get_cipher(const std::string& algo_spec, 103 Cipher_Dir dir, 104 Algorithm_Factory& af); 105 106 /** 107 * Return a new operator object for this key, if possible 108 * @param key the key we want an operator for 109 * @return newly allocated operator object, or NULL 110 */ 111 virtual PK_Ops::Key_Agreement* 112 get_key_agreement_op(const Private_Key& key) const; 113 114 /** 115 * Return a new operator object for this key, if possible 116 * @param key the key we want an operator for 117 * @return newly allocated operator object, or NULL 118 */ 119 virtual PK_Ops::Signature* 120 get_signature_op(const Private_Key& key) const; 121 122 /** 123 * Return a new operator object for this key, if possible 124 * @param key the key we want an operator for 125 * @return newly allocated operator object, or NULL 126 */ 127 virtual PK_Ops::Verification* 128 get_verify_op(const Public_Key& key) const; 129 130 /** 131 * Return a new operator object for this key, if possible 132 * @param key the key we want an operator for 133 * @return newly allocated operator object, or NULL 134 */ 135 virtual PK_Ops::Encryption* 136 get_encryption_op(const Public_Key& key) const; 137 138 /** 139 * Return a new operator object for this key, if possible 140 * @param key the key we want an operator for 141 * @return newly allocated operator object, or NULL 142 */ 143 virtual PK_Ops::Decryption* 144 get_decryption_op(const Private_Key& key) const; 145 }; 146 147 } 148 149 #endif 150