diff options
author | lloyd <[email protected]> | 2010-10-28 21:15:21 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-10-28 21:15:21 +0000 |
commit | 22f02b418f7f53431da168abe9fb74f15bf3cb0e (patch) | |
tree | cdc81938c979403d20a438d134bbd6d64479f17d /src/stream | |
parent | a7a047e6823dcbf23e172dd5c0f9a7b4fd748f10 (diff) |
Eliminate the constant size_t values in SymmetricAlgorithm that give
the parameters of the key length. Instead define a new function which
returns a simple object which contains this information.
This definitely breaks backwards compatability, though only with code
that directly manipulates low level objects like BlockCipher*s
directly, which is probably relatively rare.
Also remove some deprecated accessor functions from lookup.h. It turns
out block_size_of and output_size_of are being used in the TLS code; I
need to remove them from there before I can delete these entirely.
Really that didn't make much sense, because they assumed all
implementations of a particular algorithm will have the same
specifications, which is definitely not necessarily true, especially
WRT key length. It is much safer (and probably simpler) to first
retrieve an instance of the actual object you are going to use and
then ask it directly.
Diffstat (limited to 'src/stream')
-rw-r--r-- | src/stream/arc4/arc4.cpp | 5 | ||||
-rw-r--r-- | src/stream/arc4/arc4.h | 5 | ||||
-rw-r--r-- | src/stream/ctr/ctr.cpp | 6 | ||||
-rw-r--r-- | src/stream/ctr/ctr.h | 5 | ||||
-rw-r--r-- | src/stream/ofb/ofb.cpp | 6 | ||||
-rw-r--r-- | src/stream/ofb/ofb.h | 5 | ||||
-rw-r--r-- | src/stream/salsa20/salsa20.h | 8 | ||||
-rw-r--r-- | src/stream/stream_cipher.h | 18 | ||||
-rw-r--r-- | src/stream/turing/turing.h | 11 | ||||
-rw-r--r-- | src/stream/wid_wake/wid_wake.h | 10 |
10 files changed, 40 insertions, 39 deletions
diff --git a/src/stream/arc4/arc4.cpp b/src/stream/arc4/arc4.cpp index 9b8404e4e..cd6230022 100644 --- a/src/stream/arc4/arc4.cpp +++ b/src/stream/arc4/arc4.cpp @@ -101,8 +101,9 @@ void ARC4::clear() /* * ARC4 Constructor */ -ARC4::ARC4(size_t s) : StreamCipher(1, 256), SKIP(s), - state(256), buffer(DEFAULT_BUFFERSIZE) +ARC4::ARC4(size_t s) : SKIP(s), + state(256), + buffer(DEFAULT_BUFFERSIZE) { clear(); } diff --git a/src/stream/arc4/arc4.h b/src/stream/arc4/arc4.h index 85ddb69b7..e3df97f83 100644 --- a/src/stream/arc4/arc4.h +++ b/src/stream/arc4/arc4.h @@ -26,6 +26,11 @@ class BOTAN_DLL ARC4 : public StreamCipher StreamCipher* clone() const { return new ARC4(SKIP); } + Key_Length_Specification key_spec() const + { + return Key_Length_Specification(1, 256); + } + /** * @param skip skip this many initial bytes in the keystream */ diff --git a/src/stream/ctr/ctr.cpp b/src/stream/ctr/ctr.cpp index dc2f334a8..e01f2432c 100644 --- a/src/stream/ctr/ctr.cpp +++ b/src/stream/ctr/ctr.cpp @@ -14,11 +14,7 @@ namespace Botan { * CTR-BE Constructor */ -CTR_BE::CTR_BE(BlockCipher* ciph) : - StreamCipher(ciph->MINIMUM_KEYLENGTH, - ciph->MAXIMUM_KEYLENGTH, - ciph->KEYLENGTH_MULTIPLE), - permutation(ciph) +CTR_BE::CTR_BE(BlockCipher* ciph) : permutation(ciph) { position = 0; diff --git a/src/stream/ctr/ctr.h b/src/stream/ctr/ctr.h index e62ab2860..64b43b0f5 100644 --- a/src/stream/ctr/ctr.h +++ b/src/stream/ctr/ctr.h @@ -26,6 +26,11 @@ class BOTAN_DLL CTR_BE : public StreamCipher bool valid_iv_length(size_t iv_len) const { return (iv_len <= permutation->block_size()); } + Key_Length_Specification key_spec() const + { + return permutation->key_spec(); + } + std::string name() const; CTR_BE* clone() const diff --git a/src/stream/ofb/ofb.cpp b/src/stream/ofb/ofb.cpp index 1f25c5c14..382a2b4dd 100644 --- a/src/stream/ofb/ofb.cpp +++ b/src/stream/ofb/ofb.cpp @@ -14,11 +14,7 @@ namespace Botan { /* * OFB Constructor */ -OFB::OFB(BlockCipher* ciph) : - StreamCipher(ciph->MINIMUM_KEYLENGTH, - ciph->MAXIMUM_KEYLENGTH, - ciph->KEYLENGTH_MULTIPLE), - permutation(ciph) +OFB::OFB(BlockCipher* ciph) : permutation(ciph) { position = 0; buffer.resize(permutation->block_size()); diff --git a/src/stream/ofb/ofb.h b/src/stream/ofb/ofb.h index 587a30bab..c4d8b2601 100644 --- a/src/stream/ofb/ofb.h +++ b/src/stream/ofb/ofb.h @@ -26,6 +26,11 @@ class BOTAN_DLL OFB : public StreamCipher bool valid_iv_length(size_t iv_len) const { return (iv_len <= permutation->block_size()); } + Key_Length_Specification key_spec() const + { + return permutation->key_spec(); + } + std::string name() const; OFB* clone() const diff --git a/src/stream/salsa20/salsa20.h b/src/stream/salsa20/salsa20.h index 213cb1117..d84aa9cdc 100644 --- a/src/stream/salsa20/salsa20.h +++ b/src/stream/salsa20/salsa20.h @@ -25,12 +25,16 @@ class BOTAN_DLL Salsa20 : public StreamCipher bool valid_iv_length(size_t iv_len) const { return (iv_len == 8 || iv_len == 24); } + Key_Length_Specification key_spec() const + { + return Key_Length_Specification(16, 32, 16); + } + void clear(); std::string name() const; StreamCipher* clone() const { return new Salsa20; } - Salsa20() : StreamCipher(16, 32, 16), state(16), buffer(64) - { position = 0; } + Salsa20() : state(16), buffer(64), position(0) {} ~Salsa20() { clear(); } private: diff --git a/src/stream/stream_cipher.h b/src/stream/stream_cipher.h index 680d57f70..301e71f07 100644 --- a/src/stream/stream_cipher.h +++ b/src/stream/stream_cipher.h @@ -51,24 +51,6 @@ class BOTAN_DLL StreamCipher : public SymmetricAlgorithm * Get a new object representing the same algorithm as *this */ virtual StreamCipher* clone() const = 0; - - /** - * Zeroize internal state - */ - virtual void clear() = 0; - - /** - * StreamCipher constructor - * @param key_min the minimum key size - * @param key_max the maximum key size - * @param key_mod the modulo restriction on the key size - */ - StreamCipher(size_t key_min, - size_t key_max = 0, - size_t key_mod = 1) : - SymmetricAlgorithm(key_min, key_max, key_mod) {} - - virtual ~StreamCipher() {} }; } diff --git a/src/stream/turing/turing.h b/src/stream/turing/turing.h index adfabc0f1..aff314080 100644 --- a/src/stream/turing/turing.h +++ b/src/stream/turing/turing.h @@ -24,14 +24,17 @@ class BOTAN_DLL Turing : public StreamCipher bool valid_iv_length(size_t iv_len) const { return (iv_len % 4 == 0 && iv_len <= 16); } + Key_Length_Specification key_spec() const + { + return Key_Length_Specification(4, 32, 4); + } + void clear(); std::string name() const { return "Turing"; } StreamCipher* clone() const { return new Turing; } - Turing() : StreamCipher(4, 32, 4), - S0(256), S1(256), S2(256), S3(256), - R(17), buffer(340) - { position = 0; } + Turing() : S0(256), S1(256), S2(256), S3(256), + R(17), buffer(340), position(0) {} private: void key_schedule(const byte[], size_t); diff --git a/src/stream/wid_wake/wid_wake.h b/src/stream/wid_wake/wid_wake.h index 17e77d5b5..05842a574 100644 --- a/src/stream/wid_wake/wid_wake.h +++ b/src/stream/wid_wake/wid_wake.h @@ -27,14 +27,18 @@ class BOTAN_DLL WiderWake_41_BE : public StreamCipher bool valid_iv_length(size_t iv_len) const { return (iv_len == 8); } + Key_Length_Specification key_spec() const + { + return Key_Length_Specification(16); + } + void clear(); std::string name() const { return "WiderWake4+1-BE"; } StreamCipher* clone() const { return new WiderWake_41_BE; } - WiderWake_41_BE() : StreamCipher(16, 16, 1), - T(256), state(5), t_key(4), + WiderWake_41_BE() : T(256), state(5), t_key(4), buffer(DEFAULT_BUFFERSIZE), position(0) - { } + {} private: void key_schedule(const byte[], size_t); |