aboutsummaryrefslogtreecommitdiffstats
path: root/src/block/lion/lion.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-10-13 13:09:56 +0000
committerlloyd <[email protected]>2010-10-13 13:09:56 +0000
commit55550067fd69850c767cc9800433e1eabfeb5da2 (patch)
tree80ccea320ba00be2f7942d88657937462a6b1f03 /src/block/lion/lion.cpp
parent85a504e310666f270a3a67edf4cdac06c34c61b9 (diff)
Add a new subclass for BlockCipher BlockCipher_Fixed_Block_Size, which
sets the block size statically and also creates an enum with the size. Use the enum instead of calling block_size() where possible, since that uses two virtual function calls per block which is quite unfortunate. The real advantages here as compared to the previous version which kept the block size as a per-object u32bit: - The compiler can inline the constant as an immediate operand (previously it would load the value via an indirection on this) - Removes 32 bits per object overhead (except in cases with actually variable block sizes, which are very few and rarely used)
Diffstat (limited to 'src/block/lion/lion.cpp')
-rw-r--r--src/block/lion/lion.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/block/lion/lion.cpp b/src/block/lion/lion.cpp
index 7f6a06b79..8cede1c86 100644
--- a/src/block/lion/lion.cpp
+++ b/src/block/lion/lion.cpp
@@ -33,8 +33,8 @@ void Lion::encrypt_n(const byte in[], byte out[], size_t blocks) const
cipher->set_key(buffer, LEFT_SIZE);
cipher->cipher1(out + LEFT_SIZE, RIGHT_SIZE);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -60,8 +60,8 @@ void Lion::decrypt_n(const byte in[], byte out[], size_t blocks) const
cipher->set_key(buffer, LEFT_SIZE);
cipher->cipher1(out + LEFT_SIZE, RIGHT_SIZE);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -83,7 +83,7 @@ std::string Lion::name() const
{
return "Lion(" + hash->name() + "," +
cipher->name() + "," +
- to_string(block_size()) + ")";
+ to_string(BLOCK_SIZE) + ")";
}
/*
@@ -91,7 +91,7 @@ std::string Lion::name() const
*/
BlockCipher* Lion::clone() const
{
- return new Lion(hash->clone(), cipher->clone(), block_size());
+ return new Lion(hash->clone(), cipher->clone(), BLOCK_SIZE);
}
/*
@@ -109,14 +109,14 @@ void Lion::clear()
* Lion Constructor
*/
Lion::Lion(HashFunction* hash_in, StreamCipher* sc_in, size_t block_len) :
- BlockCipher(std::max<size_t>(2*hash_in->output_length() + 1, block_len),
- 2, 2*hash_in->output_length(), 2),
+ BlockCipher(2, 2*hash_in->output_length(), 2),
+ BLOCK_SIZE(std::max<size_t>(2*hash_in->output_length() + 1, block_len)),
LEFT_SIZE(hash_in->output_length()),
- RIGHT_SIZE(block_size() - LEFT_SIZE),
+ RIGHT_SIZE(BLOCK_SIZE - LEFT_SIZE),
hash(hash_in),
cipher(sc_in)
{
- if(2*LEFT_SIZE + 1 > block_size())
+ if(2*LEFT_SIZE + 1 > BLOCK_SIZE)
throw Invalid_Argument(name() + ": Chosen block size is too small");
if(!cipher->valid_keylength(LEFT_SIZE))