aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/stream
diff options
context:
space:
mode:
authorRenĂ© Korthaus <[email protected]>2016-07-19 15:28:09 +0200
committerRenĂ© Korthaus <[email protected]>2016-07-20 09:04:05 +0200
commitadfc3e082d176f2f5141374f507a13d575898cff (patch)
treee13bc9adb3989bf907359be93916a7d15accf5af /src/lib/stream
parent308c7d5eda678566edd26e9ab20edbe772f46363 (diff)
Make Stream_Cipher::set_iv() pure virtual
It provided a default implementation that only checked that the length was correct, but ignored the actual data and did not notify the caller, which seemed like a rather odd behaviour. The only implementation that used this default implementation, RC4, now throws an exception.
Diffstat (limited to 'src/lib/stream')
-rw-r--r--src/lib/stream/rc4/rc4.cpp6
-rw-r--r--src/lib/stream/rc4/rc4.h2
-rw-r--r--src/lib/stream/stream_cipher.cpp6
-rw-r--r--src/lib/stream/stream_cipher.h2
4 files changed, 9 insertions, 7 deletions
diff --git a/src/lib/stream/rc4/rc4.cpp b/src/lib/stream/rc4/rc4.cpp
index a4dea9e2b..e5ea2e2b8 100644
--- a/src/lib/stream/rc4/rc4.cpp
+++ b/src/lib/stream/rc4/rc4.cpp
@@ -6,6 +6,7 @@
*/
#include <botan/rc4.h>
+#include <botan/exceptn.h>
namespace Botan {
@@ -35,6 +36,11 @@ void RC4::cipher(const byte in[], byte out[], size_t length)
m_position += length;
}
+void RC4::set_iv(const byte*, size_t)
+ {
+ throw Exception("RC4 does not support an IV");
+ }
+
/*
* Generate cipher stream
*/
diff --git a/src/lib/stream/rc4/rc4.h b/src/lib/stream/rc4/rc4.h
index 88798fae6..82dd6097b 100644
--- a/src/lib/stream/rc4/rc4.h
+++ b/src/lib/stream/rc4/rc4.h
@@ -21,6 +21,8 @@ class BOTAN_DLL RC4 final : public StreamCipher
public:
void cipher(const byte in[], byte out[], size_t length) override;
+ void set_iv(const byte iv[], size_t iv_len) override;
+
void clear() override;
std::string name() const override;
diff --git a/src/lib/stream/stream_cipher.cpp b/src/lib/stream/stream_cipher.cpp
index 6f98df1fb..cd6400d8f 100644
--- a/src/lib/stream/stream_cipher.cpp
+++ b/src/lib/stream/stream_cipher.cpp
@@ -44,12 +44,6 @@ std::vector<std::string> StreamCipher::providers(const std::string& algo_spec)
StreamCipher::StreamCipher() {}
StreamCipher::~StreamCipher() {}
-void StreamCipher::set_iv(const byte[], size_t iv_len)
- {
- if(!valid_iv_length(iv_len))
- throw Invalid_IV_Length(name(), iv_len);
- }
-
#if defined(BOTAN_HAS_CHACHA)
BOTAN_REGISTER_T_1LEN(StreamCipher, ChaCha, 20);
#endif
diff --git a/src/lib/stream/stream_cipher.h b/src/lib/stream/stream_cipher.h
index 56bd2d5d9..e08bee0ce 100644
--- a/src/lib/stream/stream_cipher.h
+++ b/src/lib/stream/stream_cipher.h
@@ -67,7 +67,7 @@ class BOTAN_DLL StreamCipher : public SymmetricAlgorithm
* @param iv the initialization vector
* @param iv_len the length of the IV in bytes
*/
- virtual void set_iv(const byte[], size_t iv_len);
+ virtual void set_iv(const byte[], size_t iv_len) = 0;
/**
* @param iv_len the length of the IV in bytes