Botan: src/algo_base/sym_algo.h Source File

Botan 1.10.12

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

sym_algo.h
Go to the documentation of this file.
1 /*
2 * Symmetric Algorithm Base Class
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_SYMMETRIC_ALGORITHM_H__
9 #define BOTAN_SYMMETRIC_ALGORITHM_H__
10
11 #include <botan/algo_base.h>
12 #include <botan/key_spec.h>
13 #include <botan/exceptn.h>
14 #include <botan/symkey.h>
15 #include <botan/types.h>
16
17 namespace Botan {
18
19 /**
20 * This class represents a symmetric algorithm object.
21 */
22 class BOTAN_DLL SymmetricAlgorithm : public Algorithm
23 {
24 public:
25 /**
26 * @return object describing limits on key size
27 */
28 virtual Key_Length_Specification key_spec() const = 0;
29
30 /**
31 * @return minimum allowed key length
32 */
33 size_t maximum_keylength() const
34 {
35 return key_spec().maximum_keylength();
36 }
37
38 /**
39 * @return maxmium allowed key length
40 */
41 size_t minimum_keylength() const
42 {
43 return key_spec().minimum_keylength();
44 }
45
46 /**
47 * Check whether a given key length is valid for this algorithm.
48 * @param length the key length to be checked.
49 * @return true if the key length is valid.
50 */
51 bool valid_keylength(size_t length) const
52 {
53 return key_spec().valid_keylength(length);
54 }
55
56 /**
57 * Set the symmetric key of this object.
58 * @param key the SymmetricKey to be set.
59 */
60 void set_key(const SymmetricKey& key)
61 { set_key(key.begin(), key.length()); }
62
63 /**
64 * Set the symmetric key of this object.
65 * @param key the to be set as a byte array.
66 * @param length in bytes of key param
67 */
68 void set_key(const byte key[], size_t length)
69 {
70 if(!valid_keylength(length))
71 throw Invalid_Key_Length(name(), length);
72 key_schedule(key, length);
73 }
74 private:
75 /**
76 * Run the key schedule
77 * @param key the key
78 * @param length of key
79 */
80 virtual void key_schedule(const byte key[], size_t length) = 0;
81 };
82
83 /**
84 * The two possible directions for cipher filters, determining whether they
85 * actually perform encryption or decryption.
86 */
87 enum Cipher_Dir { ENCRYPTION, DECRYPTION };
88
89 }
90
91 #endif
Botan::Invalid_Key_Length
Definition: exceptn.h:55
Botan::OctetString
Definition: symkey.h:19
Botan::ENCRYPTION
Definition: sym_algo.h:87
Botan::Key_Length_Specification
Definition: key_spec.h:18
Botan::SymmetricAlgorithm::minimum_keylength
size_t minimum_keylength() const
Definition: sym_algo.h:41
Botan::OctetString::length
size_t length() const
Definition: symkey.h:25
Botan::DECRYPTION
Definition: sym_algo.h:87
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::SymmetricAlgorithm::valid_keylength
bool valid_keylength(size_t length) const
Definition: sym_algo.h:51
Botan::SymmetricAlgorithm
Definition: sym_algo.h:22
Botan::SymmetricAlgorithm::set_key
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:60
Botan::OctetString::begin
const byte * begin() const
Definition: symkey.h:35
Botan
Definition: algo_base.h:14
Botan::Algorithm
Definition: algo_base.h:19
Botan::Cipher_Dir
Cipher_Dir
Definition: sym_algo.h:87
Botan::SymmetricAlgorithm::maximum_keylength
size_t maximum_keylength() const
Definition: sym_algo.h:33
Botan::SymmetricAlgorithm::set_key
void set_key(const byte key[], size_t length)
Definition: sym_algo.h:68