Skip to content

Commit

Permalink
std::span<> for Tweakable_Block_Cipher::set_tweak()
Browse files Browse the repository at this point in the history
  • Loading branch information
reneme committed Jan 4, 2024
1 parent d7605c2 commit 825007d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/lib/block/block_cipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,12 @@ class BOTAN_PUBLIC_API(2, 8) Tweakable_Block_Cipher : public BlockCipher {
* 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;
void set_tweak(std::span<const uint8_t> tweak) { set_tweak_value(tweak); }

void set_tweak(const uint8_t tweak[], size_t len) { set_tweak_value(std::span(tweak, len)); }

private:
virtual void set_tweak_value(std::span<const uint8_t> tweak) = 0;
};

/**
Expand Down
7 changes: 3 additions & 4 deletions src/lib/block/threefish_512/threefish_512.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,11 @@ void Threefish_512::decrypt_blocks(std::span<const uint8_t> in, std::span<uint8_
}
}

void Threefish_512::set_tweak(const uint8_t tweak[], size_t len) {
BOTAN_ARG_CHECK(len == 16, "Threefish-512 requires 128 bit tweak");
void Threefish_512::set_tweak_value(std::span<const uint8_t> tweak) {
BOTAN_ARG_CHECK(tweak.size() == 16, "Threefish-512 requires 128 bit tweak");

m_T.resize(3);
m_T[0] = load_le<uint64_t>(tweak, 0);
m_T[1] = load_le<uint64_t>(tweak, 1);
load_le(tweak, m_T[0], m_T[1]);
m_T[2] = m_T[0] ^ m_T[1];
}

Expand Down
3 changes: 1 addition & 2 deletions src/lib/block/threefish_512/threefish_512.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ namespace Botan {
*/
class Threefish_512 final : public Block_Cipher_Fixed_Params<64, 64, 0, 1, Tweakable_Block_Cipher> {
public:
void set_tweak(const uint8_t tweak[], size_t len) override;

void clear() override;

std::string name() const override { return "Threefish-512"; }
Expand All @@ -29,6 +27,7 @@ class Threefish_512 final : public Block_Cipher_Fixed_Params<64, 64, 0, 1, Tweak

private:
void key_schedule(std::span<const uint8_t> key) override;
void set_tweak_value(std::span<const uint8_t> tweak) override;
void encrypt_blocks(std::span<const uint8_t> in, std::span<uint8_t> out, size_t blocks) const override;
void decrypt_blocks(std::span<const uint8_t> in, std::span<uint8_t> out, size_t blocks) const override;

Expand Down

0 comments on commit 825007d

Please sign in to comment.