diff options
author | Jack Lloyd <[email protected]> | 2019-09-28 08:17:47 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2019-09-28 08:17:47 -0400 |
commit | 99ff5c704af5da90f3ef2b2615fbe429f3310c2a (patch) | |
tree | 1126316bf8cc2ca8dc11e26b8be4c1b52bcc95c5 | |
parent | 2ba7d49aa3578dc279ab8c530447235a9f09fb11 (diff) | |
parent | 2e39157e3536e1c234fdce6b344bbb05d4569229 (diff) |
Merge GH #2123 XTS optimizations
-rw-r--r-- | src/lib/modes/xts/xts.cpp | 26 | ||||
-rw-r--r-- | src/lib/modes/xts/xts.h | 9 |
2 files changed, 19 insertions, 16 deletions
diff --git a/src/lib/modes/xts/xts.cpp b/src/lib/modes/xts/xts.cpp index 3d22a7094..559584b08 100644 --- a/src/lib/modes/xts/xts.cpp +++ b/src/lib/modes/xts/xts.cpp @@ -11,9 +11,12 @@ namespace Botan { -XTS_Mode::XTS_Mode(BlockCipher* cipher) : m_cipher(cipher) +XTS_Mode::XTS_Mode(BlockCipher* cipher) : + m_cipher(cipher), + m_cipher_block_size(m_cipher->block_size()), + m_cipher_parallelism(m_cipher->parallel_bytes()) { - if(poly_double_supported_size(m_cipher->block_size()) == false) + if(poly_double_supported_size(m_cipher_block_size) == false) { throw Invalid_Argument("Cannot use " + cipher->name() + " with XTS"); } @@ -38,14 +41,9 @@ std::string XTS_Mode::name() const return cipher().name() + "/XTS"; } -size_t XTS_Mode::update_granularity() const - { - return cipher().parallel_bytes(); - } - size_t XTS_Mode::minimum_final_size() const { - return cipher().block_size(); + return cipher_block_size(); } Key_Length_Specification XTS_Mode::key_spec() const @@ -55,12 +53,12 @@ Key_Length_Specification XTS_Mode::key_spec() const size_t XTS_Mode::default_nonce_length() const { - return cipher().block_size(); + return cipher_block_size(); } bool XTS_Mode::valid_nonce_length(size_t n) const { - return cipher().block_size() == n; + return cipher_block_size() == n; } void XTS_Mode::key_schedule(const uint8_t key[], size_t length) @@ -107,7 +105,7 @@ size_t XTS_Encryption::output_length(size_t input_length) const size_t XTS_Encryption::process(uint8_t buf[], size_t sz) { BOTAN_STATE_CHECK(tweak_set()); - const size_t BS = cipher().block_size(); + const size_t BS = cipher_block_size(); BOTAN_ASSERT(sz % BS == 0, "Input is full blocks"); size_t blocks = sz / BS; @@ -137,7 +135,7 @@ void XTS_Encryption::finish(secure_vector<uint8_t>& buffer, size_t offset) BOTAN_ASSERT(sz >= minimum_final_size(), "Have sufficient final input in XTS encrypt"); - const size_t BS = cipher().block_size(); + const size_t BS = cipher_block_size(); if(sz % BS == 0) { @@ -181,7 +179,7 @@ size_t XTS_Decryption::output_length(size_t input_length) const size_t XTS_Decryption::process(uint8_t buf[], size_t sz) { BOTAN_STATE_CHECK(tweak_set()); - const size_t BS = cipher().block_size(); + const size_t BS = cipher_block_size(); BOTAN_ASSERT(sz % BS == 0, "Input is full blocks"); size_t blocks = sz / BS; @@ -211,7 +209,7 @@ void XTS_Decryption::finish(secure_vector<uint8_t>& buffer, size_t offset) BOTAN_ASSERT(sz >= minimum_final_size(), "Have sufficient final input in XTS decrypt"); - const size_t BS = cipher().block_size(); + const size_t BS = cipher_block_size(); if(sz % BS == 0) { diff --git a/src/lib/modes/xts/xts.h b/src/lib/modes/xts/xts.h index e64a6de9f..cf9d50d0c 100644 --- a/src/lib/modes/xts/xts.h +++ b/src/lib/modes/xts/xts.h @@ -24,7 +24,7 @@ class BOTAN_PUBLIC_API(2,0) XTS_Mode : public Cipher_Mode public: std::string name() const override; - size_t update_granularity() const override; + size_t update_granularity() const override { return m_cipher_parallelism; } size_t minimum_final_size() const override; @@ -49,12 +49,17 @@ class BOTAN_PUBLIC_API(2,0) XTS_Mode : public Cipher_Mode void update_tweak(size_t last_used); + size_t cipher_block_size() const { return m_cipher_block_size; } + private: void start_msg(const uint8_t nonce[], size_t nonce_len) override; void key_schedule(const uint8_t key[], size_t length) override; - std::unique_ptr<BlockCipher> m_cipher, m_tweak_cipher; + std::unique_ptr<BlockCipher> m_cipher; + std::unique_ptr<BlockCipher> m_tweak_cipher; secure_vector<uint8_t> m_tweak; + const size_t m_cipher_parallelism; + const size_t m_cipher_block_size; }; /** |