aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-08-08 13:12:50 -0400
committerJack Lloyd <[email protected]>2018-08-08 13:12:50 -0400
commit5111c4c3aa0b51efb85284c2b3e6e664101dbc94 (patch)
tree659d8748c25b56f3b954071948fc42ea5ad86faf /src
parent9eb10b06036840822c03aec900a1e64f90e77181 (diff)
De-inline functions from stream cipher headers
Diffstat (limited to 'src')
-rw-r--r--src/lib/stream/chacha/chacha.cpp15
-rw-r--r--src/lib/stream/chacha/chacha.h11
-rw-r--r--src/lib/stream/ctr/ctr.cpp22
-rw-r--r--src/lib/stream/ctr/ctr.h13
-rw-r--r--src/lib/stream/ofb/ofb.cpp20
-rw-r--r--src/lib/stream/ofb/ofb.h13
-rw-r--r--src/lib/stream/rc4/rc4.cpp10
-rw-r--r--src/lib/stream/rc4/rc4.h7
-rw-r--r--src/lib/stream/salsa20/salsa20.cpp23
-rw-r--r--src/lib/stream/salsa20/salsa20.h12
-rw-r--r--src/lib/stream/shake_cipher/shake_cipher.cpp20
-rw-r--r--src/lib/stream/shake_cipher/shake_cipher.h13
12 files changed, 127 insertions, 52 deletions
diff --git a/src/lib/stream/chacha/chacha.cpp b/src/lib/stream/chacha/chacha.cpp
index fac9a5a36..d2d31a12e 100644
--- a/src/lib/stream/chacha/chacha.cpp
+++ b/src/lib/stream/chacha/chacha.cpp
@@ -233,6 +233,21 @@ void ChaCha::key_schedule(const uint8_t key[], size_t length)
set_iv(nullptr, 0);
}
+size_t ChaCha::default_iv_length() const
+ {
+ return 24;
+ }
+
+Key_Length_Specification ChaCha::key_spec() const
+ {
+ return Key_Length_Specification(16, 32, 16);
+ }
+
+StreamCipher* ChaCha::clone() const
+ {
+ return new ChaCha(m_rounds);
+ }
+
bool ChaCha::valid_iv_length(size_t iv_len) const
{
return (iv_len == 0 || iv_len == 8 || iv_len == 12 || iv_len == 24);
diff --git a/src/lib/stream/chacha/chacha.h b/src/lib/stream/chacha/chacha.h
index d0e131315..e41fd927f 100644
--- a/src/lib/stream/chacha/chacha.h
+++ b/src/lib/stream/chacha/chacha.h
@@ -18,8 +18,6 @@ namespace Botan {
class BOTAN_PUBLIC_API(2,0) ChaCha final : public StreamCipher
{
public:
- StreamCipher* clone() const override { return new ChaCha(m_rounds); }
-
/**
* @param rounds number of rounds
* @note Currently only 8, 12 or 20 rounds are supported, all others
@@ -41,15 +39,14 @@ class BOTAN_PUBLIC_API(2,0) ChaCha final : public StreamCipher
*/
bool valid_iv_length(size_t iv_len) const override;
- size_t default_iv_length() const override { return 24; }
+ size_t default_iv_length() const override;
- Key_Length_Specification key_spec() const override
- {
- return Key_Length_Specification(16, 32, 16);
- }
+ Key_Length_Specification key_spec() const override;
void clear() override;
+ StreamCipher* clone() const override;
+
std::string name() const override;
void seek(uint64_t offset) override;
diff --git a/src/lib/stream/ctr/ctr.cpp b/src/lib/stream/ctr/ctr.cpp
index 261646344..6a7d81729 100644
--- a/src/lib/stream/ctr/ctr.cpp
+++ b/src/lib/stream/ctr/ctr.cpp
@@ -44,6 +44,26 @@ void CTR_BE::clear()
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);
@@ -106,7 +126,7 @@ 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_cipher->block_size());
+ m_iv.resize(m_block_size);
zeroise(m_iv);
buffer_insert(m_iv, 0, iv, iv_len);
diff --git a/src/lib/stream/ctr/ctr.h b/src/lib/stream/ctr/ctr.h
index 3e0208363..79911b2fe 100644
--- a/src/lib/stream/ctr/ctr.h
+++ b/src/lib/stream/ctr/ctr.h
@@ -23,20 +23,15 @@ class BOTAN_PUBLIC_API(2,0) CTR_BE final : public StreamCipher
void set_iv(const uint8_t iv[], size_t iv_len) override;
- size_t default_iv_length() const override { return m_cipher->block_size(); }
+ size_t default_iv_length() const override;
- bool valid_iv_length(size_t iv_len) const override
- { return (iv_len <= m_cipher->block_size()); }
+ bool valid_iv_length(size_t iv_len) const override;
- Key_Length_Specification key_spec() const override
- {
- return m_cipher->key_spec();
- }
+ Key_Length_Specification key_spec() const override;
std::string name() const override;
- CTR_BE* clone() const override
- { return new CTR_BE(m_cipher->clone(), m_ctr_size); }
+ CTR_BE* clone() const override;
void clear() override;
diff --git a/src/lib/stream/ofb/ofb.cpp b/src/lib/stream/ofb/ofb.cpp
index ca3971dc2..dde468117 100644
--- a/src/lib/stream/ofb/ofb.cpp
+++ b/src/lib/stream/ofb/ofb.cpp
@@ -37,6 +37,26 @@ std::string OFB::name() const
return "OFB(" + m_cipher->name() + ")";
}
+size_t OFB::default_iv_length() const
+ {
+ return m_cipher->block_size();
+ }
+
+bool OFB::valid_iv_length(size_t iv_len) const
+ {
+ return (iv_len <= m_cipher->block_size());
+ }
+
+Key_Length_Specification OFB::key_spec() const
+ {
+ return m_cipher->key_spec();
+ }
+
+OFB* OFB::clone() const
+ {
+ return new OFB(m_cipher->clone());
+ }
+
void OFB::cipher(const uint8_t in[], uint8_t out[], size_t length)
{
while(length >= m_buffer.size() - m_buf_pos)
diff --git a/src/lib/stream/ofb/ofb.h b/src/lib/stream/ofb/ofb.h
index afba43753..1e9866c64 100644
--- a/src/lib/stream/ofb/ofb.h
+++ b/src/lib/stream/ofb/ofb.h
@@ -23,20 +23,15 @@ class BOTAN_PUBLIC_API(2,0) OFB final : public StreamCipher
void set_iv(const uint8_t iv[], size_t iv_len) override;
- size_t default_iv_length() const override { return m_cipher->block_size(); }
+ size_t default_iv_length() const override;
- bool valid_iv_length(size_t iv_len) const override
- { return (iv_len <= m_cipher->block_size()); }
+ bool valid_iv_length(size_t iv_len) const override;
- Key_Length_Specification key_spec() const override
- {
- return m_cipher->key_spec();
- }
+ Key_Length_Specification key_spec() const override;
std::string name() const override;
- OFB* clone() const override
- { return new OFB(m_cipher->clone()); }
+ OFB* clone() const override;
void clear() override;
diff --git a/src/lib/stream/rc4/rc4.cpp b/src/lib/stream/rc4/rc4.cpp
index 9f0a44d6e..e427c0288 100644
--- a/src/lib/stream/rc4/rc4.cpp
+++ b/src/lib/stream/rc4/rc4.cpp
@@ -29,6 +29,16 @@ void RC4::cipher(const uint8_t in[], uint8_t out[], size_t length)
m_position += length;
}
+StreamCipher* RC4::clone() const
+ {
+ return new RC4(m_SKIP);
+ }
+
+Key_Length_Specification RC4::key_spec() const
+ {
+ return Key_Length_Specification(1, 256);
+ }
+
void RC4::set_iv(const uint8_t*, size_t length)
{
if(length > 0)
diff --git a/src/lib/stream/rc4/rc4.h b/src/lib/stream/rc4/rc4.h
index 796e8d9f9..d59ce01f0 100644
--- a/src/lib/stream/rc4/rc4.h
+++ b/src/lib/stream/rc4/rc4.h
@@ -26,12 +26,9 @@ class BOTAN_PUBLIC_API(2,0) RC4 final : public StreamCipher
void clear() override;
std::string name() const override;
- StreamCipher* clone() const override { return new RC4(m_SKIP); }
+ StreamCipher* clone() const override;
- Key_Length_Specification key_spec() const override
- {
- return Key_Length_Specification(1, 256);
- }
+ Key_Length_Specification key_spec() const override;
/**
* @param skip skip this many initial bytes in the keystream
diff --git a/src/lib/stream/salsa20/salsa20.cpp b/src/lib/stream/salsa20/salsa20.cpp
index ff24995ee..cc1d80568 100644
--- a/src/lib/stream/salsa20/salsa20.cpp
+++ b/src/lib/stream/salsa20/salsa20.cpp
@@ -243,9 +243,26 @@ void Salsa20::set_iv(const uint8_t iv[], size_t length)
m_position = 0;
}
-/*
-* Return the name of this type
-*/
+bool Salsa20::valid_iv_length(size_t iv_len) const
+ {
+ return (iv_len == 0 || iv_len == 8 || iv_len == 24);
+ }
+
+size_t Salsa20::default_iv_length() const
+ {
+ return 24;
+ }
+
+Key_Length_Specification Salsa20::key_spec() const
+ {
+ return Key_Length_Specification(16, 32, 16);
+ }
+
+StreamCipher* Salsa20::clone() const
+ {
+ return new Salsa20;
+ }
+
std::string Salsa20::name() const
{
return "Salsa20";
diff --git a/src/lib/stream/salsa20/salsa20.h b/src/lib/stream/salsa20/salsa20.h
index ea193273c..60143f8e0 100644
--- a/src/lib/stream/salsa20/salsa20.h
+++ b/src/lib/stream/salsa20/salsa20.h
@@ -22,19 +22,15 @@ class BOTAN_PUBLIC_API(2,0) Salsa20 final : public StreamCipher
void set_iv(const uint8_t iv[], size_t iv_len) override;
- bool valid_iv_length(size_t iv_len) const override
- { return (iv_len == 0 || iv_len == 8 || iv_len == 24); }
+ bool valid_iv_length(size_t iv_len) const override;
- size_t default_iv_length() const override { return 24; }
+ size_t default_iv_length() const override;
- Key_Length_Specification key_spec() const override
- {
- return Key_Length_Specification(16, 32, 16);
- }
+ Key_Length_Specification key_spec() const override;
void clear() override;
std::string name() const override;
- StreamCipher* clone() const override { return new Salsa20; }
+ StreamCipher* clone() const override;
static void salsa_core(uint8_t output[64], const uint32_t input[16], size_t rounds);
diff --git a/src/lib/stream/shake_cipher/shake_cipher.cpp b/src/lib/stream/shake_cipher/shake_cipher.cpp
index f6cac8354..b0e08a700 100644
--- a/src/lib/stream/shake_cipher/shake_cipher.cpp
+++ b/src/lib/stream/shake_cipher/shake_cipher.cpp
@@ -75,4 +75,24 @@ void SHAKE_128_Cipher::seek(uint64_t)
{
throw Not_Implemented("SHAKE_128_Cipher::seek");
}
+
+Key_Length_Specification SHAKE_128_Cipher::key_spec() const
+ {
+ /*
+ In principle SHAKE can accept arbitrary length inputs, but this
+ does not seem required for a stream cipher.
+ */
+ return Key_Length_Specification(16, 160, 8);
+ }
+
+std::string SHAKE_128_Cipher::name() const
+ {
+ return "SHAKE-128";
+ }
+
+StreamCipher* SHAKE_128_Cipher::clone() const
+ {
+ return new SHAKE_128_Cipher;
+ }
+
}
diff --git a/src/lib/stream/shake_cipher/shake_cipher.h b/src/lib/stream/shake_cipher/shake_cipher.h
index 344ac965b..492341a7c 100644
--- a/src/lib/stream/shake_cipher/shake_cipher.h
+++ b/src/lib/stream/shake_cipher/shake_cipher.h
@@ -36,18 +36,11 @@ class BOTAN_PUBLIC_API(2,0) SHAKE_128_Cipher final : public StreamCipher
*/
void set_iv(const uint8_t iv[], size_t iv_len) override;
- /**
- * In principle SHAKE can accept arbitrary length inputs, but this
- * does not seem required for a stream cipher.
- */
- Key_Length_Specification key_spec() const override
- {
- return Key_Length_Specification(16, 160, 8);
- }
+ Key_Length_Specification key_spec() const override;
void clear() override;
- std::string name() const override { return "SHAKE-128"; }
- StreamCipher* clone() const override { return new SHAKE_128_Cipher; }
+ std::string name() const override;
+ StreamCipher* clone() const override;
private:
void key_schedule(const uint8_t key[], size_t key_len) override;