aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-09-14 01:16:32 +0000
committerlloyd <[email protected]>2010-09-14 01:16:32 +0000
commitae59295ea945fdcc482df2233409a5f878fa20c7 (patch)
tree768c30635a17847dccb6db6f36fa3b033adc37bf
parent548f48611760346fa2e47efd5c0865eff831946a (diff)
Completely remove the second parameter to SecureVector which specifies
the initial/default length of the array, update all users to instead pass the value to the constructor. This is a old vestigal thing from a class (SecureBuffer) that used this compile-time constant in order to store the values in an array. However this was changed way back in 2002 to use the same allocator hooks as the rest of the containers, so the only advantage to using the length field was that the initial length was set and didn't have to be set in the constructor which was midly convenient. However this directly conflicts with the desire to be able to (eventually) use std::vector with a custom allocator, since of course vector doesn't support this. Fortunately almost all of the uses are in classes which have only a single constructor, so there is little to no duplication by instead initializing the size in the constructor.
-rw-r--r--src/alloc/secmem.h19
-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
-rw-r--r--src/filters/base64/base64.cpp6
-rw-r--r--src/filters/secqueue.cpp6
-rw-r--r--src/hash/bmw/bmw_512.h7
-rw-r--r--src/hash/gost_3411/gost_3411.cpp9
-rw-r--r--src/hash/gost_3411/gost_3411.h4
-rw-r--r--src/hash/has160/has160.h7
-rw-r--r--src/hash/md2/md2.h7
-rw-r--r--src/hash/md4/md4.h7
-rw-r--r--src/hash/md5/md5.h7
-rw-r--r--src/hash/rmd128/rmd128.h7
-rw-r--r--src/hash/rmd160/rmd160.h7
-rw-r--r--src/hash/sha1/sha160.cpp4
-rw-r--r--src/hash/sha1/sha160.h2
-rw-r--r--src/hash/sha2/sha2_32.h14
-rw-r--r--src/hash/sha2/sha2_64.h13
-rw-r--r--src/hash/skein/skein_512.cpp6
-rw-r--r--src/hash/skein/skein_512.h6
-rw-r--r--src/hash/tiger/tiger.cpp5
-rw-r--r--src/hash/tiger/tiger.h3
-rw-r--r--src/hash/whirlpool/whrlpool.h7
-rw-r--r--src/mac/x919_mac/x919_mac.cpp2
-rw-r--r--src/mac/x919_mac/x919_mac.h2
-rw-r--r--src/stream/arc4/arc4.cpp3
-rw-r--r--src/stream/arc4/arc4.h4
-rw-r--r--src/stream/salsa20/salsa20.h6
-rw-r--r--src/stream/turing/turing.h13
-rw-r--r--src/stream/wid_wake/wid_wake.h15
68 files changed, 313 insertions, 272 deletions
diff --git a/src/alloc/secmem.h b/src/alloc/secmem.h
index 9b533eac0..e92efe9a0 100644
--- a/src/alloc/secmem.h
+++ b/src/alloc/secmem.h
@@ -333,7 +333,7 @@ class MemoryVector : public MemoryRegion<T>
* swapped out to disk. In this way, a security hole allowing attackers
* to find swapped out secret keys is closed.
*/
-template<typename T, u32bit INITIAL_LEN = 0>
+template<typename T>
class SecureVector : public MemoryRegion<T>
{
public:
@@ -349,8 +349,7 @@ class SecureVector : public MemoryRegion<T>
* Create a buffer of the specified length.
* @param n the length of the buffer to create.
*/
- SecureVector(u32bit n = INITIAL_LEN)
- { this->init(true, n); }
+ SecureVector(u32bit n = 0) { this->init(true, n); }
/**
* Create a buffer with the specified contents.
@@ -360,11 +359,8 @@ class SecureVector : public MemoryRegion<T>
*/
SecureVector(const T in[], u32bit n)
{
- this->init(true, INITIAL_LEN);
- if(INITIAL_LEN)
- this->copy(&in[0], n);
- else
- this->set(&in[0], n);
+ this->init(true);
+ this->set(&in[0], n);
}
/**
@@ -374,11 +370,8 @@ class SecureVector : public MemoryRegion<T>
*/
SecureVector(const MemoryRegion<T>& in)
{
- this->init(true, INITIAL_LEN);
- if(INITIAL_LEN)
- this->copy(&in[0], in.size());
- else
- this->set(&in[0], in.size());
+ this->init(true);
+ this->set(&in[0], in.size());
}
};
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;
};
}
diff --git a/src/filters/base64/base64.cpp b/src/filters/base64/base64.cpp
index e342f7109..5f365ca5a 100644
--- a/src/filters/base64/base64.cpp
+++ b/src/filters/base64/base64.cpp
@@ -107,7 +107,8 @@ void Base64_Encoder::end_msg()
if(left_over)
{
- SecureVector<byte, 3> remainder(in + start_of_last_block, left_over);
+ SecureVector<byte> remainder(3);
+ copy_mem(&remainder[0], &in[start_of_last_block], left_over);
encode(remainder, out);
@@ -217,7 +218,8 @@ void Base64_Decoder::end_msg()
if(left_over)
{
- SecureVector<byte, 4> remainder(in + start_of_last_block, left_over);
+ SecureVector<byte> remainder(4);
+ copy_mem(&remainder[0], &in[start_of_last_block], left_over);
decode(remainder, out);
send(out, ((left_over == 1) ? (1) : (left_over - 1)));
}
diff --git a/src/filters/secqueue.cpp b/src/filters/secqueue.cpp
index db0366bc8..bfe02b0d3 100644
--- a/src/filters/secqueue.cpp
+++ b/src/filters/secqueue.cpp
@@ -16,7 +16,9 @@ namespace Botan {
class SecureQueueNode
{
public:
- SecureQueueNode() { next = 0; start = end = 0; }
+ SecureQueueNode() : buffer(DEFAULT_BUFFERSIZE)
+ { next = 0; start = end = 0; }
+
~SecureQueueNode() { next = 0; start = end = 0; }
u32bit write(const byte input[], u32bit length)
@@ -48,7 +50,7 @@ class SecureQueueNode
private:
friend class SecureQueue;
SecureQueueNode* next;
- SecureVector<byte, DEFAULT_BUFFERSIZE> buffer;
+ SecureVector<byte> buffer;
u32bit start, end;
};
diff --git a/src/hash/bmw/bmw_512.h b/src/hash/bmw/bmw_512.h
index d3c9c03c6..b1eaa6874 100644
--- a/src/hash/bmw/bmw_512.h
+++ b/src/hash/bmw/bmw_512.h
@@ -21,13 +21,14 @@ class BOTAN_DLL BMW_512 : public MDx_HashFunction
void clear();
std::string name() const { return "BMW512"; }
HashFunction* clone() const { return new BMW_512; }
- BMW_512() : MDx_HashFunction(64, 128, false, true) { clear(); }
+
+ BMW_512() : MDx_HashFunction(64, 128, false, true), H(16), M(16), Q(32)
+ { clear(); }
private:
void compress_n(const byte input[], u32bit blocks);
void copy_out(byte output[]);
- SecureVector<u64bit, 16> H, M;
- SecureVector<u64bit, 32> Q;
+ SecureVector<u64bit> H, M, Q;
};
}
diff --git a/src/hash/gost_3411/gost_3411.cpp b/src/hash/gost_3411/gost_3411.cpp
index ad874fe8a..ee43514d5 100644
--- a/src/hash/gost_3411/gost_3411.cpp
+++ b/src/hash/gost_3411/gost_3411.cpp
@@ -17,7 +17,10 @@ namespace Botan {
*/
GOST_34_11::GOST_34_11() :
HashFunction(32, 32),
- cipher(GOST_28147_89_Params("R3411_CryptoPro"))
+ cipher(GOST_28147_89_Params("R3411_CryptoPro")),
+ buffer(32),
+ sum(32),
+ hash(32)
{
count = 0;
position = 0;
@@ -223,11 +226,11 @@ void GOST_34_11::final_result(byte out[])
compress_n(buffer, 1);
}
- SecureVector<byte, 32> length_buf;
+ SecureVector<byte> length_buf(32);
const u64bit bit_count = count * 8;
store_le(bit_count, length_buf);
- SecureVector<byte, 32> sum_buf(sum);
+ SecureVector<byte> sum_buf = sum;
compress_n(length_buf, 1);
compress_n(sum_buf, 1);
diff --git a/src/hash/gost_3411/gost_3411.h b/src/hash/gost_3411/gost_3411.h
index 04417d6fd..5d26e8557 100644
--- a/src/hash/gost_3411/gost_3411.h
+++ b/src/hash/gost_3411/gost_3411.h
@@ -31,9 +31,7 @@ class BOTAN_DLL GOST_34_11 : public HashFunction
void final_result(byte[]);
GOST_28147_89 cipher;
- SecureVector<byte, 32> buffer;
- SecureVector<byte, 32> sum;
- SecureVector<byte, 32> hash;
+ SecureVector<byte> buffer, sum, hash;
u64bit count;
u32bit position;
};
diff --git a/src/hash/has160/has160.h b/src/hash/has160/has160.h
index a82e4c579..7cff320b8 100644
--- a/src/hash/has160/has160.h
+++ b/src/hash/has160/has160.h
@@ -22,13 +22,14 @@ class BOTAN_DLL HAS_160 : public MDx_HashFunction
void clear();
std::string name() const { return "HAS-160"; }
HashFunction* clone() const { return new HAS_160; }
- HAS_160() : MDx_HashFunction(20, 64, false, true) { clear(); }
+
+ HAS_160() : MDx_HashFunction(20, 64, false, true), X(20), digest(5)
+ { clear(); }
private:
void compress_n(const byte[], u32bit blocks);
void copy_out(byte[]);
- SecureVector<u32bit, 20> X;
- SecureVector<u32bit, 5> digest;
+ SecureVector<u32bit> X, digest;
};
}
diff --git a/src/hash/md2/md2.h b/src/hash/md2/md2.h
index 9d39d8913..b25d5f410 100644
--- a/src/hash/md2/md2.h
+++ b/src/hash/md2/md2.h
@@ -21,14 +21,15 @@ class BOTAN_DLL MD2 : public HashFunction
void clear();
std::string name() const { return "MD2"; }
HashFunction* clone() const { return new MD2; }
- MD2() : HashFunction(16, 16) { clear(); }
+
+ MD2() : HashFunction(16, 16), X(48), checksum(16), buffer(16)
+ { clear(); }
private:
void add_data(const byte[], u32bit);
void hash(const byte[]);
void final_result(byte[]);
- SecureVector<byte, 48> X;
- SecureVector<byte, 16> checksum, buffer;
+ SecureVector<byte> X, checksum, buffer;
u32bit position;
};
diff --git a/src/hash/md4/md4.h b/src/hash/md4/md4.h
index 44d60406a..44081e635 100644
--- a/src/hash/md4/md4.h
+++ b/src/hash/md4/md4.h
@@ -21,13 +21,14 @@ class BOTAN_DLL MD4 : public MDx_HashFunction
void clear();
std::string name() const { return "MD4"; }
HashFunction* clone() const { return new MD4; }
- MD4() : MDx_HashFunction(16, 64, false, true) { clear(); }
+
+ MD4() : MDx_HashFunction(16, 64, false, true), M(16), digest(4)
+ { clear(); }
protected:
void compress_n(const byte input[], u32bit blocks);
void copy_out(byte[]);
- SecureVector<u32bit, 16> M;
- SecureVector<u32bit, 4> digest;
+ SecureVector<u32bit> M, digest;
};
}
diff --git a/src/hash/md5/md5.h b/src/hash/md5/md5.h
index d0706ab4b..732ec026d 100644
--- a/src/hash/md5/md5.h
+++ b/src/hash/md5/md5.h
@@ -21,13 +21,14 @@ class BOTAN_DLL MD5 : public MDx_HashFunction
void clear();
std::string name() const { return "MD5"; }
HashFunction* clone() const { return new MD5; }
- MD5() : MDx_HashFunction(16, 64, false, true) { clear(); }
+
+ MD5() : MDx_HashFunction(16, 64, false, true), M(16), digest(4)
+ { clear(); }
protected:
void compress_n(const byte[], u32bit blocks);
void copy_out(byte[]);
- SecureVector<u32bit, 16> M;
- SecureVector<u32bit, 4> digest;
+ SecureVector<u32bit> M, digest;
};
}
diff --git a/src/hash/rmd128/rmd128.h b/src/hash/rmd128/rmd128.h
index c7c7f4580..23272c622 100644
--- a/src/hash/rmd128/rmd128.h
+++ b/src/hash/rmd128/rmd128.h
@@ -21,13 +21,14 @@ class BOTAN_DLL RIPEMD_128 : public MDx_HashFunction
void clear();
std::string name() const { return "RIPEMD-128"; }
HashFunction* clone() const { return new RIPEMD_128; }
- RIPEMD_128() : MDx_HashFunction(16, 64, false, true) { clear(); }
+
+ RIPEMD_128() : MDx_HashFunction(16, 64, false, true), M(16), digest(4)
+ { clear(); }
private:
void compress_n(const byte[], u32bit blocks);
void copy_out(byte[]);
- SecureVector<u32bit, 16> M;
- SecureVector<u32bit, 4> digest;
+ SecureVector<u32bit> M, digest;
};
}
diff --git a/src/hash/rmd160/rmd160.h b/src/hash/rmd160/rmd160.h
index 0b6e847f0..09c995628 100644
--- a/src/hash/rmd160/rmd160.h
+++ b/src/hash/rmd160/rmd160.h
@@ -21,13 +21,14 @@ class BOTAN_DLL RIPEMD_160 : public MDx_HashFunction
void clear();
std::string name() const { return "RIPEMD-160"; }
HashFunction* clone() const { return new RIPEMD_160; }
- RIPEMD_160() : MDx_HashFunction(20, 64, false, true) { clear(); }
+
+ RIPEMD_160() : MDx_HashFunction(20, 64, false, true), M(16), digest(5)
+ { clear(); }
private:
void compress_n(const byte[], u32bit blocks);
void copy_out(byte[]);
- SecureVector<u32bit, 16> M;
- SecureVector<u32bit, 5> digest;
+ SecureVector<u32bit> M, digest;
};
}
diff --git a/src/hash/sha1/sha160.cpp b/src/hash/sha1/sha160.cpp
index 0b3d7c346..79348a371 100644
--- a/src/hash/sha1/sha160.cpp
+++ b/src/hash/sha1/sha160.cpp
@@ -156,7 +156,7 @@ void SHA_160::clear()
* SHA_160 Constructor
*/
SHA_160::SHA_160() :
- MDx_HashFunction(20, 64, true, true), W(80)
+ MDx_HashFunction(20, 64, true, true), digest(5), W(80)
{
clear();
}
@@ -165,7 +165,7 @@ SHA_160::SHA_160() :
* SHA_160 Constructor
*/
SHA_160::SHA_160(u32bit W_size) :
- MDx_HashFunction(20, 64, true, true), W(W_size)
+ MDx_HashFunction(20, 64, true, true), digest(5), W(W_size)
{
clear();
}
diff --git a/src/hash/sha1/sha160.h b/src/hash/sha1/sha160.h
index c66831a1e..690aea1d5 100644
--- a/src/hash/sha1/sha160.h
+++ b/src/hash/sha1/sha160.h
@@ -35,7 +35,7 @@ class BOTAN_DLL SHA_160 : public MDx_HashFunction
void compress_n(const byte[], u32bit blocks);
void copy_out(byte[]);
- SecureVector<u32bit, 5> digest;
+ SecureVector<u32bit> digest;
SecureVector<u32bit> W;
};
diff --git a/src/hash/sha2/sha2_32.h b/src/hash/sha2/sha2_32.h
index 71f0cff4b..a3e3a6f19 100644
--- a/src/hash/sha2/sha2_32.h
+++ b/src/hash/sha2/sha2_32.h
@@ -22,13 +22,14 @@ class BOTAN_DLL SHA_224 : public MDx_HashFunction
void clear();
std::string name() const { return "SHA-224"; }
HashFunction* clone() const { return new SHA_224; }
- SHA_224() : MDx_HashFunction(28, 64, true, true) { clear(); }
+
+ SHA_224() : MDx_HashFunction(28, 64, true, true), W(64), digest(8)
+ { clear(); }
private:
void compress_n(const byte[], u32bit blocks);
void copy_out(byte[]);
- SecureVector<u32bit, 64> W;
- SecureVector<u32bit, 8> digest;
+ SecureVector<u32bit> W, digest;
};
/**
@@ -40,13 +41,14 @@ class BOTAN_DLL SHA_256 : public MDx_HashFunction
void clear();
std::string name() const { return "SHA-256"; }
HashFunction* clone() const { return new SHA_256; }
- SHA_256() : MDx_HashFunction(32, 64, true, true) { clear(); }
+
+ SHA_256() : MDx_HashFunction(32, 64, true, true), W(64), digest(8)
+ { clear(); }
private:
void compress_n(const byte[], u32bit blocks);
void copy_out(byte[]);
- SecureVector<u32bit, 64> W;
- SecureVector<u32bit, 8> digest;
+ SecureVector<u32bit> W, digest;
};
}
diff --git a/src/hash/sha2/sha2_64.h b/src/hash/sha2/sha2_64.h
index e8112595e..726712221 100644
--- a/src/hash/sha2/sha2_64.h
+++ b/src/hash/sha2/sha2_64.h
@@ -21,13 +21,14 @@ class BOTAN_DLL SHA_384 : public MDx_HashFunction
void clear();
std::string name() const { return "SHA-384"; }
HashFunction* clone() const { return new SHA_384; }
- SHA_384() : MDx_HashFunction(48, 128, true, true, 16) { clear(); }
+
+ SHA_384() : MDx_HashFunction(48, 128, true, true, 16), W(80), digest(8)
+ { clear(); }
private:
void compress_n(const byte[], u32bit blocks);
void copy_out(byte[]);
- SecureVector<u64bit, 80> W;
- SecureVector<u64bit, 8> digest;
+ SecureVector<u64bit> W, digest;
};
/**
@@ -39,13 +40,13 @@ class BOTAN_DLL SHA_512 : public MDx_HashFunction
void clear();
std::string name() const { return "SHA-512"; }
HashFunction* clone() const { return new SHA_512; }
- SHA_512() : MDx_HashFunction(64, 128, true, true, 16) { clear(); }
+ SHA_512() : MDx_HashFunction(64, 128, true, true, 16), W(80), digest(8)
+ { clear(); }
private:
void compress_n(const byte[], u32bit blocks);
void copy_out(byte[]);
- SecureVector<u64bit, 80> W;
- SecureVector<u64bit, 8> digest;
+ SecureVector<u64bit> W, digest;
};
}
diff --git a/src/hash/skein/skein_512.cpp b/src/hash/skein/skein_512.cpp
index 5aa49ab7a..a3aff52ab 100644
--- a/src/hash/skein/skein_512.cpp
+++ b/src/hash/skein/skein_512.cpp
@@ -170,12 +170,12 @@ Skein_512::Skein_512(u32bit arg_output_bits,
const std::string& arg_personalization) :
HashFunction(arg_output_bits / 8, 64),
personalization(arg_personalization),
- output_bits(arg_output_bits)
+ output_bits(arg_output_bits),
+ H(9), T(3), buffer(64), buf_pos(0)
{
if(output_bits == 0 || output_bits % 8 != 0)
throw Invalid_Argument("Bad output bits size for Skein-512");
- buf_pos = 0;
initial_block(H, T, output_bits, personalization);
}
@@ -239,7 +239,7 @@ void Skein_512::final_result(byte out[])
u32bit out_bytes = output_bits / 8;
- SecureVector<u64bit, 9> H_out;
+ SecureVector<u64bit> H_out(9);
while(out_bytes)
{
diff --git a/src/hash/skein/skein_512.h b/src/hash/skein/skein_512.h
index 5d17fa564..811b633eb 100644
--- a/src/hash/skein/skein_512.h
+++ b/src/hash/skein/skein_512.h
@@ -37,10 +37,10 @@ class BOTAN_DLL Skein_512 : public HashFunction
std::string personalization;
u32bit output_bits;
- SecureVector<u64bit, 9> H;
- SecureVector<u64bit, 3> T;
- SecureVector<byte, 64> buffer;
+ SecureVector<u64bit> H;
+ SecureVector<u64bit> T;
+ SecureVector<byte> buffer;
u32bit buf_pos;
};
diff --git a/src/hash/tiger/tiger.cpp b/src/hash/tiger/tiger.cpp
index d931324e0..9d3e2cbe4 100644
--- a/src/hash/tiger/tiger.cpp
+++ b/src/hash/tiger/tiger.cpp
@@ -167,7 +167,10 @@ std::string Tiger::name() const
* Tiger Constructor
*/
Tiger::Tiger(u32bit hashlen, u32bit pass) :
- MDx_HashFunction(hashlen, 64, false, false), PASS(pass)
+ MDx_HashFunction(hashlen, 64, false, false),
+ X(8),
+ digest(3),
+ PASS(pass)
{
if(OUTPUT_LENGTH != 16 && OUTPUT_LENGTH != 20 && OUTPUT_LENGTH != 24)
throw Invalid_Argument("Tiger: Illegal hash output size: " +
diff --git a/src/hash/tiger/tiger.h b/src/hash/tiger/tiger.h
index 94665b902..4b8a99344 100644
--- a/src/hash/tiger/tiger.h
+++ b/src/hash/tiger/tiger.h
@@ -44,8 +44,7 @@ class BOTAN_DLL Tiger : public MDx_HashFunction
static const u64bit SBOX3[256];
static const u64bit SBOX4[256];
- SecureVector<u64bit, 8> X;
- SecureVector<u64bit, 3> digest;
+ SecureVector<u64bit> X, digest;
const u32bit PASS;
};
diff --git a/src/hash/whirlpool/whrlpool.h b/src/hash/whirlpool/whrlpool.h
index e28053d4f..98be0b480 100644
--- a/src/hash/whirlpool/whrlpool.h
+++ b/src/hash/whirlpool/whrlpool.h
@@ -21,7 +21,9 @@ class BOTAN_DLL Whirlpool : public MDx_HashFunction
void clear();
std::string name() const { return "Whirlpool"; }
HashFunction* clone() const { return new Whirlpool; }
- Whirlpool() : MDx_HashFunction(64, 64, true, true, 32) { clear(); }
+
+ Whirlpool() : MDx_HashFunction(64, 64, true, true, 32), M(8), digest(8)
+ { clear(); }
private:
void compress_n(const byte[], u32bit blocks);
void copy_out(byte[]);
@@ -34,7 +36,8 @@ class BOTAN_DLL Whirlpool : public MDx_HashFunction
static const u64bit C5[256];
static const u64bit C6[256];
static const u64bit C7[256];
- SecureVector<u64bit, 8> M, digest;
+
+ SecureVector<u64bit> M, digest;
};
}
diff --git a/src/mac/x919_mac/x919_mac.cpp b/src/mac/x919_mac/x919_mac.cpp
index f0c2419fa..975b195f6 100644
--- a/src/mac/x919_mac/x919_mac.cpp
+++ b/src/mac/x919_mac/x919_mac.cpp
@@ -89,7 +89,7 @@ ANSI_X919_MAC::ANSI_X919_MAC(BlockCipher* e_in) :
e_in->MINIMUM_KEYLENGTH,
2*e_in->MAXIMUM_KEYLENGTH,
2*e_in->KEYLENGTH_MULTIPLE),
- e(e_in), d(e->clone()), position(0)
+ e(e_in), d(e->clone()), state(e->BLOCK_SIZE), position(0)
{
if(e->name() != "DES")
throw Invalid_Argument("ANSI X9.19 MAC only supports DES");
diff --git a/src/mac/x919_mac/x919_mac.h b/src/mac/x919_mac/x919_mac.h
index 8432db7d1..275d39367 100644
--- a/src/mac/x919_mac/x919_mac.h
+++ b/src/mac/x919_mac/x919_mac.h
@@ -35,7 +35,7 @@ class BOTAN_DLL ANSI_X919_MAC : public MessageAuthenticationCode
BlockCipher* e;
BlockCipher* d;
- SecureVector<byte, 8> state;
+ SecureVector<byte> state;
u32bit position;
};
diff --git a/src/stream/arc4/arc4.cpp b/src/stream/arc4/arc4.cpp
index 90f0f0904..97364bd1a 100644
--- a/src/stream/arc4/arc4.cpp
+++ b/src/stream/arc4/arc4.cpp
@@ -97,7 +97,8 @@ void ARC4::clear()
/*
* ARC4 Constructor
*/
-ARC4::ARC4(u32bit s) : StreamCipher(1, 256), SKIP(s)
+ARC4::ARC4(u32bit s) : StreamCipher(1, 256), SKIP(s),
+ state(256), buffer(DEFAULT_BUFFERSIZE)
{
clear();
}
diff --git a/src/stream/arc4/arc4.h b/src/stream/arc4/arc4.h
index 0488783ef..1b8684e75 100644
--- a/src/stream/arc4/arc4.h
+++ b/src/stream/arc4/arc4.h
@@ -38,8 +38,8 @@ class BOTAN_DLL ARC4 : public StreamCipher
const u32bit SKIP;
- SecureVector<byte, DEFAULT_BUFFERSIZE> buffer;
- SecureVector<u32bit, 256> state;
+ SecureVector<u32bit> state;
+ SecureVector<byte> buffer;
u32bit X, Y, position;
};
diff --git a/src/stream/salsa20/salsa20.h b/src/stream/salsa20/salsa20.h
index 4ba483082..7e6c523cd 100644
--- a/src/stream/salsa20/salsa20.h
+++ b/src/stream/salsa20/salsa20.h
@@ -29,13 +29,13 @@ class BOTAN_DLL Salsa20 : public StreamCipher
std::string name() const;
StreamCipher* clone() const { return new Salsa20; }
- Salsa20() : StreamCipher(16, 32, 16) { position = 0; }
+ Salsa20() : StreamCipher(16, 32, 16), state(16), buffer(64) { position = 0; }
~Salsa20() { clear(); }
private:
void key_schedule(const byte key[], u32bit key_len);
- SecureVector<u32bit, 16> state;
- SecureVector<byte, 64> buffer;
+ SecureVector<u32bit> state;
+ SecureVector<byte> buffer;
u32bit position;
};
diff --git a/src/stream/turing/turing.h b/src/stream/turing/turing.h
index 92c5083a4..c0b11fd7b 100644
--- a/src/stream/turing/turing.h
+++ b/src/stream/turing/turing.h
@@ -27,7 +27,12 @@ class BOTAN_DLL Turing : public StreamCipher
void clear();
std::string name() const { return "Turing"; }
StreamCipher* clone() const { return new Turing; }
- Turing() : StreamCipher(4, 32, 4) { position = 0; }
+
+ Turing() : StreamCipher(4, 32, 4),
+ S0(256), S1(256), S2(256), S3(256),
+ R(17), buffer(340)
+ { position = 0; }
+
private:
void key_schedule(const byte[], u32bit);
void generate();
@@ -37,10 +42,10 @@ class BOTAN_DLL Turing : public StreamCipher
static const u32bit Q_BOX[256];
static const byte SBOX[256];
- SecureVector<u32bit, 256> S0, S1, S2, S3;
- SecureVector<u32bit, 17> R;
+ SecureVector<u32bit> S0, S1, S2, S3;
+ SecureVector<u32bit> R;
SecureVector<u32bit> K;
- SecureVector<byte, 340> buffer;
+ SecureVector<byte> buffer;
u32bit position;
};
diff --git a/src/stream/wid_wake/wid_wake.h b/src/stream/wid_wake/wid_wake.h
index 365a6d9ff..88f5690bf 100644
--- a/src/stream/wid_wake/wid_wake.h
+++ b/src/stream/wid_wake/wid_wake.h
@@ -30,16 +30,21 @@ class BOTAN_DLL WiderWake_41_BE : public StreamCipher
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) {}
+
+ WiderWake_41_BE() : StreamCipher(16, 16, 1),
+ T(256), state(5), t_key(4),
+ buffer(DEFAULT_BUFFERSIZE), position(0)
+ { }
+
private:
void key_schedule(const byte[], u32bit);
void generate(u32bit);
- SecureVector<byte, DEFAULT_BUFFERSIZE> buffer;
- SecureVector<u32bit, 256> T;
- SecureVector<u32bit, 5> state;
- SecureVector<u32bit, 4> t_key;
+ SecureVector<u32bit> T;
+ SecureVector<u32bit> state;
+ SecureVector<u32bit> t_key;
+ SecureVector<byte> buffer;
u32bit position;
};