aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/block/block_cipher.h5
-rw-r--r--src/build-data/buildh.in11
-rw-r--r--src/filters/buf_filt.h2
-rw-r--r--src/filters/modes/cbc/cbc.cpp8
-rw-r--r--src/filters/modes/ecb/ecb.cpp16
-rw-r--r--src/filters/modes/xts/xts.cpp24
-rw-r--r--src/stream/ctr/ctr.cpp4
7 files changed, 37 insertions, 33 deletions
diff --git a/src/block/block_cipher.h b/src/block/block_cipher.h
index 06e8c5cea..b3e1b0e31 100644
--- a/src/block/block_cipher.h
+++ b/src/block/block_cipher.h
@@ -24,6 +24,11 @@ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm
const u32bit BLOCK_SIZE;
/**
+ * @return the preferred parallelism of this cipher
+ */
+ virtual u32bit parallelism() const { return 1; }
+
+ /**
* Encrypt a block.
* @param in The plaintext block to be encrypted as a byte array.
* Must be of length BLOCK_SIZE.
diff --git a/src/build-data/buildh.in b/src/build-data/buildh.in
index 231a7aeeb..6412d8a6a 100644
--- a/src/build-data/buildh.in
+++ b/src/build-data/buildh.in
@@ -22,17 +22,6 @@
#define BOTAN_KARAT_SQR_THRESHOLD 32
#define BOTAN_PRIVATE_KEY_OP_BLINDING_BITS 64
-/*
-* Toggles for parallel block cipher mode processing
-*
-* CBC and CFB can only use parallel processing in decryption mode
-*/
-#define BOTAN_PARALLEL_BLOCKS_ECB 16
-#define BOTAN_PARALLEL_BLOCKS_CBC 16
-#define BOTAN_PARALLEL_BLOCKS_CFB 16
-#define BOTAN_PARALLEL_BLOCKS_CTR 16
-#define BOTAN_PARALLEL_BLOCKS_XTS 16
-
/* PK key consistency checking toggles */
#define BOTAN_PUBLIC_KEY_STRONG_CHECKS_ON_LOAD 1
#define BOTAN_PRIVATE_KEY_STRONG_CHECKS_ON_LOAD 1
diff --git a/src/filters/buf_filt.h b/src/filters/buf_filt.h
index de4102844..582f585b0 100644
--- a/src/filters/buf_filt.h
+++ b/src/filters/buf_filt.h
@@ -27,6 +27,8 @@ class BOTAN_DLL Buffered_Filter
virtual void buffered_block(const byte input[], u32bit length) = 0;
virtual void buffered_final(const byte input[], u32bit length) = 0;
+ u32bit buffered_block_size() const { return main_block_mod; }
+
u32bit current_position() const { return buffer_pos; }
void buffer_reset() { buffer_pos = 0; }
private:
diff --git a/src/filters/modes/cbc/cbc.cpp b/src/filters/modes/cbc/cbc.cpp
index 7722fad2f..4f484da77 100644
--- a/src/filters/modes/cbc/cbc.cpp
+++ b/src/filters/modes/cbc/cbc.cpp
@@ -114,7 +114,7 @@ std::string CBC_Encryption::name() const
*/
CBC_Decryption::CBC_Decryption(BlockCipher* ciph,
BlockCipherModePaddingMethod* pad) :
- Buffered_Filter(BOTAN_PARALLEL_BLOCKS_CBC * ciph->BLOCK_SIZE,
+ Buffered_Filter(ciph->parallelism() * ciph->BLOCK_SIZE,
ciph->BLOCK_SIZE),
cipher(ciph), padder(pad)
{
@@ -122,7 +122,7 @@ CBC_Decryption::CBC_Decryption(BlockCipher* ciph,
throw Invalid_Block_Size(name(), padder->name());
state.resize(cipher->BLOCK_SIZE);
- temp.resize(BOTAN_PARALLEL_BLOCKS_CBC * cipher->BLOCK_SIZE);
+ temp.resize(buffered_block_size());
}
/*
@@ -132,7 +132,7 @@ CBC_Decryption::CBC_Decryption(BlockCipher* ciph,
BlockCipherModePaddingMethod* pad,
const SymmetricKey& key,
const InitializationVector& iv) :
- Buffered_Filter(BOTAN_PARALLEL_BLOCKS_CBC * ciph->BLOCK_SIZE,
+ Buffered_Filter(ciph->parallelism() * ciph->BLOCK_SIZE,
ciph->BLOCK_SIZE),
cipher(ciph), padder(pad)
{
@@ -140,7 +140,7 @@ CBC_Decryption::CBC_Decryption(BlockCipher* ciph,
throw Invalid_Block_Size(name(), padder->name());
state.resize(cipher->BLOCK_SIZE);
- temp.resize(BOTAN_PARALLEL_BLOCKS_CBC * cipher->BLOCK_SIZE);
+ temp.resize(buffered_block_size());
set_key(key);
set_iv(iv);
diff --git a/src/filters/modes/ecb/ecb.cpp b/src/filters/modes/ecb/ecb.cpp
index 2ce6576e3..948daf6c2 100644
--- a/src/filters/modes/ecb/ecb.cpp
+++ b/src/filters/modes/ecb/ecb.cpp
@@ -14,12 +14,12 @@ namespace Botan {
*/
ECB_Encryption::ECB_Encryption(BlockCipher* ciph,
BlockCipherModePaddingMethod* pad) :
- Buffered_Filter(ciph->BLOCK_SIZE * BOTAN_PARALLEL_BLOCKS_ECB, 0)
+ Buffered_Filter(ciph->BLOCK_SIZE * ciph->parallelism(), 0)
{
cipher = ciph;
padder = pad;
- temp.resize(cipher->BLOCK_SIZE * BOTAN_PARALLEL_BLOCKS_ECB);
+ temp.resize(buffered_block_size());
}
/*
@@ -28,12 +28,12 @@ ECB_Encryption::ECB_Encryption(BlockCipher* ciph,
ECB_Encryption::ECB_Encryption(BlockCipher* ciph,
BlockCipherModePaddingMethod* pad,
const SymmetricKey& key) :
- Buffered_Filter(ciph->BLOCK_SIZE * BOTAN_PARALLEL_BLOCKS_ECB, 0)
+ Buffered_Filter(ciph->BLOCK_SIZE * ciph->parallelism(), 0)
{
cipher = ciph;
padder = pad;
- temp.resize(cipher->BLOCK_SIZE * BOTAN_PARALLEL_BLOCKS_ECB);
+ temp.resize(buffered_block_size());
cipher->set_key(key);
}
@@ -111,12 +111,12 @@ void ECB_Encryption::buffered_final(const byte input[], u32bit input_length)
*/
ECB_Decryption::ECB_Decryption(BlockCipher* ciph,
BlockCipherModePaddingMethod* pad) :
- Buffered_Filter(ciph->BLOCK_SIZE * BOTAN_PARALLEL_BLOCKS_ECB, 1)
+ Buffered_Filter(ciph->BLOCK_SIZE * ciph->parallelism(), 1)
{
cipher = ciph;
padder = pad;
- temp.resize(cipher->BLOCK_SIZE * BOTAN_PARALLEL_BLOCKS_ECB);
+ temp.resize(buffered_block_size());
}
/*
@@ -125,12 +125,12 @@ ECB_Decryption::ECB_Decryption(BlockCipher* ciph,
ECB_Decryption::ECB_Decryption(BlockCipher* ciph,
BlockCipherModePaddingMethod* pad,
const SymmetricKey& key) :
- Buffered_Filter(ciph->BLOCK_SIZE * BOTAN_PARALLEL_BLOCKS_ECB, 1)
+ Buffered_Filter(ciph->BLOCK_SIZE * ciph->parallelism(), 1)
{
cipher = ciph;
padder = pad;
- temp.resize(cipher->BLOCK_SIZE * BOTAN_PARALLEL_BLOCKS_ECB);
+ temp.resize(buffered_block_size());
cipher->set_key(key);
}
diff --git a/src/filters/modes/xts/xts.cpp b/src/filters/modes/xts/xts.cpp
index aeef4e88d..26095e830 100644
--- a/src/filters/modes/xts/xts.cpp
+++ b/src/filters/modes/xts/xts.cpp
@@ -30,13 +30,21 @@ void poly_double(byte tweak[], u32bit size)
tweak[0] ^= polynomial;
}
+/* XTS needs to process at least 2 blocks in parallel
+ because block_size+1 bytes are needed at the end
+*/
+u32bit xts_parallelism(BlockCipher* cipher)
+ {
+ return std::max<u32bit>(cipher->parallelism(), 2);
+ }
+
}
/*
* XTS_Encryption constructor
*/
XTS_Encryption::XTS_Encryption(BlockCipher* ciph) :
- Buffered_Filter(BOTAN_PARALLEL_BLOCKS_XTS * ciph->BLOCK_SIZE,
+ Buffered_Filter(xts_parallelism(ciph) * ciph->BLOCK_SIZE,
ciph->BLOCK_SIZE + 1),
cipher(ciph)
{
@@ -44,7 +52,7 @@ XTS_Encryption::XTS_Encryption(BlockCipher* ciph) :
throw std::invalid_argument("Bad cipher for XTS: " + cipher->name());
cipher2 = cipher->clone();
- tweak.resize(BOTAN_PARALLEL_BLOCKS_XTS * cipher->BLOCK_SIZE);
+ tweak.resize(buffered_block_size());
}
/*
@@ -53,7 +61,7 @@ XTS_Encryption::XTS_Encryption(BlockCipher* ciph) :
XTS_Encryption::XTS_Encryption(BlockCipher* ciph,
const SymmetricKey& key,
const InitializationVector& iv) :
- Buffered_Filter(BOTAN_PARALLEL_BLOCKS_XTS * ciph->BLOCK_SIZE,
+ Buffered_Filter(xts_parallelism(ciph) * ciph->BLOCK_SIZE,
ciph->BLOCK_SIZE + 1),
cipher(ciph)
{
@@ -61,7 +69,7 @@ XTS_Encryption::XTS_Encryption(BlockCipher* ciph,
throw std::invalid_argument("Bad cipher for XTS: " + cipher->name());
cipher2 = cipher->clone();
- tweak.resize(BOTAN_PARALLEL_BLOCKS_XTS * cipher->BLOCK_SIZE);
+ tweak.resize(buffered_block_size());
set_key(key);
set_iv(iv);
@@ -210,7 +218,7 @@ void XTS_Encryption::buffered_final(const byte input[], u32bit length)
* XTS_Decryption constructor
*/
XTS_Decryption::XTS_Decryption(BlockCipher* ciph) :
- Buffered_Filter(BOTAN_PARALLEL_BLOCKS_XTS * ciph->BLOCK_SIZE,
+ Buffered_Filter(xts_parallelism(ciph) * ciph->BLOCK_SIZE,
ciph->BLOCK_SIZE + 1),
cipher(ciph)
{
@@ -218,7 +226,7 @@ XTS_Decryption::XTS_Decryption(BlockCipher* ciph) :
throw std::invalid_argument("Bad cipher for XTS: " + cipher->name());
cipher2 = ciph->clone();
- tweak.resize(BOTAN_PARALLEL_BLOCKS_XTS * cipher->BLOCK_SIZE);
+ tweak.resize(buffered_block_size());
}
/*
@@ -227,7 +235,7 @@ XTS_Decryption::XTS_Decryption(BlockCipher* ciph) :
XTS_Decryption::XTS_Decryption(BlockCipher* ciph,
const SymmetricKey& key,
const InitializationVector& iv) :
- Buffered_Filter(BOTAN_PARALLEL_BLOCKS_XTS * ciph->BLOCK_SIZE,
+ Buffered_Filter(xts_parallelism(ciph) * ciph->BLOCK_SIZE,
ciph->BLOCK_SIZE + 1),
cipher(ciph)
{
@@ -235,7 +243,7 @@ XTS_Decryption::XTS_Decryption(BlockCipher* ciph,
throw std::invalid_argument("Bad cipher for XTS: " + cipher->name());
cipher2 = ciph->clone();
- tweak.resize(BOTAN_PARALLEL_BLOCKS_XTS * cipher->BLOCK_SIZE);
+ tweak.resize(buffered_block_size());
set_key(key);
set_iv(iv);
diff --git a/src/stream/ctr/ctr.cpp b/src/stream/ctr/ctr.cpp
index 0b0f72da2..421c9f0c0 100644
--- a/src/stream/ctr/ctr.cpp
+++ b/src/stream/ctr/ctr.cpp
@@ -22,8 +22,8 @@ CTR_BE::CTR_BE(BlockCipher* ciph) :
{
position = 0;
- counter.resize(permutation->BLOCK_SIZE * BOTAN_PARALLEL_BLOCKS_CTR);
- buffer.resize(permutation->BLOCK_SIZE * BOTAN_PARALLEL_BLOCKS_CTR);
+ counter.resize(permutation->BLOCK_SIZE * permutation->parallelism());
+ buffer.resize(counter.size());
}
/*