aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/block
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/block')
-rw-r--r--src/lib/block/block_cipher.h24
-rw-r--r--src/lib/block/threefish_512/threefish_512.h5
2 files changed, 23 insertions, 6 deletions
diff --git a/src/lib/block/block_cipher.h b/src/lib/block/block_cipher.h
index 939382fc0..5d490ae49 100644
--- a/src/lib/block/block_cipher.h
+++ b/src/lib/block/block_cipher.h
@@ -198,10 +198,26 @@ class BOTAN_PUBLIC_API(2,0) BlockCipher : public SymmetricAlgorithm
};
/**
+* Tweakable block ciphers allow setting a tweak which is a non-keyed
+* value which affects the encryption/decryption operation.
+*/
+class BOTAN_PUBLIC_API(2,8) Tweakable_Block_Cipher : public BlockCipher
+ {
+ public:
+ /**
+ * Set the tweak value. This must be called after setting a key. The value
+ * persists until either set_tweak, set_key, or clear is called.
+ * Different algorithms support different tweak length(s). If called with
+ * an unsupported length, Invalid_Argument will be thrown.
+ */
+ virtual void set_tweak(const uint8_t tweak[], size_t len) = 0;
+ };
+
+/**
* Represents a block cipher with a single fixed block size
*/
-template<size_t BS, size_t KMIN, size_t KMAX = 0, size_t KMOD = 1>
-class Block_Cipher_Fixed_Params : public BlockCipher
+template<size_t BS, size_t KMIN, size_t KMAX = 0, size_t KMOD = 1, typename BaseClass = BlockCipher>
+class Block_Cipher_Fixed_Params : public BaseClass
{
public:
enum { BLOCK_SIZE = BS };
@@ -213,7 +229,7 @@ class Block_Cipher_Fixed_Params : public BlockCipher
size_t blocks) const final override
{
xor_buf(data, mask, blocks * BS);
- encrypt_n(data, data, blocks);
+ this->encrypt_n(data, data, blocks);
xor_buf(data, mask, blocks * BS);
}
@@ -222,7 +238,7 @@ class Block_Cipher_Fixed_Params : public BlockCipher
size_t blocks) const final override
{
xor_buf(data, mask, blocks * BS);
- decrypt_n(data, data, blocks);
+ this->decrypt_n(data, data, blocks);
xor_buf(data, mask, blocks * BS);
}
diff --git a/src/lib/block/threefish_512/threefish_512.h b/src/lib/block/threefish_512/threefish_512.h
index 8b39c75c5..2e936b25f 100644
--- a/src/lib/block/threefish_512/threefish_512.h
+++ b/src/lib/block/threefish_512/threefish_512.h
@@ -15,13 +15,14 @@ namespace Botan {
/**
* Threefish-512
*/
-class BOTAN_PUBLIC_API(2,0) Threefish_512 final : public Block_Cipher_Fixed_Params<64, 64>
+class BOTAN_PUBLIC_API(2,0) Threefish_512 final :
+ public Block_Cipher_Fixed_Params<64, 64, 0, 1, Tweakable_Block_Cipher>
{
public:
void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override;
void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override;
- void set_tweak(const uint8_t tweak[], size_t len);
+ void set_tweak(const uint8_t tweak[], size_t len) override;
void clear() override;
std::string provider() const override;