Botan 2.1.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::PKCS7_Padding Class Referencefinal

`#include <mode_pad.h>`

Inheritance diagram for Botan::PKCS7_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

PKCS#7 Padding

Definition at line 68 of file mode_pad.h.

## Member Function Documentation

void Botan::PKCS7_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 41 of file mode_pad.cpp.

44 {
45 const uint8_t pad_value = static_cast<uint8_t>(block_size - last_byte_pos);
46
47 for(size_t i = 0; i != pad_value; ++i)
48 buffer.push_back(pad_value);
49 }

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

Returns
  name of the mode

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 79 of file mode_pad.h.

79 { return "PKCS7"; }

size_t Botan::PKCS7_Padding::unpad | ( | const uint8_t | block[],
|  | size_t | size
| ) |  | const
| override virtual

Remove padding bytes from block

Parameters

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

Returns
  number of padding bytes

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 54 of file mode_pad.cpp.

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

55 {
56 CT::poison(block,size);
57 size_t bad_input = 0;
58 const uint8_t last_byte = block[size-1];
59
60 bad_input |= CT::expand_mask(last_byte > size);
61
62 size_t pad_pos = size - last_byte;
63 size_t i = size - 2;
64 while(i)
65 {
66 bad_input |= ~CT::is_equal(block[i],last_byte) & CT::expand_mask(i >= pad_pos);
67 --i;
68 }
69
70 CT::conditional_copy_mem(bad_input,&pad_pos,&size,&pad_pos,1);
71 CT::unpoison(block,size);
72 CT::unpoison(pad_pos);
73 return pad_pos;
74 }
Botan::CT::conditional_copy_mem
void conditional_copy_mem(T value, T *to, const T *from0, const T *from1, size_t elems)
Definition: ct_utils.h:138
Botan::CT::poison
void poison(const T *p, size_t n)
Definition: ct_utils.h:46
Botan::CT::is_equal
T is_equal(T x, T y)
Definition: ct_utils.h:116
Botan::CT::expand_mask
T expand_mask(T x)
Definition: ct_utils.h:86
Botan::CT::unpoison
void unpoison(const T *p, size_t n)
Definition: ct_utils.h:57

bool Botan::PKCS7_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 77 of file mode_pad.h.

77 { return (bs > 0 && 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