aboutsummaryrefslogtreecommitdiffstats
path: root/src/stream
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-05-25 22:52:00 +0000
committerlloyd <[email protected]>2012-05-25 22:52:00 +0000
commit12090a7148d9ee73572cc1a7268fc489504a8173 (patch)
tree51e50ce0852c56231e9e6dc13f168b10edd45d01 /src/stream
parent9594979caf775dc4062850044715b804d1fda60c (diff)
parent65cc04445f8d40497f02a14bd8cb97081790e54b (diff)
propagate from branch 'net.randombit.botan.x509-path-validation' (head 63b5a20eab129ca13287fda33d2d02eec329708f)
to branch 'net.randombit.botan' (head 8b8150f09c55184f028f2929c4e7f7cd0d46d96e)
Diffstat (limited to 'src/stream')
-rw-r--r--src/stream/arc4/arc4.cpp18
-rw-r--r--src/stream/arc4/arc4.h4
-rw-r--r--src/stream/ctr/ctr.cpp6
-rw-r--r--src/stream/ctr/ctr.h2
-rw-r--r--src/stream/ofb/ofb.cpp4
-rw-r--r--src/stream/ofb/ofb.h2
-rw-r--r--src/stream/salsa20/salsa20.cpp11
-rw-r--r--src/stream/salsa20/salsa20.h6
-rw-r--r--src/stream/turing/turing.cpp26
-rw-r--r--src/stream/turing/turing.h10
-rw-r--r--src/stream/wid_wake/wid_wake.cpp13
-rw-r--r--src/stream/wid_wake/wid_wake.h12
12 files changed, 59 insertions, 55 deletions
diff --git a/src/stream/arc4/arc4.cpp b/src/stream/arc4/arc4.cpp
index 6eea7bb45..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);
@@ -85,7 +88,7 @@ std::string ARC4::name() const
{
if(SKIP == 0) return "ARC4";
if(SKIP == 256) return "MARK-4";
- else return "RC4_skip(" + to_string(SKIP) + ")";
+ else return "RC4_skip(" + std::to_string(SKIP) + ")";
}
/*
@@ -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/arc4/arc4.h b/src/stream/arc4/arc4.h
index e3df97f83..8f8de87b6 100644
--- a/src/stream/arc4/arc4.h
+++ b/src/stream/arc4/arc4.h
@@ -44,9 +44,9 @@ class BOTAN_DLL ARC4 : public StreamCipher
const size_t SKIP;
byte X, Y;
- SecureVector<byte> state;
+ secure_vector<byte> state;
- SecureVector<byte> buffer;
+ secure_vector<byte> buffer;
size_t position;
};
diff --git a/src/stream/ctr/ctr.cpp b/src/stream/ctr/ctr.cpp
index 3a370eca3..87ec86c65 100644
--- a/src/stream/ctr/ctr.cpp
+++ b/src/stream/ctr/ctr.cpp
@@ -49,7 +49,7 @@ void CTR_BE::key_schedule(const byte key[], size_t key_len)
permutation->set_key(key, key_len);
// Set a default all-zeros IV
- set_iv(0, 0);
+ set_iv(nullptr, 0);
}
/*
@@ -89,14 +89,14 @@ void CTR_BE::set_iv(const byte iv[], size_t iv_len)
zeroise(counter);
- counter.copy(0, iv, iv_len);
+ buffer_insert(counter, 0, iv, iv_len);
/*
* Set counter blocks to IV, IV + 1, ... IV + 255
*/
for(size_t i = 1; i != 256; ++i)
{
- counter.copy(i*bs, &counter[(i-1)*bs], bs);
+ buffer_insert(counter, i*bs, &counter[(i-1)*bs], bs);
for(size_t j = 0; j != bs; ++j)
if(++counter[i*bs + (bs - 1 - j)])
diff --git a/src/stream/ctr/ctr.h b/src/stream/ctr/ctr.h
index 64b43b0f5..9f391da7e 100644
--- a/src/stream/ctr/ctr.h
+++ b/src/stream/ctr/ctr.h
@@ -48,7 +48,7 @@ class BOTAN_DLL CTR_BE : public StreamCipher
void increment_counter();
BlockCipher* permutation;
- SecureVector<byte> counter, buffer;
+ secure_vector<byte> counter, buffer;
size_t position;
};
diff --git a/src/stream/ofb/ofb.cpp b/src/stream/ofb/ofb.cpp
index 382a2b4dd..1137a58af 100644
--- a/src/stream/ofb/ofb.cpp
+++ b/src/stream/ofb/ofb.cpp
@@ -46,7 +46,7 @@ void OFB::key_schedule(const byte key[], size_t key_len)
permutation->set_key(key, key_len);
// Set a default all-zeros IV
- set_iv(0, 0);
+ set_iv(nullptr, 0);
}
/*
@@ -84,7 +84,7 @@ void OFB::set_iv(const byte iv[], size_t iv_len)
throw Invalid_IV_Length(name(), iv_len);
zeroise(buffer);
- buffer.copy(0, iv, iv_len);
+ buffer_insert(buffer, 0, iv, iv_len);
permutation->encrypt(buffer);
position = 0;
diff --git a/src/stream/ofb/ofb.h b/src/stream/ofb/ofb.h
index c4d8b2601..9d4fd882f 100644
--- a/src/stream/ofb/ofb.h
+++ b/src/stream/ofb/ofb.h
@@ -47,7 +47,7 @@ class BOTAN_DLL OFB : public StreamCipher
void key_schedule(const byte key[], size_t key_len);
BlockCipher* permutation;
- SecureVector<byte> buffer;
+ secure_vector<byte> buffer;
size_t position;
};
diff --git a/src/stream/salsa20/salsa20.cpp b/src/stream/salsa20/salsa20.cpp
index 7d062befe..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));
}
@@ -193,7 +196,7 @@ void Salsa20::set_iv(const byte iv[], size_t length)
state[8] = load_le<u32bit>(iv, 2);
state[9] = load_le<u32bit>(iv, 3);
- SecureVector<u32bit> hsalsa(8);
+ secure_vector<u32bit> hsalsa(8);
hsalsa20(&hsalsa[0], &state[0]);
state[ 1] = hsalsa[0];
@@ -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 d9645015f..b68bb979e 100644
--- a/src/stream/salsa20/salsa20.h
+++ b/src/stream/salsa20/salsa20.h
@@ -33,13 +33,11 @@ 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);
- SecureVector<u32bit> state;
- SecureVector<byte> buffer;
+ secure_vector<u32bit> state;
+ secure_vector<byte> buffer;
size_t position;
};
diff --git a/src/stream/turing/turing.cpp b/src/stream/turing/turing.cpp
index 697c660ed..bdc53cff1 100644
--- a/src/stream/turing/turing.cpp
+++ b/src/stream/turing/turing.cpp
@@ -17,7 +17,7 @@ namespace {
/*
* Perform an N-way PHT
*/
-inline void PHT(MemoryRegion<u32bit>& B)
+inline void PHT(secure_vector<u32bit>& B)
{
u32bit sum = 0;
for(size_t i = 0; i < B.size() - 1; ++i)
@@ -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(17*20);
+
for(u32bit i = 0; i != 256; ++i)
{
u32bit W0 = 0, C0 = i;
@@ -273,7 +280,7 @@ void Turing::key_schedule(const byte key[], size_t length)
S3[i] = (W3 & 0xFFFFFF00) | C3;
}
- set_iv(0, 0);
+ set_iv(nullptr, 0);
}
/*
@@ -284,7 +291,7 @@ void Turing::set_iv(const byte iv[], size_t length)
if(!valid_iv_length(length))
throw Invalid_IV_Length(name(), length);
- SecureVector<u32bit> IV(length / 4);
+ secure_vector<u32bit> IV(length / 4);
for(size_t i = 0; i != length; ++i)
IV[i/4] = (IV[i/4] << 8) + iv[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 aff314080..f2453127a 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();
@@ -45,10 +42,9 @@ class BOTAN_DLL Turing : public StreamCipher
static const u32bit Q_BOX[256];
static const byte SBOX[256];
- SecureVector<u32bit> S0, S1, S2, S3;
- SecureVector<u32bit> R;
- SecureVector<u32bit> K;
- SecureVector<byte> buffer;
+ secure_vector<u32bit> S0, S1, S2, S3;
+ secure_vector<u32bit> R, K;
+ secure_vector<byte> buffer;
size_t position;
};
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 05842a574..501345011 100644
--- a/src/stream/wid_wake/wid_wake.h
+++ b/src/stream/wid_wake/wid_wake.h
@@ -36,19 +36,15 @@ 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);
void generate(size_t);
- SecureVector<u32bit> T;
- SecureVector<u32bit> state;
- SecureVector<u32bit> t_key;
- SecureVector<byte> buffer;
+ secure_vector<u32bit> T;
+ secure_vector<u32bit> state;
+ secure_vector<u32bit> t_key;
+ secure_vector<byte> buffer;
size_t position;
};