aboutsummaryrefslogtreecommitdiffstats
path: root/src/stream
diff options
context:
space:
mode:
Diffstat (limited to 'src/stream')
-rw-r--r--src/stream/arc4/arc4.cpp2
-rw-r--r--src/stream/arc4/arc4.h7
-rw-r--r--src/stream/arc4/info.txt2
-rw-r--r--src/stream/ctr/ctr.cpp141
-rw-r--r--src/stream/ctr/ctr.h49
-rw-r--r--src/stream/ctr/info.txt13
-rw-r--r--src/stream/info.txt3
-rw-r--r--src/stream/ofb/info.txt13
-rw-r--r--src/stream/ofb/ofb.cpp97
-rw-r--r--src/stream/ofb/ofb.h48
-rw-r--r--src/stream/salsa20/info.txt2
-rw-r--r--src/stream/salsa20/salsa20.cpp12
-rw-r--r--src/stream/salsa20/salsa20.h14
-rw-r--r--src/stream/stream_cipher.cpp30
-rw-r--r--src/stream/stream_cipher.h69
-rw-r--r--src/stream/turing/info.txt2
-rw-r--r--src/stream/turing/turing.cpp56
-rw-r--r--src/stream/turing/turing.h12
-rw-r--r--src/stream/wid_wake/info.txt2
-rw-r--r--src/stream/wid_wake/wid_wake.cpp11
-rw-r--r--src/stream/wid_wake/wid_wake.h12
21 files changed, 459 insertions, 138 deletions
diff --git a/src/stream/arc4/arc4.cpp b/src/stream/arc4/arc4.cpp
index 0f78f7362..293a0a336 100644
--- a/src/stream/arc4/arc4.cpp
+++ b/src/stream/arc4/arc4.cpp
@@ -87,7 +87,7 @@ std::string ARC4::name() const
/*
* Clear memory of sensitive data
*/
-void ARC4::clear() throw()
+void ARC4::clear()
{
state.clear();
buffer.clear();
diff --git a/src/stream/arc4/arc4.h b/src/stream/arc4/arc4.h
index aa2cea7fe..ae37cb165 100644
--- a/src/stream/arc4/arc4.h
+++ b/src/stream/arc4/arc4.h
@@ -19,13 +19,16 @@ namespace Botan {
class BOTAN_DLL ARC4 : public StreamCipher
{
public:
- void clear() throw();
+ void cipher(const byte in[], byte out[], u32bit length);
+
+ void clear();
std::string name() const;
+
StreamCipher* clone() const { return new ARC4(SKIP); }
+
ARC4(u32bit = 0);
~ARC4() { clear(); }
private:
- void cipher(const byte[], byte[], u32bit);
void key_schedule(const byte[], u32bit);
void generate();
diff --git a/src/stream/arc4/info.txt b/src/stream/arc4/info.txt
index e4689cf69..bb373dbc5 100644
--- a/src/stream/arc4/info.txt
+++ b/src/stream/arc4/info.txt
@@ -1,5 +1,3 @@
-realname "ARC4"
-
define ARC4
load_on auto
diff --git a/src/stream/ctr/ctr.cpp b/src/stream/ctr/ctr.cpp
new file mode 100644
index 000000000..5f0880fa5
--- /dev/null
+++ b/src/stream/ctr/ctr.cpp
@@ -0,0 +1,141 @@
+/*
+* CTR-BE Mode Cipher
+* (C) 1999-2009 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/ctr.h>
+#include <botan/xor_buf.h>
+
+namespace Botan {
+
+/*
+* CTR-BE Constructor
+*/
+
+CTR_BE::CTR_BE(BlockCipher* ciph) :
+ StreamCipher(ciph->MINIMUM_KEYLENGTH,
+ ciph->MAXIMUM_KEYLENGTH,
+ ciph->KEYLENGTH_MULTIPLE),
+ permutation(ciph)
+ {
+ position = 0;
+
+ counter.create(permutation->BLOCK_SIZE * BOTAN_PARALLEL_BLOCKS_CTR);
+ buffer.create(permutation->BLOCK_SIZE * BOTAN_PARALLEL_BLOCKS_CTR);
+ }
+
+/*
+* CTR_BE Destructor
+*/
+CTR_BE::~CTR_BE()
+ {
+ delete permutation;
+ }
+
+/*
+* Zeroize
+*/
+void CTR_BE::clear()
+ {
+ permutation->clear();
+ buffer.clear();
+ counter.clear();
+ position = 0;
+ }
+
+/*
+* Set the key
+*/
+void CTR_BE::key_schedule(const byte key[], u32bit key_len)
+ {
+ permutation->set_key(key, key_len);
+
+ // Set a default all-zeros IV
+ set_iv(0, 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[], u32bit length)
+ {
+ while(length >= buffer.size() - position)
+ {
+ xor_buf(out, in, buffer.begin() + position, buffer.size() - position);
+ length -= (buffer.size() - position);
+ in += (buffer.size() - position);
+ out += (buffer.size() - position);
+ increment_counter();
+ }
+ xor_buf(out, in, buffer.begin() + position, length);
+ position += length;
+ }
+
+/*
+* Set CTR-BE IV
+*/
+void CTR_BE::set_iv(const byte iv[], u32bit iv_len)
+ {
+ if(!valid_iv_length(iv_len))
+ throw Invalid_IV_Length(name(), iv_len);
+
+ const u32bit BLOCK_SIZE = permutation->BLOCK_SIZE;
+
+ counter.clear();
+
+ counter.copy(0, iv, iv_len);
+
+ const u32bit PARALLEL_BLOCKS = counter.size() / BLOCK_SIZE;
+
+ for(u32bit i = 1; i != PARALLEL_BLOCKS; ++i)
+ {
+ counter.copy(i*BLOCK_SIZE,
+ counter.begin() + (i-1)*BLOCK_SIZE, BLOCK_SIZE);
+
+ for(s32bit j = BLOCK_SIZE - 1; j >= 0; --j)
+ if(++counter[i*BLOCK_SIZE+j])
+ break;
+ }
+
+ permutation->encrypt_n(counter, buffer, PARALLEL_BLOCKS);
+ position = 0;
+ }
+
+/*
+* Increment the counter and update the buffer
+*/
+void CTR_BE::increment_counter()
+ {
+ const u32bit PARALLEL_BLOCKS = counter.size() / permutation->BLOCK_SIZE;
+
+ for(u32bit i = 0; i != PARALLEL_BLOCKS; ++i)
+ {
+ byte* this_ctr = counter + i*permutation->BLOCK_SIZE;
+
+ byte last_byte = this_ctr[permutation->BLOCK_SIZE-1];
+ last_byte += PARALLEL_BLOCKS;
+
+ if(this_ctr[permutation->BLOCK_SIZE-1] > last_byte)
+ for(s32bit j = permutation->BLOCK_SIZE - 2; j >= 0; --j)
+ if(++this_ctr[j])
+ break;
+
+ this_ctr[permutation->BLOCK_SIZE-1] = last_byte;
+ }
+
+ permutation->encrypt_n(counter, buffer, PARALLEL_BLOCKS);
+
+ position = 0;
+ }
+
+}
diff --git a/src/stream/ctr/ctr.h b/src/stream/ctr/ctr.h
new file mode 100644
index 000000000..5f94170cc
--- /dev/null
+++ b/src/stream/ctr/ctr.h
@@ -0,0 +1,49 @@
+/*
+* 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, big-endian)
+*/
+class BOTAN_DLL CTR_BE : public StreamCipher
+ {
+ public:
+ void cipher(const byte in[], byte out[], u32bit length);
+
+ void set_iv(const byte iv[], u32bit iv_len);
+
+ bool valid_iv_length(u32bit iv_len) const
+ { return (iv_len <= permutation->BLOCK_SIZE); }
+
+ std::string name() const;
+
+ CTR_BE* clone() const
+ { return new CTR_BE(permutation->clone()); }
+
+ void clear();
+
+ CTR_BE(BlockCipher*);
+ ~CTR_BE();
+ private:
+ void key_schedule(const byte key[], u32bit key_len);
+ void increment_counter();
+
+ BlockCipher* permutation;
+ SecureVector<byte> counter, buffer;
+ u32bit position;
+ };
+
+}
+
+#endif
diff --git a/src/stream/ctr/info.txt b/src/stream/ctr/info.txt
new file mode 100644
index 000000000..ac4f3f710
--- /dev/null
+++ b/src/stream/ctr/info.txt
@@ -0,0 +1,13 @@
+define CTR_BE
+
+load_on auto
+
+<add>
+ctr.cpp
+ctr.h
+</add>
+
+<requires>
+block
+stream
+</requires>
diff --git a/src/stream/info.txt b/src/stream/info.txt
index 295c73708..213c42137 100644
--- a/src/stream/info.txt
+++ b/src/stream/info.txt
@@ -1,12 +1,9 @@
-realname "Stream Ciphers"
-
load_on auto
define STREAM_CIPHER
<add>
stream_cipher.h
-stream_cipher.cpp
</add>
<requires>
diff --git a/src/stream/ofb/info.txt b/src/stream/ofb/info.txt
new file mode 100644
index 000000000..a01e9e1a6
--- /dev/null
+++ b/src/stream/ofb/info.txt
@@ -0,0 +1,13 @@
+define OFB
+
+load_on auto
+
+<add>
+ofb.cpp
+ofb.h
+</add>
+
+<requires>
+block
+stream
+</requires>
diff --git a/src/stream/ofb/ofb.cpp b/src/stream/ofb/ofb.cpp
new file mode 100644
index 000000000..0d12d23bd
--- /dev/null
+++ b/src/stream/ofb/ofb.cpp
@@ -0,0 +1,97 @@
+/*
+* OFB Mode
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/ofb.h>
+#include <botan/xor_buf.h>
+#include <algorithm>
+
+namespace Botan {
+
+/*
+* OFB Constructor
+*/
+OFB::OFB(BlockCipher* ciph) :
+ StreamCipher(ciph->MINIMUM_KEYLENGTH,
+ ciph->MAXIMUM_KEYLENGTH,
+ ciph->KEYLENGTH_MULTIPLE),
+ permutation(ciph)
+ {
+ position = 0;
+ buffer.create(permutation->BLOCK_SIZE);
+ }
+
+/*
+* OFB Destructor
+*/
+OFB::~OFB()
+ {
+ delete permutation;
+ }
+
+/*
+* Zeroize
+*/
+void OFB::clear()
+ {
+ permutation->clear();
+ buffer.clear();
+ position = 0;
+ }
+
+/*
+* Set the key
+*/
+void OFB::key_schedule(const byte key[], u32bit key_len)
+ {
+ permutation->set_key(key, key_len);
+
+ // Set a default all-zeros IV
+ set_iv(0, 0);
+ }
+
+/*
+* Return the name of this type
+*/
+std::string OFB::name() const
+ {
+ return ("OFB(" + permutation->name() + ")");
+ }
+
+/*
+* CTR-BE Encryption/Decryption
+*/
+void OFB::cipher(const byte in[], byte out[], u32bit length)
+ {
+ while(length >= buffer.size() - position)
+ {
+ xor_buf(out, in, buffer.begin() + position, buffer.size() - position);
+ length -= (buffer.size() - position);
+ in += (buffer.size() - position);
+ out += (buffer.size() - position);
+ permutation->encrypt(buffer);
+ position = 0;
+ }
+ xor_buf(out, in, buffer.begin() + position, length);
+ position += length;
+ }
+
+/*
+* Set CTR-BE IV
+*/
+void OFB::set_iv(const byte iv[], u32bit iv_len)
+ {
+ if(!valid_iv_length(iv_len))
+ throw Invalid_IV_Length(name(), iv_len);
+
+ buffer.clear();
+ buffer.copy(0, iv, iv_len);
+
+ permutation->encrypt(buffer);
+ position = 0;
+ }
+
+}
diff --git a/src/stream/ofb/ofb.h b/src/stream/ofb/ofb.h
new file mode 100644
index 000000000..1985ae5a9
--- /dev/null
+++ b/src/stream/ofb/ofb.h
@@ -0,0 +1,48 @@
+/*
+* OFB Mode
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_OUTPUT_FEEDBACK_MODE_H__
+#define BOTAN_OUTPUT_FEEDBACK_MODE_H__
+
+#include <botan/stream_cipher.h>
+#include <botan/block_cipher.h>
+
+namespace Botan {
+
+/*
+* OFB Mode
+*/
+class BOTAN_DLL OFB : public StreamCipher
+ {
+ public:
+ void cipher(const byte in[], byte out[], u32bit length);
+
+ void set_iv(const byte iv[], u32bit iv_len);
+
+ bool valid_iv_length(u32bit iv_len) const
+ { return (iv_len <= permutation->BLOCK_SIZE); }
+
+ std::string name() const;
+
+ OFB* clone() const
+ { return new OFB(permutation->clone()); }
+
+ void clear();
+
+ OFB(BlockCipher*);
+ ~OFB();
+ private:
+ void key_schedule(const byte key[], u32bit key_len);
+
+ BlockCipher* permutation;
+ SecureVector<byte> buffer;
+ u32bit position;
+ };
+
+}
+
+#endif
diff --git a/src/stream/salsa20/info.txt b/src/stream/salsa20/info.txt
index db938307b..8171708b0 100644
--- a/src/stream/salsa20/info.txt
+++ b/src/stream/salsa20/info.txt
@@ -1,5 +1,3 @@
-realname "Salsa20"
-
define SALSA20
load_on auto
diff --git a/src/stream/salsa20/salsa20.cpp b/src/stream/salsa20/salsa20.cpp
index 75137798c..3aae64eae 100644
--- a/src/stream/salsa20/salsa20.cpp
+++ b/src/stream/salsa20/salsa20.cpp
@@ -6,10 +6,8 @@
*/
#include <botan/salsa20.h>
-#include <botan/mem_ops.h>
#include <botan/xor_buf.h>
#include <botan/loadstor.h>
-#include <botan/parsing.h>
namespace Botan {
@@ -164,15 +162,15 @@ void Salsa20::key_schedule(const byte key[], u32bit length)
}
const byte ZERO[8] = { 0 };
- resync(ZERO, sizeof(ZERO));
+ set_iv(ZERO, sizeof(ZERO));
}
/*
* Return the name of this type
*/
-void Salsa20::resync(const byte iv[], u32bit length)
+void Salsa20::set_iv(const byte iv[], u32bit length)
{
- if(length != IV_LENGTH)
+ if(!valid_iv_length(length))
throw Invalid_IV_Length(name(), length);
state[6] = load_le<u32bit>(iv, 0);
@@ -199,7 +197,7 @@ std::string Salsa20::name() const
/*
* Clear memory of sensitive data
*/
-void Salsa20::clear() throw()
+void Salsa20::clear()
{
state.clear();
buffer.clear();
@@ -209,7 +207,7 @@ void Salsa20::clear() throw()
/*
* Salsa20 Constructor
*/
-Salsa20::Salsa20() : StreamCipher(16, 32, 16, 8)
+Salsa20::Salsa20() : StreamCipher(16, 32, 16)
{
clear();
}
diff --git a/src/stream/salsa20/salsa20.h b/src/stream/salsa20/salsa20.h
index 3dbfddb50..3ca781ea2 100644
--- a/src/stream/salsa20/salsa20.h
+++ b/src/stream/salsa20/salsa20.h
@@ -18,17 +18,21 @@ namespace Botan {
class BOTAN_DLL Salsa20 : public StreamCipher
{
public:
- void clear() throw();
+ void cipher(const byte in[], byte out[], u32bit length);
+
+ void set_iv(const byte iv[], u32bit iv_len);
+
+ bool valid_iv_length(u32bit iv_len) const
+ { return (iv_len == 8); }
+
+ void clear();
std::string name() const;
StreamCipher* clone() const { return new Salsa20; }
- void resync(const byte[], u32bit);
-
Salsa20();
~Salsa20() { clear(); }
private:
- void cipher(const byte[], byte[], u32bit);
- void key_schedule(const byte[], u32bit);
+ void key_schedule(const byte key[], u32bit key_len);
SecureBuffer<u32bit, 16> state;
diff --git a/src/stream/stream_cipher.cpp b/src/stream/stream_cipher.cpp
deleted file mode 100644
index 68bb5d4f0..000000000
--- a/src/stream/stream_cipher.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
-* Stream Cipher Default Implementation for IV and Seek
-* (C) 1999-2007 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#include <botan/stream_cipher.h>
-
-namespace Botan {
-
-/*
-* Default StreamCipher Resync Operation
-*/
-void StreamCipher::resync(const byte[], u32bit length)
- {
- if(length)
- throw Exception("The stream cipher " + name() +
- " does not support resyncronization");
- }
-
-/*
-* Default StreamCipher Seek Operation
-*/
-void StreamCipher::seek(u32bit)
- {
- throw Exception("The stream cipher " + name() + " does not support seek()");
- }
-
-}
diff --git a/src/stream/stream_cipher.h b/src/stream/stream_cipher.h
index 8ea359131..29c16c8b5 100644
--- a/src/stream/stream_cipher.h
+++ b/src/stream/stream_cipher.h
@@ -18,53 +18,40 @@ namespace Botan {
class BOTAN_DLL StreamCipher : public SymmetricAlgorithm
{
public:
- const u32bit IV_LENGTH;
-
- /**
- * Encrypt a message.
- * @param i the plaintext
- * @param o the byte array to hold the output, i.e. the ciphertext
- * @param len the length of both i and o
- */
- void encrypt(const byte i[], byte o[], u32bit len) { cipher(i, o, len); }
-
/**
- * Decrypt a message.
- * @param i the ciphertext to decrypt
- * @param o the byte array to hold the output, i.e. the plaintext
- * @param len the length of both i and o
+ * 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
*/
- void decrypt(const byte i[], byte o[], u32bit len) { cipher(i, o, len); }
+ virtual void cipher(const byte in[], byte out[], u32bit len) = 0;
/**
- * Encrypt a message.
- * @param in the plaintext as input, after the function has
- * returned it will hold the ciphertext
-
- * @param len the length of in
+ * Encrypt or decrypt a message
+ * @param buf the plaintext / ciphertext
+ * @param len the length of buf in bytes
*/
- void encrypt(byte in[], u32bit len) { cipher(in, in, len); }
-
- /**
- * Decrypt a message.
- * @param in the ciphertext as input, after the function has
- * returned it will hold the plaintext
- * @param len the length of in
- */
- void decrypt(byte in[], u32bit len) { cipher(in, in, len); }
+ void cipher1(byte buf[], u32bit len)
+ { cipher(buf, buf, len); }
/**
* Resync the cipher using the IV
* @param iv the initialization vector
* @param iv_len the length of the IV in bytes
*/
- virtual void resync(const byte iv[], u32bit iv_len);
+ virtual void set_iv(const byte[], u32bit iv_len)
+ {
+ if(iv_len)
+ throw Exception("The stream cipher " + name() +
+ " does not support resyncronization");
+ }
/**
- * Seek ahead in the stream.
- * @param len the length to seek ahead.
+ * @param iv_len the length of the IV in bytes
+ * @return if the length is valid for this algorithm
*/
- virtual void seek(u32bit len);
+ virtual bool valid_iv_length(u32bit iv_len) const
+ { return (iv_len == 0); }
/**
* Get a new object representing the same algorithm as *this
@@ -74,17 +61,17 @@ class BOTAN_DLL StreamCipher : public SymmetricAlgorithm
/**
* Zeroize internal state
*/
- virtual void clear() throw() = 0;
+ virtual void clear() = 0;
- StreamCipher(u32bit key_min, u32bit key_max = 0,
- u32bit key_mod = 1,
- u32bit iv_len = 0) :
- SymmetricAlgorithm(key_min, key_max, key_mod),
- IV_LENGTH(iv_len) {}
+ /**
+ * StreamCipher constructor
+ */
+ StreamCipher(u32bit key_min,
+ u32bit key_max = 0,
+ u32bit key_mod = 1) :
+ SymmetricAlgorithm(key_min, key_max, key_mod) {}
virtual ~StreamCipher() {}
- private:
- virtual void cipher(const byte[], byte[], u32bit) = 0;
};
}
diff --git a/src/stream/turing/info.txt b/src/stream/turing/info.txt
index c251a0a30..dede0dd39 100644
--- a/src/stream/turing/info.txt
+++ b/src/stream/turing/info.txt
@@ -1,5 +1,3 @@
-realname "Turing"
-
define TURING
load_on auto
diff --git a/src/stream/turing/turing.cpp b/src/stream/turing/turing.cpp
index b988568c3..810f65ca4 100644
--- a/src/stream/turing/turing.cpp
+++ b/src/stream/turing/turing.cpp
@@ -218,25 +218,6 @@ u32bit Turing::fixedS(u32bit W)
}
/*
-* Generate the expanded Turing Sbox tables
-*/
-void Turing::gen_sbox(MemoryRegion<u32bit>& S, u32bit which,
- const MemoryRegion<u32bit>& K)
- {
- for(u32bit j = 0; j != 256; ++j)
- {
- u32bit W = 0, C = j;
-
- for(u32bit k = 0; k < K.size(); ++k)
- {
- C = SBOX[get_byte(which, K[k]) ^ C];
- W ^= rotate_left(Q_BOX[C], k + 8*which);
- }
- S[j] = (W & rotate_right(0x00FFFFFF, 8*which)) | (C << (24 - 8*which));
- }
- }
-
-/*
* Turing Key Schedule
*/
void Turing::key_schedule(const byte key[], u32bit length)
@@ -250,20 +231,41 @@ void Turing::key_schedule(const byte key[], u32bit length)
PHT(K);
- gen_sbox(S0, 0, K);
- gen_sbox(S1, 1, K);
- gen_sbox(S2, 2, K);
- gen_sbox(S3, 3, K);
+ for(u32bit i = 0; i != 256; ++i)
+ {
+ u32bit W0 = 0, C0 = i;
+ u32bit W1 = 0, C1 = i;
+ u32bit W2 = 0, C2 = i;
+ u32bit W3 = 0, C3 = i;
+
+ for(u32bit j = 0; j < K.size(); ++j)
+ {
+ C0 = SBOX[get_byte(0, K[j]) ^ C0];
+ C1 = SBOX[get_byte(1, K[j]) ^ C1];
+ C2 = SBOX[get_byte(2, K[j]) ^ C2];
+ C3 = SBOX[get_byte(3, K[j]) ^ C3];
+
+ W0 ^= rotate_left(Q_BOX[C0], j);
+ W1 ^= rotate_left(Q_BOX[C1], j + 8);
+ W2 ^= rotate_left(Q_BOX[C2], j + 16);
+ W3 ^= rotate_left(Q_BOX[C3], j + 24);
+ }
+
+ S0[i] = (W0 & 0x00FFFFFF) | (C0 << 24);
+ S1[i] = (W1 & 0xFF00FFFF) | (C1 << 16);
+ S2[i] = (W2 & 0xFFFF00FF) | (C2 << 8);
+ S3[i] = (W3 & 0xFFFFFF00) | C3;
+ }
- resync(0, 0);
+ set_iv(0, 0);
}
/*
* Resynchronization
*/
-void Turing::resync(const byte iv[], u32bit length)
+void Turing::set_iv(const byte iv[], u32bit length)
{
- if(length % 4 != 0 || length > 16)
+ if(!valid_iv_length(length))
throw Invalid_IV_Length(name(), length);
SecureVector<u32bit> IV(length / 4);
@@ -293,7 +295,7 @@ void Turing::resync(const byte iv[], u32bit length)
/*
* Clear memory of sensitive data
*/
-void Turing::clear() throw()
+void Turing::clear()
{
S0.clear();
S1.clear();
diff --git a/src/stream/turing/turing.h b/src/stream/turing/turing.h
index d48c1d8a8..7291647ea 100644
--- a/src/stream/turing/turing.h
+++ b/src/stream/turing/turing.h
@@ -18,19 +18,21 @@ namespace Botan {
class BOTAN_DLL Turing : public StreamCipher
{
public:
- void clear() throw();
+ void cipher(const byte in[], byte out[], u32bit length);
+ void set_iv(const byte[], u32bit);
+
+ bool valid_iv_length(u32bit iv_len) const
+ { return (iv_len % 4 == 0 && iv_len <= 16); }
+
+ void clear();
std::string name() const { return "Turing"; }
StreamCipher* clone() const { return new Turing; }
Turing() : StreamCipher(4, 32, 4) { position = 0; }
private:
- void cipher(const byte[], byte[], u32bit);
void key_schedule(const byte[], u32bit);
- void resync(const byte[], u32bit);
void generate();
static u32bit fixedS(u32bit);
- static void gen_sbox(MemoryRegion<u32bit>&, u32bit,
- const MemoryRegion<u32bit>&);
static const u32bit Q_BOX[256];
static const byte SBOX[256];
diff --git a/src/stream/wid_wake/info.txt b/src/stream/wid_wake/info.txt
index 94416417e..6289e0369 100644
--- a/src/stream/wid_wake/info.txt
+++ b/src/stream/wid_wake/info.txt
@@ -1,5 +1,3 @@
-realname "WiderWake"
-
define WID_WAKE
load_on auto
diff --git a/src/stream/wid_wake/wid_wake.cpp b/src/stream/wid_wake/wid_wake.cpp
index 1dc0fd7f9..2a8946649 100644
--- a/src/stream/wid_wake/wid_wake.cpp
+++ b/src/stream/wid_wake/wid_wake.cpp
@@ -110,16 +110,17 @@ void WiderWake_41_BE::key_schedule(const byte key[], u32bit)
T[X] = Z;
position = 0;
- const byte iv[8] = { 0 };
- resync(iv, 8);
+
+ const byte ZEROS[8] = { 0 };
+ set_iv(ZEROS, sizeof(ZEROS));
}
/*
* Resynchronization
*/
-void WiderWake_41_BE::resync(const byte iv[], u32bit length)
+void WiderWake_41_BE::set_iv(const byte iv[], u32bit length)
{
- if(length != 8)
+ if(!valid_iv_length(length))
throw Invalid_IV_Length(name(), length);
for(u32bit j = 0; j != 4; ++j)
@@ -135,7 +136,7 @@ void WiderWake_41_BE::resync(const byte iv[], u32bit length)
/*
* Clear memory of sensitive data
*/
-void WiderWake_41_BE::clear() throw()
+void WiderWake_41_BE::clear()
{
position = 0;
t_key.clear();
diff --git a/src/stream/wid_wake/wid_wake.h b/src/stream/wid_wake/wid_wake.h
index 4720afdb2..23e1eacab 100644
--- a/src/stream/wid_wake/wid_wake.h
+++ b/src/stream/wid_wake/wid_wake.h
@@ -18,14 +18,18 @@ namespace Botan {
class BOTAN_DLL WiderWake_41_BE : public StreamCipher
{
public:
- void clear() throw();
+ void cipher(const byte[], byte[], u32bit);
+ void set_iv(const byte[], u32bit);
+
+ bool valid_iv_length(u32bit iv_len) const
+ { return (iv_len == 8); }
+
+ void clear();
std::string name() const { return "WiderWake4+1-BE"; }
StreamCipher* clone() const { return new WiderWake_41_BE; }
- WiderWake_41_BE() : StreamCipher(16, 16, 1, 8) {}
+ WiderWake_41_BE() : StreamCipher(16, 16, 1) {}
private:
- void cipher(const byte[], byte[], u32bit);
void key_schedule(const byte[], u32bit);
- void resync(const byte[], u32bit);
void generate(u32bit);