Botan  2.6.0
Crypto and TLS for C++11
Public Member Functions | List of all members
Botan::ESP_Padding Class Referencefinal

#include <mode_pad.h>

Inheritance diagram for Botan::ESP_Padding:
Botan::BlockCipherModePaddingMethod

Public Member Functions

void add_padding (secure_vector< uint8_t > &buffer, size_t final_block_bytes, size_t block_size) const override
 
std::string name () const override
 
size_t unpad (const uint8_t[], size_t) const override
 
bool valid_blocksize (size_t bs) const override
 

Detailed Description

ESP Padding (RFC 4304)

Definition at line 119 of file mode_pad.h.

Member Function Documentation

◆ add_padding()

void Botan::ESP_Padding::add_padding ( secure_vector< uint8_t > &  buffer,
size_t  final_block_bytes,
size_t  block_size 
) const
overridevirtual

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

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 159 of file mode_pad.cpp.

162  {
163  uint8_t pad_value = 0x01;
164 
165  for(size_t i = last_byte_pos; i < block_size; ++i)
166  {
167  buffer.push_back(pad_value++);
168  }
169  }

◆ name()

std::string Botan::ESP_Padding::name ( ) const
inlineoverridevirtual
Returns
name of the mode

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 130 of file mode_pad.h.

130 { return "ESP"; }

◆ unpad()

size_t Botan::ESP_Padding::unpad ( const uint8_t  block[],
size_t  size 
) const
overridevirtual

Remove padding bytes from block

Parameters
blockthe last block
sizethe size of the block in bytes
Returns
number of padding bytes

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 174 of file mode_pad.cpp.

References Botan::CT::conditional_copy_mem(), Botan::CT::poison(), and Botan::CT::unpoison().

175  {
176  CT::poison(block,size);
177 
178  const size_t last_byte = block[size-1];
179  size_t bad_input = 0;
180  bad_input |= CT::expand_mask<size_t>(last_byte > size);
181 
182  size_t pad_pos = size - last_byte;
183  size_t i = size - 1;
184  while(i)
185  {
186  bad_input |= ~CT::is_equal<uint8_t>(size_t(block[i-1]),size_t(block[i])-1) & CT::expand_mask<uint8_t>(i > pad_pos);
187  --i;
188  }
189  CT::conditional_copy_mem(bad_input,&pad_pos,&size,&pad_pos,1);
190  CT::unpoison(block, size);
191  CT::unpoison(pad_pos);
192  return pad_pos;
193  }
void conditional_copy_mem(T value, T *to, const T *from0, const T *from1, size_t elems)
Definition: ct_utils.h:142
void poison(const T *p, size_t n)
Definition: ct_utils.h:46
void unpoison(const T *p, size_t n)
Definition: ct_utils.h:57

◆ valid_blocksize()

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

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 128 of file mode_pad.h.

128 { return (bs > 0); }

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