diff options
Diffstat (limited to 'src/stream/ctr')
-rw-r--r-- | src/stream/ctr/ctr.cpp | 134 | ||||
-rw-r--r-- | src/stream/ctr/ctr.h | 61 | ||||
-rw-r--r-- | src/stream/ctr/info.txt | 6 |
3 files changed, 0 insertions, 201 deletions
diff --git a/src/stream/ctr/ctr.cpp b/src/stream/ctr/ctr.cpp deleted file mode 100644 index 87ec86c65..000000000 --- a/src/stream/ctr/ctr.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* -* Counter mode -* (C) 1999-2011 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include <botan/ctr.h> -#include <botan/internal/xor_buf.h> - -namespace Botan { - -/* -* CTR-BE Constructor -*/ - -CTR_BE::CTR_BE(BlockCipher* ciph) : - permutation(ciph), - counter(256 * permutation->block_size()), - buffer(counter.size()), - position(0) - { - } - -/* -* CTR_BE Destructor -*/ -CTR_BE::~CTR_BE() - { - delete permutation; - } - -/* -* Zeroize -*/ -void CTR_BE::clear() - { - permutation->clear(); - zeroise(buffer); - zeroise(counter); - position = 0; - } - -/* -* Set the key -*/ -void CTR_BE::key_schedule(const byte key[], size_t key_len) - { - permutation->set_key(key, key_len); - - // Set a default all-zeros IV - set_iv(nullptr, 0); - } - -/* -* Return the name of this type -*/ -std::string CTR_BE::name() const - { - return ("CTR-BE(" + permutation->name() + ")"); - } - -/* -* CTR-BE Encryption/Decryption -*/ -void CTR_BE::cipher(const byte in[], byte out[], size_t length) - { - while(length >= buffer.size() - position) - { - xor_buf(out, in, &buffer[position], buffer.size() - position); - length -= (buffer.size() - position); - in += (buffer.size() - position); - out += (buffer.size() - position); - increment_counter(); - } - xor_buf(out, in, &buffer[position], length); - position += length; - } - -/* -* Set CTR-BE IV -*/ -void CTR_BE::set_iv(const byte iv[], size_t iv_len) - { - if(!valid_iv_length(iv_len)) - throw Invalid_IV_Length(name(), iv_len); - - const size_t bs = permutation->block_size(); - - zeroise(counter); - - buffer_insert(counter, 0, iv, iv_len); - - /* - * Set counter blocks to IV, IV + 1, ... IV + 255 - */ - for(size_t i = 1; i != 256; ++i) - { - buffer_insert(counter, i*bs, &counter[(i-1)*bs], bs); - - for(size_t j = 0; j != bs; ++j) - if(++counter[i*bs + (bs - 1 - j)]) - break; - } - - permutation->encrypt_n(&counter[0], &buffer[0], 256); - position = 0; - } - -/* -* Increment the counter and update the buffer -*/ -void CTR_BE::increment_counter() - { - const size_t bs = permutation->block_size(); - - /* - * Each counter value always needs to be incremented by 256, - * so we don't touch the lowest byte and instead treat it as - * an increment of one starting with the next byte. - */ - for(size_t i = 0; i != 256; ++i) - { - for(size_t j = 1; j != bs; ++j) - if(++counter[i*bs + (bs - 1 - j)]) - break; - } - - permutation->encrypt_n(&counter[0], &buffer[0], 256); - - position = 0; - } - -} diff --git a/src/stream/ctr/ctr.h b/src/stream/ctr/ctr.h deleted file mode 100644 index 84cf9ed5d..000000000 --- a/src/stream/ctr/ctr.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -* CTR-BE Mode -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_CTR_BE_H__ -#define BOTAN_CTR_BE_H__ - -#include <botan/block_cipher.h> -#include <botan/stream_cipher.h> - -namespace Botan { - -/** -* CTR-BE (Counter mode, big-endian) -*/ -class BOTAN_DLL CTR_BE : public StreamCipher - { - public: - void cipher(const byte in[], byte out[], size_t length); - - void set_iv(const byte iv[], size_t iv_len); - - 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 - { return new CTR_BE(permutation->clone()); } - - void clear(); - - /** - * @param cipher the underlying block cipher to use - */ - CTR_BE(BlockCipher* cipher); - - CTR_BE(const CTR_BE&) = delete; - CTR_BE& operator=(const CTR_BE&) = delete; - - ~CTR_BE(); - private: - void key_schedule(const byte key[], size_t key_len); - void increment_counter(); - - BlockCipher* permutation; - secure_vector<byte> counter, buffer; - size_t position; - }; - -} - -#endif diff --git a/src/stream/ctr/info.txt b/src/stream/ctr/info.txt deleted file mode 100644 index 84d90a76f..000000000 --- a/src/stream/ctr/info.txt +++ /dev/null @@ -1,6 +0,0 @@ -define CTR_BE 20131128 - -<requires> -block -stream -</requires> |