aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-08-31 18:37:43 +0000
committerlloyd <[email protected]>2009-08-31 18:37:43 +0000
commit74d860bb2b35ee5184f77a1e3e2bb1b5b92cacd6 (patch)
tree41c50b31911d7aaf5c2d9d4643450862bfafbb58 /src
parentde705485bccc89a695488ebe69b744433388bf21 (diff)
Combine the 4 sbox calculations in the key schedule so that all four are
computed in parallel. Not a huge win but slightly faster (which affects things like Lion when using Turing), most likely due to more available ILP
Diffstat (limited to 'src')
-rw-r--r--src/stream/turing/turing.cpp48
-rw-r--r--src/stream/turing/turing.h2
2 files changed, 25 insertions, 25 deletions
diff --git a/src/stream/turing/turing.cpp b/src/stream/turing/turing.cpp
index b988568c3..1e2203480 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,10 +231,31 @@ 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);
}
diff --git a/src/stream/turing/turing.h b/src/stream/turing/turing.h
index d48c1d8a8..455d3c612 100644
--- a/src/stream/turing/turing.h
+++ b/src/stream/turing/turing.h
@@ -29,8 +29,6 @@ class BOTAN_DLL Turing : public StreamCipher
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];