diff options
Diffstat (limited to 'src/libs/3rdparty/botan/src/lib/stream')
-rw-r--r-- | src/libs/3rdparty/botan/src/lib/stream/ctr/ctr.cpp | 242 | ||||
-rw-r--r-- | src/libs/3rdparty/botan/src/lib/stream/ctr/ctr.h | 63 | ||||
-rw-r--r-- | src/libs/3rdparty/botan/src/lib/stream/ctr/info.txt | 7 | ||||
-rw-r--r-- | src/libs/3rdparty/botan/src/lib/stream/info.txt | 7 | ||||
-rw-r--r-- | src/libs/3rdparty/botan/src/lib/stream/stream_cipher.cpp | 149 | ||||
-rw-r--r-- | src/libs/3rdparty/botan/src/lib/stream/stream_cipher.h | 146 |
6 files changed, 0 insertions, 614 deletions
diff --git a/src/libs/3rdparty/botan/src/lib/stream/ctr/ctr.cpp b/src/libs/3rdparty/botan/src/lib/stream/ctr/ctr.cpp deleted file mode 100644 index 22cfade9b1..0000000000 --- a/src/libs/3rdparty/botan/src/lib/stream/ctr/ctr.cpp +++ /dev/null @@ -1,242 +0,0 @@ -/* -* Counter mode -* (C) 1999-2011,2014 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/ctr.h> -#include <botan/exceptn.h> -#include <botan/loadstor.h> - -namespace Botan { - -CTR_BE::CTR_BE(BlockCipher* ciph) : - m_cipher(ciph), - m_block_size(m_cipher->block_size()), - m_ctr_size(m_block_size), - m_ctr_blocks(m_cipher->parallel_bytes() / m_block_size), - m_counter(m_cipher->parallel_bytes()), - m_pad(m_counter.size()), - m_pad_pos(0) - { - } - -CTR_BE::CTR_BE(BlockCipher* cipher, size_t ctr_size) : - m_cipher(cipher), - m_block_size(m_cipher->block_size()), - m_ctr_size(ctr_size), - m_ctr_blocks(m_cipher->parallel_bytes() / m_block_size), - m_counter(m_cipher->parallel_bytes()), - m_pad(m_counter.size()), - m_pad_pos(0) - { - BOTAN_ARG_CHECK(m_ctr_size >= 4 && m_ctr_size <= m_block_size, - "Invalid CTR-BE counter size"); - } - -void CTR_BE::clear() - { - m_cipher->clear(); - zeroise(m_pad); - zeroise(m_counter); - zap(m_iv); - m_pad_pos = 0; - } - -size_t CTR_BE::default_iv_length() const - { - return m_block_size; - } - -bool CTR_BE::valid_iv_length(size_t iv_len) const - { - return (iv_len <= m_block_size); - } - -Key_Length_Specification CTR_BE::key_spec() const - { - return m_cipher->key_spec(); - } - -CTR_BE* CTR_BE::clone() const - { - return new CTR_BE(m_cipher->clone(), m_ctr_size); - } - -void CTR_BE::key_schedule(const uint8_t key[], size_t key_len) - { - m_cipher->set_key(key, key_len); - - // Set a default all-zeros IV - set_iv(nullptr, 0); - } - -std::string CTR_BE::name() const - { - if(m_ctr_size == m_block_size) - return ("CTR-BE(" + m_cipher->name() + ")"); - else - return ("CTR-BE(" + m_cipher->name() + "," + std::to_string(m_ctr_size) + ")"); - - } - -void CTR_BE::cipher(const uint8_t in[], uint8_t out[], size_t length) - { - verify_key_set(m_iv.empty() == false); - - const uint8_t* pad_bits = &m_pad[0]; - const size_t pad_size = m_pad.size(); - - if(m_pad_pos > 0) - { - const size_t avail = pad_size - m_pad_pos; - const size_t take = std::min(length, avail); - xor_buf(out, in, pad_bits + m_pad_pos, take); - length -= take; - in += take; - out += take; - m_pad_pos += take; - - if(take == avail) - { - add_counter(m_ctr_blocks); - m_cipher->encrypt_n(m_counter.data(), m_pad.data(), m_ctr_blocks); - m_pad_pos = 0; - } - } - - while(length >= pad_size) - { - xor_buf(out, in, pad_bits, pad_size); - length -= pad_size; - in += pad_size; - out += pad_size; - - add_counter(m_ctr_blocks); - m_cipher->encrypt_n(m_counter.data(), m_pad.data(), m_ctr_blocks); - } - - xor_buf(out, in, pad_bits, length); - m_pad_pos += length; - } - -void CTR_BE::set_iv(const uint8_t iv[], size_t iv_len) - { - if(!valid_iv_length(iv_len)) - throw Invalid_IV_Length(name(), iv_len); - - m_iv.resize(m_block_size); - zeroise(m_iv); - buffer_insert(m_iv, 0, iv, iv_len); - - seek(0); - } - -void CTR_BE::add_counter(const uint64_t counter) - { - const size_t ctr_size = m_ctr_size; - const size_t ctr_blocks = m_ctr_blocks; - const size_t BS = m_block_size; - - if(ctr_size == 4) - { - size_t off = (BS - 4); - uint32_t low32 = counter + load_be<uint32_t>(&m_counter[off], 0); - - for(size_t i = 0; i != ctr_blocks; ++i) - { - store_be(low32, &m_counter[off]); - off += BS; - low32 += 1; - } - } - else if(ctr_size == 8) - { - size_t off = (BS - 8); - uint64_t low64 = counter + load_be<uint64_t>(&m_counter[off], 0); - - for(size_t i = 0; i != ctr_blocks; ++i) - { - store_be(low64, &m_counter[off]); - off += BS; - low64 += 1; - } - } - else if(ctr_size == 16) - { - size_t off = (BS - 16); - uint64_t b0 = load_be<uint64_t>(&m_counter[off], 0); - uint64_t b1 = load_be<uint64_t>(&m_counter[off], 1); - b1 += counter; - b0 += (b1 < counter) ? 1 : 0; // carry - - for(size_t i = 0; i != ctr_blocks; ++i) - { - store_be(b0, &m_counter[off]); - store_be(b1, &m_counter[off+8]); - off += BS; - b1 += 1; - b0 += (b1 == 0); // carry - } - } - else - { - for(size_t i = 0; i != ctr_blocks; ++i) - { - uint64_t local_counter = counter; - uint16_t carry = static_cast<uint8_t>(local_counter); - for(size_t j = 0; (carry || local_counter) && j != ctr_size; ++j) - { - const size_t off = i*BS + (BS-1-j); - const uint16_t cnt = static_cast<uint16_t>(m_counter[off]) + carry; - m_counter[off] = static_cast<uint8_t>(cnt); - local_counter = (local_counter >> 8); - carry = (cnt >> 8) + static_cast<uint8_t>(local_counter); - } - } - } - } - -void CTR_BE::seek(uint64_t offset) - { - verify_key_set(m_iv.empty() == false); - - const uint64_t base_counter = m_ctr_blocks * (offset / m_counter.size()); - - zeroise(m_counter); - buffer_insert(m_counter, 0, m_iv); - - const size_t BS = m_block_size; - - // Set m_counter blocks to IV, IV + 1, ... IV + n - - if(m_ctr_size == 4 && BS >= 8) - { - const uint32_t low32 = load_be<uint32_t>(&m_counter[BS-4], 0); - for(size_t i = 1; i != m_ctr_blocks; ++i) - { - copy_mem(&m_counter[i*BS], &m_counter[0], BS); - uint32_t c = low32 + i; - store_be(c, &m_counter[(BS-4)+i*BS]); - } - } - else - { - for(size_t i = 1; i != m_ctr_blocks; ++i) - { - buffer_insert(m_counter, i*BS, &m_counter[(i-1)*BS], BS); - - for(size_t j = 0; j != m_ctr_size; ++j) - if(++m_counter[i*BS + (BS - 1 - j)]) - break; - } - } - - if(base_counter > 0) - add_counter(base_counter); - - m_cipher->encrypt_n(m_counter.data(), m_pad.data(), m_ctr_blocks); - m_pad_pos = offset % m_counter.size(); - } -} diff --git a/src/libs/3rdparty/botan/src/lib/stream/ctr/ctr.h b/src/libs/3rdparty/botan/src/lib/stream/ctr/ctr.h deleted file mode 100644 index 79911b2feb..0000000000 --- a/src/libs/3rdparty/botan/src/lib/stream/ctr/ctr.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -* CTR-BE Mode -* (C) 1999-2007 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#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_PUBLIC_API(2,0) CTR_BE final : public StreamCipher - { - public: - void cipher(const uint8_t in[], uint8_t out[], size_t length) override; - - void set_iv(const uint8_t iv[], size_t iv_len) override; - - size_t default_iv_length() const override; - - bool valid_iv_length(size_t iv_len) const override; - - Key_Length_Specification key_spec() const override; - - std::string name() const override; - - CTR_BE* clone() const override; - - void clear() override; - - /** - * @param cipher the block cipher to use - */ - explicit CTR_BE(BlockCipher* cipher); - - CTR_BE(BlockCipher* cipher, size_t ctr_size); - - void seek(uint64_t offset) override; - private: - void key_schedule(const uint8_t key[], size_t key_len) override; - void add_counter(const uint64_t counter); - - std::unique_ptr<BlockCipher> m_cipher; - - const size_t m_block_size; - const size_t m_ctr_size; - const size_t m_ctr_blocks; - - secure_vector<uint8_t> m_counter, m_pad; - std::vector<uint8_t> m_iv; - size_t m_pad_pos; - }; - -} - -#endif diff --git a/src/libs/3rdparty/botan/src/lib/stream/ctr/info.txt b/src/libs/3rdparty/botan/src/lib/stream/ctr/info.txt deleted file mode 100644 index 270ceecf8b..0000000000 --- a/src/libs/3rdparty/botan/src/lib/stream/ctr/info.txt +++ /dev/null @@ -1,7 +0,0 @@ -<defines> -CTR_BE -> 20131128 -</defines> - -<requires> -block -</requires> diff --git a/src/libs/3rdparty/botan/src/lib/stream/info.txt b/src/libs/3rdparty/botan/src/lib/stream/info.txt deleted file mode 100644 index 4f62c5a7c1..0000000000 --- a/src/libs/3rdparty/botan/src/lib/stream/info.txt +++ /dev/null @@ -1,7 +0,0 @@ -<defines> -STREAM_CIPHER -> 20131128 -</defines> - -<header:public> -stream_cipher.h -</header:public> diff --git a/src/libs/3rdparty/botan/src/lib/stream/stream_cipher.cpp b/src/libs/3rdparty/botan/src/lib/stream/stream_cipher.cpp deleted file mode 100644 index 692464723c..0000000000 --- a/src/libs/3rdparty/botan/src/lib/stream/stream_cipher.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* -* Stream Ciphers -* (C) 2015,2016 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/stream_cipher.h> -#include <botan/scan_name.h> -#include <botan/exceptn.h> - -#if defined(BOTAN_HAS_CHACHA) - #include <botan/chacha.h> -#endif - -#if defined(BOTAN_HAS_SALSA20) - #include <botan/salsa20.h> -#endif - -#if defined(BOTAN_HAS_SHAKE_CIPHER) - #include <botan/shake_cipher.h> -#endif - -#if defined(BOTAN_HAS_CTR_BE) - #include <botan/ctr.h> -#endif - -#if defined(BOTAN_HAS_OFB) - #include <botan/ofb.h> -#endif - -#if defined(BOTAN_HAS_RC4) - #include <botan/rc4.h> -#endif - -#if defined(BOTAN_HAS_OPENSSL) - #include <botan/internal/openssl.h> -#endif - -namespace Botan { - -std::unique_ptr<StreamCipher> StreamCipher::create(const std::string& algo_spec, - const std::string& provider) - { - const SCAN_Name req(algo_spec); - -#if defined(BOTAN_HAS_CTR_BE) - if((req.algo_name() == "CTR-BE" || req.algo_name() == "CTR") && req.arg_count_between(1,2)) - { - if(provider.empty() || provider == "base") - { - auto cipher = BlockCipher::create(req.arg(0)); - if(cipher) - { - size_t ctr_size = req.arg_as_integer(1, cipher->block_size()); - return std::unique_ptr<StreamCipher>(new CTR_BE(cipher.release(), ctr_size)); - } - } - } -#endif - -#if defined(BOTAN_HAS_CHACHA) - if(req.algo_name() == "ChaCha") - { - if(provider.empty() || provider == "base") - return std::unique_ptr<StreamCipher>(new ChaCha(req.arg_as_integer(0, 20))); - } - - if(req.algo_name() == "ChaCha20") - { - if(provider.empty() || provider == "base") - return std::unique_ptr<StreamCipher>(new ChaCha(20)); - } -#endif - -#if defined(BOTAN_HAS_SALSA20) - if(req.algo_name() == "Salsa20") - { - if(provider.empty() || provider == "base") - return std::unique_ptr<StreamCipher>(new Salsa20); - } -#endif - -#if defined(BOTAN_HAS_SHAKE_CIPHER) - if(req.algo_name() == "SHAKE-128") - { - if(provider.empty() || provider == "base") - return std::unique_ptr<StreamCipher>(new SHAKE_128_Cipher); - } -#endif - -#if defined(BOTAN_HAS_OFB) - if(req.algo_name() == "OFB" && req.arg_count() == 1) - { - if(provider.empty() || provider == "base") - { - if(auto c = BlockCipher::create(req.arg(0))) - return std::unique_ptr<StreamCipher>(new OFB(c.release())); - } - } -#endif - -#if defined(BOTAN_HAS_RC4) - - if(req.algo_name() == "RC4" || - req.algo_name() == "ARC4" || - req.algo_name() == "MARK-4") - { - const size_t skip = (req.algo_name() == "MARK-4") ? 256 : req.arg_as_integer(0, 0); - -#if defined(BOTAN_HAS_OPENSSL) - if(provider.empty() || provider == "openssl") - { - return std::unique_ptr<StreamCipher>(make_openssl_rc4(skip)); - } -#endif - - if(provider.empty() || provider == "base") - { - return std::unique_ptr<StreamCipher>(new RC4(skip)); - } - } - -#endif - - BOTAN_UNUSED(req); - BOTAN_UNUSED(provider); - - return nullptr; - } - -//static -std::unique_ptr<StreamCipher> -StreamCipher::create_or_throw(const std::string& algo, - const std::string& provider) - { - if(auto sc = StreamCipher::create(algo, provider)) - { - return sc; - } - throw Lookup_Error("Stream cipher", algo, provider); - } - -std::vector<std::string> StreamCipher::providers(const std::string& algo_spec) - { - return probe_providers_of<StreamCipher>(algo_spec, {"base", "openssl"}); - } - -} diff --git a/src/libs/3rdparty/botan/src/lib/stream/stream_cipher.h b/src/libs/3rdparty/botan/src/lib/stream/stream_cipher.h deleted file mode 100644 index 25bbc3287b..0000000000 --- a/src/libs/3rdparty/botan/src/lib/stream/stream_cipher.h +++ /dev/null @@ -1,146 +0,0 @@ -/* -* Stream Cipher -* (C) 1999-2007 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_STREAM_CIPHER_H_ -#define BOTAN_STREAM_CIPHER_H_ - -#include <botan/sym_algo.h> -#include <string> -#include <memory> - -namespace Botan { - -/** -* Base class for all stream ciphers -*/ -class BOTAN_PUBLIC_API(2,0) StreamCipher : public SymmetricAlgorithm - { - public: - virtual ~StreamCipher() = default; - - /** - * Create an instance based on a name - * If provider is empty then best available is chosen. - * @param algo_spec algorithm name - * @param provider provider implementation to use - * @return a null pointer if the algo/provider combination cannot be found - */ - static std::unique_ptr<StreamCipher> - create(const std::string& algo_spec, - const std::string& provider = ""); - - /** - * Create an instance based on a name - * If provider is empty then best available is chosen. - * @param algo_spec algorithm name - * @param provider provider implementation to use - * Throws a Lookup_Error if the algo/provider combination cannot be found - */ - static std::unique_ptr<StreamCipher> - create_or_throw(const std::string& algo_spec, - const std::string& provider = ""); - - /** - * @return list of available providers for this algorithm, empty if not available - */ - static std::vector<std::string> providers(const std::string& algo_spec); - - /** - * Encrypt or decrypt a message - * @param in the plaintext - * @param out the byte array to hold the output, i.e. the ciphertext - * @param len the length of both in and out in bytes - */ - virtual void cipher(const uint8_t in[], uint8_t out[], size_t len) = 0; - - /** - * Write keystream bytes to a buffer - * @param out the byte array to hold the keystream - * @param len the length of out in bytes - */ - virtual void write_keystream(uint8_t out[], size_t len) - { - clear_mem(out, len); - cipher1(out, len); - } - - /** - * Encrypt or decrypt a message - * The message is encrypted/decrypted in place. - * @param buf the plaintext / ciphertext - * @param len the length of buf in bytes - */ - void cipher1(uint8_t buf[], size_t len) - { cipher(buf, buf, len); } - - /** - * Encrypt a message - * The message is encrypted/decrypted in place. - * @param inout the plaintext / ciphertext - */ - template<typename Alloc> - void encipher(std::vector<uint8_t, Alloc>& inout) - { cipher(inout.data(), inout.data(), inout.size()); } - - /** - * Encrypt a message - * The message is encrypted in place. - * @param inout the plaintext / ciphertext - */ - template<typename Alloc> - void encrypt(std::vector<uint8_t, Alloc>& inout) - { cipher(inout.data(), inout.data(), inout.size()); } - - /** - * Decrypt a message in place - * The message is decrypted in place. - * @param inout the plaintext / ciphertext - */ - template<typename Alloc> - void decrypt(std::vector<uint8_t, Alloc>& inout) - { cipher(inout.data(), inout.data(), inout.size()); } - - /** - * Resync the cipher using the IV - * @param iv the initialization vector - * @param iv_len the length of the IV in bytes - */ - virtual void set_iv(const uint8_t iv[], size_t iv_len) = 0; - - /** - * Return the default (preferred) nonce length - * If this function returns 0, then this cipher does not support nonces - */ - virtual size_t default_iv_length() const { return 0; } - - /** - * @param iv_len the length of the IV in bytes - * @return if the length is valid for this algorithm - */ - virtual bool valid_iv_length(size_t iv_len) const { return (iv_len == 0); } - - /** - * @return a new object representing the same algorithm as *this - */ - virtual StreamCipher* clone() const = 0; - - /** - * Set the offset and the state used later to generate the keystream - * @param offset the offset where we begin to generate the keystream - */ - virtual void seek(uint64_t offset) = 0; - - /** - * @return provider information about this implementation. Default is "base", - * might also return "sse2", "avx2", "openssl", or some other arbitrary string. - */ - virtual std::string provider() const { return "base"; } - }; - -} - -#endif |