Botan 3.9.0
Crypto and TLS for C&
|
#include <mode_pad.h>
Public Member Functions | |
virtual void | add_padding (std::span< uint8_t > buffer, size_t final_block_bytes, size_t block_size) const |
virtual std::string | name () const =0 |
virtual size_t | output_length (size_t input_length, size_t block_size) const |
size_t | unpad (std::span< const uint8_t > last_block) const |
virtual bool | valid_blocksize (size_t block_size) const =0 |
virtual | ~BlockCipherModePaddingMethod ()=default |
Static Public Member Functions | |
static std::unique_ptr< BlockCipherModePaddingMethod > | create (std::string_view algo_spec) |
Protected Member Functions | |
virtual void | apply_padding (std::span< uint8_t > last_block, size_t padding_start_pos) const =0 |
virtual size_t | remove_padding (std::span< const uint8_t > last_block) const =0 |
Block Cipher Mode Padding Method This class is pretty limited, it cannot deal well with randomized padding methods, or any padding method that wants to add more than one block. For instance, it should be possible to define cipher text stealing mode as simply a padding mode for CBC, which happens to consume the last two block (and requires use of the block cipher).
Definition at line 30 of file mode_pad.h.
|
virtualdefault |
virtual destructor
|
virtual |
Add padding bytes to buffer.
buffer | data to pad, span must be large enough to hold the padding behind the final (partial) block |
final_block_bytes | size of the final block in bytes |
block_size | size of each block in bytes |
Reimplemented in Botan::Null_Padding.
Definition at line 44 of file mode_pad.cpp.
References apply_padding(), BOTAN_ASSERT_NOMSG, Botan::CT::scoped_poison(), and valid_blocksize().
|
protectedpure virtual |
Applies the concrete padding to the last_block
assuming the padding bytes should start at padding_start_pos
within the last block.
Concrete implementations of this function must ensure not to leak padding_start_pos
via side channels. Both the bytes of last_block
and padding_start_pos
are passed in with CT::poison applied.
Implemented in Botan::ANSI_X923_Padding, Botan::ESP_Padding, Botan::OneAndZeros_Padding, and Botan::PKCS7_Padding.
Referenced by add_padding().
|
static |
Get a block cipher padding mode by name (eg "NoPadding" or "PKCS7")
algo_spec | block cipher padding mode name |
Get a block cipher padding method by name
Definition at line 20 of file mode_pad.cpp.
Referenced by Botan::Cipher_Mode::create().
|
pure virtual |
Implemented in Botan::ANSI_X923_Padding, Botan::ESP_Padding, Botan::Null_Padding, Botan::OneAndZeros_Padding, and Botan::PKCS7_Padding.
|
inlinevirtual |
input_length | number of bytes to be padded |
block_size | size of each block in bytes |
Reimplemented in Botan::Null_Padding.
Definition at line 66 of file mode_pad.h.
Referenced by Botan::CBC_Encryption::output_length().
|
protectedpure virtual |
Removes the padding from last_block
and returns the number of data bytes. If the padding is invalid, this returns the byte length of last_block
.
Concrete implementations of this function must ensure not to leak the size or validity of the padding via side channels. The bytes of last_block
are passed in with CT::poison applied to them.
Implemented in Botan::ANSI_X923_Padding, Botan::ESP_Padding, Botan::Null_Padding, Botan::OneAndZeros_Padding, and Botan::PKCS7_Padding.
Referenced by unpad().
size_t Botan::BlockCipherModePaddingMethod::unpad | ( | std::span< const uint8_t > | last_block | ) | const |
Remove padding bytes from block
last_block | the last block containing the padding |
last_block
(i.e. the block size) Definition at line 54 of file mode_pad.cpp.
References Botan::CT::driveby_unpoison(), remove_padding(), Botan::CT::scoped_poison(), and valid_blocksize().
|
pure virtual |
block_size | of the cipher |
Implemented in Botan::ANSI_X923_Padding, Botan::ESP_Padding, Botan::Null_Padding, Botan::OneAndZeros_Padding, and Botan::PKCS7_Padding.
Referenced by add_padding(), and unpad().