Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
Botan::ESP_Padding Class Referencefinal

`#include <mode_pad.h>`

Inheritance diagram for Botan::ESP_Padding:

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

## Member Function Documentation

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

Add padding bytes to buffer.

Parameters

  buffer | data to pad
  final_block_bytes | size of the final block in bytes
  block_size | size of each block in bytes

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 180 of file mode_pad.cpp.

183 {
184 uint8_t pad_value = 0x01;
185
186 for(size_t i = last_byte_pos; i < block_size; ++i)
187 {
188 buffer.push_back(pad_value++);
189 }
190 }

std::string Botan::ESP_Padding::name | ( |  | ) | const
| inline override virtual

Returns
  name of the mode

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 131 of file mode_pad.h.

131 { return "ESP"; }

size_t Botan::ESP_Padding::unpad | ( | const uint8_t | block[],
|  | size_t | len
| ) |  | const
| override virtual

Remove padding bytes from block

Parameters

  block | the last block
  len | the size of the block in bytes

Returns
  number of data bytes, or if the padding is invalid returns len

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 195 of file mode_pad.cpp.

References Botan::CT::Mask< T >::is_equal(), Botan::CT::Mask< T >::is_gt(), Botan::CT::Mask< T >::is_zero(), Botan::CT::poison(), Botan::CT::unpoison(), and valid_blocksize().

196 {
197 if(!valid_blocksize(input_length))
198 return input_length;
199
200 CT::poison(input, input_length);
201
202 const uint8_t input_length_8 = static_cast<uint8_t>(input_length);
203 const uint8_t last_byte = input[input_length-1];
204
205 auto bad_input = CT::Mask<uint8_t>::is_zero(last_byte) |
206 CT::Mask<uint8_t>::is_gt(last_byte, input_length_8);
207
208 const uint8_t pad_pos = input_length_8 - last_byte;
209 size_t i = input_length_8 - 1;
210 while(i)
211 {
212 const auto in_range = CT::Mask<size_t>::is_gt(i, pad_pos);
213 const auto incrementing = CT::Mask<uint8_t>::is_equal(input[i-1], input[i]-1);
214
215 bad_input |= CT::Mask<uint8_t>(in_range) & ~incrementing;
216 --i;
217 }
218
219 CT::unpoison(input, input_length);
220 return bad_input.select_and_unpoison(input_length_8, pad_pos);
221 }
Botan::ESP_Padding::valid_blocksize
bool valid_blocksize(size_t bs) const override
Definition: mode_pad.h:129
Botan::CT::poison
void poison(const T *p, size_t n)
Definition: ct_utils.h:48
Botan::CT::unpoison
void unpoison(const T *p, size_t n)
Definition: ct_utils.h:59
Botan::CT::Mask::is_zero
static Mask< T > is_zero(T x)
Definition: ct_utils.h:141
Botan::CT::Mask::is_equal
static Mask< T > is_equal(T x, T y)
Definition: ct_utils.h:149
Botan::CT::Mask::is_gt
static Mask< T > is_gt(T x, T y)
Definition: ct_utils.h:165

bool Botan::ESP_Padding::valid_blocksize | ( | size_t | block_size | ) | const
| inline override virtual

Parameters

  block_size | of the cipher

Returns
  valid block size for this padding mode

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 129 of file mode_pad.h.

Referenced by unpad().

129 { return (bs > 2 && bs < 256); }

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

- src/lib/modes/mode_pad/mode_pad.h
- src/lib/modes/mode_pad/mode_pad.cpp