aboutsummaryrefslogtreecommitdiffstats
path: root/src/stream
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-05-25 02:11:10 +0000
committerlloyd <[email protected]>2012-05-25 02:11:10 +0000
commit113f4035f41cf3152832e1753d28b79a7ea811a4 (patch)
tree1e2071c1f7786972d268b727f52ee33225ad68d4 /src/stream
parentee42784fee56c48f72ecf03d7b93765dac35edf5 (diff)
For block and stream ciphers, don't set the size of the key vectors
until we are actually setting a key. This avoids the problem of prototype objects consuming not just memory but the precious few bytes of mlock'able memory that we're given by Linux. Use clear_mem instead of a loop in BigInt::mask_bits If OS2ECP encounters an invalid format type, include what type it was in the exception message.
Diffstat (limited to 'src/stream')
-rw-r--r--src/stream/arc4/arc4.cpp16
-rw-r--r--src/stream/salsa20/salsa20.cpp9
-rw-r--r--src/stream/salsa20/salsa20.h2
-rw-r--r--src/stream/turing/turing.cpp20
-rw-r--r--src/stream/turing/turing.h3
-rw-r--r--src/stream/wid_wake/wid_wake.cpp13
-rw-r--r--src/stream/wid_wake/wid_wake.h4
7 files changed, 36 insertions, 31 deletions
diff --git a/src/stream/arc4/arc4.cpp b/src/stream/arc4/arc4.cpp
index a25b68185..13eb6ff9e 100644
--- a/src/stream/arc4/arc4.cpp
+++ b/src/stream/arc4/arc4.cpp
@@ -61,7 +61,10 @@ void ARC4::generate()
*/
void ARC4::key_schedule(const byte key[], size_t length)
{
- clear();
+ state.resize(256);
+ buffer.resize(DEFAULT_BUFFERSIZE);
+
+ position = X = Y = 0;
for(size_t i = 0; i != 256; ++i)
state[i] = static_cast<byte>(i);
@@ -93,19 +96,14 @@ std::string ARC4::name() const
*/
void ARC4::clear()
{
- zeroise(state);
- zeroise(buffer);
+ state.clear();
+ buffer.clear();
position = X = Y = 0;
}
/*
* ARC4 Constructor
*/
-ARC4::ARC4(size_t s) : SKIP(s),
- state(256),
- buffer(DEFAULT_BUFFERSIZE)
- {
- clear();
- }
+ARC4::ARC4(size_t s) : SKIP(s) {}
}
diff --git a/src/stream/salsa20/salsa20.cpp b/src/stream/salsa20/salsa20.cpp
index 65ee3d758..a7d1b2622 100644
--- a/src/stream/salsa20/salsa20.cpp
+++ b/src/stream/salsa20/salsa20.cpp
@@ -134,7 +134,8 @@ void Salsa20::key_schedule(const byte key[], size_t length)
static const u32bit SIGMA[] =
{ 0x61707865, 0x3320646e, 0x79622d32, 0x6b206574 };
- clear();
+ state.resize(16);
+ buffer.resize(64);
if(length == 16)
{
@@ -167,6 +168,8 @@ void Salsa20::key_schedule(const byte key[], size_t length)
state[15] = SIGMA[3];
}
+ position = 0;
+
const byte ZERO[8] = { 0 };
set_iv(ZERO, sizeof(ZERO));
}
@@ -232,8 +235,8 @@ std::string Salsa20::name() const
*/
void Salsa20::clear()
{
- zeroise(state);
- zeroise(buffer);
+ state.clear();
+ buffer.clear();
position = 0;
}
diff --git a/src/stream/salsa20/salsa20.h b/src/stream/salsa20/salsa20.h
index ac2a9b33a..b68bb979e 100644
--- a/src/stream/salsa20/salsa20.h
+++ b/src/stream/salsa20/salsa20.h
@@ -33,8 +33,6 @@ class BOTAN_DLL Salsa20 : public StreamCipher
void clear();
std::string name() const;
StreamCipher* clone() const { return new Salsa20; }
-
- Salsa20() : state(16), buffer(64), position(0) {}
private:
void key_schedule(const byte key[], size_t key_len);
diff --git a/src/stream/turing/turing.cpp b/src/stream/turing/turing.cpp
index 10ac18315..5dc1a5680 100644
--- a/src/stream/turing/turing.cpp
+++ b/src/stream/turing/turing.cpp
@@ -247,6 +247,13 @@ void Turing::key_schedule(const byte key[], size_t length)
PHT(K);
+ R.resize(17);
+ S0.resize(256);
+ S1.resize(256);
+ S2.resize(256);
+ S3.resize(256);
+ buffer.resize(340);
+
for(u32bit i = 0; i != 256; ++i)
{
u32bit W0 = 0, C0 = i;
@@ -313,12 +320,13 @@ void Turing::set_iv(const byte iv[], size_t length)
*/
void Turing::clear()
{
- zeroise(S0);
- zeroise(S1);
- zeroise(S2);
- zeroise(S3);
-
- zeroise(buffer);
+ S0.clear();
+ S1.clear();
+ S2.clear();
+ S3.clear();
+ R.clear();
+ K.clear();
+ buffer.clear();
position = 0;
}
diff --git a/src/stream/turing/turing.h b/src/stream/turing/turing.h
index 84bfbe9c0..48fb013e7 100644
--- a/src/stream/turing/turing.h
+++ b/src/stream/turing/turing.h
@@ -33,9 +33,6 @@ class BOTAN_DLL Turing : public StreamCipher
std::string name() const { return "Turing"; }
StreamCipher* clone() const { return new Turing; }
- Turing() : S0(256), S1(256), S2(256), S3(256),
- R(17), buffer(340), position(0) {}
-
private:
void key_schedule(const byte[], size_t);
void generate();
diff --git a/src/stream/wid_wake/wid_wake.cpp b/src/stream/wid_wake/wid_wake.cpp
index 51159064d..e4ab6477f 100644
--- a/src/stream/wid_wake/wid_wake.cpp
+++ b/src/stream/wid_wake/wid_wake.cpp
@@ -74,6 +74,10 @@ void WiderWake_41_BE::generate(size_t length)
*/
void WiderWake_41_BE::key_schedule(const byte key[], size_t)
{
+ t_key.resize(4);
+ state.resize(5);
+ buffer.resize(DEFAULT_BUFFERSIZE);
+
for(size_t i = 0; i != 4; ++i)
t_key[i] = load_be<u32bit>(key, i);
@@ -81,6 +85,7 @@ void WiderWake_41_BE::key_schedule(const byte key[], size_t)
0x726A8F3B, 0xE69A3B5C, 0xD3C71FE5, 0xAB3C73D2,
0x4D3A8EB3, 0x0396D6E8, 0x3D4C2F7A, 0x9EE27CF3 };
+ T.resize(256);
for(size_t i = 0; i != 4; ++i)
T[i] = t_key[i];
@@ -143,10 +148,10 @@ void WiderWake_41_BE::set_iv(const byte iv[], size_t length)
void WiderWake_41_BE::clear()
{
position = 0;
- zeroise(t_key);
- zeroise(state);
- zeroise(T);
- zeroise(buffer);
+ t_key.clear();
+ state.clear();
+ T.clear();
+ buffer.clear();
}
}
diff --git a/src/stream/wid_wake/wid_wake.h b/src/stream/wid_wake/wid_wake.h
index ca8d9a316..501345011 100644
--- a/src/stream/wid_wake/wid_wake.h
+++ b/src/stream/wid_wake/wid_wake.h
@@ -36,10 +36,6 @@ class BOTAN_DLL WiderWake_41_BE : public StreamCipher
std::string name() const { return "WiderWake4+1-BE"; }
StreamCipher* clone() const { return new WiderWake_41_BE; }
- WiderWake_41_BE() : T(256), state(5), t_key(4),
- buffer(DEFAULT_BUFFERSIZE), position(0)
- {}
-
private:
void key_schedule(const byte[], size_t);