Expose block sizes of block ciphers.
All checks were successful
Chaos Ci / test-and-benchmark (push) Successful in 1m45s

Both via static data members and Encryptor/Decryptor interfaces.
Crucial for safe memory allocation routine.
This commit is contained in:
hashlag
2026-01-31 19:26:51 +03:00
parent 8897d7a910
commit a97826da88
4 changed files with 65 additions and 34 deletions

View File

@@ -20,6 +20,11 @@ public:
return Impl().DecryptBlock(block);
}
auto GetBlockSize()
{
return Impl().GetBlockSize();
}
protected:
Decryptor() = default;

View File

@@ -196,6 +196,9 @@ class DesCrypt
{
public:
using Block = uint64_t;
static constexpr size_t BlockSize = 8;
static_assert(BlockSize == sizeof(Block));
DesCrypt() = delete;
@@ -227,6 +230,8 @@ public:
class DesEncryptor : public Encryptor<DesEncryptor>
{
public:
static constexpr size_t BlockSize = DesCrypt::BlockSize;
DesEncryptor(const Key & key)
: Schedule_(Inner_::KeySchedule::Direction::Encrypt, key.Key_)
{ }
@@ -255,6 +260,11 @@ public:
return DesCrypt::ProcessBlock(block, Schedule_);
}
constexpr size_t GetBlockSize()
{
return BlockSize;
}
private:
Inner_::KeySchedule Schedule_;
};
@@ -262,6 +272,8 @@ public:
class DesDecryptor : public Decryptor<DesDecryptor>
{
public:
static constexpr size_t BlockSize = DesCrypt::BlockSize;
DesDecryptor(const Key & key)
: Schedule_(Inner_::KeySchedule::Direction::Decrypt, key.Key_)
{ }
@@ -290,6 +302,11 @@ public:
return DesCrypt::ProcessBlock(block, Schedule_);
}
constexpr size_t GetBlockSize()
{
return BlockSize;
}
private:
Inner_::KeySchedule Schedule_;
};

View File

@@ -20,6 +20,11 @@ public:
return Impl().EncryptBlock(block);
}
auto GetBlockSize()
{
return Impl().GetBlockSize();
}
protected:
Encryptor() = default;