aboutsummaryrefslogtreecommitdiffstats
path: root/src/modes/modebase/modebase.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-28 23:42:02 +0000
committerlloyd <[email protected]>2008-09-28 23:42:02 +0000
commitd4647b485a4123f0163ae541439af3f21e26b101 (patch)
tree88a4a07a0f10f33b8064cbf6e5a99184a747eb4f /src/modes/modebase/modebase.cpp
parent45e73451bcc20838b723f1871290a9badb906dac (diff)
Add modebase module (and add dep in cipher mode impls). Move data_snk.cpp to filters
Diffstat (limited to 'src/modes/modebase/modebase.cpp')
-rw-r--r--src/modes/modebase/modebase.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/modes/modebase/modebase.cpp b/src/modes/modebase/modebase.cpp
new file mode 100644
index 000000000..6661d9f33
--- /dev/null
+++ b/src/modes/modebase/modebase.cpp
@@ -0,0 +1,53 @@
+/*************************************************
+* Block Cipher Mode Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/modebase.h>
+#include <botan/lookup.h>
+
+namespace Botan {
+
+/*************************************************
+* Block Cipher Mode Constructor *
+*************************************************/
+BlockCipherMode::BlockCipherMode(const std::string& cipher_name,
+ const std::string& cipher_mode_name,
+ u32bit iv_size, u32bit iv_meth,
+ u32bit buf_mult) :
+ BLOCK_SIZE(block_size_of(cipher_name)), BUFFER_SIZE(buf_mult * BLOCK_SIZE),
+ IV_METHOD(iv_meth), mode_name(cipher_mode_name)
+ {
+ base_ptr = cipher = get_block_cipher(cipher_name);
+ buffer.create(BUFFER_SIZE);
+ state.create(iv_size);
+ position = 0;
+ }
+
+/*************************************************
+* Return the name of this type *
+*************************************************/
+std::string BlockCipherMode::name() const
+ {
+ return (cipher->name() + "/" + mode_name);
+ }
+
+/*************************************************
+* Set the IV *
+*************************************************/
+void BlockCipherMode::set_iv(const InitializationVector& new_iv)
+ {
+ if(new_iv.length() != state.size())
+ throw Invalid_IV_Length(name(), new_iv.length());
+
+ state = new_iv.bits_of();
+ buffer.clear();
+ position = 0;
+
+ if(IV_METHOD == 1)
+ cipher->encrypt(state, buffer);
+ else if(IV_METHOD == 2)
+ cipher->encrypt(state);
+ }
+
+}