Botan: src/algo_base/key_spec.h Source File

Botan 1.10.17

key_spec.h
Go to the documentation of this file.
1 /*
2 * Symmetric Key Length Specification
3 * (C) 2010 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_KEY_LEN_SPECIFICATION_H__
9 #define BOTAN_KEY_LEN_SPECIFICATION_H__
10
11 #include <botan/types.h>
12
13 namespace Botan {
14
15 /**
16 * Represents the length requirements on an algorithm key
17 */
18 class BOTAN_DLL Key_Length_Specification
19 {
20 public:
21 /**
22 * Constructor for fixed length keys
23 * @param keylen the supported key length
24 */
25 Key_Length_Specification(size_t keylen) :
26 min_keylen(keylen),
27 max_keylen(keylen),
28 keylen_mod(1)
29 {
30 }
31
32 /**
33 * Constructor for variable length keys
34 * @param min_k the smallest supported key length
35 * @param max_k the largest supported key length
36 * @param k_mod the number of bytes the key must be a multiple of
37 */
38 Key_Length_Specification(size_t min_k,
39 size_t max_k,
40 size_t k_mod = 1) :
41 min_keylen(min_k),
42 max_keylen(max_k ? max_k : min_k),
43 keylen_mod(k_mod)
44 {
45 }
46
47 /**
48 * @param length is a key length in bytes
49 * @return true iff this length is a valid length for this algo
50 */
51 bool valid_keylength(size_t length) const
52 {
53 return ((length >= min_keylen) &&
54 (length <= max_keylen) &&
55 (length % keylen_mod == 0));
56 }
57
58 /**
59 * @return minimum key length in bytes
60 */
61 size_t minimum_keylength() const
62 {
63 return min_keylen;
64 }
65
66 /**
67 * @return maximum key length in bytes
68 */
69 size_t maximum_keylength() const
70 {
71 return max_keylen;
72 }
73
74 /**
75 * @return key length multiple in bytes
76 */
77 size_t keylength_multiple() const
78 {
79 return keylen_mod;
80 }
81
82 private:
83 size_t min_keylen, max_keylen, keylen_mod;
84 };
85
86 }
87
88 #endif
Botan::Key_Length_Specification::Key_Length_Specification
Key_Length_Specification(size_t min_k, size_t max_k, size_t k_mod=1)
Definition: key_spec.h:38
Botan::Key_Length_Specification::maximum_keylength
size_t maximum_keylength() const
Definition: key_spec.h:69
Botan::Key_Length_Specification
Definition: key_spec.h:18
Botan::Key_Length_Specification::keylength_multiple
size_t keylength_multiple() const
Definition: key_spec.h:77
Botan::Key_Length_Specification::valid_keylength
bool valid_keylength(size_t length) const
Definition: key_spec.h:51
Botan
Definition: algo_base.h:14
Botan::Key_Length_Specification::minimum_keylength
size_t minimum_keylength() const
Definition: key_spec.h:61
Botan::Key_Length_Specification::Key_Length_Specification
Key_Length_Specification(size_t keylen)
Definition: key_spec.h:25