aboutsummaryrefslogtreecommitdiffstats
path: root/src/block/rc5
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/block/rc5
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/block/rc5')
-rw-r--r--src/block/rc5/rc5.cpp12
-rw-r--r--src/block/rc5/rc5.h7
2 files changed, 7 insertions, 12 deletions
diff --git a/src/block/rc5/rc5.cpp b/src/block/rc5/rc5.cpp
index 1ac421996..fe558076a 100644
--- a/src/block/rc5/rc5.cpp
+++ b/src/block/rc5/rc5.cpp
@@ -18,8 +18,6 @@ namespace Botan {
*/
void RC5::encrypt_n(const byte in[], byte out[], size_t blocks) const
{
- const size_t rounds = (S.size() - 2) / 2;
-
for(size_t i = 0; i != blocks; ++i)
{
u32bit A = load_le<u32bit>(in, 0);
@@ -53,8 +51,6 @@ void RC5::encrypt_n(const byte in[], byte out[], size_t blocks) const
*/
void RC5::decrypt_n(const byte in[], byte out[], size_t blocks) const
{
- const size_t rounds = (S.size() - 2) / 2;
-
for(size_t i = 0; i != blocks; ++i)
{
u32bit A = load_le<u32bit>(in, 0);
@@ -88,6 +84,8 @@ void RC5::decrypt_n(const byte in[], byte out[], size_t blocks) const
*/
void RC5::key_schedule(const byte key[], size_t length)
{
+ S.resize(2*rounds + 2);
+
const size_t WORD_KEYLENGTH = (((length - 1) / 4) + 1);
const size_t MIX_ROUNDS = 3 * std::max(WORD_KEYLENGTH, S.size());
@@ -116,19 +114,17 @@ void RC5::key_schedule(const byte key[], size_t length)
*/
std::string RC5::name() const
{
- return "RC5(" + std::to_string(get_rounds()) + ")";
+ return "RC5(" + std::to_string(rounds) + ")";
}
/*
* RC5 Constructor
*/
-RC5::RC5(size_t rounds)
+RC5::RC5(size_t r) : rounds(r)
{
if(rounds < 8 || rounds > 32 || (rounds % 4 != 0))
throw Invalid_Argument("RC5: Invalid number of rounds " +
std::to_string(rounds));
-
- S.resize(2*rounds + 2);
}
}
diff --git a/src/block/rc5/rc5.h b/src/block/rc5/rc5.h
index bf059a996..2279260a3 100644
--- a/src/block/rc5/rc5.h
+++ b/src/block/rc5/rc5.h
@@ -21,9 +21,9 @@ class BOTAN_DLL RC5 : public Block_Cipher_Fixed_Params<8, 1, 32>
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
void decrypt_n(const byte in[], byte out[], size_t blocks) const;
- void clear() { zeroise(S); }
+ void clear() { S.clear(); }
std::string name() const;
- BlockCipher* clone() const { return new RC5(get_rounds()); }
+ BlockCipher* clone() const { return new RC5(rounds); }
/**
* @param rounds the number of RC5 rounds to run. Must be between
@@ -31,10 +31,9 @@ class BOTAN_DLL RC5 : public Block_Cipher_Fixed_Params<8, 1, 32>
*/
RC5(size_t rounds);
private:
- size_t get_rounds() const { return (S.size() - 2) / 2; }
-
void key_schedule(const byte[], size_t);
+ size_t rounds;
secure_vector<u32bit> S;
};