aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/benchmark/benchmark.cpp4
-rw-r--r--src/block/aes/aes.cpp8
-rw-r--r--src/block/block_cipher.h18
-rw-r--r--src/block/blowfish/blowfish.cpp8
-rw-r--r--src/block/cascade/cascade.cpp12
-rw-r--r--src/block/cast/cast128.cpp8
-rw-r--r--src/block/cast/cast256.cpp8
-rw-r--r--src/block/des/des.cpp16
-rw-r--r--src/block/des/desx.cpp16
-rw-r--r--src/block/gost_28147/gost_28147.cpp8
-rw-r--r--src/block/idea_sse2/idea_sse2.cpp8
-rw-r--r--src/block/kasumi/kasumi.cpp8
-rw-r--r--src/block/lion/lion.cpp16
-rw-r--r--src/block/lubyrack/lubyrack.cpp8
-rw-r--r--src/block/mars/mars.cpp8
-rw-r--r--src/block/misty1/misty1.cpp8
-rw-r--r--src/block/noekeon/noekeon.cpp8
-rw-r--r--src/block/rc2/rc2.cpp8
-rw-r--r--src/block/rc5/rc5.cpp8
-rw-r--r--src/block/rc6/rc6.cpp8
-rw-r--r--src/block/safer/safer_sk.cpp8
-rw-r--r--src/block/seed/seed.cpp8
-rw-r--r--src/block/serpent/serpent.cpp8
-rw-r--r--src/block/serpent_ia32/serp_ia32.cpp8
-rw-r--r--src/block/serpent_simd/serp_simd.cpp8
-rw-r--r--src/block/skipjack/skipjack.cpp8
-rw-r--r--src/block/square/square.cpp8
-rw-r--r--src/block/tea/tea.cpp8
-rw-r--r--src/block/twofish/twofish.cpp8
-rw-r--r--src/block/xtea/xtea.cpp16
-rw-r--r--src/block/xtea_simd/xtea_simd.cpp8
-rw-r--r--src/cms/cms_algo.cpp2
-rw-r--r--src/cms/cms_ealg.cpp2
-rw-r--r--src/constructs/aont/package.cpp56
-rw-r--r--src/engine/core_engine/core_modes.cpp2
-rw-r--r--src/filters/modes/cbc/cbc.cpp64
-rw-r--r--src/filters/modes/cbc/cbc.h4
-rw-r--r--src/filters/modes/cfb/cfb.cpp40
-rw-r--r--src/filters/modes/cfb/cfb.h4
-rw-r--r--src/filters/modes/cts/cts.cpp78
-rw-r--r--src/filters/modes/cts/cts.h4
-rw-r--r--src/filters/modes/eax/eax.cpp6
-rw-r--r--src/filters/modes/ecb/ecb.cpp34
-rw-r--r--src/filters/modes/xts/xts.cpp124
-rw-r--r--src/filters/modes/xts/xts.h4
-rw-r--r--src/libstate/lookup.cpp2
-rw-r--r--src/mac/cbc_mac/cbc_mac.cpp4
-rw-r--r--src/mac/cmac/cmac.cpp6
-rw-r--r--src/mac/x919_mac/x919_mac.cpp4
-rw-r--r--src/pbe/pbes2/pbes2.cpp2
-rw-r--r--src/rng/randpool/randpool.cpp4
-rw-r--r--src/rng/x931_rng/x931_rng.cpp16
-rw-r--r--src/stream/ctr/ctr.cpp15
-rw-r--r--src/stream/ctr/ctr.h2
-rw-r--r--src/stream/ofb/ofb.cpp2
-rw-r--r--src/stream/ofb/ofb.h2
56 files changed, 391 insertions, 382 deletions
diff --git a/src/benchmark/benchmark.cpp b/src/benchmark/benchmark.cpp
index 46dcfb58c..837d66c05 100644
--- a/src/benchmark/benchmark.cpp
+++ b/src/benchmark/benchmark.cpp
@@ -48,7 +48,7 @@ bench_block_cipher(BlockCipher* block_cipher,
u64bit nanoseconds_max,
byte buf[], size_t buf_len)
{
- const size_t in_blocks = buf_len / block_cipher->BLOCK_SIZE;
+ const size_t in_blocks = buf_len / block_cipher->block_size();
u64bit reps = 0;
u64bit nanoseconds_used = 0;
@@ -64,7 +64,7 @@ bench_block_cipher(BlockCipher* block_cipher,
++reps;
}
- return std::make_pair(reps * in_blocks * block_cipher->BLOCK_SIZE,
+ return std::make_pair(reps * in_blocks * block_cipher->block_size(),
nanoseconds_used);
}
diff --git a/src/block/aes/aes.cpp b/src/block/aes/aes.cpp
index cfd490e1d..88439cf98 100644
--- a/src/block/aes/aes.cpp
+++ b/src/block/aes/aes.cpp
@@ -521,8 +521,8 @@ void AES::encrypt_n(const byte in[], byte out[], size_t blocks) const
out[14] = SE[get_byte(2, B1)] ^ ME[14];
out[15] = SE[get_byte(3, B2)] ^ ME[15];
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -611,8 +611,8 @@ void AES::decrypt_n(const byte in[], byte out[], size_t blocks) const
out[14] = SD[get_byte(2, B1)] ^ MD[14];
out[15] = SD[get_byte(3, B0)] ^ MD[15];
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/block_cipher.h b/src/block/block_cipher.h
index a7ca4cd99..5f5e5e530 100644
--- a/src/block/block_cipher.h
+++ b/src/block/block_cipher.h
@@ -54,15 +54,15 @@ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm
*/
size_t parallel_bytes() const
{
- return parallelism() * BLOCK_SIZE * BOTAN_BLOCK_CIPHER_PAR_MULT;
+ return parallelism() * block_size() * BOTAN_BLOCK_CIPHER_PAR_MULT;
}
/**
* Encrypt a block.
* @param in The plaintext block to be encrypted as a byte array.
- * Must be of length BLOCK_SIZE.
+ * Must be of length block_size().
* @param out The byte array designated to hold the encrypted block.
- * Must be of length BLOCK_SIZE.
+ * Must be of length block_size().
*/
void encrypt(const byte in[], byte out[]) const
{ encrypt_n(in, out, 1); }
@@ -70,9 +70,9 @@ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm
/**
* Decrypt a block.
* @param in The ciphertext block to be decypted as a byte array.
- * Must be of length BLOCK_SIZE.
+ * Must be of length block_size().
* @param out The byte array designated to hold the decrypted block.
- * Must be of length BLOCK_SIZE.
+ * Must be of length block_size().
*/
void decrypt(const byte in[], byte out[]) const
{ decrypt_n(in, out, 1); }
@@ -80,7 +80,7 @@ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm
/**
* Encrypt a block.
* @param block the plaintext block to be encrypted
- * Must be of length BLOCK_SIZE. Will hold the result when the function
+ * Must be of length block_size(). Will hold the result when the function
* has finished.
*/
void encrypt(byte block[]) const { encrypt_n(block, block, 1); }
@@ -88,14 +88,14 @@ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm
/**
* Decrypt a block.
* @param block the ciphertext block to be decrypted
- * Must be of length BLOCK_SIZE. Will hold the result when the function
+ * Must be of length block_size(). Will hold the result when the function
* has finished.
*/
void decrypt(byte block[]) const { decrypt_n(block, block, 1); }
/**
* Encrypt one or more blocks
- * @param in the input buffer (multiple of BLOCK_SIZE)
+ * @param in the input buffer (multiple of block_size())
* @param out the output buffer (same size as in)
* @param blocks the number of blocks to process
*/
@@ -104,7 +104,7 @@ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm
/**
* Decrypt one or more blocks
- * @param in the input buffer (multiple of BLOCK_SIZE)
+ * @param in the input buffer (multiple of block_size())
* @param out the output buffer (same size as in)
* @param blocks the number of blocks to process
*/
diff --git a/src/block/blowfish/blowfish.cpp b/src/block/blowfish/blowfish.cpp
index ea227e93e..f77c65d4d 100644
--- a/src/block/blowfish/blowfish.cpp
+++ b/src/block/blowfish/blowfish.cpp
@@ -40,8 +40,8 @@ void Blowfish::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, R, L);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -75,8 +75,8 @@ void Blowfish::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, R, L);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/cascade/cascade.cpp b/src/block/cascade/cascade.cpp
index 54c33bc68..225b7fd6e 100644
--- a/src/block/cascade/cascade.cpp
+++ b/src/block/cascade/cascade.cpp
@@ -12,8 +12,8 @@ namespace Botan {
void Cascade_Cipher::encrypt_n(const byte in[], byte out[],
size_t blocks) const
{
- size_t c1_blocks = blocks * (BLOCK_SIZE / cipher1->BLOCK_SIZE);
- size_t c2_blocks = blocks * (BLOCK_SIZE / cipher2->BLOCK_SIZE);
+ size_t c1_blocks = blocks * (block_size() / cipher1->block_size());
+ size_t c2_blocks = blocks * (block_size() / cipher2->block_size());
cipher1->encrypt_n(in, out, c1_blocks);
cipher2->encrypt_n(out, out, c2_blocks);
@@ -22,8 +22,8 @@ void Cascade_Cipher::encrypt_n(const byte in[], byte out[],
void Cascade_Cipher::decrypt_n(const byte in[], byte out[],
size_t blocks) const
{
- size_t c1_blocks = blocks * (BLOCK_SIZE / cipher1->BLOCK_SIZE);
- size_t c2_blocks = blocks * (BLOCK_SIZE / cipher2->BLOCK_SIZE);
+ size_t c1_blocks = blocks * (block_size() / cipher1->block_size());
+ size_t c2_blocks = blocks * (block_size() / cipher2->block_size());
cipher2->decrypt_n(in, out, c2_blocks);
cipher1->decrypt_n(out, out, c1_blocks);
@@ -81,11 +81,11 @@ size_t block_size_for_cascade(size_t bs, size_t bs2)
}
Cascade_Cipher::Cascade_Cipher(BlockCipher* c1, BlockCipher* c2) :
- BlockCipher(block_size_for_cascade(c1->BLOCK_SIZE, c2->BLOCK_SIZE),
+ BlockCipher(block_size_for_cascade(c1->block_size(), c2->block_size()),
c1->MAXIMUM_KEYLENGTH + c2->MAXIMUM_KEYLENGTH),
cipher1(c1), cipher2(c2)
{
- if(BLOCK_SIZE % c1->BLOCK_SIZE || BLOCK_SIZE % c2->BLOCK_SIZE)
+ if(block_size() % c1->block_size() || block_size() % c2->block_size())
throw Internal_Error("Failure in " + name() + " constructor");
}
diff --git a/src/block/cast/cast128.cpp b/src/block/cast/cast128.cpp
index 24469e025..092fc201e 100644
--- a/src/block/cast/cast128.cpp
+++ b/src/block/cast/cast128.cpp
@@ -74,8 +74,8 @@ void CAST_128::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, R, L);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -108,8 +108,8 @@ void CAST_128::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, R, L);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/cast/cast256.cpp b/src/block/cast/cast256.cpp
index 8be0a8dd6..1b41cd2af 100644
--- a/src/block/cast/cast256.cpp
+++ b/src/block/cast/cast256.cpp
@@ -84,8 +84,8 @@ void CAST_256::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, A, B, C, D);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -128,8 +128,8 @@ void CAST_256::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, A, B, C, D);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/des/des.cpp b/src/block/des/des.cpp
index 15c771bda..7c61df3db 100644
--- a/src/block/des/des.cpp
+++ b/src/block/des/des.cpp
@@ -162,8 +162,8 @@ void DES::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(T, out);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -193,8 +193,8 @@ void DES::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(T, out);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -234,8 +234,8 @@ void TripleDES::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(T, out);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -267,8 +267,8 @@ void TripleDES::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(T, out);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/des/desx.cpp b/src/block/des/desx.cpp
index b92011e56..c4dacdfdd 100644
--- a/src/block/des/desx.cpp
+++ b/src/block/des/desx.cpp
@@ -17,12 +17,12 @@ void DESX::encrypt_n(const byte in[], byte out[], size_t blocks) const
{
for(size_t i = 0; i != blocks; ++i)
{
- xor_buf(out, in, &K1[0], BLOCK_SIZE);
+ xor_buf(out, in, &K1[0], block_size());
des.encrypt(out);
- xor_buf(out, &K2[0], BLOCK_SIZE);
+ xor_buf(out, &K2[0], block_size());
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -33,12 +33,12 @@ void DESX::decrypt_n(const byte in[], byte out[], size_t blocks) const
{
for(size_t i = 0; i != blocks; ++i)
{
- xor_buf(out, in, &K2[0], BLOCK_SIZE);
+ xor_buf(out, in, &K2[0], block_size());
des.decrypt(out);
- xor_buf(out, &K1[0], BLOCK_SIZE);
+ xor_buf(out, &K1[0], block_size());
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/gost_28147/gost_28147.cpp b/src/block/gost_28147/gost_28147.cpp
index 4b4b83dcc..ddf26b3d0 100644
--- a/src/block/gost_28147/gost_28147.cpp
+++ b/src/block/gost_28147/gost_28147.cpp
@@ -107,8 +107,8 @@ void GOST_28147_89::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, N2, N1);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -136,8 +136,8 @@ void GOST_28147_89::decrypt_n(const byte in[], byte out[], size_t blocks) const
}
store_le(out, N2, N1);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/idea_sse2/idea_sse2.cpp b/src/block/idea_sse2/idea_sse2.cpp
index 469a33943..8c7bd2a2c 100644
--- a/src/block/idea_sse2/idea_sse2.cpp
+++ b/src/block/idea_sse2/idea_sse2.cpp
@@ -201,8 +201,8 @@ void IDEA_SSE2::encrypt_n(const byte in[], byte out[], size_t blocks) const
while(blocks >= 8)
{
idea_op_8(in, out, KS);
- in += 8 * BLOCK_SIZE;
- out += 8 * BLOCK_SIZE;
+ in += 8 * block_size();
+ out += 8 * block_size();
blocks -= 8;
}
@@ -220,8 +220,8 @@ void IDEA_SSE2::decrypt_n(const byte in[], byte out[], size_t blocks) const
while(blocks >= 8)
{
idea_op_8(in, out, KS);
- in += 8 * BLOCK_SIZE;
- out += 8 * BLOCK_SIZE;
+ in += 8 * block_size();
+ out += 8 * block_size();
blocks -= 8;
}
diff --git a/src/block/kasumi/kasumi.cpp b/src/block/kasumi/kasumi.cpp
index a57c0396a..1a217a9c7 100644
--- a/src/block/kasumi/kasumi.cpp
+++ b/src/block/kasumi/kasumi.cpp
@@ -145,8 +145,8 @@ void KASUMI::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, B0, B1, B2, B3);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -191,8 +191,8 @@ void KASUMI::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, B0, B1, B2, B3);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/lion/lion.cpp b/src/block/lion/lion.cpp
index 0b3e7762a..7f6a06b79 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());
}
/*
@@ -112,11 +112,11 @@ 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),
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))
diff --git a/src/block/lubyrack/lubyrack.cpp b/src/block/lubyrack/lubyrack.cpp
index ecc0fadfd..aa33c6bc4 100644
--- a/src/block/lubyrack/lubyrack.cpp
+++ b/src/block/lubyrack/lubyrack.cpp
@@ -42,8 +42,8 @@ void LubyRackoff::encrypt_n(const byte in[], byte out[], size_t blocks) const
hash->final(buffer);
xor_buf(out, buffer, len);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -79,8 +79,8 @@ void LubyRackoff::decrypt_n(const byte in[], byte out[], size_t blocks) const
hash->final(buffer);
xor_buf(out + len, buffer, len);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/mars/mars.cpp b/src/block/mars/mars.cpp
index fa73e564f..5864ac49b 100644
--- a/src/block/mars/mars.cpp
+++ b/src/block/mars/mars.cpp
@@ -267,8 +267,8 @@ void MARS::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, A, B, C, D);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -310,8 +310,8 @@ void MARS::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, D, C, B, A);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/misty1/misty1.cpp b/src/block/misty1/misty1.cpp
index 2f82e18e8..c904c5d78 100644
--- a/src/block/misty1/misty1.cpp
+++ b/src/block/misty1/misty1.cpp
@@ -144,8 +144,8 @@ void MISTY1::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, B2, B3, B0, B1);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -194,8 +194,8 @@ void MISTY1::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, B0, B1, B2, B3);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/noekeon/noekeon.cpp b/src/block/noekeon/noekeon.cpp
index 06c415be9..c29fed93e 100644
--- a/src/block/noekeon/noekeon.cpp
+++ b/src/block/noekeon/noekeon.cpp
@@ -114,8 +114,8 @@ void Noekeon::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, A0, A1, A2, A3);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -152,8 +152,8 @@ void Noekeon::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, A0, A1, A2, A3);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/rc2/rc2.cpp b/src/block/rc2/rc2.cpp
index 97ca5d577..5c7cb1ead 100644
--- a/src/block/rc2/rc2.cpp
+++ b/src/block/rc2/rc2.cpp
@@ -48,8 +48,8 @@ void RC2::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, R0, R1, R2, R3);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -90,8 +90,8 @@ void RC2::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, R0, R1, R2, R3);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/rc5/rc5.cpp b/src/block/rc5/rc5.cpp
index 519735967..3cd169e5d 100644
--- a/src/block/rc5/rc5.cpp
+++ b/src/block/rc5/rc5.cpp
@@ -38,8 +38,8 @@ void RC5::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, A, B);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -68,8 +68,8 @@ void RC5::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, A, B);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/rc6/rc6.cpp b/src/block/rc6/rc6.cpp
index 53ca5a7a2..df87acbb1 100644
--- a/src/block/rc6/rc6.cpp
+++ b/src/block/rc6/rc6.cpp
@@ -55,8 +55,8 @@ void RC6::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, A, B, C, D);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -103,8 +103,8 @@ void RC6::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, A, B, C, D);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/safer/safer_sk.cpp b/src/block/safer/safer_sk.cpp
index f78e326e4..48d96d1a2 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();
}
}
diff --git a/src/block/seed/seed.cpp b/src/block/seed/seed.cpp
index 408220013..015d2d48d 100644
--- a/src/block/seed/seed.cpp
+++ b/src/block/seed/seed.cpp
@@ -54,8 +54,8 @@ void SEED::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, B2, B3, B0, B1);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -94,8 +94,8 @@ void SEED::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, B2, B3, B0, B1);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/serpent/serpent.cpp b/src/block/serpent/serpent.cpp
index 1d940cf39..ec37a9e97 100644
--- a/src/block/serpent/serpent.cpp
+++ b/src/block/serpent/serpent.cpp
@@ -287,8 +287,8 @@ void Serpent::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, B0, B1, B2, B3);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -339,8 +339,8 @@ void Serpent::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, B0, B1, B2, B3);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/serpent_ia32/serp_ia32.cpp b/src/block/serpent_ia32/serp_ia32.cpp
index d2f8adb62..76814647c 100644
--- a/src/block/serpent_ia32/serp_ia32.cpp
+++ b/src/block/serpent_ia32/serp_ia32.cpp
@@ -49,8 +49,8 @@ void Serpent_IA32::encrypt_n(const byte in[], byte out[], size_t blocks) const
for(size_t i = 0; i != blocks; ++i)
{
botan_serpent_ia32_encrypt(in, out, this->get_round_keys());
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -62,8 +62,8 @@ void Serpent_IA32::decrypt_n(const byte in[], byte out[], size_t blocks) const
for(size_t i = 0; i != blocks; ++i)
{
botan_serpent_ia32_decrypt(in, out, this->get_round_keys());
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/serpent_simd/serp_simd.cpp b/src/block/serpent_simd/serp_simd.cpp
index babe68d40..aef37cb99 100644
--- a/src/block/serpent_simd/serp_simd.cpp
+++ b/src/block/serpent_simd/serp_simd.cpp
@@ -185,8 +185,8 @@ void Serpent_SIMD::encrypt_n(const byte in[], byte out[], size_t blocks) const
while(blocks >= 4)
{
serpent_encrypt_4(in, out, KS);
- in += 4 * BLOCK_SIZE;
- out += 4 * BLOCK_SIZE;
+ in += 4 * block_size();
+ out += 4 * block_size();
blocks -= 4;
}
@@ -204,8 +204,8 @@ void Serpent_SIMD::decrypt_n(const byte in[], byte out[], size_t blocks) const
while(blocks >= 4)
{
serpent_decrypt_4(in, out, KS);
- in += 4 * BLOCK_SIZE;
- out += 4 * BLOCK_SIZE;
+ in += 4 * block_size();
+ out += 4 * block_size();
blocks -= 4;
}
diff --git a/src/block/skipjack/skipjack.cpp b/src/block/skipjack/skipjack.cpp
index b73972b59..7f25cc90a 100644
--- a/src/block/skipjack/skipjack.cpp
+++ b/src/block/skipjack/skipjack.cpp
@@ -108,8 +108,8 @@ void Skipjack::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, W4, W3, W2, W1);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -149,8 +149,8 @@ void Skipjack::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, W4, W3, W2, W1);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/square/square.cpp b/src/block/square/square.cpp
index b1517b990..ba86dd931 100644
--- a/src/block/square/square.cpp
+++ b/src/block/square/square.cpp
@@ -68,8 +68,8 @@ void Square::encrypt_n(const byte in[], byte out[], size_t blocks) const
out[14] = SE[get_byte(3, B2)] ^ ME[30];
out[15] = SE[get_byte(3, B3)] ^ ME[31];
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -130,8 +130,8 @@ void Square::decrypt_n(const byte in[], byte out[], size_t blocks) const
out[14] = SD[get_byte(3, B2)] ^ MD[30];
out[15] = SD[get_byte(3, B3)] ^ MD[31];
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/tea/tea.cpp b/src/block/tea/tea.cpp
index 4ef995a7c..328786a14 100644
--- a/src/block/tea/tea.cpp
+++ b/src/block/tea/tea.cpp
@@ -30,8 +30,8 @@ void TEA::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, L, R);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -55,8 +55,8 @@ void TEA::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, L, R);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/twofish/twofish.cpp b/src/block/twofish/twofish.cpp
index 41bc7ca1c..a573c2ec8 100644
--- a/src/block/twofish/twofish.cpp
+++ b/src/block/twofish/twofish.cpp
@@ -57,8 +57,8 @@ void Twofish::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, C, D, A, B);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -108,8 +108,8 @@ void Twofish::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, C, D, A, B);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/xtea/xtea.cpp b/src/block/xtea/xtea.cpp
index 597eedd07..ba07ba57c 100644
--- a/src/block/xtea/xtea.cpp
+++ b/src/block/xtea/xtea.cpp
@@ -64,8 +64,8 @@ void XTEA::encrypt_n(const byte in[], byte out[], size_t blocks) const
while(blocks >= 4)
{
xtea_encrypt_4(in, out, &(this->EK[0]));
- in += 4 * BLOCK_SIZE;
- out += 4 * BLOCK_SIZE;
+ in += 4 * block_size();
+ out += 4 * block_size();
blocks -= 4;
}
@@ -82,8 +82,8 @@ void XTEA::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, L, R);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
@@ -95,8 +95,8 @@ void XTEA::decrypt_n(const byte in[], byte out[], size_t blocks) const
while(blocks >= 4)
{
xtea_decrypt_4(in, out, &(this->EK[0]));
- in += 4 * BLOCK_SIZE;
- out += 4 * BLOCK_SIZE;
+ in += 4 * block_size();
+ out += 4 * block_size();
blocks -= 4;
}
@@ -113,8 +113,8 @@ void XTEA::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, L, R);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
diff --git a/src/block/xtea_simd/xtea_simd.cpp b/src/block/xtea_simd/xtea_simd.cpp
index 831cc0359..5b73c7bb9 100644
--- a/src/block/xtea_simd/xtea_simd.cpp
+++ b/src/block/xtea_simd/xtea_simd.cpp
@@ -99,8 +99,8 @@ void XTEA_SIMD::encrypt_n(const byte in[], byte out[], size_t blocks) const
while(blocks >= 8)
{
xtea_encrypt_8(in, out, KS);
- in += 8 * BLOCK_SIZE;
- out += 8 * BLOCK_SIZE;
+ in += 8 * block_size();
+ out += 8 * block_size();
blocks -= 8;
}
@@ -118,8 +118,8 @@ void XTEA_SIMD::decrypt_n(const byte in[], byte out[], size_t blocks) const
while(blocks >= 8)
{
xtea_decrypt_8(in, out, KS);
- in += 8 * BLOCK_SIZE;
- out += 8 * BLOCK_SIZE;
+ in += 8 * block_size();
+ out += 8 * block_size();
blocks -= 8;
}
diff --git a/src/cms/cms_algo.cpp b/src/cms/cms_algo.cpp
index e74c385fa..33652a6b6 100644
--- a/src/cms/cms_algo.cpp
+++ b/src/cms/cms_algo.cpp
@@ -53,7 +53,7 @@ SecureVector<byte> do_rfc3217_wrap(RandomNumberGenerator& rng,
const BlockCipher* cipher = af.prototype_block_cipher(cipher_name);
- if(!cipher || cipher->BLOCK_SIZE != 8)
+ if(!cipher || cipher->block_size() != 8)
throw Encoding_Error("do_rfc3217_wrap: Bad cipher: " + cipher_name);
Pipe icv(new Hash_Filter(new SHA_160, 8));
diff --git a/src/cms/cms_ealg.cpp b/src/cms/cms_ealg.cpp
index 7b1ab6bc9..382d5230e 100644
--- a/src/cms/cms_ealg.cpp
+++ b/src/cms/cms_ealg.cpp
@@ -258,7 +258,7 @@ SecureVector<byte> CMS_Encoder::do_encrypt(RandomNumberGenerator& rng,
if(!OIDS::have_oid(cipher->name() + "/CBC"))
throw Encoding_Error("CMS: No OID assigned for " + cipher_name + "/CBC");
- InitializationVector iv(rng, cipher->BLOCK_SIZE);
+ InitializationVector iv(rng, cipher->block_size());
AlgorithmIdentifier content_cipher;
content_cipher.oid = OIDS::lookup(cipher->name() + "/CBC");
diff --git a/src/constructs/aont/package.cpp b/src/constructs/aont/package.cpp
index 1e25a3b24..a773d6558 100644
--- a/src/constructs/aont/package.cpp
+++ b/src/constructs/aont/package.cpp
@@ -19,13 +19,15 @@ void aont_package(RandomNumberGenerator& rng,
const byte input[], u32bit input_len,
byte output[])
{
- if(!cipher->valid_keylength(cipher->BLOCK_SIZE))
+ const size_t BLOCK_SIZE = cipher->block_size();
+
+ if(!cipher->valid_keylength(BLOCK_SIZE))
throw Invalid_Argument("AONT::package: Invalid cipher");
// The all-zero string which is used both as the CTR IV and as K0
- const std::string all_zeros(cipher->BLOCK_SIZE*2, '0');
+ const std::string all_zeros(BLOCK_SIZE*2, '0');
- SymmetricKey package_key(rng, cipher->BLOCK_SIZE);
+ SymmetricKey package_key(rng, BLOCK_SIZE);
Pipe pipe(new StreamCipher_Filter(new CTR_BE(cipher), package_key));
@@ -35,80 +37,82 @@ void aont_package(RandomNumberGenerator& rng,
// Set K0 (the all zero key)
cipher->set_key(SymmetricKey(all_zeros));
- SecureVector<byte> buf(cipher->BLOCK_SIZE);
+ SecureVector<byte> buf(BLOCK_SIZE);
const u32bit blocks =
- (input_len + cipher->BLOCK_SIZE - 1) / cipher->BLOCK_SIZE;
+ (input_len + BLOCK_SIZE - 1) / BLOCK_SIZE;
byte* final_block = output + input_len;
- clear_mem(final_block, cipher->BLOCK_SIZE);
+ clear_mem(final_block, BLOCK_SIZE);
// XOR the hash blocks into the final block
for(u32bit i = 0; i != blocks; ++i)
{
- u32bit left = std::min<u32bit>(cipher->BLOCK_SIZE,
- input_len - cipher->BLOCK_SIZE * i);
+ u32bit left = std::min<u32bit>(BLOCK_SIZE,
+ input_len - BLOCK_SIZE * i);
zeroise(buf);
- copy_mem(&buf[0], output + cipher->BLOCK_SIZE * i, left);
+ copy_mem(&buf[0], output + BLOCK_SIZE * i, left);
for(u32bit j = 0; j != 4; ++j)
- buf[cipher->BLOCK_SIZE - 1 - j] ^= get_byte(3-j, i);
+ buf[BLOCK_SIZE - 1 - j] ^= get_byte(3-j, i);
cipher->encrypt(buf);
- xor_buf(final_block, buf, cipher->BLOCK_SIZE);
+ xor_buf(final_block, buf, BLOCK_SIZE);
}
// XOR the random package key into the final block
- xor_buf(final_block, package_key.begin(), cipher->BLOCK_SIZE);
+ xor_buf(final_block, package_key.begin(), BLOCK_SIZE);
}
void aont_unpackage(BlockCipher* cipher,
const byte input[], u32bit input_len,
byte output[])
{
- if(!cipher->valid_keylength(cipher->BLOCK_SIZE))
+ const size_t BLOCK_SIZE = cipher->block_size();
+
+ if(!cipher->valid_keylength(BLOCK_SIZE))
throw Invalid_Argument("AONT::unpackage: Invalid cipher");
- if(input_len < cipher->BLOCK_SIZE)
+ if(input_len < BLOCK_SIZE)
throw Invalid_Argument("AONT::unpackage: Input too short");
// The all-zero string which is used both as the CTR IV and as K0
- const std::string all_zeros(cipher->BLOCK_SIZE*2, '0');
+ const std::string all_zeros(BLOCK_SIZE*2, '0');
cipher->set_key(SymmetricKey(all_zeros));
- SecureVector<byte> package_key(cipher->BLOCK_SIZE);
- SecureVector<byte> buf(cipher->BLOCK_SIZE);
+ SecureVector<byte> package_key(BLOCK_SIZE);
+ SecureVector<byte> buf(BLOCK_SIZE);
// Copy the package key (masked with the block hashes)
copy_mem(&package_key[0],
- input + (input_len - cipher->BLOCK_SIZE),
- cipher->BLOCK_SIZE);
+ input + (input_len - BLOCK_SIZE),
+ BLOCK_SIZE);
- const u32bit blocks = ((input_len - 1) / cipher->BLOCK_SIZE);
+ const u32bit blocks = ((input_len - 1) / BLOCK_SIZE);
// XOR the blocks into the package key bits
for(u32bit i = 0; i != blocks; ++i)
{
- u32bit left = std::min<u32bit>(cipher->BLOCK_SIZE,
- input_len - cipher->BLOCK_SIZE * (i+1));
+ u32bit left = std::min<u32bit>(BLOCK_SIZE,
+ input_len - BLOCK_SIZE * (i+1));
zeroise(buf);
- copy_mem(&buf[0], input + cipher->BLOCK_SIZE * i, left);
+ copy_mem(&buf[0], input + BLOCK_SIZE * i, left);
for(u32bit j = 0; j != 4; ++j)
- buf[cipher->BLOCK_SIZE - 1 - j] ^= get_byte(3-j, i);
+ buf[BLOCK_SIZE - 1 - j] ^= get_byte(3-j, i);
cipher->encrypt(buf);
- xor_buf(&package_key[0], buf, cipher->BLOCK_SIZE);
+ xor_buf(&package_key[0], buf, BLOCK_SIZE);
}
Pipe pipe(new StreamCipher_Filter(new CTR_BE(cipher), package_key));
- pipe.process_msg(input, input_len - cipher->BLOCK_SIZE);
+ pipe.process_msg(input, input_len - BLOCK_SIZE);
pipe.read(output, pipe.remaining());
}
diff --git a/src/engine/core_engine/core_modes.cpp b/src/engine/core_engine/core_modes.cpp
index a0d857a11..7bd981c21 100644
--- a/src/engine/core_engine/core_modes.cpp
+++ b/src/engine/core_engine/core_modes.cpp
@@ -145,7 +145,7 @@ Keyed_Filter* get_cipher_mode(const BlockCipher* block_cipher,
std::vector<std::string> algo_info = parse_algorithm_name(mode);
std::string mode_name = algo_info[0];
if(algo_info.size() == 1)
- bits = 8*block_cipher->BLOCK_SIZE;
+ bits = 8 * block_cipher->block_size();
else if(algo_info.size() == 2)
bits = to_u32bit(algo_info[1]);
else
diff --git a/src/filters/modes/cbc/cbc.cpp b/src/filters/modes/cbc/cbc.cpp
index 8389fc070..cb7f94fc7 100644
--- a/src/filters/modes/cbc/cbc.cpp
+++ b/src/filters/modes/cbc/cbc.cpp
@@ -16,13 +16,13 @@ namespace Botan {
*/
CBC_Encryption::CBC_Encryption(BlockCipher* ciph,
BlockCipherModePaddingMethod* pad) :
- Buffered_Filter(ciph->BLOCK_SIZE, 0),
+ Buffered_Filter(ciph->block_size(), 0),
cipher(ciph), padder(pad)
{
- if(!padder->valid_blocksize(cipher->BLOCK_SIZE))
+ if(!padder->valid_blocksize(cipher->block_size()))
throw Invalid_Block_Size(name(), padder->name());
- state.resize(cipher->BLOCK_SIZE);
+ state.resize(cipher->block_size());
}
/*
@@ -32,13 +32,13 @@ CBC_Encryption::CBC_Encryption(BlockCipher* ciph,
BlockCipherModePaddingMethod* pad,
const SymmetricKey& key,
const InitializationVector& iv) :
- Buffered_Filter(ciph->BLOCK_SIZE, 0),
+ Buffered_Filter(ciph->block_size(), 0),
cipher(ciph), padder(pad)
{
- if(!padder->valid_blocksize(cipher->BLOCK_SIZE))
+ if(!padder->valid_blocksize(cipher->block_size()))
throw Invalid_Block_Size(name(), padder->name());
- state.resize(cipher->BLOCK_SIZE);
+ state.resize(cipher->block_size());
set_key(key);
set_iv(iv);
@@ -65,7 +65,7 @@ void CBC_Encryption::buffered_block(const byte input[], size_t length)
for(size_t i = 0; i != blocks; ++i)
{
- xor_buf(state, input + i * cipher->BLOCK_SIZE, state.size());
+ xor_buf(state, input + i * cipher->block_size(), state.size());
cipher->encrypt(state);
send(state, state.size());
}
@@ -76,7 +76,7 @@ void CBC_Encryption::buffered_block(const byte input[], size_t length)
*/
void CBC_Encryption::buffered_final(const byte input[], size_t length)
{
- if(length % cipher->BLOCK_SIZE == 0)
+ if(length % cipher->block_size() == 0)
buffered_block(input, length);
else if(length != 0)
throw Encoding_Error(name() + ": Did not pad to full blocksize");
@@ -89,12 +89,12 @@ void CBC_Encryption::write(const byte input[], size_t input_length)
void CBC_Encryption::end_msg()
{
- size_t last_block = current_position() % cipher->BLOCK_SIZE;
+ size_t last_block = current_position() % cipher->block_size();
- SecureVector<byte> padding(cipher->BLOCK_SIZE);
+ SecureVector<byte> padding(cipher->block_size());
padder->pad(padding, padding.size(), last_block);
- size_t pad_bytes = padder->pad_bytes(cipher->BLOCK_SIZE, last_block);
+ size_t pad_bytes = padder->pad_bytes(cipher->block_size(), last_block);
if(pad_bytes)
Buffered_Filter::write(padding, pad_bytes);
@@ -114,13 +114,13 @@ std::string CBC_Encryption::name() const
*/
CBC_Decryption::CBC_Decryption(BlockCipher* ciph,
BlockCipherModePaddingMethod* pad) :
- Buffered_Filter(ciph->parallel_bytes(), ciph->BLOCK_SIZE),
+ Buffered_Filter(ciph->parallel_bytes(), ciph->block_size()),
cipher(ciph), padder(pad)
{
- if(!padder->valid_blocksize(cipher->BLOCK_SIZE))
+ if(!padder->valid_blocksize(cipher->block_size()))
throw Invalid_Block_Size(name(), padder->name());
- state.resize(cipher->BLOCK_SIZE);
+ state.resize(cipher->block_size());
temp.resize(buffered_block_size());
}
@@ -131,13 +131,13 @@ CBC_Decryption::CBC_Decryption(BlockCipher* ciph,
BlockCipherModePaddingMethod* pad,
const SymmetricKey& key,
const InitializationVector& iv) :
- Buffered_Filter(ciph->parallel_bytes(), ciph->BLOCK_SIZE),
+ Buffered_Filter(ciph->parallel_bytes(), ciph->block_size()),
cipher(ciph), padder(pad)
{
- if(!padder->valid_blocksize(cipher->BLOCK_SIZE))
+ if(!padder->valid_blocksize(cipher->block_size()))
throw Invalid_Block_Size(name(), padder->name());
- state.resize(cipher->BLOCK_SIZE);
+ state.resize(cipher->block_size());
temp.resize(buffered_block_size());
set_key(key);
@@ -161,8 +161,8 @@ void CBC_Decryption::set_iv(const InitializationVector& iv)
*/
void CBC_Decryption::buffered_block(const byte input[], size_t length)
{
- const size_t blocks_in_temp = temp.size() / cipher->BLOCK_SIZE;
- size_t blocks = length / cipher->BLOCK_SIZE;
+ const size_t blocks_in_temp = temp.size() / cipher->block_size();
+ size_t blocks = length / cipher->block_size();
while(blocks)
{
@@ -170,18 +170,18 @@ void CBC_Decryption::buffered_block(const byte input[], size_t length)
cipher->decrypt_n(input, &temp[0], to_proc);
- xor_buf(temp, state, cipher->BLOCK_SIZE);
+ xor_buf(temp, state, cipher->block_size());
for(size_t i = 1; i < to_proc; ++i)
- xor_buf(&temp[i * cipher->BLOCK_SIZE],
- input + (i-1) * cipher->BLOCK_SIZE,
- cipher->BLOCK_SIZE);
+ xor_buf(&temp[i * cipher->block_size()],
+ input + (i-1) * cipher->block_size(),
+ cipher->block_size());
- state.set(input + (to_proc - 1) * cipher->BLOCK_SIZE, cipher->BLOCK_SIZE);
+ state.set(input + (to_proc - 1) * cipher->block_size(), cipher->block_size());
- send(temp, to_proc * cipher->BLOCK_SIZE);
+ send(temp, to_proc * cipher->block_size());
- input += to_proc * cipher->BLOCK_SIZE;
+ input += to_proc * cipher->block_size();
blocks -= to_proc;
}
}
@@ -191,18 +191,18 @@ void CBC_Decryption::buffered_block(const byte input[], size_t length)
*/
void CBC_Decryption::buffered_final(const byte input[], size_t length)
{
- if(length == 0 || length % cipher->BLOCK_SIZE != 0)
+ if(length == 0 || length % cipher->block_size() != 0)
throw Decoding_Error(name() + ": Ciphertext not multiple of block size");
- size_t extra_blocks = (length - 1) / cipher->BLOCK_SIZE;
+ size_t extra_blocks = (length - 1) / cipher->block_size();
- buffered_block(input, extra_blocks * cipher->BLOCK_SIZE);
+ buffered_block(input, extra_blocks * cipher->block_size());
- input += extra_blocks * cipher->BLOCK_SIZE;
+ input += extra_blocks * cipher->block_size();
cipher->decrypt(input, temp);
- xor_buf(temp, state, cipher->BLOCK_SIZE);
- send(temp, padder->unpad(temp, cipher->BLOCK_SIZE));
+ xor_buf(temp, state, cipher->block_size());
+ send(temp, padder->unpad(temp, cipher->block_size()));
state.set(input, state.size());
}
diff --git a/src/filters/modes/cbc/cbc.h b/src/filters/modes/cbc/cbc.h
index 801b57ec5..d828f53a6 100644
--- a/src/filters/modes/cbc/cbc.h
+++ b/src/filters/modes/cbc/cbc.h
@@ -32,7 +32,7 @@ class BOTAN_DLL CBC_Encryption : public Keyed_Filter,
{ return cipher->valid_keylength(key_len); }
bool valid_iv_length(size_t iv_len) const
- { return (iv_len == cipher->BLOCK_SIZE); }
+ { return (iv_len == cipher->block_size()); }
CBC_Encryption(BlockCipher* cipher,
BlockCipherModePaddingMethod* padding);
@@ -72,7 +72,7 @@ class BOTAN_DLL CBC_Decryption : public Keyed_Filter,
{ return cipher->valid_keylength(key_len); }
bool valid_iv_length(size_t iv_len) const
- { return (iv_len == cipher->BLOCK_SIZE); }
+ { return (iv_len == cipher->block_size()); }
CBC_Decryption(BlockCipher* cipher,
BlockCipherModePaddingMethod* padding);
diff --git a/src/filters/modes/cfb/cfb.cpp b/src/filters/modes/cfb/cfb.cpp
index 98206ed8f..8f7471c98 100644
--- a/src/filters/modes/cfb/cfb.cpp
+++ b/src/filters/modes/cfb/cfb.cpp
@@ -18,13 +18,13 @@ namespace Botan {
CFB_Encryption::CFB_Encryption(BlockCipher* ciph, size_t fback_bits)
{
cipher = ciph;
- feedback = fback_bits ? fback_bits / 8: cipher->BLOCK_SIZE;
+ feedback = fback_bits ? fback_bits / 8: cipher->block_size();
- buffer.resize(cipher->BLOCK_SIZE);
- state.resize(cipher->BLOCK_SIZE);
+ buffer.resize(cipher->block_size());
+ state.resize(cipher->block_size());
position = 0;
- if(feedback == 0 || fback_bits % 8 != 0 || feedback > cipher->BLOCK_SIZE)
+ if(feedback == 0 || fback_bits % 8 != 0 || feedback > cipher->block_size())
throw Invalid_Argument("CFB_Encryption: Invalid feedback size " +
to_string(fback_bits));
}
@@ -38,13 +38,13 @@ CFB_Encryption::CFB_Encryption(BlockCipher* ciph,
size_t fback_bits)
{
cipher = ciph;
- feedback = fback_bits ? fback_bits / 8: cipher->BLOCK_SIZE;
+ feedback = fback_bits ? fback_bits / 8: cipher->block_size();
- buffer.resize(cipher->BLOCK_SIZE);
- state.resize(cipher->BLOCK_SIZE);
+ buffer.resize(cipher->block_size());
+ state.resize(cipher->block_size());
position = 0;
- if(feedback == 0 || fback_bits % 8 != 0 || feedback > cipher->BLOCK_SIZE)
+ if(feedback == 0 || fback_bits % 8 != 0 || feedback > cipher->block_size())
throw Invalid_Argument("CFB_Encryption: Invalid feedback size " +
to_string(fback_bits));
@@ -80,9 +80,9 @@ void CFB_Encryption::write(const byte input[], size_t length)
if(position == feedback)
{
- for(size_t j = 0; j != cipher->BLOCK_SIZE - feedback; ++j)
+ for(size_t j = 0; j != cipher->block_size() - feedback; ++j)
state[j] = state[j + feedback];
- state.copy(cipher->BLOCK_SIZE - feedback, buffer, feedback);
+ state.copy(cipher->block_size() - feedback, buffer, feedback);
cipher->encrypt(state, buffer);
position = 0;
}
@@ -95,13 +95,13 @@ void CFB_Encryption::write(const byte input[], size_t length)
CFB_Decryption::CFB_Decryption(BlockCipher* ciph, size_t fback_bits)
{
cipher = ciph;
- feedback = fback_bits ? fback_bits / 8: cipher->BLOCK_SIZE;
+ feedback = fback_bits ? fback_bits / 8: cipher->block_size();
- buffer.resize(cipher->BLOCK_SIZE);
- state.resize(cipher->BLOCK_SIZE);
+ buffer.resize(cipher->block_size());
+ state.resize(cipher->block_size());
position = 0;
- if(feedback == 0 || fback_bits % 8 != 0 || feedback > cipher->BLOCK_SIZE)
+ if(feedback == 0 || fback_bits % 8 != 0 || feedback > cipher->block_size())
throw Invalid_Argument("CFB_Decryption: Invalid feedback size " +
to_string(fback_bits));
}
@@ -115,13 +115,13 @@ CFB_Decryption::CFB_Decryption(BlockCipher* ciph,
size_t fback_bits)
{
cipher = ciph;
- feedback = fback_bits ? fback_bits / 8: cipher->BLOCK_SIZE;
+ feedback = fback_bits ? fback_bits / 8: cipher->block_size();
- buffer.resize(cipher->BLOCK_SIZE);
- state.resize(cipher->BLOCK_SIZE);
+ buffer.resize(cipher->block_size());
+ state.resize(cipher->block_size());
position = 0;
- if(feedback == 0 || fback_bits % 8 != 0 || feedback > cipher->BLOCK_SIZE)
+ if(feedback == 0 || fback_bits % 8 != 0 || feedback > cipher->block_size())
throw Invalid_Argument("CFB_Decryption: Invalid feedback size " +
to_string(fback_bits));
@@ -157,9 +157,9 @@ void CFB_Decryption::write(const byte input[], size_t length)
position += xored;
if(position == feedback)
{
- for(size_t j = 0; j != cipher->BLOCK_SIZE - feedback; ++j)
+ for(size_t j = 0; j != cipher->block_size() - feedback; ++j)
state[j] = state[j + feedback];
- state.copy(cipher->BLOCK_SIZE - feedback, buffer, feedback);
+ state.copy(cipher->block_size() - feedback, buffer, feedback);
cipher->encrypt(state, buffer);
position = 0;
}
diff --git a/src/filters/modes/cfb/cfb.h b/src/filters/modes/cfb/cfb.h
index da1115f4f..64eb1e832 100644
--- a/src/filters/modes/cfb/cfb.h
+++ b/src/filters/modes/cfb/cfb.h
@@ -29,7 +29,7 @@ class BOTAN_DLL CFB_Encryption : public Keyed_Filter
{ return cipher->valid_keylength(key_len); }
bool valid_iv_length(size_t iv_len) const
- { return (iv_len == cipher->BLOCK_SIZE); }
+ { return (iv_len == cipher->block_size()); }
CFB_Encryption(BlockCipher* cipher, size_t feedback = 0);
@@ -63,7 +63,7 @@ class BOTAN_DLL CFB_Decryption : public Keyed_Filter
{ return cipher->valid_keylength(key_len); }
bool valid_iv_length(size_t iv_len) const
- { return (iv_len == cipher->BLOCK_SIZE); }
+ { return (iv_len == cipher->block_size()); }
CFB_Decryption(BlockCipher* cipher, size_t feedback = 0);
diff --git a/src/filters/modes/cts/cts.cpp b/src/filters/modes/cts/cts.cpp
index dc0082258..c654c8719 100644
--- a/src/filters/modes/cts/cts.cpp
+++ b/src/filters/modes/cts/cts.cpp
@@ -17,8 +17,8 @@ namespace Botan {
CTS_Encryption::CTS_Encryption(BlockCipher* ciph) :
cipher(ciph)
{
- buffer.resize(2 * cipher->BLOCK_SIZE);
- state.resize(cipher->BLOCK_SIZE);
+ buffer.resize(2 * cipher->block_size());
+ state.resize(cipher->block_size());
position = 0;
}
@@ -30,8 +30,8 @@ CTS_Encryption::CTS_Encryption(BlockCipher* ciph,
const InitializationVector& iv) :
cipher(ciph)
{
- buffer.resize(2 * cipher->BLOCK_SIZE);
- state.resize(cipher->BLOCK_SIZE);
+ buffer.resize(2 * cipher->block_size());
+ state.resize(cipher->block_size());
position = 0;
set_key(key);
@@ -56,9 +56,9 @@ void CTS_Encryption::set_iv(const InitializationVector& iv)
*/
void CTS_Encryption::encrypt(const byte block[])
{
- xor_buf(state, block, cipher->BLOCK_SIZE);
+ xor_buf(state, block, cipher->block_size());
cipher->encrypt(state);
- send(state, cipher->BLOCK_SIZE);
+ send(state, cipher->block_size());
}
/*
@@ -75,21 +75,21 @@ void CTS_Encryption::write(const byte input[], size_t length)
if(length == 0) return;
encrypt(&buffer[0]);
- if(length > cipher->BLOCK_SIZE)
+ if(length > cipher->block_size())
{
- encrypt(&buffer[cipher->BLOCK_SIZE]);
- while(length > 2*cipher->BLOCK_SIZE)
+ encrypt(&buffer[cipher->block_size()]);
+ while(length > 2*cipher->block_size())
{
encrypt(input);
- length -= cipher->BLOCK_SIZE;
- input += cipher->BLOCK_SIZE;
+ length -= cipher->block_size();
+ input += cipher->block_size();
}
position = 0;
}
else
{
- copy_mem(&buffer[0], &buffer[cipher->BLOCK_SIZE], cipher->BLOCK_SIZE);
- position = cipher->BLOCK_SIZE;
+ copy_mem(&buffer[0], &buffer[cipher->block_size()], cipher->block_size());
+ position = cipher->block_size();
}
buffer.copy(position, input, length);
position += length;
@@ -100,15 +100,15 @@ void CTS_Encryption::write(const byte input[], size_t length)
*/
void CTS_Encryption::end_msg()
{
- if(position < cipher->BLOCK_SIZE + 1)
+ if(position < cipher->block_size() + 1)
throw Encoding_Error(name() + ": insufficient data to encrypt");
- xor_buf(state, buffer, cipher->BLOCK_SIZE);
+ xor_buf(state, buffer, cipher->block_size());
cipher->encrypt(state);
SecureVector<byte> cn = state;
clear_mem(&buffer[position], buffer.size() - position);
- encrypt(&buffer[cipher->BLOCK_SIZE]);
- send(cn, position - cipher->BLOCK_SIZE);
+ encrypt(&buffer[cipher->block_size()]);
+ send(cn, position - cipher->block_size());
}
/*
@@ -117,9 +117,9 @@ void CTS_Encryption::end_msg()
CTS_Decryption::CTS_Decryption(BlockCipher* ciph) :
cipher(ciph)
{
- buffer.resize(2 * cipher->BLOCK_SIZE);
- state.resize(cipher->BLOCK_SIZE);
- temp.resize(cipher->BLOCK_SIZE);
+ buffer.resize(2 * cipher->block_size());
+ state.resize(cipher->block_size());
+ temp.resize(cipher->block_size());
position = 0;
}
@@ -131,9 +131,9 @@ CTS_Decryption::CTS_Decryption(BlockCipher* ciph,
const InitializationVector& iv) :
cipher(ciph)
{
- buffer.resize(2 * cipher->BLOCK_SIZE);
- state.resize(cipher->BLOCK_SIZE);
- temp.resize(cipher->BLOCK_SIZE);
+ buffer.resize(2 * cipher->block_size());
+ state.resize(cipher->block_size());
+ temp.resize(cipher->block_size());
position = 0;
set_key(key);
@@ -159,9 +159,9 @@ void CTS_Decryption::set_iv(const InitializationVector& iv)
void CTS_Decryption::decrypt(const byte block[])
{
cipher->decrypt(block, &temp[0]);
- xor_buf(temp, state, cipher->BLOCK_SIZE);
- send(temp, cipher->BLOCK_SIZE);
- state.copy(block, cipher->BLOCK_SIZE);
+ xor_buf(temp, state, cipher->block_size());
+ send(temp, cipher->block_size());
+ state.copy(block, cipher->block_size());
}
/*
@@ -178,21 +178,21 @@ void CTS_Decryption::write(const byte input[], size_t length)
if(length == 0) return;
decrypt(buffer);
- if(length > cipher->BLOCK_SIZE)
+ if(length > cipher->block_size())
{
- decrypt(&buffer[cipher->BLOCK_SIZE]);
- while(length > 2*cipher->BLOCK_SIZE)
+ decrypt(&buffer[cipher->block_size()]);
+ while(length > 2*cipher->block_size())
{
decrypt(input);
- length -= cipher->BLOCK_SIZE;
- input += cipher->BLOCK_SIZE;
+ length -= cipher->block_size();
+ input += cipher->block_size();
}
position = 0;
}
else
{
- copy_mem(&buffer[0], &buffer[cipher->BLOCK_SIZE], cipher->BLOCK_SIZE);
- position = cipher->BLOCK_SIZE;
+ copy_mem(&buffer[0], &buffer[cipher->block_size()], cipher->block_size());
+ position = cipher->block_size();
}
buffer.copy(position, input, length);
position += length;
@@ -204,18 +204,18 @@ void CTS_Decryption::write(const byte input[], size_t length)
void CTS_Decryption::end_msg()
{
cipher->decrypt(buffer, temp);
- xor_buf(temp, &buffer[cipher->BLOCK_SIZE], position - cipher->BLOCK_SIZE);
+ xor_buf(temp, &buffer[cipher->block_size()], position - cipher->block_size());
SecureVector<byte> xn = temp;
copy_mem(&buffer[position],
- &xn[position - cipher->BLOCK_SIZE],
+ &xn[position - cipher->block_size()],
buffer.size() - position);
- cipher->decrypt(&buffer[cipher->BLOCK_SIZE], temp);
- xor_buf(temp, state, cipher->BLOCK_SIZE);
- send(temp, cipher->BLOCK_SIZE);
- send(xn, position - cipher->BLOCK_SIZE);
+ cipher->decrypt(&buffer[cipher->block_size()], temp);
+ xor_buf(temp, state, cipher->block_size());
+ send(temp, cipher->block_size());
+ send(xn, position - cipher->block_size());
}
}
diff --git a/src/filters/modes/cts/cts.h b/src/filters/modes/cts/cts.h
index 51d6dec3e..8e19073f4 100644
--- a/src/filters/modes/cts/cts.h
+++ b/src/filters/modes/cts/cts.h
@@ -29,7 +29,7 @@ class BOTAN_DLL CTS_Encryption : public Keyed_Filter
{ return cipher->valid_keylength(key_len); }
bool valid_iv_length(size_t iv_len) const
- { return (iv_len == cipher->BLOCK_SIZE); }
+ { return (iv_len == cipher->block_size()); }
CTS_Encryption(BlockCipher* cipher);
@@ -64,7 +64,7 @@ class BOTAN_DLL CTS_Decryption : public Keyed_Filter
{ return cipher->valid_keylength(key_len); }
bool valid_iv_length(size_t iv_len) const
- { return (iv_len == cipher->BLOCK_SIZE); }
+ { return (iv_len == cipher->block_size()); }
CTS_Decryption(BlockCipher* cipher);
diff --git a/src/filters/modes/eax/eax.cpp b/src/filters/modes/eax/eax.cpp
index bd8633ad7..6d6d9ec18 100644
--- a/src/filters/modes/eax/eax.cpp
+++ b/src/filters/modes/eax/eax.cpp
@@ -23,7 +23,7 @@ SecureVector<byte> eax_prf(byte tag, size_t BLOCK_SIZE,
MessageAuthenticationCode* mac,
const byte in[], size_t length)
{
- for(size_t j = 0; j != BLOCK_SIZE - 1; ++j)
+ for(size_t i = 0; i != BLOCK_SIZE - 1; ++i)
mac->update(0);
mac->update(tag);
mac->update(in, length);
@@ -36,7 +36,7 @@ SecureVector<byte> eax_prf(byte tag, size_t BLOCK_SIZE,
* EAX_Base Constructor
*/
EAX_Base::EAX_Base(BlockCipher* cipher, size_t tag_size) :
- BLOCK_SIZE(cipher->BLOCK_SIZE),
+ BLOCK_SIZE(cipher->block_size()),
TAG_SIZE(tag_size ? tag_size / 8 : BLOCK_SIZE),
cipher_name(cipher->name()),
ctr_buf(DEFAULT_BUFFERSIZE)
@@ -78,7 +78,7 @@ void EAX_Base::set_key(const SymmetricKey& key)
*/
void EAX_Base::start_msg()
{
- for(size_t j = 0; j != BLOCK_SIZE - 1; ++j)
+ for(size_t i = 0; i != BLOCK_SIZE - 1; ++i)
cmac->update(0);
cmac->update(2);
}
diff --git a/src/filters/modes/ecb/ecb.cpp b/src/filters/modes/ecb/ecb.cpp
index 2a3ecf6f9..9115d6362 100644
--- a/src/filters/modes/ecb/ecb.cpp
+++ b/src/filters/modes/ecb/ecb.cpp
@@ -68,12 +68,12 @@ void ECB_Encryption::write(const byte input[], size_t length)
*/
void ECB_Encryption::end_msg()
{
- size_t last_block = current_position() % cipher->BLOCK_SIZE;
+ size_t last_block = current_position() % cipher->block_size();
- SecureVector<byte> padding(cipher->BLOCK_SIZE);
+ SecureVector<byte> padding(cipher->block_size());
padder->pad(padding, padding.size(), last_block);
- size_t pad_bytes = padder->pad_bytes(cipher->BLOCK_SIZE, last_block);
+ size_t pad_bytes = padder->pad_bytes(cipher->block_size(), last_block);
if(pad_bytes)
Buffered_Filter::write(padding, pad_bytes);
@@ -82,8 +82,8 @@ void ECB_Encryption::end_msg()
void ECB_Encryption::buffered_block(const byte input[], size_t input_length)
{
- const size_t blocks_in_temp = temp.size() / cipher->BLOCK_SIZE;
- size_t blocks = input_length / cipher->BLOCK_SIZE;
+ const size_t blocks_in_temp = temp.size() / cipher->block_size();
+ size_t blocks = input_length / cipher->block_size();
while(blocks)
{
@@ -91,16 +91,16 @@ void ECB_Encryption::buffered_block(const byte input[], size_t input_length)
cipher->encrypt_n(input, &temp[0], to_proc);
- send(temp, to_proc * cipher->BLOCK_SIZE);
+ send(temp, to_proc * cipher->block_size());
- input += to_proc * cipher->BLOCK_SIZE;
+ input += to_proc * cipher->block_size();
blocks -= to_proc;
}
}
void ECB_Encryption::buffered_final(const byte input[], size_t input_length)
{
- if(input_length % cipher->BLOCK_SIZE == 0)
+ if(input_length % cipher->block_size() == 0)
buffered_block(input, input_length);
else if(input_length != 0)
throw Encoding_Error(name() + ": Did not pad to full blocksize");
@@ -173,8 +173,8 @@ void ECB_Decryption::end_msg()
*/
void ECB_Decryption::buffered_block(const byte input[], size_t length)
{
- const size_t blocks_in_temp = temp.size() / cipher->BLOCK_SIZE;
- size_t blocks = length / cipher->BLOCK_SIZE;
+ const size_t blocks_in_temp = temp.size() / cipher->block_size();
+ size_t blocks = length / cipher->block_size();
while(blocks)
{
@@ -182,9 +182,9 @@ void ECB_Decryption::buffered_block(const byte input[], size_t length)
cipher->decrypt_n(input, &temp[0], to_proc);
- send(temp, to_proc * cipher->BLOCK_SIZE);
+ send(temp, to_proc * cipher->block_size());
- input += to_proc * cipher->BLOCK_SIZE;
+ input += to_proc * cipher->block_size();
blocks -= to_proc;
}
}
@@ -194,17 +194,17 @@ void ECB_Decryption::buffered_block(const byte input[], size_t length)
*/
void ECB_Decryption::buffered_final(const byte input[], size_t length)
{
- if(length == 0 || length % cipher->BLOCK_SIZE != 0)
+ if(length == 0 || length % cipher->block_size() != 0)
throw Decoding_Error(name() + ": Ciphertext not multiple of block size");
- size_t extra_blocks = (length - 1) / cipher->BLOCK_SIZE;
+ size_t extra_blocks = (length - 1) / cipher->block_size();
- buffered_block(input, extra_blocks * cipher->BLOCK_SIZE);
+ buffered_block(input, extra_blocks * cipher->block_size());
- input += extra_blocks * cipher->BLOCK_SIZE;
+ input += extra_blocks * cipher->block_size();
cipher->decrypt(input, temp);
- send(temp, padder->unpad(temp, cipher->BLOCK_SIZE));
+ send(temp, padder->unpad(temp, cipher->block_size()));
}
}
diff --git a/src/filters/modes/xts/xts.cpp b/src/filters/modes/xts/xts.cpp
index 176746d0f..2d2957088 100644
--- a/src/filters/modes/xts/xts.cpp
+++ b/src/filters/modes/xts/xts.cpp
@@ -36,7 +36,7 @@ void poly_double(byte tweak[], size_t size)
size_t xts_parallelism(BlockCipher* cipher)
{
return std::max<size_t>(cipher->parallel_bytes(),
- 2 * cipher->BLOCK_SIZE);
+ 2 * cipher->block_size());
}
}
@@ -45,10 +45,10 @@ size_t xts_parallelism(BlockCipher* cipher)
* XTS_Encryption constructor
*/
XTS_Encryption::XTS_Encryption(BlockCipher* ciph) :
- Buffered_Filter(xts_parallelism(ciph), ciph->BLOCK_SIZE + 1),
+ Buffered_Filter(xts_parallelism(ciph), ciph->block_size() + 1),
cipher(ciph)
{
- if(cipher->BLOCK_SIZE != 8 && cipher->BLOCK_SIZE != 16)
+ if(cipher->block_size() != 8 && cipher->block_size() != 16)
throw std::invalid_argument("Bad cipher for XTS: " + cipher->name());
cipher2 = cipher->clone();
@@ -61,10 +61,10 @@ XTS_Encryption::XTS_Encryption(BlockCipher* ciph) :
XTS_Encryption::XTS_Encryption(BlockCipher* ciph,
const SymmetricKey& key,
const InitializationVector& iv) :
- Buffered_Filter(xts_parallelism(ciph), ciph->BLOCK_SIZE + 1),
+ Buffered_Filter(xts_parallelism(ciph), ciph->block_size() + 1),
cipher(ciph)
{
- if(cipher->BLOCK_SIZE != 8 && cipher->BLOCK_SIZE != 16)
+ if(cipher->block_size() != 8 && cipher->block_size() != 16)
throw std::invalid_argument("Bad cipher for XTS: " + cipher->name());
cipher2 = cipher->clone();
@@ -90,18 +90,18 @@ void XTS_Encryption::set_iv(const InitializationVector& iv)
if(!valid_iv_length(iv.length()))
throw Invalid_IV_Length(name(), iv.length());
- const size_t blocks_in_tweak = tweak.size() / cipher->BLOCK_SIZE;
+ const size_t blocks_in_tweak = tweak.size() / cipher->block_size();
tweak.copy(iv.begin(), iv.length());
cipher2->encrypt(tweak);
for(size_t i = 1; i < blocks_in_tweak; ++i)
{
- tweak.copy(i*cipher->BLOCK_SIZE,
- &tweak[(i-1)*cipher->BLOCK_SIZE],
- cipher->BLOCK_SIZE);
+ tweak.copy(i*cipher->block_size(),
+ &tweak[(i-1)*cipher->block_size()],
+ cipher->block_size());
- poly_double(&tweak[i*cipher->BLOCK_SIZE], cipher->BLOCK_SIZE);
+ poly_double(&tweak[i*cipher->block_size()], cipher->block_size());
}
}
@@ -133,15 +133,15 @@ void XTS_Encryption::end_msg()
void XTS_Encryption::buffered_block(const byte input[], size_t length)
{
- const size_t blocks_in_tweak = tweak.size() / cipher->BLOCK_SIZE;
- size_t blocks = length / cipher->BLOCK_SIZE;
+ const size_t blocks_in_tweak = tweak.size() / cipher->block_size();
+ size_t blocks = length / cipher->block_size();
SecureVector<byte> temp(tweak.size());
while(blocks)
{
size_t to_proc = std::min(blocks, blocks_in_tweak);
- size_t to_proc_bytes = to_proc * cipher->BLOCK_SIZE;
+ size_t to_proc_bytes = to_proc * cipher->block_size();
xor_buf(temp, input, tweak, to_proc_bytes);
@@ -151,20 +151,20 @@ void XTS_Encryption::buffered_block(const byte input[], size_t length)
send(temp, to_proc_bytes);
- tweak.copy(&tweak[(to_proc-1)*cipher->BLOCK_SIZE],
- cipher->BLOCK_SIZE);
- poly_double(&tweak[0], cipher->BLOCK_SIZE);
+ tweak.copy(&tweak[(to_proc-1)*cipher->block_size()],
+ cipher->block_size());
+ poly_double(&tweak[0], cipher->block_size());
for(size_t i = 1; i < blocks_in_tweak; ++i)
{
- tweak.copy(i*cipher->BLOCK_SIZE,
- &tweak[(i-1)*cipher->BLOCK_SIZE],
- cipher->BLOCK_SIZE);
+ tweak.copy(i*cipher->block_size(),
+ &tweak[(i-1)*cipher->block_size()],
+ cipher->block_size());
- poly_double(&tweak[i*cipher->BLOCK_SIZE], cipher->BLOCK_SIZE);
+ poly_double(&tweak[i*cipher->block_size()], cipher->block_size());
}
- input += to_proc * cipher->BLOCK_SIZE;
+ input += to_proc * cipher->block_size();
blocks -= to_proc;
}
}
@@ -174,10 +174,10 @@ void XTS_Encryption::buffered_block(const byte input[], size_t length)
*/
void XTS_Encryption::buffered_final(const byte input[], size_t length)
{
- if(length <= cipher->BLOCK_SIZE)
+ if(length <= cipher->block_size())
throw Encoding_Error("XTS_Encryption: insufficient data to encrypt");
- if(length % cipher->BLOCK_SIZE == 0)
+ if(length % cipher->block_size() == 0)
{
buffered_block(input, length);
}
@@ -185,7 +185,7 @@ void XTS_Encryption::buffered_final(const byte input[], size_t length)
{ // steal ciphertext
size_t leftover_blocks =
- ((length / cipher->BLOCK_SIZE) - 1) * cipher->BLOCK_SIZE;
+ ((length / cipher->block_size()) - 1) * cipher->block_size();
buffered_block(input, leftover_blocks);
@@ -194,18 +194,18 @@ void XTS_Encryption::buffered_final(const byte input[], size_t length)
SecureVector<byte> temp(input, length);
- xor_buf(temp, tweak, cipher->BLOCK_SIZE);
+ xor_buf(temp, tweak, cipher->block_size());
cipher->encrypt(temp);
- xor_buf(temp, tweak, cipher->BLOCK_SIZE);
+ xor_buf(temp, tweak, cipher->block_size());
- poly_double(&tweak[0], cipher->BLOCK_SIZE);
+ poly_double(&tweak[0], cipher->block_size());
- for(size_t i = 0; i != length - cipher->BLOCK_SIZE; ++i)
- std::swap(temp[i], temp[i + cipher->BLOCK_SIZE]);
+ for(size_t i = 0; i != length - cipher->block_size(); ++i)
+ std::swap(temp[i], temp[i + cipher->block_size()]);
- xor_buf(temp, tweak, cipher->BLOCK_SIZE);
+ xor_buf(temp, tweak, cipher->block_size());
cipher->encrypt(temp);
- xor_buf(temp, tweak, cipher->BLOCK_SIZE);
+ xor_buf(temp, tweak, cipher->block_size());
send(temp, temp.size());
}
@@ -217,10 +217,10 @@ void XTS_Encryption::buffered_final(const byte input[], size_t length)
* XTS_Decryption constructor
*/
XTS_Decryption::XTS_Decryption(BlockCipher* ciph) :
- Buffered_Filter(xts_parallelism(ciph), ciph->BLOCK_SIZE + 1),
+ Buffered_Filter(xts_parallelism(ciph), ciph->block_size() + 1),
cipher(ciph)
{
- if(cipher->BLOCK_SIZE != 8 && cipher->BLOCK_SIZE != 16)
+ if(cipher->block_size() != 8 && cipher->block_size() != 16)
throw std::invalid_argument("Bad cipher for XTS: " + cipher->name());
cipher2 = ciph->clone();
@@ -233,10 +233,10 @@ XTS_Decryption::XTS_Decryption(BlockCipher* ciph) :
XTS_Decryption::XTS_Decryption(BlockCipher* ciph,
const SymmetricKey& key,
const InitializationVector& iv) :
- Buffered_Filter(xts_parallelism(ciph), ciph->BLOCK_SIZE + 1),
+ Buffered_Filter(xts_parallelism(ciph), ciph->block_size() + 1),
cipher(ciph)
{
- if(cipher->BLOCK_SIZE != 8 && cipher->BLOCK_SIZE != 16)
+ if(cipher->block_size() != 8 && cipher->block_size() != 16)
throw std::invalid_argument("Bad cipher for XTS: " + cipher->name());
cipher2 = ciph->clone();
@@ -262,18 +262,18 @@ void XTS_Decryption::set_iv(const InitializationVector& iv)
if(!valid_iv_length(iv.length()))
throw Invalid_IV_Length(name(), iv.length());
- const size_t blocks_in_tweak = tweak.size() / cipher->BLOCK_SIZE;
+ const size_t blocks_in_tweak = tweak.size() / cipher->block_size();
tweak.copy(iv.begin(), iv.length());
cipher2->encrypt(tweak);
for(size_t i = 1; i < blocks_in_tweak; ++i)
{
- tweak.copy(i*cipher->BLOCK_SIZE,
- &tweak[(i-1)*cipher->BLOCK_SIZE],
- cipher->BLOCK_SIZE);
+ tweak.copy(i*cipher->block_size(),
+ &tweak[(i-1)*cipher->block_size()],
+ cipher->block_size());
- poly_double(&tweak[i*cipher->BLOCK_SIZE], cipher->BLOCK_SIZE);
+ poly_double(&tweak[i*cipher->block_size()], cipher->block_size());
}
}
@@ -306,15 +306,15 @@ void XTS_Decryption::end_msg()
void XTS_Decryption::buffered_block(const byte input[], size_t input_length)
{
- const size_t blocks_in_tweak = tweak.size() / cipher->BLOCK_SIZE;
- size_t blocks = input_length / cipher->BLOCK_SIZE;
+ const size_t blocks_in_tweak = tweak.size() / cipher->block_size();
+ size_t blocks = input_length / cipher->block_size();
SecureVector<byte> temp(tweak.size());
while(blocks)
{
size_t to_proc = std::min(blocks, blocks_in_tweak);
- size_t to_proc_bytes = to_proc * cipher->BLOCK_SIZE;
+ size_t to_proc_bytes = to_proc * cipher->block_size();
xor_buf(temp, input, tweak, to_proc_bytes);
@@ -324,37 +324,37 @@ void XTS_Decryption::buffered_block(const byte input[], size_t input_length)
send(temp, to_proc_bytes);
- tweak.copy(&tweak[(to_proc-1)*cipher->BLOCK_SIZE],
- cipher->BLOCK_SIZE);
- poly_double(&tweak[0], cipher->BLOCK_SIZE);
+ tweak.copy(&tweak[(to_proc-1)*cipher->block_size()],
+ cipher->block_size());
+ poly_double(&tweak[0], cipher->block_size());
for(size_t i = 1; i < blocks_in_tweak; ++i)
{
- tweak.copy(i*cipher->BLOCK_SIZE,
- &tweak[(i-1)*cipher->BLOCK_SIZE],
- cipher->BLOCK_SIZE);
+ tweak.copy(i*cipher->block_size(),
+ &tweak[(i-1)*cipher->block_size()],
+ cipher->block_size());
- poly_double(&tweak[i*cipher->BLOCK_SIZE], cipher->BLOCK_SIZE);
+ poly_double(&tweak[i*cipher->block_size()], cipher->block_size());
}
- input += to_proc * cipher->BLOCK_SIZE;
+ input += to_proc * cipher->block_size();
blocks -= to_proc;
}
}
void XTS_Decryption::buffered_final(const byte input[], size_t length)
{
- if(length <= cipher->BLOCK_SIZE)
+ if(length <= cipher->block_size())
throw Decoding_Error("XTS_Decryption: insufficient data to decrypt");
- if(length % cipher->BLOCK_SIZE == 0)
+ if(length % cipher->block_size() == 0)
{
buffered_block(input, length);
}
else
{
size_t leftover_blocks =
- ((length / cipher->BLOCK_SIZE) - 1) * cipher->BLOCK_SIZE;
+ ((length / cipher->block_size()) - 1) * cipher->block_size();
buffered_block(input, leftover_blocks);
@@ -362,20 +362,20 @@ void XTS_Decryption::buffered_final(const byte input[], size_t length)
length -= leftover_blocks;
SecureVector<byte> temp(input, length);
- SecureVector<byte> tweak_copy(&tweak[0], cipher->BLOCK_SIZE);
+ SecureVector<byte> tweak_copy(&tweak[0], cipher->block_size());
- poly_double(&tweak_copy[0], cipher->BLOCK_SIZE);
+ poly_double(&tweak_copy[0], cipher->block_size());
- xor_buf(temp, tweak_copy, cipher->BLOCK_SIZE);
+ xor_buf(temp, tweak_copy, cipher->block_size());
cipher->decrypt(temp);
- xor_buf(temp, tweak_copy, cipher->BLOCK_SIZE);
+ xor_buf(temp, tweak_copy, cipher->block_size());
- for(size_t i = 0; i != length - cipher->BLOCK_SIZE; ++i)
- std::swap(temp[i], temp[i + cipher->BLOCK_SIZE]);
+ for(size_t i = 0; i != length - cipher->block_size(); ++i)
+ std::swap(temp[i], temp[i + cipher->block_size()]);
- xor_buf(temp, tweak, cipher->BLOCK_SIZE);
+ xor_buf(temp, tweak, cipher->block_size());
cipher->decrypt(temp);
- xor_buf(temp, tweak, cipher->BLOCK_SIZE);
+ xor_buf(temp, tweak, cipher->block_size());
send(temp, length);
}
diff --git a/src/filters/modes/xts/xts.h b/src/filters/modes/xts/xts.h
index 0cf7080bd..52db9bcfc 100644
--- a/src/filters/modes/xts/xts.h
+++ b/src/filters/modes/xts/xts.h
@@ -28,7 +28,7 @@ class BOTAN_DLL XTS_Encryption : public Keyed_Filter,
{ return cipher->valid_keylength(key_len); }
bool valid_iv_length(size_t iv_len) const
- { return (iv_len == cipher->BLOCK_SIZE); }
+ { return (iv_len == cipher->block_size()); }
std::string name() const;
@@ -65,7 +65,7 @@ class BOTAN_DLL XTS_Decryption : public Keyed_Filter,
{ return cipher->valid_keylength(key_len); }
bool valid_iv_length(size_t iv_len) const
- { return (iv_len == cipher->BLOCK_SIZE); }
+ { return (iv_len == cipher->block_size()); }
std::string name() const;
diff --git a/src/libstate/lookup.cpp b/src/libstate/lookup.cpp
index c701ad8e3..ad0362264 100644
--- a/src/libstate/lookup.cpp
+++ b/src/libstate/lookup.cpp
@@ -37,7 +37,7 @@ u32bit block_size_of(const std::string& name)
Algorithm_Factory& af = global_state().algorithm_factory();
if(const BlockCipher* cipher = af.prototype_block_cipher(name))
- return cipher->BLOCK_SIZE;
+ return cipher->block_size();
if(const HashFunction* hash = af.prototype_hash_function(name))
return hash->HASH_BLOCK_SIZE;
diff --git a/src/mac/cbc_mac/cbc_mac.cpp b/src/mac/cbc_mac/cbc_mac.cpp
index 3eaa115b8..48cc8ab3e 100644
--- a/src/mac/cbc_mac/cbc_mac.cpp
+++ b/src/mac/cbc_mac/cbc_mac.cpp
@@ -89,11 +89,11 @@ MessageAuthenticationCode* CBC_MAC::clone() const
* CBC-MAC Constructor
*/
CBC_MAC::CBC_MAC(BlockCipher* e_in) :
- MessageAuthenticationCode(e_in->BLOCK_SIZE,
+ MessageAuthenticationCode(e_in->block_size(),
e_in->MINIMUM_KEYLENGTH,
e_in->MAXIMUM_KEYLENGTH,
e_in->KEYLENGTH_MULTIPLE),
- e(e_in), state(e->BLOCK_SIZE)
+ e(e_in), state(e->block_size())
{
position = 0;
}
diff --git a/src/mac/cmac/cmac.cpp b/src/mac/cmac/cmac.cpp
index a4a9394ae..2147f9a45 100644
--- a/src/mac/cmac/cmac.cpp
+++ b/src/mac/cmac/cmac.cpp
@@ -131,15 +131,15 @@ MessageAuthenticationCode* CMAC::clone() const
* CMAC Constructor
*/
CMAC::CMAC(BlockCipher* e_in) :
- MessageAuthenticationCode(e_in->BLOCK_SIZE,
+ MessageAuthenticationCode(e_in->block_size(),
e_in->MINIMUM_KEYLENGTH,
e_in->MAXIMUM_KEYLENGTH,
e_in->KEYLENGTH_MULTIPLE),
e(e_in)
{
- if(e->BLOCK_SIZE == 16)
+ if(e->block_size() == 16)
polynomial = 0x87;
- else if(e->BLOCK_SIZE == 8)
+ else if(e->block_size() == 8)
polynomial = 0x1B;
else
throw Invalid_Argument("CMAC cannot use the cipher " + e->name());
diff --git a/src/mac/x919_mac/x919_mac.cpp b/src/mac/x919_mac/x919_mac.cpp
index 330ca0043..c46ab82cb 100644
--- a/src/mac/x919_mac/x919_mac.cpp
+++ b/src/mac/x919_mac/x919_mac.cpp
@@ -85,11 +85,11 @@ MessageAuthenticationCode* ANSI_X919_MAC::clone() const
* ANSI X9.19 MAC Constructor
*/
ANSI_X919_MAC::ANSI_X919_MAC(BlockCipher* e_in) :
- MessageAuthenticationCode(e_in->BLOCK_SIZE,
+ MessageAuthenticationCode(e_in->block_size(),
e_in->MINIMUM_KEYLENGTH,
2*e_in->MAXIMUM_KEYLENGTH,
2*e_in->KEYLENGTH_MULTIPLE),
- e(e_in), d(e->clone()), state(e->BLOCK_SIZE), position(0)
+ e(e_in), d(e->clone()), state(e->block_size()), position(0)
{
if(e->name() != "DES")
throw Invalid_Argument("ANSI X9.19 MAC only supports DES");
diff --git a/src/pbe/pbes2/pbes2.cpp b/src/pbe/pbes2/pbes2.cpp
index 7188e42d7..e74609467 100644
--- a/src/pbe/pbes2/pbes2.cpp
+++ b/src/pbe/pbes2/pbes2.cpp
@@ -101,7 +101,7 @@ void PBE_PKCS5v20::new_params(RandomNumberGenerator& rng)
key_length = block_cipher->MAXIMUM_KEYLENGTH;
salt = rng.random_vec(12);
- iv = rng.random_vec(block_cipher->BLOCK_SIZE);
+ iv = rng.random_vec(block_cipher->block_size());
}
/*
diff --git a/src/rng/randpool/randpool.cpp b/src/rng/randpool/randpool.cpp
index e66081a07..92f225a9c 100644
--- a/src/rng/randpool/randpool.cpp
+++ b/src/rng/randpool/randpool.cpp
@@ -71,7 +71,7 @@ void Randpool::update_buffer()
*/
void Randpool::mix_pool()
{
- const size_t BLOCK_SIZE = cipher->BLOCK_SIZE;
+ const size_t BLOCK_SIZE = cipher->block_size();
mac->update(static_cast<byte>(MAC_KEY));
mac->update(pool);
@@ -175,7 +175,7 @@ Randpool::Randpool(BlockCipher* cipher_in,
cipher(cipher_in),
mac(mac_in)
{
- const size_t BLOCK_SIZE = cipher->BLOCK_SIZE;
+ const size_t BLOCK_SIZE = cipher->block_size();
const size_t OUTPUT_LENGTH = mac->output_length();
if(OUTPUT_LENGTH < BLOCK_SIZE ||
diff --git a/src/rng/x931_rng/x931_rng.cpp b/src/rng/x931_rng/x931_rng.cpp
index 6da1e214d..0911ce526 100644
--- a/src/rng/x931_rng/x931_rng.cpp
+++ b/src/rng/x931_rng/x931_rng.cpp
@@ -38,13 +38,15 @@ void ANSI_X931_RNG::randomize(byte out[], size_t length)
*/
void ANSI_X931_RNG::update_buffer()
{
- SecureVector<byte> DT = prng->random_vec(cipher->BLOCK_SIZE);
+ const size_t BLOCK_SIZE = cipher->block_size();
+
+ SecureVector<byte> DT = prng->random_vec(BLOCK_SIZE);
cipher->encrypt(DT);
- xor_buf(&R[0], &V[0], &DT[0], cipher->BLOCK_SIZE);
+ xor_buf(&R[0], &V[0], &DT[0], BLOCK_SIZE);
cipher->encrypt(R);
- xor_buf(&V[0], &R[0], &DT[0], cipher->BLOCK_SIZE);
+ xor_buf(&V[0], &R[0], &DT[0], BLOCK_SIZE);
cipher->encrypt(V);
position = 0;
@@ -55,12 +57,14 @@ void ANSI_X931_RNG::update_buffer()
*/
void ANSI_X931_RNG::rekey()
{
+ const size_t BLOCK_SIZE = cipher->block_size();
+
if(prng->is_seeded())
{
cipher->set_key(prng->random_vec(cipher->MAXIMUM_KEYLENGTH));
- if(V.size() != cipher->BLOCK_SIZE)
- V.resize(cipher->BLOCK_SIZE);
+ if(V.size() != BLOCK_SIZE)
+ V.resize(BLOCK_SIZE);
prng->randomize(&V[0], V.size());
update_buffer();
@@ -134,7 +138,7 @@ ANSI_X931_RNG::ANSI_X931_RNG(BlockCipher* cipher_in,
cipher = cipher_in;
prng = prng_in;
- R.resize(cipher->BLOCK_SIZE);
+ R.resize(cipher->block_size());
position = 0;
}
diff --git a/src/stream/ctr/ctr.cpp b/src/stream/ctr/ctr.cpp
index 0a962bd5a..dc2f334a8 100644
--- a/src/stream/ctr/ctr.cpp
+++ b/src/stream/ctr/ctr.cpp
@@ -89,7 +89,7 @@ void CTR_BE::set_iv(const byte iv[], size_t iv_len)
if(!valid_iv_length(iv_len))
throw Invalid_IV_Length(name(), iv_len);
- const size_t BLOCK_SIZE = permutation->BLOCK_SIZE;
+ const size_t BLOCK_SIZE = permutation->block_size();
zeroise(counter);
@@ -117,21 +117,22 @@ void CTR_BE::set_iv(const byte iv[], size_t iv_len)
*/
void CTR_BE::increment_counter()
{
- const size_t PARALLEL_BLOCKS = counter.size() / permutation->BLOCK_SIZE;
+ const size_t BLOCK_SIZE = permutation->block_size();
+ const size_t PARALLEL_BLOCKS = counter.size() / BLOCK_SIZE;
for(size_t i = 0; i != PARALLEL_BLOCKS; ++i)
{
- byte* this_ctr = &counter[i * permutation->BLOCK_SIZE];
+ byte* this_ctr = &counter[i * BLOCK_SIZE];
- byte last_byte = this_ctr[permutation->BLOCK_SIZE-1];
+ byte last_byte = this_ctr[BLOCK_SIZE-1];
last_byte += PARALLEL_BLOCKS;
- if(this_ctr[permutation->BLOCK_SIZE-1] > last_byte)
- for(s32bit j = permutation->BLOCK_SIZE - 2; j >= 0; --j)
+ if(this_ctr[BLOCK_SIZE-1] > last_byte)
+ for(s32bit j = BLOCK_SIZE - 2; j >= 0; --j)
if(++this_ctr[j])
break;
- this_ctr[permutation->BLOCK_SIZE-1] = last_byte;
+ this_ctr[BLOCK_SIZE-1] = last_byte;
}
permutation->encrypt_n(&counter[0], &buffer[0], PARALLEL_BLOCKS);
diff --git a/src/stream/ctr/ctr.h b/src/stream/ctr/ctr.h
index 8c317acb0..e62ab2860 100644
--- a/src/stream/ctr/ctr.h
+++ b/src/stream/ctr/ctr.h
@@ -24,7 +24,7 @@ class BOTAN_DLL CTR_BE : public StreamCipher
void set_iv(const byte iv[], size_t iv_len);
bool valid_iv_length(size_t iv_len) const
- { return (iv_len <= permutation->BLOCK_SIZE); }
+ { return (iv_len <= permutation->block_size()); }
std::string name() const;
diff --git a/src/stream/ofb/ofb.cpp b/src/stream/ofb/ofb.cpp
index 921401d32..1f25c5c14 100644
--- a/src/stream/ofb/ofb.cpp
+++ b/src/stream/ofb/ofb.cpp
@@ -21,7 +21,7 @@ OFB::OFB(BlockCipher* ciph) :
permutation(ciph)
{
position = 0;
- buffer.resize(permutation->BLOCK_SIZE);
+ buffer.resize(permutation->block_size());
}
/*
diff --git a/src/stream/ofb/ofb.h b/src/stream/ofb/ofb.h
index af771de15..587a30bab 100644
--- a/src/stream/ofb/ofb.h
+++ b/src/stream/ofb/ofb.h
@@ -24,7 +24,7 @@ class BOTAN_DLL OFB : public StreamCipher
void set_iv(const byte iv[], size_t iv_len);
bool valid_iv_length(size_t iv_len) const
- { return (iv_len <= permutation->BLOCK_SIZE); }
+ { return (iv_len <= permutation->block_size()); }
std::string name() const;