Botan 1.10.17
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
17namespace Botan {
18
19/**
20* This class represents a symmetric algorithm object.
21*/
22class BOTAN_DLL SymmetricAlgorithm : public Algorithm
23 {
24 public:
25 /**
26 * @return object describing limits on key size
27 */
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*/
88
89}
90
91#endif
virtual std::string name() const =0
const byte * begin() const
Definition symkey.h:35
size_t length() const
Definition symkey.h:25
bool valid_keylength(size_t length) const
Definition sym_algo.h:51
void set_key(const SymmetricKey &key)
Definition sym_algo.h:60
void set_key(const byte key[], size_t length)
Definition sym_algo.h:68
size_t maximum_keylength() const
Definition sym_algo.h:33
size_t minimum_keylength() const
Definition sym_algo.h:41
virtual Key_Length_Specification key_spec() const =0
OctetString SymmetricKey
Definition symkey.h:147
Cipher_Dir
Definition sym_algo.h:87
@ DECRYPTION
Definition sym_algo.h:87
@ ENCRYPTION
Definition sym_algo.h:87