Botan
1.11.15
|
00001 /* 00002 * Keyed_Filter 00003 * (C) 1999-2007 Jack Lloyd 00004 * 00005 * Botan is released under the Simplified BSD License (see license.txt) 00006 */ 00007 00008 #ifndef BOTAN_KEYED_FILTER_H__ 00009 #define BOTAN_KEYED_FILTER_H__ 00010 00011 #include <botan/filter.h> 00012 #include <botan/cipher_mode.h> 00013 #include <botan/sym_algo.h> 00014 00015 namespace Botan { 00016 00017 /** 00018 * This class represents keyed filters, i.e. filters that have to be 00019 * fed with a key in order to function. 00020 */ 00021 class BOTAN_DLL Keyed_Filter : public Filter 00022 { 00023 public: 00024 /** 00025 * Set the key of this filter 00026 * @param key the key to use 00027 */ 00028 virtual void set_key(const SymmetricKey& key) = 0; 00029 00030 /** 00031 * Set the initialization vector of this filter. Note: you should 00032 * call set_iv() only after you have called set_key() 00033 * @param iv the initialization vector to use 00034 */ 00035 virtual void set_iv(const InitializationVector& iv); 00036 00037 /** 00038 * Check whether a key length is valid for this filter 00039 * @param length the key length to be checked for validity 00040 * @return true if the key length is valid, false otherwise 00041 */ 00042 bool valid_keylength(size_t length) const 00043 { 00044 return key_spec().valid_keylength(length); 00045 } 00046 00047 /** 00048 * @return object describing limits on key size 00049 */ 00050 virtual Key_Length_Specification key_spec() const = 0; 00051 00052 /** 00053 * Check whether an IV length is valid for this filter 00054 * @param length the IV length to be checked for validity 00055 * @return true if the IV length is valid, false otherwise 00056 */ 00057 virtual bool valid_iv_length(size_t length) const 00058 { return (length == 0); } 00059 }; 00060 00061 00062 00063 /* 00064 * Get a cipher object 00065 */ 00066 00067 /** 00068 * Factory method for general symmetric cipher filters. 00069 * @param algo_spec the name of the desired cipher 00070 * @param key the key to be used for encryption/decryption performed by 00071 * the filter 00072 * @param iv the initialization vector to be used 00073 * @param direction determines whether the filter will be an encrypting 00074 * or decrypting filter 00075 * @return pointer to newly allocated encryption or decryption filter 00076 */ 00077 BOTAN_DLL Keyed_Filter* get_cipher(const std::string& algo_spec, 00078 const SymmetricKey& key, 00079 const InitializationVector& iv, 00080 Cipher_Dir direction); 00081 00082 /** 00083 * Factory method for general symmetric cipher filters. 00084 * @param algo_spec the name of the desired cipher 00085 * @param key the key to be used for encryption/decryption performed by 00086 * the filter 00087 * @param direction determines whether the filter will be an encrypting 00088 * or decrypting filter 00089 * @return pointer to the encryption or decryption filter 00090 */ 00091 BOTAN_DLL Keyed_Filter* get_cipher(const std::string& algo_spec, 00092 const SymmetricKey& key, 00093 Cipher_Dir direction); 00094 00095 /** 00096 * Factory method for general symmetric cipher filters. No key will be 00097 * set in the filter. 00098 * 00099 * @param algo_spec the name of the desired cipher 00100 * @param direction determines whether the filter will be an encrypting or 00101 * decrypting filter 00102 * @return pointer to the encryption or decryption filter 00103 */ 00104 BOTAN_DLL Keyed_Filter* get_cipher(const std::string& algo_spec, 00105 Cipher_Dir direction); 00106 00107 } 00108 00109 #endif