aboutsummaryrefslogtreecommitdiffstats
path: root/src/block
diff options
context:
space:
mode:
Diffstat (limited to 'src/block')
-rw-r--r--src/block/aes/aes.cpp5
-rw-r--r--src/block/aes/aes.h10
-rw-r--r--src/block/aes_ssse3/aes_ssse3.h12
-rw-r--r--src/block/blowfish/blowfish.cpp6
-rw-r--r--src/block/blowfish/blowfish.h6
-rw-r--r--src/block/cast/cast128.cpp4
-rw-r--r--src/block/cast/cast128.h4
-rw-r--r--src/block/cast/cast256.cpp9
-rw-r--r--src/block/cast/cast256.h6
-rw-r--r--src/block/des/des.h8
-rw-r--r--src/block/des/desx.h4
-rw-r--r--src/block/gost_28147/gost_28147.cpp2
-rw-r--r--src/block/gost_28147/gost_28147.h8
-rw-r--r--src/block/idea/idea.h8
-rw-r--r--src/block/kasumi/kasumi.cpp2
-rw-r--r--src/block/kasumi/kasumi.h4
-rw-r--r--src/block/mars/mars.cpp3
-rw-r--r--src/block/mars/mars.h4
-rw-r--r--src/block/misty1/misty1.cpp4
-rw-r--r--src/block/misty1/misty1.h2
-rw-r--r--src/block/noekeon/noekeon.h8
-rw-r--r--src/block/noekeon_simd/noekeon_simd.cpp4
-rw-r--r--src/block/rc2/rc2.cpp2
-rw-r--r--src/block/rc2/rc2.h4
-rw-r--r--src/block/rc5/rc5.cpp4
-rw-r--r--src/block/rc6/rc6.cpp4
-rw-r--r--src/block/rc6/rc6.h4
-rw-r--r--src/block/safer/safer_sk.cpp2
-rw-r--r--src/block/seed/seed.cpp2
-rw-r--r--src/block/seed/seed.h4
-rw-r--r--src/block/serpent/serpent.cpp2
-rw-r--r--src/block/serpent/serpent.h6
-rw-r--r--src/block/skipjack/skipjack.h4
-rw-r--r--src/block/square/square.cpp2
-rw-r--r--src/block/square/square.h6
-rw-r--r--src/block/tea/tea.h4
-rw-r--r--src/block/twofish/twofish.cpp201
-rw-r--r--src/block/twofish/twofish.h5
-rw-r--r--src/block/xtea/xtea.cpp2
-rw-r--r--src/block/xtea/xtea.h6
40 files changed, 202 insertions, 185 deletions
diff --git a/src/block/aes/aes.cpp b/src/block/aes/aes.cpp
index 93f7f4363..f2f1bc9e5 100644
--- a/src/block/aes/aes.cpp
+++ b/src/block/aes/aes.cpp
@@ -627,7 +627,7 @@ void AES::key_schedule(const byte key[], u32bit length)
ROUNDS = (length / 4) + 6;
- SecureVector<u32bit, 64> XEK, XDK;
+ SecureVector<u32bit> XEK(64), XDK(64);
const u32bit X = length / 4;
for(u32bit j = 0; j != X; ++j)
@@ -681,7 +681,8 @@ u32bit AES::S(u32bit input)
/*
* AES Constructor
*/
-AES::AES(u32bit key_size) : BlockCipher(16, key_size)
+AES::AES(u32bit key_size) : BlockCipher(16, key_size),
+ EK(56), ME(16), DK(56), MD(16)
{
if(key_size != 16 && key_size != 24 && key_size != 32)
throw Invalid_Key_Length(name(), key_size);
diff --git a/src/block/aes/aes.h b/src/block/aes/aes.h
index 8770bdb35..ba688a6e3 100644
--- a/src/block/aes/aes.h
+++ b/src/block/aes/aes.h
@@ -25,7 +25,7 @@ class BOTAN_DLL AES : public BlockCipher
std::string name() const { return "AES"; }
BlockCipher* clone() const { return new AES; }
- AES() : BlockCipher(16, 16, 32, 8) { ROUNDS = 14; }
+ AES() : BlockCipher(16, 16, 32, 8), EK(56), ME(16), DK(56), MD(16) { ROUNDS = 14; }
/**
* AES fixed to a particular key_size (16, 24, or 32 bytes)
@@ -38,11 +38,11 @@ class BOTAN_DLL AES : public BlockCipher
u32bit ROUNDS;
- SecureVector<u32bit, 56> EK;
- SecureVector<byte, 16> ME;
+ SecureVector<u32bit> EK;
+ SecureVector<byte> ME;
- SecureVector<u32bit, 56> DK;
- SecureVector<byte, 16> MD;
+ SecureVector<u32bit> DK;
+ SecureVector<byte> MD;
};
/**
diff --git a/src/block/aes_ssse3/aes_ssse3.h b/src/block/aes_ssse3/aes_ssse3.h
index babd30509..6e7d29a37 100644
--- a/src/block/aes_ssse3/aes_ssse3.h
+++ b/src/block/aes_ssse3/aes_ssse3.h
@@ -25,11 +25,11 @@ class BOTAN_DLL AES_128_SSSE3 : public BlockCipher
std::string name() const { return "AES-128"; }
BlockCipher* clone() const { return new AES_128_SSSE3; }
- AES_128_SSSE3() : BlockCipher(16, 16) {}
+ AES_128_SSSE3() : BlockCipher(16, 16), EK(44), DK(44) {}
private:
void key_schedule(const byte[], u32bit);
- SecureVector<u32bit, 44> EK, DK;
+ SecureVector<u32bit> EK, DK;
};
/**
@@ -45,11 +45,11 @@ class BOTAN_DLL AES_192_SSSE3 : public BlockCipher
std::string name() const { return "AES-192"; }
BlockCipher* clone() const { return new AES_192_SSSE3; }
- AES_192_SSSE3() : BlockCipher(16, 24) {}
+ AES_192_SSSE3() : BlockCipher(16, 24), EK(52), DK(52) {}
private:
void key_schedule(const byte[], u32bit);
- SecureVector<u32bit, 52> EK, DK;
+ SecureVector<u32bit> EK, DK;
};
/**
@@ -65,11 +65,11 @@ class BOTAN_DLL AES_256_SSSE3 : public BlockCipher
std::string name() const { return "AES-256"; }
BlockCipher* clone() const { return new AES_256_SSSE3; }
- AES_256_SSSE3() : BlockCipher(16, 32) {}
+ AES_256_SSSE3() : BlockCipher(16, 32), EK(60), DK(60) {}
private:
void key_schedule(const byte[], u32bit);
- SecureVector<u32bit, 60> EK, DK;
+ SecureVector<u32bit> EK, DK;
};
}
diff --git a/src/block/blowfish/blowfish.cpp b/src/block/blowfish/blowfish.cpp
index 6e4ad5b28..91d25884d 100644
--- a/src/block/blowfish/blowfish.cpp
+++ b/src/block/blowfish/blowfish.cpp
@@ -131,8 +131,10 @@ void Blowfish::generate_sbox(MemoryRegion<u32bit>& box,
*/
void Blowfish::clear()
{
- P.copy(P_INIT, 18);
- S.copy(S_INIT, 1024);
+ std::copy(P_INIT, P_INIT + 18, P.begin());
+ std::copy(S_INIT, S_INIT + 1024, S.begin());
+ //P.copy(P_INIT, 18);
+ //S.copy(S_INIT, 1024);
}
}
diff --git a/src/block/blowfish/blowfish.h b/src/block/blowfish/blowfish.h
index 88122aed8..0b4df50ad 100644
--- a/src/block/blowfish/blowfish.h
+++ b/src/block/blowfish/blowfish.h
@@ -25,7 +25,7 @@ class BOTAN_DLL Blowfish : public BlockCipher
std::string name() const { return "Blowfish"; }
BlockCipher* clone() const { return new Blowfish; }
- Blowfish() : BlockCipher(8, 1, 56) {}
+ Blowfish() : BlockCipher(8, 1, 56), S(1024), P(18) {}
private:
void key_schedule(const byte[], u32bit);
void generate_sbox(MemoryRegion<u32bit>& box,
@@ -34,8 +34,8 @@ class BOTAN_DLL Blowfish : public BlockCipher
static const u32bit P_INIT[18];
static const u32bit S_INIT[1024];
- SecureVector<u32bit, 1024> S;
- SecureVector<u32bit, 18> P;
+ SecureVector<u32bit> S;
+ SecureVector<u32bit> P;
};
}
diff --git a/src/block/cast/cast128.cpp b/src/block/cast/cast128.cpp
index b68b7abd7..48eb910ce 100644
--- a/src/block/cast/cast128.cpp
+++ b/src/block/cast/cast128.cpp
@@ -119,7 +119,7 @@ void CAST_128::decrypt_n(const byte in[], byte out[], u32bit blocks) const
void CAST_128::key_schedule(const byte key[], u32bit length)
{
clear();
- SecureVector<u32bit, 4> X;
+ SecureVector<u32bit> X(4);
for(u32bit j = 0; j != length; ++j)
X[j/4] = (X[j/4] << 8) + key[j];
@@ -145,7 +145,7 @@ void CAST_128::cast_ks(MemoryRegion<u32bit>& K,
const u32bit* X;
};
- SecureVector<u32bit, 4> Z;
+ SecureVector<u32bit> Z(4);
ByteReader x(&X[0]), z(&Z[0]);
Z[0] = X[0] ^ S5[x(13)] ^ S6[x(15)] ^ S7[x(12)] ^ S8[x(14)] ^ S7[x( 8)];
diff --git a/src/block/cast/cast128.h b/src/block/cast/cast128.h
index 425eb46cc..bb8332aca 100644
--- a/src/block/cast/cast128.h
+++ b/src/block/cast/cast128.h
@@ -25,7 +25,7 @@ class BOTAN_DLL CAST_128 : public BlockCipher
std::string name() const { return "CAST-128"; }
BlockCipher* clone() const { return new CAST_128; }
- CAST_128() : BlockCipher(8, 11, 16) {}
+ CAST_128() : BlockCipher(8, 11, 16), MK(16), RK(16) {}
private:
void key_schedule(const byte[], u32bit);
@@ -37,7 +37,7 @@ class BOTAN_DLL CAST_128 : public BlockCipher
static const u32bit S7[256];
static const u32bit S8[256];
- SecureVector<u32bit, 16> MK, RK;
+ SecureVector<u32bit> MK, RK;
};
extern const u32bit CAST_SBOX1[256];
diff --git a/src/block/cast/cast256.cpp b/src/block/cast/cast256.cpp
index 8aaf8009f..551d4e387 100644
--- a/src/block/cast/cast256.cpp
+++ b/src/block/cast/cast256.cpp
@@ -138,12 +138,13 @@ void CAST_256::decrypt_n(const byte in[], byte out[], u32bit blocks) const
*/
void CAST_256::key_schedule(const byte key[], u32bit length)
{
- SecureVector<u32bit, 8> TMP;
+ SecureVector<u32bit> K(8);
for(u32bit j = 0; j != length; ++j)
- TMP[j/4] = (TMP[j/4] << 8) + key[j];
+ K[j/4] = (K[j/4] << 8) + key[j];
+
+ u32bit A = K[0], B = K[1], C = K[2], D = K[3],
+ E = K[4], F = K[5], G = K[6], H = K[7];
- u32bit A = TMP[0], B = TMP[1], C = TMP[2], D = TMP[3],
- E = TMP[4], F = TMP[5], G = TMP[6], H = TMP[7];
for(u32bit j = 0; j != 48; j += 4)
{
round1(G, H, KEY_MASK[4*j+ 0], KEY_ROT[(4*j+ 0) % 32]);
diff --git a/src/block/cast/cast256.h b/src/block/cast/cast256.h
index c9820c1ab..533f57ac1 100644
--- a/src/block/cast/cast256.h
+++ b/src/block/cast/cast256.h
@@ -25,15 +25,15 @@ class BOTAN_DLL CAST_256 : public BlockCipher
std::string name() const { return "CAST-256"; }
BlockCipher* clone() const { return new CAST_256; }
- CAST_256() : BlockCipher(16, 4, 32, 4) {}
+ CAST_256() : BlockCipher(16, 4, 32, 4), MK(48), RK(48) {}
private:
void key_schedule(const byte[], u32bit);
static const u32bit KEY_MASK[192];
static const byte KEY_ROT[32];
- SecureVector<u32bit, 48> MK;
- SecureVector<byte, 48> RK;
+ SecureVector<u32bit> MK;
+ SecureVector<byte> RK;
};
extern const u32bit CAST_SBOX1[256];
diff --git a/src/block/des/des.h b/src/block/des/des.h
index f631986f0..e338b9a29 100644
--- a/src/block/des/des.h
+++ b/src/block/des/des.h
@@ -25,11 +25,11 @@ class BOTAN_DLL DES : public BlockCipher
std::string name() const { return "DES"; }
BlockCipher* clone() const { return new DES; }
- DES() : BlockCipher(8, 8) {}
+ DES() : BlockCipher(8, 8), round_key(32) {}
private:
void key_schedule(const byte[], u32bit);
- SecureVector<u32bit, 32> round_key;
+ SecureVector<u32bit> round_key;
};
/**
@@ -45,11 +45,11 @@ class BOTAN_DLL TripleDES : public BlockCipher
std::string name() const { return "TripleDES"; }
BlockCipher* clone() const { return new TripleDES; }
- TripleDES() : BlockCipher(8, 16, 24, 8) {}
+ TripleDES() : BlockCipher(8, 16, 24, 8), round_key(96) {}
private:
void key_schedule(const byte[], u32bit);
- SecureVector<u32bit, 96> round_key;
+ SecureVector<u32bit> round_key;
};
/*
diff --git a/src/block/des/desx.h b/src/block/des/desx.h
index 007948ba7..cb452c47b 100644
--- a/src/block/des/desx.h
+++ b/src/block/des/desx.h
@@ -25,10 +25,10 @@ class BOTAN_DLL DESX : public BlockCipher
std::string name() const { return "DESX"; }
BlockCipher* clone() const { return new DESX; }
- DESX() : BlockCipher(8, 24) {}
+ DESX() : BlockCipher(8, 24), K1(8), K2(8) {}
private:
void key_schedule(const byte[], u32bit);
- SecureVector<byte, 8> K1, K2;
+ SecureVector<byte> K1, K2;
DES des;
};
diff --git a/src/block/gost_28147/gost_28147.cpp b/src/block/gost_28147/gost_28147.cpp
index 3844fd441..8d7e950c6 100644
--- a/src/block/gost_28147/gost_28147.cpp
+++ b/src/block/gost_28147/gost_28147.cpp
@@ -52,7 +52,7 @@ GOST_28147_89_Params::GOST_28147_89_Params(const std::string& n) : name(n)
* GOST Constructor
*/
GOST_28147_89::GOST_28147_89(const GOST_28147_89_Params& param) :
- BlockCipher(8, 32)
+ BlockCipher(8, 32), SBOX(1024), EK(8)
{
// Convert the parallel 4x4 sboxes into larger word-based sboxes
for(size_t i = 0; i != 4; ++i)
diff --git a/src/block/gost_28147/gost_28147.h b/src/block/gost_28147/gost_28147.h
index 9d845ae72..501e621e0 100644
--- a/src/block/gost_28147/gost_28147.h
+++ b/src/block/gost_28147/gost_28147.h
@@ -65,13 +65,13 @@ class BOTAN_DLL GOST_28147_89 : public BlockCipher
*/
GOST_28147_89(const GOST_28147_89_Params& params);
private:
- GOST_28147_89(const SecureVector<u32bit, 1024>& other_SBOX) :
- BlockCipher(8, 32), SBOX(other_SBOX) {}
+ GOST_28147_89(const SecureVector<u32bit>& other_SBOX) :
+ BlockCipher(8, 32), SBOX(other_SBOX), EK(8) {}
void key_schedule(const byte[], u32bit);
- SecureVector<u32bit, 1024> SBOX;
- SecureVector<u32bit, 8> EK;
+ SecureVector<u32bit> SBOX;
+ SecureVector<u32bit> EK;
};
}
diff --git a/src/block/idea/idea.h b/src/block/idea/idea.h
index 737970b29..1a315ce3f 100644
--- a/src/block/idea/idea.h
+++ b/src/block/idea/idea.h
@@ -25,21 +25,21 @@ class BOTAN_DLL IDEA : public BlockCipher
std::string name() const { return "IDEA"; }
BlockCipher* clone() const { return new IDEA; }
- IDEA() : BlockCipher(8, 16) {}
+ IDEA() : BlockCipher(8, 16), EK(52), DK(52) {}
protected:
/**
* @return const reference to encryption subkeys
*/
- const SecureVector<u16bit, 52>& get_EK() const { return EK; }
+ const SecureVector<u16bit>& get_EK() const { return EK; }
/**
* @return const reference to decryption subkeys
*/
- const SecureVector<u16bit, 52>& get_DK() const { return DK; }
+ const SecureVector<u16bit>& get_DK() const { return DK; }
private:
void key_schedule(const byte[], u32bit);
- SecureVector<u16bit, 52> EK, DK;
+ SecureVector<u16bit> EK, DK;
};
}
diff --git a/src/block/kasumi/kasumi.cpp b/src/block/kasumi/kasumi.cpp
index 8dcdff716..023a7a503 100644
--- a/src/block/kasumi/kasumi.cpp
+++ b/src/block/kasumi/kasumi.cpp
@@ -204,7 +204,7 @@ void KASUMI::key_schedule(const byte key[], u32bit)
static const u16bit RC[] = { 0x0123, 0x4567, 0x89AB, 0xCDEF,
0xFEDC, 0xBA98, 0x7654, 0x3210 };
- SecureVector<u16bit, 16> K;
+ SecureVector<u16bit> K(16);
for(u32bit j = 0; j != 8; ++j)
{
K[j] = load_be<u16bit>(key, j);
diff --git a/src/block/kasumi/kasumi.h b/src/block/kasumi/kasumi.h
index f8575c2d2..51727dd4d 100644
--- a/src/block/kasumi/kasumi.h
+++ b/src/block/kasumi/kasumi.h
@@ -25,11 +25,11 @@ class BOTAN_DLL KASUMI : public BlockCipher
std::string name() const { return "KASUMI"; }
BlockCipher* clone() const { return new KASUMI; }
- KASUMI() : BlockCipher(8, 16) {}
+ KASUMI() : BlockCipher(8, 16), EK(64) {}
private:
void key_schedule(const byte[], u32bit);
- SecureVector<u16bit, 64> EK;
+ SecureVector<u16bit> EK;
};
}
diff --git a/src/block/mars/mars.cpp b/src/block/mars/mars.cpp
index 57a224fac..71cef3ee8 100644
--- a/src/block/mars/mars.cpp
+++ b/src/block/mars/mars.cpp
@@ -320,9 +320,10 @@ void MARS::decrypt_n(const byte in[], byte out[], u32bit blocks) const
*/
void MARS::key_schedule(const byte key[], u32bit length)
{
- SecureVector<u32bit, 15> T;
+ SecureVector<u32bit> T(15);
for(u32bit j = 0; j != length / 4; ++j)
T[j] = load_le<u32bit>(key, j);
+
T[length / 4] = length / 4;
for(u32bit j = 0; j != 4; ++j)
diff --git a/src/block/mars/mars.h b/src/block/mars/mars.h
index 37501fff1..84a9a21f7 100644
--- a/src/block/mars/mars.h
+++ b/src/block/mars/mars.h
@@ -25,11 +25,11 @@ class BOTAN_DLL MARS : public BlockCipher
std::string name() const { return "MARS"; }
BlockCipher* clone() const { return new MARS; }
- MARS() : BlockCipher(16, 16, 32, 4) {}
+ MARS() : BlockCipher(16, 16, 32, 4), EK(40) {}
private:
void key_schedule(const byte[], u32bit);
- SecureVector<u32bit, 40> EK;
+ SecureVector<u32bit> EK;
};
}
diff --git a/src/block/misty1/misty1.cpp b/src/block/misty1/misty1.cpp
index d5d3513a2..1d032172d 100644
--- a/src/block/misty1/misty1.cpp
+++ b/src/block/misty1/misty1.cpp
@@ -204,7 +204,7 @@ void MISTY1::decrypt_n(const byte in[], byte out[], u32bit blocks) const
*/
void MISTY1::key_schedule(const byte key[], u32bit length)
{
- SecureVector<u16bit, 32> KS;
+ SecureVector<u16bit> KS(32);
for(u32bit j = 0; j != length / 2; ++j)
KS[j] = load_be<u16bit>(key, j);
@@ -251,7 +251,7 @@ void MISTY1::key_schedule(const byte key[], u32bit length)
/*
* MISTY1 Constructor
*/
-MISTY1::MISTY1(u32bit rounds) : BlockCipher(8, 16)
+MISTY1::MISTY1(u32bit rounds) : BlockCipher(8, 16), EK(100), DK(100)
{
if(rounds != 8)
throw Invalid_Argument("MISTY1: Invalid number of rounds: "
diff --git a/src/block/misty1/misty1.h b/src/block/misty1/misty1.h
index dbb8e2c45..7a9f1f9d9 100644
--- a/src/block/misty1/misty1.h
+++ b/src/block/misty1/misty1.h
@@ -33,7 +33,7 @@ class BOTAN_DLL MISTY1 : public BlockCipher
private:
void key_schedule(const byte[], u32bit);
- SecureVector<u16bit, 100> EK, DK;
+ SecureVector<u16bit> EK, DK;
};
}
diff --git a/src/block/noekeon/noekeon.h b/src/block/noekeon/noekeon.h
index 2e524f8b8..ee3d32c80 100644
--- a/src/block/noekeon/noekeon.h
+++ b/src/block/noekeon/noekeon.h
@@ -25,7 +25,7 @@ class BOTAN_DLL Noekeon : public BlockCipher
std::string name() const { return "Noekeon"; }
BlockCipher* clone() const { return new Noekeon; }
- Noekeon() : BlockCipher(16, 16) {}
+ Noekeon() : BlockCipher(16, 16), EK(4), DK(4) {}
protected:
/**
* The Noekeon round constants
@@ -35,16 +35,16 @@ class BOTAN_DLL Noekeon : public BlockCipher
/**
* @return const reference to encryption subkeys
*/
- const SecureVector<u32bit, 4>& get_EK() const { return EK; }
+ const SecureVector<u32bit>& get_EK() const { return EK; }
/**
* @return const reference to decryption subkeys
*/
- const SecureVector<u32bit, 4>& get_DK() const { return DK; }
+ const SecureVector<u32bit>& get_DK() const { return DK; }
private:
void key_schedule(const byte[], u32bit);
- SecureVector<u32bit, 4> EK, DK;
+ SecureVector<u32bit> EK, DK;
};
}
diff --git a/src/block/noekeon_simd/noekeon_simd.cpp b/src/block/noekeon_simd/noekeon_simd.cpp
index be7ca86da..a7fb66f98 100644
--- a/src/block/noekeon_simd/noekeon_simd.cpp
+++ b/src/block/noekeon_simd/noekeon_simd.cpp
@@ -55,7 +55,7 @@ namespace Botan {
*/
void Noekeon_SIMD::encrypt_n(const byte in[], byte out[], u32bit blocks) const
{
- const SecureVector<u32bit, 4>& EK = this->get_EK();
+ const SecureVector<u32bit>& EK = this->get_EK();
SIMD_32 K0 = SIMD_32(EK[0]);
SIMD_32 K1 = SIMD_32(EK[1]);
@@ -112,7 +112,7 @@ void Noekeon_SIMD::encrypt_n(const byte in[], byte out[], u32bit blocks) const
*/
void Noekeon_SIMD::decrypt_n(const byte in[], byte out[], u32bit blocks) const
{
- const SecureVector<u32bit, 4>& DK = this->get_DK();
+ const SecureVector<u32bit>& DK = this->get_DK();
SIMD_32 K0 = SIMD_32(DK[0]);
SIMD_32 K1 = SIMD_32(DK[1]);
diff --git a/src/block/rc2/rc2.cpp b/src/block/rc2/rc2.cpp
index 4657d7b6c..8a939ecae 100644
--- a/src/block/rc2/rc2.cpp
+++ b/src/block/rc2/rc2.cpp
@@ -124,7 +124,7 @@ void RC2::key_schedule(const byte key[], u32bit length)
0xC5, 0xF3, 0xDB, 0x47, 0xE5, 0xA5, 0x9C, 0x77, 0x0A, 0xA6, 0x20, 0x68,
0xFE, 0x7F, 0xC1, 0xAD };
- SecureVector<byte, 128> L;
+ SecureVector<byte> L(128);
L.copy(key, length);
for(u32bit j = length; j != 128; ++j)
diff --git a/src/block/rc2/rc2.h b/src/block/rc2/rc2.h
index e6c900056..7e1953441 100644
--- a/src/block/rc2/rc2.h
+++ b/src/block/rc2/rc2.h
@@ -32,11 +32,11 @@ class BOTAN_DLL RC2 : public BlockCipher
std::string name() const { return "RC2"; }
BlockCipher* clone() const { return new RC2; }
- RC2() : BlockCipher(8, 1, 32) {}
+ RC2() : BlockCipher(8, 1, 32), K(64) {}
private:
void key_schedule(const byte[], u32bit);
- SecureVector<u16bit, 64> K;
+ SecureVector<u16bit> K;
};
}
diff --git a/src/block/rc5/rc5.cpp b/src/block/rc5/rc5.cpp
index dcda1bb25..ded0f961d 100644
--- a/src/block/rc5/rc5.cpp
+++ b/src/block/rc5/rc5.cpp
@@ -82,9 +82,11 @@ void RC5::key_schedule(const byte key[], u32bit length)
for(u32bit j = 1; j != S.size(); ++j)
S[j] = S[j-1] + 0x9E3779B9;
- SecureVector<u32bit, 8> K;
+ SecureVector<u32bit> K(8);
+
for(s32bit j = length-1; j >= 0; --j)
K[j/4] = (K[j/4] << 8) + key[j];
+
for(u32bit j = 0, A = 0, B = 0; j != MIX_ROUNDS; ++j)
{
A = rotate_left(S[j % S.size()] + A + B, 3);
diff --git a/src/block/rc6/rc6.cpp b/src/block/rc6/rc6.cpp
index ff846f006..5f88d1d0b 100644
--- a/src/block/rc6/rc6.cpp
+++ b/src/block/rc6/rc6.cpp
@@ -119,9 +119,11 @@ void RC6::key_schedule(const byte key[], u32bit length)
for(u32bit j = 1; j != S.size(); ++j)
S[j] = S[j-1] + 0x9E3779B9;
- SecureVector<u32bit, 8> K;
+ SecureVector<u32bit> K(8);
+
for(s32bit j = length-1; j >= 0; --j)
K[j/4] = (K[j/4] << 8) + key[j];
+
for(u32bit j = 0, A = 0, B = 0; j != MIX_ROUNDS; ++j)
{
A = rotate_left(S[j % S.size()] + A + B, 3);
diff --git a/src/block/rc6/rc6.h b/src/block/rc6/rc6.h
index 02c464c5c..55a9d412e 100644
--- a/src/block/rc6/rc6.h
+++ b/src/block/rc6/rc6.h
@@ -25,11 +25,11 @@ class BOTAN_DLL RC6 : public BlockCipher
std::string name() const { return "RC6"; }
BlockCipher* clone() const { return new RC6; }
- RC6() : BlockCipher(16, 1, 32) {}
+ RC6() : BlockCipher(16, 1, 32), S(44) {}
private:
void key_schedule(const byte[], u32bit);
- SecureVector<u32bit, 44> S;
+ SecureVector<u32bit> S;
};
}
diff --git a/src/block/safer/safer_sk.cpp b/src/block/safer/safer_sk.cpp
index 74e7b6298..aebb770d7 100644
--- a/src/block/safer/safer_sk.cpp
+++ b/src/block/safer/safer_sk.cpp
@@ -91,7 +91,7 @@ void SAFER_SK::decrypt_n(const byte in[], byte out[], u32bit blocks) const
*/
void SAFER_SK::key_schedule(const byte key[], u32bit)
{
- SecureVector<byte, 18> KB;
+ SecureVector<byte> KB(18);
for(u32bit j = 0; j != 8; ++j)
{
diff --git a/src/block/seed/seed.cpp b/src/block/seed/seed.cpp
index 651233bdb..ca09937e8 100644
--- a/src/block/seed/seed.cpp
+++ b/src/block/seed/seed.cpp
@@ -111,7 +111,7 @@ void SEED::key_schedule(const byte key[], u32bit)
0x779B99E3, 0xEF3733C6, 0xDE6E678D, 0xBCDCCF1B
};
- SecureVector<u32bit, 4> WK;
+ SecureVector<u32bit> WK(4);
for(u32bit j = 0; j != 4; ++j)
WK[j] = load_be<u32bit>(key, j);
diff --git a/src/block/seed/seed.h b/src/block/seed/seed.h
index bfc9c7fa1..001743ada 100644
--- a/src/block/seed/seed.h
+++ b/src/block/seed/seed.h
@@ -25,7 +25,7 @@ class BOTAN_DLL SEED : public BlockCipher
std::string name() const { return "SEED"; }
BlockCipher* clone() const { return new SEED; }
- SEED() : BlockCipher(16, 16) {}
+ SEED() : BlockCipher(16, 16), K(32) {}
private:
void key_schedule(const byte[], u32bit);
@@ -37,7 +37,7 @@ class BOTAN_DLL SEED : public BlockCipher
static const u32bit S0[256], S1[256], S2[256], S3[256];
};
- SecureVector<u32bit, 32> K;
+ SecureVector<u32bit> K;
};
}
diff --git a/src/block/serpent/serpent.cpp b/src/block/serpent/serpent.cpp
index 4979ecbab..4133750ad 100644
--- a/src/block/serpent/serpent.cpp
+++ b/src/block/serpent/serpent.cpp
@@ -355,7 +355,7 @@ void Serpent::key_schedule(const byte key[], u32bit length)
{
const u32bit PHI = 0x9E3779B9;
- SecureVector<u32bit, 140> W;
+ SecureVector<u32bit> W(140);
for(u32bit j = 0; j != length / 4; ++j)
W[j] = load_le<u32bit>(key, j);
diff --git a/src/block/serpent/serpent.h b/src/block/serpent/serpent.h
index 56afd3330..f980c602e 100644
--- a/src/block/serpent/serpent.h
+++ b/src/block/serpent/serpent.h
@@ -24,13 +24,13 @@ class BOTAN_DLL Serpent : public BlockCipher
void clear() { zeroise(round_key); }
std::string name() const { return "Serpent"; }
BlockCipher* clone() const { return new Serpent; }
- Serpent() : BlockCipher(16, 16, 32, 8) {}
+ Serpent() : BlockCipher(16, 16, 32, 8), round_key(132) {}
protected:
/**
* For use by subclasses using SIMD, asm, etc
* @return const reference to the key schedule
*/
- const SecureVector<u32bit, 132>& get_round_keys() const
+ const SecureVector<u32bit>& get_round_keys() const
{ return round_key; }
/**
@@ -42,7 +42,7 @@ class BOTAN_DLL Serpent : public BlockCipher
private:
void key_schedule(const byte key[], u32bit length);
- SecureVector<u32bit, 132> round_key;
+ SecureVector<u32bit> round_key;
};
}
diff --git a/src/block/skipjack/skipjack.h b/src/block/skipjack/skipjack.h
index 29978efc7..123ab85ae 100644
--- a/src/block/skipjack/skipjack.h
+++ b/src/block/skipjack/skipjack.h
@@ -25,11 +25,11 @@ class BOTAN_DLL Skipjack : public BlockCipher
std::string name() const { return "Skipjack"; }
BlockCipher* clone() const { return new Skipjack; }
- Skipjack() : BlockCipher(8, 10) {}
+ Skipjack() : BlockCipher(8, 10), FTAB(2560) {}
private:
void key_schedule(const byte[], u32bit);
- SecureVector<byte, 2560> FTAB;
+ SecureVector<byte> FTAB;
};
}
diff --git a/src/block/square/square.cpp b/src/block/square/square.cpp
index 2d798c3e8..4b6709d50 100644
--- a/src/block/square/square.cpp
+++ b/src/block/square/square.cpp
@@ -140,7 +140,7 @@ void Square::decrypt_n(const byte in[], byte out[], u32bit blocks) const
*/
void Square::key_schedule(const byte key[], u32bit)
{
- SecureVector<u32bit, 36> XEK, XDK;
+ SecureVector<u32bit> XEK(36), XDK(36);
for(u32bit i = 0; i != 4; ++i)
XEK[i] = load_be<u32bit>(key, i);
diff --git a/src/block/square/square.h b/src/block/square/square.h
index a17771f11..0c0cc871d 100644
--- a/src/block/square/square.h
+++ b/src/block/square/square.h
@@ -25,7 +25,7 @@ class BOTAN_DLL Square : public BlockCipher
std::string name() const { return "Square"; }
BlockCipher* clone() const { return new Square; }
- Square() : BlockCipher(16, 16) {}
+ Square() : BlockCipher(16, 16), EK(28), DK(28), ME(32), MD(32) {}
private:
void key_schedule(const byte[], u32bit);
@@ -45,8 +45,8 @@ class BOTAN_DLL Square : public BlockCipher
static const u32bit TD2[256];
static const u32bit TD3[256];
- SecureVector<u32bit, 28> EK, DK;
- SecureVector<byte, 32> ME, MD;
+ SecureVector<u32bit> EK, DK;
+ SecureVector<byte> ME, MD;
};
}
diff --git a/src/block/tea/tea.h b/src/block/tea/tea.h
index 6e1c4fafb..dd03ec3c6 100644
--- a/src/block/tea/tea.h
+++ b/src/block/tea/tea.h
@@ -25,10 +25,10 @@ class BOTAN_DLL TEA : public BlockCipher
std::string name() const { return "TEA"; }
BlockCipher* clone() const { return new TEA; }
- TEA() : BlockCipher(8, 16) {}
+ TEA() : BlockCipher(8, 16), K(4) {}
private:
void key_schedule(const byte[], u32bit);
- SecureVector<u32bit, 4> K;
+ SecureVector<u32bit> K;
};
}
diff --git a/src/block/twofish/twofish.cpp b/src/block/twofish/twofish.cpp
index 805695087..b760de382 100644
--- a/src/block/twofish/twofish.cpp
+++ b/src/block/twofish/twofish.cpp
@@ -18,42 +18,42 @@ void Twofish::encrypt_n(const byte in[], byte out[], u32bit blocks) const
{
for(u32bit i = 0; i != blocks; ++i)
{
- u32bit A = load_le<u32bit>(in, 0) ^ round_key[0];
- u32bit B = load_le<u32bit>(in, 1) ^ round_key[1];
- u32bit C = load_le<u32bit>(in, 2) ^ round_key[2];
- u32bit D = load_le<u32bit>(in, 3) ^ round_key[3];
+ u32bit A = load_le<u32bit>(in, 0) ^ RK[0];
+ u32bit B = load_le<u32bit>(in, 1) ^ RK[1];
+ u32bit C = load_le<u32bit>(in, 2) ^ RK[2];
+ u32bit D = load_le<u32bit>(in, 3) ^ RK[3];
for(u32bit j = 0; j != 16; j += 2)
{
u32bit X, Y;
- X = SBox0[get_byte(3, A)] ^ SBox1[get_byte(2, A)] ^
- SBox2[get_byte(1, A)] ^ SBox3[get_byte(0, A)];
- Y = SBox0[get_byte(0, B)] ^ SBox1[get_byte(3, B)] ^
- SBox2[get_byte(2, B)] ^ SBox3[get_byte(1, B)];
+ X = SB[ get_byte(3, A)] ^ SB[256+get_byte(2, A)] ^
+ SB[512+get_byte(1, A)] ^ SB[768+get_byte(0, A)];
+ Y = SB[ get_byte(0, B)] ^ SB[256+get_byte(3, B)] ^
+ SB[512+get_byte(2, B)] ^ SB[768+get_byte(1, B)];
X += Y;
- Y += X + round_key[2*j + 9];
- X += round_key[2*j + 8];
+ Y += X + RK[2*j + 9];
+ X += RK[2*j + 8];
C = rotate_right(C ^ X, 1);
D = rotate_left(D, 1) ^ Y;
- X = SBox0[get_byte(3, C)] ^ SBox1[get_byte(2, C)] ^
- SBox2[get_byte(1, C)] ^ SBox3[get_byte(0, C)];
- Y = SBox0[get_byte(0, D)] ^ SBox1[get_byte(3, D)] ^
- SBox2[get_byte(2, D)] ^ SBox3[get_byte(1, D)];
+ X = SB[ get_byte(3, C)] ^ SB[256+get_byte(2, C)] ^
+ SB[512+get_byte(1, C)] ^ SB[768+get_byte(0, C)];
+ Y = SB[ get_byte(0, D)] ^ SB[256+get_byte(3, D)] ^
+ SB[512+get_byte(2, D)] ^ SB[768+get_byte(1, D)];
X += Y;
- Y += X + round_key[2*j + 11];
- X += round_key[2*j + 10];
+ Y += X + RK[2*j + 11];
+ X += RK[2*j + 10];
A = rotate_right(A ^ X, 1);
B = rotate_left(B, 1) ^ Y;
}
- C ^= round_key[4];
- D ^= round_key[5];
- A ^= round_key[6];
- B ^= round_key[7];
+ C ^= RK[4];
+ D ^= RK[5];
+ A ^= RK[6];
+ B ^= RK[7];
store_le(out, C, D, A, B);
@@ -69,42 +69,42 @@ void Twofish::decrypt_n(const byte in[], byte out[], u32bit blocks) const
{
for(u32bit i = 0; i != blocks; ++i)
{
- u32bit A = load_le<u32bit>(in, 0) ^ round_key[4];
- u32bit B = load_le<u32bit>(in, 1) ^ round_key[5];
- u32bit C = load_le<u32bit>(in, 2) ^ round_key[6];
- u32bit D = load_le<u32bit>(in, 3) ^ round_key[7];
+ u32bit A = load_le<u32bit>(in, 0) ^ RK[4];
+ u32bit B = load_le<u32bit>(in, 1) ^ RK[5];
+ u32bit C = load_le<u32bit>(in, 2) ^ RK[6];
+ u32bit D = load_le<u32bit>(in, 3) ^ RK[7];
for(u32bit j = 0; j != 16; j += 2)
{
u32bit X, Y;
- X = SBox0[get_byte(3, A)] ^ SBox1[get_byte(2, A)] ^
- SBox2[get_byte(1, A)] ^ SBox3[get_byte(0, A)];
- Y = SBox0[get_byte(0, B)] ^ SBox1[get_byte(3, B)] ^
- SBox2[get_byte(2, B)] ^ SBox3[get_byte(1, B)];
+ X = SB[ get_byte(3, A)] ^ SB[256+get_byte(2, A)] ^
+ SB[512+get_byte(1, A)] ^ SB[768+get_byte(0, A)];
+ Y = SB[ get_byte(0, B)] ^ SB[256+get_byte(3, B)] ^
+ SB[512+get_byte(2, B)] ^ SB[768+get_byte(1, B)];
X += Y;
- Y += X + round_key[39 - 2*j];
- X += round_key[38 - 2*j];
+ Y += X + RK[39 - 2*j];
+ X += RK[38 - 2*j];
C = rotate_left(C, 1) ^ X;
D = rotate_right(D ^ Y, 1);
- X = SBox0[get_byte(3, C)] ^ SBox1[get_byte(2, C)] ^
- SBox2[get_byte(1, C)] ^ SBox3[get_byte(0, C)];
- Y = SBox0[get_byte(0, D)] ^ SBox1[get_byte(3, D)] ^
- SBox2[get_byte(2, D)] ^ SBox3[get_byte(1, D)];
+ X = SB[ get_byte(3, C)] ^ SB[256+get_byte(2, C)] ^
+ SB[512+get_byte(1, C)] ^ SB[768+get_byte(0, C)];
+ Y = SB[ get_byte(0, D)] ^ SB[256+get_byte(3, D)] ^
+ SB[512+get_byte(2, D)] ^ SB[768+get_byte(1, D)];
X += Y;
- Y += X + round_key[37 - 2*j];
- X += round_key[36 - 2*j];
+ Y += X + RK[37 - 2*j];
+ X += RK[36 - 2*j];
A = rotate_left(A, 1) ^ X;
B = rotate_right(B ^ Y, 1);
}
- C ^= round_key[0];
- D ^= round_key[1];
- A ^= round_key[2];
- B ^= round_key[3];
+ C ^= RK[0];
+ D ^= RK[1];
+ A ^= RK[2];
+ B ^= RK[3];
store_le(out, C, D, A, B);
@@ -118,78 +118,90 @@ void Twofish::decrypt_n(const byte in[], byte out[], u32bit blocks) const
*/
void Twofish::key_schedule(const byte key[], u32bit length)
{
- SecureVector<byte, 16> S;
+ SecureVector<byte> S(16);
- for(u32bit j = 0; j != length; ++j)
- rs_mul(&S[4*(j/8)], key[j], j);
+ for(u32bit i = 0; i != length; ++i)
+ rs_mul(&S[4*(i/8)], key[i], i);
if(length == 16)
{
- for(u32bit j = 0; j != 256; ++j)
+ for(u32bit i = 0; i != 256; ++i)
{
- SBox0[j] = MDS0[Q0[Q0[j]^S[ 0]]^S[ 4]];
- SBox1[j] = MDS1[Q0[Q1[j]^S[ 1]]^S[ 5]];
- SBox2[j] = MDS2[Q1[Q0[j]^S[ 2]]^S[ 6]];
- SBox3[j] = MDS3[Q1[Q1[j]^S[ 3]]^S[ 7]];
+ SB[ i] = MDS0[Q0[Q0[i]^S[ 0]]^S[ 4]];
+ SB[256+i] = MDS1[Q0[Q1[i]^S[ 1]]^S[ 5]];
+ SB[512+i] = MDS2[Q1[Q0[i]^S[ 2]]^S[ 6]];
+ SB[768+i] = MDS3[Q1[Q1[i]^S[ 3]]^S[ 7]];
}
- for(u32bit j = 0; j != 40; j += 2)
+
+ for(u32bit i = 0; i != 40; i += 2)
{
- u32bit X = MDS0[Q0[Q0[j ]^key[ 8]]^key[ 0]] ^
- MDS1[Q0[Q1[j ]^key[ 9]]^key[ 1]] ^
- MDS2[Q1[Q0[j ]^key[10]]^key[ 2]] ^
- MDS3[Q1[Q1[j ]^key[11]]^key[ 3]];
- u32bit Y = MDS0[Q0[Q0[j+1]^key[12]]^key[ 4]] ^
- MDS1[Q0[Q1[j+1]^key[13]]^key[ 5]] ^
- MDS2[Q1[Q0[j+1]^key[14]]^key[ 6]] ^
- MDS3[Q1[Q1[j+1]^key[15]]^key[ 7]];
- Y = rotate_left(Y, 8); X += Y; Y += X;
- round_key[j] = X; round_key[j+1] = rotate_left(Y, 9);
+ u32bit X = MDS0[Q0[Q0[i ]^key[ 8]]^key[ 0]] ^
+ MDS1[Q0[Q1[i ]^key[ 9]]^key[ 1]] ^
+ MDS2[Q1[Q0[i ]^key[10]]^key[ 2]] ^
+ MDS3[Q1[Q1[i ]^key[11]]^key[ 3]];
+ u32bit Y = MDS0[Q0[Q0[i+1]^key[12]]^key[ 4]] ^
+ MDS1[Q0[Q1[i+1]^key[13]]^key[ 5]] ^
+ MDS2[Q1[Q0[i+1]^key[14]]^key[ 6]] ^
+ MDS3[Q1[Q1[i+1]^key[15]]^key[ 7]];
+ Y = rotate_left(Y, 8);
+ X += Y; Y += X;
+
+ RK[i] = X;
+ RK[i+1] = rotate_left(Y, 9);
}
}
else if(length == 24)
{
- for(u32bit j = 0; j != 256; ++j)
+ for(u32bit i = 0; i != 256; ++i)
{
- SBox0[j] = MDS0[Q0[Q0[Q1[j]^S[ 0]]^S[ 4]]^S[ 8]];
- SBox1[j] = MDS1[Q0[Q1[Q1[j]^S[ 1]]^S[ 5]]^S[ 9]];
- SBox2[j] = MDS2[Q1[Q0[Q0[j]^S[ 2]]^S[ 6]]^S[10]];
- SBox3[j] = MDS3[Q1[Q1[Q0[j]^S[ 3]]^S[ 7]]^S[11]];
+ SB[ i] = MDS0[Q0[Q0[Q1[i]^S[ 0]]^S[ 4]]^S[ 8]];
+ SB[256+i] = MDS1[Q0[Q1[Q1[i]^S[ 1]]^S[ 5]]^S[ 9]];
+ SB[512+i] = MDS2[Q1[Q0[Q0[i]^S[ 2]]^S[ 6]]^S[10]];
+ SB[768+i] = MDS3[Q1[Q1[Q0[i]^S[ 3]]^S[ 7]]^S[11]];
}
- for(u32bit j = 0; j != 40; j += 2)
+
+ for(u32bit i = 0; i != 40; i += 2)
{
- u32bit X = MDS0[Q0[Q0[Q1[j ]^key[16]]^key[ 8]]^key[ 0]] ^
- MDS1[Q0[Q1[Q1[j ]^key[17]]^key[ 9]]^key[ 1]] ^
- MDS2[Q1[Q0[Q0[j ]^key[18]]^key[10]]^key[ 2]] ^
- MDS3[Q1[Q1[Q0[j ]^key[19]]^key[11]]^key[ 3]];
- u32bit Y = MDS0[Q0[Q0[Q1[j+1]^key[20]]^key[12]]^key[ 4]] ^
- MDS1[Q0[Q1[Q1[j+1]^key[21]]^key[13]]^key[ 5]] ^
- MDS2[Q1[Q0[Q0[j+1]^key[22]]^key[14]]^key[ 6]] ^
- MDS3[Q1[Q1[Q0[j+1]^key[23]]^key[15]]^key[ 7]];
- Y = rotate_left(Y, 8); X += Y; Y += X;
- round_key[j] = X; round_key[j+1] = rotate_left(Y, 9);
+ u32bit X = MDS0[Q0[Q0[Q1[i ]^key[16]]^key[ 8]]^key[ 0]] ^
+ MDS1[Q0[Q1[Q1[i ]^key[17]]^key[ 9]]^key[ 1]] ^
+ MDS2[Q1[Q0[Q0[i ]^key[18]]^key[10]]^key[ 2]] ^
+ MDS3[Q1[Q1[Q0[i ]^key[19]]^key[11]]^key[ 3]];
+ u32bit Y = MDS0[Q0[Q0[Q1[i+1]^key[20]]^key[12]]^key[ 4]] ^
+ MDS1[Q0[Q1[Q1[i+1]^key[21]]^key[13]]^key[ 5]] ^
+ MDS2[Q1[Q0[Q0[i+1]^key[22]]^key[14]]^key[ 6]] ^
+ MDS3[Q1[Q1[Q0[i+1]^key[23]]^key[15]]^key[ 7]];
+ Y = rotate_left(Y, 8);
+ X += Y; Y += X;
+
+ RK[i] = X;
+ RK[i+1] = rotate_left(Y, 9);
}
}
else if(length == 32)
{
- for(u32bit j = 0; j != 256; ++j)
+ for(u32bit i = 0; i != 256; ++i)
{
- SBox0[j] = MDS0[Q0[Q0[Q1[Q1[j]^S[ 0]]^S[ 4]]^S[ 8]]^S[12]];
- SBox1[j] = MDS1[Q0[Q1[Q1[Q0[j]^S[ 1]]^S[ 5]]^S[ 9]]^S[13]];
- SBox2[j] = MDS2[Q1[Q0[Q0[Q0[j]^S[ 2]]^S[ 6]]^S[10]]^S[14]];
- SBox3[j] = MDS3[Q1[Q1[Q0[Q1[j]^S[ 3]]^S[ 7]]^S[11]]^S[15]];
+ SB[ i] = MDS0[Q0[Q0[Q1[Q1[i]^S[ 0]]^S[ 4]]^S[ 8]]^S[12]];
+ SB[256+i] = MDS1[Q0[Q1[Q1[Q0[i]^S[ 1]]^S[ 5]]^S[ 9]]^S[13]];
+ SB[512+i] = MDS2[Q1[Q0[Q0[Q0[i]^S[ 2]]^S[ 6]]^S[10]]^S[14]];
+ SB[768+i] = MDS3[Q1[Q1[Q0[Q1[i]^S[ 3]]^S[ 7]]^S[11]]^S[15]];
}
- for(u32bit j = 0; j != 40; j += 2)
+
+ for(u32bit i = 0; i != 40; i += 2)
{
- u32bit X = MDS0[Q0[Q0[Q1[Q1[j ]^key[24]]^key[16]]^key[ 8]]^key[ 0]] ^
- MDS1[Q0[Q1[Q1[Q0[j ]^key[25]]^key[17]]^key[ 9]]^key[ 1]] ^
- MDS2[Q1[Q0[Q0[Q0[j ]^key[26]]^key[18]]^key[10]]^key[ 2]] ^
- MDS3[Q1[Q1[Q0[Q1[j ]^key[27]]^key[19]]^key[11]]^key[ 3]];
- u32bit Y = MDS0[Q0[Q0[Q1[Q1[j+1]^key[28]]^key[20]]^key[12]]^key[ 4]] ^
- MDS1[Q0[Q1[Q1[Q0[j+1]^key[29]]^key[21]]^key[13]]^key[ 5]] ^
- MDS2[Q1[Q0[Q0[Q0[j+1]^key[30]]^key[22]]^key[14]]^key[ 6]] ^
- MDS3[Q1[Q1[Q0[Q1[j+1]^key[31]]^key[23]]^key[15]]^key[ 7]];
- Y = rotate_left(Y, 8); X += Y; Y += X;
- round_key[j] = X; round_key[j+1] = rotate_left(Y, 9);
+ u32bit X = MDS0[Q0[Q0[Q1[Q1[i ]^key[24]]^key[16]]^key[ 8]]^key[ 0]] ^
+ MDS1[Q0[Q1[Q1[Q0[i ]^key[25]]^key[17]]^key[ 9]]^key[ 1]] ^
+ MDS2[Q1[Q0[Q0[Q0[i ]^key[26]]^key[18]]^key[10]]^key[ 2]] ^
+ MDS3[Q1[Q1[Q0[Q1[i ]^key[27]]^key[19]]^key[11]]^key[ 3]];
+ u32bit Y = MDS0[Q0[Q0[Q1[Q1[i+1]^key[28]]^key[20]]^key[12]]^key[ 4]] ^
+ MDS1[Q0[Q1[Q1[Q0[i+1]^key[29]]^key[21]]^key[13]]^key[ 5]] ^
+ MDS2[Q1[Q0[Q0[Q0[i+1]^key[30]]^key[22]]^key[14]]^key[ 6]] ^
+ MDS3[Q1[Q1[Q0[Q1[i+1]^key[31]]^key[23]]^key[15]]^key[ 7]];
+ Y = rotate_left(Y, 8);
+ X += Y; Y += X;
+
+ RK[i] = X;
+ RK[i+1] = rotate_left(Y, 9);
}
}
}
@@ -220,11 +232,8 @@ void Twofish::rs_mul(byte S[4], byte key, u32bit offset)
*/
void Twofish::clear()
{
- zeroise(SBox0);
- zeroise(SBox1);
- zeroise(SBox2);
- zeroise(SBox3);
- zeroise(round_key);
+ zeroise(SB);
+ zeroise(RK);
}
}
diff --git a/src/block/twofish/twofish.h b/src/block/twofish/twofish.h
index 3191dc963..eb4900ffa 100644
--- a/src/block/twofish/twofish.h
+++ b/src/block/twofish/twofish.h
@@ -25,7 +25,7 @@ class BOTAN_DLL Twofish : public BlockCipher
std::string name() const { return "Twofish"; }
BlockCipher* clone() const { return new Twofish; }
- Twofish() : BlockCipher(16, 16, 32, 8) {}
+ Twofish() : BlockCipher(16, 16, 32, 8), SB(1024), RK(40) {}
private:
void key_schedule(const byte[], u32bit);
@@ -41,8 +41,7 @@ class BOTAN_DLL Twofish : public BlockCipher
static const byte EXP_TO_POLY[255];
static const byte POLY_TO_EXP[255];
- SecureVector<u32bit, 256> SBox0, SBox1, SBox2, SBox3;
- SecureVector<u32bit, 40> round_key;
+ SecureVector<u32bit> SB, RK;
};
}
diff --git a/src/block/xtea/xtea.cpp b/src/block/xtea/xtea.cpp
index 03e9f628c..9e47e5328 100644
--- a/src/block/xtea/xtea.cpp
+++ b/src/block/xtea/xtea.cpp
@@ -121,7 +121,7 @@ void XTEA::decrypt_n(const byte in[], byte out[], u32bit blocks) const
*/
void XTEA::key_schedule(const byte key[], u32bit)
{
- SecureVector<u32bit, 4> UK;
+ SecureVector<u32bit> UK(4);
for(u32bit i = 0; i != 4; ++i)
UK[i] = load_be<u32bit>(key, i);
diff --git a/src/block/xtea/xtea.h b/src/block/xtea/xtea.h
index d328bf2f0..54c925df2 100644
--- a/src/block/xtea/xtea.h
+++ b/src/block/xtea/xtea.h
@@ -25,16 +25,16 @@ class BOTAN_DLL XTEA : public BlockCipher
std::string name() const { return "XTEA"; }
BlockCipher* clone() const { return new XTEA; }
- XTEA() : BlockCipher(8, 16) {}
+ XTEA() : BlockCipher(8, 16), EK(64) {}
protected:
/**
* @return const reference to the key schedule
*/
- const SecureVector<u32bit, 64>& get_EK() const { return EK; }
+ const SecureVector<u32bit>& get_EK() const { return EK; }
private:
void key_schedule(const byte[], u32bit);
- SecureVector<u32bit, 64> EK;
+ SecureVector<u32bit> EK;
};
}