From 55550067fd69850c767cc9800433e1eabfeb5da2 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 13 Oct 2010 13:09:56 +0000 Subject: 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) --- src/block/safer/safer_sk.cpp | 13 +++++++------ src/block/safer/safer_sk.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'src/block/safer') diff --git a/src/block/safer/safer_sk.cpp b/src/block/safer/safer_sk.cpp index 48d96d1a2..cd9dddf34 100644 --- a/src/block/safer/safer_sk.cpp +++ b/src/block/safer/safer_sk.cpp @@ -43,8 +43,8 @@ void SAFER_SK::encrypt_n(const byte in[], byte out[], size_t blocks) const out[4] = E ^ EK[16*ROUNDS+4]; out[5] = F + EK[16*ROUNDS+5]; out[6] = G + EK[16*ROUNDS+6]; out[7] = H ^ EK[16*ROUNDS+7]; - in += block_size(); - out += block_size(); + in += BLOCK_SIZE; + out += BLOCK_SIZE; } } @@ -81,8 +81,8 @@ void SAFER_SK::decrypt_n(const byte in[], byte out[], size_t blocks) const out[0] = A; out[1] = B; out[2] = C; out[3] = D; out[4] = E; out[5] = F; out[6] = G; out[7] = H; - in += block_size(); - out += block_size(); + in += BLOCK_SIZE; + out += BLOCK_SIZE; } } @@ -127,8 +127,9 @@ BlockCipher* SAFER_SK::clone() const /* * SAFER-SK Constructor */ -SAFER_SK::SAFER_SK(size_t rounds) : BlockCipher(8, 16), - EK(16 * rounds + 8), ROUNDS(rounds) +SAFER_SK::SAFER_SK(size_t rounds) : + BlockCipher_Fixed_Block_Size(16), + EK(16 * rounds + 8), ROUNDS(rounds) { if(ROUNDS > 13 || ROUNDS == 0) throw Invalid_Argument(name() + ": Invalid number of rounds"); diff --git a/src/block/safer/safer_sk.h b/src/block/safer/safer_sk.h index a64d09fb7..5e8d32b0a 100644 --- a/src/block/safer/safer_sk.h +++ b/src/block/safer/safer_sk.h @@ -15,7 +15,7 @@ namespace Botan { /** * SAFER-SK */ -class BOTAN_DLL SAFER_SK : public BlockCipher +class BOTAN_DLL SAFER_SK : public BlockCipher_Fixed_Block_Size<8> { public: void encrypt_n(const byte in[], byte out[], size_t blocks) const; -- cgit v1.2.3