Botan 3.4.0
Crypto and TLS for C&
Public Member Functions | Static Public Member Functions | List of all members
Botan::BlockCipherModePaddingMethod Class Referenceabstract

#include <mode_pad.h>

Inheritance diagram for Botan::BlockCipherModePaddingMethod:
Botan::ANSI_X923_Padding Botan::ESP_Padding Botan::Null_Padding Botan::OneAndZeros_Padding Botan::PKCS7_Padding

Public Member Functions

virtual void add_padding (secure_vector< uint8_t > &buffer, size_t final_block_bytes, size_t block_size) const =0
 
virtual std::string name () const =0
 
virtual size_t unpad (const uint8_t block[], size_t len) const =0
 
virtual bool valid_blocksize (size_t block_size) const =0
 
virtual ~BlockCipherModePaddingMethod ()=default
 

Static Public Member Functions

static std::unique_ptr< BlockCipherModePaddingMethodcreate (std::string_view algo_spec)
 

Detailed Description

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 26 of file mode_pad.h.

Constructor & Destructor Documentation

◆ ~BlockCipherModePaddingMethod()

virtual Botan::BlockCipherModePaddingMethod::~BlockCipherModePaddingMethod ( )
virtualdefault

virtual destructor

Member Function Documentation

◆ add_padding()

virtual void Botan::BlockCipherModePaddingMethod::add_padding ( secure_vector< uint8_t > & buffer,
size_t final_block_bytes,
size_t block_size ) const
pure virtual

Add padding bytes to buffer.

Parameters
bufferdata to pad
final_block_bytessize of the final block in bytes
block_sizesize of each block in bytes

Implemented in Botan::Null_Padding, Botan::PKCS7_Padding, Botan::ANSI_X923_Padding, Botan::OneAndZeros_Padding, and Botan::ESP_Padding.

◆ create()

std::unique_ptr< BlockCipherModePaddingMethod > Botan::BlockCipherModePaddingMethod::create ( std::string_view algo_spec)
static

Get a block cipher padding mode by name (eg "NoPadding" or "PKCS7")

Parameters
algo_specblock cipher padding mode name

Get a block cipher padding method by name

Definition at line 19 of file mode_pad.cpp.

19 {
20 if(algo_spec == "NoPadding") {
21 return std::make_unique<Null_Padding>();
22 }
23
24 if(algo_spec == "PKCS7") {
25 return std::make_unique<PKCS7_Padding>();
26 }
27
28 if(algo_spec == "OneAndZeros") {
29 return std::make_unique<OneAndZeros_Padding>();
30 }
31
32 if(algo_spec == "X9.23") {
33 return std::make_unique<ANSI_X923_Padding>();
34 }
35
36 if(algo_spec == "ESP") {
37 return std::make_unique<ESP_Padding>();
38 }
39
40 return nullptr;
41}

Referenced by Botan::Cipher_Mode::create().

◆ name()

virtual std::string Botan::BlockCipherModePaddingMethod::name ( ) const
pure virtual

◆ unpad()

virtual size_t Botan::BlockCipherModePaddingMethod::unpad ( const uint8_t block[],
size_t len ) const
pure virtual

Remove padding bytes from block

Parameters
blockthe last block
lenthe size of the block in bytes
Returns
number of data bytes, or if the padding is invalid returns len

Implemented in Botan::Null_Padding, Botan::PKCS7_Padding, Botan::ANSI_X923_Padding, Botan::OneAndZeros_Padding, and Botan::ESP_Padding.

◆ valid_blocksize()

virtual bool Botan::BlockCipherModePaddingMethod::valid_blocksize ( size_t block_size) const
pure virtual
Parameters
block_sizeof the cipher
Returns
valid block size for this padding mode

Implemented in Botan::PKCS7_Padding, Botan::ANSI_X923_Padding, Botan::OneAndZeros_Padding, Botan::ESP_Padding, and Botan::Null_Padding.


The documentation for this class was generated from the following files: