Botan  2.4.0
Crypto and TLS for C++11
key_filt.h
Go to the documentation of this file.
1 /*
2 * Keyed_Filter
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_KEYED_FILTER_H_
9 #define BOTAN_KEYED_FILTER_H_
10 
11 #include <botan/symkey.h>
12 #include <botan/filter.h>
13 #include <botan/cipher_mode.h>
14 
15 namespace Botan {
16 
17 /**
18 * This class represents keyed filters, i.e. filters that have to be
19 * fed with a key in order to function.
20 */
22  {
23  public:
24  /**
25  * Set the key of this filter
26  * @param key the key to use
27  */
28  virtual void set_key(const SymmetricKey& key) = 0;
29 
30  /**
31  * Set the initialization vector of this filter. Note: you should
32  * call set_iv() only after you have called set_key()
33  * @param iv the initialization vector to use
34  */
35  virtual void set_iv(const InitializationVector& iv);
36 
37  /**
38  * Check whether a key length is valid for this filter
39  * @param length the key length to be checked for validity
40  * @return true if the key length is valid, false otherwise
41  */
42  bool valid_keylength(size_t length) const
43  {
44  return key_spec().valid_keylength(length);
45  }
46 
47  /**
48  * @return object describing limits on key size
49  */
50  virtual Key_Length_Specification key_spec() const = 0;
51 
52  /**
53  * Check whether an IV length is valid for this filter
54  * @param length the IV length to be checked for validity
55  * @return true if the IV length is valid, false otherwise
56  */
57  virtual bool valid_iv_length(size_t length) const
58  { return (length == 0); }
59  };
60 
61 
62 
63 /*
64 * Get a cipher object
65 */
66 
67 /**
68 * Factory method for general symmetric cipher filters.
69 * @param algo_spec the name of the desired cipher
70 * @param key the key to be used for encryption/decryption performed by
71 * the filter
72 * @param iv the initialization vector to be used
73 * @param direction determines whether the filter will be an encrypting
74 * or decrypting filter
75 * @return pointer to newly allocated encryption or decryption filter
76 */
77 BOTAN_PUBLIC_API(2,0) Keyed_Filter* get_cipher(const std::string& algo_spec,
78  const SymmetricKey& key,
79  const InitializationVector& iv,
80  Cipher_Dir direction);
81 
82 /**
83 * Factory method for general symmetric cipher filters.
84 * @param algo_spec the name of the desired cipher
85 * @param key the key to be used for encryption/decryption performed by
86 * the filter
87 * @param direction determines whether the filter will be an encrypting
88 * or decrypting filter
89 * @return pointer to the encryption or decryption filter
90 */
91 BOTAN_PUBLIC_API(2,0) Keyed_Filter* get_cipher(const std::string& algo_spec,
92  const SymmetricKey& key,
93  Cipher_Dir direction);
94 
95 /**
96 * Factory method for general symmetric cipher filters. No key will be
97 * set in the filter.
98 *
99 * @param algo_spec the name of the desired cipher
100 * @param direction determines whether the filter will be an encrypting or
101 * decrypting filter
102 * @return pointer to the encryption or decryption filter
103 */
104 BOTAN_PUBLIC_API(2,0) Keyed_Filter* get_cipher(const std::string& algo_spec,
105  Cipher_Dir direction);
106 
107 }
108 
109 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
virtual bool valid_iv_length(size_t length) const
Definition: key_filt.h:57
Definition: alg_id.cpp:13
bool valid_keylength(size_t length) const
Definition: key_filt.h:42
Keyed_Filter * get_cipher(const std::string &algo_spec, Cipher_Dir direction)
Definition: key_filt.cpp:12