aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/modes/cipher_mode.cpp18
-rw-r--r--src/lib/modes/ecb/ecb.cpp145
-rw-r--r--src/lib/modes/ecb/ecb.h99
-rw-r--r--src/lib/modes/ecb/info.txt5
-rw-r--r--src/lib/modes/mode_pad/mode_pad.h2
5 files changed, 1 insertions, 268 deletions
diff --git a/src/lib/modes/cipher_mode.cpp b/src/lib/modes/cipher_mode.cpp
index d622e7754..843e49581 100644
--- a/src/lib/modes/cipher_mode.cpp
+++ b/src/lib/modes/cipher_mode.cpp
@@ -18,10 +18,6 @@
#include <botan/aead.h>
#endif
-#if defined(BOTAN_HAS_MODE_ECB)
- #include <botan/ecb.h>
-#endif
-
#if defined(BOTAN_HAS_MODE_CBC)
#include <botan/cbc.h>
#endif
@@ -140,20 +136,6 @@ Cipher_Mode* get_cipher_mode(const std::string& algo, Cipher_Dir direction)
}
#endif
-#if defined(BOTAN_HAS_MODE_ECB)
- if(spec.algo_name() == "ECB")
- {
- std::unique_ptr<BlockCipherModePaddingMethod> pad(get_bc_pad(spec.arg(1, "NoPadding")));
- if(pad)
- {
- if(direction == ENCRYPTION)
- return new ECB_Encryption(bc.release(), pad.release());
- else
- return new ECB_Decryption(bc.release(), pad.release());
- }
- }
-#endif
-
#endif
return nullptr;
diff --git a/src/lib/modes/ecb/ecb.cpp b/src/lib/modes/ecb/ecb.cpp
deleted file mode 100644
index 78dff5ffa..000000000
--- a/src/lib/modes/ecb/ecb.cpp
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
-* ECB Mode
-* (C) 1999-2009,2013 Jack Lloyd
-* (C) 2016 Daniel Neus, Rohde & Schwarz Cybersecurity
-*
-* Botan is released under the Simplified BSD License (see license.txt)
-*/
-
-#include <botan/ecb.h>
-#include <botan/internal/rounding.h>
-
-namespace Botan {
-
-ECB_Mode::ECB_Mode(BlockCipher* cipher, BlockCipherModePaddingMethod* padding) :
- m_cipher(cipher),
- m_padding(padding)
- {
- if(!m_padding->valid_blocksize(cipher->block_size()))
- throw Invalid_Argument("Padding " + m_padding->name() +
- " cannot be used with " +
- cipher->name() + "/ECB");
- }
-
-void ECB_Mode::clear()
- {
- m_cipher->clear();
- }
-
-void ECB_Mode::reset()
- {
- // no msg state here
- return;
- }
-
-std::string ECB_Mode::name() const
- {
- return cipher().name() + "/ECB/" + padding().name();
- }
-
-size_t ECB_Mode::update_granularity() const
- {
- return cipher().parallel_bytes();
- }
-
-Key_Length_Specification ECB_Mode::key_spec() const
- {
- return cipher().key_spec();
- }
-
-size_t ECB_Mode::default_nonce_length() const
- {
- return 0;
- }
-
-bool ECB_Mode::valid_nonce_length(size_t n) const
- {
- return (n == 0);
- }
-
-void ECB_Mode::key_schedule(const byte key[], size_t length)
- {
- m_cipher->set_key(key, length);
- }
-
-void ECB_Mode::start_msg(const byte[], size_t nonce_len)
- {
- if(nonce_len != 0)
- throw Invalid_IV_Length(name(), nonce_len);
- }
-
-size_t ECB_Encryption::minimum_final_size() const
- {
- return 0;
- }
-
-size_t ECB_Encryption::output_length(size_t input_length) const
- {
- if(input_length == 0)
- return cipher().block_size();
- else
- return round_up(input_length, cipher().block_size());
- }
-
-size_t ECB_Encryption::process(uint8_t buf[], size_t sz)
- {
- const size_t BS = cipher().block_size();
- BOTAN_ASSERT(sz % BS == 0, "ECB input is full blocks");
- const size_t blocks = sz / BS;
- cipher().encrypt_n(buf, buf, blocks);
- return sz;
- }
-
-void ECB_Encryption::finish(secure_vector<byte>& buffer, size_t offset)
- {
- BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane");
- const size_t sz = buffer.size() - offset;
-
- const size_t BS = cipher().block_size();
-
- const size_t bytes_in_final_block = sz % BS;
-
- padding().add_padding(buffer, bytes_in_final_block, BS);
-
- if(buffer.size() % BS)
- throw Exception("Did not pad to full block size in " + name());
-
- update(buffer, offset);
- }
-
-size_t ECB_Decryption::output_length(size_t input_length) const
- {
- return input_length;
- }
-
-size_t ECB_Decryption::minimum_final_size() const
- {
- return cipher().block_size();
- }
-
-size_t ECB_Decryption::process(uint8_t buf[], size_t sz)
- {
- const size_t BS = cipher().block_size();
- BOTAN_ASSERT(sz % BS == 0, "Input is full blocks");
- size_t blocks = sz / BS;
- cipher().decrypt_n(buf, buf, blocks);
- return sz;
- }
-
-void ECB_Decryption::finish(secure_vector<byte>& buffer, size_t offset)
- {
- BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane");
- const size_t sz = buffer.size() - offset;
-
- const size_t BS = cipher().block_size();
-
- if(sz == 0 || sz % BS)
- throw Decoding_Error(name() + ": Ciphertext not a multiple of block size");
-
- update(buffer, offset);
-
- const size_t pad_bytes = BS - padding().unpad(&buffer[buffer.size()-BS], BS);
- buffer.resize(buffer.size() - pad_bytes); // remove padding
- }
-
-}
diff --git a/src/lib/modes/ecb/ecb.h b/src/lib/modes/ecb/ecb.h
deleted file mode 100644
index 9fc17a80d..000000000
--- a/src/lib/modes/ecb/ecb.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
-* ECB Mode
-* (C) 1999-2009,2013 Jack Lloyd
-* (C) 2016 Daniel Neus, Rohde & Schwarz Cybersecurity
-*
-* Botan is released under the Simplified BSD License (see license.txt)
-*/
-
-#ifndef BOTAN_MODE_ECB_H__
-#define BOTAN_MODE_ECB_H__
-
-#include <botan/cipher_mode.h>
-#include <botan/block_cipher.h>
-#include <botan/mode_pad.h>
-
-namespace Botan {
-
-/**
-* ECB mode
-*/
-class BOTAN_DLL ECB_Mode : public Cipher_Mode
- {
- public:
- std::string name() const override;
-
- size_t update_granularity() const override;
-
- Key_Length_Specification key_spec() const override;
-
- size_t default_nonce_length() const override;
-
- bool valid_nonce_length(size_t n) const override;
-
- void clear() override;
-
- void reset() override;
-
- protected:
- ECB_Mode(BlockCipher* cipher, BlockCipherModePaddingMethod* padding);
-
- const BlockCipher& cipher() const { return *m_cipher; }
-
- const BlockCipherModePaddingMethod& padding() const { return *m_padding; }
-
- private:
- void start_msg(const byte nonce[], size_t nonce_len) override;
- void key_schedule(const byte key[], size_t length) override;
-
- std::unique_ptr<BlockCipher> m_cipher;
- std::unique_ptr<BlockCipherModePaddingMethod> m_padding;
- };
-
-/**
-* ECB Encryption
-*/
-class BOTAN_DLL ECB_Encryption final : public ECB_Mode
- {
- public:
- /**
- * @param cipher block cipher to use
- * @param padding padding method to use
- */
- ECB_Encryption(BlockCipher* cipher, BlockCipherModePaddingMethod* padding) :
- ECB_Mode(cipher, padding) {}
-
- size_t process(uint8_t buf[], size_t size) override;
-
- void finish(secure_vector<byte>& final_block, size_t offset = 0) override;
-
- size_t output_length(size_t input_length) const override;
-
- size_t minimum_final_size() const override;
- };
-
-/**
-* ECB Decryption
-*/
-class BOTAN_DLL ECB_Decryption final : public ECB_Mode
- {
- public:
- /**
- * @param cipher block cipher to use
- * @param padding padding method to use
- */
- ECB_Decryption(BlockCipher* cipher, BlockCipherModePaddingMethod* padding) :
- ECB_Mode(cipher, padding) {}
-
- size_t process(uint8_t buf[], size_t size) override;
-
- void finish(secure_vector<byte>& final_block, size_t offset = 0) override;
-
- size_t output_length(size_t input_length) const override;
-
- size_t minimum_final_size() const override;
- };
-
-}
-
-#endif
diff --git a/src/lib/modes/ecb/info.txt b/src/lib/modes/ecb/info.txt
deleted file mode 100644
index 5e7737717..000000000
--- a/src/lib/modes/ecb/info.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-define MODE_ECB 20131128
-
-<requires>
-mode_pad
-</requires>
diff --git a/src/lib/modes/mode_pad/mode_pad.h b/src/lib/modes/mode_pad/mode_pad.h
index 7c67ceaad..4f07bc6ae 100644
--- a/src/lib/modes/mode_pad/mode_pad.h
+++ b/src/lib/modes/mode_pad/mode_pad.h
@@ -1,5 +1,5 @@
/*
-* ECB/CBC Padding Methods
+* CBC Padding Methods
* (C) 1999-2008,2013 Jack Lloyd
* (C) 2016 René Korthaus, Rohde & Schwarz Cybersecurity
*