diff options
author | lloyd <[email protected]> | 2010-11-01 17:25:48 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-11-01 17:25:48 +0000 |
commit | 04cb06b11bbb64a6bf947abec8849d1bf02ec093 (patch) | |
tree | dc6508dfcc6084d7e52cfb2861462b8614a4dec4 /src/algo_base/key_spec.h | |
parent | ba069386cdfb31720fa5a305c81baa18a0c8504d (diff) |
Add new top-level algorithm which provides basic functionality: name
query, clearing, and cloning. Applies to ciphers, hashes, MACs, and
PBKDFs. May extend to KDFs later as well.
A single combined hierarchy in particular will make the algo_factory
much simpler.
Diffstat (limited to 'src/algo_base/key_spec.h')
-rw-r--r-- | src/algo_base/key_spec.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/algo_base/key_spec.h b/src/algo_base/key_spec.h new file mode 100644 index 000000000..7788bb988 --- /dev/null +++ b/src/algo_base/key_spec.h @@ -0,0 +1,62 @@ +/* +* Symmetric Key Length Specification +* (C) 2010 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_KEY_LEN_SPECIFICATION_H__ +#define BOTAN_KEY_LEN_SPECIFICATION_H__ + +#include <botan/types.h> + +namespace Botan { + +class BOTAN_DLL Key_Length_Specification + { + public: + Key_Length_Specification(size_t keylen) : + min_keylen(keylen), + max_keylen(keylen), + keylen_mod(1) + { + } + + Key_Length_Specification(size_t min_k, + size_t max_k, + size_t k_mod = 1) : + min_keylen(min_k), + max_keylen(max_k ? max_k : min_k), + keylen_mod(k_mod) + { + } + + bool valid_keylength(size_t length) const + { + return ((length >= min_keylen) && + (length <= max_keylen) && + (length % keylen_mod == 0)); + } + + size_t minimum_keylength() const + { + return min_keylen; + } + + size_t maximum_keylength() const + { + return max_keylen; + } + + size_t keylength_multiple() const + { + return keylen_mod; + } + + private: + size_t min_keylen, max_keylen, keylen_mod; + }; + +} + +#endif |