aboutsummaryrefslogtreecommitdiffstats
path: root/src/modes/ecb
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-11-17 07:19:37 +0000
committerlloyd <[email protected]>2009-11-17 07:19:37 +0000
commite00b46cf9c1dcb364ebb7d5968d6ff9dcd600c4e (patch)
tree8ffb8d032f06bbcb7ab376c7469751a25b556dca /src/modes/ecb
parenta98a9ff5f95bd4dca9c1eda11e27e712c869cd66 (diff)
Move most code that relies heavily on Filters into src/filters.
Remove support for (unused) modset settings. Move tss, fpe, cryptobox, and aont to new dir constructs
Diffstat (limited to 'src/modes/ecb')
-rw-r--r--src/modes/ecb/ecb.cpp222
-rw-r--r--src/modes/ecb/ecb.h83
-rw-r--r--src/modes/ecb/info.txt13
3 files changed, 0 insertions, 318 deletions
diff --git a/src/modes/ecb/ecb.cpp b/src/modes/ecb/ecb.cpp
deleted file mode 100644
index bff6d70f4..000000000
--- a/src/modes/ecb/ecb.cpp
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
-* ECB Mode
-* (C) 1999-2007 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#include <botan/ecb.h>
-
-namespace Botan {
-
-namespace {
-
-const u32bit PARALLEL_BLOCKS = BOTAN_PARALLEL_BLOCKS_ECB;
-
-}
-
-/*
-* ECB_Encryption Constructor
-*/
-ECB_Encryption::ECB_Encryption(BlockCipher* ciph,
- BlockCipherModePaddingMethod* pad)
- {
- cipher = ciph;
- padder = pad;
-
- plaintext.resize(cipher->BLOCK_SIZE);
- ciphertext.resize(cipher->BLOCK_SIZE * PARALLEL_BLOCKS);
-
- position = 0;
- }
-
-/*
-* ECB_Encryption Constructor
-*/
-ECB_Encryption::ECB_Encryption(BlockCipher* ciph,
- BlockCipherModePaddingMethod* pad,
- const SymmetricKey& key)
- {
- cipher = ciph;
- padder = pad;
-
- plaintext.resize(cipher->BLOCK_SIZE);
- ciphertext.resize(cipher->BLOCK_SIZE * PARALLEL_BLOCKS);
-
- position = 0;
-
- cipher->set_key(key);
- }
-
-/*
-* ECB_Encryption Destructor
-*/
-ECB_Encryption::~ECB_Encryption()
- {
- delete cipher;
- delete padder;
- }
-
-/*
-* Return an ECB mode name
-*/
-std::string ECB_Encryption::name() const
- {
- return (cipher->name() + "/ECB/" + padder->name());
- }
-
-/*
-* Encrypt in ECB mode
-*/
-void ECB_Encryption::write(const byte input[], u32bit length)
- {
- const u32bit BLOCK_SIZE = cipher->BLOCK_SIZE;
-
- if(position)
- {
- plaintext.copy(position, input, length);
-
- if(position + length >= BLOCK_SIZE)
- {
- cipher->encrypt(plaintext, ciphertext);
- send(ciphertext, BLOCK_SIZE);
- input += (BLOCK_SIZE - position);
- length -= (BLOCK_SIZE - position);
- position = 0;
- }
- }
-
- while(length >= BLOCK_SIZE)
- {
- const u32bit to_proc =
- std::min<u32bit>(length, ciphertext.size()) / BLOCK_SIZE;
-
- cipher->encrypt_n(input, ciphertext, to_proc);
- send(ciphertext, to_proc * BLOCK_SIZE);
- input += to_proc * BLOCK_SIZE;
- length -= to_proc * BLOCK_SIZE;
- }
-
- plaintext.copy(position, input, length);
- position += length;
- }
-
-/*
-* Finish encrypting in ECB mode
-*/
-void ECB_Encryption::end_msg()
- {
- const u32bit BLOCK_SIZE = cipher->BLOCK_SIZE;
-
- SecureVector<byte> padding(BLOCK_SIZE);
- padder->pad(padding, padding.size(), position);
- write(padding, padder->pad_bytes(BLOCK_SIZE, position));
- if(position != 0)
- throw Encoding_Error(name() + ": Did not pad to full blocksize");
- }
-
-/*
-* ECB_Decryption Constructor
-*/
-ECB_Decryption::ECB_Decryption(BlockCipher* ciph,
- BlockCipherModePaddingMethod* pad)
- {
- cipher = ciph;
- padder = pad;
-
- ciphertext.resize(cipher->BLOCK_SIZE);
- plaintext.resize(cipher->BLOCK_SIZE * PARALLEL_BLOCKS);
-
- position = 0;
- }
-
-/*
-* ECB_Decryption Constructor
-*/
-ECB_Decryption::ECB_Decryption(BlockCipher* ciph,
- BlockCipherModePaddingMethod* pad,
- const SymmetricKey& key)
- {
- cipher = ciph;
- padder = pad;
-
- ciphertext.resize(cipher->BLOCK_SIZE);
- plaintext.resize(cipher->BLOCK_SIZE * PARALLEL_BLOCKS);
-
- position = 0;
-
- cipher->set_key(key);
- }
-
-/*
-* ECB_Decryption Destructor
-*/
-ECB_Decryption::~ECB_Decryption()
- {
- delete cipher;
- delete padder;
- }
-
-/*
-* Return an ECB mode name
-*/
-std::string ECB_Decryption::name() const
- {
- return (cipher->name() + "/ECB/" + padder->name());
- }
-
-/*
-* Decrypt in ECB mode
-*/
-void ECB_Decryption::write(const byte input[], u32bit length)
- {
- const u32bit BLOCK_SIZE = cipher->BLOCK_SIZE;
-
- if(position)
- {
- ciphertext.copy(position, input, length);
-
- if(position + length > BLOCK_SIZE)
- {
- cipher->decrypt(ciphertext, plaintext);
- send(plaintext, BLOCK_SIZE);
- input += (BLOCK_SIZE - position);
- length -= (BLOCK_SIZE - position);
- position = 0;
- }
- }
-
- while(length > BLOCK_SIZE)
- {
- /* Always leave at least 1 byte left over, to ensure that (as long
- as the input message actually is a multiple of the block size)
- we will have the full final block left over in end_msg so as
- to remove the padding
- */
- const u32bit to_proc =
- std::min<u32bit>(length - 1, plaintext.size()) / BLOCK_SIZE;
-
- cipher->decrypt_n(input, plaintext, to_proc);
- send(plaintext, to_proc * BLOCK_SIZE);
- input += to_proc * BLOCK_SIZE;
- length -= to_proc * BLOCK_SIZE;
- }
-
- ciphertext.copy(position, input, length);
- position += length;
- }
-
-/*
-* Finish decrypting in ECB mode
-*/
-void ECB_Decryption::end_msg()
- {
- if(position != cipher->BLOCK_SIZE)
- throw Decoding_Error(name());
-
- cipher->decrypt(ciphertext);
- send(ciphertext, padder->unpad(ciphertext, cipher->BLOCK_SIZE));
- position = 0;
- }
-
-}
diff --git a/src/modes/ecb/ecb.h b/src/modes/ecb/ecb.h
deleted file mode 100644
index ff9ea9635..000000000
--- a/src/modes/ecb/ecb.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
-* ECB Mode
-* (C) 1999-2009 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#ifndef BOTAN_ECB_H__
-#define BOTAN_ECB_H__
-
-#include <botan/basefilt.h>
-#include <botan/block_cipher.h>
-#include <botan/mode_pad.h>
-
-#include <botan/modebase.h>
-
-namespace Botan {
-
-/*
-* ECB Encryption
-*/
-class BOTAN_DLL ECB_Encryption : public Keyed_Filter
- {
- public:
- std::string name() const;
-
- void set_key(const SymmetricKey& key) { cipher->set_key(key); }
-
- bool valid_keylength(u32bit key_len) const
- { return cipher->valid_keylength(key_len); }
-
- ECB_Encryption(BlockCipher* ciph,
- BlockCipherModePaddingMethod* pad);
-
- ECB_Encryption(BlockCipher* ciph,
- BlockCipherModePaddingMethod* pad,
- const SymmetricKey& key);
-
- ~ECB_Encryption();
- private:
- void write(const byte[], u32bit);
- void end_msg();
-
- BlockCipher* cipher;
- BlockCipherModePaddingMethod* padder;
- SecureVector<byte> plaintext, ciphertext;
- u32bit position;
- };
-
-/*
-* ECB Decryption
-*/
-class BOTAN_DLL ECB_Decryption : public Keyed_Filter
- {
- public:
- std::string name() const;
-
- void set_key(const SymmetricKey& key) { cipher->set_key(key); }
-
- bool valid_keylength(u32bit key_len) const
- { return cipher->valid_keylength(key_len); }
-
- ECB_Decryption(BlockCipher* ciph,
- BlockCipherModePaddingMethod* pad);
-
- ECB_Decryption(BlockCipher* ciph,
- BlockCipherModePaddingMethod* pad,
- const SymmetricKey& key);
-
- ~ECB_Decryption();
- private:
- void write(const byte[], u32bit);
- void end_msg();
-
- BlockCipher* cipher;
- BlockCipherModePaddingMethod* padder;
- SecureVector<byte> plaintext, ciphertext;
- u32bit position;
- };
-
-}
-
-#endif
diff --git a/src/modes/ecb/info.txt b/src/modes/ecb/info.txt
deleted file mode 100644
index f5c831169..000000000
--- a/src/modes/ecb/info.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-define ECB
-
-load_on auto
-
-<add>
-ecb.cpp
-ecb.h
-</add>
-
-<requires>
-block
-mode_pad
-</requires>