aboutsummaryrefslogtreecommitdiffstats
path: root/src/stream/turing
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-10-28 22:55:12 +0000
committerlloyd <[email protected]>2009-10-28 22:55:12 +0000
commit3623be3fd05d890309cc3da4b3a1e319e357df65 (patch)
tree34ca43fcf8a7007cc01a3919f63e9ab6763cb673 /src/stream/turing
parentfc1e61500e77fcabe67e6d2607810c1ba071bbdd (diff)
parent9462f875b13a321f42a127166d49670ca04afcde (diff)
propagate from branch 'net.randombit.botan.1_8' (head 3158f8272a3582dd44dfb771665eb71f7d005339)
to branch 'net.randombit.botan' (head bf629b13dd132b263e76a72b7eca0f7e4ab19aac)
Diffstat (limited to 'src/stream/turing')
-rw-r--r--src/stream/turing/turing.cpp56
-rw-r--r--src/stream/turing/turing.h12
2 files changed, 36 insertions, 32 deletions
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];